/* ==========================================================================
   CyberLink Store · Consultas Perú
   Hoja de estilos única. Sin frameworks: nada que descargar, nada que
   compilar, y el navegador pinta la primera vista sin esperar a nadie.

   Estructura:
     1. Tokens y temas      5. Formularios
     2. Base                6. Datos y tablas
     3. Estructura          7. Estados y utilidades
     4. Componentes         8. Adaptación a pantallas
   ========================================================================== */

/* ── 1. Tokens y temas ─────────────────────────────────────────────────── */

:root {
  /* Marca, tomada del logo: azul marino profundo y cian eléctrico. */
  --navy-900: #050B16;
  --navy-800: #0B1B33;
  --navy-700: #12294a;
  --navy-600: #1B3A63;
  --cyan-300: #7DE3FF;
  --cyan-400: #22C8F5;
  --cyan-500: #00A8E8;
  --cyan-600: #0086BD;
  --cyan-700: #026C99;

  --green-500: #10B981;
  --amber-500: #F59E0B;
  --red-500:   #EF4444;
  --violet-500:#8B5CF6;

  /* Tema claro (por defecto). */
  --bg:            #F4F6FA;
  --bg-pattern:    rgba(11, 27, 51, .025);
  --surface:       #FFFFFF;
  --surface-2:     #F8FAFC;
  --surface-3:     #EFF3F9;
  --border:        #E2E8F1;
  --border-strong: #CBD6E5;
  --text:          #0F1B2D;
  --text-soft:     #3D4E68;
  --text-muted:    #6B7C96;
  --accent:        #0086BD;
  --accent-hover:  #026C99;
  --accent-soft:   #E7F6FD;
  --accent-text:   #FFFFFF;
  --header-bg:     var(--navy-800);
  --header-text:   #FFFFFF;

  --ok-bg:    #E9F9F1;  --ok-fg:    #06714A;  --ok-line:  #A7E8CB;
  --warn-bg:  #FEF6E7;  --warn-fg:  #92510B;  --warn-line:#FBDCA4;
  --err-bg:   #FDECEC;  --err-fg:   #A31919;  --err-line: #F7BFBF;
  --info-bg:  #E9F1FD;  --info-fg:  #17458E;  --info-line:#B9D2F6;

  --radius-sm: 8px;
  --radius:    12px;
  --radius-lg: 16px;
  --radius-xl: 22px;

  --shadow-sm: 0 1px 2px rgba(11, 27, 51, .06);
  --shadow:    0 2px 8px rgba(11, 27, 51, .07), 0 1px 2px rgba(11, 27, 51, .05);
  --shadow-lg: 0 12px 32px rgba(11, 27, 51, .12), 0 2px 8px rgba(11, 27, 51, .06);
  --shadow-focus: 0 0 0 3px rgba(0, 168, 232, .28);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, "SF Mono", Menlo, monospace;

  --sidebar-w: 248px;
  --header-h:  60px;

  /* Una sola curva y una sola duración: la interfaz se siente coherente
     y nada tarda tanto como para que el usuario espere a la animación. */
  --ease: cubic-bezier(.4, 0, .2, 1);
  --fast: 130ms;
  --slow: 240ms;
}

