/* ==========================================================================
   Lab4Leads v3 — hoja de estilo única (CRM + sitio público)
   --------------------------------------------------------------------------
   Sin frameworks, sin build. Se sube tal cual por FTP.

   Orden del archivo:
     1. Tokens              6. Tablas            11. Modal
     2. Reset y base        7. Formularios       12. Paginación y pestañas
     3. Utilidades          8. Botones           13. KPI, timeline, vacío
     4. Estructura CRM      9. Badges            14. Sitio público
     5. Tarjetas           10. Alertas           15. Responsive y a11y

   Convención de nombres: bloque `.card`, elemento `.card__title`,
   modificador `.btn--primary`, estado `.is-active`.
   ========================================================================== */

/* ==========================================================================
   1. TOKENS
   --------------------------------------------------------------------------
   Todo el color, el espaciado y la tipografía salen de aquí. El modo oscuro
   NO redefine componentes: solo reasigna estos mismos tokens, de modo que
   añadir un componente no obliga a escribirlo dos veces.
   ========================================================================== */

:root {
  color-scheme: light;

  /* --- Marca: petróleo sobrio, legible sobre blanco y sobre oscuro ------ */
  --brand-50:  #eef7f8;
  --brand-100: #d2ebee;
  --brand-200: #a6d6dd;
  --brand-300: #6dbac5;
  --brand-400: #3d99a6;
  --brand-500: #1f7e8c;
  --brand-600: #166874;
  --brand-700: #12525c;
  --brand-800: #0e3f47;
  --brand-900: #0a2d33;

  /* --- Grises neutros, escalonados para contraste predecible ----------- */
  --gray-0:   #ffffff;
  --gray-25:  #fbfcfd;
  --gray-50:  #f5f7f9;
  --gray-100: #edf1f4;
  --gray-200: #e0e6eb;
  --gray-300: #c9d2da;
  --gray-400: #98a4b0;
  --gray-500: #6a7784;
  --gray-600: #4e5a66;
  --gray-700: #39434d;
  --gray-800: #252d35;
  --gray-900: #161c22;
  --gray-950: #0c1116;

  /* --- Semánticos ------------------------------------------------------ */
  /* Coinciden con LeadStatus::badge(): info, warning, secondary, dark,
     primary, success. `danger` se añade para acciones destructivas. */
  --success:      #1a7a49;
  --success-soft: #e6f4ec;
  --success-line: #a9d9be;

  --warning:      #8a5a00;
  --warning-soft: #fdf3df;
  --warning-line: #ecd19a;

  --danger:       #ad2a20;
  --danger-soft:  #fdeceb;
  --danger-line:  #f0b7b3;

  --info:         #15628f;
  --info-soft:    #e7f1f9;
  --info-line:    #a9cbe4;

  --secondary:      var(--gray-500);
  --secondary-soft: var(--gray-100);
  --secondary-line: var(--gray-300);

  --dark:      var(--gray-800);
  --dark-soft: var(--gray-200);
  --dark-line: var(--gray-400);

  --primary:      var(--brand-600);
  --primary-soft: var(--brand-50);
  --primary-line: var(--brand-200);

  /* --- Roles de superficie y texto ------------------------------------- */
  --bg:            var(--gray-50);
  --surface:       var(--gray-0);
  --surface-2:     var(--gray-25);
  --surface-sunken: var(--gray-100);
  --surface-hover: var(--gray-50);

  --text:          var(--gray-900);
  --text-muted:    var(--gray-600);
  --text-subtle:   var(--gray-500);
  --text-invert:   var(--gray-0);

  --border:        var(--gray-200);
  --border-strong: var(--gray-300);

  --link:       var(--brand-700);
  --link-hover: var(--brand-800);

  --focus: var(--brand-500);

  /* La banda de "modo pruebas" tiene tokens propios porque los semánticos se
     invierten en oscuro: el ámbar pasa a ser claro y el texto blanco quedaría
     ilegible justo en el aviso que más se tiene que leer. */
  --envbar-bg: var(--warning);
  --envbar-text: #ffffff;
  --envbar-tag-bg: rgba(255, 255, 255, 0.22);

  /* Halo del foco y del error como valores propios: `color-mix()` no está en
     los navegadores de todos los móviles que usa el equipo comercial, y si la
     declaración se invalida el foco deja de verse. */
  --focus-ring: rgba(31, 126, 140, 0.28);
  --danger-ring: rgba(173, 42, 32, 0.24);

  --primary-hover: var(--brand-700);
  --danger-hover: #8f211a;
  --success-hover: #14603a;

  /* Barra lateral: oscura en ambos modos, así el CRM se lee como una
     herramienta y no como un documento. */
  --sidebar-bg:         var(--brand-900);
  --sidebar-bg-hover:   #123c44;
  --sidebar-bg-active:  var(--brand-700);
  --sidebar-text:       #cfe3e6;
  --sidebar-text-muted: #85a8ad;
  --sidebar-text-active: #ffffff;
  --sidebar-border:     #0d353c;

  /* --- Espaciado (escala de 4px) --------------------------------------- */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.25rem;
  --sp-6: 1.5rem;
  --sp-8: 2rem;
  --sp-10: 2.5rem;
  --sp-12: 3rem;
  --sp-16: 4rem;

  /* --- Radios ---------------------------------------------------------- */
  --radius-sm: 4px;
  --radius:    8px;
  --radius-lg: 12px;
  --radius-xl: 18px;
  --radius-pill: 999px;

  /* --- Sombras --------------------------------------------------------- */
  --shadow-xs: 0 1px 2px rgba(13, 27, 34, 0.06);
  --shadow-sm: 0 1px 3px rgba(13, 27, 34, 0.08), 0 1px 2px rgba(13, 27, 34, 0.04);
  --shadow:    0 4px 12px rgba(13, 27, 34, 0.08);
  --shadow-lg: 0 12px 32px rgba(13, 27, 34, 0.14);

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

  --fs-xs: 0.75rem;
  --fs-sm: 0.8125rem;
  --fs-base: 0.9375rem;
  --fs-md: 1rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.375rem;
  --fs-2xl: 1.75rem;
  --fs-3xl: 2.25rem;
  --fs-4xl: 3rem;

  --lh-tight: 1.2;
  --lh: 1.55;

  --fw-normal: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;

  /* --- Medidas de la estructura ---------------------------------------- */
  --sidebar-w: 258px;
  --sidebar-w-collapsed: 68px;
  --header-h: 60px;
  --content-max: 1400px;
  --prose-max: 68ch;

  --transition: 160ms ease;
  /* El orden importa y se rompe fácil: el fondo oscuro tiene que quedar por
     DEBAJO del panel lateral. Estaba al revés, así que en móvil el backdrop
     se dibujaba sobre el menú y se comía los clics: se veía, pero no se podía
     pulsar nada. */
  --z-header: 30;
  --z-backdrop: 40;
  --z-sidebar: 50;
  --z-modal: 60;
  --z-toast: 70;
}

