/* ==========================================================================
   SISTEMA DE DISEÑO DE LA CONSOLA (prefijo ds-)
   Reglas y criterios: ver DESIGN_SYSTEM.md en la raíz del proyecto.
   Se apoya en los tokens de admin.css (--canvas-bg, --surface-*, --text-*, --spot-*)
   y añade la escala tipográfica, el espaciado y los componentes reutilizables.
   Toda pantalla nueva se construye con estas clases; no se declaran colores ni
   tamaños sueltos en los módulos.
   ========================================================================== */

:root {
  /* Escala tipográfica: cuatro tamaños, ninguno más */
  --fs-figure: 26px; /* cifras de KPI */
  --fs-title: 20px;  /* títulos de pantalla y de modal (serif) */
  --fs-body: 13px;   /* texto, controles, tablas */
  --fs-meta: 11px;   /* etiquetas, insignias, fechas, ayudas */

  /* Espaciado: base de 4px */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;

  --control-h: 34px;
  --control-h-sm: 28px;

  --line: rgba(255, 255, 255, 0.08);
  --line-soft: rgba(255, 255, 255, 0.05);
  --line-strong: rgba(255, 255, 255, 0.16);
  --line-pop: rgba(255, 255, 255, 0.12);
  --wash: rgba(255, 255, 255, 0.025);
  --wash-2: rgba(255, 255, 255, 0.07);
  --solid-bg: var(--text-primary);
  --solid-hover: #ffffff;
  --on-solid: var(--canvas-bg);
  --pop-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --thumb: rgba(255, 255, 255, 0.18);
  --scheme: dark;
  --fs-display: 28px; /* nombre del paciente en el expediente (serif) */
  --accent: var(--spot-blue-text);
  --focus-ring: 0 0 0 2px color-mix(in srgb, var(--accent) 40%, transparent);
  --scrim: rgba(6, 7, 10, 0.66);

  --z-menu: 150; /* por encima de modales y paneles laterales: los menús se abren desde dentro de ellos */
  --z-modal: 100;
  --z-toast: 200;
}

/* --- Tema claro (papel) ----------------------------------------------------------------------------------------------
   El oscuro es el de partida (admin.css y :root). El claro solo redefine tokens; ningún componente tiene colores fijos.
   El atributo data-theme lo pone theme.js en <html> (preferencia guardada o la del sistema). */
:root { color-scheme: dark; }
:root[data-theme="light"] {
  color-scheme: light;

  --border-hairline: 1px solid rgb(var(--ink-rgb) / 0.08);
  --border-subtle: 1px solid rgb(var(--ink-rgb) / 0.05);

  --canvas-bg: #f7f6f3;
  --surface-base: #ffffff;
  --surface-card: #fbfbfa;
  --surface-card-hover: #f3f2ee;
  --surface-elevated: #ffffff;
  --text-primary: #1b1b1a;
  --text-secondary: #5f5e5a;
  --text-muted: #8a8984;
  --line: #eaeaea;
  --line-soft: #f1f0ec;
  --line-strong: #d6d5d0;
  --line-pop: #e2e1dc;
  --wash: rgba(17, 17, 17, 0.03);
  --wash-2: rgba(17, 17, 17, 0.06);
  --solid-bg: #111111;
  --solid-hover: #333333;
  --on-solid: #ffffff;
  --pop-shadow: 0 2px 12px rgba(17, 17, 17, 0.05);
  --thumb: rgba(17, 17, 17, 0.22);
  --scheme: light;
  --scrim: rgba(17, 17, 17, 0.34);
  --accent: #1f6c9f;
  --spot-blue-bg: #e1f3fe;
  --spot-blue-text: #1f6c9f;
  --spot-blue-border: rgba(31, 108, 159, 0.22);
  --spot-sand-bg: #fbf3db;
  --spot-sand-text: #956400;
  --spot-sand-border: rgba(149, 100, 0, 0.24);
  --spot-rose-bg: #fbeaf1;
  --spot-rose-text: #99325f;
  --spot-rose-border: rgba(153, 50, 95, 0.22);
  --spot-green-bg: #edf3ec;
  --spot-green-text: #346538;
  --spot-green-border: rgba(52, 101, 56, 0.24);
  --spot-red-bg: #fdebec;
  --spot-red-text: #9f2f2d;
  --spot-red-border: rgba(159, 47, 45, 0.24);
  --spot-neutral-bg: #f1f0ec;
  --spot-neutral-text: #5f5e5a;
  --spot-neutral-border: rgba(95, 94, 90, 0.2);
  --ink-rgb: 17 17 17;
  --shadow-rgb: 17 17 17;
  --shadow-k: 0.16;
  --text-strong: #111111;
  --surface-inset: #f1f0ec;
  --btn-blue: #1f6c9f;
  --btn-blue-hover: #185a85;
  --btn-blue-border: #1f6c9f;
  --login-bg: #f7f6f3;
  --border-focus: 1px solid #1f6c9f;
}
:root[data-theme="light"] ::selection { background: var(--spot-blue-bg); color: var(--text-primary); }

