/* ==========================================================================
   SACI — Informes Financieros
   ========================================================================== */

:root {
  --bg: #08111f;
  --bg-2: #0d1a2e;
  --panel: #12203a;
  --panel-2: #17263f;
  --line: #26365a;
  --line-soft: #1d2b46;
  --text: #e6edf7;
  --text-2: #a7b6cc;
  --text-3: #6f8199;
  --accent: #c9a85c;
  --teal: #c9a85c;
  --accent-2: #e2c57f;
  --blue: #8fb3e0;
  --amber: #d9a441;
  --red: #e08585;
  --violet: #a99bc9;
  --radius: 14px;
  --shadow: 0 18px 40px -22px rgba(0, 0, 0, .9);
  --mono: "SFMono-Regular", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(1200px 600px at 8% -10%, rgba(201, 168, 92, .09), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(96, 165, 250, .10), transparent 55%),
    var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(201, 168, 92, .28); }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 246px 1fr; min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 18px;
  padding: 20px 14px 16px;
  background: linear-gradient(180deg, rgba(15, 26, 43, .96), rgba(8, 14, 25, .96));
  border-right: 1px solid var(--line-soft);
  backdrop-filter: blur(8px);
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand-logo {
  width: 58px; height: 58px; border-radius: 50%; flex: none;
  background: #f8f4e9; padding: 2px;
  border: 2px solid rgba(201, 168, 92, .75);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .5);
}
.topbar-logo {
  display: none; border-radius: 50%; flex: none;
  background: #f8f4e9; padding: 1px;
  border: 1px solid rgba(201, 168, 92, .75);
}
.brand-mark {
  width: 36px; height: 36px; border-radius: 11px;
  display: grid; place-items: center; color: #1a1206;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 20px -8px rgba(201, 168, 92, .8);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 15px; letter-spacing: -.01em; }
.brand-text span { font-size: 10.5px; color: var(--text-3); text-transform: uppercase; letter-spacing: .09em; }

.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.nav-label {
  font-size: 9.5px; text-transform: uppercase; letter-spacing: .12em;
  color: var(--text-3); padding: 14px 10px 6px; font-weight: 600;
}
.nav-item[hidden] { display: none; }
.btn[hidden] { display: none; }
.side-link[hidden], .chip[hidden] { display: none; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px; border: 1px solid transparent;
  background: transparent; color: var(--text-2); font-size: 13px; font-weight: 500;
  cursor: pointer; text-align: left; font-family: inherit;
  transition: background .15s, color .15s, border-color .15s;
}
.nav-item svg { width: 17px; height: 17px; flex: none; opacity: .85; }
.nav-item[data-view="que-dicen"] { align-items: flex-start; line-height: 1.3; padding-top: 8px; padding-bottom: 8px; }
.nav-item.salir { color: #e08585; }
.nav-item.salir svg { opacity: 1; }
.nav-item.salir:hover { background: rgba(224, 133, 133, .1); color: #f0a0a0; }
.nav-item:hover { background: rgba(255, 255, 255, .04); color: var(--text); }
.nav-item.active {
  background: linear-gradient(90deg, rgba(201, 168, 92, .16), rgba(201, 168, 92, .02));
  color: #d7fbe9; border-color: rgba(201, 168, 92, .28);
}
.nav-item.active svg { color: var(--accent); opacity: 1; }

.side-foot { display: flex; flex-direction: column; gap: 8px; }
.ds-card {
  display: flex; gap: 10px; align-items: center;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px;
}
.ds-flag {
  font-size: 10px; font-weight: 700; letter-spacing: .06em; line-height: 1;
  min-width: 26px; text-align: center; padding: 5px 4px; border-radius: 6px;
  background: rgba(96, 165, 250, .14); color: #bfdbfe; border: 1px solid rgba(96, 165, 250, .28);
}
.flagpill {
  display: inline-block; font-size: 9.5px; font-weight: 700; letter-spacing: .06em;
  padding: 3px 5px; border-radius: 5px; vertical-align: middle;
  background: rgba(96, 165, 250, .14); color: #bfdbfe; border: 1px solid rgba(96, 165, 250, .28);
}
tr.empty-row td { opacity: .45; }
.ds-card div { display: flex; flex-direction: column; min-width: 0; }
.ds-card strong { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ds-card span { font-size: 10.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-contact {
  display: flex; flex-direction: column; gap: 6px; margin-top: 10px;
  padding-top: 10px; border-top: 1px solid var(--line-soft);
}
.side-contact a {
  display: inline-flex; align-items: center; gap: 7px; font-size: 11.5px;
  color: var(--text-3); text-decoration: none; transition: color .15s;
}
.side-contact a:hover { color: var(--accent); }
.side-contact svg { width: 13px; height: 13px; flex: none; opacity: .85; }

.side-link { font-size: 11.5px; color: var(--text-3); text-decoration: none; text-align: center; padding: 4px; }
.side-link:hover { color: var(--accent); }

/* ---------- topbar ---------- */
.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 24px;
  background: rgba(7, 12, 22, .82);
  border-bottom: 1px solid var(--line-soft);
  backdrop-filter: blur(14px);
}
.tb-left { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.tb-right { display: flex; align-items: center; gap: 8px; }

.sel-wrap { display: flex; align-items: center; gap: 8px; }
.sel-label { font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--text-3); }
.sel {
  appearance: none;
  background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236f8199' stroke-width='3'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
  border: 1px solid var(--line); color: var(--text);
  padding: 7px 30px 7px 11px; border-radius: 9px; font-size: 12.5px; font-family: inherit;
  cursor: pointer; max-width: 300px;
}
.sel:focus { outline: none; border-color: rgba(201, 168, 92, .5); }

.tb-badges { display: flex; gap: 6px; flex-wrap: wrap; }
#roleChip { cursor: pointer; transition: border-color .15s, color .15s, background .15s; }
#roleChip:hover { border-color: var(--accent); color: var(--accent); }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10.5px; font-weight: 600; letter-spacing: .02em;
  padding: 4px 8px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text-2);
}
.chip.green { color: #9df3c8; border-color: rgba(201, 168, 92, .3); background: rgba(201, 168, 92, .1); }
.chip.blue { color: #bfdbfe; border-color: rgba(96, 165, 250, .3); background: rgba(96, 165, 250, .1); }
.chip.amber { color: #fde68a; border-color: rgba(251, 191, 36, .3); background: rgba(251, 191, 36, .1); }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: inherit; font-size: 12.5px; font-weight: 600;
  padding: 7px 12px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--text-2);
  transition: all .15s;
}
.btn svg { width: 15px; height: 15px; }
.btn:hover { color: var(--text); border-color: #2b3d5a; background: var(--panel-2); }
.btn-primary {
  background: linear-gradient(140deg, #34d399, #10b981);
  border-color: transparent; color: #1a1206;
  box-shadow: 0 8px 20px -10px rgba(201, 168, 92, .9);
}
.btn-primary:hover { filter: brightness(1.06); color: #1a1206; }
.btn-sm { padding: 5px 9px; font-size: 11.5px; border-radius: 8px; }
.btn-ghost { background: transparent; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- view ---------- */
.view { padding: 22px 24px 60px; max-width: 1500px; width: 100%; }
.view.wide, .view.has-full { max-width: none; }
.card.full { border-color: rgba(201, 168, 92, .38); box-shadow: 0 0 0 1px rgba(201, 168, 92, .08), var(--shadow); }
.loading { display: flex; align-items: center; gap: 10px; color: var(--text-3); padding: 60px 0; justify-content: center; }
.spinner {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .15); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- page head ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 18px; flex-wrap: wrap; }
.page-title { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin: 0 0 4px; }
.page-sub { color: var(--text-3); font-size: 12.5px; margin: 0; max-width: 760px; line-height: 1.5; }
.page-actions { display: flex; gap: 8px; align-items: center; }

/* ---------- kpi ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi {
  background: linear-gradient(160deg, var(--panel), rgba(15, 26, 43, .55));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 15px; position: relative; overflow: hidden;
}
.kpi::after {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 2px;
  background: linear-gradient(90deg, var(--accent), transparent 70%); opacity: .7;
}
.kpi.blue::after { background: linear-gradient(90deg, var(--blue), transparent 70%); }
.kpi.amber::after { background: linear-gradient(90deg, var(--amber), transparent 70%); }
.kpi.red::after { background: linear-gradient(90deg, var(--red), transparent 70%); }
.kpi-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--text-3); font-weight: 600; }
.kpi-value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; margin: 6px 0 3px; font-variant-numeric: tabular-nums; }
.kpi-foot { font-size: 11px; color: var(--text-3); display: flex; align-items: center; gap: 6px; }
.pos { color: var(--accent); }
.neg { color: var(--red); }
.dim { color: var(--text-3); }

/* ---------- cards ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 16px; overflow: hidden;
}
.card-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 14px;
  padding: 14px 18px; border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, rgba(255, 255, 255, .022), transparent);
}
.card-head h3 { margin: 0; font-size: 14.5px; font-weight: 650; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
.card-head p { margin: 3px 0 0; font-size: 11.5px; color: var(--text-3); line-height: 1.45; max-width: 780px; }
.card-tools { display: flex; gap: 6px; align-items: center; flex: none; }
.card-body { padding: 4px 0 8px; }
.card-body.pad { padding: 16px 18px; }

/* ---------- segmented ---------- */
.seg {
  display: flex; width: 100%; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 9px; padding: 2px; gap: 2px;
}
.seg button {
  flex: 1; border: 0; background: transparent; color: var(--text-3); font-family: inherit;
  font-size: 11.5px; font-weight: 600; padding: 7px 8px; border-radius: 7px; cursor: pointer;
  transition: all .15s; white-space: nowrap;
}
.seg button.on { background: var(--panel-2); color: var(--text); box-shadow: 0 1px 0 rgba(255, 255, 255, .04) inset; }
.seg button:hover { color: var(--text-2); }

/* ---------- tabla financiera ---------- */
.tbl-wrap { width: 100%; overflow-x: auto; }
table.fin {
  width: 100%; border-collapse: separate; border-spacing: 0;
  font-size: 13px; font-variant-numeric: tabular-nums;
}
table.fin th, table.fin td { padding: 7px 12px; text-align: right; white-space: nowrap; }
table.fin th:first-child, table.fin td:first-child { text-align: left; white-space: normal; min-width: 260px; }

table.fin thead th {
  position: sticky; top: 0; z-index: 2;
  background: #0c1524; font-size: 10.5px; font-weight: 650; color: var(--text-2);
  letter-spacing: .035em; text-transform: uppercase;
  border-bottom: 1px solid var(--line); padding-top: 9px; padding-bottom: 9px;
}
.col-sub {
  display: block; font-size: 9px; font-weight: 500; color: var(--text-3);
  text-transform: none; letter-spacing: 0; font-style: normal; margin-top: 1px;
}
table.fin thead tr.dates th {
  font-size: 10px; font-weight: 500; text-transform: none; letter-spacing: 0;
  color: var(--text-3); background: #0a1220; border-bottom: 1px solid var(--line-soft);
  padding-top: 5px; padding-bottom: 5px;
}
table.fin thead th.col-h { cursor: pointer; }
table.fin thead th.col-h:hover { color: var(--text); }
table.fin thead th.sel-col { color: var(--accent); }
table.fin tbody tr { transition: background .1s; }
table.fin tbody tr:hover { background: rgba(255, 255, 255, .028); }
table.fin tbody td { border-bottom: 1px solid rgba(30, 44, 68, .45); color: var(--text-2); }
table.fin tbody td:first-child { color: var(--text); }
table.fin td.num, table.fin th.num { font-feature-settings: "tnum"; }
table.fin .negv { color: #fca5a5; }
table.fin .posv { color: #86efac; }

tr.subtotal td {
  font-weight: 700; color: var(--text) !important;
  background: rgba(201, 168, 92, .055);
  border-top: 1px solid rgba(201, 168, 92, .28);
  border-bottom: 1px solid rgba(201, 168, 92, .18) !important;
}
tr.total td {
  font-weight: 700; color: #eafff6 !important;
  background: rgba(201, 168, 92, .12);
  border-top: 1px solid rgba(201, 168, 92, .45);
  font-size: 13.5px;
}
tr.metric td { color: var(--text-3) !important; font-size: 11.5px; font-style: italic; }
tr.metric td:first-child { padding-left: 26px; }
tr.subtotal td:first-child { padding-left: 12px; }
td.indent { padding-left: 26px !important; }

tr.clickable { cursor: pointer; }
tr.clickable td:first-child::after {
  content: "›"; color: var(--text-3); margin-left: 8px; font-size: 13px; opacity: 0;
  transition: opacity .15s;
}
tr.clickable:hover td:first-child::after { opacity: 1; color: var(--accent); }

.flag-ok { color: var(--accent); }
.flag-bad { color: var(--red); }

/* barra dentro de celda */
.cellbar { position: relative; }
.cellbar span { position: relative; z-index: 1; }
.cellbar i {
  position: absolute; top: 50%; transform: translateY(-50%);
  height: 14px; border-radius: 3px; background: rgba(96, 165, 250, .16); z-index: 0;
}

/* sparkline */
.spark { display: block; width: 74px; height: 18px; opacity: .8; }
.spark path { fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- charts ---------- */
.chart-grid { display: grid; grid-template-columns: 1.55fr 1fr; gap: 16px; }
@media (max-width: 1180px) { .chart-grid { grid-template-columns: 1fr; } }
.chart { width: 100%; height: auto; display: block; }
.chart text { font-family: inherit; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; padding: 0 18px 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-3); }
.legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }

/* ---------- checks ---------- */
.checks { display: flex; flex-direction: column; gap: 1px; }
.check-row {
  display: grid; grid-template-columns: 1fr auto auto auto; gap: 12px; align-items: center;
  padding: 9px 18px; font-size: 12px; border-bottom: 1px solid var(--line-soft);
}
.check-row:last-child { border-bottom: 0; }
.check-row .lbl { color: var(--text-2); }
.check-row .per { color: var(--text-3); font-size: 11px; }
.check-row .val { font-variant-numeric: tabular-nums; color: var(--text-2); font-size: 12px; min-width: 90px; text-align: right; }
.badge-ok, .badge-bad {
  font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 999px; letter-spacing: .04em;
}
.badge-ok { background: rgba(201, 168, 92, .14); color: #6ee7b7; border: 1px solid rgba(201, 168, 92, .3); }
.badge-bad { background: rgba(248, 113, 113, .14); color: #fca5a5; border: 1px solid rgba(248, 113, 113, .3); }

/* ---------- el atributo hidden siempre oculta ---------- */
[hidden] { display: none !important; }

/* ---------- navegación móvil ---------- */
.mobile-nav { display: none; }

@media (max-width: 860px) {
  .mobile-nav {
    display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px;
    background: var(--panel); border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 25;
  }
  .mobile-chip {
    flex: 0 0 auto; display: inline-flex; align-items: center; gap: 5px;
    padding: 6px 10px; border-radius: 999px; border: 1px solid var(--line);
    background: var(--bg-2); color: var(--text-2); font-size: 11.5px;
    font-family: inherit; white-space: nowrap; cursor: pointer;
    text-decoration: none; line-height: 1.2;
  }
  .mobile-chip svg { width: 13px; height: 13px; opacity: .9; }
  .mobile-chip.active {
    background: rgba(201, 168, 92, .16); border-color: rgba(201, 168, 92, .5);
    color: var(--text);
  }
  .mobile-chip[hidden] { display: none; }
  .mobile-chip.salir { border-color: rgba(224, 133, 133, .5); color: #e08585; }
  .mobile-chip.entrar { border-color: rgba(201, 168, 92, .6); color: var(--accent); }

  /* la barra superior se aligera y se ordena en dos filas */
  .tb-badges, #btnUpload { display: none; }
  .topbar-logo { display: block; width: 34px; height: 34px; }
  /* sólo la barra de pestañas queda fija; la superior se desplaza */
  .topbar { position: static; }
  .topbar { gap: 8px; flex-wrap: wrap; padding: 10px 12px; }
  .tb-left { width: 100%; gap: 8px; }
  .tb-right { width: 100%; justify-content: flex-end; gap: 6px; }
  .sel-wrap { flex: 1 1 0; min-width: 0; }
  .sel { width: 100%; max-width: none; }
  .btn { padding: 7px 11px; font-size: 12.5px; }

  /* informes: una tarjeta por fila, siempre visibles */
  .dl-grid { grid-template-columns: 1fr; }
  .dl-card { padding: 14px; }
  .dl-card-actions .btn { flex: 1 1 100%; }
  .doc-search { padding: 9px 12px; }
}

/* ---------- visor de informes ---------- */
.viewer {
  position: fixed; inset: 0; z-index: 130; display: flex; flex-direction: column;
  background: rgba(4, 9, 17, .94); backdrop-filter: blur(4px);
  opacity: 0; pointer-events: none; transition: opacity .18s;
}
.viewer.on { opacity: 1; pointer-events: auto; }
.viewer-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.viewer-title { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text); }
.viewer-title strong { font-weight: 600; }
.viewer-actions { display: flex; gap: 8px; align-items: center; }
.viewer-body { flex: 1; display: flex; flex-direction: column; padding: 12px 16px 16px; gap: 8px; min-height: 0; }
.viewer-body iframe {
  flex: 1; width: 100%; min-height: 0; border: 1px solid var(--line); border-radius: 10px;
  background: #fff;
}
.viewer-error {
  margin: 0; padding: 12px 16px; border-radius: 10px; font-size: 12.5px; line-height: 1.55;
  background: rgba(224, 133, 133, .12); border: 1px solid rgba(224, 133, 133, .45); color: #f0b4b4;
}
.viewer-hint { margin: 0; font-size: 11px; color: var(--text-3); text-align: center; }

/* ---------- descargas ---------- */
.dl-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; }
.dl-item {
  display: flex; gap: 10px; align-items: flex-start; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg-2); color: var(--text-2);
  text-decoration: none; transition: border-color .15s, background .15s, transform .15s;
}
.dl-item:hover { border-color: rgba(201, 168, 92, .45); background: rgba(201, 168, 92, .07); transform: translateY(-1px); }
.dl-item svg { width: 17px; height: 17px; flex: 0 0 17px; margin-top: 2px; color: var(--teal); }
.dl-item strong { display: block; font-size: 12.5px; color: var(--text); font-weight: 600; }
.dl-item em { display: block; font-style: normal; font-size: 11px; color: var(--text-3); margin-top: 2px; line-height: 1.45; }

/* ---------- buscador de informes ---------- */
.doc-search {
  display: flex; align-items: center; gap: 10px; margin-bottom: 14px;
  padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel);
}
.doc-search svg { width: 17px; height: 17px; flex: none; color: var(--accent); }
.doc-search input {
  flex: 1; min-width: 0; background: transparent; border: 0; outline: none;
  color: var(--text); font-family: inherit; font-size: 13.5px;
}
.doc-search input::placeholder { color: var(--text-3); }
.doc-search input::-webkit-search-cancel-button { display: none; }
.doc-clear {
  background: transparent; border: 1px solid var(--line); color: var(--text-3);
  font-family: inherit; font-size: 11.5px; padding: 4px 10px; border-radius: 8px; cursor: pointer;
}
.doc-clear:hover { color: var(--text); border-color: var(--accent); }
.doc-empty { color: var(--text-3); font-size: 13px; margin: 4px 2px 14px; }

/* ---------- tarjetas de informes ---------- */
.dl-card {
  display: flex; flex-direction: column; gap: 6px; padding: 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text-2);
  text-decoration: none; transition: border-color .15s, transform .15s, box-shadow .15s;
}
.dl-card:hover { border-color: rgba(201, 168, 92, .45); transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, .28); }
.dl-card.off { opacity: .55; border-style: dashed; }
.dl-card.off:hover { transform: none; box-shadow: none; border-color: var(--line); }
.dl-card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 2px; }
.dl-badge {
  font-size: 9.5px; font-weight: 700; letter-spacing: .06em; padding: 3px 7px; border-radius: 5px;
  background: rgba(239, 68, 68, .14); color: #fca5a5; border: 1px solid rgba(239, 68, 68, .3);
}
.dl-tag { font-size: 10px; color: var(--text-3); text-transform: uppercase; letter-spacing: .07em; }
.dl-card strong { font-size: 13.5px; color: var(--text); font-weight: 600; }
.dl-card-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.dl-card-actions .btn { flex: 1; justify-content: center; min-width: 118px; text-decoration: none; }
.dl-card em { font-style: normal; font-size: 11.5px; color: var(--text-3); line-height: 1.5; }
.dl-cta {
  display: inline-flex; align-items: center; gap: 5px; margin-top: 8px; font-size: 11.5px;
  color: var(--teal); font-weight: 600;
}
.dl-cta svg { width: 14px; height: 14px; }

/* ---------- menú desplegable ---------- */
.menu-wrap { position: relative; }
.menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 40;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 4px; min-width: 230px; box-shadow: var(--shadow);
}
.menu button {
  display: block; width: 100%; text-align: left; background: transparent; border: 0;
  color: var(--text-2); font-family: inherit; font-size: 12.5px; padding: 8px 10px;
  border-radius: 7px; cursor: pointer;
}
.menu button:hover { background: rgba(255,255,255,.05); color: var(--text); }
.menu-sep { height: 1px; background: var(--line); margin: 4px 6px; }

/* ---------- login ---------- */
.login-overlay {
  position: fixed; inset: 0; z-index: 120; display: grid; place-items: center;
  background: rgba(4, 9, 17, .82); backdrop-filter: blur(6px);
  opacity: 0; pointer-events: none; transition: opacity .18s;
}
.login-overlay.on { opacity: 1; pointer-events: auto; }
.login-card {
  width: min(420px, 92vw); background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 22px; box-shadow: var(--shadow); display: flex;
  flex-direction: column; gap: 14px;
}
.login-head { display: flex; gap: 12px; align-items: center; }
.login-head h3 { margin: 0; font-size: 16px; }
.login-head p { margin: 2px 0 0; font-size: 11.5px; color: var(--text-3); }
.login-card .field { display: flex; flex-direction: column; gap: 5px; }
.login-ident {
  padding: 9px 11px; border-radius: 9px; border: 1px solid var(--line);
  background: rgba(201, 168, 92, .10); color: var(--accent);
  font-size: 13px; font-weight: 600;
}
.field-hint { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.login-card label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); font-weight: 600; }
.login-card input, .login-card select {
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  padding: 9px 11px; border-radius: 9px; font-family: inherit; font-size: 13px;
}
.login-card input:focus, .login-card select:focus { outline: none; border-color: rgba(201, 168, 92, .55); }
.login-actions { display: flex; gap: 8px; }
.login-actions .btn { flex: 1; justify-content: center; }
.login-error { color: #fca5a5; font-size: 12px; min-height: 16px; }
.login-note { font-size: 11px; color: var(--text-3); margin: 0; line-height: 1.5; }
.public-banner {
  display: flex; align-items: center; gap: 8px; padding: 8px 18px; font-size: 11.5px;
  color: #bfdbfe; background: rgba(96, 165, 250, .08); border-bottom: 1px solid rgba(96, 165, 250, .18);
}

/* ---------- seguridad ---------- */
.key-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.key-row:last-child { border-bottom: 0; }
.key-name { font-size: 12.5px; }
.key-name span { display: block; font-size: 10.5px; color: var(--text-3); }
.key-input {
  width: 130px; padding: 6px 9px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--text); font-family: inherit; font-size: 11.5px;
}
.key-input:focus { outline: none; border-color: var(--accent); }
.key-out {
  font-family: var(--mono); font-size: 12.5px; background: rgba(201,168,92,.12);
  border: 1px dashed rgba(201,168,92,.4); color: #a7f3d0; padding: 6px 10px; border-radius: 8px;
}
.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-2); }

