/* ============================================================
   Presupuesto 2027 — identidad "planilla contable"
   Tipografía: Archivo (Omnibus-Type, Buenos Aires) + Source Serif 4 + IBM Plex Mono
   ============================================================ */

:root {
  /* --- neutros con sesgo verde (papel de planilla, no gris puro) --- */
  --paper:      #F4F6F1;
  --surface:    #FCFCFB;
  --surface-2:  #FFFFFF;
  --bar:        #EDF1E8;        /* la raya del greenbar */
  --rule:       #D6DCD0;
  --rule-soft:  #E5EADF;
  --ink:        #16201A;
  --ink-2:      #3F4C43;
  --ink-3:      #6C786F;
  --ink-4:      #939C93;

  /* --- acento: verde tinta contable --- */
  --accent:     #0F6B54;
  --accent-ink: #0A4D3C;
  --accent-bg:  #E2EFE9;

  /* --- semánticos (estado, nunca series) --- */
  --crit:       #99242B;
  --crit-bg:    #F7E6E6;
  --warn:       #A8620F;
  --warn-bg:    #F8EDDE;
  --ok:         #2C6A47;
  --ok-bg:      #E4EFE7;
  --neg:        #99242B;
  --pos:        #2C6A47;

  /* --- categóricos (validados: lightness, croma, CVD, contraste) --- */
  --c1: #00897B;  --c2: #D1690B;  --c3: #3552C9;
  --c4: #A4359B;  --c5: #6D8F00;  --c6: #8A9287;

  --shadow: 0 1px 2px rgba(22, 32, 26, .06), 0 8px 24px -12px rgba(22, 32, 26, .18);
  --shadow-lg: 0 2px 4px rgba(22, 32, 26, .08), 0 24px 48px -16px rgba(22, 32, 26, .25);

  --sans: 'Archivo', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Consolas, monospace;

  --nav-w: 208px;
  --top-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:     #0F1512;
    --surface:   #161D19;
    --surface-2: #1B231E;
    --bar:       #1C241F;
    --rule:      #2C3730;
    --rule-soft: #232C27;
    --ink:       #E7EDE6;
    --ink-2:     #B9C4BA;
    --ink-3:     #8C978D;
    --ink-4:     #6B756C;
    --accent:     #4FBE9B;
    --accent-ink: #7FD4B8;
    --accent-bg:  #122C24;
    --crit:  #E8858A;  --crit-bg: #2E1A1B;
    --warn:  #DFA44F;  --warn-bg: #2C2317;
    --ok:    #6FC08D;  --ok-bg:   #16271C;
    --neg:   #E8858A;  --pos:     #6FC08D;
    --c1: #1FA08F;  --c2: #C97524;  --c3: #6273E6;
    --c4: #C053B6;  --c5: #7E9B18;  --c6: #7C867E;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.6);
    --shadow-lg: 0 2px 4px rgba(0,0,0,.5), 0 24px 48px -16px rgba(0,0,0,.7);
  }
}

:root[data-theme="dark"] {
  --paper:     #0F1512;
  --surface:   #161D19;
  --surface-2: #1B231E;
  --bar:       #1C241F;
  --rule:      #2C3730;
  --rule-soft: #232C27;
  --ink:       #E7EDE6;
  --ink-2:     #B9C4BA;
  --ink-3:     #8C978D;
  --ink-4:     #6B756C;
  --accent:     #4FBE9B;
  --accent-ink: #7FD4B8;
  --accent-bg:  #122C24;
  --crit:  #E8858A;  --crit-bg: #2E1A1B;
  --warn:  #DFA44F;  --warn-bg: #2C2317;
  --ok:    #6FC08D;  --ok-bg:   #16271C;
  --neg:   #E8858A;  --pos:     #6FC08D;
  --c1: #1FA08F;  --c2: #C97524;  --c3: #6273E6;
  --c4: #C053B6;  --c5: #7E9B18;  --c6: #7C867E;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.6);
  --shadow-lg: 0 2px 4px rgba(0,0,0,.5), 0 24px 48px -16px rgba(0,0,0,.7);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; text-wrap: balance; letter-spacing: -.011em; }
a { color: var(--accent-ink); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: .86em; }

/* eyebrow: etiqueta de sección */
.eyebrow {
  font-size: 10.5px; font-weight: 600; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-3);
}