/* Tema oscuro por preferencia del sistema, salvo que se pida claro. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #060D1A;
    --bg-pattern:    rgba(125, 227, 255, .03);
    --surface:       #0C1728;
    --surface-2:     #111F36;
    --surface-3:     #162944;
    --border:        #1D2F4C;
    --border-strong: #2B4368;
    --text:          #E9EFF8;
    --text-soft:     #BCCADD;
    --text-muted:    #8497B3;
    --accent:        #22C8F5;
    --accent-hover:  #7DE3FF;
    --accent-soft:   #0C2A3D;
    --accent-text:   #04121F;
    --header-bg:     #081326;
    --header-text:   #FFFFFF;

    --ok-bg:   #06251A;  --ok-fg:   #5EE9B5;  --ok-line:  #14543C;
    --warn-bg: #2A1D06;  --warn-fg: #FBBF4E;  --warn-line:#5B3F0E;
    --err-bg:  #2A0E0E;  --err-fg:  #F98A8A;  --err-line: #5E1F1F;
    --info-bg: #0A1C33;  --info-fg: #8FBBF5;  --info-line:#1D3A63;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow:    0 2px 10px rgba(0, 0, 0, .45);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, .6);
  }
}

/* Tema oscuro elegido explícitamente: gana sobre la preferencia del sistema. */
:root[data-theme="dark"] {
  --bg:            #060D1A;
  --bg-pattern:    rgba(125, 227, 255, .03);
  --surface:       #0C1728;
  --surface-2:     #111F36;
  --surface-3:     #162944;
  --border:        #1D2F4C;
  --border-strong: #2B4368;
  --text:          #E9EFF8;
  --text-soft:     #BCCADD;
  --text-muted:    #8497B3;
  --accent:        #22C8F5;
  --accent-hover:  #7DE3FF;
  --accent-soft:   #0C2A3D;
  --accent-text:   #04121F;
  --header-bg:     #081326;
  --header-text:   #FFFFFF;

  --ok-bg:   #06251A;  --ok-fg:   #5EE9B5;  --ok-line:  #14543C;
  --warn-bg: #2A1D06;  --warn-fg: #FBBF4E;  --warn-line:#5B3F0E;
  --err-bg:  #2A0E0E;  --err-fg:  #F98A8A;  --err-line: #5E1F1F;
  --info-bg: #0A1C33;  --info-fg: #8FBBF5;  --info-line:#1D3A63;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow:    0 2px 10px rgba(0, 0, 0, .45);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, .6);
}

/* ── 2. Base ───────────────────────────────────────────────────────────── */

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

* { margin: 0; }

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

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}

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

h1, h2, h3, h4 { line-height: 1.25; font-weight: 700; letter-spacing: -.015em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.22rem; }
h3 { font-size: 1.02rem; }
h4 { font-size: .92rem; }

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

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

/* Foco visible sólo cuando se navega con teclado: no molesta con el ratón
   pero nunca deja a alguien sin saber dónde está. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
:focus:not(:focus-visible) { outline: none; }

::selection { background: var(--accent); color: var(--accent-text); }

/* Barras de desplazamiento discretas y acordes al tema. */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; border: 3px solid var(--bg); }

/* Quien pidió menos movimiento, no lo recibe. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── 3. Estructura ─────────────────────────────────────────────────────── */

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

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--header-bg);
  color: #DCE7F5;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 18px 18px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.sidebar__brand:hover { text-decoration: none; }