/* ---------- drawer ---------- */
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: min(460px, 92vw);
  background: #0b1424; border-left: 1px solid var(--line);
  transform: translateX(102%); transition: transform .22s cubic-bezier(.4, 0, .2, 1);
  z-index: 60; display: flex; flex-direction: column; box-shadow: -30px 0 60px -30px #000;
}
.drawer.open { transform: none; }
.drawer-body { padding: 18px; overflow-y: auto; }
.scrim {
  position: fixed; inset: 0; background: rgba(2, 6, 12, .55); z-index: 55;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.scrim.on { opacity: 1; pointer-events: auto; }
.drawer h4 { margin: 0 0 2px; font-size: 15px; }
.drawer .sub { color: var(--text-3); font-size: 11.5px; margin-bottom: 14px; }
.drawer-close { position: absolute; top: 14px; right: 14px; }
.drill-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.drill-table th { text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-3); padding: 6px 6px; border-bottom: 1px solid var(--line); }
.drill-table td { padding: 6px; border-bottom: 1px solid var(--line-soft); color: var(--text-2); font-variant-numeric: tabular-nums; }
.drill-table td:last-child, .drill-table th:last-child { text-align: right; }
.drill-table .code { font-family: var(--mono); font-size: 10.5px; color: var(--text-3); }
.note-box {
  background: rgba(96, 165, 250, .07); border: 1px solid rgba(96, 165, 250, .2);
  border-radius: 10px; padding: 10px 12px; font-size: 11.5px; color: var(--text-2); line-height: 1.5;
}
.note-box.warn { background: rgba(251, 191, 36, .07); border-color: rgba(251, 191, 36, .22); }