/* Modo oscuro: solo tokens. */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --bg:             var(--gray-950);
    --surface:        #141b21;
    --surface-2:      #182027;
    --surface-sunken: #0f151a;
    --surface-hover:  #1d262e;

    --text:        #e7edf1;
    --text-muted:  #a4b1bc;
    --text-subtle: #7e8b97;
    --text-invert: var(--gray-950);

    --border:        #26313a;
    --border-strong: #35424d;

    --link:       var(--brand-300);
    --link-hover: var(--brand-200);
    --focus:      var(--brand-300);

    --envbar-bg: #e0b465;
    --envbar-text: #2b1f08;
    --envbar-tag-bg: rgba(0, 0, 0, 0.16);

    --focus-ring: rgba(109, 186, 197, 0.3);
    --danger-ring: rgba(240, 132, 124, 0.28);

    --primary-hover: var(--brand-500);
    --danger-hover: #c9564d;
    --success-hover: #7ed6a6;

    --primary:      var(--brand-400);
    --primary-soft: #10333a;
    --primary-line: #1d5763;

    --success:      #5cc98d;
    --success-soft: #123024;
    --success-line: #1f5a3d;

    --warning:      #e0b465;
    --warning-soft: #33260d;
    --warning-line: #5e4718;

    --danger:       #f0847c;
    --danger-soft:  #371715;
    --danger-line:  #6b2b26;

    --info:         #7ab8e0;
    --info-soft:    #102a3a;
    --info-line:    #1d4a63;

    --secondary:      var(--gray-400);
    --secondary-soft: #1d262e;
    --secondary-line: #35424d;

    --dark:      #cbd5dd;
    --dark-soft: #1d262e;
    --dark-line: #3b4854;

    --sidebar-bg:         #0d1418;
    --sidebar-bg-hover:   #172226;
    --sidebar-bg-active:  var(--brand-700);
    --sidebar-border:     #1c272c;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.45);
    --shadow:    0 4px 14px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 14px 36px rgba(0, 0, 0, 0.6);
  }
}

/* ==========================================================================
   2. RESET Y BASE
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--fw-normal) var(--fs-base) / var(--lh) var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0 0 var(--sp-3);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-tight);
  color: var(--text);
  text-wrap: balance;
}

h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }
h5, h6 { font-size: var(--fs-base); }

p { margin: 0 0 var(--sp-4); }
p:last-child { margin-bottom: 0; }

a {
  color: var(--link);
  text-decoration: none;
}

a:hover { color: var(--link-hover); text-decoration: underline; }

img, svg, video { max-width: 100%; height: auto; display: block; }

ul, ol { margin: 0 0 var(--sp-4); padding-left: var(--sp-5); }

hr {
  margin: var(--sp-6) 0;
  border: 0;
  border-top: 1px solid var(--border);
}

code, kbd, pre, samp { font-family: var(--font-mono); font-size: 0.9em; }

code {
  padding: 0.1em 0.35em;
  background: var(--surface-sunken);
  border-radius: var(--radius-sm);
}

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0.15em 0.4em;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-align: center;
  color: var(--text);
}

/* Un único anillo de foco para todo lo interactivo. */
:focus { outline: none; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

::selection {
  background: var(--brand-200);
  color: var(--brand-900);
}

/* ==========================================================================
   3. UTILIDADES
   ========================================================================== */

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: -100px;
  left: var(--sp-3);
  z-index: var(--z-toast);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-weight: var(--fw-semibold);
}

.skip-link:focus { top: var(--sp-3); }

.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.small { font-size: var(--fs-sm); }
.tiny { font-size: var(--fs-xs); }
.strong { font-weight: var(--fw-semibold); }
.mono { font-family: var(--font-mono); }
.nowrap { white-space: nowrap; }
.truncate { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }

.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.text-info { color: var(--info); }
.text-primary { color: var(--primary); }

.stack > * + * { margin-top: var(--sp-4); }
.stack--tight > * + * { margin-top: var(--sp-2); }
.stack--loose > * + * { margin-top: var(--sp-6); }

.row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
}

.row--between { justify-content: space-between; }
.row--end { justify-content: flex-end; }
.row--middle { align-items: center; }

.grid {
  display: grid;
  gap: var(--sp-4);
}

/* Rejilla auto-ajustable: sin media queries, se adapta al ancho disponible. */
.grid--auto { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid--4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.divider { height: 1px; background: var(--border); margin: var(--sp-5) 0; }

.prose { max-width: var(--prose-max); }

/* ==========================================================================
   4. ESTRUCTURA DEL CRM
   --------------------------------------------------------------------------
   Móvil primero: la barra lateral es un panel deslizante fuera de pantalla.
   A partir de 1024px pasa a columna fija y puede colapsarse a solo iconos
   (clase `is-collapsed`, que persiste en localStorage desde app.js).
   ========================================================================== */

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Barra lateral ---------------------------------------------------- */

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: var(--z-sidebar);
  width: min(84vw, 300px);
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  border-right: 1px solid var(--sidebar-border);
  transform: translateX(-100%);
  transition: transform var(--transition);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.app.is-sidebar-open .sidebar { transform: translateX(0); }

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--header-h);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--sidebar-border);
  color: var(--sidebar-text-active);
  font-weight: var(--fw-bold);
  font-size: var(--fs-md);
  letter-spacing: 0.01em;
}

.sidebar__brand:hover { color: var(--sidebar-text-active); text-decoration: none; }

/* Marca cuadrada del logo. Se usa en la barra lateral del CRM y en la
   cabecera del sitio público, de ahí el nombre independiente del bloque. */
.brand-mark,
.sidebar__mark {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  background: var(--brand-500);
  color: #fff;
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
}

.sidebar__nav {
  flex: 1 1 auto;
  padding: var(--sp-3) var(--sp-2) var(--sp-8);
}

.sidebar__group + .sidebar__group { margin-top: var(--sp-5); }

.sidebar__group-title {
  margin: 0 0 var(--sp-2);
  padding: 0 var(--sp-3);
  color: var(--sidebar-text-muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sidebar__list { margin: 0; padding: 0; list-style: none; }

.sidebar__link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 44px;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius);
  color: var(--sidebar-text);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  transition: background var(--transition), color var(--transition);
}

.sidebar__link:hover {
  background: var(--sidebar-bg-hover);
  color: var(--sidebar-text-active);
  text-decoration: none;
}

.sidebar__link.is-active {
  background: var(--sidebar-bg-active);
  color: var(--sidebar-text-active);
  font-weight: var(--fw-semibold);
}

.sidebar__link:focus-visible { outline-color: var(--brand-200); }

.sidebar__icon {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 1.7;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.85;
}

.sidebar__label { flex: 1 1 auto; min-width: 0; }

.sidebar__count {
  flex: 0 0 auto;
  padding: 0.1em 0.5em;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.14);
  color: var(--sidebar-text-active);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
}

.sidebar__footer {
  padding: var(--sp-3) var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--sidebar-border);
  color: var(--sidebar-text-muted);
  font-size: var(--fs-xs);
}

/* Fondo oscuro que cubre el contenido mientras el panel está abierto. */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-backdrop);
  background: rgba(8, 16, 20, 0.55);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition), visibility var(--transition);
}

.app.is-sidebar-open .backdrop { opacity: 1; visibility: visible; }

/* --- Cabecera --------------------------------------------------------- */

.header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--header-h);
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}

.header__title {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-left: auto;
}

.header__user {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius);
  color: var(--text);
}

.header__user:hover { background: var(--surface-hover); text-decoration: none; }

/* Nombre y rol apilados; el bloque entero desaparece en móvil, donde solo
   queda el avatar. */