.sidebar__brand-mark { width: 34px; height: 34px; flex-shrink: 0; }
.sidebar__brand-name { color: #fff; font-weight: 800; font-size: .95rem; letter-spacing: .2px; line-height: 1.1; }
.sidebar__brand-sub  { color: var(--cyan-400); font-size: .62rem; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; }

.sidebar__nav { padding: 12px 10px; flex: 1; }
.sidebar__group { margin-bottom: 18px; }
.sidebar__label {
  padding: 0 10px 7px;
  font-size: .64rem;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: rgba(220, 231, 245, .42);
}

.navlink {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  color: #C3D3E8;
  font-size: .875rem;
  font-weight: 500;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
  position: relative;
}
.navlink:hover { background: rgba(255, 255, 255, .07); color: #fff; text-decoration: none; }
.navlink.is-active { background: rgba(34, 200, 245, .14); color: #fff; font-weight: 600; }
.navlink.is-active::before {
  content: "";
  position: absolute;
  left: -10px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 20px;
  background: var(--cyan-400);
  border-radius: 0 3px 3px 0;
}
.navlink__icon { width: 18px; height: 18px; flex-shrink: 0; opacity: .85; }
.navlink__badge {
  margin-left: auto;
  background: var(--cyan-500);
  color: #04121F;
  font-size: .66rem;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 99px;
  min-width: 18px;
  text-align: center;
}

.sidebar__foot { padding: 12px; border-top: 1px solid rgba(255, 255, 255, .08); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 clamp(14px, 3vw, 26px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar__title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -.01em;
  /* min-width:0 permite que el título se recorte en lugar de empujar el
     ancho de la barra y provocar desplazamiento horizontal en móvil. */
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar__spacer { flex: 1; min-width: 0; }
.topbar > .credits,
.topbar > .theme-toggle,
.topbar > .menu,
.topbar > .menu-btn { flex-shrink: 0; }

/* El selector de tema del menú desplegable sólo aparece en móvil, donde no
   cabe en la barra superior. */
.menu__theme { display: none; padding: 7px 11px; }

.content { padding: clamp(16px, 3vw, 26px); flex: 1; width: 100%; max-width: 1440px; }
.content--narrow { max-width: 820px; }

.page-head { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head__text { flex: 1; min-width: 220px; }
.page-head__sub { color: var(--text-muted); font-size: .875rem; margin-top: 3px; }

/* ── 4. Componentes ────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card__head {
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.card__title { font-size: .95rem; font-weight: 700; }
.card__sub { font-size: .8rem; color: var(--text-muted); }
.card__body { padding: 18px; }
.card__foot { padding: 13px 18px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.card--flush .card__body { padding: 0; }

.grid { display: grid; gap: 16px; }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid--4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* Tarjeta de métrica. */
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 17px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.stat::after {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, var(--cyan-500), var(--cyan-300));
  opacity: 0;
  transition: opacity var(--slow) var(--ease);
}
.stat--accent::after { opacity: 1; }
.stat__label { font-size: .74rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .7px; }
.stat__value { font-size: 1.75rem; font-weight: 800; letter-spacing: -.03em; margin-top: 5px; font-variant-numeric: tabular-nums; }
.stat__meta { font-size: .78rem; color: var(--text-muted); margin-top: 3px; }
.stat__value--sm { font-size: 1.25rem; }

/* Botones. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: .875rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease),
              color var(--fast) var(--ease), transform var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; transform: none; }

.btn--primary { background: var(--accent); color: var(--accent-text); }
.btn--primary:hover:not(:disabled) { background: var(--accent-hover); box-shadow: var(--shadow); }

.btn--ghost { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-2); border-color: var(--accent); color: var(--accent); }

.btn--quiet { background: transparent; color: var(--text-muted); }
.btn--quiet:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }

.btn--danger { background: var(--red-500); color: #fff; }
.btn--danger:hover:not(:disabled) { background: #DC2626; }

.btn--sm { padding: 6px 11px; font-size: .8rem; }
.btn--lg { padding: 12px 22px; font-size: .95rem; }
.btn--block { width: 100%; }
.btn--icon { padding: 8px; }

/* Estado de carga: el botón se bloquea y muestra un giro, para que nadie
   pulse dos veces una consulta que ya está en curso. */
.btn.is-loading { color: transparent !important; pointer-events: none; position: relative; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 15px; height: 15px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  color: var(--accent-text);
}
.btn--ghost.is-loading::after, .btn--quiet.is-loading::after { color: var(--text); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Distintivos. */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 700;
  line-height: 1.6;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge--ok   { background: var(--ok-bg);   color: var(--ok-fg);   border-color: var(--ok-line); }
.badge--warn { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-line); }
.badge--err  { background: var(--err-bg);  color: var(--err-fg);  border-color: var(--err-line); }
.badge--info { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-line); }
.badge--neutral { background: var(--surface-3); color: var(--text-muted); border-color: var(--border); }
.badge--accent { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

.dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dot--ok { background: var(--green-500); }
.dot--warn { background: var(--amber-500); }
.dot--err { background: var(--red-500); }

/* Contador de créditos de la barra superior. */
.credits {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 13px;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 34%, transparent);
  border-radius: 99px;
  font-weight: 700;
  font-size: .85rem;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  transition: transform var(--slow) var(--ease);
}
.credits.is-bumped { animation: bump .5s var(--ease); }
@keyframes bump {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.14); }
  100% { transform: scale(1); }
}

/* Avisos. */
.alert {
  display: flex;
  gap: 11px;
  padding: 12px 15px;
  border-radius: var(--radius);
  border: 1px solid;
  font-size: .875rem;
  line-height: 1.5;
}
.alert--ok   { background: var(--ok-bg);   color: var(--ok-fg);   border-color: var(--ok-line); }
.alert--warn { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-line); }
.alert--err  { background: var(--err-bg);  color: var(--err-fg);  border-color: var(--err-line); }
.alert--info { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-line); }
.alert__icon { flex-shrink: 0; width: 18px; height: 18px; margin-top: 1px; }
.alert__title { font-weight: 700; }