/* ---------- uploader ---------- */
.drop {
  border: 2px dashed #2a3c59; border-radius: var(--radius);
  padding: 34px 20px; text-align: center; cursor: pointer;
  transition: all .15s; background: rgba(255, 255, 255, .012);
}
.drop:hover, .drop.hot { border-color: var(--accent); background: rgba(201, 168, 92, .06); }
.drop svg { width: 30px; height: 30px; color: var(--text-3); margin-bottom: 10px; }
.drop strong { display: block; font-size: 13.5px; margin-bottom: 4px; }
.drop span { font-size: 11.5px; color: var(--text-3); }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); font-weight: 600; }
.field input, .field select {
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  padding: 8px 10px; border-radius: 9px; font-family: inherit; font-size: 13px;
}
.field input:focus, .field select:focus { outline: none; border-color: rgba(201, 168, 92, .5); }

.file-list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.file-row {
  display: grid; grid-template-columns: 1fr 120px 120px 34px; gap: 10px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
}
.file-row .fname { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .fsize { font-size: 11px; color: var(--text-3); }
.file-row select { background: var(--bg-2); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 5px 7px; font-family: inherit; font-size: 12px; }
.icon-btn {
  background: transparent; border: 1px solid transparent; color: var(--text-3);
  cursor: pointer; border-radius: 8px; padding: 5px; display: grid; place-items: center;
}
.icon-btn:hover { color: var(--red); border-color: rgba(248, 113, 113, .3); background: rgba(248, 113, 113, .08); }

/* ---------- mapping ---------- */
.mapping-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 18px; border-bottom: 1px solid var(--line-soft); }
.search {
  flex: 1; min-width: 200px; background: var(--bg-2); border: 1px solid var(--line);
  color: var(--text); padding: 7px 11px; border-radius: 9px; font-family: inherit; font-size: 12.5px;
}
.search:focus { outline: none; border-color: rgba(201, 168, 92, .5); }
table.map { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12.5px; }
table.map th {
  text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-3); padding: 8px 12px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: #0c1524; z-index: 2;
}
table.map td { padding: 6px 12px; border-bottom: 1px solid var(--line-soft); color: var(--text-2); }
table.map tr:hover td { background: rgba(255, 255, 255, .025); }
table.map td.code { font-family: var(--mono); font-size: 11px; color: var(--text-3); }
table.map select {
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 7px; padding: 4px 6px; font-family: inherit; font-size: 11.5px; width: 100%;
}
table.map select.changed { border-color: var(--accent); color: #d1fae5; }
.map-scroll { max-height: 60vh; overflow: auto; }

/* ---------- empresas ---------- */
.company-card .card-body { display: flex; flex-direction: column; gap: 12px; }
.company-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  background: var(--bg-2); border: 1px solid var(--line-soft); border-radius: 10px; padding: 10px;
}
.company-stats div { display: flex; flex-direction: column; gap: 2px; }
.company-stats span { font-size: 9.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); }
.company-stats strong { font-size: 14px; font-variant-numeric: tabular-nums; }
.company-activity { font-size: 11.5px; color: var(--text-3); margin: 0; line-height: 1.5; min-height: 34px; }
.company-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }
.company-actions .btn { flex: 1; justify-content: center; }