.header__user-meta { display: none; line-height: 1.25; }
.header__user-name { display: block; font-size: var(--fs-sm); font-weight: var(--fw-semibold); }
.header__user-role { display: block; font-size: var(--fs-xs); color: var(--text-muted); }

.avatar {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid var(--primary-line);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  letter-spacing: 0.02em;
}

.avatar--lg { width: 56px; height: 56px; font-size: var(--fs-md); }

/* Botón hamburguesa / colapsar. */
.icon-btn {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

.icon-btn svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --- Contenido -------------------------------------------------------- */

.main {
  flex: 1 1 auto;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--sp-4) var(--sp-3) var(--sp-12);
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}

.page-head__text { flex: 1 1 260px; min-width: 0; }
.page-head__title { margin: 0; font-size: var(--fs-xl); }
.page-head__sub { margin: var(--sp-1) 0 0; color: var(--text-muted); font-size: var(--fs-sm); }
.page-head__actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin: 0 0 var(--sp-3);
  padding: 0;
  list-style: none;
  font-size: var(--fs-sm);
  color: var(--text-subtle);
}

.breadcrumb li + li::before { content: "/"; margin-right: var(--sp-2); color: var(--border-strong); }

/* Bandas de entorno: deben verse a la primera, no ser decorativas. */
.envbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2) var(--sp-4);
  padding: var(--sp-2) var(--sp-4);
  background: var(--envbar-bg);
  color: var(--envbar-text);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  text-align: center;
  letter-spacing: 0.01em;
}

.envbar--env { background: var(--gray-800); color: #fff; }
.envbar--env .envbar__tag { background: rgba(255, 255, 255, 0.22); }

.envbar__tag {
  padding: 0.1em 0.6em;
  border-radius: var(--radius-pill);
  background: var(--envbar-tag-bg);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Zona de alertas flash: aria-live la anuncia; el hueco no reserva espacio. */
.flash-zone { display: grid; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.flash-zone:empty { display: none; margin: 0; }

/* ==========================================================================
   5. TARJETAS
   ========================================================================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}

.card + .card { margin-top: var(--sp-4); }

.card__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}

.card__title {
  margin: 0;
  flex: 1 1 auto;
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
}

.card__sub { margin: var(--sp-1) 0 0; font-size: var(--fs-sm); color: var(--text-muted); font-weight: var(--fw-normal); }

.card__actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-left: auto; }

.card__body { padding: var(--sp-5); }
.card__body--flush { padding: 0; }

.card__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Lista de pares etiqueta/valor, para la ficha de un lead o cliente. */
/* Ficha de datos: pares etiqueta / valor.
   Se reparte en columnas según el ancho disponible en vez de apilarse
   siempre: una ficha de ocho campos en una sola columna ocupaba una pantalla
   entera y obligaba a hacer scroll para ver algo que cabe de un vistazo. */
.datalist {
  margin: 0;
  display: grid;
  gap: 0;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

/* La línea inferior separa filas sin añadir espacio: es lo que permite
   apretar el interlineado sin que se lea como un bloque continuo. */
.datalist__row {
  display: grid;
  gap: 0.1rem;
  padding: var(--sp-2) var(--sp-3) var(--sp-2) 0;
  border-bottom: 1px solid var(--border-subtle, var(--border));
  min-width: 0;
}

.datalist__key {
  font-size: 0.7rem;
  font-weight: var(--fw-semibold);
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1.3;
}

.datalist__val {
  margin: 0;
  font-size: var(--fs-sm);
  line-height: 1.35;
  overflow-wrap: anywhere;
}

/* Un valor destacado (un importe, un total) puede pedir más peso. */
.datalist__val--strong { font-weight: var(--fw-semibold); font-size: var(--fs-base); }

/* Las últimas filas de cada columna no llevan línea: en una rejilla no se
   puede saber cuáles son con :last-child, así que se quita en todas y se
   pone arriba, que sí es predecible. */
.datalist__row { border-bottom: 0; border-top: 1px solid var(--border-subtle, var(--border)); }
.datalist__row:first-child { border-top: 0; }

/* Con varias columnas la primera fila de cada una tampoco debe llevar línea
   superior; se resuelve dejándola solo a partir de la segunda fila real. */
@media (min-width: 560px) {
  .datalist { column-gap: var(--sp-5); }
}

/* Variante en línea para fichas estrechas: etiqueta a la izquierda, valor a
   la derecha. Se usa donde la ficha vive en una columna lateral. */
.datalist--inline { grid-template-columns: 1fr; }

.datalist--inline .datalist__row {
  grid-template-columns: minmax(7rem, 38%) 1fr;
  align-items: baseline;
  gap: var(--sp-3);
}

.datalist--inline .datalist__key { padding-top: 0.1rem; }

/* ==========================================================================
   6. TABLAS DE DATOS
   --------------------------------------------------------------------------
   El scroll horizontal vive en `.table-wrap`, nunca en el body: en un móvil
   el listado se desplaza dentro de su caja y la página no baila.
   ========================================================================== */

.table-wrap {
  width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-lg);
}

.card__body--flush .table-wrap { border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

.table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

.table th,
.table td {
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
}

.table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-hover); }

.table--striped tbody tr:nth-child(even) { background: var(--surface-2); }
.table--striped tbody tr:hover { background: var(--surface-hover); }

.table__num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table__actions { text-align: right; white-space: nowrap; }

/* Cabecera ordenable: es un enlace, para que funcione sin JavaScript. */
.table__sort {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  color: inherit;
}

.table__sort:hover { color: var(--link); text-decoration: none; }
.table__sort.is-asc::after { content: "\2191"; }
.table__sort.is-desc::after { content: "\2193"; }

.table-total {
  padding: var(--sp-2) var(--sp-4);
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

/* Barra de filtros sobre un listado. */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--sp-3);
}

.filters .field { flex: 1 1 170px; min-width: 0; margin: 0; }
.filters__actions { display: flex; gap: var(--sp-2); }

/* ==========================================================================
   7. FORMULARIOS
   ========================================================================== */

.form { display: grid; gap: var(--sp-4); }

/* align-items:start es lo que impide que un campo con ayuda larga estire la
   fila y descuadre los de al lado: cada celda crece hacia abajo por su
   cuenta y los controles siguen alineados arriba. */
.form-grid {
  display: grid;
  gap: var(--sp-4) var(--sp-4);
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  align-items: start;
}

.form-grid--wide { grid-template-columns: 1fr; }

.fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

.fieldset__legend {
  padding: 0;
  margin-bottom: var(--sp-3);
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
}

.field { display: grid; gap: var(--sp-2); }

.label {
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--text);
}

.label__required { color: var(--danger); margin-left: 0.15em; }
.label__optional { color: var(--text-subtle); font-weight: var(--fw-normal); margin-left: 0.35em; font-size: var(--fs-xs); }

.input,
.select,
.textarea {
  width: 100%;
  min-height: 44px;
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font: inherit;
  font-size: var(--fs-base);
  transition: border-color var(--transition), box-shadow var(--transition);
  /* 16px en móvil evita el zoom automático de iOS al enfocar. */
}

.textarea { min-height: 110px; resize: vertical; line-height: var(--lh); }