/* --- Utilidades ---------------------------------------------------------- */
.ds-mono { font-family: var(--font-mono); font-size: var(--fs-meta); letter-spacing: 0; }
.ds-num { font-variant-numeric: tabular-nums; }
.ds-muted { color: var(--text-muted); }
.ds-secondary { color: var(--text-secondary); }
.ds-row { display: flex; align-items: center; gap: var(--sp-2); }
.ds-row--end { justify-content: flex-end; }
[hidden] { display: none !important; }
.ds-stack { display: flex; flex-direction: column; gap: var(--sp-3); }
/* Ritmo vertical de toda pantalla. Lo que cuelga directamente de una pantalla (cabecera, indicadores, pestañas, tarjetas y rejillas)
   se separa siempre --sp-4, y lo pone el hueco, no el margen de cada bloque, para que no se sume ni falte en ninguna pantalla nueva.
   Una pantalla nueva solo necesita class="ds-page" en su contenedor. */
.ds-page { display: flex; flex-direction: column; gap: var(--sp-4); }
/* :not([hidden]) sube la especificidad para ganar a los márgenes propios de cada bloque (.ds-page-head, .ds-kpis, .ds-tabs...). */
.ds-page > :not([hidden]) { margin-top: 0; margin-bottom: 0; }
/* Un corte de sección sí se separa más: el doble antes de su línea. */
.ds-page > .st-filters-head:not([hidden]) { margin-top: var(--sp-4); }
.ds-grow { flex: 1 1 auto; min-width: 0; }
.ds-nowrap { white-space: nowrap; }
.ds-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ds-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ds-icon { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

/* --- Cabecera de pantalla ------------------------------------------------- */
.ds-page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-4); }
.ds-title { font-family: var(--font-serif); font-size: var(--fs-title); font-weight: 400; letter-spacing: -0.02em; line-height: 1.2; color: var(--text-primary); }
.ds-sub { font-size: var(--fs-body); color: var(--text-secondary); margin-top: var(--sp-1); }

/* --- KPI ----------------------------------------------------------------- */
.ds-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--sp-3); margin-bottom: var(--sp-4); }
.ds-kpi {
  display: flex; flex-direction: column; gap: var(--sp-1); text-align: left;
  padding: var(--sp-3) var(--sp-4); background: var(--surface-card); border: 1px solid var(--line);
  border-radius: var(--radius-md); color: var(--text-primary); font: inherit; cursor: pointer;
  transition: var(--transition-fast);
}
.ds-kpi:hover { background: var(--surface-card-hover); }
.ds-kpi.is-active { border-color: var(--spot-blue-border); background: var(--spot-blue-bg); }
.ds-kpi-label { font-size: var(--fs-meta); text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-secondary); }
.ds-kpi-value { font-size: var(--fs-figure); line-height: 1.1; font-family: var(--font-mono); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.ds-kpi[data-tone="ok"] .ds-kpi-value { color: var(--spot-green-text); }
.ds-kpi[data-tone="warn"] .ds-kpi-value { color: var(--spot-sand-text); }
.ds-kpi[data-tone="danger"] .ds-kpi-value { color: var(--spot-red-text); }

/* --- Superficie y barra de herramientas ------------------------------------ */
.ds-card { background: var(--surface-base); border: 1px solid var(--line); border-radius: var(--radius-md); }
.ds-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--line); }
.ds-toolbar .ds-search { flex: 1 1 240px; max-width: 360px; }