/* ---------- misc ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 1050px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 20px);
  background: #10243a; border: 1px solid rgba(201, 168, 92, .4); color: #d9ffee;
  padding: 10px 16px; border-radius: 10px; font-size: 12.5px; z-index: 90;
  opacity: 0; pointer-events: none; transition: all .22s; box-shadow: var(--shadow);
  max-width: 90vw;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: rgba(248, 113, 113, .5); color: #ffdede; }

.empty { padding: 40px 20px; text-align: center; color: var(--text-3); font-size: 12.5px; }
.empty strong { display: block; color: var(--text-2); font-size: 14px; margin-bottom: 6px; }

.waterfall-note { padding: 0 18px 14px; font-size: 11px; color: var(--text-3); line-height: 1.5; }

details.help { border-top: 1px solid var(--line-soft); }
details.help summary {
  cursor: pointer; padding: 11px 18px; font-size: 12px; color: var(--text-2);
  list-style: none; display: flex; align-items: center; gap: 8px;
}
details.help summary::-webkit-details-marker { display: none; }
details.help summary::before { content: "＋"; color: var(--text-3); font-size: 11px; }
details.help[open] summary::before { content: "－"; }
details.help .body { padding: 0 18px 16px; font-size: 12px; color: var(--text-3); line-height: 1.65; }
details.help .body strong { color: var(--text-2); }
details.help .body code { font-family: var(--mono); font-size: 11px; background: rgba(255, 255, 255, .06); padding: 1px 5px; border-radius: 4px; }
details.help .body ul { margin: 6px 0; padding-left: 18px; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .view { padding: 16px; }
  .topbar { padding: 10px 14px; }
  table.fin th:first-child, table.fin td:first-child { min-width: 190px; }
}

/* ---------- plan de cuentas ---------- */
.plan-buscar {
  padding: 7px 11px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--text); font-family: inherit; font-size: 12px;
  min-width: 280px;
}
.plan-buscar:focus { outline: none; border-color: var(--accent); }
.plan-tabla { width: 100%; font-size: 12px; }
.plan-tabla th { position: sticky; top: 0; background: var(--panel); z-index: 1; }
.plan-tabla td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.plan-tabla tr.plan-grupo { background: rgba(201, 168, 92, .07); font-weight: 600; }
.plan-tabla .mono { font-family: ui-monospace, Consolas, monospace; font-size: 11.5px; }
.plan-acciones { display: flex; gap: 6px; white-space: nowrap; }
.plan-form { margin-bottom: 14px; border-color: rgba(201, 168, 92, .45); }
.plan-campos { display: flex; flex-wrap: wrap; gap: 10px; }
.plan-campo { display: flex; flex-direction: column; gap: 3px; min-width: 150px; }
.plan-campo span { font-size: 10.5px; color: var(--text-3); }
.plan-campo input {
  padding: 7px 9px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--text); font-family: inherit; font-size: 12px;
}
.plan-campo input:focus { outline: none; border-color: var(--accent); }
@media (max-width: 860px) {
  .plan-buscar { min-width: 0; width: 100%; }
  .plan-tabla { font-size: 11px; }
  .plan-acciones { flex-direction: column; }
}