.select {
  appearance: none;
  padding-right: var(--sp-8);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%236a7784' stroke-width='1.8' stroke-linecap='round'%3E%3Cpath d='M4 6.5 8 10.5 12 6.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--sp-3) center;
  background-size: 16px 16px;
}

.select[multiple] {
  min-height: 140px;
  padding-right: var(--sp-3);
  background-image: none;
}

.input:hover,
.select:hover,
.textarea:hover { border-color: var(--gray-400); }

.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px var(--focus-ring);
  outline: 1px solid var(--focus);
  outline-offset: 0;
}

.input::placeholder,
.textarea::placeholder { color: var(--text-subtle); opacity: 1; }

.input:disabled,
.select:disabled,
.textarea:disabled,
.input[readonly] {
  background: var(--surface-sunken);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* Estado de error: `View::invalidClass()` devuelve ` is-invalid`. */
.is-invalid,
.input.is-invalid,
.select.is-invalid,
.textarea.is-invalid {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.is-invalid:focus-visible {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-ring);
  outline-color: var(--danger);
}

.field-error {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-1);
  color: var(--danger);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
}

.field-error svg {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  margin-top: 3px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* La ayuda es apoyo, no contenido: tamaño menor, interlineado ajustado y
   ancho limitado para que no se estire por toda la columna. */
.field-help {
  color: var(--text-muted);
  font-size: var(--fs-xs);
  line-height: 1.4;
  max-width: 46ch;
  margin-top: calc(var(--sp-1) * -1);
}

/* Casillas y radios: el área pulsable incluye la etiqueta. */
.check {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  min-height: 44px;
  padding: var(--sp-2) 0;
  cursor: pointer;
}

.check__input {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  margin: 2px 0 0;
  accent-color: var(--primary);
  cursor: pointer;
}

.check__text { font-size: var(--fs-base); line-height: 1.4; }
.check__text small { display: block; color: var(--text-muted); font-size: var(--fs-sm); }

.check-group { display: grid; gap: var(--sp-1); }

/* Grupo de radios en línea, como los estados del marcador. */
.radio-tiles { display: grid; gap: var(--sp-2); }

.radio-tile {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 48px;
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}

.radio-tile:hover { border-color: var(--border-strong); background: var(--surface-hover); }

.radio-tile:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.radio-tile__key {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  color: var(--text-muted);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3);
  padding-top: var(--sp-2);
}

.form-actions--split { justify-content: space-between; }

/* Contador de caracteres/segmentos del SMS. */
.counter { font-size: var(--fs-sm); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.counter.is-warning { color: var(--warning); font-weight: var(--fw-semibold); }
.counter.is-danger { color: var(--danger); font-weight: var(--fw-semibold); }

/* ==========================================================================
   8. BOTONES
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 44px;
  padding: var(--sp-2) var(--sp-4);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font: inherit;
  font-size: var(--fs-base);
  font-weight: var(--fw-semibold);
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition),
              color var(--transition), box-shadow var(--transition), transform var(--transition);
}

.btn:hover { text-decoration: none; background: var(--surface-hover); border-color: var(--gray-400); }
.btn:active { transform: translateY(1px); }

.btn[disabled],
.btn.is-disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  pointer-events: none;
}

.btn svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; }

.btn--primary {
  background: var(--brand-600);
  border-color: var(--brand-600);
  color: #fff;
  box-shadow: var(--shadow-xs);
}

.btn--primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }

.btn--secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn--danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn--danger:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
  color: #fff;
}

.btn--success {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.btn--success:hover {
  background: var(--success-hover);
  border-color: var(--success-hover);
  color: #fff;
}

.btn--ghost { background: transparent; border-color: transparent; color: var(--link); }
.btn--ghost:hover { background: var(--primary-soft); border-color: transparent; }

.btn--link {
  min-height: 0;
  padding: 0;
  background: none;
  border: 0;
  color: var(--link);
  font-weight: var(--fw-medium);
}

.btn--link:hover { background: none; text-decoration: underline; }

/* Tamaños. En móvil ningún botón baja de 44px de alto (ver §15). */
.btn--sm { min-height: 36px; padding: var(--sp-1) var(--sp-3); font-size: var(--fs-sm); }
.btn--lg { min-height: 52px; padding: var(--sp-3) var(--sp-6); font-size: var(--fs-md); }
.btn--block { width: 100%; }

.btn-group { display: inline-flex; flex-wrap: wrap; gap: var(--sp-2); }

/* Barra de acciones pegada al fondo en móvil: guardar siempre al alcance. */
.sticky-actions {
  position: sticky;
  bottom: 0;
  z-index: var(--z-header);
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  padding: var(--sp-3);
  margin: var(--sp-4) calc(-1 * var(--sp-3)) 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 12px rgba(13, 27, 34, 0.06);
}

.sticky-actions .btn { flex: 1 1 140px; }

/* ==========================================================================
   9. BADGES Y ETIQUETAS DE ESTADO
   --------------------------------------------------------------------------
   Los modificadores son exactamente los valores de LeadStatus::badge():
   info, warning, secondary, dark, primary, success (+ danger).
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 0.2em 0.65em;
  border: 1px solid var(--secondary-line);
  border-radius: var(--radius-pill);
  background: var(--secondary-soft);
  color: var(--secondary);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  line-height: 1.5;
  white-space: nowrap;
  vertical-align: middle;
}

.badge--info      { background: var(--info-soft);      border-color: var(--info-line);      color: var(--info); }
.badge--warning   { background: var(--warning-soft);   border-color: var(--warning-line);   color: var(--warning); }
.badge--secondary { background: var(--secondary-soft);  border-color: var(--secondary-line); color: var(--secondary); }
.badge--dark      { background: var(--dark-soft);      border-color: var(--dark-line);      color: var(--dark); }
.badge--primary   { background: var(--primary-soft);   border-color: var(--primary-line);   color: var(--primary); }
.badge--success   { background: var(--success-soft);   border-color: var(--success-line);   color: var(--success); }
.badge--danger    { background: var(--danger-soft);    border-color: var(--danger-line);    color: var(--danger); }

.badge--dot::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge--solid { color: #fff; border-color: transparent; }
.badge--solid.badge--success { background: var(--success); }
.badge--solid.badge--danger { background: var(--danger); }
.badge--solid.badge--primary { background: var(--brand-600); }

.tag {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 0.15em 0.55em;
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
}

/* ==========================================================================
   10. ALERTAS FLASH
   ========================================================================== */

.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--secondary-line);
  border-left-width: 4px;
  border-radius: var(--radius);
  background: var(--secondary-soft);
  color: var(--text);
  font-size: var(--fs-base);
}