/* --- Campos --------------------------------------------------------------- */
.ds-field { display: flex; flex-direction: column; gap: 6px; }
.ds-label { font-size: var(--fs-meta); text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-secondary); }
.ds-hint { font-size: var(--fs-meta); color: var(--text-muted); }
.ds-hint[data-tone="warn"] { color: var(--spot-sand-text); }
.ds-input, .ds-select, .ds-textarea {
  width: 100%; min-height: var(--control-h); padding: 6px 10px; font: inherit; font-size: var(--fs-body);
  color: var(--text-primary); background: var(--surface-card); border: 1px solid var(--line);
  border-radius: var(--radius-sm); transition: var(--transition-fast);
}
.ds-textarea { resize: vertical; line-height: 1.5; }
.ds-input::placeholder, .ds-textarea::placeholder { color: var(--text-muted); }
.ds-input:hover, .ds-select:hover, .ds-textarea:hover { border-color: var(--line-strong); }
.ds-input:focus-visible, .ds-select:focus-visible, .ds-textarea:focus-visible { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
.ds-input[aria-invalid="true"] { border-color: var(--spot-red-border); }
.ds-select--auto { width: auto; min-width: 180px; }
.ds-search { position: relative; }
.ds-search .ds-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.ds-search .ds-input { padding-left: 32px; }
.ds-check { display: flex; align-items: flex-start; gap: var(--sp-2); font-size: var(--fs-body); color: var(--text-primary); cursor: pointer; }
.ds-check input { margin-top: 3px; accent-color: var(--accent); }
.ds-check[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

/* --- Botones -------------------------------------------------------------- */
.ds-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--control-h);
  padding: 0 var(--sp-3); font: inherit; font-size: var(--fs-body); font-weight: 500; color: var(--text-primary);
  background: transparent; border: 1px solid var(--line); border-radius: var(--radius-sm);
  cursor: pointer; white-space: nowrap; transition: var(--transition-fast);
}
.ds-btn, .ds-icon-btn { text-decoration: none; }
.ds-btn:hover { background: var(--surface-card-hover); border-color: var(--line-strong); }
.ds-btn:active { transform: scale(0.98); }
.ds-btn:focus-visible, .ds-kpi:focus-visible, .ds-chip:focus-visible, .ds-th-sort:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.ds-btn:disabled, .ds-btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; transform: none; }
.ds-btn--solid { background: var(--solid-bg); border-color: var(--solid-bg); color: var(--on-solid); }
.ds-btn--solid:hover { background: var(--solid-hover); border-color: var(--solid-hover); }
.ds-btn--ghost { border-color: transparent; color: var(--text-secondary); }
.ds-btn--danger { color: var(--spot-red-text); border-color: var(--spot-red-border); }
.ds-btn--danger:hover { background: var(--spot-red-bg); border-color: var(--spot-red-border); }
.ds-btn--sm { min-height: var(--control-h-sm); padding: 0 10px; font-size: var(--fs-meta); }
.ds-icon-btn { display: inline-flex; align-items: center; justify-content: center; width: var(--control-h-sm); height: var(--control-h-sm); padding: 0; color: var(--text-secondary); background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm); cursor: pointer; transition: var(--transition-fast); }
.ds-icon-btn:hover { color: var(--text-primary); background: var(--surface-card-hover); border-color: var(--line); }
.ds-icon-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.ds-icon-btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.ds-link { padding: 0; font: inherit; color: var(--text-primary); background: none; border: 0; cursor: pointer; text-align: left; }
.ds-link:hover { color: var(--accent); }
.ds-link:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: 2px; }

