/* Pos IA · estilos base y componentes compartidos. Marca del cliente en --brand. */
:root {
  --bg: #efede8;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --ink: #0f1720;
  --muted: #4a5563;
  --faint: #7b8492;
  --line: #e2dfd8;
  --brand: #4b4be0;
  --brand-ink: #ffffff;
  --brand-fg: var(--brand);
  --brand-soft: color-mix(in oklab, var(--brand) 12%, var(--surface));
  --good: #157a3c; --good-soft: #e3f3e8;
  --warn: #a35a00; --warn-soft: #fbefdc;
  --crit: #c02a2a; --crit-soft: #fbe5e3;
  --series-1: #2a78d6;
  --shadow: 0 1px 2px rgb(15 23 32 / .06), 0 8px 24px rgb(15 23 32 / .06);
  --font-ui: "Jost", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --r: 14px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0a0f15; --surface: #121a23; --surface-2: #17212c; --ink: #edf0f3; --muted: #a3adb8; --faint: #6f7a88; --line: #253140;
  --brand-fg: color-mix(in oklab, var(--brand) 62%, white);
  --brand-soft: color-mix(in oklab, var(--brand) 22%, var(--surface));
  --good: #4cc27a; --good-soft: #13301f; --warn: #e9a23b; --warn-soft: #33260f; --crit: #f07a72; --crit-soft: #3a1817;
  --series-1: #3987e5;
  --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .25);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0f15; --surface: #121a23; --surface-2: #17212c; --ink: #edf0f3; --muted: #a3adb8; --faint: #6f7a88; --line: #253140;
    --brand-fg: color-mix(in oklab, var(--brand) 62%, white);
    --brand-soft: color-mix(in oklab, var(--brand) 22%, var(--surface));
    --good: #4cc27a; --good-soft: #13301f; --warn: #e9a23b; --warn-soft: #33260f; --crit: #f07a72; --crit-soft: #3a1817;
    --series-1: #3987e5;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--font-ui); font-size: 15px; line-height: 1.4; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--brand-fg); outline-offset: 2px; }
[hidden] { display: none !important; }
/* Tamaño por defecto de los íconos de trazo; cada componente puede ajustarlo. */
svg[viewBox="0 0 24 24"] { width: 20px; height: 20px; flex: none; vertical-align: middle; }
h1, h2, h3, h4 { margin: 0; font-weight: 500; text-wrap: balance; }
p { margin: 0; }
a { color: var(--brand-fg); }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); }
.eyebrow { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); font-weight: 500; }
.note { font-size: 13px; color: var(--faint); }
.muted { color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: 12px; }

/* Shell */
.shell { height: 100%; display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 12px;
  padding-block: max(12px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-bottom, 0px));
  padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: max(12px, env(safe-area-inset-right, 0px)); }
