/* ==========================================================================
   Consola · Facturación DIAN — sistema de diseño
   Tokens → base → layout → componentes → páginas → utilidades
   ========================================================================== */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light dark;

  /* Neutros (grises fríos) */
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --surface-3: #e2e8f0;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #64748b;

  /* Marca: verde petróleo */
  --brand: #0f766e;
  --brand-hover: #115e59;
  --brand-soft: #f0fdfa;
  --brand-border: #99f6e4;
  --on-brand: #ffffff;

  /* Semánticos: texto · fondo suave · borde */
  --ok: #15803d;      --ok-soft: #f0fdf4;     --ok-border: #bbf7d0;
  --proc: #b45309;    --proc-soft: #fffbeb;   --proc-border: #fde68a;
  --mal: #b91c1c;     --mal-soft: #fef2f2;    --mal-border: #fecaca;
  --gris: #475569;    --gris-soft: #f1f5f9;   --gris-border: #e2e8f0;

  /* Tipografía */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
  --fs-xs: 12px; --fs-sm: 13px; --fs-base: 14px; --fs-md: 16px; --fs-lg: 20px; --fs-xl: 24px; --fs-2xl: 30px;

  /* Espaciado (escala de 4 px) */
  --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;

  /* Radios y sombras */
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-full: 999px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 1px rgba(15, 23, 42, .03);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, .08), 0 2px 6px rgba(15, 23, 42, .04);
  --ring: 0 0 0 3px rgba(15, 118, 110, .25);

  --side-w: 248px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #172033;
    --surface-3: #243045;
    --border: #243045;
    --border-strong: #334155;
    --text: #e5e7eb;
    --text-2: #a3adbd;
    --text-3: #94a3b8;

    --brand: #2dd4bf;
    --brand-hover: #5eead4;
    --brand-soft: rgba(45, 212, 191, .10);
    --brand-border: rgba(45, 212, 191, .35);
    --on-brand: #042f2e;

    --ok: #4ade80;   --ok-soft: rgba(74, 222, 128, .10);   --ok-border: rgba(74, 222, 128, .30);
    --proc: #fbbf24; --proc-soft: rgba(251, 191, 36, .10); --proc-border: rgba(251, 191, 36, .30);
    --mal: #f87171;  --mal-soft: rgba(248, 113, 113, .10); --mal-border: rgba(248, 113, 113, .32);
    --gris: #cbd5e1; --gris-soft: rgba(148, 163, 184, .12); --gris-border: rgba(148, 163, 184, .28);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 10px 30px rgba(0, 0, 0, .45);
    --ring: 0 0 0 3px rgba(45, 212, 191, .3);
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--fs-base)/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-md); }
h3 { font-size: var(--fs-base); }
p { margin: 0; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
code, .mono { font-family: var(--mono); font-size: var(--fs-sm); }
.mono { overflow-wrap: anywhere; }
b, strong { font-weight: 600; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--brand-border); }
[hidden] { display: none !important; }

.icon { width: 18px; height: 18px; flex: none; }
.icon--sm { width: 14px; height: 14px; }
.icon--lg { width: 22px; height: 22px; }

.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;
}
.skip-link {
  position: absolute; left: var(--s-3); top: -60px; z-index: 100;
  background: var(--brand); color: var(--on-brand); padding: var(--s-2) var(--s-4); border-radius: var(--r-sm);
}
.skip-link:focus { top: var(--s-3); }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; }
.main { padding: var(--s-8) var(--s-10) var(--s-12); width: 100%; max-width: 1280px; min-width: 0; }