/* ============================================================ layout */
.shell { display: grid; grid-template-columns: var(--nav-w) 1fr; min-height: 100vh; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  grid-column: 1 / -1;
  height: var(--top-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: baseline; gap: 9px; width: calc(var(--nav-w) - 18px); flex: none; }
.brand b { font-size: 15px; font-weight: 700; letter-spacing: -.02em; white-space: nowrap; }
.brand span { font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.search-wrap { flex: 1; max-width: 560px; position: relative; }
.search-wrap input {
  width: 100%; height: 34px; padding: 0 34px 0 11px;
  background: var(--paper); color: var(--ink);
  border: 1px solid var(--rule); border-radius: 5px;
  font: inherit; font-size: 13px;
}
.search-wrap input::placeholder { color: var(--ink-4); }
.search-wrap kbd {
  position: absolute; right: 8px; top: 8px;
  font-family: var(--mono); font-size: 10px; color: var(--ink-4);
  border: 1px solid var(--rule); border-radius: 3px; padding: 1px 4px;
  background: var(--surface);
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.icon-btn {
  height: 30px; padding: 0 10px; background: transparent;
  border: 1px solid var(--rule); border-radius: 5px; cursor: pointer;
  font-size: 12px; color: var(--ink-2);
}
.icon-btn:hover { background: var(--bar); }

nav.side {
  position: sticky; top: var(--top-h); align-self: start;
  height: calc(100vh - var(--top-h));
  padding: 14px 10px; background: var(--surface);
  border-right: 1px solid var(--rule);
  display: flex; flex-direction: column; gap: 2px;
  overflow-y: auto;
}
nav.side button {
  display: flex; align-items: baseline; gap: 9px;
  width: 100%; padding: 7px 10px; text-align: left;
  background: transparent; border: 0; border-radius: 5px; cursor: pointer;
  font-size: 13px; color: var(--ink-2);
}
nav.side button .n { font-family: var(--mono); font-size: 10px; color: var(--ink-4); }
nav.side button:hover { background: var(--bar); color: var(--ink); }
nav.side button[aria-current="true"] { background: var(--accent-bg); color: var(--accent-ink); font-weight: 600; }
nav.side button[aria-current="true"] .n { color: var(--accent); }
.side-foot { margin-top: auto; padding: 12px 10px 4px; border-top: 1px solid var(--rule-soft); font-size: 11px; color: var(--ink-4); line-height: 1.45; }

main { padding: 22px 26px 80px; min-width: 0; }
.view { display: none; }
.view.on { display: block; }

.view-head { margin-bottom: 20px; }
.view-head h1 { font-size: 22px; letter-spacing: -.025em; }
.view-head p { margin: 5px 0 0; color: var(--ink-3); font-size: 13px; max-width: 74ch; }

/* ============================================================ tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(178px, 1fr)); gap: 1px; background: var(--rule); border: 1px solid var(--rule); border-radius: 7px; overflow: hidden; margin-bottom: 22px; }
.tile { background: var(--surface); padding: 13px 15px 14px; display: flex; flex-direction: column; gap: 3px; }
.tile .k { font-size: 10.5px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-3); }
.tile .v { font-size: 22px; font-weight: 700; letter-spacing: -.03em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.tile .s { font-size: 11.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.tile .v.pos { color: var(--pos); } .tile .v.neg { color: var(--neg); }

/* ============================================================ panels */
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: 7px; margin-bottom: 18px; overflow: hidden; }
.panel > header { padding: 12px 15px; border-bottom: 1px solid var(--rule-soft); display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.panel > header h2 { font-size: 13.5px; }
.panel > header .hint { font-size: 11.5px; color: var(--ink-3); }
.panel > header .spacer { margin-left: auto; }
.panel .body { padding: 15px; }
.panel .body.flush { padding: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 18px; }
.grid-2 > .panel { margin: 0; }

/* ============================================================ tablas greenbar */
.tbl-wrap { overflow-x: auto; }
table.g { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.g th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface); text-align: left; font-weight: 600;
  font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3);
  padding: 8px 11px; border-bottom: 1px solid var(--rule); white-space: nowrap;
}
table.g th.r, table.g td.r { text-align: right; font-variant-numeric: tabular-nums; }
table.g td { padding: 6px 11px; border-bottom: 1px solid var(--rule-soft); vertical-align: top; }
table.g tbody tr:nth-child(even) { background: var(--bar); }
table.g tbody tr.click { cursor: pointer; }
table.g tbody tr.click:hover { background: var(--accent-bg); }
table.g td.name { max-width: 380px; }
table.g .sub { color: var(--ink-3); font-size: 11px; }
table.g th.sortable { cursor: pointer; user-select: none; }
table.g th.sortable:hover { color: var(--ink); }
table.g th .caret { opacity: .45; font-size: 9px; }

/* barra dentro de celda */
.cellbar { position: relative; display: block; height: 15px; border-radius: 0 3px 3px 0; background: var(--accent); opacity: .75; }

/* ============================================================ chips */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 7px; border-radius: 10px; font-size: 10.5px; font-weight: 600;
  letter-spacing: .02em; white-space: nowrap;
  background: var(--bar); color: var(--ink-2); border: 1px solid var(--rule);
}
.chip.crit { background: var(--crit-bg); color: var(--crit); border-color: transparent; }
.chip.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.chip.ok   { background: var(--ok-bg);   color: var(--ok);   border-color: transparent; }
.chip.acc  { background: var(--accent-bg); color: var(--accent-ink); border-color: transparent; }

