/* =====================================================================
   RedSalud · Panel de agenda médica
   Tema claro, sanitario e institucional. Sin dependencias de build.
   ===================================================================== */

/* ---------------------------------------------------------- 1. Variables */
:root {
  /* Superficies y texto */
  --fondo: #f6f8fb;
  --superficie: #ffffff;
  --superficie-2: #f8fafc;
  --superficie-3: #f1f5f9;
  --texto: #0f172a;
  --texto-suave: #475569;
  --texto-tenue: #64748b;
  --borde: #e2e8f0;
  --borde-fuerte: #cbd5e1;

  /* Marca y acciones neutras */
  --marca: #d92d3f;
  --marca-oscura: #b81f30;
  --marca-suave: #fef2f3;
  --azul: #2563eb;
  --azul-oscuro: #1d4ed8;
  --azul-suave: #eff6ff;

  /* Estados de cita — se usan en TODAS las vistas para que sean coherentes */
  --estado-agendada: #2563eb;
  --estado-confirmada: #4f46e5;
  --estado-en-sala: #d97706;
  --estado-atendida: #16a34a;
  --estado-no-asiste: #64748b;
  --estado-cancelada: #dc2626;

  /* Acentos de apoyo */
  --verde: #16a34a;
  --verde-suave: #f0fdf4;
  --ambar: #d97706;
  --ambar-suave: #fffbeb;
  --indigo: #4f46e5;
  --indigo-suave: #eef2ff;
  --rojo: #dc2626;
  --rojo-suave: #fef2f2;

  /* Espaciados */
  --e-1: 4px;
  --e-2: 8px;
  --e-3: 12px;
  --e-4: 16px;
  --e-5: 24px;
  --e-6: 32px;

  /* Radios y sombras */
  --r-sm: 8px;
  --r-md: 10px;
  --r-lg: 12px;
  --r-full: 999px;
  --sombra-1: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 3px rgba(15, 23, 42, .04);
  --sombra-2: 0 4px 12px rgba(15, 23, 42, .07), 0 2px 4px rgba(15, 23, 42, .04);
  --sombra-3: 0 18px 40px rgba(15, 23, 42, .16);

  /* Tipografía */
  --fuente: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --alto-slot: 34px;
  --alto-fijo: 232px;
}

/* ---------------------------------------------------------- 2. Base */
*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--fondo);
  color: var(--texto);
  font-family: var(--fuente);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; line-height: 1.25; letter-spacing: -.01em; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }

a { color: var(--azul); }

button, input, select, textarea { font: inherit; color: inherit; }

/* Foco siempre visible (accesibilidad con teclado) */
:focus-visible {
  outline: 2px solid var(--azul);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

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

.saltar {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--superficie);
  padding: var(--e-3) var(--e-4);
  border-radius: 0 0 var(--r-md) 0;
  box-shadow: var(--sombra-2);
}
.saltar:focus { left: 0; }

.sin-js {
  margin: var(--e-5);
  padding: var(--e-4);
  background: var(--ambar-suave);
  border: 1px solid #fcd34d;
  border-radius: var(--r-md);
}