.alert__icon { flex: 0 0 auto; width: 20px; height: 20px; margin-top: 1px; stroke: currentColor; stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.alert__body { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.alert__title { margin: 0 0 var(--sp-1); font-size: var(--fs-base); font-weight: var(--fw-semibold); }
.alert__body p { margin: 0; }
.alert__body p + p { margin-top: var(--sp-1); }

.alert__close {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin: -2px calc(-1 * var(--sp-1)) 0 0;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  color: inherit;
  font-size: var(--fs-lg);
  line-height: 1;
  opacity: 0.6;
  cursor: pointer;
}

.alert__close:hover { opacity: 1; background: rgba(0, 0, 0, 0.06); }

.alert--success { background: var(--success-soft); border-color: var(--success-line); border-left-color: var(--success); color: var(--success); }
.alert--error,
.alert--danger  { background: var(--danger-soft);  border-color: var(--danger-line);  border-left-color: var(--danger);  color: var(--danger); }
.alert--warning { background: var(--warning-soft); border-color: var(--warning-line); border-left-color: var(--warning); color: var(--warning); }
.alert--info    { background: var(--info-soft);    border-color: var(--info-line);    border-left-color: var(--info);    color: var(--info); }

/* Aviso flotante breve (portapapeles, atajos). Lo crea app.js. */
.toast {
  position: fixed;
  left: 50%;
  bottom: var(--sp-6);
  z-index: var(--z-toast);
  transform: translate(-50%, 12px);
  max-width: min(92vw, 420px);
  padding: var(--sp-3) var(--sp-5);
  background: var(--gray-900);
  color: #fff;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  text-align: center;
  opacity: 0;
  transition: opacity var(--transition), transform var(--transition);
}

.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ==========================================================================
   11. MODAL
   ========================================================================== */

.modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.modal.is-open { display: flex; }

.modal__overlay {
  position: absolute;
  inset: 0;
  background: rgba(8, 16, 20, 0.6);
}

.modal__dialog {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal__head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}

.modal__title { margin: 0; flex: 1 1 auto; font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.modal__body { flex: 1 1 auto; padding: var(--sp-5); overflow-y: auto; -webkit-overflow-scrolling: touch; }

.modal__foot {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  justify-content: flex-end;
  padding: var(--sp-3) var(--sp-5) var(--sp-5);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

.modal__foot .btn { flex: 1 1 130px; }

/* El body no debe hacer scroll detrás del modal (clase que pone app.js). */
body.has-modal { overflow: hidden; }

/* ==========================================================================
   12. PAGINACIÓN, PESTAÑAS, TOOLTIP, PROGRESO
   ========================================================================== */

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3);
  margin-top: var(--sp-4);
}

.pagination__summary { color: var(--text-muted); font-size: var(--fs-sm); }

.pagination__list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
  margin: 0 0 0 auto;
  padding: 0;
  list-style: none;
}

.pagination__link {
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 var(--sp-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  font-variant-numeric: tabular-nums;
}

.pagination__link:hover { background: var(--surface-hover); border-color: var(--border-strong); text-decoration: none; }

.pagination__link.is-active {
  background: var(--brand-600);
  border-color: var(--brand-600);
  color: #fff;
  font-weight: var(--fw-semibold);
}

.pagination__link.is-disabled,
.pagination__gap {
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  color: var(--text-subtle);
  pointer-events: none;
  border: 1px solid transparent;
}

/* --- Pestañas --------------------------------------------------------- */

.tabs {
  display: flex;
  gap: var(--sp-1);
  margin-bottom: var(--sp-4);
  padding-bottom: 1px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tabs__item {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 44px;
  padding: var(--sp-2) var(--sp-4);
  border: 1px solid transparent;
  border-bottom: 2px solid transparent;
  border-radius: var(--radius) var(--radius) 0 0;
  color: var(--text-muted);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  white-space: nowrap;
}

.tabs__item:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }

.tabs__item.is-active,
.tabs__item[aria-current="page"] {
  color: var(--link);
  border-bottom-color: var(--brand-600);
  font-weight: var(--fw-semibold);
}

/* --- Tooltip: solo CSS, con `data-tip` como texto --------------------- */

.tip { position: relative; }

.tip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  max-width: 240px;
  width: max-content;
  padding: var(--sp-1) var(--sp-2);
  background: var(--gray-900);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  line-height: 1.4;
  white-space: normal;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition), visibility var(--transition);
  pointer-events: none;
}

.tip:hover::after,
.tip:focus-visible::after { opacity: 1; visibility: visible; }

/* En pantallas táctiles el hover no existe: el tooltip nunca es la única
   vía de acceso a la información, así que aquí simplemente se oculta. */
@media (hover: none) {
  .tip::after { display: none; }
}

/* --- Barra de progreso ------------------------------------------------ */

.progress {
  height: 8px;
  background: var(--surface-sunken);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.progress__bar {
  height: 100%;
  width: 0;
  background: var(--brand-500);
  border-radius: var(--radius-pill);
  transition: width 320ms ease;
}

.progress--lg { height: 14px; }
.progress__bar--success { background: var(--success); }
.progress__bar--warning { background: var(--warning); }
.progress__bar--danger { background: var(--danger); }

.progress-row { display: grid; gap: var(--sp-1); }
.progress-row__head { display: flex; justify-content: space-between; gap: var(--sp-2); font-size: var(--fs-sm); }
.progress-row__value { font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }

/* ==========================================================================
   13. KPI, TIMELINE, ESTADO VACÍO, TEMPORIZADOR
   ========================================================================== */

.kpis {
  display: grid;
  gap: var(--sp-3);
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin-bottom: var(--sp-5);
}

.kpi {
  display: grid;
  gap: var(--sp-1);
  padding: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}

.kpi__label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.kpi__value {
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.kpi__unit { font-size: var(--fs-md); font-weight: var(--fw-medium); color: var(--text-muted); }
.kpi__foot { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); color: var(--text-muted); }

.kpi__delta { font-weight: var(--fw-semibold); }
.kpi__delta--up { color: var(--success); }
.kpi__delta--down { color: var(--danger); }
.kpi__delta--flat { color: var(--text-muted); }

.kpi--accent { border-left: 3px solid var(--brand-500); }
.kpi--success { border-left: 3px solid var(--success); }
.kpi--warning { border-left: 3px solid var(--warning); }
.kpi--danger { border-left: 3px solid var(--danger); }

/* --- Timeline de actividad ------------------------------------------- */

.timeline { margin: 0; padding: 0 0 0 var(--sp-5); list-style: none; position: relative; }

.timeline::before {
  content: "";
  position: absolute;
  top: 6px;
  bottom: 6px;
  left: 5px;
  width: 2px;
  background: var(--border);
}

.timeline__item { position: relative; padding: 0 0 var(--sp-5); }
.timeline__item:last-child { padding-bottom: 0; }

.timeline__item::before {
  content: "";
  position: absolute;
  top: 6px;
  left: calc(-1 * var(--sp-5) + 1px);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--border-strong);
}

.timeline__item--primary::before { border-color: var(--brand-500); }
.timeline__item--success::before { border-color: var(--success); }
.timeline__item--danger::before { border-color: var(--danger); }
.timeline__item--warning::before { border-color: var(--warning); }

.timeline__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-xs);
  color: var(--text-subtle);
}

.timeline__title { margin: var(--sp-1) 0 0; font-size: var(--fs-base); font-weight: var(--fw-semibold); }
.timeline__text { margin: var(--sp-1) 0 0; font-size: var(--fs-sm); color: var(--text-muted); overflow-wrap: anywhere; }

/* --- Estado vacío ---------------------------------------------------- */

.empty {
  display: grid;
  justify-items: center;
  gap: var(--sp-3);
  padding: var(--sp-10) var(--sp-5);
  text-align: center;
  color: var(--text-muted);
}

.empty__icon {
  width: 48px;
  height: 48px;
  stroke: var(--border-strong);
  stroke-width: 1.5;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.empty__title { margin: 0; font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--text); }
