/* ============================================================
   OPTOMETRÍA SUNWATCH — Estilos globales
   ============================================================ */

/* Variables */
:root {
  --navy:        #1B2A4A;
  --navy-dark:   #0F1E38;
  --blue:        #2E5FA3;
  --blue-light:  #D6E4F7;
  --blue-pale:   #EBF3FC;
  --blue-mid:    #7BA3CC;
  --white:       #FFFFFF;
  --bg:          #F4F6FA;
  --border:      #DDE3EE;
  --text:        #1B2A4A;
  --text-muted:  #6B7A99;
  --text-light:  #374151;
  --green:       #0F6E56;
  --green-bg:    #E1F5EE;
  --green-bdr:   #9FE1CB;
  --amber:       #854F0B;
  --amber-bg:    #FFF8E6;
  --amber-bdr:   #FAEEDA;
  --red:         #A32D2D;
  --red-bg:      #FCEBEB;
  --red-bdr:     #F7C1C1;
  --purple:      #534AB7;
  --purple-bg:   #EEEDFE;
  --sidebar-w:   208px;
  --sidebar-w-collapsed: 56px;
  --topbar-h:    56px;
  --radius:      12px;
  --radius-sm:   8px;
  --transition:  .15s ease;

  /* Sidebar claro — separado del navy oscuro que ahora solo vive en topbar/logo/acentos */
  --sidebar-bg:        #F7F9FC;
  --sidebar-border:    #E4E9F2;
  --sidebar-text:      #45557A;
  --sidebar-text-muted:#93A0BC;
  --sidebar-hover-bg:  #EAF0FA;
  --sidebar-active-bg: var(--blue);

  --shadow-card: 0 1px 2px rgba(27,42,74,.05), 0 1px 6px rgba(27,42,74,.04);

  /* Sistema de color semántico: gris = normal, ámbar = atención, rojo = urgente.
     Reemplaza los colores sueltos (morado/azul-marino/verde-menta) que antes
     se usaban sin un criterio consistente para indicar estado. */
  --sem-normal:      #6B7A99;
  --sem-normal-bg:   #F1F3F7;
  --sem-normal-bdr:  #DDE3EE;
  --sem-atencion:     var(--amber);
  --sem-atencion-bg:  var(--amber-bg);
  --sem-atencion-bdr: var(--amber-bdr);
  --sem-urgente:      var(--red);
  --sem-urgente-bg:   var(--red-bg);
  --sem-urgente-bdr:  var(--red-bdr);
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-tap-highlight-color: transparent; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
       background: var(--bg); color: var(--text); line-height: 1.5; }
a { color: var(--blue); text-decoration: none; }
img { max-width: 100%; }

/* ---- LOGIN ---- */
.login-body { background: var(--navy-dark); min-height: 100vh;
              display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-wrap { width: 100%; max-width: 380px; }
.login-card { background: var(--white); border-radius: 16px; padding: 2rem 1.75rem; }
.login-logo { display: flex; justify-content: center; margin-bottom: 1rem; }
.login-logo-img { width: 64px; height: 64px; object-fit: contain; border-radius: 12px; }
.login-logo-fallback { width: 56px; height: 56px; border-radius: 50%;
                        background: var(--blue); color: #fff; font-size: 18px;
                        font-weight: 600; align-items: center; justify-content: center; }
.login-title { font-size: 1.25rem; font-weight: 600; color: var(--navy);
               text-align: center; margin-bottom: .25rem; }
.login-sub  { font-size: .8rem; color: var(--text-muted); text-align: center; margin-bottom: 1.5rem; }
.login-footer { font-size: .75rem; color: var(--text-muted); text-align: center; margin-top: 1rem; }

/* ---- LAYOUT ---- */
.app-layout { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.app-body   { flex: 1; display: flex; overflow: hidden; min-height: 0; }

.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w); background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex; flex-direction: column; align-items: stretch;
  padding: .85rem .6rem; gap: 2px; flex-shrink: 0; overflow-y: auto; overflow-x: hidden;
  box-sizing: border-box;
}
.sidebar-group-lbl { font-size: .64rem; font-weight: 600; letter-spacing: .06em;
                      text-transform: uppercase; color: var(--sidebar-text-muted);
                      padding: .7rem .6rem .25rem; white-space: nowrap; overflow: hidden;
                      text-overflow: ellipsis; max-width: 100%; box-sizing: border-box; }
