
/* ── Theme variables ─────────────────────── */
:root {
  --bg-app: #f0f5f4;
  --bg-header: #eaefee;
  --bg-sidebar: #fafbfb;
  --bg-chat: #e4dcd4;
  --bg-input: #fafbfb;
  --bg-sent: #dbf8c6;
  --bg-received: #fafbfb;
  --bg-bot: #fff3cd;
  --bg-card: #fafbfb;
  --text-primary: #0e1a1a;
  --text-secondary: #2f3f3e;
  --text-muted: #5e706e;
  --border-color: #dce5e3;
  --accent: #0f766e;
  --accent-light: #14b8a6;
  --accent-dark: #0d5c56;
  --accent-green: #25D366;
  --hover-bg: #f5f6f6;
  --active-bg: #e8e8e8;
  --badge-bg: #e1f2fa;
  --badge-text: #000;
  --shadow: 0 1px 3px rgba(13,59,59,0.06), 0 2px 8px rgba(13,59,59,0.08);
  --shadow-lg: 0 4px 24px rgba(13,59,59,0.10), 0 2px 8px rgba(13,59,59,0.05);
  --input-border: #c0cec9;
  --scrollbar-color: rgba(0,0,0,0.15);
  --wa-bg: #dddbd1;
  --wa-teal: #00a884;
  --date-badge-bg: #e1f2fa;
  --icon-color: rgb(145,145,145);
  --read-blue: #0da9e5;
  --unread-badge: #25D366;

  /* Extended palette */
  --primary: #0f766e;
  --primary-light: #14b8a6;
  --primary-dark: #0d5c56;
  --secondary: #1e40af;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --surface: #fafbfb;
  --bg-page: #f0f5f4;
  --text-heading: #0e1a1a;
  --text-body: #2f3f3e;
  --border-light: #dce5e3;
  --border-medium: #c0cec9;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Component tokens (shadcn-style, additive) */
  --ring: rgba(15, 118, 110, 0.22);
  --shadow-xs: 0 1px 2px rgba(13, 59, 59, 0.05);

  /* Navbar */
  --nav-bg: #0f766e;
  --nav-text: #ffffff;
  --nav-btn: rgba(255,255,255,0.15);
  --nav-btn-hover: rgba(255,255,255,0.25);
  --nav-btn-active: rgba(255,255,255,0.3);
  --nav-shadow: 0 2px 12px rgba(0,0,0,0.15);
}
[data-theme="dark"] {
  --bg-app: #0f172a;
  --bg-header: #1e293b;
  --bg-sidebar: #1e293b;
  --bg-chat: #0b141a;
  --bg-input: #1e293b;
  --bg-sent: rgb(5, 97, 98);
  --bg-received: #1e293b;
  --bg-bot: rgb(42, 52, 43);
  --bg-card: #1e293b;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border-color: #334155;
  --accent: #14b8a6;
  --accent-light: #2dd4bf;
  --accent-dark: #0f766e;
  --accent-green: rgb(0, 175, 156);
  --hover-bg: rgba(255,255,255,0.05);
  --active-bg: rgba(255,255,255,0.08);
  --badge-bg: #1e3a5f;
  --badge-text: rgba(241, 241, 242, 0.92);
  --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 2px 8px rgba(0,0,0,0.2);
  --shadow-lg: 0 4px 24px rgba(0,0,0,0.3);
  --input-border: #334155;
  --scrollbar-color: rgba(255,255,255,0.15);
  --wa-bg: #090F13;
  --wa-teal: rgb(0, 175, 156);
  --date-badge-bg: rgb(30, 42, 48);
  --icon-color: rgb(166, 168, 170);
  --read-blue: #0da9e5;
  --unread-badge: rgb(0, 175, 156);

  /* Extended palette — dark */
  --primary: #14b8a6;
  --primary-light: #2dd4bf;
  --primary-dark: #0f766e;
  /* Texto sobre los fondos primarios. El blanco sobre #14b8a6 daba 2,4:1; el texto oscuro da 7:1
     y aguanta los hovers, que en oscuro aclaran. Solo en oscuro: en claro no existe y cada regla
     cae a su blanco de siempre (var(--on-primary, #fff)). */
  --on-primary: #0f172a;
  --secondary: #3b82f6;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --surface: #1e293b;
  --bg-page: #0f172a;
  --text-heading: #f1f5f9;
  --text-body: #cbd5e1;
  --border-light: #334155;
  --border-medium: #475569;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Component tokens (shadcn-style, additive) — dark */
  --ring: rgba(20, 184, 166, 0.35);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);

  /* Navbar — dark */
  --nav-bg: #1e293b;
  --nav-text: #f1f5f9;
  --nav-btn: rgba(255,255,255,0.08);
  --nav-btn-hover: rgba(255,255,255,0.12);
  --nav-btn-active: rgba(255,255,255,0.18);
  --nav-shadow: 0 2px 12px rgba(0,0,0,0.4);
}


