/* =============================================================================================
 * APPIA · sistema de diseño (CORE)
 * Tokens → base → tipografía → layout → componentes → utilidades.
 * Tema: <html data-theme="auto|light|dark"> (lo fija core/theme-init.js antes de pintar).
 * Color de una app en el Reproductor: ui.applyBrand('#hex') redefine --primary* en :root.
 * Documentado en DOCS_CORE.md § Sistema de diseño.
 * ========================================================================================== */

/* ---------- Tokens ---------- */
:root {
  /* Esmeralda profunda (marca) */
  --g-50: #eefbf4;  --g-100: #d4f5e3; --g-200: #a9e9c9; --g-300: #70d5a6; --g-400: #38bb82;
  --g-500: #179f69; --g-600: #0c8456; --g-700: #0b6b4f; --g-800: #0b5440; --g-900: #0a4535; --g-950: #052a20;
  --mint: #7cf0c0;  /* acento claro */

  /* Neutros con un toque verde */
  --n-0: #ffffff; --n-25: #fbfcfb; --n-50: #f6f8f7; --n-100: #eef1ef; --n-150: #e6eae8; --n-200: #dde3e0;
  --n-300: #c7d0cb; --n-400: #98a59f; --n-500: #6a7771; --n-600: #4e5a54; --n-700: #36413c; --n-800: #222a26;
  --n-900: #141a17; --n-950: #0b0f0d;

  /* Semánticos (claro) */
  --bg: var(--n-25);
  --surface: var(--n-0);
  --surface-2: var(--n-50);
  --surface-3: var(--n-100);
  --overlay: rgb(10 20 16 / .44);
  --border: var(--n-200);
  --border-strong: var(--n-300);
  --text: var(--n-900);
  --text-2: var(--n-700);
  --muted: #5b6862;          /* 5.7:1 sobre blanco */
  --faint: var(--n-400);

  --primary: var(--g-700);
  --primary-hover: var(--g-800);
  --primary-active: var(--g-900);
  --primary-soft: var(--g-50);
  --primary-soft-2: var(--g-100);
  --primary-text: var(--g-700);  /* texto de marca sobre superficie */
  --on-primary: #ffffff;

  --danger: #c42b2b;  --danger-hover: #a52222; --danger-soft: #fdeeee; --danger-text: #b42323;
  --warning: #b45309; --warning-soft: #fff6e5; --warning-text: #92400e;
  --success: var(--g-600); --success-soft: var(--g-50); --success-text: var(--g-700);
  --info: #1d5fd1;    --info-soft: #ecf2fe; --info-text: #1a4fb0;

  --focus: 0 0 0 3px color-mix(in srgb, var(--primary) 38%, transparent);
  --focus-ring: color-mix(in srgb, var(--primary) 70%, white);

  /* Tipografía del sistema */
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --fs-xs: .75rem; --fs-sm: .8125rem; --fs-md: .9375rem; --fs-base: 1rem; --fs-lg: 1.125rem;
  --fs-xl: 1.375rem; --fs-2xl: 1.75rem; --fs-3xl: 2.25rem; --fs-4xl: clamp(2.25rem, 5vw + 1rem, 3.75rem);
  --lh: 1.55; --lh-tight: 1.2;

  /* Espacio, radios, sombras, movimiento */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px; --s-16: 64px;
  --r-xs: 6px; --r-sm: 8px; --r: 10px; --r-lg: 14px; --r-xl: 20px; --r-full: 999px;
  --shadow-xs: 0 1px 2px rgb(16 24 20 / .06);
  --shadow-sm: 0 1px 2px rgb(16 24 20 / .06), 0 1px 3px rgb(16 24 20 / .08);
  --shadow: 0 2px 4px rgb(16 24 20 / .04), 0 6px 16px rgb(16 24 20 / .08);
  --shadow-lg: 0 8px 20px rgb(16 24 20 / .08), 0 24px 48px rgb(16 24 20 / .14);
  --ease: cubic-bezier(.2, .7, .2, 1);
  --t-fast: 120ms; --t: 180ms; --t-slow: 280ms;
  --tap: 44px;               /* área táctil mínima */
  --control-h: 44px;         /* alto de botones y campos */
  --control-h-sm: 36px;
  --appbar-h: 56px;
  --bottomnav-h: 64px;
  --maxw: 1200px;
  --safe-b: env(safe-area-inset-bottom, 0px);

  color-scheme: light;
}