/* --- Insignias y filtros ---------------------------------------------------- */
.ds-badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; font-size: var(--fs-meta); font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.05em; line-height: 1.5; white-space: nowrap;
  color: var(--spot-neutral-text); background: var(--spot-neutral-bg); border: 1px solid var(--spot-neutral-border); border-radius: var(--radius-pill);
}
.ds-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.ds-badge--plain::before { display: none; }
.ds-badge[data-tone="ok"] { color: var(--spot-green-text); background: var(--spot-green-bg); border-color: var(--spot-green-border); }
.ds-badge[data-tone="warn"] { color: var(--spot-sand-text); background: var(--spot-sand-bg); border-color: var(--spot-sand-border); }
.ds-badge[data-tone="danger"] { color: var(--spot-red-text); background: var(--spot-red-bg); border-color: var(--spot-red-border); }
.ds-badge[data-tone="info"] { color: var(--spot-blue-text); background: var(--spot-blue-bg); border-color: var(--spot-blue-border); }
.ds-chip { display: inline-flex; align-items: center; gap: 6px; min-height: var(--control-h-sm); padding: 0 10px; font: inherit; font-size: var(--fs-meta); color: var(--text-secondary); background: transparent; border: 1px solid var(--line); border-radius: var(--radius-pill); cursor: pointer; transition: var(--transition-fast); }
.ds-chip:hover { color: var(--text-primary); }
.ds-chip[aria-pressed="true"] { color: var(--text-primary); background: var(--surface-elevated); border-color: var(--line-strong); }

/* --- Tabla ------------------------------------------------------------------ */
.ds-table-wrap { overflow-x: auto; }
.ds-table { width: 100%; border-collapse: collapse; font-size: var(--fs-body); }
.ds-table th { padding: 10px var(--sp-3); font-size: var(--fs-meta); font-weight: 500; text-align: left; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-secondary); white-space: nowrap; border-bottom: 1px solid var(--line); background: var(--surface-base); }
.ds-table td { padding: var(--sp-3); vertical-align: middle; border-bottom: 1px solid var(--line-soft); }
.ds-table tbody tr:hover > td { background: var(--wash); }
.ds-table tr.is-expanded > td { background: var(--wash); border-bottom-color: transparent; }
.ds-table .is-right { text-align: right; }
.ds-table .is-center { text-align: center; }
.ds-col-toggle { width: 44px; }
.ds-th-sort { display: inline-flex; align-items: center; gap: 4px; padding: 0; font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; background: none; border: 0; cursor: pointer; }
.ds-th-sort:hover { color: var(--text-primary); }
.ds-th-sort .ds-icon { width: 12px; height: 12px; opacity: 0; }
.ds-th-sort[data-dir] .ds-icon { opacity: 1; }
.ds-cell { display: flex; flex-direction: column; gap: 2px; min-width: 0; max-width: 260px; }
.ds-cell--plan { min-width: 200px; }
.ds-clamp { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; }
.ds-table th.is-sticky, .ds-table td.is-sticky { position: sticky; right: 0; background: var(--surface-base); border-left: 1px solid var(--line-soft); }
.ds-table tbody tr:hover > td.is-sticky { background: var(--surface-card-hover); }
.ds-table tr.is-expanded > td.is-sticky { background: var(--surface-card-hover); }
.ds-detail > td { padding: var(--sp-4) var(--sp-5); background: var(--wash); border-bottom: 1px solid var(--line-soft); }
.ds-detail-grid { display: grid; grid-template-columns: minmax(240px, 1fr) minmax(280px, 1.4fr); gap: var(--sp-5); }
.ds-kv { display: grid; grid-template-columns: max-content 1fr; gap: var(--sp-2) var(--sp-4); align-items: center; }
.ds-kv dt { font-size: var(--fs-meta); text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-secondary); }
.ds-kv dd { margin: 0; min-width: 0; }
.ds-counter { display: inline-flex; align-items: center; gap: 4px; min-width: 38px; height: var(--control-h-sm); padding: 0 8px; justify-content: center; font: inherit; font-family: var(--font-mono); font-size: var(--fs-meta); font-variant-numeric: tabular-nums; color: var(--text-muted); background: transparent; border: 1px solid var(--line-soft); border-radius: var(--radius-sm); cursor: default; }
.ds-counter .ds-icon { width: 13px; height: 13px; }
.ds-counter[data-tone] { cursor: pointer; }
.ds-counter[data-tone="warn"] { color: var(--spot-sand-text); background: var(--spot-sand-bg); border-color: var(--spot-sand-border); }
.ds-counter[data-tone="danger"] { color: var(--spot-red-text); background: var(--spot-red-bg); border-color: var(--spot-red-border); }
.ds-counter[data-tone="info"] { color: var(--spot-blue-text); background: var(--spot-blue-bg); border-color: var(--spot-blue-border); }
.ds-counter[data-tone]:hover { filter: brightness(1.15); }
.ds-counter:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.ds-pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--line); font-size: var(--fs-meta); color: var(--text-secondary); }
.ds-pager .ds-select { width: auto; min-height: var(--control-h-sm); font-size: var(--fs-meta); }
.ds-empty { padding: var(--sp-6) var(--sp-4); text-align: center; color: var(--text-secondary); font-size: var(--fs-body); }
.ds-empty strong { display: block; margin-bottom: var(--sp-1); color: var(--text-primary); font-weight: 500; }
.ds-skeleton { height: 14px; border-radius: var(--radius-xs); background: linear-gradient(90deg, var(--surface-card) 25%, var(--surface-card-hover) 50%, var(--surface-card) 75%); background-size: 200% 100%; animation: ds-shimmer 1.4s linear infinite; }
@keyframes ds-shimmer { to { background-position: -200% 0; } }