/* ---------- catálogo del SII y selector de plan ---------- */
.plan-selector {
  padding: 7px 11px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--text); font-family: inherit; font-size: 12px;
  max-width: 320px;
}
.plan-selector:focus { outline: none; border-color: var(--accent); }
.sii-card { margin-bottom: 14px; }
.sii-cuerpo { max-height: 620px; overflow-y: auto; }
.sii-normativa { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.sii-norma {
  flex: 1 1 260px; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; background: var(--bg-2);
}
.sii-norma strong { display: block; font-size: 11.5px; color: var(--accent); margin-bottom: 4px; }
.sii-norma span { font-size: 10.5px; color: var(--text-3); line-height: 1.45; }
.sii-columnas { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.sii-columnas h4 {
  margin: 0 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-3);
}
.sii-tabla-wrap { max-height: 260px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.sii-tabla { width: 100%; border-collapse: collapse; font-size: 11px; }
.sii-tabla th {
  position: sticky; top: 0; background: var(--panel); text-align: left;
  padding: 5px 8px; font-size: 10px; color: var(--text-3); border-bottom: 1px solid var(--line);
}
.sii-tabla td { padding: 4px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.sii-tabla .mono { font-family: ui-monospace, Consolas, monospace; white-space: nowrap; }
@media (max-width: 900px) {
  .sii-columnas { grid-template-columns: 1fr; }
  .sii-cuerpo { max-height: none; }
  .plan-selector { max-width: 100%; width: 100%; }
}

/* ---------- biblioteca de planes de cuentas ---------- */
.planes-grupo {
  margin: 22px 0 10px; font-size: 12px; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--accent);
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
}
.planes-grupo span {
  font-size: 10.5px; font-weight: 500; letter-spacing: 0; text-transform: none;
  color: var(--text-3);
}
.planes-lista { display: flex; flex-direction: column; gap: 12px; }
.plan-card {
  border: 1px solid var(--line); border-radius: 14px; background: var(--panel);
  overflow: hidden;
}
.plan-card-actual { border-color: rgba(201, 168, 92, .55); box-shadow: 0 0 0 1px rgba(201, 168, 92, .18) inset; }
.plan-card-head {
  display: flex; justify-content: space-between; gap: 16px; padding: 16px 18px; flex-wrap: wrap;
}
.plan-card-titulo { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.plan-card-titulo h3 { margin: 0; font-size: 14px; color: var(--text); }
.chip-regimen {
  font-size: 10px; padding: 2px 8px; border-radius: 999px;
  background: rgba(201, 168, 92, .16); color: var(--accent); font-weight: 700;
}
.chip-actual {
  font-size: 10px; padding: 2px 8px; border-radius: 999px;
  background: rgba(31, 111, 67, .14); color: #1f6f43; font-weight: 700;
}
.plan-card-head p { margin: 0 0 8px; font-size: 12px; color: var(--text-2); line-height: 1.5; max-width: 720px; }
.plan-card-meta { display: flex; gap: 16px; flex-wrap: wrap; font-size: 11px; color: var(--text-3); }
.plan-card-meta strong { color: var(--text); }
.plan-card-acciones { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.plan-card-cuerpo { border-top: 1px solid var(--line); padding: 12px 18px 18px; }
.plan-preview { max-height: 360px; overflow: auto; }
.planes-nota { margin-top: 18px; font-size: 11px; color: var(--text-3); font-style: italic; }
@media (max-width: 780px) {
  .plan-card-head { flex-direction: column; }
  .plan-card-acciones { width: 100%; }
  .plan-card-acciones .btn { flex: 1 1 auto; }
}