/* ---------------------------------------------------------- 3. Iconos y botones */
.icono {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--e-2);
  padding: 8px 14px;
  border: 1px solid var(--borde);
  border-radius: var(--r-sm);
  background: var(--superficie);
  color: var(--texto-suave);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .14s ease, border-color .14s ease, color .14s ease, box-shadow .14s ease;
}
.btn:hover:not(:disabled) { background: var(--superficie-3); border-color: var(--borde-fuerte); color: var(--texto); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn--primario {
  background: var(--marca);
  border-color: var(--marca);
  color: #fff;
  box-shadow: 0 1px 2px rgba(217, 45, 63, .3);
}
.btn--primario:hover:not(:disabled) { background: var(--marca-oscura); border-color: var(--marca-oscura); color: #fff; }

.btn--azul { background: var(--azul); border-color: var(--azul); color: #fff; }
.btn--azul:hover:not(:disabled) { background: var(--azul-oscuro); border-color: var(--azul-oscuro); color: #fff; }

.btn--peligro { background: var(--rojo); border-color: var(--rojo); color: #fff; }
.btn--peligro:hover:not(:disabled) { background: #b91c1c; border-color: #b91c1c; color: #fff; }

.btn--fantasma { background: transparent; }
.btn--fantasma:hover:not(:disabled) { background: var(--superficie-3); }

.btn--chico { padding: 5px 10px; font-size: 12px; }

.btn-icono {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--borde);
  border-radius: var(--r-sm);
  background: var(--superficie);
  color: var(--texto-suave);
  cursor: pointer;
  transition: background-color .14s ease, border-color .14s ease, color .14s ease;
}
.btn-icono:hover:not(:disabled) { background: var(--superficie-3); border-color: var(--borde-fuerte); color: var(--texto); }
.btn-icono:disabled { opacity: .45; cursor: not-allowed; }

/* ---------------------------------------------------------- 4. Cabecera fija */
.fijo {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--superficie);
  border-bottom: 1px solid var(--borde);
  box-shadow: var(--sombra-1);
}

.cabecera { padding: var(--e-3) var(--e-5) 0; }

.cabecera__fila {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--e-4);
  flex-wrap: wrap;
}

.marca { display: flex; align-items: center; gap: var(--e-3); }

.marca__logo svg { width: 38px; height: 38px; display: block; }
.marca__logo rect { fill: var(--marca); }
.marca__logo path {
  fill: none;
  stroke: #fff;
  stroke-width: 3.2;
  stroke-linecap: round;
}

.marca__texto { display: flex; flex-direction: column; line-height: 1.15; }
.marca__texto strong { font-size: 19px; font-weight: 700; letter-spacing: -.02em; }
.marca__texto small { font-size: 12px; color: var(--texto-tenue); font-weight: 500; }

.cabecera__acciones { display: flex; align-items: center; gap: var(--e-2); flex-wrap: wrap; }

.vivo {
  display: inline-flex;
  align-items: center;
  gap: var(--e-2);
  padding: 6px 12px;
  border: 1px solid var(--borde);
  border-radius: var(--r-full);
  background: var(--superficie-2);
  font-size: 12px;
  color: var(--texto-tenue);
  white-space: nowrap;
}
.vivo__punto {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--texto-tenue);
  flex: none;
}
.vivo--ok .vivo__punto { background: var(--verde); box-shadow: 0 0 0 3px rgba(22, 163, 74, .16); animation: latido 2.4s ease-in-out infinite; }
.vivo--error .vivo__punto { background: var(--rojo); box-shadow: 0 0 0 3px rgba(220, 38, 38, .16); }

@keyframes latido {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

/* ---------------------------------------------------------- 5. Tarjetas KPI */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: var(--e-2);
  margin-top: var(--e-3);
}

.kpi {
  background: var(--superficie-2);
  border: 1px solid var(--borde);
  border-radius: var(--r-md);
  padding: 9px var(--e-3);
  min-width: 0;
}
.kpi__etiqueta {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--texto-tenue);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi__valor {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--texto);
  line-height: 1.2;
}
.kpi--marca { background: var(--marca-suave); border-color: #fbd0d5; }
.kpi--marca .kpi__valor { color: var(--marca); }
.kpi--azul { background: var(--azul-suave); border-color: #dbeafe; }
.kpi--azul .kpi__valor { color: var(--azul); }
.kpi--verde { background: var(--verde-suave); border-color: #dcfce7; }
.kpi--verde .kpi__valor { color: var(--verde); }
.kpi--ambar { background: var(--ambar-suave); border-color: #fde68a; }
.kpi--ambar .kpi__valor { color: var(--ambar); }

/* Esqueleto de los KPIs mientras carga */
.kpi--esqueleto { min-height: 58px; }
.kpi--esqueleto .kpi__etiqueta,
.kpi--esqueleto .kpi__valor {
  background: linear-gradient(90deg, #eef2f7 25%, #e2e8f0 37%, #eef2f7 63%);
  background-size: 400% 100%;
  animation: brillo 1.4s ease-in-out infinite;
  border-radius: 4px;
  color: transparent;
  width: 70%;
  height: 11px;
  margin: 2px 0;
}
.kpi--esqueleto .kpi__valor { height: 20px; width: 45%; margin-top: 6px; }

@keyframes brillo {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* ---------------------------------------------------------- 6. Barra de fecha */
.barra-fecha {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--e-4);
  flex-wrap: wrap;
  padding: var(--e-3) 0;
}
.barra-fecha__grupo { display: flex; align-items: center; gap: var(--e-2); flex-wrap: wrap; }
.barra-fecha__titulo {
  font-size: 15px;
  font-weight: 650;
  color: var(--texto);
  margin-left: var(--e-2);
  text-transform: capitalize;
}

.campo { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.campo > span {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--texto-tenue);
}
.campo input, .campo select, .campo textarea {
  padding: 7px 10px;
  border: 1px solid var(--borde);
  border-radius: var(--r-sm);
  background: var(--superficie);
  color: var(--texto);
  font-size: 13px;
  min-width: 0;
  transition: border-color .14s ease, box-shadow .14s ease;
}
.campo input:hover, .campo select:hover, .campo textarea:hover { border-color: var(--borde-fuerte); }
.campo input:focus, .campo select:focus, .campo textarea:focus {
  outline: none;
  border-color: var(--azul);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .13);
}
.campo textarea { resize: vertical; min-height: 68px; font-family: inherit; }
.campo--fecha input { width: 148px; }
.campo--ancho { min-width: 280px; flex: 1 1 280px; }
.campo select { cursor: pointer; }

.conmutador {
  display: inline-flex;
  align-items: center;
  gap: var(--e-2);
  font-size: 13px;
  color: var(--texto-suave);
  cursor: pointer;
  user-select: none;
  padding: 7px 12px;
  border: 1px solid var(--borde);
  border-radius: var(--r-sm);
  background: var(--superficie);
}
.conmutador input { accent-color: var(--azul); width: 15px; height: 15px; cursor: pointer; }

/* ---------------------------------------------------------- 7. Pestañas */
.tabs {
  display: flex;
  gap: var(--e-1);
  padding: 0 var(--e-5);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  display: inline-flex;
  align-items: center;
  gap: var(--e-2);
  padding: 11px 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--texto-tenue);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: color .14s ease, border-color .14s ease;
}
.tab:hover { color: var(--texto); }
.tab[aria-selected="true"] { color: var(--marca); border-bottom-color: var(--marca); }

/* ---------------------------------------------------------- 8. Vistas */
#principal { padding: var(--e-4) var(--e-5) var(--e-6); }

.vista:focus { outline: none; }

.vista__barra {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--e-4);
  flex-wrap: wrap;
  margin-bottom: var(--e-3);
}

.filtros { display: flex; align-items: flex-end; gap: var(--e-3); flex-wrap: wrap; }

.nota {
  font-size: 12px;
  color: var(--texto-tenue);
  padding-bottom: 6px;
}
.nota strong { color: var(--texto-suave); }

.sobretitulo {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--texto-tenue);
}

/* ---------------------------------------------------------- 9. Estados */
.estado {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--e-2);
  text-align: center;
  padding: var(--e-6) var(--e-4);
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: var(--r-lg);
  color: var(--texto-suave);
}
.estado h3 { font-size: 15px; color: var(--texto); }
.estado p { font-size: 13px; max-width: 46ch; color: var(--texto-tenue); }
.estado--error { background: var(--rojo-suave); border-color: #fecaca; }
.estado--error h3 { color: var(--rojo); }
.estado--vacio { background: var(--superficie); }
.estado__icono { font-size: 22px; line-height: 1; }

.spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--borde);
  border-top-color: var(--azul);
  border-radius: 50%;
  animation: girar .7s linear infinite;
  flex: none;
}
@keyframes girar { to { transform: rotate(360deg); } }

