/* I-KELA · Facturación electrónica — panel. Tema claro y oscuro (sigue al sistema, o el
   elegido en la barra). Sin estilos inline: CSP style-src 'self'; fuentes alojadas acá. */

@font-face {
  font-family: 'Inter';
  src: url('./fonts/inter-var.woff2') format('woff2');
  font-weight: 100 900; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Plex Mono';
  src: url('./fonts/plex-mono-400.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Plex Mono';
  src: url('./fonts/plex-mono-500.woff2') format('woff2');
  font-weight: 500 700; font-style: normal; font-display: swap;
}

/* ── Tokens ─────────────────────────────────────────────────────────────────
   brand: el celeste del logo (#26A0DA), para el isotipo y acentos que no son texto.
   brand-ink / accent: variantes legibles como texto o fondo de botón. */
:root {
  color-scheme: light;
  --navy: #0e1a2b;
  --navy-2: #172840;
  --brand: #26a0da;

  --bg: #f2f5f8;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --border: #d9e1ea;
  --border-strong: #c3ceda;
  --text: #0e1a2b;
  --text-2: #4a5b70;
  --text-3: #66778b;
  --brand-ink: #1272a6;
  --accent: #1477ae;
  --accent-hover: #0f6596;
  --on-accent: #ffffff;
  --accent-soft: #e3f2fa;
  --danger: #c2362b;
  --danger-hover: #a52c22;
  --on-danger: #ffffff;
  --code: #0f5e8a;

  --ok-bg: #e2f4ea;      --ok-fg: #17663f;
  --warn-bg: #fdf0d9;    --warn-fg: #85500e;
  --bad-bg: #fbe5e2;     --bad-fg: #a42a21;
  --info-bg: #e2f1fa;    --info-fg: #10618f;
  --batch-bg: #ecebfb;   --batch-fg: #4a41a8;
  --neutral-bg: #edf0f4; --neutral-fg: #4a5b70;

  --overlay: rgba(14, 26, 43, .42);
  --shadow: 0 1px 2px rgba(14, 26, 43, .05), 0 6px 20px rgba(14, 26, 43, .07);
  --shadow-lg: 0 12px 40px rgba(14, 26, 43, .18);

  /* Serie del gráfico de actividad (validada para CVD). */
  --viz-aprobado: #1f9254;
  --viz-proceso: #2f8fd0;
  --viz-rechazado: #d0473b;
  --viz-otro: #8a7fd6;

  --radius: 10px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Oscuro: con la preferencia del sistema (si no se eligió claro) o elegido a mano. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #0a1220; --surface: #111c2d; --surface-2: #18263b; --border: #22334b;
    --border-strong: #2e4360; --text: #e6edf5; --text-2: #9db0c6; --text-3: #8297ad;
    --brand-ink: #5ec0ec; --accent: #26a0da; --accent-hover: #4bb3e4; --on-accent: #04121f;
    --accent-soft: rgba(38, 160, 218, .14); --danger: #c8433a; --danger-hover: #d75a51;
    --code: #8dd3f3;
    --ok-bg: rgba(34, 160, 90, .16); --ok-fg: #7edca8;
    --warn-bg: rgba(230, 160, 40, .16); --warn-fg: #f2c46b;
    --bad-bg: rgba(226, 90, 78, .17); --bad-fg: #f4a39a;
    --info-bg: rgba(38, 160, 218, .16); --info-fg: #8dd3f3;
    --batch-bg: rgba(130, 120, 240, .18); --batch-fg: #c3bdfa;
    --neutral-bg: #1c2a40; --neutral-fg: #b6c4d6;
    --overlay: rgba(2, 6, 15, .66);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .28);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, .5);
    --viz-aprobado: #0ca30c; --viz-proceso: #3987e5; --viz-rechazado: #d03b3b; --viz-otro: #9085e9;
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0a1220; --surface: #111c2d; --surface-2: #18263b; --border: #22334b;
  --border-strong: #2e4360; --text: #e6edf5; --text-2: #9db0c6; --text-3: #8297ad;
  --brand-ink: #5ec0ec; --accent: #26a0da; --accent-hover: #4bb3e4; --on-accent: #04121f;
  --accent-soft: rgba(38, 160, 218, .14); --danger: #c8433a; --danger-hover: #d75a51;
  --code: #8dd3f3;
  --ok-bg: rgba(34, 160, 90, .16); --ok-fg: #7edca8;
  --warn-bg: rgba(230, 160, 40, .16); --warn-fg: #f2c46b;
  --bad-bg: rgba(226, 90, 78, .17); --bad-fg: #f4a39a;
  --info-bg: rgba(38, 160, 218, .16); --info-fg: #8dd3f3;
  --batch-bg: rgba(130, 120, 240, .18); --batch-fg: #c3bdfa;
  --neutral-bg: #1c2a40; --neutral-fg: #b6c4d6;
  --overlay: rgba(2, 6, 15, .66);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .28);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, .5);
  --viz-aprobado: #0ca30c; --viz-proceso: #3987e5; --viz-rechazado: #d03b3b; --viz-otro: #9085e9;
}