/* ── Navbar ─────────────────────── */
.main-nav { background: var(--nav-bg); box-shadow: var(--nav-shadow); position: sticky; top: 0; z-index: 100; }
.nav-inner { max-width: 1400px; margin: 0 auto; display: flex; align-items: center; padding: 0 24px; height: 56px; gap: 16px; }
.nav-brand { display: flex; align-items: center; flex-shrink: 0; }
.nav-clinic { font-size: 1rem; font-weight: 700; color: var(--nav-text); letter-spacing: -0.3px; }
.nav-links { display: flex; align-items: center; gap: 20px; margin-left: 32px; min-width: 0; } /* red en todos los anchos (antes ≤1090; Gate B #341, 15/10): */
.nav-links-scroll { display: flex; align-items: center; gap: 20px; min-width: 0; overflow-x: auto; } /* si no entra, la fila se desliza y la página no scrollea */
.nav-link { color: var(--nav-text); text-decoration: none; font-size: 0.84rem; font-weight: 500; border: none; background: none; cursor: pointer; padding: 4px 0; border-bottom: 2px solid transparent; transition: all 0.15s ease; white-space: nowrap; opacity: 0.8; }
.nav-link:hover { opacity: 1; border-bottom-color: rgba(255,255,255,0.5); }
.nav-link-active { opacity: 1; font-weight: 700; border-bottom-color: var(--nav-text); }
.nav-logout { opacity: 0.7; font-size: 0.82rem; }
.nav-logout:hover { opacity: 1; color: #fca5a5; }
.nav-right { margin-left: auto; display: flex; align-items: center; gap: 16px; flex-shrink: 0; }
/* El nombre se corta con elipsis en todos los anchos: con un nombre de 40 letras,
   «No disponible» y «Activar avisos», la barra pedía 1306 px a 1280 (QA 9/10). */
.nav-user { color: var(--nav-text); font-size: 0.82rem; font-weight: 600; text-decoration: none; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-profile-link:hover { opacity: 0.8; text-decoration: underline; }
/* Plan 121: «No disponible» fuera de /chat */
.nav-nodisp { color: var(--nav-text); font-size: 0.75rem; font-weight: 600; text-decoration: none; white-space: nowrap; padding: 2px 8px; border: 1px dashed rgba(255,255,255,0.5); border-radius: 10px; opacity: 0.85; }
.nav-nodisp:hover { opacity: 1; }

/* Badge de derivaciones pendientes (lo puebla updateDerivBadge del JS compartido) */
.nav-badge { display: inline-block; min-width: 18px; margin-left: 6px; padding: 1px 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 0.68rem; font-weight: 700; text-align: center; line-height: 1.5; }
.nav-badge[hidden] { display: none; }

/* Dropdown "Gestión" — agrupa herramientas de admin */
.nav-dropdown { position: relative; display: inline-flex; }
.nav-dropdown-trigger { display: inline-flex; align-items: center; gap: 4px; }
.nav-caret { font-size: 0.65rem; transition: transform 0.15s ease; opacity: 0.9; }
.nav-dropdown.open .nav-caret { transform: rotate(180deg); }
.nav-dropdown-menu {
  position: absolute; top: calc(100% + 12px); left: 0; min-width: 184px;
  background: var(--surface); border: 1px solid var(--border-light);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
  padding: 6px; display: none; flex-direction: column; gap: 2px; z-index: 200;
}
.nav-dropdown.open .nav-dropdown-menu { display: flex; animation: navMenuIn 0.14s ease; }
@keyframes navMenuIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.nav-dropdown-item {
  color: var(--text-body); text-decoration: none; font-size: 0.84rem; font-weight: 500;
  padding: 8px 12px; border-radius: var(--radius-sm); white-space: nowrap; opacity: 1;
  border: none; transition: background 0.12s ease, color 0.12s ease;
}
.nav-dropdown-item:hover { background: var(--hover-bg); color: var(--text-heading); }
.nav-dropdown-item-active { background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); font-weight: 600; }
/* Fuera de 769-1090 px el link secundario está en la fila: su copia del menú no se ve. */
.nav-sec-menu { display: none; }

@media (max-width: 768px) {
  .nav-inner { padding: 0 12px; gap: 8px; height: 50px; }
  /* min-width: 0 — como flex item, .nav-links no bajaba de su contenido y el
     overflow-x de .nav-links-scroll nunca actuaba: a 375 px la barra del admin
     medía 443 y empujaba Salir y toda la página hacia la derecha. */
  .nav-links { gap: 12px; margin-left: 12px; min-width: 0; }
  .nav-links-scroll { gap: 12px; overflow-x: auto; }
  .nav-link { font-size: 0.75rem; }
  .nav-clinic { display: none; }
  .nav-user { display: none; }
  .nav-nodisp-txt { display: none; } /* plan 121: en el celular, solo el ⚪ */
  .nav-dropdown-menu { right: 0; left: auto; }
}

/* 769-1090 px: la barra del admin desbordaba y la página crecía a la derecha.
   A 794 px .nav-inner mide 788 y el contenido pedía 851 (marca 221, links 392,
   derecha ~120, gaps y padding); con nombre largo y «Activar avisos», o con el
   texto de «No disponible», 1090. Los links secundarios del admin pasan a
   «Gestión» (.nav-sec / .nav-sec-menu), la fila se compacta, el nombre se
   corta, «No disponible» queda en el ⚪ (con su title, como en el celular) y,
   como red, el mismo par del celular (PR #95): si igual sobra, la fila se
   desliza adentro de la barra. */
@media (min-width: 769px) and (max-width: 1090px) {
  .nav-sec { display: none; }
  .nav-sec-menu { display: block; }
  .nav-links { margin-left: 12px; gap: 12px; min-width: 0; }
  .nav-links-scroll { gap: 12px; overflow-x: auto; }
  .nav-user { max-width: 100px; }
  /* La marca también se acorta: a 794 con todo visible la fila de links quedaba en 40 px. */
  .nav-clinic { display: block; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .nav-nodisp-txt { display: none; }
}
/* Mejora #340: «Avisos desactivados» mide 41 px más que «Activar avisos». Con nombre
   largo y «No disponible», la barra del admin ya pedía hasta 1192 px y pasó a 1234
   (QA 15/10). Entre 1091 y 1240 se compacta solo la derecha, como en tablet (nombre
   corto, «No disponible» en el ⚪): los links y «Gestión» quedan como están. */
@media (min-width: 1091px) and (max-width: 1240px) {
  .nav-user { max-width: 100px; }
  .nav-nodisp-txt { display: none; }
}