/* franja de severidad */
.sev { width: 3px; border-radius: 2px; flex: none; align-self: stretch; }
.sev.alta { background: var(--crit); } .sev.media { background: var(--warn); }
.sev.baja { background: var(--ink-4); } .sev.ok { background: var(--ok); }

/* ============================================================ filtros */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input[type=text], .filters select {
  height: 30px; padding: 0 9px; font: inherit; font-size: 12.5px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--rule); border-radius: 5px;
}
.filters input[type=text] { min-width: 230px; }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 5px; overflow: hidden; background: var(--surface); }
.seg button { padding: 5px 11px; background: transparent; border: 0; border-right: 1px solid var(--rule); cursor: pointer; font-size: 12px; color: var(--ink-2); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent-bg); color: var(--accent-ink); font-weight: 600; }
.count { font-size: 11.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* ============================================================ charts */
.legend { display: flex; flex-wrap: wrap; gap: 6px 15px; margin: 0 0 11px; padding: 0; list-style: none; font-size: 11.5px; color: var(--ink-2); }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.stack { display: flex; width: 100%; height: 30px; gap: 2px; margin-bottom: 9px; }
.stack > div { height: 100%; position: relative; }
.stack > div:first-child { border-radius: 3px 0 0 3px; }
.stack > div:last-child { border-radius: 0 3px 3px 0; }
svg.chart { display: block; width: 100%; height: auto; overflow: visible; }
svg.chart text { font-family: var(--sans); fill: var(--ink-2); }
svg.chart .ax { stroke: var(--rule); stroke-width: 1; }
svg.chart .grid { stroke: var(--rule-soft); stroke-width: 1; }
svg.chart .lbl { font-size: 10.5px; fill: var(--ink-3); }
svg.chart .val { font-size: 10.5px; fill: var(--ink-2); font-variant-numeric: tabular-nums; }

/* barras diverging (variación real) */
.divrow { display: grid; grid-template-columns: 210px 1fr 74px; gap: 11px; align-items: center; padding: 3px 0; font-size: 12.5px; }
.divrow .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.divtrack { position: relative; height: 17px; background: var(--rule-soft); border-radius: 2px; }
.divtrack .zero { position: absolute; top: -2px; bottom: -2px; width: 1px; background: var(--ink-4); }
.divtrack .fill { position: absolute; top: 0; bottom: 0; border-radius: 2px; }
.divrow .pc { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ============================================================ drawer */
.scrim { position: fixed; inset: 0; background: rgba(12, 20, 15, .38); z-index: 60; opacity: 0; pointer-events: none; transition: opacity .16s; }
.scrim.on { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 94vw);
  background: var(--surface); border-left: 1px solid var(--rule);
  box-shadow: var(--shadow-lg); z-index: 61;
  transform: translateX(100%); transition: transform .2s cubic-bezier(.2,.7,.3,1);
  display: flex; flex-direction: column;
}
.drawer.on { transform: none; }
.drawer > header { padding: 15px 20px 13px; border-bottom: 1px solid var(--rule); display: flex; gap: 14px; align-items: flex-start; }
.drawer > header h3 { font-size: 15.5px; letter-spacing: -.015em; line-height: 1.3; }
.drawer > header .meta { margin-top: 4px; font-size: 11.5px; color: var(--ink-3); display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }
.drawer .close { margin-left: auto; flex: none; width: 28px; height: 28px; border: 1px solid var(--rule); background: transparent; border-radius: 5px; cursor: pointer; font-size: 15px; line-height: 1; color: var(--ink-3); }
.drawer .close:hover { background: var(--bar); }
.drawer .content { padding: 18px 20px 40px; overflow-y: auto; }
.drawer .content h4 { font-size: 11px; letter-spacing: .09em; text-transform: uppercase; color: var(--ink-3); margin: 22px 0 9px; }
.drawer .content h4:first-child { margin-top: 0; }
.prose { font-family: var(--serif); font-size: 14.5px; line-height: 1.62; color: var(--ink-2); max-width: 66ch; }
.prose p { margin: 0 0 .8em; }

/* lista definición */
.dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; font-size: 12.5px; }
.dl dt { color: var(--ink-3); }
.dl dd { margin: 0; font-variant-numeric: tabular-nums; }

