:root {
  /* Marca NuFlow (estilo visual; CEMESA sigue siendo la marca visible) */
  --verde: #0671c6;        /* Azul Profundo — acción primaria (AA sobre blanco) */
  --verde-osc: #033863;    /* Azul Oscuro — fin del degradado del topbar / hover */
  --verde-700: #02325c;    /* navy más oscuro */
  --verde-topbar: #0671c6; /* inicio del degradado del topbar */
  --aqua: #03cdd3;         /* Aqua Brillante — acento decorativo (no texto/contornos) */
  --teal: #0E7490;         /* acento accesible (AA): foco, "Programada", hoy, spinner */
  --naranja: #B45309;
  --naranja-bg: #FDF0DC;

  /* Rampa neutral (gris verde-frío) */
  --n-0: #ffffff;
  --n-50: #f6f8f6;
  --n-100: #eef2ef;
  --n-200: #e2e8e3;
  --n-300: #cdd6cf;
  --n-500: #6b7770;
  --n-700: #3a443d;
  --n-900: #18211b;

  /* Estados (verde + teal + rojo + naranja: on-brand y distintos) */
  --st-prog: #0E7490;   --st-prog-bg: #E0F2F4;   /* Programada = teal */
  --st-done: #15803D;   --st-done-bg: #DEF3E3;   /* Realizada  = verde */
  --st-cancel: #B3261E; --st-cancel-bg: #FBEAE9; /* Cancelada  = rojo */
  --st-noshow: #B45309; --st-noshow-bg: #FDF0DC; /* No asistió = naranja */

  /* Aliases sobre la rampa */
  --bg: var(--n-50);
  --card: var(--n-0);
  --ink: var(--n-900);
  --muted: var(--n-500);
  --line: var(--n-200);
  --danger: var(--st-cancel);

  --radius: 14px;
  --radius-sm: 10px;
  --tap: 48px;

  /* Elevación */
  --shadow-sm: 0 1px 2px rgba(2, 17, 31, 0.06), 0 1px 3px rgba(2, 17, 31, 0.05);
  --shadow-md: 0 2px 8px rgba(2, 17, 31, 0.08), 0 4px 16px rgba(2, 17, 31, 0.04);
  --shadow-lg: 0 8px 24px rgba(2, 17, 31, 0.12);

  font-family: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.4;
}

/* Foco visible global (teclado) */
:where(button, a, [tabindex], input, select, textarea):focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: 2px;
  border-radius: 6px;
}

/* Topbar */
.topbar {
  background: linear-gradient(180deg, var(--verde-topbar) 0%, var(--verde-osc) 100%);
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 14px) 16px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.06), var(--shadow-sm);
}
.topbar__brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar__logo {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: #fff;
  padding: 3px;
  object-fit: contain;
  flex: none;
  box-shadow: var(--shadow-sm);
}
.topbar h1 { font-size: 1.25rem; margin: 0; font-weight: 800; letter-spacing: -0.01em; }
.topbar__sub { margin: 2px 0 0; font-size: 0.78rem; opacity: 0.9; font-weight: 500; }
.chip {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.8rem;
  white-space: nowrap;
  max-width: 38vw;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: none;
}
/* El chip del nombre es un botón (abre el menú de cuenta): quita el look nativo
   y agrega afordancia de clic. */
.chip--btn { border: 0; color: inherit; font: inherit; cursor: pointer; transition: background-color 0.15s; }
.chip--btn:hover { background: rgba(255, 255, 255, 0.3); }
/* Menú sin ítems (móvil/modo sesión): el chip queda como etiqueta informativa. */
.chip--btn:disabled { cursor: default; pointer-events: none; }