.empty__text { margin: 0; max-width: 46ch; font-size: var(--fs-sm); }

/* --- Temporizador del marcador --------------------------------------- */

.timer {
  display: inline-flex;
  align-items: baseline;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-3);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-family: var(--font-mono);
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.timer__label { font-family: var(--font); font-size: var(--fs-xs); font-weight: var(--fw-medium); color: var(--text-muted); letter-spacing: 0; }
.timer.is-long { background: var(--warning-soft); border-color: var(--warning-line); color: var(--warning); }

/* Panel de atajos de teclado del marcador. */
.shortcuts { display: grid; gap: var(--sp-2); font-size: var(--fs-sm); }
.shortcuts__row { display: flex; align-items: center; gap: var(--sp-3); }
.shortcuts__keys { flex: 0 0 auto; display: flex; gap: var(--sp-1); }
.shortcuts__desc { color: var(--text-muted); }

/* Los atajos solo tienen sentido con teclado físico. */
@media (hover: none) and (pointer: coarse) {
  .shortcuts-card { display: none; }
}

/* ==========================================================================
   14. SITIO PÚBLICO (landings, gracias, confirmación, legales)
   ========================================================================== */

.site { display: flex; flex-direction: column; min-height: 100vh; }

.site__header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.site__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  color: var(--text);
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  letter-spacing: -0.01em;
}

.site__brand:hover { text-decoration: none; color: var(--text); }

.site__phone {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 44px;
  margin-left: auto;
  padding: var(--sp-2) var(--sp-4);
  border: 1px solid var(--brand-200);
  border-radius: var(--radius-pill);
  background: var(--primary-soft);
  color: var(--link);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
}

.site__phone:hover { text-decoration: none; background: var(--brand-100); }

.site__main { flex: 1 1 auto; }

.site__footer {
  padding: var(--sp-6) var(--sp-4) var(--sp-8);
  background: var(--gray-900);
  color: var(--gray-300);
  font-size: var(--fs-sm);
}

.site__footer a { color: var(--gray-100); text-decoration: underline; }
.site__footer a:hover { color: #fff; }

.site__footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3) var(--sp-5);
  max-width: 1080px;
  margin: 0 auto;
}

.site__legal-nav { display: flex; flex-wrap: wrap; gap: var(--sp-4); margin: 0; padding: 0; list-style: none; }
.site__legal-nav a { min-height: 44px; display: inline-flex; align-items: center; }
.site__copy { margin: 0; color: var(--gray-400); }

/* --- Hero de landing -------------------------------------------------- */

.hero {
  padding: var(--sp-8) var(--sp-4) var(--sp-10);
  background:
    radial-gradient(120% 80% at 15% 0%, var(--brand-50) 0%, transparent 60%),
    var(--bg);
}

.hero__inner {
  display: grid;
  gap: var(--sp-8);
  max-width: 1080px;
  margin: 0 auto;
  align-items: start;
}

.hero__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
  padding: 0.25em 0.8em;
  border-radius: var(--radius-pill);
  background: var(--primary-soft);
  border: 1px solid var(--primary-line);
  color: var(--primary);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.hero__title {
  margin: 0 0 var(--sp-4);
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.hero__lead {
  margin: 0 0 var(--sp-5);
  max-width: 52ch;
  font-size: var(--fs-md);
  color: var(--text-muted);
}

.hero__points { display: grid; gap: var(--sp-3); margin: 0 0 var(--sp-5); padding: 0; list-style: none; }

.hero__point {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  font-size: var(--fs-base);
}

.hero__point::before {
  content: "";
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  margin-top: 2px;
  border-radius: 50%;
  background: var(--brand-500) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23fff' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m3.5 8.5 3 3 6-7'/%3E%3C/svg%3E") center / 13px 13px no-repeat;
}

.hero__media img { border-radius: var(--radius-lg); box-shadow: var(--shadow); }

.hero__note { font-size: var(--fs-xs); color: var(--text-subtle); }

/* Hero con imagen de fondo.
   La URL llega en la variable --hero-bg desde la plantilla (atributo style),
   porque la imagen la elige cada landing en el CRM y no puede estar en la
   hoja. El degradado va ENCIMA de la foto: sin él, un fondo claro deja el
   titular ilegible, y eso es justo donde está la propuesta de valor. Se ha
   bajado al mínimo que mantiene el contraste AA del titular: la foto tiene
   que verse. Los textos sobre la foto llevan además sombra, que da
   legibilidad sin oscurecer la imagen entera. */
.hero--image {
  position: relative;
  background-image:
    linear-gradient(180deg, rgba(10, 22, 26, 0.42) 0%, rgba(10, 22, 26, 0.24) 45%, rgba(10, 22, 26, 0.50) 100%),
    var(--hero-bg);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

/* Sobre la foto, el texto va en claro pase lo que pase con el tema. */
.hero--image .hero__title,
.hero--image .hero__lead,
.hero--image .hero__point,
.hero--image .hero__note { color: #fff; }

/* La sombra hace el trabajo que antes hacía el degradado oscuro. */
.hero--image .hero__title { text-shadow: 0 2px 12px rgba(0, 0, 0, 0.55); }

.hero--image .hero__lead,
.hero--image .hero__note,
.hero--image .hero__point { text-shadow: 0 1px 8px rgba(0, 0, 0, 0.6); }

.hero--image .hero__lead,
.hero--image .hero__note { opacity: 0.92; }

.hero--image .hero__eyebrow {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}

.hero--image .hero__point::before { color: #fff; }

/* En móvil la foto ocupa toda la altura visible y el texto queda encima;
   fijarla causaría saltos en iOS, así que se desplaza con la página. */
@media (max-width: 767px) {
  .hero--image { background-attachment: scroll; }
}

/* La tarjeta del formulario mantiene fondo sólido: es lo que tiene que
   destacar sobre la foto. */
.hero--image .capture { box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35); }

/* --- Formulario de captación destacado -------------------------------- */

.capture {
  position: relative;
  padding: var(--sp-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--brand-500);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.capture__title { margin: 0 0 var(--sp-1); font-size: var(--fs-lg); }
.capture__sub { margin: 0 0 var(--sp-5); font-size: var(--fs-sm); color: var(--text-muted); }
.capture__form { display: grid; gap: var(--sp-4); }

.capture .input,
.capture .select,
.capture .textarea { min-height: 48px; font-size: var(--fs-md); }

.capture .btn { min-height: 52px; font-size: var(--fs-md); }

.capture__consent { font-size: var(--fs-sm); }
.capture__consent a { text-decoration: underline; }

.capture__trust {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2) var(--sp-4);
  margin-top: var(--sp-4);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--border);
  font-size: var(--fs-xs);
  color: var(--text-subtle);
  text-align: center;
}

/* --- Páginas de resultado: gracias, confirmación ---------------------- */

.result {
  display: grid;
  justify-items: center;
  gap: var(--sp-4);
  max-width: 620px;
  margin: 0 auto;
  padding: var(--sp-10) var(--sp-4) var(--sp-12);
  text-align: center;
}

.result__mark {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--success-soft);
  border: 2px solid var(--success-line);
  color: var(--success);
}

.result__mark svg { width: 34px; height: 34px; stroke: currentColor; stroke-width: 2.2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.result__mark--warning { background: var(--warning-soft); border-color: var(--warning-line); color: var(--warning); }
.result__mark--danger { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger); }

.result__title { margin: 0; font-size: var(--fs-xl); }
.result__text { margin: 0; max-width: 48ch; color: var(--text-muted); }

.result__panel {
  width: 100%;
  margin-top: var(--sp-2);
  padding: var(--sp-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-align: left;
}

.result__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--sp-3); width: 100%; }
.result__actions .btn { flex: 1 1 180px; }