.capa {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--e-3);
  padding: var(--e-5);
  background: rgba(255, 255, 255, .86);
  border-radius: var(--r-lg);
  text-align: center;
  color: var(--texto-suave);
}
.capa--bloque { position: relative; min-height: 240px; border: 1px solid var(--borde); }

/* Esqueleto genérico para listas y tablas */
.esqueleto { display: flex; flex-direction: column; gap: var(--e-2); padding: var(--e-4); }
.esqueleto__linea {
  height: 14px;
  border-radius: 5px;
  background: linear-gradient(90deg, #eef2f7 25%, #e2e8f0 37%, #eef2f7 63%);
  background-size: 400% 100%;
  animation: brillo 1.4s ease-in-out infinite;
}
.esqueleto__linea:nth-child(odd) { width: 92%; }
.esqueleto__linea:nth-child(even) { width: 72%; }

/* ---------------------------------------------------------- 10. Calendario */
.calendario-envoltorio {
  position: relative;
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: var(--r-lg);
  box-shadow: var(--sombra-1);
  padding: var(--e-3) var(--e-4) var(--e-4);
  height: calc(100vh - 336px);
  min-height: 460px;
}
#calendario { height: 100%; }

/* Ajustes de tema sobre las variables propias de FullCalendar 6 */
.fc {
  --fc-border-color: var(--borde);
  --fc-page-bg-color: var(--superficie);
  --fc-neutral-bg-color: var(--superficie-2);
  --fc-today-bg-color: #fff7f8;
  --fc-now-indicator-color: var(--marca);
  --fc-small-font-size: 12px;
  --fc-button-bg-color: var(--superficie);
  --fc-button-border-color: var(--borde);
  --fc-button-text-color: var(--texto-suave);
  --fc-button-hover-bg-color: var(--superficie-3);
  --fc-button-hover-border-color: var(--borde-fuerte);
  --fc-button-active-bg-color: var(--azul);
  --fc-button-active-border-color: var(--azul);
  font-family: var(--fuente);
}

.fc .fc-toolbar.fc-header-toolbar { margin-bottom: var(--e-3); }
.fc .fc-toolbar-title { font-size: 16px; font-weight: 650; text-transform: capitalize; color: var(--texto); }
.fc .fc-button { font-size: 12.5px; font-weight: 600; padding: 6px 11px; box-shadow: none !important; }
.fc .fc-button-active { color: #fff !important; }
.fc .fc-col-header-cell-cushion,
.fc .fc-daygrid-day-number,
.fc .fc-timegrid-slot-label-cushion {
  color: var(--texto-suave);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  padding: 6px;
}
.fc .fc-day-today .fc-daygrid-day-number { color: var(--marca); font-weight: 700; }
.fc .fc-daygrid-day-top { flex-direction: row; }
.fc .fc-timegrid-slot { height: var(--alto-slot); }
.fc .fc-timegrid-slot-label { vertical-align: top; }
.fc .fc-timegrid-axis-cushion { font-size: 11px; color: var(--texto-tenue); }
.fc .fc-event { border: none; border-radius: 5px; padding: 1px 4px; cursor: pointer; font-size: 12px; }
.fc .fc-event:hover { filter: brightness(.94); }
.fc .fc-daygrid-event { margin-top: 1px; white-space: normal; }
.fc .fc-timegrid-event { box-shadow: none; }
.fc .fc-non-business { background: rgba(241, 245, 249, .7); }

/* Contenido propio de los eventos de cita */
.ev { display: flex; flex-direction: column; overflow: hidden; line-height: 1.25; }
.ev__hora { font-weight: 700; font-size: 11px; opacity: .95; }
.ev__paciente { font-weight: 600; }
.ev__meta { font-size: 10.5px; opacity: .88; }

/* Cupos libres: color tenue y sin interacción (display: 'background') */
.fc .fc-bg-event { opacity: 1; }

/* ---------------------------------------------------------- 11. Agenda médica */
.agenda-envoltorio {
  position: relative;
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: var(--r-lg);
  box-shadow: var(--sombra-1);
  overflow: auto;
  max-height: calc(100vh - 288px);
  min-height: 420px;
}

.agenda { min-width: max-content; }

.agenda__fila {
  display: grid;
  grid-template-columns: 66px repeat(var(--columnas, 1), minmax(178px, 1fr));
  min-width: max-content;
}

.agenda__esquina,
.agenda__prof {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--superficie);
  border-bottom: 1px solid var(--borde);
  padding: var(--e-2) var(--e-3);
  min-width: 0;
}
.agenda__esquina {
  left: 0;
  z-index: 5;
  border-right: 1px solid var(--borde);
}
.agenda__prof { border-right: 1px solid var(--borde); }
.agenda__prof strong { display: block; font-size: 12.5px; font-weight: 650; }
.agenda__prof small { display: block; font-size: 11px; color: var(--texto-tenue); }

.agenda__horas {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--superficie);
  border-right: 1px solid var(--borde);
}
.agenda__hora {
  height: var(--alto-slot);
  font-size: 11px;
  font-weight: 600;
  color: var(--texto-tenue);
  text-align: right;
  padding: 0 var(--e-2);
  transform: translateY(-7px);
  white-space: nowrap;
}
.agenda__hora:first-child { transform: translateY(4px); }