/* Barra lateral */
.side {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
}
.side__top { display: flex; align-items: center; justify-content: space-between; padding: var(--s-5) var(--s-4) var(--s-4); }
.brand { display: flex; align-items: center; gap: var(--s-3); color: var(--text); }
.brand:hover { text-decoration: none; }
.brand__mark {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px;
  background: var(--brand); color: var(--on-brand);
}
.brand__mark .icon { width: 18px; height: 18px; }
.brand__name { display: block; font-weight: 600; font-size: var(--fs-base); line-height: 1.2; }
.brand__sub { display: block; font-size: var(--fs-xs); color: var(--text-3); }
.side__toggle { display: none; }
.side__panel { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow-y: auto; padding: 0 var(--s-3) var(--s-3); }
.nav-group + .nav-group { margin-top: var(--s-5); }
.nav-group__label {
  padding: 0 var(--s-3) var(--s-2); font-size: var(--fs-xs); font-weight: 600;
  color: var(--text-3); text-transform: uppercase; letter-spacing: .06em;
}
.nav-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav-link {
  position: relative; display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-2) var(--s-3); border-radius: var(--r-sm);
  color: var(--text-2); font-weight: 500;
}
.nav-link .icon { color: var(--text-3); }
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link[aria-current="page"] { background: var(--brand-soft); color: var(--brand); }
.nav-link[aria-current="page"] .icon { color: var(--brand); }
.nav-link[aria-current="page"]::before {
  content: ""; position: absolute; left: calc(-1 * var(--s-3)); top: 8px; bottom: 8px;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--brand);
}
.side__foot { margin-top: auto; padding-top: var(--s-4); border-top: 1px solid var(--border); }
.user { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) var(--s-3) var(--s-3); min-width: 0; }
.avatar {
  display: grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: var(--r-full);
  background: var(--surface-3); color: var(--text); font-weight: 600; font-size: var(--fs-sm); text-transform: uppercase;
}
.user__name { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user__mail { display: block; font-size: var(--fs-xs); color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user__text { min-width: 0; }
.nav-button {
  width: 100%; background: none; border: 0; font: inherit; cursor: pointer; text-align: left;
}

/* ---------- Cabecera de página ---------- */
.page-head {
  display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between;
  gap: var(--s-4); margin-bottom: var(--s-6);
}
.page-head__text { min-width: 0; flex: 1 1 320px; }
.page-head__title { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); }
.page-head__title h1 { overflow-wrap: anywhere; }
.page-head__desc { margin-top: var(--s-1); color: var(--text-2); }
.page-head__meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3); margin-top: var(--s-2); color: var(--text-2); font-size: var(--fs-sm); }
.page-head__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.page-head__actions:empty { display: none; }
.dot-sep { width: 3px; height: 3px; border-radius: 50%; background: var(--text-3); }

.crumbs { margin-bottom: var(--s-3); }
.crumbs ol { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-1); margin: 0; padding: 0; list-style: none; font-size: var(--fs-sm); color: var(--text-3); }
.crumbs li { display: inline-flex; align-items: center; gap: var(--s-1); }
.crumbs li + li::before {
  content: ""; width: 6px; height: 6px; margin: 0 var(--s-1);
  border-right: 1.5px solid currentColor; border-top: 1.5px solid currentColor; transform: rotate(45deg);
}
.crumbs a { color: var(--text-2); }
.crumbs [aria-current] { color: var(--text); font-weight: 500; }