/* --- Menú contextual -------------------------------------------------------- */
.ds-menu { position: fixed; z-index: var(--z-menu); min-width: 232px; max-height: calc(100vh - 24px); overflow-y: auto; padding: var(--sp-1); background: var(--surface-elevated); border: 1px solid var(--line-pop); border-radius: var(--radius-md); box-shadow: var(--pop-shadow); }
.ds-menu-label { padding: var(--sp-2) var(--sp-3) var(--sp-1); font-size: var(--fs-meta); text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
.ds-menu-item { display: flex; align-items: center; gap: var(--sp-2); width: 100%; padding: 7px var(--sp-3); font: inherit; font-size: var(--fs-body); color: var(--text-primary); text-align: left; background: none; border: 0; border-radius: var(--radius-xs); cursor: pointer; }
.ds-menu-item:hover, .ds-menu-item:focus-visible { outline: none; background: var(--wash-2); }
.ds-menu-item[data-tone="danger"] { color: var(--spot-red-text); }
.ds-menu-item .ds-icon { color: var(--text-secondary); }
.ds-menu-sep { height: 1px; margin: var(--sp-1) 0; background: var(--line); }

/* --- Modal -------------------------------------------------------------------- */
.ds-scrim { position: fixed; inset: 0; z-index: var(--z-modal); display: flex; align-items: center; justify-content: center; padding: var(--sp-4); background: var(--scrim); }
.ds-modal { display: flex; flex-direction: column; width: 100%; max-width: 480px; max-height: calc(100vh - 32px); background: var(--surface-base); border: 1px solid var(--line-pop); border-radius: var(--radius-md); }
.ds-modal--wide { max-width: 640px; }
.ds-modal--xl { max-width: 1040px; }
.ds-modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--line); }
.ds-modal-title { font-family: var(--font-serif); font-size: var(--fs-title); font-weight: 400; letter-spacing: -0.02em; line-height: 1.2; }
.ds-modal-body { display: flex; flex-direction: column; gap: var(--sp-4); padding: var(--sp-5); overflow-y: auto; font-size: var(--fs-body); color: var(--text-secondary); }
.ds-modal-body strong { color: var(--text-primary); font-weight: 500; }
.ds-modal-foot { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--line); }
@media (prefers-reduced-motion: no-preference) {
  .ds-scrim { animation: ds-fade 0.16s ease-out; }
  .ds-modal { animation: ds-rise 0.2s cubic-bezier(0.16, 1, 0.3, 1); }
  .ds-menu { animation: ds-fade 0.12s ease-out; }
  .ds-toast { animation: ds-rise 0.2s cubic-bezier(0.16, 1, 0.3, 1); }
}
@keyframes ds-fade { from { opacity: 0; } }
@keyframes ds-rise { from { opacity: 0; transform: translateY(8px); } }

/* --- Avisos efímeros --------------------------------------------------------- */
.ds-toasts { position: fixed; right: var(--sp-4); bottom: var(--sp-4); z-index: var(--z-toast); display: flex; flex-direction: column; gap: var(--sp-2); max-width: min(380px, calc(100vw - 32px)); }
.ds-toast { display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); font-size: var(--fs-body); color: var(--text-primary); background: var(--surface-elevated); border: 1px solid var(--line-pop); border-left-width: 3px; border-radius: var(--radius-sm); }
.ds-toast[data-tone="ok"] { border-left-color: var(--spot-green-text); }
.ds-toast[data-tone="warn"] { border-left-color: var(--spot-sand-text); }
.ds-toast[data-tone="danger"] { border-left-color: var(--spot-red-text); }
.ds-toast a, .ds-toast button { color: var(--accent); font: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; }