.agenda__col {
  position: relative;
  border-right: 1px solid var(--borde);
  height: calc(var(--slots, 24) * var(--alto-slot));
  /* Líneas de las franjas de 30 minutos, dibujadas sin elementos extra */
  background-image: repeating-linear-gradient(
    to bottom,
    var(--borde) 0 1px,
    transparent 1px var(--alto-slot)
  );
}
.agenda__col:last-child { border-right: 0; }

/* Cupo libre: celda punteada y clicable */
.cupo {
  position: absolute;
  left: 3px;
  right: 3px;
  border: 1.5px dashed #b8c6db;
  border-radius: 6px;
  background: rgba(37, 99, 235, .035);
  color: var(--texto-tenue);
  font-size: 10.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0 4px;
  cursor: pointer;
  overflow: hidden;
  transition: background-color .14s ease, border-color .14s ease, color .14s ease;
}
.cupo:hover {
  background: var(--azul-suave);
  border-color: var(--azul);
  color: var(--azul);
}
.cupo__mas { font-size: 13px; font-weight: 700; line-height: 1; }

/* Cita dentro de la rejilla */
.cita-chip {
  position: absolute;
  left: 3px;
  right: 3px;
  border: 0;
  border-left: 3px solid rgba(0, 0, 0, .25);
  border-radius: 6px;
  padding: 3px 7px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 1px;
  text-align: left;
  color: #fff;
  cursor: pointer;
  overflow: hidden;
  box-shadow: var(--sombra-1);
  transition: filter .14s ease, transform .14s ease;
}
.cita-chip:hover { filter: brightness(1.06); transform: translateX(1px); }
.cita-chip__hora { font-size: 10px; font-weight: 700; opacity: .95; }
.cita-chip__nombre {
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cita-chip__meta {
  font-size: 10px;
  opacity: .9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cita-chip--cancelada { text-decoration: line-through; }

.agenda__fuera {
  margin: var(--e-3);
  padding: var(--e-2) var(--e-3);
  background: var(--ambar-suave);
  border: 1px solid #fde68a;
  border-radius: var(--r-sm);
  font-size: 12px;
  color: #92400e;
}

/* ---------------------------------------------------------- 12. Tablas */
.tabla-envoltorio {
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: var(--r-lg);
  box-shadow: var(--sombra-1);
  overflow: auto;
  max-height: calc(100vh - 268px);
  min-height: 300px;
}

.tabla { width: 100%; border-collapse: collapse; font-size: 13px; }
.tabla thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--superficie-2);
  border-bottom: 1px solid var(--borde);
  padding: 10px var(--e-3);
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--texto-tenue);
  white-space: nowrap;
}
.tabla tbody tr {
  border-bottom: 1px solid var(--borde);
  cursor: pointer;
  transition: background-color .12s ease;
}
.tabla tbody tr:last-child { border-bottom: 0; }
.tabla tbody tr:hover { background: var(--superficie-2); }
.tabla tbody td { padding: 10px var(--e-3); vertical-align: middle; }
.tabla__nombre { font-weight: 600; color: var(--texto); }
.tabla__sub { font-size: 11.5px; color: var(--texto-tenue); }
.tabla__num { font-variant-numeric: tabular-nums; }
.tabla th[scope="row"] { text-align: left; }