/* Notificaciones flotantes. */
.toasts {
  position: fixed;
  bottom: 18px; right: 18px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 9px;
  max-width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: .865rem;
  animation: toast-in var(--slow) var(--ease);
}
.toast--ok   { border-left-color: var(--green-500); }
.toast--err  { border-left-color: var(--red-500); }
.toast--warn { border-left-color: var(--amber-500); }
.toast.is-leaving { animation: toast-out var(--slow) var(--ease) forwards; }
@keyframes toast-in  { from { opacity: 0; transform: translateY(14px) scale(.97); } }
@keyframes toast-out { to   { opacity: 0; transform: translateX(24px); } }

/* Pestañas. */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 10px 15px;
  font-size: .875rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  background: none;
  border-top: 0; border-left: 0; border-right: 0;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: color var(--fast) var(--ease), border-color var(--fast) var(--ease);
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

/* Interruptor de tema. */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 99px;
  gap: 1px;
}
.theme-toggle__btn {
  display: grid;
  place-items: center;
  width: 29px; height: 29px;
  border: 0;
  background: transparent;
  border-radius: 99px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.theme-toggle__btn:hover { color: var(--text); }
.theme-toggle__btn[aria-pressed="true"] { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); }
.theme-toggle__btn svg { width: 15px; height: 15px; }

/* Menú desplegable. */
.menu { position: relative; }
.menu__panel {
  position: absolute;
  right: 0; top: calc(100% + 7px);
  min-width: 224px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 5px;
  z-index: 60;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-5px);
  transition: opacity var(--fast) var(--ease), transform var(--fast) var(--ease), visibility var(--fast);
}
.menu.is-open .menu__panel { opacity: 1; visibility: visible; transform: translateY(0); }
.menu__item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  font-size: .86rem;
  color: var(--text);
  background: none;
  border: 0;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}
.menu__item:hover { background: var(--surface-2); text-decoration: none; }
.menu__item--danger { color: var(--red-500); }
.menu__sep { height: 1px; background: var(--border); margin: 5px 0; }
.menu__head { padding: 9px 11px 7px; }

/* Ventana modal. */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 11, 22, .58);
  backdrop-filter: blur(3px);
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 18px;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--slow) var(--ease), visibility var(--slow);
}
.modal-backdrop.is-open { opacity: 1; visibility: visible; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: min(560px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  transform: scale(.96);
  transition: transform var(--slow) var(--ease);
}
.modal-backdrop.is-open .modal { transform: scale(1); }
.modal__head { padding: 18px 20px 13px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.modal__body { padding: 20px; }
.modal__foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 9px; justify-content: flex-end; flex-wrap: wrap; }

/* ── 5. Formularios ────────────────────────────────────────────────────── */

.field { margin-bottom: 15px; }
.field__label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: 6px; color: var(--text-soft); }
.field__hint { font-size: .765rem; color: var(--text-muted); margin-top: 5px; line-height: 1.45; }
.field__error { font-size: .765rem; color: var(--red-500); margin-top: 5px; font-weight: 600; }
.field__req { color: var(--red-500); }