/* Resumen de la cita en la página de confirmación. */
.appointment-summary { display: grid; gap: var(--sp-3); margin: 0; }
.appointment-summary__row { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: baseline; }
.appointment-summary__key { flex: 0 0 110px; font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--text-subtle); text-transform: uppercase; letter-spacing: 0.05em; }
.appointment-summary__val { flex: 1 1 160px; margin: 0; font-size: var(--fs-md); font-weight: var(--fw-medium); }

/* --- Páginas legales -------------------------------------------------- */

.legal {
  max-width: var(--prose-max);
  margin: 0 auto;
  padding: var(--sp-8) var(--sp-4) var(--sp-12);
}

.legal h1 { margin-bottom: var(--sp-2); font-size: var(--fs-2xl); }
.legal__updated { margin-bottom: var(--sp-8); color: var(--text-subtle); font-size: var(--fs-sm); }
.legal h2 { margin-top: var(--sp-8); font-size: var(--fs-lg); }
.legal h3 { margin-top: var(--sp-6); font-size: var(--fs-md); }
.legal li + li { margin-top: var(--sp-2); }

.legal table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--sp-4) 0;
  font-size: var(--fs-sm);
}

.legal th,
.legal td { padding: var(--sp-2) var(--sp-3); border: 1px solid var(--border); text-align: left; }
.legal th { background: var(--surface-2); }

/* --- Acceso al CRM y página de error --------------------------------- */

.auth {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: var(--sp-5) var(--sp-4);
}

.auth__card {
  width: 100%;
  max-width: 400px;
  padding: var(--sp-6) var(--sp-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.auth__brand { display: grid; justify-items: center; gap: var(--sp-2); margin-bottom: var(--sp-6); text-align: center; }
.auth__title { margin: 0; font-size: var(--fs-lg); }
.auth__sub { margin: 0; font-size: var(--fs-sm); color: var(--text-muted); }

.errorpage {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: var(--sp-8) var(--sp-4);
}

.errorpage__inner { width: 100%; max-width: 720px; text-align: center; }

.errorpage__status {
  display: block;
  font-size: var(--fs-4xl);
  font-weight: var(--fw-bold);
  line-height: 1;
  color: var(--brand-500);
  font-variant-numeric: tabular-nums;
}

.errorpage__title { margin: var(--sp-4) 0 var(--sp-2); font-size: var(--fs-xl); }
.errorpage__text { margin: 0 auto var(--sp-6); max-width: 52ch; color: var(--text-muted); }
.errorpage__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--sp-3); }