/* ---------------------------------------------------------- 13. Chips / etiquetas */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: var(--r-full);
  font-size: 11.5px;
  font-weight: 650;
  white-space: nowrap;
  border: 1px solid transparent;
}
.chip__punto { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.chip--neutro { background: var(--superficie-3); color: var(--texto-suave); border-color: var(--borde); }
.chip--azul { background: var(--azul-suave); color: var(--azul); border-color: #dbeafe; }
.chip--indigo { background: var(--indigo-suave); color: var(--indigo); border-color: #e0e7ff; }
.chip--ambar { background: var(--ambar-suave); color: #b45309; border-color: #fde68a; }
.chip--verde { background: var(--verde-suave); color: #15803d; border-color: #dcfce7; }
.chip--rojo { background: var(--rojo-suave); color: #b91c1c; border-color: #fecaca; }
.chip--gris { background: var(--superficie-3); color: var(--texto-tenue); border-color: var(--borde); }

/* ---------------------------------------------------------- 14. Conversaciones */
.conversaciones {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: var(--e-4);
  align-items: start;
}

.conversaciones__lista {
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: var(--r-lg);
  box-shadow: var(--sombra-1);
  overflow: auto;
  max-height: calc(100vh - 268px);
  min-height: 300px;
}

.conv {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--borde);
  border-left: 3px solid transparent;
  background: var(--superficie);
  padding: var(--e-3);
  cursor: pointer;
  transition: background-color .12s ease, border-color .12s ease;
}
.conv:hover { background: var(--superficie-2); }
.conv[aria-current="true"] { background: var(--marca-suave); border-left-color: var(--marca); }
.conv__fila { display: flex; align-items: center; justify-content: space-between; gap: var(--e-2); }
.conv__paciente { font-weight: 650; font-size: 13px; }
.conv__meta { font-size: 11.5px; color: var(--texto-tenue); margin-top: 2px; display: flex; gap: var(--e-2); flex-wrap: wrap; }

.conversaciones__detalle {
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: var(--r-lg);
  box-shadow: var(--sombra-1);
  min-height: 300px;
  overflow: hidden;
}

.transcripcion__cabecera {
  padding: var(--e-4);
  border-bottom: 1px solid var(--borde);
  background: var(--superficie-2);
}
.transcripcion__cabecera h2 { font-size: 15px; }
.transcripcion__datos {
  display: flex;
  gap: var(--e-4);
  flex-wrap: wrap;
  margin-top: var(--e-2);
  font-size: 12px;
  color: var(--texto-tenue);
}

.transcripcion__cuerpo {
  padding: var(--e-4);
  max-height: calc(100vh - 400px);
  min-height: 240px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: var(--e-3);
}

.turno {
  display: flex;
  flex-direction: column;
  gap: var(--e-2);
  padding-left: var(--e-3);
  border-left: 2px solid var(--borde);
}
.turno__rotulo {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--texto-tenue);
}

.evento {
  display: flex;
  gap: var(--e-3);
  padding: var(--e-3);
  border: 1px solid var(--borde);
  border-left: 3px solid var(--borde-fuerte);
  border-radius: var(--r-md);
  background: var(--superficie);
}
.evento--paciente { border-left-color: var(--azul); background: var(--azul-suave); }
.evento--agente { border-left-color: var(--marca); background: var(--marca-suave); }
.evento--sistema { border-left-color: var(--texto-tenue); background: var(--superficie-2); }

.evento__lateral { flex: none; display: flex; flex-direction: column; gap: 3px; align-items: flex-start; width: 92px; }
.evento__hora { font-size: 11px; color: var(--texto-tenue); font-variant-numeric: tabular-nums; }
.evento__cuerpo { flex: 1 1 auto; min-width: 0; }
.evento__texto { font-size: 13.5px; color: var(--texto); white-space: pre-wrap; overflow-wrap: anywhere; }

/* Tool calls del agente: resaltadas */
.tool {
  border: 1px solid #c7d2fe;
  border-radius: var(--r-md);
  background: var(--indigo-suave);
  overflow: hidden;
}
.tool__cabecera {
  display: flex;
  align-items: center;
  gap: var(--e-2);
  padding: 6px 10px;
  background: #e0e7ff;
  border-bottom: 1px solid #c7d2fe;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #3730a3;
}
.tool__nombre {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
  color: #312e81;
}
.tool__args {
  margin: 0;
  padding: var(--e-3);
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.55;
  color: #1e1b4b;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 220px;
  overflow: auto;
}

/* ---------------------------------------------------------- 15. Métricas */
.metricas__seccion { margin-bottom: var(--e-5); }
.metricas__seccion > h2 { font-size: 15px; margin-bottom: var(--e-3); }

.metricas__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--e-3);
}

.tarjeta {
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: var(--r-lg);
  box-shadow: var(--sombra-1);
  padding: var(--e-4);
}
.tarjeta__titulo { font-size: 13px; font-weight: 650; margin-bottom: var(--e-3); }

.barra {
  display: flex;
  align-items: center;
  gap: var(--e-3);
  padding: var(--e-2) 0;
}
.barra__nombre { flex: 0 0 190px; font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.barra__pista {
  flex: 1 1 auto;
  height: 20px;
  border-radius: var(--r-full);
  background: var(--superficie-3);
  overflow: hidden;
  display: flex;
  min-width: 90px;
}
.barra__relleno { height: 100%; background: var(--azul); transition: width .3s ease; }
.barra__relleno--alta { background: var(--ambar); }
.barra__relleno--lleno { background: var(--marca); }
.barra__cifra {
  flex: 0 0 116px;
  text-align: right;
  font-size: 11.5px;
  color: var(--texto-tenue);
  font-variant-numeric: tabular-nums;
}
.barra__cifra strong { color: var(--texto); }

.grafico { width: 100%; }
.grafico svg { width: 100%; height: auto; display: block; }
.grafico__leyenda {
  display: flex;
  gap: var(--e-4);
  flex-wrap: wrap;
  margin-top: var(--e-3);
  font-size: 12px;
  color: var(--texto-tenue);
}
.grafico__leyenda span { display: inline-flex; align-items: center; gap: 6px; }
.grafico__muestra { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.grafico__muestra--linea { width: 16px; height: 0; border-top: 2px dashed var(--texto-tenue); border-radius: 0; }

/* ---------------------------------------------------------- 16. Drawer lateral */
.drawer { position: fixed; inset: 0; z-index: 60; }
.drawer__fondo {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .38);
  animation: aparecer .16s ease;
}
.drawer__panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(480px, 94vw);
  display: flex;
  flex-direction: column;
  background: var(--superficie);
  box-shadow: var(--sombra-3);
  animation: deslizar-derecha .22s cubic-bezier(.22, .61, .36, 1);
}
.drawer__cabecera {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--e-3);
  padding: var(--e-4);
  border-bottom: 1px solid var(--borde);
}
.drawer__cabecera h2 { font-size: 17px; }
.drawer__cuerpo { flex: 1 1 auto; overflow: auto; padding: var(--e-4); }

@keyframes deslizar-derecha { from { transform: translateX(24px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes aparecer { from { opacity: 0; } to { opacity: 1; } }

/* Bloques de la ficha de paciente */
.datos { display: grid; grid-template-columns: 1fr 1fr; gap: var(--e-3); }
.dato { min-width: 0; }
.dato__etiqueta {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--texto-tenue);
}
.dato__valor { font-size: 13.5px; color: var(--texto); overflow-wrap: anywhere; }
.dato--ancho { grid-column: 1 / -1; }

.bloque { margin-top: var(--e-5); }
.bloque > h3 { font-size: 13px; margin-bottom: var(--e-3); display: flex; align-items: center; gap: var(--e-2); }
.bloque > h3 .cuenta {
  font-size: 11px;
  font-weight: 700;
  color: var(--texto-tenue);
  background: var(--superficie-3);
  border-radius: var(--r-full);
  padding: 1px 8px;
}

.lista-citas { display: flex; flex-direction: column; gap: var(--e-2); }
.cita-fila {
  display: flex;
  align-items: center;
  gap: var(--e-3);
  width: 100%;
  text-align: left;
  padding: var(--e-3);
  border: 1px solid var(--borde);
  border-left: 3px solid var(--borde-fuerte);
  border-radius: var(--r-md);
  background: var(--superficie);
  cursor: pointer;
  transition: background-color .12s ease;
}
.cita-fila:hover { background: var(--superficie-2); }
.cita-fila__cuando { flex: 0 0 96px; font-size: 12px; font-weight: 650; color: var(--texto); }
.cita-fila__cuerpo { flex: 1 1 auto; min-width: 0; }
.cita-fila__titulo { font-size: 13px; font-weight: 600; }
.cita-fila__meta { font-size: 11.5px; color: var(--texto-tenue); }

/* ---------------------------------------------------------- 17. Modales */
.modales { position: relative; z-index: 70; }

.modal { position: fixed; inset: 0; display: flex; align-items: flex-start; justify-content: center; padding: var(--e-5) var(--e-4); overflow: auto; }
.modal__fondo { position: fixed; inset: 0; background: rgba(15, 23, 42, .42); animation: aparecer .16s ease; }
.modal__caja {
  position: relative;
  width: 100%;
  max-width: 560px;
  margin: auto;
  background: var(--superficie);
  border-radius: var(--r-lg);
  box-shadow: var(--sombra-3);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 48px);
  animation: subir .2s cubic-bezier(.22, .61, .36, 1);
}
.modal__caja--sm { max-width: 420px; }
.modal__caja--lg { max-width: 880px; }

@keyframes subir { from { transform: translateY(10px); opacity: .5; } to { transform: none; opacity: 1; } }

.modal__cabecera {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--e-3);
  padding: var(--e-4);
  border-bottom: 1px solid var(--borde);
}
.modal__cabecera h2 { font-size: 16px; }
.modal__cuerpo { flex: 1 1 auto; overflow: auto; padding: var(--e-4); }
.modal__pie {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--e-2);
  padding: var(--e-3) var(--e-4);
  border-top: 1px solid var(--borde);
  background: var(--superficie-2);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
  flex-wrap: wrap;
}
.modal__pie .separador { margin-right: auto; }