.input, .select, .textarea {
  width: 100%;
  padding: 9px 12px;
  font: inherit;
  font-size: .9rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
  -webkit-appearance: none;
  appearance: none;
}
.input:hover:not(:disabled), .select:hover:not(:disabled) { border-color: var(--text-muted); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--shadow-focus);
}
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-3); color: var(--text-muted); cursor: not-allowed; }
.input::placeholder, .textarea::placeholder { color: var(--text-muted); opacity: .75; }
.input.is-invalid, .select.is-invalid { border-color: var(--red-500); }
.textarea { min-height: 96px; resize: vertical; line-height: 1.55; }
.input--mono { font-family: var(--mono); letter-spacing: .4px; }

.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236B7C96' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 15px;
  padding-right: 34px;
}

/* Campo grande para DNI y RUC: son números que se teclean y se leen mucho. */
.input--doc {
  font-family: var(--mono);
  font-size: 1.28rem;
  letter-spacing: 3px;
  padding: 13px 15px;
  text-align: center;
  font-weight: 600;
}

.checkbox, .radio { display: flex; align-items: flex-start; gap: 9px; cursor: pointer; font-size: .875rem; line-height: 1.45; }
.checkbox input, .radio input { width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--accent); cursor: pointer; flex-shrink: 0; }

/* Interruptor. */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: .875rem; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track {
  width: 40px; height: 23px;
  background: var(--border-strong);
  border-radius: 99px;
  position: relative;
  transition: background var(--fast) var(--ease);
  flex-shrink: 0;
}
.switch__track::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 17px; height: 17px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--fast) var(--ease);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}
.switch input:checked + .switch__track { background: var(--accent); }
.switch input:checked + .switch__track::after { transform: translateX(17px); }
.switch input:focus-visible + .switch__track { box-shadow: var(--shadow-focus); }