/* Traza: solo se pinta en modo depuración, y solo si hay excepción. */
.trace {
  margin-top: var(--sp-8);
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.trace__head {
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
}

.trace__meta { display: grid; gap: var(--sp-1); padding: var(--sp-3) var(--sp-4); font-size: var(--fs-sm); border-bottom: 1px solid var(--border); }
.trace__meta code { overflow-wrap: anywhere; }

.trace__code {
  margin: 0;
  max-height: 55vh;
  padding: var(--sp-4);
  overflow: auto;
  background: var(--surface-sunken);
  color: var(--text);
  font-size: var(--fs-xs);
  line-height: 1.6;
  white-space: pre;
  tab-size: 4;
}

/* ==========================================================================
   15. RESPONSIVE Y ACCESIBILIDAD
   ========================================================================== */

/* En móvil, 16px en los controles evita que iOS haga zoom al enfocar, y
   todo lo pulsable llega a 44px. */
@media (max-width: 767px) {
  .input,
  .select,
  .textarea { font-size: 16px; }

  .btn,
  .btn--sm { min-height: 44px; }

  .table th,
  .table td { padding: var(--sp-3); }

  .modal__dialog { max-height: 88vh; }

  /* Listado en fichas: la vista añade `data-label` a cada celda. */
  .table--stacked { min-width: 0; }
  .table--stacked thead { display: none; }

  .table--stacked tbody tr {
    display: grid;
    gap: var(--sp-1);
    padding: var(--sp-3);
    margin-bottom: var(--sp-3);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
  }

  .table--stacked tbody td {
    display: grid;
    grid-template-columns: 40% 1fr;
    gap: var(--sp-3);
    padding: var(--sp-1) 0;
    border: 0;
    text-align: left;
  }

  .table--stacked tbody td::before {
    content: attr(data-label);
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    color: var(--text-subtle);
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  .table--stacked tbody td:not([data-label]) { grid-template-columns: 1fr; }
}

/* Tablet: la cabecera muestra ya el nombre del usuario. */
@media (min-width: 640px) {
  .main { padding: var(--sp-6) var(--sp-5) var(--sp-12); }
  .header { padding: var(--sp-2) var(--sp-5); }
  .header__user-meta { display: block; }
  .sticky-actions { margin-left: calc(-1 * var(--sp-5)); margin-right: calc(-1 * var(--sp-5)); }
  .sticky-actions .btn { flex: 0 1 auto; }
  .hero { padding: var(--sp-12) var(--sp-5); }
  .hero__title { font-size: var(--fs-3xl); }
  .modal { align-items: center; padding: var(--sp-5); }
  .modal__dialog { border-radius: var(--radius-xl); max-height: 86vh; }
  .modal__foot .btn { flex: 0 1 auto; }
  .site__header { padding: var(--sp-4) var(--sp-6); }
  .capture { padding: var(--sp-6); }
}

/* Escritorio: barra lateral fija, colapsable a iconos. */
@media (min-width: 1024px) {
  .app {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    grid-template-areas: "sidebar body";
  }

  .app__body { grid-area: body; min-width: 0; display: flex; flex-direction: column; }

  .sidebar {
    grid-area: sidebar;
    position: sticky;
    top: 0;
    height: 100vh;
    width: auto;
    transform: none;
    transition: none;
  }

  .backdrop { display: none; }

  .app.is-collapsed { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }

  /* Colapsada: solo iconos. Los rótulos siguen en el DOM para el lector de
     pantalla, pero fuera de la vista. */
  .app.is-collapsed .sidebar__label,
  .app.is-collapsed .sidebar__count,
  .app.is-collapsed .sidebar__group-title,
  .app.is-collapsed .sidebar__brand span,
  .app.is-collapsed .sidebar__footer { display: none; }

  .app.is-collapsed .sidebar__brand { justify-content: center; padding-inline: 0; }
  .app.is-collapsed .sidebar__link { justify-content: center; padding-inline: 0; }
  .app.is-collapsed .sidebar__nav { padding-inline: var(--sp-2); }
  .app.is-collapsed .sidebar__group + .sidebar__group { margin-top: var(--sp-3); padding-top: var(--sp-3); border-top: 1px solid var(--sidebar-border); }

  .main { padding: var(--sp-6) var(--sp-8) var(--sp-16); }
  .header { padding: var(--sp-2) var(--sp-6); }
  .sticky-actions { position: static; margin: var(--sp-4) 0 0; padding: 0; background: none; border: 0; box-shadow: none; }

  .hero__inner { grid-template-columns: 1.05fr 0.95fr; gap: var(--sp-12); align-items: center; }
  .hero__title { font-size: var(--fs-3xl); }
  .form-grid--wide { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Sin animación para quien la ha desactivado en el sistema. */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .btn:active { transform: none; }
}

/* Bordes visibles cuando el usuario pide más contraste. */
@media (prefers-contrast: more) {
  :root {
    --border: var(--gray-400);
    --border-strong: var(--gray-600);
    --text-muted: var(--gray-700);
  }

  .badge, .alert, .card, .btn { border-width: 2px; }
}

@media print {
  .sidebar,
  .header,
  .backdrop,
  .envbar,
  .site__footer,
  .pagination,
  .form-actions,
  .sticky-actions,
  .modal { display: none !important; }

  body { background: #fff; color: #000; }
  .app { display: block; }
  .card { border-color: #999; box-shadow: none; break-inside: avoid; }
  .table-wrap { overflow: visible; }
  .table { min-width: 0; font-size: 10pt; }
  a { color: #000; text-decoration: underline; }
}

/* ==========================================================================
   AYUDA PLEGABLE
   --------------------------------------------------------------------------
   Explicaciones dentro de la propia pantalla, plegadas por defecto. Se usa
   <details> nativo: ni una línea de JavaScript, así que funciona con la CSP
   puesta y con el teclado sin que haya que programar nada.
   ========================================================================== */

.help { border: 0; }

.help__summary {
  cursor: pointer;
  padding: var(--sp-4);
  font-weight: var(--fw-semibold);
  color: var(--text);
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.help__summary::-webkit-details-marker { display: none; }

/* Triángulo propio: el nativo no se puede estilar de forma consistente. */
.help__summary::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2px solid var(--text-subtle);
  border-bottom: 2px solid var(--text-subtle);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
}

.help[open] .help__summary::before { transform: rotate(45deg); }

.help__summary:hover { color: var(--primary); }
.help__summary:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }

.help__body {
  padding: 0 var(--sp-4) var(--sp-4);
  border-top: 1px solid var(--border);
  padding-top: var(--sp-4);
  font-size: var(--fs-sm);
  line-height: 1.55;
  max-width: 68ch;
}

.help__title {
  margin: var(--sp-4) 0 var(--sp-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--text);
}

.help__body > .help__title:first-child { margin-top: 0; }

.help__list { margin: 0 0 var(--sp-2); padding-left: 1.25rem; }
.help__list li { margin-bottom: 0.25rem; }

.help__body p { margin: 0 0 var(--sp-2); }

kbd {
  display: inline-block;
  padding: 0.1em 0.4em;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm, 0.25rem);
  background: var(--surface-2, var(--bg));
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8em;
  line-height: 1.4;
}

/* ==========================================================================
   AGENDA
   --------------------------------------------------------------------------
   Las citas se agrupan por día, así que cada día es una tarjeta. Lo que se
   busca es poder barrer la columna de horas de un vistazo y que solo salten
   a la vista las filas que piden algo.
   ========================================================================== */

.agenda__toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}

.agenda__quickfilter { margin: 0 0 var(--sp-4); }

.agenda__day { margin-bottom: var(--sp-5); }

/* El día de hoy lleva un filo de color: es a lo que se entra a mirar. */
.agenda__day--today { border-left: 3px solid var(--primary); }

/* Contador de citas del día, junto al título. */
.agenda__count {
  display: inline-block;
  margin-left: var(--sp-2);
  padding: 0.05em 0.5em;
  border-radius: var(--radius-pill);
  background: var(--primary-soft);
  color: var(--primary);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  vertical-align: middle;
}

/* La hora en tabular para que las cifras queden en columna aunque cambie el
   ancho de los dígitos. */
.agenda__time {
  font-variant-numeric: tabular-nums;
  font-weight: var(--fw-semibold);
  font-size: var(--fs-base);
  white-space: nowrap;
}

.agenda__name { display: block; font-weight: var(--fw-semibold); }
.agenda__phone { display: block; font-size: var(--fs-sm); color: var(--text-muted); white-space: nowrap; }

.agenda__state { display: flex; flex-direction: column; gap: 0.15rem; align-items: flex-start; }

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

/* Cita pasada sin marcar: lo único que en esta pantalla está "pendiente de
   ti", así que se señala en la fila entera y no solo en la etiqueta. */
.table tbody tr.is-pending > * { background: var(--warning-soft, transparent); }

/* Reprogramar, plegado. El summary se pinta como un botón, así que se le
   quita el triángulo nativo. */
.agenda__more > summary { list-style: none; cursor: pointer; }
.agenda__more > summary::-webkit-details-marker { display: none; }

.agenda__reschedule {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
}

.agenda__reschedule .input { width: auto; min-width: 12rem; }

/* Columnas que no deben estirarse. */
.table__tight { width: 1%; white-space: nowrap; }
.table__actions { width: 1%; }

.input--sm { padding: 0.35rem 0.55rem; font-size: var(--fs-sm); }

/* Un aviso más en la columna de KPIs. */
.kpi--warn .kpi__value { color: var(--warning); }

@media (max-width: 640px) {
  .agenda__toolbar { flex-direction: column; align-items: stretch; }
  .agenda__toolbar .btn { width: 100%; }
  .table__tight, .table__actions { width: auto; white-space: normal; }
}

/* El atributo `hidden` tiene que ganar a cualquier `display` de una clase.
   La hoja del navegador lo declara con especificidad mínima, así que una
   regla como `.field { display: grid }` lo anulaba y el elemento seguía
   viéndose aunque el JavaScript lo hubiera ocultado. */
[hidden] { display: none !important; }

/* ==========================================================================
   ACORDEÓN DE RESOLUCIÓN
   --------------------------------------------------------------------------
   Cada estado es una fila pulsable que despliega sus propios campos. La
   selección sigue siendo un radio nativo: el teclado, los atajos 1-6 y el
   envío funcionan sin que el CSS tenga nada que ver.
   ========================================================================== */

.accordion {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.accordion__item + .accordion__item { border-top: 1px solid var(--border); }

.accordion__head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  cursor: pointer;
  background: var(--surface);
  transition: background var(--transition);

  /* Objetivo táctil cómodo: esto se usa en el móvil, entre llamadas. */
  min-height: 3rem;
}

.accordion__head:hover { background: var(--surface-2, var(--bg)); }

.accordion__item.is-open .accordion__head {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: var(--fw-semibold);
}

/* El radio se oculta a la vista pero sigue existiendo para el teclado y los
   lectores de pantalla: la fila entera es su etiqueta. */
.accordion__radio {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.accordion__radio:focus-visible + .accordion__label { outline: 2px solid var(--focus-ring); outline-offset: 3px; }

/* Número del atajo de teclado. */
.accordion__key {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: var(--radius-sm, 0.25rem);
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  color: var(--text-subtle);
}

.accordion__item.is-open .accordion__key {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.accordion__label { flex: 1 1 auto; }

.accordion__body {
  padding: var(--sp-4);
  border-top: 1px solid var(--border);
  background: var(--bg);
  display: grid;
  gap: var(--sp-3);
}