/* ---------- Tarjetas y rejillas ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  box-shadow: var(--shadow-sm); min-width: 0;
}
.card + .card, .grid + .card, .card + .grid, .grid + .grid { margin-top: var(--s-5); }
.card__head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-2) var(--s-4);
  padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--border);
}
.card__head h2 { display: flex; align-items: center; gap: var(--s-2); }
.card__head h2 .icon { color: var(--text-3); }
.card__desc { margin-top: 2px; font-size: var(--fs-sm); color: var(--text-2); }
.card__body { padding: var(--s-5); }
.card__foot {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-3);
  padding: var(--s-3) var(--s-5); border-top: 1px solid var(--border); font-size: var(--fs-sm);
}
.card__section { border-top: 1px solid var(--border); }
.card__subtitle { font-size: var(--fs-sm); font-weight: 600; margin-bottom: var(--s-3); }

.grid { display: grid; gap: var(--s-5); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
.grid--metrics { grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: var(--s-4); }
.grid--aside { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }

/* ---------- Métricas ---------- */
.metric { padding: var(--s-5); }
.metric__label { display: flex; align-items: center; gap: var(--s-2); color: var(--text-2); font-size: var(--fs-sm); font-weight: 500; }
.metric__value { margin-top: var(--s-2); font-size: var(--fs-2xl); font-weight: 600; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.metric__ctx { margin-top: var(--s-2); font-size: var(--fs-xs); color: var(--text-3); }
.metric__ctx.tono-ok { color: var(--ok); }
.metric__ctx.tono-mal { color: var(--mal); }
.metric__ctx.tono-proc { color: var(--proc); }
.metric--link { display: block; color: inherit; transition: border-color .15s, box-shadow .15s; }
.metric--link:hover { text-decoration: none; border-color: var(--border-strong); box-shadow: var(--shadow-md); }

/* Gráfico de barras por estado (CSS puro) */
.bars { display: grid; gap: var(--s-3); margin: 0; padding: 0; list-style: none; }
.bars__row { display: grid; grid-template-columns: 130px minmax(0, 1fr) 88px; align-items: center; gap: var(--s-3); }
.bars__label:hover { text-decoration: none; }
.bars__label:hover .badge { filter: brightness(.96); }
.bars__track { height: 10px; border-radius: var(--r-full); background: var(--surface-2); overflow: hidden; }
.bars__fill { display: block; height: 100%; border-radius: var(--r-full); }
.bars__pct { display: inline-block; min-width: 40px; margin-left: var(--s-2); color: var(--text-3); font-weight: 400; font-size: var(--fs-xs); }
.bars__fill.tono-ok { background: var(--ok); }
.bars__fill.tono-proc { background: var(--proc); }
.bars__fill.tono-gris { background: var(--text-3); }
.bars__fill.tono-mal { background: var(--mal); }
.bars__val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.bars__total { display: flex; justify-content: space-between; margin-top: var(--s-4); padding-top: var(--s-3); border-top: 1px solid var(--border); font-size: var(--fs-sm); color: var(--text-2); }

/* Barra de progreso (uso de consecutivos) */
.meter { display: grid; gap: var(--s-1); min-width: 140px; }
.meter__track { height: 6px; border-radius: var(--r-full); background: var(--surface-3); overflow: hidden; }
.meter__fill { display: block; height: 100%; background: var(--brand); border-radius: var(--r-full); }
.meter__fill.tono-proc { background: var(--proc); }
.meter__fill.tono-mal { background: var(--mal); }
.meter__label { font-size: var(--fs-xs); color: var(--text-2); font-variant-numeric: tabular-nums; }

/* ---------- Insignias ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  padding: 2px 8px 2px 6px; border-radius: var(--r-full); border: 1px solid;
  font-size: var(--fs-xs); font-weight: 500; line-height: 18px;
}
.badge .icon { width: 13px; height: 13px; }
.badge--ok   { color: var(--ok);   background: var(--ok-soft);   border-color: var(--ok-border); }
.badge--proc { color: var(--proc); background: var(--proc-soft); border-color: var(--proc-border); }
.badge--mal  { color: var(--mal);  background: var(--mal-soft);  border-color: var(--mal-border); }
.badge--gris { color: var(--gris); background: var(--gris-soft); border-color: var(--gris-border); }
.badge--brand { color: var(--brand); background: var(--brand-soft); border-color: var(--brand-border); }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: 36px; padding: 0 var(--s-4); border-radius: var(--r-sm); border: 1px solid transparent;
  font: 500 var(--fs-base)/1 var(--font); white-space: nowrap; cursor: pointer; text-decoration: none;
  transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:hover { text-decoration: none; }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn .icon { width: 16px; height: 16px; }
.btn--primary { background: var(--brand); color: var(--on-brand); box-shadow: var(--shadow-sm); }
.btn--primary:hover { background: var(--brand-hover); }
.btn--secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.btn--secondary:hover { background: var(--surface-2); }
.btn--ghost { background: transparent; color: var(--text-2); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }
.btn--danger { background: var(--mal); color: #fff; }
.btn--danger:hover { filter: brightness(.92); }
.btn--danger-soft { background: var(--surface); color: var(--mal); border-color: var(--mal-border); }
.btn--danger-soft:hover { background: var(--mal-soft); }
.btn--sm { height: 30px; padding: 0 var(--s-3); font-size: var(--fs-sm); }
.btn--sm .icon { width: 14px; height: 14px; }
.btn--block { width: 100%; }
.btn--icon { width: 36px; padding: 0; }
.btn--sm.btn--icon { width: 30px; }
.btn.is-disabled, .btn:disabled { opacity: .5; cursor: not-allowed; pointer-events: none; box-shadow: none; }
@media (prefers-color-scheme: dark) { .btn--danger { color: #1f0a0a; } }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.actions--end { justify-content: flex-end; }
form.inline { display: inline-flex; margin: 0; }

/* ---------- Avisos ---------- */
.avisos { display: grid; gap: var(--s-3); margin-bottom: var(--s-5); }
.avisos:empty { display: none; }
.aviso {
  display: flex; align-items: flex-start; gap: var(--s-3);
  padding: var(--s-3) var(--s-3) var(--s-3) var(--s-4); border-radius: var(--r-md); border: 1px solid;
  box-shadow: var(--shadow-sm); animation: aviso-in .2s ease-out;
}
.aviso > .icon { margin-top: 2px; }
.aviso__text { flex: 1; min-width: 0; color: var(--text); }
.aviso__title { font-weight: 600; }
.aviso ul { margin: var(--s-2) 0 0; padding-left: var(--s-5); }
.aviso li + li { margin-top: var(--s-1); }
.aviso--ok   { background: var(--ok-soft);   border-color: var(--ok-border); }
.aviso--ok > .icon { color: var(--ok); }
.aviso--mal  { background: var(--mal-soft);  border-color: var(--mal-border); }
.aviso--mal > .icon { color: var(--mal); }
.aviso--proc { background: var(--proc-soft); border-color: var(--proc-border); }
.aviso--proc > .icon { color: var(--proc); }
.aviso--gris { background: var(--surface-2); border-color: var(--border); }
.aviso--gris > .icon { color: var(--text-2); }
.aviso__close {
  display: grid; place-items: center; width: 28px; height: 28px; margin: -2px 0;
  border: 0; border-radius: var(--r-sm); background: transparent; color: var(--text-2); cursor: pointer;
}
.aviso__close:hover { background: rgba(127, 127, 127, .14); color: var(--text); }
html:not(.js) .aviso__close { display: none; }
@keyframes aviso-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .aviso { animation: none; } * { transition: none !important; } }