/* --- Cronología ---------------------------------------------------------------- */
.ds-timeline { list-style: none; margin: 0; padding: 0; }
.ds-timeline-day { padding: var(--sp-3) 0 var(--sp-1); font-size: var(--fs-meta); text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
.ds-timeline-item { display: grid; grid-template-columns: 52px 1fr; gap: var(--sp-3); padding: var(--sp-2) 0; border-bottom: 1px solid var(--line-soft); }
.ds-timeline-item p { margin-top: 2px; color: var(--text-secondary); overflow-wrap: anywhere; }

/* --- Editor de texto básico ------------------------------------------------------ */
.ds-editor { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-card); transition: var(--transition-fast); }
.ds-editor:focus-within { border-color: var(--accent); box-shadow: var(--focus-ring); }
.ds-editor-bar { display: flex; gap: 2px; padding: var(--sp-1); border-bottom: 1px solid var(--line-soft); }
.ds-editor-bar .ds-icon-btn { font-size: var(--fs-body); font-weight: 600; }
.ds-editor-area { min-height: 84px; max-height: 280px; overflow-y: auto; padding: var(--sp-2) var(--sp-3); font-size: var(--fs-body); line-height: 1.55; color: var(--text-primary); outline: none; overflow-wrap: anywhere; }
.ds-editor-area:empty::before { content: attr(data-placeholder); color: var(--text-muted); }
.ds-editor-area ul, .ds-editor-area ol { padding-left: 1.25em; }
.ds-editor-area a { color: var(--accent); }
.ds-editor-area blockquote { padding-left: var(--sp-3); border-left: 2px solid var(--line); color: var(--text-secondary); }
.ds-save-state { font-size: var(--fs-meta); font-family: var(--font-mono); color: var(--text-muted); min-height: 1.5em; }
.ds-save-state[data-tone="ok"] { color: var(--spot-green-text); }
.ds-save-state[data-tone="danger"] { color: var(--spot-red-text); }

/* --- Gráficas -------------------------------------------------------------------- */
.ds-chart { position: relative; width: 100%; }
.ds-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.ds-chart-grid { stroke: var(--line-soft); stroke-width: 1; }
.ds-chart-axis { fill: var(--text-muted); font-family: var(--font-mono); font-size: var(--fs-meta); }
.ds-chart-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.ds-chart-bar { fill: var(--accent); }
.ds-chart-dot { fill: var(--accent); stroke: var(--surface-base); stroke-width: 2; }
.ds-chart-cross { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.ds-chart-sel { fill: color-mix(in srgb, var(--accent) 14%, transparent); stroke: var(--accent); stroke-width: 1; }
.ds-chart-reset { position: absolute; top: 0; right: 0; }
.ds-preview--tall { min-height: 68vh; }
.ds-chart-tip { position: absolute; z-index: 2; pointer-events: none; padding: 6px 10px; font-size: var(--fs-meta); color: var(--text-primary); background: var(--surface-elevated); border: 1px solid var(--line-pop); border-radius: var(--radius-sm); white-space: nowrap; transform: translate(-50%, -100%); }
.ds-chart-tip b { display: block; font-family: var(--font-mono); font-size: var(--fs-body); font-weight: 500; }

/* --- Navegador de documentos ------------------------------------------------------ */
.ds-split { display: grid; grid-template-columns: minmax(260px, 2fr) 3fr; gap: var(--sp-4); min-height: 56vh; }
.ds-split-list { overflow-y: auto; max-height: 64vh; border-right: 1px solid var(--line); padding-right: var(--sp-3); }
.ds-split-view { display: flex; flex-direction: column; gap: var(--sp-2); min-width: 0; }
.ds-preview { flex: 1 1 auto; display: flex; align-items: center; justify-content: center; min-height: 320px; overflow: hidden; background: var(--surface-card); border: 1px solid var(--line-soft); border-radius: var(--radius-sm); color: var(--text-muted); }
.ds-preview img, .ds-preview iframe { width: 100%; height: 100%; min-height: 320px; border: 0; object-fit: contain; }
.ds-group > summary { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-2) 0; font-size: var(--fs-meta); text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-secondary); cursor: pointer; list-style: none; }
.ds-group > summary::-webkit-details-marker { display: none; }
.ds-doc { display: flex; align-items: center; gap: var(--sp-2); padding: 6px var(--sp-2); border-radius: var(--radius-sm); }
.ds-doc[aria-current="true"] { background: var(--spot-blue-bg); }
.ds-doc[data-missing="true"] .ds-link { color: var(--text-muted); text-decoration: line-through; }