/* ── Base ───────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-feature-settings: 'cv11', 'ss01';
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: rgba(38, 160, 218, .18);
}
a { color: var(--brand-ink); text-underline-offset: 2px; }
h1, h2, h3 { letter-spacing: -.01em; }
.skip-link {
  position: fixed; top: 8px; left: 8px; z-index: 100;
  padding: 8px 12px; border-radius: 8px; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow); transform: translateY(-150%);
}
.skip-link:focus { transform: translateY(0); }

/* ── Marca ──────────────────────────────────────────────────────────────── */
/* El isotipo de nodos va como máscara: toma el color de su contexto. */
.isotipo {
  display: inline-block; width: 26px; height: 28px; flex: none;
  background: var(--brand);
  -webkit-mask: url('./img/isotipo.svg') center / contain no-repeat;
  mask: url('./img/isotipo.svg') center / contain no-repeat;
}
.marca { display: inline-flex; align-items: center; gap: 10px; white-space: nowrap; text-decoration: none; }
.marca .palabra { font-weight: 800; font-size: 17px; letter-spacing: .06em; color: #fff; }
.marca .producto {
  padding-left: 10px; border-left: 1px solid rgba(255, 255, 255, .18);
  color: #a9bbcf; font-size: 12px; font-weight: 500; letter-spacing: .01em;
}

/* ── Layout ─────────────────────────────────────────────────────────────── */
.app { min-height: 100vh; display: flex; flex-direction: column; }
/* La barra es la franja de marca: azul marino en los dos temas. */
.topbar {
  display: flex; align-items: center; gap: 22px;
  background: var(--navy); color: #fff; padding: 0 22px; height: 58px;
  position: sticky; top: 0; z-index: 20;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .04), 0 2px 12px rgba(4, 10, 20, .25);
}
.topbar nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; align-self: stretch; scrollbar-width: none; }
.topbar nav::-webkit-scrollbar { display: none; }
.topbar nav a {
  display: flex; align-items: center; position: relative;
  color: #a9bbcf; text-decoration: none; padding: 0 12px; white-space: nowrap;
  font-size: 13px; font-weight: 500; transition: color .15s;
}
.topbar nav a:hover { color: #fff; }
.topbar nav a.active { color: #fff; }
.topbar nav a.active::after {
  content: ''; position: absolute; left: 12px; right: 12px; bottom: 0; height: 3px;
  border-radius: 3px 3px 0 0; background: var(--brand);
}
.topbar nav a:focus-visible { outline-offset: -3px; }
.topbar .session { display: flex; align-items: center; gap: 8px; color: #a9bbcf; font-size: 12px; }
.topbar .session .who { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .session button {
  background: rgba(255, 255, 255, .06); color: #e6edf5; border: 1px solid rgba(255, 255, 255, .14);
  padding: 6px 11px; font-size: 12px;
}
.topbar .session button:hover { background: rgba(255, 255, 255, .12); }
.topbar .session button.tema { padding: 5px 7px; line-height: 0; }

main.content { padding: 28px 24px 40px; max-width: 1240px; width: 100%; margin: 0 auto; flex: 1; }

.view-title { display: flex; align-items: baseline; gap: 6px 14px; margin: 0 0 20px; flex-wrap: wrap; }
.view-title h1 { margin: 0; font-size: 22px; font-weight: 750; letter-spacing: -.02em; text-wrap: balance; }
.view-title .sub { color: var(--text-2); font-size: 13px; }
.view-title > button, .view-title > .btn { margin-left: auto; }

/* ── Controles ──────────────────────────────────────────────────────────── */
input, select, textarea {
  background: var(--surface); border: 1px solid var(--border-strong); color: var(--text);
  padding: 8px 10px; border-radius: 8px; font: inherit; transition: border-color .15s, box-shadow .15s;
}
input:hover, select:hover, textarea:hover { border-color: var(--text-3); }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(38, 160, 218, .25);
}
button:focus-visible, a:focus-visible, summary:focus-visible, .btn:focus-visible {
  outline: 3px solid var(--brand); outline-offset: 2px;
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 500; color: var(--text-2); }
.company-form { display: flex; flex-direction: column; gap: 14px; }
.company-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.company-form textarea { resize: vertical; min-height: 120px; }

button, .btn {
  background: var(--accent); border: 1px solid transparent; color: var(--on-accent); padding: 8px 14px;
  border-radius: 8px; cursor: pointer; font: inherit; font-weight: 600; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px; transition: background-color .15s, border-color .15s;
}
button, a, input, select, textarea { touch-action: manipulation; }
button:hover, .btn:hover { background: var(--accent-hover); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.secondary, .btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
button.secondary:hover, .btn.secondary:hover { background: var(--surface-2); }
button.danger { background: var(--danger); color: var(--on-danger); }
button.danger:hover { background: var(--danger-hover); }
button.link { background: none; color: var(--brand-ink); padding: 3px 6px; font-weight: 500; border-radius: 6px; }
button.link:hover { background: var(--accent-soft); }
button.danger-link { color: var(--bad-fg); }
button.danger-link:hover { background: var(--bad-bg); }

.filters {
  display: flex; gap: 10px; align-items: end; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px; box-shadow: var(--shadow);
}

/* ── Tarjetas / indicadores ─────────────────────────────────────────────── */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 22px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.card .n { font-size: 28px; font-weight: 750; line-height: 1.15; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.card .l { font-size: 11px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .07em; margin-top: 4px; }
.card.clickable { cursor: pointer; display: block; color: inherit; text-decoration: none; transition: border-color .15s, transform .15s; }
.card.clickable:hover { border-color: var(--brand); }

.panel-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.panel-box h2 { margin: 0 0 12px; font-size: 15px; color: var(--text); font-weight: 650; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-head h2 { margin: 0; }
.section-note { color: var(--text-2); font-size: 13px; margin: -4px 0 14px; max-width: 72ch; }

/* ── Integraciones ──────────────────────────────────────────────────────── */
.destination-list { display: grid; gap: 10px; }
.destination { padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.destination-head { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.destination-url { overflow-wrap: anywhere; }
.destination-actions { margin: 10px 0 0; }
.event-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.event-chip {
  padding: 3px 9px; border: 1px solid var(--border-strong); border-radius: 999px;
  color: var(--text-2); font-size: 11px; background: var(--surface);
}
.event-selector { display: grid; gap: 8px; margin: 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; }
.event-selector legend { color: var(--text-2); font-size: 12px; padding: 0 4px; }
.event-option { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }
.event-option input { margin: 0; accent-color: var(--accent); }
.secret-reveal p { line-height: 1.5; }
.secret-code {
  display: block; padding: 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--code); font-family: var(--mono);
  overflow-wrap: anywhere; user-select: all;
}
.recovery-codes { white-space: pre-wrap; line-height: 1.65; }

/* ── Configuración fiscal ───────────────────────────────────────────────── */
.fiscal-sequence {
  list-style: none; margin: 0 0 20px; padding: 0; display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)); counter-reset: fiscal-step;
}
.fiscal-sequence li {
  counter-increment: fiscal-step; position: relative; min-width: 0;
  padding: 12px 14px 12px 46px; border-block: 1px solid var(--border);
  background: var(--surface);
}
.fiscal-sequence li:first-child { border-left: 1px solid var(--border); border-radius: var(--radius) 0 0 var(--radius); }
.fiscal-sequence li:last-child { border-right: 1px solid var(--border); border-radius: 0 var(--radius) var(--radius) 0; }
.fiscal-sequence li::before {
  content: counter(fiscal-step); position: absolute; left: 14px; top: 14px;
  width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%;
  background: var(--neutral-bg); color: var(--neutral-fg); font: 500 11px var(--mono);
}
.fiscal-sequence li.ready::before { background: var(--ok-bg); color: var(--ok-fg); }
.fiscal-sequence li.missing::before { background: var(--warn-bg); color: var(--warn-fg); }
.sequence-name, .sequence-state { display: block; overflow-wrap: anywhere; }
.sequence-name { color: var(--text-3); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.fiscal-sequence strong { display: block; margin: 2px 0; font-size: 20px; font-variant-numeric: tabular-nums; }
.sequence-state { color: var(--text-3); font-size: 11px; }
.config-list { display: grid; gap: 10px; }
.config-record { padding: 13px 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.config-record.inactive, .point-list li.inactive { opacity: .68; }
.config-record-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.config-record-head > div { min-width: 0; display: flex; align-items: baseline; gap: 10px; }
.record-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 6px; }
.config-code { color: var(--code); font-family: var(--mono); }
.record-meta, .record-empty { margin: 8px 0 0; color: var(--text-2); font-size: 12px; overflow-wrap: anywhere; }
.config-warning { margin: 0; padding: 9px 11px; border-radius: 7px; background: var(--warn-bg); color: var(--warn-fg); font-size: 12px; }
.config-warning:empty { display: none; }
.point-list { display: flex; flex-wrap: wrap; gap: 7px; list-style: none; margin: 10px 0 0; padding: 0; }
.point-list li { display: flex; align-items: center; gap: 6px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; background: var(--surface); }
.intervention-box { border-color: var(--warn-fg); }
.dlq-error { max-width: 340px; overflow-wrap: anywhere; color: var(--bad-fg); }

/* ── Tablas ─────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.panel-box .table-wrap, .modal .table-wrap { box-shadow: none; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; font-size: 13px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
th {
  background: var(--surface-2); color: var(--text-3); text-transform: uppercase;
  font-size: 11px; font-weight: 600; letter-spacing: .06em; white-space: nowrap;
}
tbody tr { transition: background-color .12s; }
tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
tbody tr.row-click { cursor: pointer; }
td.mono, .mono { font-family: var(--mono); font-size: 12px; letter-spacing: -.01em; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 28px; text-align: center; color: var(--text-2); }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 4px; color: var(--text-2); font-size: 13px; }

/* CDC en once grupos de 4, como en el KuDE (MT v150 §13.4.4): se lee y se dicta mejor. */
.cdc { font-family: var(--mono); font-size: 12px; letter-spacing: .01em; word-spacing: .2em; }

/* ── Estados ────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; white-space: nowrap; line-height: 1.6;
  background: var(--neutral-bg); color: var(--neutral-fg);
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge.rol::before { display: none; }
.badge.APPROVED, .badge.PROCESSED, .badge.ACTIVO, .badge.PROD { background: var(--ok-bg); color: var(--ok-fg); }
.badge.OBSERVED, .badge.TEST, .badge.EXPIRADO, .badge.NEEDS_REVIEW { background: var(--warn-bg); color: var(--warn-fg); }
.badge.CONTINGENCY { background: var(--warn-bg); color: var(--warn-fg); }
.badge.REJECTED, .badge.ERROR, .badge.FAILED, .badge.EXHAUSTED, .badge.SUSPENDIDO, .badge.BAJA { background: var(--bad-bg); color: var(--bad-fg); }
.badge.RECEIVED, .badge.VALIDATED, .badge.CANCELLED, .badge.INUTILIZED, .badge.REVOCADO { background: var(--neutral-bg); color: var(--neutral-fg); }
.badge.SIGNED, .badge.QUEUED, .badge.SENT, .badge.PENDING, .badge.SUBMITTING, .badge.SUBMITTED, .badge.DELIVERED { background: var(--info-bg); color: var(--info-fg); }
.badge.IN_BATCH, .badge.BATCH_SUBMITTED, .badge.BATCH_PENDING, .badge.BUILDING { background: var(--batch-bg); color: var(--batch-fg); }
.badge.rol { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }

/* ── Certificado ────────────────────────────────────────────────────────── */
.cert-ficha { display: flex; flex-direction: column; gap: 6px; }
.cert-row { display: flex; gap: 12px; font-size: 13px; align-items: baseline; }
.cert-row .k { color: var(--text-2); min-width: 130px; }
.cert-row .v { overflow-wrap: anywhere; }
.cert-warn { margin-top: 12px; padding: 10px 12px; border-radius: 8px; font-size: 13px; background: var(--warn-bg); color: var(--warn-fg); }
.cert-warn.vencido { background: var(--bad-bg); color: var(--bad-fg); }

/* ── Login: franja de marca + formulario ────────────────────────────────── */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
.login-marca {
  position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between;
  padding: 44px 52px; color: #fff;
  background:
    radial-gradient(120% 90% at 85% 15%, rgba(38, 160, 218, .22), transparent 60%),
    linear-gradient(160deg, var(--navy-2) 0%, var(--navy) 55%, #08111e 100%);
}
.login-marca .marca .palabra { font-size: 19px; }
.login-red { width: min(300px, 62%); align-self: center; margin: 24px 0; }
.login-red svg { display: block; width: 100%; height: auto; overflow: visible; }
/* Los nodos se conectan una vez al entrar; con movimiento reducido, aparecen quietos. */
.login-red .n, .login-red .l, .login-red .c { fill: none; stroke: var(--brand); stroke-linecap: round; stroke-linejoin: round; }
.login-red .n { stroke-width: 3.2; animation: red-aparecer .5s ease-out both; }
.login-red .l { stroke-width: 2.6; stroke-dasharray: 44; animation: red-trazar .7s ease-in-out both; }
.login-red .c { stroke-width: 3.6; fill: rgba(38, 160, 218, .14); transform-box: fill-box; transform-origin: center;
  animation: red-centro .6s cubic-bezier(.2, .9, .3, 1.3) 1.25s both; }
.login-red .p { fill: var(--brand); animation: red-aparecer .3s ease-out 1.5s both; }
.login-red .n1 { animation-delay: .05s; } .login-red .n2 { animation-delay: .15s; }
.login-red .n3 { animation-delay: .25s; } .login-red .n4 { animation-delay: .35s; }
.login-red .l1 { animation-delay: .45s; } .login-red .l2 { animation-delay: .55s; }
.login-red .l3 { animation-delay: .65s; } .login-red .l4 { animation-delay: .75s; }
@keyframes red-aparecer { from { opacity: 0; } to { opacity: 1; } }
@keyframes red-trazar { from { stroke-dashoffset: 44; } to { stroke-dashoffset: 0; } }
@keyframes red-centro { from { opacity: 0; transform: scale(.6); } to { opacity: 1; transform: scale(1); } }
.login-lema { max-width: 30ch; margin: 0; }
.login-lema strong { display: block; font-size: 30px; font-weight: 750; line-height: 1.12; letter-spacing: -.025em; }
.login-lema span { display: block; margin-top: 12px; color: #a9bbcf; font-size: 14px; line-height: 1.5; }
.login-form { display: grid; place-items: center; padding: 32px 24px; background: var(--bg); }
.login-box { width: 100%; max-width: 360px; }
.login-box h1 { font-size: 22px; font-weight: 750; letter-spacing: -.02em; margin: 0 0 6px; }
.login-box .sub { color: var(--text-2); font-size: 13px; margin-bottom: 24px; }
.login-box form { display: flex; flex-direction: column; gap: 14px; }
.login-box form button[type='submit'] { justify-content: center; padding: 10px 14px; margin-top: 4px; }
.login-alt { margin-top: 18px; text-align: center; }
.login-alt .link { font-size: 12px; color: var(--text-2); }
.login-alt .link:hover { color: var(--text); }
.form-error { color: var(--bad-fg); font-size: 13px; min-height: 18px; }

/* ── Detalle (drawer) ───────────────────────────────────────────────────── */
.drawer-backdrop { position: fixed; inset: 0; background: var(--overlay); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(680px, 100%);
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
  z-index: 41; overflow-y: auto; overscroll-behavior: contain;
  padding: max(20px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom)) 24px;
}
.drawer .drawer-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.drawer .drawer-head h2 { margin: 0; flex: 1; font-size: 17px; font-weight: 700; }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 7px 14px; font-size: 13px; margin-bottom: 16px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; word-break: break-word; }
.timeline { list-style: none; margin: 0 0 16px; padding: 0; }
.timeline li { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px; align-items: baseline; }
.timeline li:last-child { border-bottom: 0; }
.timeline .t { color: var(--text-3); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.actions-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0; }
details.raw { margin-top: 12px; }
details.raw pre {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; overflow: auto; max-height: 320px; font: 12px/1.5 var(--mono);
}
details.raw summary { cursor: pointer; color: var(--text-2); }

/* ── Modal ──────────────────────────────────────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; background: var(--overlay); z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg);
  padding: 24px; width: 100%; max-width: 440px; max-height: calc(100dvh - 40px);
  overflow-y: auto; overscroll-behavior: contain;
}
.modal h2 { margin: 0 0 14px; font-size: 17px; font-weight: 700; }
.modal.wide { max-width: 760px; }
.modal .panel-box { box-shadow: none; padding: 0; border: 0; margin-bottom: 8px; }
.row-actions { white-space: nowrap; }
.modal form { display: flex; flex-direction: column; gap: 12px; }
.modal .modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }

/* ── Avisos ─────────────────────────────────────────────────────────────── */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--info-fg); color: var(--text);
  padding: 10px 14px; border-radius: 10px; font-size: 13px; max-width: 380px; box-shadow: var(--shadow-lg);
}
.toast.error { border-left-color: var(--bad-fg); }
.toast.warn { border-left-color: var(--warn-fg); }
.toast.ok { border-left-color: var(--ok-fg); }

/* ── Gráfico de actividad ───────────────────────────────────────────────── */
.viz { position: relative; }
.viz svg { display: block; width: 100%; height: auto; }
.viz .bar-seg { shape-rendering: crispEdges; }
.viz .grid-line { stroke: var(--border); stroke-width: 1; }
.viz .axis-label { fill: var(--text-3); font-size: 10px; font-family: inherit; }
.viz-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 10px; font-size: 12px; color: var(--text-2); }
.viz-legend .item { display: inline-flex; align-items: center; gap: 6px; }
.viz-legend .swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.viz-legend .swatch.aprobado { background: var(--viz-aprobado); }
.viz-legend .swatch.proceso { background: var(--viz-proceso); }
.viz-legend .swatch.rechazado { background: var(--viz-rechazado); }
.viz-legend .swatch.otro { background: var(--viz-otro); }
.viz-tooltip {
  position: absolute; left: 40px; top: 8px; pointer-events: none; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  font-size: 12px; z-index: 10; min-width: 140px; box-shadow: var(--shadow-lg);
  display: none;
}
.viz-tooltip.visible { display: block; }
.viz-tooltip .tt-title { color: var(--text-2); margin-bottom: 4px; }
.viz-tooltip .tt-row { display: flex; justify-content: space-between; gap: 12px; }

.loading { color: var(--text-2); padding: 30px; text-align: center; }

/* ── Personalización del KuDE (Empresa) ─────────────────────────────────── */
.logo-row { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; margin: 12px 0; }
.logo-preview {
  width: 200px; height: 120px; flex: none; display: flex; align-items: center; justify-content: center;
  background: #fff; border: 1px dashed var(--border-strong); border-radius: var(--radius); padding: 8px;
}
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-preview .sub { color: #64748b; }
.logo-actions { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 220px; }
.logo-actions .actions-row { margin: 6px 0 0; }

/* ── Movimiento ─────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ── Pantallas chicas ───────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .login-wrap { grid-template-columns: 1fr; }
  .login-marca { padding: 22px 22px 26px; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 14px; }
  .login-red { display: none; }
  .login-lema strong { font-size: 20px; }
  .login-lema span { margin-top: 6px; font-size: 13px; }
  .login-form { place-items: start center; padding-top: 28px; }
}
@media (max-width: 720px) {
  .topbar { height: auto; min-height: 56px; padding: 10px 14px 0; flex-wrap: wrap; gap: 6px 10px; }
  .vista-cliente { position: static; }
  .topbar .marca .producto { display: none; }
  .topbar nav { order: 3; flex-basis: 100%; height: 42px; }
  .topbar .session { margin-left: auto; }
  .topbar .session .who { display: none; }
  .kv { grid-template-columns: 1fr; }
  .company-grid { grid-template-columns: 1fr; }
  .fiscal-sequence { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fiscal-sequence li:first-child { border-radius: var(--radius) 0 0 0; }
  .fiscal-sequence li:nth-child(2) { border-right: 1px solid var(--border); border-radius: 0 var(--radius) 0 0; }
  .fiscal-sequence li:nth-child(3) { border-left: 1px solid var(--border); border-radius: 0 0 0 var(--radius); }
  .fiscal-sequence li:last-child { border-radius: 0 0 var(--radius) 0; }
  main.content { padding: 18px 14px 32px; }
  .view-title h1 { font-size: 20px; }
}

/* «Ver como cliente»: aviso fijo de que la plataforma está viendo el panel de un tenant. */
.vista-cliente {
  position: sticky; top: 58px; z-index: 9;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px;
  padding: 8px 16px; background: var(--warn-bg); color: var(--warn-fg);
  border-bottom: 1px solid currentColor; font-size: 13px;
}