/* ---------- Tablas ---------- */
.table-wrap { overflow: auto; max-height: min(72vh, 760px); }
.table-wrap--free { max-height: none; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-base); }
.table th, .table td { padding: var(--s-3) var(--s-4); text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
.table thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2); color: var(--text-2);
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: .03em; text-transform: uppercase; white-space: nowrap;
}
.table th:first-child, .table td:first-child { padding-left: var(--s-5); }
.table th:last-child, .table td:last-child { padding-right: var(--s-5); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background-color .1s; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .nowrap { white-space: nowrap; }
.table .cell-actions { text-align: right; white-space: nowrap; }
.table .cell-actions .actions { justify-content: flex-end; }
.table--compact th, .table--compact td { padding-top: var(--s-2); padding-bottom: var(--s-2); }
.cell-main { display: block; font-weight: 500; color: var(--text); }
a.cell-main { color: var(--brand); }
.cell-sub { display: block; font-size: var(--fs-xs); color: var(--text-3); }
.cell-msg { max-width: 520px; overflow-wrap: anywhere; }
.text-2 { color: var(--text-2); }
.only-narrow { display: none; }
.text-3 { color: var(--text-3); }
.files { display: inline-flex; gap: var(--s-1); }
.chip-link {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--r-sm);
  border: 1px solid var(--border); color: var(--text-2); font-size: var(--fs-xs); font-weight: 500; background: var(--surface);
}
.chip-link:hover { color: var(--brand); border-color: var(--brand-border); background: var(--brand-soft); text-decoration: none; }
.chip-link .icon { width: 13px; height: 13px; }

/* Estado vacío */
.empty { display: grid; justify-items: center; gap: var(--s-2); padding: var(--s-10) var(--s-6); text-align: center; }
.empty__art { width: 96px; height: 72px; margin-bottom: var(--s-2); color: var(--text-3); }
.empty__art .art-fill { fill: var(--surface-2); }
.empty__art .art-surface { fill: var(--surface); }
.empty__art .art-accent { stroke: var(--brand); }
.empty__title { font-weight: 600; font-size: var(--fs-md); }
.empty__text { max-width: 420px; color: var(--text-2); }
.empty .btn { margin-top: var(--s-3); }
.empty--sm { padding: var(--s-6); }
.empty--sm .empty__art { width: 64px; height: 48px; }

/* Paginación */
.pager {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-3);
  padding: var(--s-3) var(--s-5); border-top: 1px solid var(--border); font-size: var(--fs-sm); color: var(--text-2);
}
.pager__nav { display: flex; align-items: center; gap: var(--s-2); }
.pager__page { padding: 0 var(--s-2); font-variant-numeric: tabular-nums; }
.pager b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- Filtros ---------- */
.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s-3);
  padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--border);
}
.filters .field { margin: 0; flex: 0 1 220px; min-width: 160px; }
.filters .field--grow { flex: 1 1 280px; }
.filters__actions { display: flex; gap: var(--s-2); }