/* Banner */
.banner {
  margin: 12px 16px 0;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 0.95rem;
}
.banner--error { background: #fbeae9; color: var(--danger); border: 1px solid #f3c9c6; }
/* Aviso de instalación PWA (teléfono en navegador, no standalone). */
.banner--install { display: flex; align-items: center; gap: 10px; background: #eaf4ef; color: var(--verde-osc); border: 1px solid #cfe5d8; }
.banner--install[hidden] { display: none; }
.banner__close { flex: none; margin-left: auto; border: 0; background: transparent; font: inherit; cursor: pointer; color: inherit; }

/* Screen */
.screen { padding: 16px 16px 120px; max-width: 720px; margin: 0 auto; }
/* La vista "Mes" con bloques aprovecha el ancho del escritorio; las demás vistas
   (Día/Próximas) mantienen la columna de 720px. En móvil no cambia nada. */
@media (min-width: 760px) {
  .screen--wide { max-width: 1100px; }
}

.daybar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.daybar__label { font-weight: 600; color: var(--muted); }
.daybar__input {
  flex: 1;
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  font-size: 1rem;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  background: var(--card);
  color: var(--ink);
}

/* View tabs */
.viewtabs {
  display: flex;
  gap: 6px;
  background: var(--n-100);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 14px;
}
.viewtab {
  flex: 1;
  min-height: 42px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.viewtab--active { background: var(--card); color: var(--verde-osc); box-shadow: var(--shadow-sm); }
.daybar[hidden] { display: none; }

/* Vista mensual + selector de fecha del formulario */
.monthview[hidden] { display: none; }
.list[hidden] { display: none; }

.cal-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.cal-nav__label {
  flex: 1;
  text-align: center;
  font-weight: 800;
  font-size: 1.02rem;
}
.cal-nav__arrow {
  width: 40px; height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--ink);
  font-size: 1.4rem;
  line-height: 1;
  font-family: inherit;
  cursor: pointer;
}

.cal {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal__dow {
  text-align: center;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  padding-bottom: 4px;
}
.cal__cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-height: 52px;
  padding: 5px 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--ink);
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.cal__cell--out {
  border-color: transparent;
  background: transparent;
  color: var(--n-300);
  cursor: default;
  justify-content: flex-start;
}
.cal__cell--today { border-color: var(--teal); }
.cal__cell--selected { background: var(--st-done-bg); border-color: var(--st-done); }
/* Día sin atención del calendario activo (openHours) en el selector del
   formulario: apagado y no clickeable. */
.cal__cell--closed {
  background: var(--n-100);
  border-color: transparent;
  color: var(--n-300);
  cursor: not-allowed;
}
.cal__cell--closed .cal__num { text-decoration: line-through; text-decoration-color: var(--n-300); }
.cal__cell--has { font-weight: 700; }
.cal__num { font-size: 0.92rem; line-height: 1; margin-top: 2px; }
.cal__count {
  font-size: 0.62rem;
  font-weight: 800;
  color: var(--muted);
  line-height: 1;
}
.cal__dots { display: flex; gap: 2px; min-height: 6px; }
.cal__dot { width: 5px; height: 5px; border-radius: 50%; }
.cal__dot--prog { background: var(--st-prog); }
.cal__dot--done { background: var(--st-done); }
.cal__dot--cancel { background: var(--st-cancel); }
.cal__dot--noshow { background: var(--st-noshow); }

/* Vista "Mes" con bloques de cita titulados (cal--events). Celdas más altas,
   encabezado que abre el día y chips clickeables por visita. El selector del
   formulario (.calpicker, sin cal--events) conserva las celdas compactas. */
/* minmax(0, 1fr) + min-width:0 let the columns/chips shrink and ellipsize instead
   of forcing horizontal overflow when a cell holds text (the default 1fr track has
   a content-based minimum). */
.cal--events { gap: 5px; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal--events .cal__cell {
  min-height: 92px;
  min-width: 0;
  align-items: stretch;
  justify-content: flex-start;
  gap: 4px;
  padding: 4px;
  cursor: default;
}
.cal--events .cal__open {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 28px;
  padding: 2px 4px;
  border: none;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  cursor: pointer;
}
.cal--events .cal__num { margin-top: 0; }
.cal--events .cal__cell--today .cal__num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--teal);
  color: #fff;
  font-weight: 800;
}
.cal--events .cal__cell--today { border-color: var(--teal); }

.cal__chips { display: flex; flex-direction: column; gap: 3px; overflow: hidden; }
.cal__chip {
  display: flex;
  align-items: baseline;
  gap: 4px;
  width: 100%;
  min-height: 24px;
  padding: 2px 6px;
  border: none;
  border-left: 3px solid var(--st-prog);
  border-radius: 6px;
  background: var(--st-prog-bg);
  color: var(--st-prog);
  font-family: inherit;
  font-size: 0.74rem;
  line-height: 1.2;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
}
.cal__chiptime { font-weight: 800; font-variant-numeric: tabular-nums; flex: none; }
.cal__chipname {
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.cal__chip--done   { border-left-color: var(--st-done);   background: var(--st-done-bg);   color: var(--st-done); }
.cal__chip--cancel { border-left-color: var(--st-cancel); background: var(--st-cancel-bg); color: var(--st-cancel); opacity: 0.78; }
.cal__chip--cancel .cal__chipname { text-decoration: line-through; text-decoration-color: var(--n-300); }
.cal__chip--noshow { border-left-color: var(--st-noshow); background: var(--st-noshow-bg); color: var(--st-noshow); }
.cal__more {
  border: none;
  background: transparent;
  padding: 1px 6px;
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
}
.cal__more:hover { color: var(--ink); }

/* Selector de fecha embebido en el formulario */
.calpicker {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--n-50);
  padding: 12px;
}
.calpicker .cal-nav { margin-bottom: 10px; }
.calpicker .cal__cell { min-height: 44px; }

/* Slots de hora (cascada fecha -> hora) */
.slots[data-empty] .slots__hint { display: block; }
.slots__hint {
  margin: 0;
  padding: 14px;
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.slots__group {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin: 12px 2px 6px;
}
.slots__group:first-child { margin-top: 0; }
.slots__row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(82px, 1fr));
  gap: 6px;
}
.slot {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.slot:disabled { opacity: 0.38; cursor: not-allowed; text-decoration: line-through; }
/* Slot ya reservado en un calendario de 1 cita por slot. Se distingue del
   "pasado" (gris tenue): rojo legible, sin tachado, sin atenuar. */
.slot--blocked:disabled {
  opacity: 1;
  background: #fdeaea;
  border-color: var(--st-cancel);
  color: var(--st-cancel);
  text-decoration: none;
  cursor: not-allowed;
}
.slot--active {
  background: var(--verde);
  border-color: var(--verde);
  color: #fff;
  font-weight: 700;
}

/* Resumen del día */
.summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.summary__stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.summary__stat--zero { opacity: 0.55; }
.summary__num { font-size: 1.25rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.summary__lbl {
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-top: 4px;
}
/* Etiqueta completa en escritorio; la corta solo bajo el breakpoint móvil. */
.summary__lbl--short { display: none; }
.summary__stat--prog   .summary__num { color: var(--st-prog); }
.summary__stat--done   .summary__num { color: var(--st-done); }
.summary__stat--cancel .summary__num { color: var(--st-cancel); }
.summary__stat--noshow .summary__num { color: var(--st-noshow); }

/* Day group headers */
.dayhead {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: 0.02em;
  text-transform: capitalize;
  margin: 16px 2px 8px;
}
.dayhead:first-child { margin-top: 0; }

/* List */
.list { display: flex; flex-direction: column; gap: 10px; }
.visit {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--st-prog);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow 0.18s ease, transform 0.18s ease;
}
.visit:active { transform: scale(0.99); }
@media (hover: hover) {
  .visit:has(.visit__open:hover) { box-shadow: var(--shadow-md); }
}
.visit__open {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 14px;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

/* Bloque de hora teñido por estado (fuente de verdad del color) */
.visit__time {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 62px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: var(--st-prog-bg);
  color: var(--st-prog);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.visit__time b { font-size: 1.05rem; font-weight: 800; }
.visit__time small {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.85;
}

.visit__main { min-width: 0; }
.visit__name {
  font-weight: 700;
  font-size: 1.02rem;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.visit__sub {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Variantes por estado */
.visit--showed    { border-left-color: var(--st-done); }
.visit--showed   .visit__time { background: var(--st-done-bg);   color: var(--st-done); }
.visit--cancelled { border-left-color: var(--st-cancel); opacity: 0.72; }
.visit--cancelled .visit__time { background: var(--st-cancel-bg); color: var(--st-cancel); }
.visit--cancelled .visit__name { text-decoration: line-through; text-decoration-color: var(--n-300); }
.visit--noshow    { border-left-color: var(--st-noshow); }
.visit--noshow   .visit__time { background: var(--st-noshow-bg); color: var(--st-noshow); }

.visit__actions {
  display: flex;
  gap: 8px;
  padding: 0 14px 12px;
}
.chipbtn {
  flex: 1;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--st-done-bg);
  color: var(--st-done);
  font-size: 0.85rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
.chipbtn:disabled { opacity: 0.5; cursor: progress; }
.chipbtn--danger { background: var(--st-cancel-bg); color: var(--st-cancel); }

.badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 9px 4px 8px;
  border-radius: 999px;
  background: var(--st-prog-bg);
  color: var(--st-prog);
  white-space: nowrap;
}
.badge::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
  margin-right: 6px;
  vertical-align: middle;
}
.badge--cancelled { background: var(--st-cancel-bg); color: var(--st-cancel); }
.badge--showed { background: var(--st-done-bg); color: var(--st-done); }
.badge--noshow { background: var(--st-noshow-bg); color: var(--st-noshow); }

/* Línea de tiempo por hora (vista "Día") */
.timeline { display: flex; flex-direction: column; margin-top: 4px; }
.timeline__row {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 10px;
  align-items: start;
  border-top: 1px solid var(--line);
  padding: 7px 0;
  min-height: 50px;
}
.timeline__row:last-child { border-bottom: 1px solid var(--line); }
.timeline__label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-align: right;
  padding-top: 6px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.timeline__band { display: flex; flex-direction: column; gap: 8px; min-width: 0; }

/* Cita en el rail: pill de una línea (la franja izq. + tinte codifican el estado) */
.tlevent {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--st-prog);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow 0.18s ease;
}
@media (hover: hover) {
  .tlevent:has(.tlevent__open:hover) { box-shadow: var(--shadow-md); }
}
.tlevent__open {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 10px 12px;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
/* Wraps instead of truncating: 1 line where it fits (desktop), graceful wrap on
   narrow screens so the patient name + motivo are never clipped. */
.tlevent__line {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.35;
}
.tlevent__time { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--ink); white-space: nowrap; }
.tlevent__name { font-weight: 700; color: var(--ink); margin-left: 6px; }
.tlevent__motivo { color: var(--muted); font-weight: 400; }
.tlevent .badge { flex-shrink: 0; margin-top: 1px; }
.tlevent .visit__actions { padding: 0 10px 10px; }

.tlevent--showed    { background: var(--st-done-bg);   border-left-color: var(--st-done); }
.tlevent--cancelled { background: var(--st-cancel-bg); border-left-color: var(--st-cancel); opacity: 0.72; }
.tlevent--cancelled .tlevent__name,
.tlevent--cancelled .tlevent__time { text-decoration: line-through; text-decoration-color: var(--n-300); }
.tlevent--noshow    { background: var(--st-noshow-bg); border-left-color: var(--st-noshow); }

/* Empty / loading / error states */
.state {
  text-align: center;
  color: var(--muted);
  padding: 48px 20px;
}
.state__big { font-size: 1.05rem; color: var(--ink); margin-bottom: 6px; font-weight: 600; }

/* Skeleton */
.skeleton { display: flex; flex-direction: column; gap: 10px; }
.sk-card {
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 12px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--n-200);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}
.sk-block { height: 42px; width: 62px; border-radius: var(--radius-sm); background: var(--n-100); }
.sk-line {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--n-100) 25%, var(--n-200) 37%, var(--n-100) 63%);
  background-size: 400% 100%;
  animation: sk 1.4s ease infinite;
}
.sk-name { width: 60%; }
.sk-sub { width: 40%; margin-top: 8px; }
@keyframes sk { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* Buttons */
.btn {
  min-height: var(--tap);
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  padding: 0 18px;
  cursor: pointer;
}
.btn--primary { background: var(--verde); color: #fff; }
.btn--primary:disabled { background: #9cc3e8; cursor: progress; }
.btn--ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn--lg { width: 100%; min-height: 54px; font-size: 1.08rem; }

.fab {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  max-width: 688px;
  margin: 0 auto;
  min-height: 56px;
  background: var(--verde);
  color: #fff;
  border: none;
  border-radius: 999px;
  font-size: 1.1rem;
  font-weight: 800;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 8px 24px rgba(6, 113, 198, 0.32);
  cursor: pointer;
  z-index: 15;
}
.fab[hidden] { display: none; }
.fab__plus { font-size: 1.5rem; line-height: 1; }

/* Sheet / dialog */
.sheet {
  border: none;
  padding: 0;
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  border-radius: 18px 18px 0 0;
  margin: auto auto 0;
  background: var(--card);
  color: var(--ink);
}
.sheet[open] { animation: sheetUp 0.26s cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes sheetUp {
  from { transform: translateY(16px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}
.sheet::backdrop { background: rgba(2, 17, 31, 0.5); }
.sheet__body { padding: 6px 18px calc(env(safe-area-inset-bottom) + 18px); overflow-y: auto; max-height: 92vh; }
/* Drag-handle */
.sheet__body::before {
  content: "";
  display: block;
  width: 36px; height: 4px;
  border-radius: 999px;
  background: var(--n-300);
  margin: 6px auto 14px;
}
.sheet__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet__head h2 { margin: 0; font-size: 1.2rem; font-weight: 800; }
.sheet__head-actions { display: flex; align-items: center; gap: 6px; }
.btn--sm { min-height: 38px; padding: 0 14px; font-size: 0.9rem; }
.sheet__foot {
  position: sticky;
  bottom: 0;
  background: var(--card);
  padding-top: 12px;
  margin-top: 18px;
  box-shadow: 0 -8px 16px -8px rgba(0, 0, 0, 0.08);
}

/* --- Wizard registrar visita (punto de ajuste: ref visual app-clinicas-saas-flow) ---
   Todo el look del wizard vive acá + los labels del <ol id="wizardProgress"> en
   index.html + los textos de public/wizard.js. Ajustar solo esto al llegar la
   referencia visual; la estructura (pasos, navegación) no cambia. */
.wizstep[hidden] { display: none; }
.wizprogress {
  display: flex;
  list-style: none;
  margin: 4px 0 16px;
  padding: 0;
  gap: 6px;
}
.wizprogress[hidden] { display: none; }
.wizprogress li {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
}
.wizprogress__num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--n-100);
  color: var(--muted);
  font-size: 0.85rem;
  border: 2px solid transparent;
}
.wizprogress__step--active .wizprogress__num {
  background: var(--verde);
  color: #fff;
}
.wizprogress__step--active { color: var(--verde-osc, var(--verde)); }
.wizprogress__step--done .wizprogress__num {
  background: #fff;
  color: var(--verde);
  border-color: var(--verde);
}
.wizsummary { margin-bottom: 6px; }
.wizsummary[hidden] { display: none; }
.wizsummary dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  margin: 0;
  background: var(--n-100);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.wizsummary dt { font-weight: 800; color: var(--muted); font-size: 0.82rem; }
.wizsummary dd { margin: 0; font-weight: 600; }
/* Los botones son .btn--lg (width:100%); acá se resetea a auto para que el flex
   reparta el ancho — si no, "Atrás" (flex-basis:auto → 100%) reclama toda la
   fila y empuja a "Siguiente"/"Guardar" fuera con scroll horizontal. */
.sheet__foot--wizard { display: flex; gap: 10px; }
.sheet__foot--wizard .btn { width: auto; flex: 1 1 0; min-width: 0; }
.sheet__foot--wizard #wizardBack { flex: 0 0 auto; }
.iconbtn {
  width: var(--tap); height: var(--tap);
  border: none; background: transparent;
  font-size: 1.2rem; cursor: pointer; color: var(--muted);
  border-radius: 50%;
}

/* Fields */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field[hidden] { display: none; }
.field > span, .field__label { font-weight: 600; font-size: 0.9rem; color: var(--muted); }
.field__opt { font-weight: 400; color: var(--muted); opacity: 0.8; }
.field input, .field textarea, .field select {
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}
.field select { appearance: none; -webkit-appearance: none; }
.field textarea { min-height: auto; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus {
  outline: 2px solid var(--teal);
  border-color: var(--teal);
}
.field input:disabled { background: var(--n-100); color: var(--muted); }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.field [type=date], .field [type=time] { font-variant-numeric: tabular-nums; }

/* Contact search suggestions */
.field--search { position: relative; }
.suggest {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 5;
  margin-top: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  max-height: 240px;
  overflow-y: auto;
}
.suggest[hidden] { display: none; }
.suggest__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.suggest__item:last-child { border-bottom: none; }
.suggest__item:hover { background: var(--n-100); }
.suggest__name { font-weight: 600; color: var(--ink); }
.suggest__meta { font-size: 0.82rem; color: var(--muted); }

/* Chips de exámenes (formulario de Radiología). Scoped a .chips para no pisar
   el .chip del topbar (#agentChip). */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips[hidden] { display: none; }
.chips .chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: none;
  background: var(--n-100);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 6px 6px 12px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink);
}
.chip__label { line-height: 1.2; }
.chip__remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
}
.chip__remove:hover { background: var(--danger); color: #fff; }

.formerror { color: var(--danger); font-size: 0.9rem; margin: 0 0 8px; }

/* Detail */
.detail-meta { background: var(--n-50); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 18px; }
.detail-meta dt { font-size: 0.78rem; color: var(--muted); font-weight: 700; }
.detail-meta dd { margin: 0 0 10px; }
.detail-meta dd:last-child { margin-bottom: 0; }

.thread__title { font-size: 1rem; margin: 0 0 10px; font-weight: 800; }
.thread { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.bubble { background: var(--n-100); border-radius: 12px; padding: 10px 12px; }
.bubble__head { display: flex; justify-content: space-between; gap: 8px; font-size: 0.78rem; color: var(--muted); margin-bottom: 3px; }
.bubble__author { font-weight: 700; color: var(--verde-osc); }
.bubble__body { white-space: pre-wrap; word-break: break-word; }

.comment-form { display: flex; flex-direction: column; gap: 8px; }
.comment-form textarea {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 88px);
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 0.92rem;
  box-shadow: var(--shadow-lg);
  z-index: 30;
  max-width: 90vw;
  text-align: center;
  animation: toastIn 0.22s ease-out;
}
@keyframes toastIn { from { transform: translate(-50%, 8px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
.toast[hidden] { display: none; }
.toast--error { background: var(--danger); }

.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--verde);
  border-radius: 50%;
  margin: 0 auto;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Login (app móvil standalone) ----------------------------------------- */
.login {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top) + 24px) 20px calc(env(safe-area-inset-bottom) + 24px);
  background: linear-gradient(180deg, var(--verde-topbar) 0%, var(--verde-osc) 100%);
}
.login[hidden] { display: none; }
.login__card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 28px 22px 24px;
  text-align: center;
}
.login__logo {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: #fff;
  padding: 4px;
  object-fit: contain;
  box-shadow: var(--shadow-sm);
}
.login__title { margin: 14px 0 4px; font-size: 1.35rem; font-weight: 800; letter-spacing: -0.01em; }
.login__sub { margin: 0 0 20px; color: var(--muted); font-size: 0.95rem; }
.login__form { text-align: left; }
.login__form .btn { width: 100%; margin-top: 6px; }

/* --- Calendar tabs (calendario activo + cambio entre los asignados) ------- */
.calbar {
  margin-bottom: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-sm);
}
.calbar[hidden] { display: none; }

/* --- Selector de grupo (Área) --------------------------------------------- */
/* Reusa el look de la calbar; se muestra solo cuando el agente pertenece a 2+
   grupos. Con un solo grupo queda oculto y la UI es idéntica a la de un grupo. */
.groupbar {
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.groupbar[hidden] { display: none; }
.groupswitch {
  display: flex;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}
/* Cada pill es un wrapper (botón de selección + botón ★): un <button> no puede
   contener otro. El chrome del pill vive en el wrapper. */
.groupswitch__item {
  display: inline-flex;
  align-items: center;
  flex: none;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
}
.groupswitch__item--active {
  background: var(--verde-osc, var(--verde));
  border-color: var(--verde-osc, var(--verde));
}
.groupswitch__pill {
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0 4px 0 16px;
  min-height: 34px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--muted);
  white-space: nowrap;
}
.groupswitch__item--active .groupswitch__pill { color: #fff; }
.groupswitch__pin {
  border: none;
  background: transparent;
  cursor: pointer;
  min-height: 34px;
  padding: 0 10px 0 2px;
  font-size: 0.95rem;
  line-height: 1;
  color: var(--n-300);
}
.groupswitch__pin--on { color: var(--naranja); }
.groupswitch__item--active .groupswitch__pin { color: rgba(255, 255, 255, 0.65); }
.groupswitch__item--active .groupswitch__pin--on { color: #ffd479; }
.calbar__label {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  flex: none;
}
.calswitch {
  display: flex;
  gap: 6px;
  background: var(--n-100);
  border-radius: 999px;
  padding: 4px;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  /* Safety net for the ≤4 inline case: if long names overflow the row, a thin
     scrollbar appears (it used to be hidden, so calendars scrolled off invisibly).
     The 5+ case uses the searchable palette below instead. */
  scrollbar-width: thin;
}
.calswitch::-webkit-scrollbar { height: 6px; }
.calswitch::-webkit-scrollbar-thumb { background: var(--n-300); border-radius: 999px; }
.calswitch[hidden] { display: none; }
.calswitch__pill {
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 999px;
  padding: 0 16px;
  min-height: 38px;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
  flex: 1 1 auto;
}
.calswitch__pill--active {
  background: var(--verde);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.calswitch__pill--single {
  background: var(--card);
  color: var(--verde-osc);
  cursor: default;
}

/* --- Freshness stamp + manual refresh ------------------------------------- */
/* La calbar NO envuelve (nowrap default): con nombres de calendario largos el
   selector encoge/ellipsa y el ⟳ queda fijo en su fila — nunca baja a una
   segunda línea. Los hijos flexibles ya absorben el shrink (.calswitch con
   overflow-x, .calselect con ellipsis). */
.calbar__fresh {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: none;
  margin-left: auto;
}
.freshstamp {
  font-size: 0.74rem;
  color: var(--muted);
  white-space: nowrap;
}
.freshstamp--stale { color: var(--naranja); font-weight: 700; }
.iconbtn--refresh { flex: none; font-size: 1.15rem; }
.iconbtn--refresh:hover { background: var(--n-100); }
.iconbtn--spinning { cursor: progress; }
.iconbtn__ico { display: inline-block; line-height: 1; }
.iconbtn--spinning .iconbtn__ico { animation: spin 0.8s linear infinite; }

/* --- Scalable calendar selector (5+ -> searchable command palette) -------- */
/* min-width fijo: el dropdown nunca colapsa por debajo de un ancho útil, pero
   flex:1 lo expande en pantallas grandes; el nombre largo ellipsa (__current). */
.calselect { position: relative; flex: 1 1 auto; min-width: 170px; }
.calselect__trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 14px;
  background: var(--n-100);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
}
.calselect__current { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.calselect__caret { color: var(--muted); flex: none; }
.calselect__panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  max-height: 340px;
  padding: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.calselect__search {
  width: 100%;
  min-height: 44px;
  margin-bottom: 6px;
  padding: 0 12px;
  background: var(--n-50);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--ink);
}
.calselect__list { overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.calselect__opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 6px 0 12px;
  border-radius: var(--radius-sm);
  color: var(--ink);
  cursor: pointer;
}
.calselect__opt--active { background: var(--n-100); }
.calselect__opt--selected { font-weight: 700; color: var(--verde-osc); }
.calselect__opt--selected .calselect__optname::before { content: '✓ '; color: var(--verde); }
.calselect__optname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.calselect__pin {
  flex: none;
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  font-size: 1.05rem;
  line-height: 1;
  color: var(--n-300);
  border-radius: 8px;
  cursor: pointer;
}
.calselect__pin--on { color: var(--naranja); }
.calselect__pin:hover { background: var(--n-100); }
.calselect__empty { padding: 14px 12px; color: var(--muted); font-size: 0.9rem; text-align: center; }

/* Botón de cerrar sesión en el header */
.iconbtn--logout { color: #fff; flex: none; }
.iconbtn--logout:hover { background: rgba(255, 255, 255, 0.16); }

/* El header se ocultaba/mostraba con [hidden]; .topbar fija display, así que
   necesita su propia regla. Permitir que el switcher baje de línea en pantallas
   angostas. */
.topbar { flex-wrap: wrap; }
.topbar[hidden] { display: none; }

@media (min-width: 700px) {
  .sheet { border-radius: 18px; margin: auto; }
}

/* Respeto a usuarios que reducen movimiento */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- Pre-registro (link firmado para pacientes) --- */
.prereg__hint { color: var(--muted, #5b7185); font-size: .92rem; margin: 0 0 10px; }
/* Pasos de instalación PWA en el diálogo "Instalar la app en tu teléfono". */
.prereg__steps { margin: 0 0 12px; padding-left: 20px; font-size: .92rem; display: flex; flex-direction: column; gap: 6px; }
.prereg__steps ul { margin: 4px 0 0; padding-left: 16px; display: flex; flex-direction: column; gap: 4px; }
/* Aviso de credencial personal en el diálogo "Descargar app móvil". */
.prereg__warn { margin: 10px 0 0; font-size: .82rem; color: var(--muted, #5b7185); text-align: center; }
.prereg__qr {
  display: block;
  margin: 0 auto 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  image-rendering: pixelated; /* módulos nítidos si el canvas se re-escala */
}
.prereg__qr[hidden] { display: none; }
.prereg__link {
  background: #f2f7fb;
  border: 1px solid #d5e3ee;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: .85rem;
  word-break: break-all;
  user-select: all;
  min-height: 1.2em;
}
.prereg__actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }

/* --- Barra inferior móvil (Propuesta B) ------------------------------------
   Asistente · Registrar visita · Enlaces. Oculta en escritorio (el FAB y los
   iconos del header siguen ahí); bajo el breakpoint móvil reemplaza a ambos.
   El atributo [hidden] (auth) manda sobre el breakpoint. */
.mobilenav {
  display: none; /* solo existe bajo el breakpoint móvil (ver media query) */
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  align-items: center;
  gap: 8px;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px);
  background: var(--card);
  border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(2, 17, 31, 0.08);
}
.mobilenav__side {
  flex: none;
  width: 64px;
  min-height: var(--tap);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: none;
  background: transparent;
  padding: 4px 0;
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}
.mobilenav__ico { font-size: 1.3rem; line-height: 1; }
.mobilenav__cta {
  flex: 1;
  min-height: 52px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--verde), var(--verde-osc));
  color: #fff;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 6px 16px rgba(6, 113, 198, 0.35);
  cursor: pointer;
}
.mobilenav__side[hidden], .mobilenav__cta[hidden] { display: none; }

/* Hoja de enlaces rápidos */
.linklist { display: flex; flex-direction: column; gap: 8px; padding-bottom: 8px; }
.linklist__item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--n-50);
  font-family: inherit;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
}
.linklist__item:hover { background: var(--n-100); }
.linklist__ico { font-size: 1.25rem; flex: none; }
.linklist__txt { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.linklist__txt b { font-size: 0.98rem; }
.linklist__txt small { color: var(--muted); font-size: 0.8rem; }

/* --- Móvil (Propuesta B): header colapsado, controles compactos, barra abajo.
   SOLO bajo el breakpoint — el escritorio y el iframe de GHL no cambian. */
@media (max-width: 640px) {
  /* Header colapsado a UNA fila: sin eslogan, logo y título más chicos, sin
     salto de línea (el título ellipsa antes que el chip baje de fila). Los
     iconos de asistente/pre-registro migran a la barra inferior. */
  .topbar { padding: calc(env(safe-area-inset-top) + 10px) 14px 10px; flex-wrap: nowrap; }
  .topbar__logo { width: 30px; height: 30px; }
  .topbar__brand { flex: 1; min-width: 0; }
  .topbar__title { min-width: 0; }
  .topbar h1 { font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar__sub { display: none; }
  .topbar .chip { font-size: 0.72rem; padding: 5px 10px; }
  .topbar #preregBtn,
  .topbar #assistantBtn { display: none; }

  /* Calbar en UNA fila: sin label (el dropdown ya muestra el calendario) y sin
     el texto "Actualizado …" — queda solo el ⟳. El sello reaparece únicamente
     cuando hay datos en caché (estado stale, que sí hay que avisar). */
  .calbar { padding: 8px 10px; margin-bottom: 10px; }
  .calbar > .calbar__label { display: none; }
  .freshstamp { display: none; }
  .freshstamp--stale { display: inline; font-size: 0.72rem; }

  /* Selector de calendario: con 2+ siempre dropdown (inlineMax=1 en app.js).
     La pill única (1 calendario) ellipsa en vez de scrollear cortada. */
  .calswitch__pill--single {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Áreas: sin label, toda la fila para las pills (scrollean; la activa se
     auto-centra al render). */
  .groupbar .calbar__label { display: none; }

  /* Pestañas Día/Próximas/Mes compactas (segmented pequeño) */
  .viewtabs { padding: 3px; margin-bottom: 10px; }
  .viewtab { min-height: 34px; font-size: 0.85rem; }

  /* Contadores: de 4 tarjetas a una fila de chips */
  .summary { display: flex; gap: 6px; margin-bottom: 10px; }
  .summary__stat {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 4px;
    border-radius: 999px;
  }
  .summary__num { font-size: 0.95rem; }
  .summary__lbl { margin-top: 0; font-size: 0.6rem; letter-spacing: 0.02em; white-space: nowrap; }
  .summary__lbl--full { display: none; }
  .summary__lbl--short { display: inline; }

  /* El FAB sale; la barra inferior toma el CTA (y el resto de acciones) */
  .fab { display: none; }
  .mobilenav:not([hidden]) { display: flex; }
  .screen { padding-bottom: calc(env(safe-area-inset-bottom) + 108px); }
  .toast { bottom: calc(env(safe-area-inset-bottom) + 104px); }
}

/* --- Asistente SAC (chat) --- */
.chatthread {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 46vh;
  min-height: 120px;
  overflow-y: auto;
  padding: 4px 2px;
  margin-bottom: 10px;
}
.chatmsg {
  max-width: 85%;
  padding: 10px 12px;
  border-radius: 14px;
  font-size: .95rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.chatmsg--assistant {
  align-self: flex-start;
  background: #eef4f9;
  border-bottom-left-radius: 4px;
}
.chatmsg--user {
  align-self: flex-end;
  background: #0a6ebd;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chatmsg--typing { color: #5b7185; letter-spacing: 3px; }
/* Rich text del asistente (renderChatRich): bloques con márgenes propios. */
.chatmsg--assistant { white-space: normal; }
.chatmsg--assistant p { margin: 0 0 8px; }
.chatmsg--assistant ul,
.chatmsg--assistant ol { margin: 0 0 8px; padding-left: 20px; }
.chatmsg--assistant li { margin: 2px 0; }
.chatmsg--assistant > :last-child { margin-bottom: 0; }
.chatmsg--assistant code {
  background: #dbe6f0;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: .88em;
}
.chatform { display: flex; flex-direction: column; gap: 8px; }
.chatform textarea {
  width: 100%;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid #c6d4e0;
  border-radius: 10px;
  font: inherit;
}