/* ============================================================ articulado */
.art-list { display: flex; flex-direction: column; gap: 1px; background: var(--rule-soft); }
.art-item { background: var(--surface); padding: 11px 15px; cursor: pointer; display: flex; gap: 13px; align-items: flex-start; }
.art-item:hover { background: var(--accent-bg); }
.art-item .no { font-family: var(--mono); font-size: 11px; color: var(--ink-3); width: 30px; flex: none; padding-top: 2px; }
.art-item .tx { flex: 1; min-width: 0; }
.art-item .tx p { margin: 0; font-size: 12.5px; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.art-item .fl { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 5px; }
.art-text { font-family: var(--serif); font-size: 14.5px; line-height: 1.65; white-space: pre-wrap; color: var(--ink); }
mark { background: #FFE9A3; color: #3B2E05; border-radius: 2px; padding: 0 1px; }
:root[data-theme="dark"] mark, :root:not([data-theme="light"]) mark { background: #5C4A12; color: #FFEFC2; }
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) mark { background: #FFE9A3; color: #3B2E05; } }

/* ============================================================ hallazgos */
.find { background: var(--surface); border: 1px solid var(--rule); border-radius: 7px; margin-bottom: 11px; overflow: hidden; }
.find > button { display: flex; gap: 13px; width: 100%; padding: 13px 15px; background: transparent; border: 0; text-align: left; cursor: pointer; align-items: flex-start; }
.find > button:hover { background: var(--bar); }
.find h3 { font-size: 14px; letter-spacing: -.012em; margin-bottom: 4px; }
.find .dt { font-size: 12.5px; color: var(--ink-2); line-height: 1.55; max-width: 84ch; }
.find .ev { border-top: 1px solid var(--rule-soft); background: var(--paper); padding: 0; }
.find .ev table { font-size: 12px; }
.find .tags { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }

/* ============================================================ búsqueda */
.hit { background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; padding: 11px 14px; margin-bottom: 8px; cursor: pointer; }
.hit:hover { border-color: var(--accent); }
.hit .hd { display: flex; gap: 9px; align-items: baseline; margin-bottom: 4px; flex-wrap: wrap; }
.hit .hd b { font-size: 12.5px; }
.hit .sn { font-size: 12.5px; color: var(--ink-2); line-height: 1.55; font-family: var(--serif); }
.empty { padding: 44px 20px; text-align: center; color: var(--ink-3); font-size: 13px; }

/* ============================================================ misc */
.note { font-size: 11.5px; color: var(--ink-3); line-height: 1.5; margin-top: 10px; max-width: 80ch; }
.note b { color: var(--ink-2); font-weight: 600; }
.bardot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.treemap { display: flex; flex-wrap: wrap; gap: 2px; }
.treemap a { display: flex; flex-direction: column; justify-content: flex-end; padding: 7px 9px; color: #fff; text-decoration: none; overflow: hidden; border-radius: 2px; min-height: 42px; }
.treemap a .t { font-size: 11px; font-weight: 600; line-height: 1.25; text-shadow: 0 1px 2px rgba(0,0,0,.35); }
.treemap a .v { font-size: 10.5px; opacity: .9; font-variant-numeric: tabular-nums; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  nav.side { position: static; height: auto; flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--rule); }
  nav.side button { width: auto; white-space: nowrap; }
  .side-foot { display: none; }
  .brand { width: auto; }
  main { padding: 16px 14px 60px; }
  .divrow { grid-template-columns: 120px 1fr 62px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