.seccion { margin-bottom: var(--e-5); }
.seccion:last-child { margin-bottom: 0; }
.seccion > h3 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--texto-tenue);
  margin-bottom: var(--e-3);
  display: flex;
  align-items: center;
  gap: var(--e-2);
}
.seccion > h3 .paso {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--marca);
  color: #fff;
  font-size: 10px;
  flex: none;
}

.rejilla-campos { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--e-3); }

.alerta {
  display: flex;
  gap: var(--e-2);
  padding: var(--e-3);
  border-radius: var(--r-md);
  font-size: 13px;
  margin-bottom: var(--e-3);
  border: 1px solid transparent;
}
.alerta--error { background: var(--rojo-suave); border-color: #fecaca; color: #991b1b; }
.alerta--ok { background: var(--verde-suave); border-color: #bbf7d0; color: #166534; }
.alerta--info { background: var(--azul-suave); border-color: #dbeafe; color: #1e40af; }
.alerta--aviso { background: var(--ambar-suave); border-color: #fde68a; color: #92400e; }

.lista-cupos {
  border: 1px solid var(--borde);
  border-radius: var(--r-md);
  max-height: 268px;
  overflow: auto;
  background: var(--superficie-2);
}
.cupo-opcion {
  display: flex;
  align-items: center;
  gap: var(--e-3);
  width: 100%;
  text-align: left;
  padding: 9px var(--e-3);
  border: 0;
  border-bottom: 1px solid var(--borde);
  background: var(--superficie);
  cursor: pointer;
  transition: background-color .12s ease;
}
.cupo-opcion:last-child { border-bottom: 0; }
.cupo-opcion:hover { background: var(--azul-suave); }
.cupo-opcion[aria-pressed="true"] { background: var(--azul-suave); box-shadow: inset 3px 0 0 var(--azul); }
.cupo-opcion__cuando { flex: 0 0 118px; font-size: 12.5px; font-weight: 650; font-variant-numeric: tabular-nums; }
.cupo-opcion__cuerpo { flex: 1 1 auto; min-width: 0; font-size: 12.5px; }
.cupo-opcion__centro { font-size: 11.5px; color: var(--texto-tenue); }

.seleccion {
  display: flex;
  align-items: center;
  gap: var(--e-2);
  padding: var(--e-3);
  border: 1px solid #bfdbfe;
  border-radius: var(--r-md);
  background: var(--azul-suave);
  font-size: 13px;
  color: #1e40af;
}
.seleccion--vacia { border-color: var(--borde); background: var(--superficie-2); color: var(--texto-tenue); }

/* Bloque de acciones de estado en el detalle de la cita */
.acciones-estado { display: flex; flex-wrap: wrap; gap: var(--e-2); }

.ficha-cita { display: grid; grid-template-columns: 1fr 1fr; gap: var(--e-3); }
.ficha-cita .dato--ancho { grid-column: 1 / -1; }

.linea-tiempo { display: flex; flex-direction: column; gap: var(--e-2); }
.paso-tiempo {
  display: flex;
  gap: var(--e-3);
  padding-left: var(--e-3);
  border-left: 2px solid var(--borde);
  font-size: 12.5px;
}
.paso-tiempo__ts { flex: 0 0 118px; color: var(--texto-tenue); font-variant-numeric: tabular-nums; }
.paso-tiempo__nota { color: var(--texto-suave); }

/* ---------------------------------------------------------- 18. Avisos (toasts) */
.avisos {
  position: fixed;
  right: var(--e-5);
  bottom: var(--e-5);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: var(--e-2);
  align-items: flex-end;
  pointer-events: none;
}
.aviso {
  pointer-events: auto;
  min-width: 260px;
  max-width: 420px;
  padding: var(--e-3) var(--e-4);
  border-radius: var(--r-md);
  border: 1px solid var(--borde);
  border-left: 4px solid var(--texto-tenue);
  background: var(--superficie);
  box-shadow: var(--sombra-2);
  font-size: 13px;
  color: var(--texto);
  animation: subir .18s ease;
}
.aviso--ok { border-left-color: var(--verde); }
.aviso--error { border-left-color: var(--rojo); }
.aviso--info { border-left-color: var(--azul); }
.aviso strong { display: block; font-size: 12.5px; margin-bottom: 2px; }
.aviso p { color: var(--texto-suave); font-size: 12.5px; }

/* ---------------------------------------------------------- 19. Responsive */
@media (max-width: 1180px) {
  .conversaciones { grid-template-columns: 1fr; }
  .conversaciones__lista { max-height: 320px; }
  .transcripcion__cuerpo { max-height: none; }
  .datos, .ficha-cita { grid-template-columns: 1fr; }
  .dato--ancho, .ficha-cita .dato--ancho { grid-column: auto; }
  .evento__lateral { width: 74px; }
}

@media (max-width: 900px) {
  #principal { padding: var(--e-4) var(--e-3) var(--e-5); }
  .cabecera { padding: var(--e-3) var(--e-3) 0; }
  .tabs { padding: 0 var(--e-3); }
  .barra { flex-wrap: wrap; }
  .barra__nombre { flex: 1 1 100%; }
  .barra__cifra { flex: 0 0 96px; }
  .calendario-envoltorio { height: auto; min-height: 480px; }
  #calendario { height: 70vh; }
  .avisos { right: var(--e-3); left: var(--e-3); bottom: var(--e-3); align-items: stretch; }
  .aviso { max-width: none; }
  .modal { padding: var(--e-3); }
}

/* Respeta la preferencia de movimiento reducido */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

/* =====================================================================
   Probar agente
   =====================================================================
   Dos columnas: la conversación a la izquierda y el estado/la traza a la
   derecha. Reutiliza los tokens de color para que las burbujas del agente
   sean coherentes con el resto del panel.
   ===================================================================== */

.agente {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: var(--e-4, 16px);
  align-items: start;
  min-height: 0;
}

.agente__panel {
  display: flex;
  flex-direction: column;
  min-height: 620px;
  padding: 0;
  overflow: hidden;
}

.agente__cabecera {
  display: flex;
  flex-wrap: wrap;
  gap: var(--e-3, 12px);
  align-items: flex-start;
  justify-content: space-between;
  padding: var(--e-4, 16px) var(--e-5, 24px);
  border-bottom: 1px solid var(--borde);
  background: var(--superficie-2);
}

.agente__cabecera .tarjeta__titulo { margin: 0 0 2px; }
.agente__botones { display: flex; gap: var(--e-2, 8px); flex-wrap: wrap; }

.agente__hilo {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--e-5, 24px);
  display: flex;
  flex-direction: column;
  gap: var(--e-3, 12px);
  max-height: 460px;
  background: var(--fondo);
}

.burbuja {
  max-width: min(680px, 84%);
  padding: var(--e-3, 12px) var(--e-4, 16px);
  border-radius: 14px;
  border: 1px solid var(--borde);
  background: var(--superficie);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.burbuja--paciente {
  align-self: flex-end;
  background: var(--azul-suave);
  border-color: #dbeafe;
  border-bottom-right-radius: 4px;
}

.burbuja--agente {
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.burbuja__meta { margin-bottom: 2px; }

.burbuja__autor {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--texto-tenue);
}

.burbuja--agente .burbuja__autor { color: var(--marca); }

.burbuja__texto {
  color: var(--texto);
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.burbuja__acciones {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: var(--e-2, 8px);
}

.burbuja__cita {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--e-2, 8px);
  margin-top: var(--e-3, 12px);
  padding: var(--e-3, 12px);
  border: 1px solid #bbf7d0;
  border-radius: 10px;
  background: var(--verde-suave);
  color: #14532d;
  font-size: 13px;
}

.agente__sugerencias {
  display: flex;
  flex-wrap: wrap;
  gap: var(--e-2, 8px);
  padding: 0 var(--e-5, 24px) var(--e-3, 12px);
  background: var(--fondo);
}

.agente__sugerencia {
  cursor: pointer;
  border: 1px dashed var(--borde-fuerte);
  background: var(--superficie);
  transition: border-color 0.15s, background 0.15s;
}

.agente__sugerencia:hover {
  border-color: var(--azul);
  background: var(--azul-suave);
  border-style: solid;
}

.agente__entrada {
  display: flex;
  gap: var(--e-2, 8px);
  padding: var(--e-4, 16px) var(--e-5, 24px);
  border-top: 1px solid var(--borde);
  background: var(--superficie);
}

.agente__entrada input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--borde-fuerte);
  border-radius: 10px;
  font: inherit;
  color: var(--texto);
  background: var(--superficie);
}

.agente__entrada input:focus-visible {
  outline: 2px solid var(--azul);
  outline-offset: 1px;
  border-color: var(--azul);
}

.agente__lado {
  display: flex;
  flex-direction: column;
  gap: var(--e-4, 16px);
}

.agente__datos { margin: 0; }

.agente__dato {
  display: flex;
  justify-content: space-between;
  gap: var(--e-3, 12px);
  padding: 7px 0;
  border-bottom: 1px dashed var(--borde);
  font-size: 13px;
}

.agente__dato:last-child { border-bottom: 0; }

.agente__dato dt {
  color: var(--texto-tenue);
  font-weight: 600;
  white-space: nowrap;
}

.agente__dato dd {
  margin: 0;
  color: var(--texto);
  text-align: right;
  word-break: break-word;
}

.agente__tools {
  display: flex;
  flex-direction: column;
  gap: var(--e-2, 8px);
  max-height: 320px;
  overflow-y: auto;
}

.agente__tool {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: var(--e-2, 8px);
  border: 1px solid var(--borde);
  border-radius: 8px;
  background: var(--superficie-2);
}

.agente__tool time { font-size: 11px; color: var(--texto-tenue); }

.agente__tool code {
  flex: 1 1 100%;
  font-size: 11px;
  color: var(--texto-suave);
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: 6px;
  padding: 4px 6px;
  overflow-x: auto;
  white-space: pre;
}

.agente__vacio { padding: var(--e-5, 24px); text-align: center; }

@media (max-width: 1100px) {
  .agente { grid-template-columns: minmax(0, 1fr); }
  .agente__panel { min-height: 0; }
  .agente__hilo { max-height: 380px; }
}