/* ---------- Formularios ---------- */
.form-section { display: grid; grid-template-columns: minmax(0, 260px) minmax(0, 1fr); gap: var(--s-6); padding: var(--s-6) var(--s-5); }
.form-section + .form-section { border-top: 1px solid var(--border); }
.form-section__title { font-size: var(--fs-md); font-weight: 600; }
.form-section__desc { margin-top: var(--s-1); font-size: var(--fs-sm); color: var(--text-2); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: var(--s-4) var(--s-4); align-content: start; }
.form-grid .span-2 { grid-column: span 2; }
.form-stack { display: grid; gap: var(--s-4); }
.form-foot {
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--s-2);
  padding: var(--s-4) var(--s-5); border-top: 1px solid var(--border); background: var(--surface-2);
  border-radius: 0 0 var(--r-md) var(--r-md);
}
.field { display: grid; gap: 6px; align-content: start; min-width: 0; }
.field__label { font-size: var(--fs-sm); font-weight: 500; color: var(--text); }
.field__opt { font-weight: 400; color: var(--text-3); }
.field__help { font-size: var(--fs-xs); color: var(--text-3); }
.field__error { display: flex; align-items: center; gap: 4px; font-size: var(--fs-xs); color: var(--mal); font-weight: 500; }
.field__error:empty { display: none; }
.input, .select, .textarea, .field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), .field select, .field textarea {
  width: 100%; height: 36px; padding: 0 var(--s-3);
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text); font: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { height: auto; min-height: 96px; padding: var(--s-2) var(--s-3); }
.field select {
  appearance: none; padding-right: var(--s-8);
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 16px) 15px, calc(100% - 11px) 15px;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.field input::placeholder { color: var(--text-3); }
.field input:hover, .field select:hover, .field textarea:hover { border-color: var(--text-3); }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.field input[readonly] { background: var(--surface-2); color: var(--text-2); cursor: not-allowed; }
.field.has-error input, .field.has-error select { border-color: var(--mal); }
.field.has-error input:focus { box-shadow: 0 0 0 3px var(--mal-soft); }
.field input[type="file"] {
  width: 100%; padding: var(--s-2); border: 1px dashed var(--border-strong); border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--text-2); font: inherit; font-size: var(--fs-sm);
}
.field input[type="file"]::file-selector-button {
  margin-right: var(--s-3); height: 28px; padding: 0 var(--s-3); border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text); font: 500 var(--fs-sm) var(--font); cursor: pointer;
}
.input-icon { position: relative; }
.input-icon > .icon { position: absolute; left: 10px; top: 9px; color: var(--text-3); pointer-events: none; }
.field .input-icon input { padding-left: 34px; }
.input-group { display: flex; }
.field .input-group input { border-top-right-radius: 0; border-bottom-right-radius: 0; min-width: 0; }
.input-group__btn {
  display: grid; place-items: center; flex: none; width: 38px; height: 36px; margin-left: -1px;
  border: 1px solid var(--border-strong); border-radius: 0 var(--r-sm) var(--r-sm) 0;
  background: var(--surface-2); color: var(--text-2); cursor: pointer;
}
.input-group__btn:hover { color: var(--text); background: var(--surface-3); }
.input-group__btn:focus-visible { outline: none; box-shadow: var(--ring); position: relative; }
.input-group__btn .ico-show, .input-group__btn[aria-pressed="true"] .ico-hide { display: grid; }
.input-group__btn .ico-hide, .input-group__btn[aria-pressed="true"] .ico-show { display: none; }
html:not(.js) .input-group__btn { display: none; }
html:not(.js) .field .input-group input { border-radius: var(--r-sm); }
.inline-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s-3); }
.inline-form .field { flex: 1 1 200px; }

/* ---------- Listas de definición ---------- */
.kv { display: grid; grid-template-columns: minmax(120px, 38%) minmax(0, 1fr); margin: 0; }
.kv > dt, .kv > dd { padding: var(--s-3) 0; border-bottom: 1px solid var(--border); }
.kv > dt { color: var(--text-2); padding-right: var(--s-4); }
.kv > dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.kv > dt:last-of-type, .kv > dd:last-of-type { border-bottom: 0; }
.kv--tight > dt, .kv--tight > dd { padding: var(--s-2) 0; }
.kv .num { font-variant-numeric: tabular-nums; }
.kv__total { font-size: var(--fs-md); font-weight: 600; }

/* Bloque técnico copiable */
.code-block { position: relative; }
.code-block pre, pre.code {
  margin: 0; padding: var(--s-4); max-height: 420px; overflow: auto;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm);
  font: var(--fs-xs)/1.6 var(--mono); color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere;
}
.copy-row { display: flex; align-items: center; gap: var(--s-2); min-width: 0; }
.copy-row .mono { min-width: 0; }

/* Clave recién creada */
.secret {
  border: 1px solid var(--brand-border); background: var(--brand-soft); border-radius: var(--r-md);
  padding: var(--s-5); margin-bottom: var(--s-5);
}
.secret__head { display: flex; align-items: center; gap: var(--s-2); font-weight: 600; }
.secret__head .icon { color: var(--brand); }
.secret__warn { margin-top: var(--s-1); color: var(--text-2); font-size: var(--fs-sm); }
.secret__value {
  display: flex; align-items: center; gap: var(--s-3); margin-top: var(--s-4);
  padding: var(--s-2) var(--s-2) var(--s-2) var(--s-4); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
}
.secret__value code { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: var(--fs-sm); }