/* Oscuro: por preferencia del sistema (auto) o elegido */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0f0d; --surface: #111714; --surface-2: #161d1a; --surface-3: #1d2622; --overlay: rgb(0 0 0 / .6);
  --border: #26302b; --border-strong: #35413b;
  --text: #e9efeb; --text-2: #c6d1cb; --muted: #9baba3; --faint: #6c7a73;
  --primary: #3ecb93; --primary-hover: #5bd8a6; --primary-active: #7ce3b9;
  --primary-soft: #0f2a20; --primary-soft-2: #143728; --primary-text: #5fdaa8; --on-primary: #03180f;
  --danger: #f06363; --danger-hover: #f58080; --danger-soft: #3a1414; --danger-text: #f68b8b;
  --warning: #f0a43a; --warning-soft: #33240c; --warning-text: #f5bd6b;
  --success: #3ecb93; --success-soft: #0f2a20; --success-text: #5fdaa8;
  --info: #6aa2ff; --info-soft: #102340; --info-text: #8fb8ff;
  --shadow-xs: 0 1px 2px rgb(0 0 0 / .4);
  --shadow-sm: 0 1px 3px rgb(0 0 0 / .45);
  --shadow: 0 6px 18px rgb(0 0 0 / .45);
  --shadow-lg: 0 24px 56px rgb(0 0 0 / .6);
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    color-scheme: dark;
    --bg: #0b0f0d; --surface: #111714; --surface-2: #161d1a; --surface-3: #1d2622; --overlay: rgb(0 0 0 / .6);
    --border: #26302b; --border-strong: #35413b;
    --text: #e9efeb; --text-2: #c6d1cb; --muted: #9baba3; --faint: #6c7a73;
    --primary: #3ecb93; --primary-hover: #5bd8a6; --primary-active: #7ce3b9;
    --primary-soft: #0f2a20; --primary-soft-2: #143728; --primary-text: #5fdaa8; --on-primary: #03180f;
    --danger: #f06363; --danger-hover: #f58080; --danger-soft: #3a1414; --danger-text: #f68b8b;
    --warning: #f0a43a; --warning-soft: #33240c; --warning-text: #f5bd6b;
    --success: #3ecb93; --success-soft: #0f2a20; --success-text: #5fdaa8;
    --info: #6aa2ff; --info-soft: #102340; --info-text: #8fb8ff;
    --shadow-xs: 0 1px 2px rgb(0 0 0 / .4);
    --shadow-sm: 0 1px 3px rgb(0 0 0 / .45);
    --shadow: 0 6px 18px rgb(0 0 0 / .45);
    --shadow-lg: 0 24px 56px rgb(0 0 0 / .6);
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; scroll-padding-top: calc(var(--appbar-h) + 8px); }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh;
  font-family: var(--font); font-size: var(--fs-base); line-height: var(--lh);
  color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility;
  font-feature-settings: "cv11", "ss01";
}
img, svg, video, canvas { display: block; max-width: 100%; }
img { height: auto; }
input, button, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled, [aria-disabled="true"] { cursor: not-allowed; }
a { color: var(--primary-text); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
p, h1, h2, h3, h4, h5, h6, figure, blockquote, dl, dd { margin: 0; }
ul, ol { margin: 0; padding: 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--s-6) 0; }
table { border-collapse: collapse; }
[hidden] { display: none !important; }
::selection { background: color-mix(in srgb, var(--primary) 24%, transparent); }

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

