/* ══════════════════════════════════════════════
   ISM App — Estilos mobile-first
   Color corporativo: #e22575
   ══════════════════════════════════════════════ */

:root {
  --pink:        #e22575;
  --pink-dark:   #b81a5a;
  --pink-light:  #fbeaf0;
  --pink-mid:    #f4c0d1;
  --pink-text:   #72243e;
  --gray-1:      #f8f8f8;
  --gray-2:      #f0f0f0;
  --gray-3:      #e0e0e0;
  --gray-4:      #aaaaaa;
  --gray-5:      #666666;
  --gray-6:      #333333;
  --success:     #2e7d32;
  --success-bg:  #e6f4ea;
  --warning:     #e65100;
  --warning-bg:  #fff3e0;
  --radius-sm:   8px;
  --radius-md:   12px;
  --radius-lg:   20px;
  --radius-xl:   28px;
  --shadow:      0 2px 12px rgba(226,37,117,.10);
  --shadow-sm:   0 1px 4px rgba(0,0,0,.08);
  --transition:  .18s ease;
  --bottom-nav:  60px;
  --header-h:    80px;
  --font:        'Inter', 'Helvetica Neue', sans-serif;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--gray-1);
  color: var(--gray-6);
  min-height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  overscroll-behavior: none;
}
a { color: var(--pink); text-decoration: none; }
img { max-width: 100%; }
button, input, select, textarea { font-family: inherit; outline: none; }

/* ── Tipografía ── */
h1 { font-size: 1.4rem; font-weight: 700; color: var(--gray-6); }
h2 { font-size: 1.1rem; font-weight: 600; color: var(--gray-6); }
h3 { font-size: .95rem; font-weight: 600; color: var(--gray-6); }
p  { font-size: .9rem; color: var(--gray-5); line-height: 1.5; }

/* ── Layout principal ── */
.app-wrapper { display: flex; flex-direction: column; min-height: 100vh; }

.page-content {
  flex: 1;
  padding-bottom: calc(var(--bottom-nav) + 8px);
  overflow-y: auto;
}

/* ── Header ── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--pink);
  min-height: var(--header-h);
  display: flex;
  align-items: flex-end;
  padding: 0 16px 10px;
  padding-top: 44px;
  gap: 12px;
  box-shadow: 0 2px 8px rgba(226,37,117,.2);
}
.app-header .header-title {
  flex: 1;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
}
.app-header .header-subtitle {
  color: rgba(255,255,255,.75);
  font-size: .75rem;
  margin-top: 1px;
}
.header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,.4);
  background: rgba(255,255,255,.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .85rem;
  color: var(--pink);
}
.header-avatar img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }

.center-selector {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,.2);
  border-radius: var(--radius-lg);
  padding: 4px 10px;
  color: #fff;
  font-size: .75rem;
  cursor: pointer;
  border: none;
  transition: background var(--transition);
}
.center-selector:active { background: rgba(255,255,255,.35); }

/* ── Bottom Navigation ── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: var(--bottom-nav);
  background: #fff;
  border-top: 1px solid var(--gray-3);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 200;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  padding: 6px 14px;
  border-radius: 12px;
  transition: background var(--transition);
  border: none;
  background: transparent;
  text-decoration: none;
}
.nav-item:active { background: var(--pink-light); }
.nav-item .nav-icon { font-size: 1.4rem; line-height: 1; }
.nav-item .nav-label { font-size: .65rem; color: var(--gray-4); font-weight: 500; }
.nav-item.active .nav-label { color: var(--pink); font-weight: 700; }
.nav-item.active .nav-icon { filter: none; }


/* ── Cards ── */
.card {
  background: #fff;
  border-radius: var(--radius-md);
  border: 1px solid var(--gray-3);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 8px; }

.card-title { font-size: .9rem; font-weight: 600; color: var(--gray-6); }
.card-subtitle { font-size: .75rem; color: var(--gray-4); margin-top: 2px; }