/* ---------- Pestañas por anclas ---------- */
.tabs {
  position: sticky; top: 0; z-index: 5; display: flex; gap: var(--s-1); overflow-x: auto;
  margin: 0 0 var(--s-6); padding: 0; list-style: none;
  background: var(--bg); border-bottom: 1px solid var(--border); scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  display: inline-flex; align-items: center; gap: var(--s-2); padding: var(--s-3) var(--s-3);
  color: var(--text-2); font-weight: 500; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); text-decoration: none; border-bottom-color: var(--border-strong); }
.tabs a[aria-current="true"] { color: var(--brand); border-bottom-color: var(--brand); }
.tabs .count { font-size: var(--fs-xs); color: var(--text-3); background: var(--surface-2); padding: 0 6px; border-radius: var(--r-full); font-variant-numeric: tabular-nums; }
.section-anchor { scroll-margin-top: 64px; }

/* ---------- Línea de tiempo ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline__item { position: relative; display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: var(--s-3); padding-bottom: var(--s-5); }
.timeline__item:last-child { padding-bottom: 0; }
.timeline__item::before {
  content: ""; position: absolute; left: 13px; top: 28px; bottom: 0; width: 2px; background: var(--border);
}
.timeline__item:last-child::before { display: none; }
.timeline__dot {
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: var(--r-full);
  border: 1px solid; background: var(--surface);
}
.timeline__dot .icon { width: 14px; height: 14px; }
.timeline__dot.tono-ok { color: var(--ok); background: var(--ok-soft); border-color: var(--ok-border); }
.timeline__dot.tono-proc { color: var(--proc); background: var(--proc-soft); border-color: var(--proc-border); }
.timeline__dot.tono-mal { color: var(--mal); background: var(--mal-soft); border-color: var(--mal-border); }
.timeline__dot.tono-gris { color: var(--gris); background: var(--gris-soft); border-color: var(--gris-border); }
.timeline__head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s-1) var(--s-3); padding-top: 4px; }
.timeline__title { font-weight: 600; font-size: var(--fs-sm); }
.timeline__time { font-size: var(--fs-xs); color: var(--text-3); font-variant-numeric: tabular-nums; }
.timeline__msg { margin-top: 2px; color: var(--text-2); font-size: var(--fs-sm); overflow-wrap: anywhere; }

/* ---------- Lista de atención ---------- */
.attn { list-style: none; margin: 0; padding: 0; }
.attn__item { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-5); border-bottom: 1px solid var(--border); }
.attn__item:last-child { border-bottom: 0; }
.attn__icon { display: grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: var(--r-sm); }
.attn__icon.tono-mal { color: var(--mal); background: var(--mal-soft); }
.attn__icon.tono-proc { color: var(--proc); background: var(--proc-soft); }
.attn__icon.tono-ok { color: var(--ok); background: var(--ok-soft); }
.attn__text { flex: 1; min-width: 0; }
.attn__title { display: block; font-weight: 500; overflow-wrap: anywhere; }
.attn__sub { display: block; font-size: var(--fs-xs); color: var(--text-2); overflow-wrap: anywhere; }

/* Indicador de estado (punto) */
.status { display: inline-flex; align-items: center; gap: var(--s-2); font-weight: 500; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 3px var(--surface-2); }
.status--ok { color: var(--ok); }
.status--mal { color: var(--mal); }
.status--proc { color: var(--proc); }

/* Tarjeta de certificado */
.cert { display: flex; align-items: center; gap: var(--s-4); padding: var(--s-4); border-radius: var(--r-md); border: 1px solid; }
.cert__icon { display: grid; place-items: center; flex: none; width: 44px; height: 44px; border-radius: var(--r-md); background: var(--surface); }
.cert__icon .icon { width: 22px; height: 22px; }
.cert__title { font-weight: 600; }
.cert__sub { font-size: var(--fs-sm); color: var(--text-2); }
.cert--ok { background: var(--ok-soft); border-color: var(--ok-border); }
.cert--ok .cert__icon { color: var(--ok); }
.cert--proc { background: var(--proc-soft); border-color: var(--proc-border); }
.cert--proc .cert__icon { color: var(--proc); }
.cert--mal { background: var(--mal-soft); border-color: var(--mal-border); }
.cert--mal .cert__icon { color: var(--mal); }
.cert--gris { background: var(--surface-2); border-color: var(--border); }
.cert--gris .cert__icon { color: var(--text-2); }