/* --- Adaptación a pantallas estrechas -------------------------------------------- */
@media (max-width: 900px) {
  .ds-detail-grid, .ds-split { grid-template-columns: 1fr; }
  .ds-split-list { max-height: 30vh; border-right: 0; padding-right: 0; }
  .ds-page-head { flex-direction: column; align-items: flex-start; }
}
@media (max-width: 640px) {
  .ds-scrim { padding: 0; align-items: flex-end; }
  .ds-modal { max-width: none; max-height: 92vh; border-radius: var(--radius-md) var(--radius-md) 0 0; }
}
@media (prefers-reduced-motion: reduce) {
  .ds-skeleton { animation: none; }
  .ds-btn:active { transform: none; }
}

/* --- Pestañas ----------------------------------------------------------------------------------------------------- */
.ds-tabs { display: flex; gap: 2px; margin: var(--sp-4) 0 var(--sp-3); border-bottom: 1px solid var(--line); overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
.ds-tab { display: inline-flex; align-items: center; gap: 6px; padding: 8px var(--sp-3); font: inherit; font-size: var(--fs-body); color: var(--text-secondary); white-space: nowrap; background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; transition: var(--transition-fast); }
.ds-tab:hover { color: var(--text-primary); }
.ds-tab[aria-selected="true"] { color: var(--text-primary); border-bottom-color: var(--accent); }
.ds-tab:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-xs); }
button.ds-badge { font: inherit; font-size: var(--fs-meta); font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; cursor: pointer; }
button.ds-badge:hover { filter: brightness(1.2); }

/* --- Campos de fichero y fecha en tema oscuro ------------------------------------------------------------------------ */
.ds-input, .ds-select, .ds-textarea { color-scheme: var(--scheme); }
.ds-input[type="file"] { padding: 3px; }
.ds-input[type="file"]::file-selector-button { margin-right: var(--sp-3); padding: 4px 10px; font: inherit; font-size: var(--fs-meta); color: var(--text-primary); background: var(--surface-elevated); border: 1px solid var(--line); border-radius: var(--radius-xs); cursor: pointer; }

/* --- Barras de desplazamiento en tema oscuro ---------------------------------------------------------------------------- */
.ds-modal-body, .ds-split-list, .ds-table-wrap, .ds-menu, .ds-editor-area { scrollbar-width: thin; scrollbar-color: var(--thumb) transparent; }

/* --- Panel lateral (modal con size: 'drawer') ----------------------------------------------------------------------------- */
.ds-scrim--drawer { justify-content: flex-end; padding: 0; }
.ds-modal--drawer { max-width: 640px; height: 100vh; max-height: none; border-radius: 0; border-width: 0 0 0 1px; }
.ds-modal--drawer .ds-modal-body { flex: 1 1 auto; color: var(--text-primary); }
@media (prefers-reduced-motion: no-preference) { .ds-modal--drawer { animation: ds-slide 0.26s cubic-bezier(0.16, 1, 0.3, 1); } }
@keyframes ds-slide { from { opacity: 0; transform: translateX(24px); } }
@media (max-width: 640px) { .ds-modal--drawer { max-width: none; max-height: none; border-radius: 0; } }