/* ── Botones ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--radius-md);
  padding: 11px 18px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: transform var(--transition), opacity var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--pink); color: #fff; }
.btn-primary:hover { background: var(--pink-dark); }
.btn-outline {
  background: transparent;
  color: var(--pink);
  border: 1.5px solid var(--pink);
}
.btn-outline:hover { background: var(--pink-light); }
.btn-gray {
  background: var(--gray-2);
  color: var(--gray-5);
  border: 1px solid var(--gray-3);
}
.btn-full { width: 100%; }
.btn-sm { padding: 7px 14px; font-size: .8rem; }
.btn:disabled { opacity: .45; pointer-events: none; }

/* ── Formularios ── */
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-label {
  font-size: .75rem;
  font-weight: 600;
  color: var(--gray-5);
  text-transform: uppercase;
  letter-spacing: .4px;
}
.form-label .required { color: var(--pink); margin-left: 2px; }
.form-control {
  width: 100%;
  border: 1.5px solid var(--gray-3);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: .9rem;
  color: var(--gray-6);
  background: #fff;
  transition: border-color var(--transition);
  -webkit-appearance: none;
}
.form-control:focus { border-color: var(--pink); box-shadow: 0 0 0 3px rgba(226,37,117,.1); }
.form-control.is-invalid { border-color: #e53935; }
.form-error { font-size: .75rem; color: #e53935; margin-top: 3px; display: none; }
.form-error.visible { display: block; }
textarea.form-control { min-height: 72px; resize: vertical; }

/* ── Chips / Actos ── */
.chip-group { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  background: var(--gray-2);
  border: 1px solid var(--gray-3);
  border-radius: var(--radius-lg);
  padding: 6px 12px;
  font-size: .8rem;
  color: var(--gray-5);
  cursor: pointer;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.chip:active, .chip.active {
  background: var(--pink);
  color: #fff;
  border-color: var(--pink);
}
.chip-more {
  background: transparent;
  border: 1px dashed var(--gray-4);
  color: var(--gray-4);
}

/* ── Logos aseguradoras ── */
.insurance-scroll { display: flex; gap: 8px; }
.insurance-item {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  height: 52px;
  border: 1.5px solid var(--gray-3);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color var(--transition);
  background: #fff;
  overflow: hidden;
}
.insurance-item.active { border-color: var(--pink); border-width: 2px; box-shadow: 0 0 0 3px rgba(226,37,117,.1); }
.insurance-item img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 8px;
  box-sizing: border-box;
}
.insurance-item .insurance-fallback {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: .6rem;
  line-height: 1.15;
  color: var(--gray-5);
  padding: 4px;
  background: #fff;
}
.insurance-item span { font-size: .65rem; color: var(--gray-5); }
#btn-ver-todas-aseg { flex-direction: column; gap: 2px; }

/* ── Badges / Estados ── */
.badge {
  display: inline-block;
  border-radius: var(--radius-lg);
  padding: 3px 8px;
  font-size: .7rem;
  font-weight: 600;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-pending { background: var(--pink-light); color: var(--pink-text); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-info    { background: #e3f2fd; color: #1565c0; }

/* ── Alertas / Banners ── */
.alert-banner {
  background: var(--pink-light);
  border: 1px solid var(--pink-mid);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin: 12px 14px;
}
.alert-banner .alert-title { font-size: .85rem; font-weight: 700; color: var(--pink-text); }
.alert-banner .alert-body  { font-size: .8rem; color: var(--pink-text); margin-top: 4px; }
.alert-banner .alert-actions { display: flex; gap: 8px; margin-top: 10px; }

/* ── Métricas ── */
.metrics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 14px; }
.metric-card {
  background: #fff;
  border: 1px solid var(--gray-3);
  border-radius: var(--radius-md);
  padding: 12px;
}
.metric-label { font-size: .7rem; color: var(--gray-4); font-weight: 500; margin-bottom: 4px; }
.metric-value { font-size: 1.3rem; font-weight: 700; color: var(--gray-6); }
.metric-value.pink { color: var(--pink); }
.metric-sub { font-size: .7rem; color: var(--gray-4); margin-top: 2px; }

/* ── Lista de registros ── */
.record-list { display: flex; flex-direction: column; gap: 8px; padding: 0 14px; }
.record-item {
  background: #fff;
  border: 1px solid var(--gray-3);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.record-left { flex: 1; min-width: 0; }
.record-title { font-size: .88rem; font-weight: 600; color: var(--gray-6); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.record-sub   { font-size: .75rem; color: var(--gray-4); margin-top: 2px; }
.record-meta  { font-size: .7rem; color: var(--gray-5); background: var(--gray-1); border-radius: 6px; padding: 3px 7px; margin-top: 6px; }
.record-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.record-amount { font-size: .88rem; font-weight: 700; color: var(--gray-6); }
.record-date { font-size: .72rem; color: var(--gray-4); }

/* ── Calendario ── */
.cal-grid { display: grid; grid-template-columns: repeat(7,1fr); gap: 2px; }
.cal-day-name { text-align: center; font-size: .65rem; color: var(--gray-4); font-weight: 700; padding: 4px 0; text-transform: uppercase; }
.cal-day {
  text-align: center;
  padding: 5px 2px;
  font-size: .8rem;
  border-radius: 8px;
  cursor: pointer;
  position: relative;
  transition: background var(--transition);
}
.cal-day:hover { background: var(--gray-2); }
.cal-day.today { background: var(--pink); color: #fff; font-weight: 700; }
.cal-day.has-event::after {
  content: '';
  display: block;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--pink);
  margin: 2px auto 0;
}
.cal-day.has-event.today::after { background: #fff; }

/* ── Sección separador ── */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 14px;
  margin-bottom: 8px;
}
.section-title { font-size: .9rem; font-weight: 700; color: var(--gray-6); }

/* ── Loading ── */
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--gray-3);
  border-top-color: var(--pink);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  display: none;
}
.loading-overlay.visible { display: flex; }

/* ── Toast ── */
#toast-container {
  position: fixed;
  bottom: calc(var(--bottom-nav) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 5000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% - 28px);
  max-width: 452px;
  pointer-events: none;
}
.toast {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: .85rem;
  font-weight: 600;
  color: #fff;
  opacity: 0;
  transform: translateY(10px);
  animation: toastIn .3s forwards, toastOut .3s 2.7s forwards;
  pointer-events: none;
}
.toast.success { background: #2e7d32; }
.toast.error   { background: #c62828; }
.toast.info    { background: #1565c0; }
@keyframes toastIn  { to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(10px); } }

/* ── Modal / Bottom Sheet ── */
.sheet-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  display: none;
  align-items: flex-end;
  -webkit-overflow-scrolling: touch;
}
.sheet-overlay.open {
  display: flex;
}
.sheet {
  background: #fff;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  width: 100%;
  max-height: 80vh;
  height: auto;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  padding: 20px 16px 32px;
  animation: slideUp .25s ease;
  position: relative;
  z-index: 1001;
}
.sheet-handle {
  width: 40px; height: 4px;
  border-radius: 2px;
  background: var(--gray-3);
  margin: 0 auto 16px;
}
.sheet-title { font-size: 1rem; font-weight: 700; color: var(--gray-6); margin-bottom: 16px; }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ── Búsqueda con autocomplete ── */
.autocomplete-wrapper { position: relative; }
.autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: #fff;
  border: 1px solid var(--gray-3);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 500;
  max-height: 200px;
  overflow-y: auto;
}
.autocomplete-item {
  padding: 10px 12px;
  font-size: .85rem;
  cursor: pointer;
  border-bottom: 1px solid var(--gray-2);
}
.autocomplete-item:hover { background: var(--pink-light); }

/* ── Filtros fecha inline ── */
.filter-row {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 14px;
  background: #fff;
  border-bottom: 1px solid var(--gray-3);
}
.filter-row input[type="date"],
.filter-row select {
  flex: 1;
  border: 1px solid var(--gray-3);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: .82rem;
  color: var(--gray-6);
  background: #fff;
  -webkit-appearance: none;
}
.filter-row input[type="date"]:focus,
.filter-row select:focus { border-color: var(--pink); }

/* ── Factura vista detalle ── */
.invoice-header {
  text-align: center;
  padding: 24px 16px 16px;
  border-bottom: 1px solid var(--gray-3);
}
.invoice-logo { max-height: 48px; margin-bottom: 8px; }
.invoice-number { font-size: 1.1rem; font-weight: 700; color: var(--pink); }
.invoice-date { font-size: .8rem; color: var(--gray-4); }

.invoice-line {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--gray-2);
  font-size: .85rem;
}
.invoice-line-label { color: var(--gray-5); }
.invoice-line-value { font-weight: 600; color: var(--gray-6); }
.invoice-total {
  display: flex;
  justify-content: space-between;
  padding: 14px 0 0;
  font-size: 1rem;
  font-weight: 700;
}
.invoice-total .value { color: var(--pink); font-size: 1.2rem; }

/* ── Leyenda calendario ── */
.legend { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 14px; }
.legend-item { display: flex; align-items: center; gap: 5px; font-size: .72rem; color: var(--gray-5); }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ── Scroll principal ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-3); border-radius: 4px; }

/* ── Fix WebView Android ── */
html, body {
  height: 100%;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
.sheet-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  width: 100%;
  height: 100%;
  z-index: 9999;
  background: rgba(0,0,0,0.45);
  align-items: flex-end;
}
.sheet-overlay.open {
  display: flex;
}
.sheet {
  width: 100%;
  max-height: 75vh;
  background: #fff;
  border-radius: 24px 24px 0 0;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  padding: 20px 16px 48px;
}
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .bottom-nav { padding-bottom: env(safe-area-inset-bottom); height: calc(var(--bottom-nav) + env(safe-area-inset-bottom)); }
  .page-content { padding-bottom: calc(var(--bottom-nav) + env(safe-area-inset-bottom) + 8px); }
}

/* ── Animación entrada de página ── */
.page-enter { animation: fadeSlide .22s ease; }
@keyframes fadeSlide { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }

/* ── Select actos con búsqueda ── */
.acto-search-wrapper { position: relative; }
.acto-search-input { padding-right: 36px; }
.acto-search-icon {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray-4);
  font-size: 1rem;
  pointer-events: none;
}
/* Elementos ocultos con el atributo hidden (avisos de instalación y push) */
[hidden] { display: none !important; }