/* ---------- Login ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: var(--s-6) var(--s-4); }
.auth__box { width: 100%; max-width: 400px; }
.auth__brand { display: flex; flex-direction: column; align-items: center; gap: var(--s-3); margin-bottom: var(--s-6); text-align: center; }
.auth__brand .brand__mark { width: 44px; height: 44px; border-radius: 12px; }
.auth__brand .brand__mark .icon { width: 24px; height: 24px; }
.auth__product { font-size: var(--fs-lg); font-weight: 600; letter-spacing: -.01em; }
.auth__tag { color: var(--text-2); font-size: var(--fs-sm); }
.auth__card { padding: var(--s-8); box-shadow: var(--shadow-md); }
.auth__card h1 { font-size: var(--fs-lg); }
.auth__lead { margin-top: var(--s-1); margin-bottom: var(--s-6); color: var(--text-2); }
.auth__foot { margin-top: var(--s-6); text-align: center; font-size: var(--fs-xs); color: var(--text-3); }

/* ---------- Utilidades ---------- */
.stack > * + * { margin-top: var(--s-5); }
.mt-4 { margin-top: var(--s-4); }
.mt-6 { margin-top: var(--s-6); }
.w-narrow { max-width: 560px; }
.right { text-align: right; }
.muted { color: var(--text-2); }
.small { font-size: var(--fs-sm); }
.link-more { display: inline-flex; align-items: center; gap: 4px; font-weight: 500; font-size: var(--fs-sm); }
.link-more .icon { width: 14px; height: 14px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .col-ter { display: none; }
  .only-narrow { display: block; }
  .main { padding: var(--s-6) var(--s-6) var(--s-10); }
  .grid--aside { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .shell { display: block; }
  .side { position: sticky; top: 0; z-index: 50; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .side__top { padding: var(--s-3) var(--s-4); }
  .side__toggle { display: inline-flex; }
  .js .side__panel { display: none; }
  .js .side.is-open .side__panel {
    display: flex; position: absolute; left: 0; right: 0; top: 100%;
    max-height: calc(100vh - 57px); background: var(--surface); border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-md); padding-top: var(--s-3);
  }
  .form-section { grid-template-columns: minmax(0, 1fr); gap: var(--s-4); }
}
@media (max-width: 720px) {
  .col-sec { display: none; }
  .main { padding: var(--s-5) var(--s-4) var(--s-10); }
  .page-head { margin-bottom: var(--s-5); }
  .page-head__actions { width: 100%; }
  h1 { font-size: var(--fs-lg); }
  .card__head, .card__body { padding-left: var(--s-4); padding-right: var(--s-4); }
  .table th:first-child, .table td:first-child { padding-left: var(--s-4); }
  .table th:last-child, .table td:last-child { padding-right: var(--s-4); }
  .table th, .table td { padding-left: var(--s-3); padding-right: var(--s-3); }
  .filters { padding: var(--s-4); }
  .filters .field { flex: 1 1 100%; }
  .bars__row { grid-template-columns: 112px minmax(0, 1fr) auto; }
  .bars__pct { display: none; }
  .kv { grid-template-columns: minmax(0, 1fr); }
  .kv > dt { border-bottom: 0; padding-bottom: 0; font-size: var(--fs-xs); }
  .kv > dd { padding-top: 2px; }
  .form-grid .span-2 { grid-column: auto; }
  .auth__card { padding: var(--s-6); }
  .metric { padding: var(--s-4); }
  .metric__value { font-size: var(--fs-xl); }
}

@media print {
  .side, .page-head__actions, .tabs, .aviso__close { display: none !important; }
  .shell { display: block; }
  .card { box-shadow: none; }
}

/* ---------- Desplegables sin JS (details/summary) ---------- */
.disclosure > summary { list-style: none; }
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure[open] > summary { background: var(--surface-2); color: var(--text); }
.disclosure__panel {
  display: grid; gap: var(--s-2); margin-top: var(--s-2); padding: var(--s-3); min-width: 260px;
  text-align: left; white-space: normal; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-sm); box-shadow: var(--shadow-sm);
}
.disclosure__panel .btn { justify-self: start; }

/* ---------- Detalle de factura ---------- */
.aviso--block { margin-bottom: var(--s-5); padding: var(--s-4) var(--s-5); }
.aviso__title { font-size: var(--fs-base); font-weight: 600; }
.aviso__hint { margin-top: var(--s-3); font-size: var(--fs-sm); color: var(--text-2); }
.error-list { margin: var(--s-2) 0 0; padding-left: var(--s-5); }
.error-list li { line-height: 1.5; overflow-wrap: anywhere; }
.error-list li + li { margin-top: var(--s-2); }
.grow { flex: 1; min-width: 0; }
html:not(.js) [data-copiar] { display: none; }