.rail { background: var(--surface); border-radius: var(--r); display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 6px; box-shadow: var(--shadow); overflow-y: auto; scrollbar-width: none; }
.rail .logo { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; margin-bottom: 8px; overflow: hidden; color: var(--brand-fg); flex: none; }
.rail .logo img { width: 100%; height: 100%; object-fit: contain; }
.nav-btn { width: 64px; flex: none; border: 0; background: transparent; border-radius: 12px; padding: 8px 2px; display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--muted); font-size: 11px; position: relative; text-decoration: none; text-align: center; line-height: 1.15; }
.nav-btn svg { width: 22px; height: 22px; }
.nav-btn[aria-current="page"] { background: var(--brand-soft); color: var(--brand-fg); }
.nav-btn .dot { position: absolute; top: 3px; right: 8px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--crit); color: #fff; font-size: 11px; display: grid; place-items: center; padding: 0 5px; }
.main { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 12px; }
.topbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.topbar .who { display: flex; flex-direction: column; min-width: 0; margin-right: auto; }
.topbar .who strong { font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .who span { font-size: 12px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.view { min-height: 0; overflow: auto; }
.pill { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 13px; }
.pill select { border: 0; background: transparent; padding: 0; font-weight: 500; max-width: 220px; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; color: var(--muted); flex: none; }
.icon-btn svg { width: 20px; height: 20px; }

/* Componentes */
.panel { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); }
.sec { padding: 16px; display: grid; gap: 12px; min-width: 0; align-content: start; }
.sec > h3 { font-size: 16px; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 14px; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap; text-decoration: none; color: var(--ink); }
.btn:hover { border-color: var(--faint); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.07); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.danger { color: var(--crit); }
.btn.big { padding: 14px 18px; font-size: 17px; border-radius: 12px; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn svg { width: 18px; height: 18px; flex: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.chip.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.crit { background: var(--crit-soft); color: var(--crit); border-color: transparent; }
.chip.brand { background: var(--brand-soft); color: var(--brand-fg); border-color: transparent; }
.chip .led { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
button.chip { cursor: pointer; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; border-radius: 8px; padding: 6px 10px; font-size: 13px; color: var(--muted); font-weight: 500; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }
input[type="text"], input[type="email"], input[type="password"], input[type="tel"], input[type="number"], input[type="search"], input[type="date"], input[type="url"], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 12px; min-height: 40px; }
textarea { min-height: 80px; resize: vertical; }
label.f { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
label.f > span { display: flex; gap: 6px; align-items: center; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.switch { appearance: none; width: 42px; height: 24px; border-radius: 12px; background: var(--line); position: relative; flex: none; cursor: pointer; transition: background .15s; margin: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgb(0 0 0 / .3); }
.switch:checked { background: var(--brand); }
.switch:checked::after { left: 21px; }
.page { display: grid; gap: 14px; padding-bottom: 24px; align-content: start; }
.page-h { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.page-h h2 { font-size: 24px; margin-right: auto; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { padding: 14px 16px; display: grid; gap: 2px; }
.kpi .v { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12px; color: var(--faint); }
.tbl-wrap { overflow-x: auto; }
table.tbl { border-collapse: collapse; width: 100%; font-size: 14px; }
.tbl th { text-align: left; font-weight: 500; color: var(--faint); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl td.r, .tbl th.r { text-align: right; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--surface-2); }
.empty { padding: 36px 20px; text-align: center; color: var(--faint); display: grid; gap: 6px; place-items: center; }
.empty svg { width: 40px; height: 40px; opacity: .6; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a, .tabs button { border: 0; background: none; padding: 10px 14px; color: var(--muted); font-weight: 500; text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs [aria-current="page"], .tabs [aria-selected="true"] { color: var(--ink); border-bottom-color: var(--brand); }

/* Modal y toast */
.scrim { position: fixed; inset: 0; background: rgb(8 12 18 / .5); display: grid; place-items: center; z-index: 50;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); }
.modal { background: var(--surface); border-radius: 18px; width: min(560px, 100%); max-height: 100%; overflow: auto; box-shadow: 0 20px 60px rgb(0 0 0 / .35); display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.modal.wide { width: min(880px, 100%); }
.modal.full { width: min(1100px, 100%); }
.modal-h { display: flex; justify-content: space-between; align-items: start; gap: 10px; padding: 18px 20px 6px; }
.modal-h h3 { font-size: 20px; }
.modal-b { padding: 10px 20px 20px; display: grid; gap: 14px; overflow: auto; align-content: start; }
.modal-f { padding: 12px 20px 18px; display: flex; gap: 8px; justify-content: flex-end; border-top: 1px solid var(--line); flex-wrap: wrap; }
.x { border: 0; background: var(--surface-2); width: 34px; height: 34px; border-radius: 50%; font-size: 18px; color: var(--muted); flex: none; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); translate: -50% 0; background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 12px; z-index: 80; font-size: 14px; max-width: calc(100% - 32px); box-shadow: var(--shadow); pointer-events: none; }
.toast.err { background: var(--crit); color: #fff; }

/* Ayuda */
.help-panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100%); background: var(--surface); box-shadow: -10px 0 40px rgb(0 0 0 / .2); z-index: 60; display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); padding-right: env(safe-area-inset-right, 0px); }
.help-panel header { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.help-body { overflow: auto; padding: 16px 18px; display: grid; gap: 10px; align-content: start; font-size: 15px; line-height: 1.55; }
.help-body h4 { font-size: 15px; font-weight: 600; margin-top: 6px; }
.help-body ul, .help-body ol { margin: 0; padding-left: 1.2em; display: grid; gap: 4px; }
.help-ai { border-top: 1px solid var(--line); padding: 12px 18px; display: grid; gap: 8px; }
.help-answer { background: var(--brand-soft); border-radius: 12px; padding: 10px 12px; font-size: 14px; display: grid; gap: 6px; }
.help-answer p, .help-answer ul, .help-answer ol { margin: 0; }
.help-answer ul, .help-answer ol { padding-left: 1.2em; display: grid; gap: 3px; }
.tip-i { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--line); font-size: 11px; color: var(--faint); cursor: help; background: var(--surface); }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: max(16px, env(safe-area-inset-left, 0px)); }
.login-card { width: min(420px, 100%); padding: 28px; display: grid; gap: 16px; }

@media (max-width: 860px) {
  .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); height: auto; min-height: 100%; padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
  .rail { position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; flex-direction: row; border-radius: 16px 16px 0 0; overflow-x: auto; gap: 0;
    padding: 6px max(8px, env(safe-area-inset-left, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-right, 0px)); }
  .rail .logo { display: none; }
  .nav-btn { width: auto; min-width: 62px; }
  .view { overflow: visible; }
  .topbar .who strong { font-size: 16px; }
  .pill select { max-width: 150px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
/* Versión publicada (login y menú lateral) */
.login-card .ver { text-align: center; opacity: .7; font-variant-numeric: tabular-nums; }
.rail .rail-ver { margin-top: auto; padding-top: 10px; font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (max-width: 720px) { .rail .rail-ver { display: none; } }
.help-ver { padding: 10px 16px 16px; text-align: center; opacity: .7; }

/* Bitácora (auditoría) */
.aud-filters { display: grid; gap: 10px; }
.aud-frow { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; }
.aud-dates .f { min-width: 140px; }
.aud-tl { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.aud-day { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); padding: 12px 4px 4px; }
.aud-it { width: 100%; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center; text-align: left; background: none; border: 0; border-radius: 10px; padding: 10px 8px; color: inherit; font: inherit; cursor: pointer; min-height: 52px; }
.aud-it:hover, .aud-it:focus-visible { background: var(--surface-2); }
.aud-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); box-shadow: 0 0 0 3px var(--surface); }
.aud-it.sev-warning .aud-dot { background: var(--warn); }
.aud-it.sev-critical .aud-dot { background: var(--crit); }
.aud-ico svg { width: 20px; height: 20px; color: var(--muted); }
.aud-main { display: grid; gap: 2px; min-width: 0; }
.aud-sum { overflow-wrap: anywhere; }
.aud-meta { font-size: 12px; color: var(--faint); overflow-wrap: anywhere; }
.aud-tag { justify-self: end; }
.aud-kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 14px; margin: 0; }
.aud-kv dt { color: var(--faint); font-size: 13px; }
.aud-kv dd { margin: 0; overflow-wrap: anywhere; }
.aud-diff { display: grid; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.aud-diff-h, .aud-diff-r { display: grid; grid-template-columns: minmax(90px, 1fr) minmax(0, 1.3fr) minmax(0, 1.3fr); gap: 10px; padding: 8px 12px; }
.aud-diff-h { background: var(--surface-2); font-size: 12px; color: var(--faint); text-transform: uppercase; letter-spacing: .05em; }
.aud-diff-r { border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.aud-k { color: var(--muted); font-size: 13px; }
.aud-old { color: var(--crit); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--crit) 40%, transparent); }
.aud-new { color: var(--good); font-weight: 500; }
.aud-code, .aud-pre { font-family: var(--font-mono); font-size: 12px; overflow-wrap: anywhere; white-space: pre-wrap; }
.aud-pre { background: var(--surface-2); border-radius: 8px; padding: 10px; max-height: 260px; overflow: auto; margin: 0; }
.aud-k-warn .v { color: var(--warn); }
.aud-k-crit .v { color: var(--crit); }
@media (max-width: 560px) {
  .aud-it { grid-template-columns: auto minmax(0, 1fr); }
  .aud-tag { grid-column: 2; justify-self: start; }
  .aud-diff-h { display: none; }
  .aud-diff-r { grid-template-columns: 1fr 1fr; }
  .aud-diff-r .aud-k { grid-column: 1 / -1; }
  .aud-kv { grid-template-columns: 1fr; gap: 2px; }
  .aud-kv dd { margin-bottom: 6px; }
}