/* --- Gráficas de varias series --------------------------------------------------------------------------------------------- */
.ds-legend { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); margin: 0 0 var(--sp-3); padding: 0; list-style: none; font-size: var(--fs-meta); color: var(--text-secondary); }
.ds-legend li { display: inline-flex; align-items: center; gap: var(--sp-2); }
.ds-swatch { display: inline-block; width: 12px; height: 12px; flex: none; background: var(--c); border-radius: 3px; }
.ds-swatch.is-dash { background: repeating-linear-gradient(90deg, var(--c) 0 4px, transparent 4px 7px); height: 3px; border-radius: 0; }
.ds-series-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.ds-chart-tip--multi { display: flex; flex-direction: column; gap: 2px; transform: translateX(-50%); min-width: 130px; }
.ds-tip-row { display: flex; align-items: center; gap: var(--sp-2); }
.ds-tip-row b { margin-left: auto; padding-left: var(--sp-3); font-family: var(--font-mono); font-weight: 500; }

/* --- Buscador global (cabecera) ------------------------------------------------ */
.global-search { position: relative; display: flex; align-items: center; width: 280px; }
.global-search > .ds-icon { position: absolute; left: var(--sp-3); color: var(--text-muted); pointer-events: none; }
.global-search .ds-input { width: 100%; padding-left: 34px; padding-right: 58px; }
.gs-key { position: absolute; right: var(--sp-2); padding: 1px 6px; font: inherit; font-size: var(--fs-meta); color: var(--text-muted); border: 1px solid var(--line-strong); border-radius: var(--radius-xs); pointer-events: none; }
.gs-results { position: absolute; top: calc(100% + 6px); right: 0; z-index: var(--z-menu); width: 380px; max-width: calc(100vw - 24px); max-height: 420px; overflow-y: auto; padding: var(--sp-1); background: var(--surface-elevated); border: 1px solid var(--line-pop); border-radius: var(--radius-md); box-shadow: var(--pop-shadow); }
.gs-group { padding: var(--sp-2) var(--sp-3) var(--sp-1); font-size: var(--fs-meta); text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
.gs-item { display: flex; flex-direction: column; gap: 2px; width: 100%; padding: 7px var(--sp-3); font: inherit; text-align: left; color: var(--text-primary); background: none; border: 0; border-radius: var(--radius-xs); cursor: pointer; }
.gs-item strong { font-size: var(--fs-body); font-weight: 600; }
.gs-item span { font-size: var(--fs-meta); color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gs-item[aria-selected="true"], .gs-item:hover { background: var(--wash-2); }
.gs-empty { margin: 0; padding: var(--sp-3); font-size: var(--fs-body); color: var(--text-secondary); }
/* --- Centro de notificaciones (campana de la cabecera) -------------------------------- */
.notif { position: relative; }
.notif-btn { position: relative; }
.notif-badge { position: absolute; top: -4px; right: -4px; min-width: 16px; height: 16px; padding: 0 4px; font-size: 10px; font-weight: 600; line-height: 16px; text-align: center; color: #fff; background: var(--spot-red-text, #c0392b); border-radius: 8px; }
.notif-panel { position: absolute; top: calc(100% + 6px); right: 0; z-index: var(--z-menu); width: 400px; max-width: calc(100vw - 24px); display: flex; flex-direction: column; background: var(--surface-elevated); border: 1px solid var(--line-pop); border-radius: var(--radius-md); box-shadow: var(--pop-shadow); }
.notif-panel[hidden] { display: none; }
.notif-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--line); }
.notif-list { max-height: 440px; overflow-y: auto; padding: var(--sp-1); }
.notif-item { display: flex; align-items: flex-start; gap: var(--sp-2); padding: 8px var(--sp-3); color: var(--text-primary); text-decoration: none; border-radius: var(--radius-xs); }
.notif-item:hover, .notif-item:focus-visible { outline: none; background: var(--wash-2); }
.notif-item.is-unread { background: var(--wash-1, var(--wash-2)); }
.notif-item.is-unread .notif-text strong::before { content: ''; display: inline-block; width: 6px; height: 6px; margin-right: 6px; vertical-align: middle; background: var(--spot-red-text, #c0392b); border-radius: 50%; }
.notif-ic { color: var(--text-secondary); padding-top: 2px; }
.notif-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.notif-text strong { font-size: var(--fs-body); font-weight: 600; }
.notif-text span { font-size: var(--fs-meta); color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notif-time { flex: none; font-size: var(--fs-meta); color: var(--text-muted); }
@media (max-width: 900px) { .global-search { width: 180px; } .gs-key { display: none; } .global-search .ds-input { padding-right: var(--sp-3); } }
@media (max-width: 600px) { .global-search { width: 130px; } }