/* ---------- Tipografía ---------- */
h1, .h1 { font-size: var(--fs-2xl); line-height: var(--lh-tight); font-weight: 700; letter-spacing: -.02em; }
h2, .h2 { font-size: var(--fs-xl); line-height: 1.25; font-weight: 650; letter-spacing: -.015em; }
h3, .h3 { font-size: var(--fs-lg); line-height: 1.3; font-weight: 600; letter-spacing: -.01em; }
h4, .h4 { font-size: var(--fs-base); font-weight: 600; }
.display { font-size: var(--fs-4xl); line-height: 1.05; font-weight: 750; letter-spacing: -.035em; }
.lead { font-size: var(--fs-lg); color: var(--text-2); line-height: 1.5; }
.eyebrow { font-size: var(--fs-xs); font-weight: 650; letter-spacing: .08em; text-transform: uppercase; color: var(--primary-text); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small, small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.strong { font-weight: 600; }
.mono, code, kbd { font-family: var(--font-mono); font-size: .9em; }
code { background: var(--surface-3); padding: .1em .35em; border-radius: 5px; }
kbd { display: inline-block; min-width: 1.6em; padding: .05em .4em; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px; background: var(--surface); font-size: .8em; text-align: center; color: var(--text-2); }
.prose { max-width: 70ch; }
.prose > * + * { margin-top: 1em; }
.prose h2 { margin-top: 1.6em; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li + li { margin-top: .35em; }
.tnum { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- Layout ---------- */
.container { width: 100%; max-width: var(--maxw); margin-inline: auto; padding-inline: var(--s-4); }
@media (min-width: 720px) { .container { padding-inline: var(--s-6); } }
.container-sm { max-width: 720px; }
.container-xs { max-width: 440px; }
.stack { display: flex; flex-direction: column; gap: var(--s-4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--s-2); }
.stack-lg { display: flex; flex-direction: column; gap: var(--s-8); }
.row { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.row-nowrap { display: flex; align-items: center; gap: var(--s-3); min-width: 0; }
.row-center { display: flex; align-items: center; justify-content: center; gap: var(--s-3); flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.grid { display: grid; gap: var(--s-4); }
.grid-2 { display: grid; gap: var(--s-4); grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); }
.grid-3 { display: grid; gap: var(--s-4); grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); }
.page { padding-block: var(--s-6) var(--s-12); }
.page-center { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: var(--s-6) var(--s-4); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; margin-bottom: var(--s-6); }
.page-head p { color: var(--muted); margin-top: var(--s-1); }
.divider { height: 1px; background: var(--border); border: 0; margin: 0; }
.spacer { flex: 1; }

/* ---------- Íconos ---------- */
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; display: inline-block; vertical-align: middle; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 24px; height: 24px; }
.icon-xl { width: 32px; height: 32px; stroke-width: 1.75; }
.icon-tile { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: var(--r); background: var(--primary-soft); color: var(--primary-text); flex: none; }
.icon-tile.lg { width: 48px; height: 48px; border-radius: var(--r-lg); }

/* ---------- Botones ---------- */
.btn {
  --_bg: var(--surface); --_fg: var(--text); --_bd: var(--border-strong); --_bg-h: var(--surface-2);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: var(--control-h); padding: 0 var(--s-4); border-radius: var(--r);
  border: 1px solid var(--_bd); background: var(--_bg); color: var(--_fg);
  font-size: var(--fs-md); font-weight: 600; line-height: 1; white-space: nowrap; text-decoration: none;
  box-shadow: var(--shadow-xs); user-select: none; position: relative;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
}
.btn:hover { background: var(--_bg-h); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); border-color: var(--primary); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; transform: none; }
.btn .icon { width: 18px; height: 18px; margin-inline: -2px; }
.btn-primary { --_bg: var(--primary); --_fg: var(--on-primary); --_bd: transparent; --_bg-h: var(--primary-hover); box-shadow: 0 1px 2px rgb(11 107 79 / .25), inset 0 1px 0 rgb(255 255 255 / .08); }
.btn-primary:active { --_bg: var(--primary-active); }
.btn-soft { --_bg: var(--primary-soft); --_fg: var(--primary-text); --_bd: transparent; --_bg-h: var(--primary-soft-2); box-shadow: none; }
.btn-ghost { --_bg: transparent; --_bd: transparent; --_bg-h: var(--surface-3); box-shadow: none; }
.btn-danger { --_bg: var(--danger); --_fg: #fff; --_bd: transparent; --_bg-h: var(--danger-hover); }
.btn-danger-ghost { --_bg: transparent; --_fg: var(--danger-text); --_bd: transparent; --_bg-h: var(--danger-soft); box-shadow: none; }
.btn-link { --_bg: transparent; --_bd: transparent; --_bg-h: transparent; --_fg: var(--primary-text); box-shadow: none; padding-inline: var(--s-1); }
.btn-link:hover { text-decoration: underline; }
.btn-sm { min-height: var(--control-h-sm); padding: 0 var(--s-3); font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn-lg { min-height: 52px; padding: 0 var(--s-6); font-size: var(--fs-base); border-radius: var(--r-lg); }
.btn-block { width: 100%; }
.btn-icon { width: var(--control-h); padding: 0; }
.btn-icon.btn-sm { width: var(--control-h-sm); }
/* Áreas táctiles: los botones pequeños conservan 44px de área con un pseudo-elemento */
.btn-sm::after, .btn-icon.btn-sm::after { content: ""; position: absolute; inset: -4px; }
.btn.is-busy { color: transparent !important; pointer-events: none; }
.btn.is-busy::before {
  content: ""; position: absolute; inset: 0; margin: auto; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--_fg); border-right-color: transparent; animation: spin .7s linear infinite;
}
.btn-group { display: inline-flex; }
.btn-group > .btn { border-radius: 0; }
.btn-group > .btn:first-child { border-radius: var(--r) 0 0 var(--r); }
.btn-group > .btn:last-child { border-radius: 0 var(--r) var(--r) 0; }
.btn-group > .btn + .btn { margin-left: -1px; }

/* ---------- Campos ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field + .field { margin-top: var(--s-4); }
.stack > .field + .field, .form-grid > .field + .field { margin-top: 0; }
.label { font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); display: flex; align-items: baseline; gap: var(--s-2); }
.label .req { color: var(--danger-text); font-weight: 700; }
.label .opt { color: var(--faint); font-weight: 400; }
.hint { font-size: var(--fs-sm); color: var(--muted); }
.field-error, .error-text { font-size: var(--fs-sm); color: var(--danger-text); display: flex; gap: 6px; align-items: flex-start; }
.input, .select, .textarea {
  width: 100%; min-height: var(--control-h); padding: 10px var(--s-3);
  border: 1px solid var(--border-strong); border-radius: var(--r); background: var(--surface); color: var(--text);
  font-size: var(--fs-base); line-height: 1.4; box-shadow: var(--shadow-xs);
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
  appearance: none; -webkit-appearance: none;
}
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--n-400); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
.input:disabled, .select:disabled, .textarea:disabled, .input[readonly] { background: var(--surface-2); color: var(--muted); }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); }
.input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 25%, transparent); }
.textarea { min-height: 96px; resize: vertical; }
.select {
  padding-right: 40px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236a7771' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 18px;
}
.input-sm { min-height: var(--control-h-sm); padding-block: 6px; font-size: var(--fs-md); }
.input-group { position: relative; display: flex; align-items: center; }
.input-group > .icon { position: absolute; left: 12px; color: var(--faint); pointer-events: none; }
.input-group > .icon + .input { padding-left: 40px; }
.input-group > .input-affix { position: absolute; right: 4px; }
.input-group .prefix, .input-group .suffix { position: absolute; color: var(--muted); font-size: var(--fs-md); pointer-events: none; }
.input-group .prefix { left: 12px; }
.input-group .prefix + .input { padding-left: 32px; }
.input-group .suffix { right: 12px; }
.form-grid { display: grid; gap: var(--s-4); grid-template-columns: 1fr; }
@media (min-width: 640px) { .form-grid.cols-2 { grid-template-columns: 1fr 1fr; } .form-grid .span-2 { grid-column: 1 / -1; } }
.form-actions { display: flex; gap: var(--s-3); justify-content: flex-end; flex-wrap: wrap; margin-top: var(--s-6); }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; font-weight: 600; margin-bottom: var(--s-2); }

/* Casilla y opción */
.check { display: flex; align-items: flex-start; gap: var(--s-3); min-height: var(--tap); padding: 10px 0; cursor: pointer; line-height: 1.4; }
.check input { appearance: none; -webkit-appearance: none; flex: none; width: 20px; height: 20px; margin: 1px 0 0; border: 1.5px solid var(--border-strong); background: var(--surface); border-radius: 6px; display: grid; place-items: center; transition: background var(--t-fast), border-color var(--t-fast); cursor: pointer; }
.check input[type="radio"] { border-radius: 50%; }
.check input::after { content: ""; width: 10px; height: 6px; border: 2px solid var(--on-primary); border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px) scale(0); transition: transform var(--t-fast) var(--ease); }
.check input[type="radio"]::after { width: 8px; height: 8px; border: 0; border-radius: 50%; background: var(--on-primary); transform: scale(0); }
.check input:checked { background: var(--primary); border-color: var(--primary); }
.check input:checked::after { transform: rotate(-45deg) translate(1px, -1px) scale(1); }
.check input[type="radio"]:checked::after { transform: scale(1); }
.check input:focus-visible { box-shadow: var(--focus); outline: none; }
.check .check-text small { display: block; color: var(--muted); }

/* Interruptor */
.switch { display: inline-flex; align-items: center; gap: var(--s-3); min-height: var(--tap); cursor: pointer; }
.switch input { appearance: none; -webkit-appearance: none; flex: none; position: relative; width: 44px; height: 26px; border-radius: var(--r-full); background: var(--n-300); transition: background var(--t) var(--ease); cursor: pointer; margin: 0; }
:root[data-theme="dark"] .switch input { background: #3a4741; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .25); transition: transform var(--t) var(--ease); }
.switch input:checked { background: var(--primary); }
.switch input:checked::after { transform: translateX(18px); }
.switch input:focus-visible { box-shadow: var(--focus); outline: none; }

/* Selector segmentado */
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-3); border-radius: var(--r); max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.segmented button, .segmented a { min-height: 38px; padding: 0 var(--s-3); border: 0; background: transparent; border-radius: 8px; font-size: var(--fs-sm); font-weight: 600; color: var(--muted); white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
.segmented [aria-pressed="true"], .segmented [aria-selected="true"], .segmented [aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- Pestañas ---------- */
.tabs { display: flex; gap: var(--s-1); border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { position: relative; min-height: var(--tap); padding: 0 var(--s-3); border: 0; background: none; color: var(--muted); font-weight: 600; font-size: var(--fs-md); white-space: nowrap; display: inline-flex; align-items: center; gap: var(--s-2); text-decoration: none; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"], .tab[aria-current="page"] { color: var(--text); }
.tab[aria-selected="true"]::after, .tab[aria-current="page"]::after { content: ""; position: absolute; left: var(--s-2); right: var(--s-2); bottom: -1px; height: 2px; border-radius: 2px; background: var(--primary); }
.tab .count { font-size: var(--fs-xs); background: var(--surface-3); color: var(--muted); padding: 1px 7px; border-radius: var(--r-full); }

/* ---------- Tarjetas ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-xs); }
.card-body { padding: var(--s-5); }
.card-head { padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: var(--s-3); justify-content: space-between; }
.card-foot { padding: var(--s-3) var(--s-5); border-top: 1px solid var(--border); display: flex; gap: var(--s-3); justify-content: flex-end; flex-wrap: wrap; }
.card-link { display: block; color: inherit; text-decoration: none; transition: border-color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast); }
.card-link:hover { border-color: var(--border-strong); box-shadow: var(--shadow); text-decoration: none; }
.card-link:active { transform: translateY(1px); }
.card-soft { background: var(--surface-2); border-color: transparent; box-shadow: none; }
@media (max-width: 480px) { .card-body { padding: var(--s-4); } .card-head, .card-foot { padding-inline: var(--s-4); } }

/* Listas tipo «ajustes» */
.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; align-items: center; gap: var(--s-3); min-height: 56px; padding: var(--s-3) var(--s-4); border-top: 1px solid var(--border); color: inherit; text-decoration: none; }
.list-item:first-child { border-top: 0; }
a.list-item:hover, button.list-item:hover { background: var(--surface-2); }
button.list-item { width: 100%; border: 0; background: none; text-align: left; border-top: 1px solid var(--border); }
.list-item .meta { color: var(--muted); font-size: var(--fs-sm); }

/* ---------- Distintivos, chips, avatares ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: var(--r-full); font-size: var(--fs-xs); font-weight: 600; background: var(--surface-3); color: var(--text-2); white-space: nowrap; line-height: 1; }
.badge::before { content: none; }
.badge.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-soft); color: var(--success-text); }
.badge-danger { background: var(--danger-soft); color: var(--danger-text); }
.badge-warning { background: var(--warning-soft); color: var(--warning-text); }
.badge-info { background: var(--info-soft); color: var(--info-text); }
.badge-gray { background: var(--surface-3); color: var(--muted); }
[data-theme="dark"] .badge { --badge-bg: 20%; --badge-fg: 50%; }
@media (prefers-color-scheme: dark) { [data-theme="auto"] .badge { --badge-bg: 20%; --badge-fg: 50%; } }
/* Colores con nombre de la definición (opciones, estados): .badge-<color>, y --c para usarlos en otros componentes (.c-<color>). */
.c-red { --c: #dc2626; }
.c-orange { --c: #ea580c; }
.c-amber { --c: #d97706; }
.c-yellow { --c: #ca8a04; }
.c-lime { --c: #65a30d; }
.c-green { --c: #16a34a; }
.c-emerald { --c: #059669; }
.c-teal { --c: #0d9488; }
.c-cyan { --c: #0891b2; }
.c-sky { --c: #0284c7; }
.c-blue { --c: #2563eb; }
.c-indigo { --c: #4f46e5; }
.c-violet { --c: #7c3aed; }
.c-purple { --c: #9333ea; }
.c-pink { --c: #db2777; }
.c-rose { --c: #e11d48; }
.c-gray { --c: #6b7a73; }
.badge-red, .badge-orange, .badge-amber, .badge-yellow, .badge-lime, .badge-green, .badge-emerald, .badge-teal, .badge-cyan, .badge-sky, .badge-blue, .badge-indigo, .badge-violet, .badge-purple, .badge-pink, .badge-rose { background: color-mix(in srgb, var(--c) var(--badge-bg, 13%), var(--surface)); color: color-mix(in srgb, var(--c) var(--badge-fg, 62%), var(--text)); }
.badge-red { --c: #dc2626; }
.badge-orange { --c: #ea580c; }
.badge-amber { --c: #d97706; }
.badge-yellow { --c: #ca8a04; }
.badge-lime { --c: #65a30d; }
.badge-green { --c: #16a34a; }
.badge-emerald { --c: #059669; }
.badge-teal { --c: #0d9488; }
.badge-cyan { --c: #0891b2; }
.badge-sky { --c: #0284c7; }
.badge-blue { --c: #2563eb; }
.badge-indigo { --c: #4f46e5; }
.badge-violet { --c: #7c3aed; }
.badge-purple { --c: #9333ea; }
.badge-pink { --c: #db2777; }
.badge-rose { --c: #e11d48; }
.badge-solid { background: var(--primary); color: var(--on-primary); }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 var(--s-3); border-radius: var(--r-full); border: 1px solid var(--border-strong); background: var(--surface); font-size: var(--fs-sm); font-weight: 500; color: var(--text-2); }
button.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 40%, transparent); color: var(--primary-text); }
.avatar { --_s: 32px; width: var(--_s); height: var(--_s); border-radius: 50%; flex: none; display: inline-grid; place-items: center; background: var(--primary-soft-2); color: var(--primary-text); font-size: calc(var(--_s) * .4); font-weight: 650; overflow: hidden; text-transform: uppercase; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { --_s: 24px; } .avatar-lg { --_s: 44px; } .avatar-xl { --_s: 72px; }
.counter { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--r-full); background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; line-height: 1; }

/* ---------- Avisos en línea ---------- */
.callout { display: flex; gap: var(--s-3); align-items: flex-start; padding: var(--s-3) var(--s-4); border-radius: var(--r); background: var(--info-soft); color: var(--info-text); font-size: var(--fs-md); border: 1px solid color-mix(in srgb, currentColor 15%, transparent); }
.callout .icon { margin-top: 2px; }
.callout > div { min-width: 0; flex: 1; }
.callout strong { display: block; }
.callout-success { background: var(--success-soft); color: var(--success-text); }
.callout-warning { background: var(--warning-soft); color: var(--warning-text); }
.callout-danger { background: var(--danger-soft); color: var(--danger-text); }
.callout-neutral { background: var(--surface-2); color: var(--text-2); }

/* ---------- Tablas ---------- */
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); -webkit-overflow-scrolling: touch; }
.table { width: 100%; font-size: var(--fs-md); }
.table th, .table td { padding: 10px var(--s-4); text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: var(--fs-xs); font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background var(--t-fast); }
.table tbody tr:hover { background: var(--surface-2); }
.table tr[aria-selected="true"] { background: var(--primary-soft); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .col-check { width: 44px; padding-right: 0; }
.table-compact th, .table-compact td { padding-block: 6px; }
.table a { color: inherit; font-weight: 500; }

/* ---------- Estados vacíos y de carga ---------- */
.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s-3); padding: var(--s-10) var(--s-4); max-width: 460px; margin-inline: auto; }
.empty-state img, .empty-state .illus { width: 160px; height: auto; margin-bottom: var(--s-2); }
.empty-state h1, .empty-state h2, .empty-state h3 { font-size: var(--fs-xl); }
.empty-state p { color: var(--muted); }
.empty-state .row-center { margin-top: var(--s-3); }
.skeleton { position: relative; overflow: hidden; background: var(--surface-3); border-radius: var(--r-sm); color: transparent !important; }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgb(255 255 255 / .45), transparent); animation: shimmer 1.4s infinite; }
:root[data-theme="dark"] .skeleton::after { background: linear-gradient(90deg, transparent, rgb(255 255 255 / .06), transparent); }
.sk-line { height: 12px; margin: 8px 0; }
.sk-title { height: 22px; width: 40%; margin-bottom: 16px; }
.sk-block { height: 72px; border-radius: var(--r); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--border-strong); border-top-color: var(--primary); animation: spin .7s linear infinite; flex: none; }
.spinner-lg { width: 36px; height: 36px; border-width: 3px; }
.loading-center { display: grid; place-items: center; gap: var(--s-3); padding: var(--s-12) var(--s-4); color: var(--muted); }
.progress { height: 6px; border-radius: var(--r-full); background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: inherit; transition: width var(--t-slow) var(--ease); }
.progress.indeterminate > span { width: 35%; animation: indet 1.2s var(--ease) infinite; }
.meter { display: flex; flex-direction: column; gap: 6px; }
.meter .progress > span.warn { background: var(--warning); }
.meter .progress > span.full { background: var(--danger); }

/* ---------- Capas: modal, hoja inferior, menú, toasts ---------- */
.layer-backdrop { position: fixed; inset: 0; background: var(--overlay); z-index: 900; animation: fade-in var(--t) var(--ease); backdrop-filter: blur(2px); }
.modal {
  position: fixed; z-index: 901; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 32px)); max-height: min(86vh, 860px); display: flex; flex-direction: column;
  background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--shadow-lg); border: 1px solid var(--border);
  animation: modal-in var(--t-slow) var(--ease);
}
.modal-lg { width: min(860px, calc(100vw - 32px)); }
.modal-sm { width: min(420px, calc(100vw - 32px)); }
.modal-head { display: flex; align-items: flex-start; gap: var(--s-3); padding: var(--s-5) var(--s-5) var(--s-2); }
.modal-head h2 { font-size: var(--fs-lg); flex: 1; padding-top: 8px; }
.modal-head .btn-icon { margin: -2px -8px 0 0; }
.modal-body { padding: var(--s-2) var(--s-5) var(--s-5); overflow-y: auto; overscroll-behavior: contain; }
.modal-body > p { color: var(--text-2); }
.modal-foot { display: flex; gap: var(--s-3); justify-content: flex-end; padding: var(--s-4) var(--s-5); border-top: 1px solid var(--border); flex-wrap: wrap; }
/* En el teléfono, los modales son hojas inferiores */
@media (max-width: 640px) {
  .modal, .modal-lg, .modal-sm {
    left: 0; right: 0; top: auto; bottom: 0; transform: none; width: 100%; max-height: 92vh; max-height: 92dvh;
    border-radius: var(--r-xl) var(--r-xl) 0 0; border-bottom: 0; animation: sheet-in var(--t-slow) var(--ease);
    padding-bottom: var(--safe-b);
  }
  .modal::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--border-strong); margin: 8px auto 0; flex: none; }
  .modal-foot { flex-direction: column-reverse; }
  .modal-foot .btn { width: 100%; }
}
.sheet { position: fixed; z-index: 901; left: 0; right: 0; bottom: 0; max-height: 92dvh; background: var(--surface); border-radius: var(--r-xl) var(--r-xl) 0 0; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: sheet-in var(--t-slow) var(--ease); padding-bottom: var(--safe-b); }
.drawer { position: fixed; z-index: 901; top: 0; right: 0; bottom: 0; width: min(480px, 100vw); background: var(--surface); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: drawer-in var(--t-slow) var(--ease); border-left: 1px solid var(--border); }
.menu {
  position: fixed; z-index: 950; min-width: 200px; max-width: min(320px, calc(100vw - 16px)); padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  animation: pop-in var(--t) var(--ease); max-height: 70vh; overflow-y: auto;
}
.menu-item { display: flex; align-items: center; gap: var(--s-3); width: 100%; min-height: var(--tap); padding: 0 var(--s-3); border: 0; border-radius: var(--r-sm); background: none; color: var(--text); font-size: var(--fs-md); text-align: left; text-decoration: none; }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-3); outline: none; }
.menu-item .icon { color: var(--muted); }
.menu-item.danger { color: var(--danger-text); }
.menu-item.danger .icon { color: currentColor; }
.menu-item .kbd-hint { margin-left: auto; color: var(--faint); font-size: var(--fs-xs); }
.menu-sep { height: 1px; background: var(--border); margin: 6px 4px; }
.menu-label { padding: 8px 12px 4px; font-size: var(--fs-xs); font-weight: 650; color: var(--faint); text-transform: uppercase; letter-spacing: .05em; }
@media (max-width: 640px) {
  .menu.as-sheet { left: 0 !important; right: 0; top: auto !important; bottom: 0; max-width: none; width: 100%; border-radius: var(--r-xl) var(--r-xl) 0 0; padding: 10px 8px calc(10px + var(--safe-b)); animation: sheet-in var(--t-slow) var(--ease); }
  .menu.as-sheet .menu-item { min-height: 52px; font-size: var(--fs-base); }
}
.toasts { position: fixed; z-index: 1000; left: 50%; transform: translateX(-50%); bottom: calc(var(--s-4) + var(--safe-b)); display: flex; flex-direction: column; align-items: center; gap: var(--s-2); width: min(480px, calc(100vw - 24px)); pointer-events: none; }
body.has-bottom-nav .toasts { bottom: calc(var(--bottomnav-h) + var(--s-3) + var(--safe-b)); }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: var(--s-3); width: 100%; min-height: 48px; padding: 8px 8px 8px var(--s-4);
  background: var(--n-900); color: #f2f6f4; border-radius: var(--r-lg); box-shadow: var(--shadow-lg); font-size: var(--fs-md);
  animation: toast-in var(--t-slow) var(--ease);
}
:root[data-theme="dark"] .toast { background: #26302b; }
.toast .icon { color: var(--g-300); }
.toast.error .icon { color: #ff9a9a; }
.toast.warning .icon { color: #ffc672; }
.toast-msg { flex: 1; min-width: 0; padding-block: 4px; }
.toast .btn { --_fg: var(--g-200); --_bg: transparent; --_bd: transparent; --_bg-h: rgb(255 255 255 / .1); box-shadow: none; min-height: 36px; }
.toast .btn-icon { --_fg: #c8d3cd; }
.toast.leaving { animation: toast-out var(--t) var(--ease) forwards; }

/* Tooltip simple (data-tip) — solo decorativo; el texto real va en aria-label */
[data-tip] { position: relative; }
@media (hover: hover) {
  [data-tip]:hover::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); padding: 5px 8px; border-radius: 6px; background: var(--n-900); color: #fff; font-size: var(--fs-xs); font-weight: 500; white-space: nowrap; pointer-events: none; z-index: 960; animation: fade-in var(--t-fast); }
}

/* ---------- Armazón de aplicación ---------- */
.appbar { position: sticky; top: 0; z-index: 100; height: var(--appbar-h); display: flex; align-items: center; gap: var(--s-3); padding: 0 var(--s-4); background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px); border-bottom: 1px solid var(--border); }
.appbar-title { font-weight: 650; font-size: var(--fs-base); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 750; font-size: 1.2rem; letter-spacing: -.03em; min-height: var(--tap); }
.brand:hover { text-decoration: none; }
.brand img { width: 30px; height: 30px; }
.bottom-nav { position: fixed; z-index: 100; left: 0; right: 0; bottom: 0; height: calc(var(--bottomnav-h) + var(--safe-b)); padding-bottom: var(--safe-b); display: flex; background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--border); }
.bottom-nav a, .bottom-nav button { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border: 0; background: none; color: var(--muted); font-size: 11px; font-weight: 600; text-decoration: none; position: relative; }
.bottom-nav .icon { width: 22px; height: 22px; }
.bottom-nav [aria-current="page"] { color: var(--primary-text); }
.bottom-nav [aria-current="page"]::before { content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 2px; border-radius: 0 0 2px 2px; background: var(--primary); }
.bottom-nav span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-inline: 2px; }
body.has-bottom-nav { padding-bottom: calc(var(--bottomnav-h) + var(--safe-b)); }
@media (min-width: 900px) { .bottom-nav.mobile-only { display: none; } body.has-bottom-nav.mobile-only-nav { padding-bottom: 0; } }
.sidebar { width: 248px; flex: none; border-right: 1px solid var(--border); background: var(--surface); height: calc(100vh - var(--appbar-h)); height: calc(100dvh - var(--appbar-h)); position: sticky; top: var(--appbar-h); overflow-y: auto; padding: var(--s-3); }
.nav-item { display: flex; align-items: center; gap: var(--s-3); min-height: 40px; padding: 0 var(--s-3); border-radius: var(--r-sm); color: var(--text-2); text-decoration: none; font-size: var(--fs-md); font-weight: 500; border: 0; background: none; width: 100%; text-align: left; }
.nav-item:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-item[aria-current="page"] { background: var(--primary-soft); color: var(--primary-text); font-weight: 600; }
.nav-item .icon { color: currentColor; opacity: .85; }
.nav-section { padding: var(--s-4) var(--s-3) var(--s-1); font-size: var(--fs-xs); font-weight: 650; color: var(--faint); text-transform: uppercase; letter-spacing: .06em; }
@media (max-width: 899px) { .sidebar.desktop-only { display: none; } }
.shell { display: flex; min-height: calc(100vh - var(--appbar-h)); }
.shell-main { flex: 1; min-width: 0; }

/* ---------- Accesibilidad y utilidades ---------- */
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 8px; top: -60px; z-index: 2000; padding: 10px 16px; border-radius: var(--r); background: var(--primary); color: var(--on-primary); font-weight: 600; text-decoration: none; transition: top var(--t); }
.skip-link:focus { top: 8px; outline: none; box-shadow: var(--focus); }
.noscript { max-width: 520px; margin: 15vh auto; padding: var(--s-6); text-align: center; color: var(--text-2); }
.page-error { max-width: 520px; margin: 15vh auto; padding: var(--s-6); text-align: center; }
.center { text-align: center; }
.right { text-align: right; }
.w-full { width: 100%; }
.mt-0 { margin-top: 0 !important; } .mt-1 { margin-top: var(--s-1); } .mt-2 { margin-top: var(--s-2); } .mt-3 { margin-top: var(--s-3); } .mt-4 { margin-top: var(--s-4); } .mt-6 { margin-top: var(--s-6); } .mt-8 { margin-top: var(--s-8); }
.mb-2 { margin-bottom: var(--s-2); } .mb-4 { margin-bottom: var(--s-4); } .mb-6 { margin-bottom: var(--s-6); }
.gap-1 { gap: var(--s-1); } .gap-2 { gap: var(--s-2); } .gap-6 { gap: var(--s-6); }
.hide-mobile { } .show-mobile { display: none; }
@media (max-width: 640px) { .hide-mobile { display: none !important; } .show-mobile { display: initial; } }
.surface { background: var(--surface); }
.rounded { border-radius: var(--r); }
.border { border: 1px solid var(--border); }
.pill-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); display: inline-block; flex: none; }
.live-region { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Banner de «entraste como» / anuncio */
.banner { display: flex; align-items: center; justify-content: center; gap: var(--s-3); flex-wrap: wrap; padding: 8px var(--s-4); font-size: var(--fs-sm); font-weight: 500; background: var(--warning-soft); color: var(--warning-text); text-align: center; }
.banner-brand { background: var(--primary); color: var(--on-primary); }
.banner a { color: inherit; font-weight: 650; }

/* «En construcción» provisional (lo reemplaza cada equipo) */
.wip { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: var(--s-6) var(--s-4); background: radial-gradient(1000px 500px at 50% -10%, var(--primary-soft), transparent 70%), var(--bg); }
.wip-card { width: min(460px, 100%); text-align: center; display: flex; flex-direction: column; align-items: center; gap: var(--s-4); }
.wip-card .mark { width: 64px; height: 64px; }
.wip-card h1 { font-size: var(--fs-2xl); }
.wip-card p { color: var(--muted); }

/* ---------- Movimiento ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { transform: translateX(100%); } }
@keyframes indet { 0% { transform: translateX(-100%); } 100% { transform: translateX(300%); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: scale(.97) translateY(-4px); } }
@keyframes modal-in { from { opacity: 0; transform: translate(-50%, -48%) scale(.98); } }
@keyframes sheet-in { from { transform: translateY(100%); } }
@keyframes drawer-in { from { transform: translateX(100%); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(.98); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
  .skeleton::after { display: none; }
}

/* ---------- Impresión ---------- */
@media print {
  .appbar, .bottom-nav, .sidebar, .toasts, .skip-link, .no-print { display: none !important; }
  body { background: #fff; color: #000; padding: 0 !important; }
  .card { box-shadow: none; border-color: #ccc; }
}