/* Barra de fuerza de la contraseña. */
.strength { display: flex; gap: 4px; margin-top: 7px; }
.strength__bar { height: 3px; flex: 1; background: var(--border); border-radius: 99px; transition: background var(--slow) var(--ease); }
.strength__bar.is-on-1 { background: var(--red-500); }
.strength__bar.is-on-2 { background: var(--amber-500); }
.strength__bar.is-on-3 { background: #84CC16; }
.strength__bar.is-on-4 { background: var(--green-500); }

.form-row { display: grid; gap: 15px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

/* ── 6. Datos y tablas ─────────────────────────────────────────────────── */

/* Contenedor con desplazamiento propio: una tabla ancha nunca debe empujar
   el ancho de la página en móvil. */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.table { width: 100%; border-collapse: collapse; font-size: .865rem; }
.table th {
  text-align: left;
  padding: 10px 14px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { transition: background var(--fast) var(--ease); }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table--compact th, .table--compact td { padding: 7px 11px; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .nowrap { white-space: nowrap; }

/* Fila recién llegada por refresco en vivo: destello breve y suficiente. */
.is-fresh { animation: fresh 1.6s var(--ease); }
@keyframes fresh {
  0%   { background: color-mix(in srgb, var(--accent) 20%, transparent); }
  100% { background: transparent; }
}

/* Estado vacío. */
.empty { text-align: center; padding: 44px 20px; color: var(--text-muted); }
.empty__icon { width: 42px; height: 42px; margin: 0 auto 13px; opacity: .38; }
.empty__title { font-weight: 700; color: var(--text); margin-bottom: 4px; font-size: .95rem; }
.empty__text { font-size: .865rem; max-width: 380px; margin: 0 auto; }

/* Bloque de resultado JSON. */
.result {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.result__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 15px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
}
.result__body { padding: 4px 0; }

.kv { display: grid; grid-template-columns: minmax(130px, 220px) 1fr; gap: 0; }
.kv__k {
  padding: 9px 15px;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: .4px;
}
.kv__v {
  padding: 9px 15px;
  font-size: .885rem;
  border-bottom: 1px solid var(--border);
  word-break: break-word;
}
.kv > :nth-last-child(-n+2) { border-bottom: 0; }
.kv__v--strong { font-weight: 700; }
.kv__v--mono { font-family: var(--mono); font-size: .82rem; }

pre.json {
  margin: 0;
  padding: 15px;
  background: var(--navy-900);
  color: #A8E9FF;
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: .79rem;
  line-height: 1.6;
  max-height: 460px;
}

/* Barra de progreso. */
.progress { height: 7px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.progress__bar { height: 100%; background: linear-gradient(90deg, var(--cyan-500), var(--cyan-300)); border-radius: 99px; transition: width var(--slow) var(--ease); }
.progress__bar--warn { background: linear-gradient(90deg, var(--amber-500), #FBBF24); }
.progress__bar--err  { background: linear-gradient(90deg, var(--red-500), #F87171); }

/* Gráfico de barras en CSS puro: sin librerías y sin peticiones extra.
   Cada columna ocupa toda la altura y hace de carril; la barra va dentro,
   anclada abajo. Sin el carril a altura completa, el porcentaje de la barra
   no tendría contra qué calcularse y todas saldrían del mismo tamaño. */
.chart { display: flex; align-items: stretch; gap: 2px; height: 130px; padding-top: 8px; }
.chart__col {
  flex: 1;
  min-width: 3px;
  height: 100%;
  background: var(--accent-soft);
  border-radius: 3px 3px 0 0;
  position: relative;
  transition: background var(--fast) var(--ease);
}
.chart__col > span {
  position: absolute;
  left: 0; bottom: 0;
  width: 100%;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  transition: height var(--slow) var(--ease);
}
.chart__col:hover { background: var(--surface-3); }
.chart__col:hover::after {
  content: attr(data-label);
  position: absolute;
  bottom: calc(100% + 6px); left: 50%;
  transform: translateX(-50%);
  background: var(--navy-800);
  color: #fff;
  font-size: .7rem;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
  z-index: 5;
  pointer-events: none;
}

/* Paginación. */
.pager { display: flex; gap: 5px; align-items: center; justify-content: center; flex-wrap: wrap; padding: 16px 0 4px; }
.pager__link {
  min-width: 33px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-soft);
  text-align: center;
  background: var(--surface);
}
.pager__link:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.pager__link.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* Esqueleto de carga. */
.skeleton {
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── 7. Estados y utilidades ───────────────────────────────────────────── */

.stack     { display: flex; flex-direction: column; gap: 16px; }
.stack--sm { gap: 9px; }
.stack--lg { gap: 24px; }
.row       { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row--tight{ gap: 6px; }
.row--between { justify-content: space-between; }
.row--end  { justify-content: flex-end; }

.muted   { color: var(--text-muted); }
.soft    { color: var(--text-soft); }
.small   { font-size: .8rem; }
.tiny    { font-size: .72rem; }
.strong  { font-weight: 700; }
.center  { text-align: center; }
.right   { text-align: right; }
.nums    { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.break   { word-break: break-all; }

.mt-0 { margin-top: 0; }  .mt-1 { margin-top: 8px; }  .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.hidden { display: none !important; }
.flex-1 { flex: 1; }

.text-ok   { color: var(--green-500); }
.text-warn { color: var(--amber-500); }
.text-err  { color: var(--red-500); }
.text-accent { color: var(--accent); }

/* Sólo para lectores de pantalla. */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Salto al contenido, visible sólo al tabular. */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: 999;
  padding: 10px 16px;
  background: var(--accent);
  color: var(--accent-text);
  border-radius: var(--radius-sm);
  font-weight: 600;
}
.skip-link:focus { left: 8px; }

/* ── 8. Adaptación a pantallas ─────────────────────────────────────────── */

/* Los diseños de dos columnas se apilan por debajo de 900 px.
   El selector apunta sólo a las rejillas con columnas declaradas en el
   atributo style; las de `grid--2/3/4` ya se adaptan solas con auto-fit y no
   conviene tocarlas. Sin esta regla, la columna estrecha quedaría por debajo
   de su ancho mínimo y empujaría la página hacia los lados. */
@media (max-width: 900px) {
  .grid[style*="grid-template-columns"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}

/* Barra lateral deslizante en tabletas y móviles. */
@media (max-width: 1023px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform var(--slow) var(--ease);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(5, 11, 22, .5);
    z-index: 99;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--slow) var(--ease), visibility var(--slow);
  }
  .sidebar-backdrop.is-open { opacity: 1; visibility: visible; }
  .menu-btn { display: inline-flex !important; }
}

@media (min-width: 1024px) {
  .menu-btn { display: none !important; }
}

/* Teléfonos. */
@media (max-width: 640px) {
  body { font-size: 14.5px; }
  h1 { font-size: 1.32rem; }

  /* En 375 px no caben el menú, el título, el saldo, el selector de tema y
     el menú de usuario. El selector de tema se traslada al desplegable, que
     es donde el usuario ya va a buscar los ajustes de su cuenta. */
  .topbar--app > .theme-toggle { display: none; }
  .menu__theme { display: flex; justify-content: center; }
  .topbar { gap: 8px; padding: 0 11px; }
  /* La cabecera pública no tiene menú de usuario, así que conserva su
     selector de tema y en su lugar puede crecer en alto si hace falta. */
  .topbar:not(.topbar--app) { height: auto; flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; }
  .topbar__title { font-size: .95rem; }
  .credits { padding: 5px 10px; font-size: .8rem; }

  .content { padding: 13px; padding-bottom: 78px; }
  .card__body, .card__head, .card__foot { padding-left: 14px; padding-right: 14px; }
  .stat__value { font-size: 1.5rem; }

  /* Las tablas densas pasan a formato de ficha: en 360 px de ancho, una
     tabla de siete columnas es ilegible por muy bien que se desplace. */
  .table--cards thead { display: none; }
  .table--cards tbody tr {
    display: block;
    padding: 11px 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 9px;
    background: var(--surface);
  }
  .table--cards tbody td {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    padding: 4px 0;
    border: 0;
    text-align: right;
  }
  .table--cards tbody td::before {
    content: attr(data-label);
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted);
    text-align: left;
    flex-shrink: 0;
  }

  /* En modo tarjeta la fila deja de ser una fila de tabla, pero la <table>
     seguia reclamando el ancho de su contenido mas ancho y la tarjeta se salia
     del movil. Con table-layout fijo y los anchos en linea neutralizados, cada
     tarjeta se ajusta al hueco disponible. */
  .table--cards { width: 100%; table-layout: fixed; }
  .table--cards tbody td { min-width: 0; }
  .table--cards tbody td > * { max-width: 100% !important; }
  .table--cards tbody td::before { max-width: 42%; }
  /* Correos, glosas y nombres largos no tienen espacios donde partir: sin
     esto empujan la tarjeta a lo ancho y reaparece el desplazamiento. */
  .table--cards tbody td { overflow-wrap: anywhere; }

  /* Una celda con varias lineas (remitente + asunto, glosa + pagador + orden)
     no cabe en la fila "etiqueta a la izquierda, valor a la derecha": las
     lineas se colocaban una al lado de otra y quedaba ilegible. En esos casos
     se pone la etiqueta encima y el valor debajo.
     Si el navegador no entiende :has(), la regla se ignora y queda como antes:
     nunca peor. */
  .table--cards tbody td:has(> * + *) {
    display: block;
    text-align: left;
  }
  .table--cards tbody td:has(> * + *)::before {
    display: block;
    max-width: none;
    margin-bottom: 3px;
  }

  .kv { grid-template-columns: 1fr; }
  .kv__k { padding-bottom: 1px; border-bottom: 0; }
  .kv__v { padding-top: 1px; }

  .toasts { left: 13px; right: 13px; bottom: 13px; max-width: none; }
  .modal { border-radius: var(--radius-lg); }
  .modal__foot { flex-direction: column-reverse; }
  .modal__foot .btn { width: 100%; }

  /* Barra inferior de navegación: alcanzable con el pulgar. */
  .tabbar {
    display: flex !important;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 5px 4px calc(5px + env(safe-area-inset-bottom));
    z-index: 90;
  }
  .tabbar__item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 2px;
    font-size: .66rem;
    font-weight: 600;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
  }
  .tabbar__item.is-active { color: var(--accent); }
  .tabbar__item:hover { text-decoration: none; }
  .tabbar__item svg { width: 20px; height: 20px; }
}

.tabbar { display: none; }

/* Impresión: sólo el contenido. */
/* Caja del QR de alta del 2FA. El SVG lleva ancho fijo y crece con la
   longitud del correo del usuario, asi que se le deja encoger para que nunca
   se salga de la tarjeta en pantallas estrechas. */
.qr-box {
  display: inline-block;
  background: #fff;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  max-width: 100%;
}
.qr-box svg { display: block; width: 100%; height: auto; max-width: 280px; }

/* Ventana de confirmación propia, la que sustituye al confirm() del navegador. */
.modal--confirm { width: min(440px, 100%); }
.modal--confirm .modal__head { border-bottom: 0; padding-bottom: 4px; align-items: flex-start; }
.modal--confirm .modal__body { padding-top: 10px; }

.modal__icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 50%;
}
.modal__icon--danger { background: var(--err-bg);  color: var(--err-fg); }
.modal__icon--warn   { background: var(--warn-bg); color: var(--warn-fg); }
.modal__icon--info   { background: var(--info-bg); color: var(--info-fg); }

.modal__text { margin: 0; color: var(--text-muted); line-height: 1.55; }

/* Los datos que el usuario debe leer antes de aceptar: coste, consecuencias. */
.modal__points {
  margin: 12px 0 0;
  padding: 11px 14px;
  list-style: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: grid;
  gap: 7px;
}
.modal__points li {
  position: relative;
  padding-left: 16px;
  font-size: .86rem;
  color: var(--text);
  line-height: 1.45;
}
.modal__points li::before {
  content: "";
  position: absolute;
  left: 0;
  top: .5em;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
}

/* Con una modal abierta el fondo no debe desplazarse. */
body.has-modal { overflow: hidden; }

/* ── Gestión del buzón de correos de pago ─────────────────────────────── */

/* La cabecera de esa tarjeta lleva buscador, dos selectores y botones: en
   pantallas estrechas tiene que poder envolver en varias líneas. */
.card__head--wrap { flex-wrap: wrap; gap: 10px; row-gap: 10px; }

.input--sm, .select--sm { padding: 6px 10px; font-size: .82rem; }

/* Barra que aparece al marcar correos. Se queda pegada arriba para que los
   botones sigan a mano aunque la lista sea larga. */
.bulkbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 18px;
  background: var(--info-bg);
  color: var(--info-fg);
  border-bottom: 1px solid var(--info-line);
}

/* Fila que se está quitando: se desvanece antes de desaparecer, para que el
   administrador vea cuál se fue. */
tr.is-removing { opacity: .35; transition: opacity var(--slow) var(--ease); }

/* Mientras se recarga la tabla por AJAX se atenúa, en lugar de parpadear en
   blanco: se sigue leyendo lo anterior hasta que llega lo nuevo. */
[data-correos-caja].is-loading { opacity: .5; pointer-events: none; transition: opacity 120ms var(--ease); }

/* Código QR de la pantalla de pago. Fondo blanco siempre: un QR sobre fondo
   oscuro no lo lee ninguna cámara. */
.qr-pago {
  display: inline-block;
  background: #fff;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  max-width: 100%;
}
.qr-pago svg,
.qr-pago img { display: block; width: 100%; height: auto; max-width: 240px; }

@media print {
  .sidebar, .topbar, .tabbar, .toasts, .btn, .pager { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border: 1px solid #ccc; box-shadow: none; break-inside: avoid; }
  .content { padding: 0; max-width: none; }
}