.sidebar-group-lbl:first-child { padding-top: .1rem; }
.nav-item { height: 42px; min-height: 42px; max-height: 42px;
            width: 100%; max-width: 100%; box-sizing: border-box;
            border-radius: var(--radius-sm); padding: 0 .65rem; overflow: hidden;
            display: flex; align-items: center; flex-wrap: nowrap; gap: .6rem;
            cursor: pointer; transition: var(--transition); color: var(--sidebar-text);
            text-decoration: none; }
.nav-item:hover { background: var(--sidebar-hover-bg); color: var(--navy); }
.nav-item.active { background: var(--sidebar-active-bg); color: #fff; }
.nav-item.active:hover { background: var(--sidebar-active-bg); }
.nav-item svg { width: 18px !important; height: 18px !important;
                min-width: 18px !important; max-width: 18px !important;
                flex-shrink: 0 !important; display: block; opacity: .85; }
.nav-item.active svg { opacity: 1; }
.nav-item-lbl { display: block; flex: 1 1 auto; min-width: 0; max-width: 100%;
                font-size: .78rem; font-weight: 500; line-height: 42px;
                white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-sep { height: 1px; background: var(--sidebar-border); margin: .5rem .6rem; }

/* ---- FILTER PILLS (listados con filtros por estatus) ---- */
.filter-pill { display: inline-flex; align-items: center; gap: .35rem; padding: .4rem .8rem;
               border-radius: 16px; font-size: .75rem; font-weight: 500; text-decoration: none;
               background: var(--white); color: var(--text-muted); border: 1px solid var(--border);
               transition: var(--transition); }
.filter-pill:hover  { border-color: var(--blue); color: var(--blue); }
.filter-pill.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.filter-pill i { font-size: .85rem; }
.chev { transform: rotate(0deg); }
.chev.rot { transform: rotate(180deg); }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  height: var(--topbar-h); background: var(--navy); padding: 0 1.1rem;
  display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
  width: 100%; box-sizing: border-box;
}
.topbar-left { display: flex; align-items: center; gap: .7rem; }
.topbar-logo { width: 32px; height: 32px; object-fit: cover; border-radius: 50%; flex-shrink: 0; display: block; }
.topbar-logo-fallback { width: 32px; height: 32px; border-radius: 50%; background: var(--blue);
                         color: #fff; font-size: .68rem; font-weight: 600;
                         display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.topbar-title { font-size: .9rem; font-weight: 500; color: #fff; }
.topbar-sub   { font-size: .7rem; color: var(--blue-mid); }
.topbar-right { display: flex; align-items: center; gap: .5rem; }

.content { flex: 1; overflow-y: auto; padding: 1rem; }

/* ---- TARJETAS ---- */
.card { background: var(--white); border-radius: var(--radius);
        border: .5px solid var(--border); box-shadow: var(--shadow-card);
        padding: 1rem; margin-bottom: .8rem; }
.card-title { font-size: .7rem; font-weight: 600; color: var(--blue);
              padding-bottom: .5rem; border-bottom: .5px solid var(--blue-pale);
              margin-bottom: .75rem; letter-spacing: .03em; text-transform: uppercase; }

/* ---- FORMULARIOS ----
   NOTA: ".f" es un alias de ".field" — la mayoría de los módulos del sistema
   usan class="f" en sus campos, pero solo ".field" tenía estilos definidos.
   Esto dejaba 244 campos sin estilo en 16 archivos. Se agrega el alias aquí
   en vez de renombrar cada campo, para no tocar la lógica de cada módulo. */
.field, .f { display: flex; flex-direction: column; gap: .2rem; }
.field label, .f label { font-size: .7rem; font-weight: 600; color: var(--text-muted);
               letter-spacing: .03em; text-transform: uppercase; }
.field input, .field select, .field textarea,
.f input, .f select, .f textarea {
  border: .5px solid var(--border); border-radius: var(--radius-sm);
  padding: .55rem .6rem; font-size: .8rem; color: var(--text);
  background: var(--white); width: 100%; transition: var(--transition);
  font-family: inherit; height: 40px; box-sizing: border-box;
}
.field textarea, .f textarea { height: auto; }
.field input:focus, .field select:focus, .field textarea:focus,
.f input:focus, .f select:focus, .f textarea:focus {
  outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(46,95,163,.12);
}
.field-hint { font-size: .7rem; color: var(--text-muted); }
.field textarea { resize: vertical; min-height: 60px; }
.field input[readonly], .f input[readonly] { background: var(--bg); color: var(--text-muted); cursor: default; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .6rem; }
.grid4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: .6rem; }
.grid5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: .5rem; }

/* ---- BOTONES ----
   Área mínima de toque ~40-44px de alto (uso en tablet en mostrador). */
.btn-primary { background: var(--blue); color: #fff; border: none;
               border-radius: var(--radius-sm); padding: .65rem 1.1rem; min-height: 40px;
               font-size: .82rem; font-weight: 500; cursor: pointer;
               transition: var(--transition); font-family: inherit; }
.btn-primary:hover  { background: var(--navy); }
.btn-primary:active { transform: scale(.98); }
.btn-ghost { background: transparent; color: var(--blue);
             border: .5px solid var(--blue); border-radius: var(--radius-sm);
             padding: .6rem 1.1rem; min-height: 40px; font-size: .82rem; font-weight: 500;
             cursor: pointer; transition: var(--transition); font-family: inherit; }
.btn-ghost:hover { background: var(--blue-pale); }
.btn-danger { background: transparent; color: var(--red);
              border: .5px solid var(--red); border-radius: var(--radius-sm);
              padding: .6rem 1.1rem; min-height: 40px; font-size: .82rem; font-weight: 500;
              cursor: pointer; font-family: inherit; }
.btn-full { width: 100%; padding: .75rem; }
.btn-sm   { padding: .45rem .8rem; min-height: 34px; font-size: .75rem; }
.btn-icon { background: none; border: none; cursor: pointer; color: var(--blue);
            font-size: .75rem; padding: .3rem; min-width: 34px; min-height: 34px; }

/* ---- BADGES ---- */
.badge { display: inline-flex; align-items: center; padding: .25rem .65rem;
         border-radius: 20px; font-size: .72rem; font-weight: 500; white-space: nowrap; }
.badge-green  { background: var(--green-bg);  color: var(--green);  }
.badge-amber  { background: var(--amber-bg);  color: var(--amber);  }
.badge-red    { background: var(--red-bg);    color: var(--red);    }
.badge-blue   { background: var(--blue-pale); color: #185FA5;       }
.badge-gray   { background: #F1EFE8;          color: #5F5E5A;       }
.badge-purple { background: var(--purple-bg); color: var(--purple); }
.badge-navy   { background: var(--navy);      color: #fff;          }

/* Alias semánticos de estado (gris=normal, ámbar=atención, rojo=urgente).
   Preferir estos sobre badge-amber/red/gray directamente en código nuevo,
   para que el significado quede explícito en la marca. */
.badge-normal   { background: var(--sem-normal-bg);   color: var(--sem-normal);   }
.badge-atencion { background: var(--sem-atencion-bg); color: var(--sem-atencion); }
.badge-urgente  { background: var(--sem-urgente-bg);  color: var(--sem-urgente);  }

/* ---- ALERTAS ---- */
.alert { border-radius: var(--radius-sm); padding: .6rem .85rem;
         font-size: .8rem; margin-bottom: .75rem; }
.alert-error   { background: var(--red-bg);   color: var(--red);   border: .5px solid var(--red-bdr); }
.alert-success { background: var(--green-bg); color: var(--green); border: .5px solid var(--green-bdr); }
.alert-warning { background: var(--amber-bg); color: var(--amber); border: .5px solid var(--amber-bdr); }

/* ---- FILAS DE LISTA ---- */
.list-row { display: flex; align-items: center; gap: .6rem;
            background: var(--white); border-radius: var(--radius);
            padding: .65rem .85rem; margin-bottom: .4rem;
            border: .5px solid var(--border); cursor: pointer; transition: var(--transition); }
.list-row:hover { border-color: var(--blue); background: #FAFCFF; }
.list-row-info { flex: 1; }
.list-row-name { font-size: .85rem; font-weight: 500; color: var(--text); }
.list-row-meta { font-size: .72rem; color: var(--text-muted); margin-top: 1px; }

/* ---- AVATAR ---- */
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--blue-light);
          display: flex; align-items: center; justify-content: center;
          font-size: .75rem; font-weight: 600; color: #0C447C; flex-shrink: 0; }
.avatar-lg { width: 42px; height: 42px; font-size: .9rem; }

/* ---- TABS ---- */
.tab-row { display: flex; border-bottom: .5px solid var(--border); background: var(--white); }
.tab { flex: 1; padding: .55rem .3rem; font-size: .72rem; font-weight: 500;
       text-align: center; cursor: pointer; color: var(--text-muted);
       border-bottom: 2px solid transparent; transition: var(--transition);
       white-space: nowrap; }
.tab:hover  { color: var(--blue); }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ---- OJO ENCABEZADOS ---- */
.eye-hdr    { background: var(--blue-pale); border-radius: 6px; padding: .3rem .5rem;
              font-size: .7rem; font-weight: 600; color: #185FA5; margin-bottom: .5rem;
              text-align: center; }
.eye-hdr.oi { background: #EEF5E8; color: #3B6D11; }

/* ---- BARRA DE PROGRESO LAB ---- */
.progress-track { display: flex; align-items: center; margin: .6rem 0; }
.p-step  { display: flex; flex-direction: column; align-items: center; }
.p-dot   { width: 12px; height: 12px; border-radius: 50%; background: var(--border); flex-shrink: 0;
           box-sizing: border-box; transition: var(--transition); }
.p-dot.done { background: var(--green); }
.p-dot.now  { background: var(--blue); border: 3px solid var(--blue-light); box-shadow: 0 0 0 2px var(--blue); }
.p-line { flex: 1; height: 2px; background: var(--border); }
.p-line.done { background: var(--green); }
.p-lbl { font-size: .6rem; color: var(--text-muted); margin-top: 3px; text-align: center; }

/* ---- SECCIÓN TÍTULO ---- */
.sec-title { font-size: .7rem; font-weight: 600; color: var(--text-muted);
             letter-spacing: .04em; text-transform: uppercase; margin: .75rem 0 .4rem; }

/* ---- STATS ---- */
.stat-grid { display: grid; gap: .6rem; margin-bottom: .75rem; }
.stat-card { background: var(--white); border-radius: var(--radius);
             border: .5px solid var(--border); box-shadow: var(--shadow-card); padding: .9rem; }
.stat-icon { width: 30px; height: 30px; border-radius: 8px; display: flex;
             align-items: center; justify-content: center; margin-bottom: .55rem; font-size: 15px; }
.stat-icon.blue  { background: var(--blue-pale); color: #185FA5; }
.stat-icon.green { background: var(--green-bg);  color: var(--green); }
.stat-icon.amber { background: var(--amber-bg);  color: var(--amber); }
.stat-icon.red   { background: var(--red-bg);    color: var(--red);   }
.stat-val  { font-size: 1.35rem; font-weight: 500; color: var(--text); }
.stat-lbl  { font-size: .72rem; color: var(--text-muted); margin-top: 1px; }
.stat-val.green  { color: var(--green); }
.stat-val.amber  { color: var(--amber); }
.stat-val.red    { color: var(--red);   }
.stat-val.blue   { color: #185FA5;      }

/* ---- SALDO ---- */
.saldo-box { border-radius: var(--radius-sm); padding: .6rem .85rem;
             display: flex; align-items: center; justify-content: space-between; }
.saldo-ok   { background: var(--green-bg); border: .5px solid var(--green-bdr); }
.saldo-pend { background: var(--amber-bg); border: .5px solid var(--amber-bdr); }
.saldo-val  { font-size: 1.1rem; font-weight: 500; }
.saldo-lbl  { font-size: .68rem; font-weight: 600; }

/* ---- BARRAS RESUMEN ---- */
.bar-row { display: flex; align-items: center; gap: .5rem; margin-bottom: .4rem; }
.bar-name { font-size: .75rem; color: var(--text-light); width: 54px; flex-shrink: 0; }
.bar-track { flex: 1; height: 6px; background: var(--blue-pale); border-radius: 3px; overflow: hidden; }
.bar-fill  { height: 100%; border-radius: 3px; transition: width .4s ease; }
.bar-val   { font-size: .7rem; color: var(--text-muted); width: 32px; text-align: right; flex-shrink: 0; }

/* ---- TABLA PERMISOS ---- */
.perms-table { width: 100%; border-collapse: collapse; font-size: .78rem; }
.perms-table th { font-size: .68rem; font-weight: 600; color: var(--text-muted);
                  padding: .3rem .5rem; text-align: center; border-bottom: .5px solid var(--border); }
.perms-table th:first-child { text-align: left; }
.perms-table td { padding: .35rem .5rem; border-bottom: .5px solid var(--bg); }
.perms-table td:not(:first-child) { text-align: center; }
.check-yes { color: var(--green); font-size: 1rem; }
.check-no  { color: var(--red);   font-size: 1rem; }

/* ---- ESTADO VACÍO (positivo, en vez de espacio en blanco) ---- */
.empty-state { text-align: center; padding: 2rem 1rem; color: var(--sem-normal); }
.empty-state .empty-icon { font-size: 1.6rem; margin-bottom: .4rem; }
.empty-state .empty-msg  { font-size: .85rem; font-weight: 500; color: var(--text-light); }
.empty-state .empty-sub  { font-size: .75rem; color: var(--text-muted); margin-top: .2rem; }

/* ---- "NECESITA TU ATENCIÓN HOY" (dashboard priorizado) ---- */
.atencion-card { background: var(--sem-urgente-bg); border: 1px solid var(--sem-urgente-bdr);
                  border-radius: var(--radius); padding: .875rem; margin-bottom: .9rem; }
.atencion-card .ct { color: var(--sem-urgente); }
.atencion-row { display: flex; align-items: center; gap: .6rem;
                background: var(--white); border-radius: var(--radius-sm);
                padding: .6rem .75rem; margin-bottom: .4rem; cursor: pointer;
                text-decoration: none; transition: var(--transition); }
.atencion-row:last-child { margin-bottom: 0; }
.atencion-row:hover { border-color: var(--sem-urgente); }
.atencion-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--sem-urgente); flex-shrink: 0; }
.atencion-ok { text-align: center; padding: .5rem; font-size: .82rem;
               color: var(--green); font-weight: 500; }

/* ---- UTILITARIOS ---- */
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-center  { display: flex; align-items: center; }
.gap-sm { gap: .4rem; }
.gap-md { gap: .75rem; }
.mt-sm  { margin-top: .4rem; }
.mt-md  { margin-top: .75rem; }
.text-muted  { color: var(--text-muted); }
.text-small  { font-size: .75rem; }
.text-right  { text-align: right; }
.text-red    { color: var(--red); }
.text-green  { color: var(--green); }
.text-amber  { color: var(--amber); }
.text-blue   { color: #185FA5; }
.font-medium { font-weight: 500; }
.w-full { width: 100%; }

/* ---- RESPONSIVE iPad ---- */
@media (max-width: 768px) {
  .grid4 { grid-template-columns: 1fr 1fr; }
  .grid3 { grid-template-columns: 1fr 1fr; }
  .stat-grid.g4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  /* Teléfono: el sidebar con etiquetas es para tablet en mostrador;
     en pantallas angostas se colapsa a solo íconos para no robar contenido.
     Hay que pisar también "flex" (no solo "width"): el sidebar es un flex-item
     con flex-basis fijo en la regla base, y flex-basis le gana a width si no
     se sobreescribe igual aquí. */
  .sidebar { width: var(--sidebar-w-collapsed); flex: 0 0 var(--sidebar-w-collapsed); padding: .75rem .25rem; }
  .nav-item-lbl, .sidebar-group-lbl { display: none; }
  .nav-item { justify-content: center; padding: 0; }
}
@media (max-width: 480px) {
  .grid4, .grid3, .grid2 { grid-template-columns: 1fr; }
}
