/* Gastos abiertos de Córdoba — estilo "libro mayor": papel cálido, tinta oscura, dos acentos. */
:root {
  --paper: #f4efe3;
  --paper-2: #ebe4d1;
  --card: #fbf8f0;
  --ink: #14231f;
  --ink-soft: #46564f;
  --line: #cdc4ac;
  --ac: #0b5d63;
  --ac-soft: #bcd9d9;
  --em: #b0471f;
  --em-soft: #efcdbd;
  --gold: #e3b04b;
  --warn-bg: #f6e2ae;
  --focus: #1b4fd8;
  --serif: Charter, "Bitstream Charter", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Segoe UI", "Helvetica Neue", Roboto, "Noto Sans", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background-color: var(--paper);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .08 0 0 0 0 .14 0 0 0 0 .12 0 0 0 .05 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
  color: var(--ink);
  font: 16px/1.55 var(--sans);
}
.wrap { width: min(1280px, 100% - 2rem); margin-inline: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
.masthead :focus-visible, .site-foot :focus-visible { outline-color: var(--gold); }

.skip { position: absolute; left: .5rem; top: -4rem; background: var(--gold); color: var(--ink); padding: .5rem .8rem; z-index: 10; font-weight: 600; }
.skip:focus { top: .5rem; }

/* ---------- Cabecera ---------- */
.masthead {
  background:
    radial-gradient(900px 300px at 85% -20%, rgba(227, 176, 75, .28), transparent 60%),
    radial-gradient(700px 400px at 0% 120%, rgba(11, 93, 99, .55), transparent 65%),
    var(--ink);
  color: #f4efe3;
  padding: 2.4rem 0 1.6rem;
  border-bottom: 6px solid var(--gold);
}
.kicker { margin: 0 0 .4rem; font: 600 .78rem/1 var(--sans); letter-spacing: .16em; text-transform: uppercase; color: var(--gold); }
h1 { margin: 0; font: 700 clamp(2.1rem, 6vw, 4rem)/1.02 var(--serif); letter-spacing: -.02em; }
h1 span { font-style: italic; font-weight: 400; color: var(--gold); }
.lede { max-width: 62ch; margin: .9rem 0 1.4rem; color: #d9d6c8; font-size: 1.05rem; }
.status { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0; margin: 0; border-top: 1px solid rgba(244, 239, 227, .25); }
.status > div { padding: .8rem 1rem .2rem 0; }
.status dt { font: 600 .72rem/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: #aebdb6; }
.status dd { margin: .3rem 0 0; font: 600 1.1rem/1.3 var(--serif); overflow-wrap: anywhere; }
.status a { color: #fff; text-decoration-color: var(--gold); text-underline-offset: 3px; }
.status a:hover { color: var(--gold); }

/* ---------- Avisos ---------- */
.notices { display: grid; gap: .6rem; margin-top: 1.2rem; }
.notice { margin: 0; padding: .7rem 1rem; border-left: 5px solid var(--ac); background: var(--card); font-size: .95rem; box-shadow: 0 1px 0 var(--line); }
.notice--partial { border-left-color: #8a5a00; background: var(--warn-bg); }
.notice--scope { border-left-color: var(--em); }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 1.6rem; margin-top: 1.4rem; align-items: start; }
.layout:focus { outline: none; }
.filters { position: sticky; top: 1rem; background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--ink); padding: 0 1rem 1rem; box-shadow: 6px 6px 0 var(--paper-2); }
.filters summary { display: flex; justify-content: space-between; align-items: center; cursor: pointer; padding: .9rem 0 .6rem; font: 700 1.15rem var(--serif); list-style: none; }
.filters summary::-webkit-details-marker { display: none; }
.filters summary::after { content: none; }
.link-btn { background: none; border: 0; color: var(--ac); font: 600 .85rem var(--sans); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; padding: .3rem; }
.field { margin-bottom: .8rem; }
.field label, legend { display: block; font: 700 .72rem/1.2 var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: .3rem; }
select {
  width: 100%; max-width: 100%; padding: .55rem 2rem .55rem .6rem; font: 500 .92rem var(--sans); color: var(--ink);
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%2314231f' stroke-width='2'/%3E%3C/svg%3E") no-repeat right .7rem center;
  border: 1.5px solid var(--ink); border-radius: 0; appearance: none; text-overflow: ellipsis; min-height: 42px;
}
select:hover { background-color: #fffdf6; }
.hint { margin: .4rem 0 0; font-size: .82rem; color: var(--ink-soft); }

/* Segmentados */
fieldset { border: 0; padding: 0; margin: 0 0 .9rem; min-width: 0; }
.seg { display: flex; flex-wrap: wrap; gap: 0; }
.seg legend { width: 100%; padding: 0; float: left; }
.seg legend + * { clear: both; }
.seg label { position: relative; flex: 1 1 auto; }
.seg input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.seg span { display: block; text-align: center; padding: .55rem .8rem; border: 1.5px solid var(--ink); margin: 0 -1.5px 0 0; font: 600 .9rem var(--sans); background: #fff; cursor: pointer; min-height: 42px; display: flex; align-items: center; justify-content: center; }
.seg input:checked + span { background: var(--ink); color: #fff; }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; position: relative; z-index: 1; }
.seg input:disabled + span { color: #8a928e; background: var(--paper-2); cursor: not-allowed; text-decoration: line-through; }
.seg .hint { width: 100%; }

/* ---------- Contenido ---------- */
.selection { margin: 0 0 .8rem; font: 400 1.05rem/1.4 var(--serif); color: var(--ink-soft); }
.selection b { color: var(--ink); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 0; border: 1.5px solid var(--ink); background: var(--card); margin-bottom: 1.2rem; }
.kpi { padding: .9rem 1rem; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); margin: 0 -1px -1px 0; }
.kpi.is-active { background: var(--ink); color: #f4efe3; }
.kpi.is-active .kpi-sub, .kpi.is-active .kpi-name { color: #c4cec9; }
.kpi-name { font: 700 .72rem/1.1 var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-soft); }
.kpi-val { font: 700 1.4rem/1.2 var(--serif); margin: .3rem 0 .1rem; font-variant-numeric: tabular-nums; }
.kpi-sub { font: 400 .78rem var(--mono); color: var(--ink-soft); overflow-wrap: anywhere; }

.toolbar { display: flex; flex-wrap: wrap; align-items: end; gap: .4rem 1.2rem; margin-bottom: 1rem; }
.toolbar .seg { margin: 0; flex: 0 1 auto; }
.toolbar .hint { margin: 0 0 .5rem; }

/* Pestañas */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 2px solid var(--ink); }
.tabs button { font: 700 .95rem var(--sans); padding: .7rem 1.1rem; background: var(--paper-2); color: var(--ink); border: 1.5px solid var(--line); border-bottom: 0; cursor: pointer; margin-bottom: -2px; min-height: 44px; }
.tabs button:hover { background: #f1ebd9; }
.tabs button[aria-selected="true"] { background: var(--card); border-color: var(--ink); border-bottom: 2px solid var(--card); }
.tabs .tab--off { color: #5c6862; border-style: dashed; }
.tabs .tab--off em { font: 600 .68rem var(--sans); font-style: normal; text-transform: uppercase; letter-spacing: .06em; background: var(--warn-bg); color: #5a3a00; padding: .1rem .4rem; margin-left: .4rem; }
.panel { background: var(--card); border: 1.5px solid var(--ink); border-top: 0; padding: 1.2rem 1.2rem 1.4rem; min-height: 300px; }
.panel-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: end; gap: .6rem 1.4rem; margin-bottom: .6rem; }
.panel h2 { margin: 0; font: 700 1.5rem/1.2 var(--serif); }
.badge { font: 700 .7rem var(--sans); text-transform: uppercase; letter-spacing: .08em; background: var(--warn-bg); padding: .2rem .5rem; vertical-align: middle; margin-left: .4rem; }
.big-note { font: 600 1.15rem/1.45 var(--serif); border-left: 5px solid var(--em); padding-left: 1rem; max-width: 60ch; }
.inline-fields { display: flex; gap: .8rem; flex-wrap: wrap; }
.field--inline { margin: 0; min-width: 150px; }
.check { display: inline-flex; gap: .5rem; align-items: center; font: 600 .9rem var(--sans); text-transform: none; letter-spacing: 0; color: var(--ink); cursor: pointer; min-height: 44px; }
.check input { width: 20px; height: 20px; accent-color: var(--ac); }
.check input:disabled + span { color: #6a746f; }
.foot { margin: 1rem 0 0; font-size: .82rem; color: var(--ink-soft); max-width: 90ch; }

/* ---------- Gráfico anual ---------- */
.chart { display: grid; grid-template-columns: repeat(var(--n, 3), 1fr); gap: clamp(.5rem, 3vw, 2.4rem); align-items: end; height: 340px; padding: 1.8rem .5rem 0; border-bottom: 2px solid var(--ink); margin-top: .6rem;
  background: repeating-linear-gradient(to top, transparent 0, transparent calc(25% - 1px), rgba(20, 35, 31, .12) calc(25% - 1px), rgba(20, 35, 31, .12) 25%); }
.grp { display: flex; align-items: flex-end; justify-content: center; gap: 6px; height: 100%; position: relative; }
.bar-wrap { flex: 0 1 110px; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; }
.bar-val { font: 700 .82rem/1.15 var(--serif); text-align: center; margin-bottom: .25rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.bar { background: var(--ac); min-height: 2px; transform-origin: bottom; animation: grow .8s cubic-bezier(.2, .8, .2, 1) both; border: 1.5px solid var(--ink); border-bottom: 0; }
.bar.t-EMAEE { background: var(--em); }
.bar.is-partial { background-image: repeating-linear-gradient(135deg, rgba(255, 255, 255, .45) 0 6px, transparent 6px 12px); }
.bar.is-sel { box-shadow: 0 0 0 3px var(--gold); }
.grp:nth-child(2) .bar { animation-delay: .1s; }
.grp:nth-child(3) .bar { animation-delay: .2s; }
@keyframes grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
.xlabels { display: grid; grid-template-columns: repeat(var(--n, 3), 1fr); gap: clamp(.5rem, 3vw, 2.4rem); padding: .4rem .5rem 0; }
.xlabels div { text-align: center; font: 700 1rem var(--serif); }
.xlabels small { display: block; font: 400 .75rem var(--sans); color: var(--ink-soft); }
.legend { display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; margin: .8rem 0; font-size: .85rem; }
.legend i { display: inline-block; width: 14px; height: 14px; border: 1.5px solid var(--ink); vertical-align: -2px; margin-right: .35rem; }
.legend .l-ac { background: var(--ac); } .legend .l-em { background: var(--em); }
.legend .l-par { background: #fff repeating-linear-gradient(135deg, rgba(20, 35, 31, .5) 0 3px, transparent 3px 6px); }
.legend .l-sel { background: #fff; box-shadow: 0 0 0 2px var(--gold); }
.empty { padding: 2rem 1rem; text-align: center; font: italic 1.1rem var(--serif); color: var(--ink-soft); }

/* ---------- Tablas ---------- */
.table-scroll { overflow-x: auto; border: 1px solid var(--line); background: #fff; }
.table-scroll:focus-visible { outline-offset: 0; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
caption { text-align: left; padding: .5rem .7rem; font: 600 .85rem var(--sans); color: var(--ink-soft); caption-side: top; }
th, td { padding: .55rem .7rem; text-align: left; border-bottom: 1px solid #e3dcc7; vertical-align: top; }
thead th { background: var(--ink); color: #f4efe3; font: 700 .72rem/1.2 var(--sans); letter-spacing: .06em; text-transform: uppercase; white-space: nowrap; position: sticky; top: 0; }
thead th button { all: unset; cursor: pointer; display: inline-flex; gap: .35rem; align-items: center; }
thead th button:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
thead th .arrow { color: var(--gold); min-width: .8em; }
#detail-table { min-width: 1250px; }
#detail-table td:nth-child(-n+4) { min-width: 11rem; }
#detail-table td:nth-child(3) { min-width: 14rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:nth-child(even) { background: #faf6ea; }
tbody tr:hover { background: #f3ecd6; }
tbody th { font-weight: 600; }
tfoot td, tfoot th { background: var(--paper-2); font-weight: 700; border-top: 2px solid var(--ink); }
td.nd { color: #6a746f; font-style: italic; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: .6rem; margin-top: .8rem; flex-wrap: wrap; }
.pager button { font: 700 .9rem var(--sans); padding: .6rem 1rem; background: #fff; border: 1.5px solid var(--ink); cursor: pointer; min-height: 44px; }
.pager button:hover:not(:disabled) { background: var(--ink); color: #fff; }
.pager button:disabled { opacity: .45; cursor: not-allowed; }
details.datatable { margin-top: .8rem; }
details.datatable summary { cursor: pointer; font-weight: 700; padding: .4rem 0; }

/* Ranking */
.rank td, .rank th { vertical-align: middle; }
.rank .pos { width: 2.5rem; font: 700 1rem var(--serif); color: var(--ink-soft); text-align: right; }
.rank .name { min-width: 14rem; font-weight: 600; }
.rank .name small { display: block; font-weight: 400; color: var(--ink-soft); }
.rank .barcell { width: 32%; min-width: 120px; }
.meter { height: 14px; background: var(--paper-2); border: 1px solid var(--line); }
.meter > i { display: block; height: 100%; background: var(--ac); }
.meter.t-EMAEE > i { background: var(--em); }
.rank-sum { margin: .6rem 0 0; font-size: .9rem; color: var(--ink-soft); }

/* ---------- Pie ---------- */
.site-foot { margin-top: 2.5rem; background: var(--ink); color: #d9d6c8; padding: 1.6rem 0 2.2rem; }
.site-foot h2 { font: 700 1.2rem var(--serif); margin: 0 0 .6rem; color: #fff; }
.site-foot ul { margin: 0 0 1rem; padding-left: 1.2rem; max-width: 80ch; }
.site-foot a { color: var(--gold); }
.small { font-size: .85rem; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .content { min-width: 0; }
  .filters { position: static; }
  .filters summary::after { content: "▾"; font-size: 1rem; }
  .filters details:not([open]) summary::after { content: "▸"; }
  .filters summary .link-btn { margin-left: auto; margin-right: .6rem; }
}
@media (max-width: 560px) {
  .masthead { padding-top: 1.6rem; }
  .chart { height: 280px; padding-top: 2.4rem; }
  .bar-val { font-size: .7rem; }
  .panel { padding: 1rem .7rem 1.2rem; }
  .tabs button { flex: 1 1 45%; padding: .6rem .5rem; font-size: .88rem; }
  .kpi-val { font-size: 1.3rem; }
  .kpi { padding: .8rem .7rem; }
  .kpi-sub { font-size: .66rem; overflow-wrap: normal; white-space: nowrap; }
  .seg--metric span { padding: .5rem .55rem; font-size: .85rem; }
  .bar-wrap { flex-basis: 70px; }
  /* Ranking en móvil: cada fila pasa a una mini ficha (nombre arriba; monto y % abajo) */
  .rank, .rank tbody, .rank tfoot, .rank tr { display: block; }
  .rank thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .rank tbody tr { display: grid; grid-template-columns: 1.8rem 1fr auto; column-gap: .5rem; padding: .55rem .6rem; border-bottom: 1px solid #e3dcc7; }
  .rank tfoot tr { display: grid; grid-template-columns: 1fr auto; padding: .6rem; background: var(--paper-2); border-top: 2px solid var(--ink); }
  .rank th, .rank td { padding: 0; border: 0; background: none; font-size: .88rem; }
  .rank .barcell { display: none; }
  .rank .pos { grid-column: 1; grid-row: 1 / 3; text-align: left; }
  .rank .name { grid-column: 2 / 4; min-width: 0; }
  .rank tbody td.num:nth-of-type(3) { grid-column: 2; grid-row: 2; text-align: left; font-weight: 600; }
  .rank tbody td.num:nth-of-type(4) { grid-column: 3; grid-row: 2; color: var(--ink-soft); }
  .rank tfoot th { grid-column: 1 / -1; margin-bottom: .2rem; }
  .rank tfoot td.num:nth-of-type(1) { grid-column: 1; text-align: left; }
  .rank tfoot td.num:nth-of-type(2) { grid-column: 2; }
  .rank caption { display: block; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .seg--metric label { flex: 1 1 45%; }
}
@media (prefers-reduced-motion: reduce) { .bar { animation: none; } }
@media (forced-colors: active) { .bar { forced-color-adjust: none; } }