/* ---------- Detalle de empresa ---------- */
.add-panel__summary {
  display: flex; align-items: center; gap: var(--s-2); padding: var(--s-4) var(--s-5);
  color: var(--brand); font-weight: 500; cursor: pointer; list-style: none;
}
.add-panel__summary::-webkit-details-marker { display: none; }
.add-panel__summary:hover { background: var(--surface-2); }
.add-panel__summary .icon { width: 16px; height: 16px; transition: transform .15s; }
.add-panel[open] > .add-panel__summary { color: var(--text); }
.add-panel[open] > .add-panel__summary .icon { transform: rotate(45deg); }
.add-panel:last-child > .add-panel__summary { border-radius: 0 0 var(--r-md) var(--r-md); }
.add-panel__body { padding: 0 var(--s-5) var(--s-5); }
.danger-zone { border-color: var(--mal-border); }
.danger-zone__row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-4); }
.card__body.grid { gap: var(--s-6); }
@media (max-width: 720px) { .add-panel__summary, .add-panel__body { padding-left: var(--s-4); padding-right: var(--s-4); } }
.field__error .icon { width: 14px; height: 14px; }
.card > .avisos { margin: var(--s-5) var(--s-5) 0; }
.card > .avisos:empty { display: none; }
@media (max-width: 900px) {
  .tabs { top: 57px; }
  .section-anchor { scroll-margin-top: 120px; }
}

/* ---------- Pie ---------- */
.app-foot {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3);
  margin-top: var(--s-10); padding-top: var(--s-5); border-top: 1px solid var(--border);
  font-size: var(--fs-xs); color: var(--text-3);
}
.auth .app-foot { justify-content: center; margin-top: var(--s-4); padding-top: 0; border-top: 0; }

/* ---------- Verificación en dos pasos ---------- */
.field input.input--codigo, input.input--codigo {
  height: 48px; font: 600 var(--fs-lg)/1 var(--mono); letter-spacing: .3em; text-align: center;
}
.pasos { margin: 0; padding-left: var(--s-5); display: grid; gap: var(--s-6); }
.pasos > li::marker { font-weight: 600; color: var(--brand); }
.pasos__titulo { font-weight: 600; margin-bottom: var(--s-3); }
.qr {
  display: block; width: 220px; height: 220px; margin-bottom: var(--s-3);
  padding: var(--s-2); background: #fff; border: 1px solid var(--border); border-radius: var(--r-md);
}
.aviso .btn { margin-left: auto; align-self: center; }

/* ---------- Niveles de servicio ---------- */
.ans { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
.ans__item { padding: var(--s-5); border-right: 1px solid var(--border); }
.ans__item:last-child { border-right: 0; }
.ans__valor { margin-top: var(--s-2); font-size: var(--fs-xl); font-weight: 600; font-variant-numeric: tabular-nums; }
.ans__valor.tono-mal { color: var(--mal); }
.ans__valor.tono-proc { color: var(--proc); }
@media (max-width: 720px) { .ans__item { border-right: 0; border-bottom: 1px solid var(--border); padding: var(--s-4); } }

/* ---------- Política y términos ---------- */
.auth--ancho .auth__box { max-width: 760px; }
.legal-caja {
  max-height: 52vh; overflow: auto; padding: var(--s-5); margin-top: var(--s-4);
  border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2);
}
.legal h2 { font-size: var(--fs-base); margin: var(--s-5) 0 var(--s-2); }
.legal h2:first-of-type { margin-top: var(--s-3); }
.legal p, .legal li { color: var(--text-2); line-height: 1.65; }
.legal ul { margin: 0; padding-left: var(--s-5); }
.legal__borrador { padding: var(--s-3) var(--s-4); border-radius: var(--r-sm); background: var(--proc-soft); border: 1px solid var(--proc-border); color: var(--text); }
.check { display: flex; align-items: flex-start; gap: var(--s-3); cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--brand); flex: none; }

/* ---------- PQRSF ---------- */
.pre-linea { white-space: pre-line; overflow-wrap: anywhere; }
.opciones { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s-2); }
.opciones legend { margin-bottom: var(--s-2); padding: 0; }
.opcion {
  display: inline-flex; align-items: center; gap: var(--s-2); padding: var(--s-2) var(--s-3);
  border: 1px solid var(--border-strong); border-radius: var(--r-sm); cursor: pointer; background: var(--surface);
}
.opcion:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); font-weight: 500; }
.opcion input { accent-color: var(--brand); margin: 0; }
.opcion:focus-within { box-shadow: var(--ring); }
