/* =====================================================================
   Apaxco en cifras — estilos del dashboard (sobre Bootstrap 5.3)
   Layout: encabezado institucional → barra de filtros fija → vistas por pestaña;
   tarjetas solo para gráficas y tablas, el resto respira sobre el fondo "cantera".
   ===================================================================== */
:root {
  /* superficies y tinta (neutros con ligero sesgo verde-cantera) */
  --bg: #f1f2ee;
  --surface: #fcfcfb;
  --surface-2: #f6f6f2;
  --ink: #16181a;
  --ink-2: #4a4e52;
  --muted: #7b7f83;
  --line: #e0e1db;
  --line-strong: #c6c8c0;
  /* acento institucional (guinda) y oro, con mesura */
  --accent: #7a1f3d;
  --accent-ink: #ffffff;
  --accent-soft: #f2e5ea;
  --gold: #8a6a22;
  /* series de gráficas: administraciones (slots 1–3 validados) */
  --adm-1: #2a78d6;
  --adm-2: #eb6834;
  --adm-3: #1baf7a;
  /* grupos de obra (slots 1–7 validados, orden fijo) */
  --g-1: #2a78d6; --g-2: #eb6834; --g-3: #1baf7a; --g-4: #eda100;
  --g-5: #e87ba4; --g-6: #008300; --g-7: #6250d6;
  /* rampa secuencial azul y polos divergentes */
  --seq-0: #e8f0fb; --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #6da7ec; --seq-4: #3987e5; --seq-5: #256abf; --seq-6: #184f95; --seq-7: #0d366b;
  --div-up: #2a78d6;
  --div-down: #e34948;
  --div-mid: #f0efec;
  /* ejes y retícula */
  --grid: #e3e3dc;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);
  /* tipografía */
  --font-display: "Archivo", "Arial Narrow", system-ui, sans-serif;
  --font-body: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1010; --surface: #1a1a19; --surface-2: #212120; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #8f8d86;
    --line: #2c2c2a; --line-strong: #3d3d3a; --accent: #e08aa6; --accent-ink: #1a0b10; --accent-soft: #3a1d27; --gold: #d4b26a;
    --adm-1: #3987e5; --adm-2: #d95926; --adm-3: #199e70;
    --g-1: #3987e5; --g-2: #d95926; --g-3: #199e70; --g-4: #c98500; --g-5: #d55181; --g-6: #008300; --g-7: #9085e9;
    --seq-0: #16263a; --seq-1: #1a3150; --seq-2: #184f95; --seq-3: #1c5cab; --seq-4: #2a78d6; --seq-5: #5598e7; --seq-6: #86b6ef; --seq-7: #cde2fb;
    --div-up: #3987e5; --div-down: #e66767; --div-mid: #383835;
    --grid: #2c2c2a; --axis: #383835; --ring: rgba(255, 255, 255, 0.10);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1010; --surface: #1a1a19; --surface-2: #212120; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #8f8d86;
  --line: #2c2c2a; --line-strong: #3d3d3a; --accent: #e08aa6; --accent-ink: #1a0b10; --accent-soft: #3a1d27; --gold: #d4b26a;
  --adm-1: #3987e5; --adm-2: #d95926; --adm-3: #199e70;
  --g-1: #3987e5; --g-2: #d95926; --g-3: #199e70; --g-4: #c98500; --g-5: #d55181; --g-6: #008300; --g-7: #9085e9;
  --seq-0: #16263a; --seq-1: #1a3150; --seq-2: #184f95; --seq-3: #1c5cab; --seq-4: #2a78d6; --seq-5: #5598e7; --seq-6: #86b6ef; --seq-7: #cde2fb;
  --div-up: #3987e5; --div-down: #e66767; --div-mid: #383835;
  --grid: #2c2c2a; --axis: #383835; --ring: rgba(255, 255, 255, 0.10);
  color-scheme: dark;
}

/* ---------- Bootstrap atado a los tokens ---------- */
:root, [data-bs-theme] {
  --bs-body-bg: var(--bg); --bs-body-color: var(--ink); --bs-body-font-family: var(--font-body);
  --bs-border-color: var(--line); --bs-secondary-color: var(--muted); --bs-emphasis-color: var(--ink);
  --bs-tertiary-bg: var(--surface-2); --bs-secondary-bg: var(--surface-2);
  --bs-link-color: var(--accent); --bs-link-hover-color: var(--accent); --bs-link-color-rgb: 122, 31, 61;
  --bs-focus-ring-color: color-mix(in srgb, var(--accent) 35%, transparent);
}
html { background: var(--bg); }
body { background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 15px; line-height: 1.5; }
.form-control, .form-select { background-color: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.form-control::placeholder { color: var(--muted); }
.form-control:focus, .form-select:focus { background-color: var(--surface); color: var(--ink); border-color: var(--accent); box-shadow: 0 0 0 .2rem var(--bs-focus-ring-color); }
.form-check-input { background-color: var(--surface); border-color: var(--line-strong); }
.form-check-input:checked { background-color: var(--accent); border-color: var(--accent); }
.form-select { --bs-form-select-bg-img: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%237b7f83' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e"); }
.table { --bs-table-bg: transparent; --bs-table-color: var(--ink); --bs-table-border-color: var(--line); --bs-table-hover-bg: var(--surface-2); --bs-table-hover-color: var(--ink); --bs-table-striped-bg: var(--surface-2); --bs-table-striped-color: var(--ink); margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .45rem .6rem; }
.table thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; white-space: nowrap; border-bottom-color: var(--line-strong); }
.btn { font-weight: 500; }
.text-secondary { color: var(--muted) !important; }
.btn-ghost { color: var(--ink-2); border: 1px solid var(--line-strong); background: var(--surface); }
.btn-ghost:hover, .btn-ghost:focus-visible { background: var(--surface-2); color: var(--ink); border-color: var(--ink-2); }
.btn-accent { background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent); }
.btn-accent:hover { filter: brightness(1.08); color: var(--accent-ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- estructura ---------- */
.wrap { max-width: 1320px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.masthead { background: var(--surface); border-bottom: 1px solid var(--line); }
.masthead .wrap { padding-block: 22px 0; display: grid; gap: 14px; }
.masthead-top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; }
.eyebrow { font-family: var(--font-mono); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.brand-title { font-family: var(--font-display); font-weight: 800; font-stretch: 85%; font-size: clamp(1.9rem, 1.4rem + 2vw, 2.7rem); line-height: 1; letter-spacing: -.01em; margin: 4px 0 6px; text-wrap: balance; }
.brand-title span { color: var(--accent); }
.brand-sub { color: var(--ink-2); margin: 0; max-width: 62ch; }
.masthead-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.source-pill { font-family: var(--font-mono); font-size: .72rem; color: var(--ink-2); border: 1px solid var(--line-strong); border-radius: 999px; padding: 4px 10px; background: var(--surface-2); white-space: nowrap; }
.source-pill b { color: var(--ink); font-weight: 600; }

.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: thin; margin-bottom: -1px; }
.tabs a { font-family: var(--font-display); font-weight: 600; font-stretch: 92%; font-size: .98rem; color: var(--ink-2); text-decoration: none; padding: 10px 14px 11px; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }

body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 30; background: var(--surface); }
.filterbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.filterbar .wrap { padding-block: 10px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; }
.filter-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; }
.year-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2); border-radius: 999px; padding: 3px 10px 3px 8px; font-size: .85rem; font-variant-numeric: tabular-nums; cursor: pointer; user-select: none; line-height: 1.4; }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c, var(--muted)); box-shadow: 0 0 0 2px var(--surface); }
.chip[aria-pressed="true"] { border-color: var(--ink-2); color: var(--ink); background: var(--surface); font-weight: 600; }
.chip[aria-pressed="false"] { opacity: .55; text-decoration: line-through; text-decoration-color: var(--muted); }
.chip small { font-weight: 500; color: var(--muted); }
.toggles { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.toggles .form-check { margin: 0; font-size: .86rem; color: var(--ink-2); }

main.wrap { padding-block: 22px 56px; }
.view { display: grid; gap: 22px; }
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 16px; }
.section-head h2 { font-family: var(--font-display); font-weight: 700; font-stretch: 90%; font-size: 1.45rem; margin: 0; text-wrap: balance; }
.section-head p { margin: 0; color: var(--ink-2); max-width: 70ch; }
.grid-2 { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); }
.grid-3 { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr)); }
.minw0 { min-width: 0; }
.justify-self-start { justify-self: start; }

/* ---------- línea de administraciones ---------- */
.admins { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.admin { border-top: 3px solid var(--c); padding-top: 10px; display: grid; gap: 6px; align-content: start; }
.admin-years { font-family: var(--font-display); font-weight: 700; font-stretch: 88%; font-size: 1.15rem; }
.admin-pres { color: var(--ink-2); font-size: .9rem; }
.informes-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.inf { font-size: .8rem; border: 1px solid var(--line-strong); border-radius: 6px; padding: 2px 8px; background: var(--surface); color: var(--ink); font-variant-numeric: tabular-nums; }
.inf.missing { border-style: dashed; color: var(--muted); background: transparent; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: .7rem; font-weight: 600; letter-spacing: .03em; border-radius: 4px; padding: 1px 6px; vertical-align: middle; white-space: nowrap; }
.tag-trienio { background: var(--accent-soft); color: var(--accent); }
.tag-prelim { background: color-mix(in srgb, var(--gold) 16%, transparent); color: var(--gold); }
.tag-ver { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }

/* ---------- tarjetas de gráfica ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 16px 14px; display: grid; gap: 10px; min-width: 0; }
.panel-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 10px; }
.panel-head > .minw0, .panel-head > div:first-child { flex: 1 1 220px; min-width: 0; }
.panel-title { font-family: var(--font-display); font-weight: 700; font-stretch: 92%; font-size: 1.05rem; margin: 0; line-height: 1.25; }
.panel-sub { color: var(--muted); font-size: .83rem; margin: 2px 0 0; }
.panel-note { color: var(--muted); font-size: .78rem; margin: 0; }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line-strong); border-radius: 7px; overflow: hidden; flex: none; max-width: 100%; }
.seg button { border: 0; background: var(--surface); color: var(--ink-2); font-size: .76rem; padding: 3px 9px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.chart { width: 100%; min-height: 120px; }
.table-scroll { background: var(--surface); overflow-x: auto; max-height: 520px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.table-scroll thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.legend-inline { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .8rem; color: var(--ink-2); }
.legend-inline i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; background: var(--c); margin-right: 5px; vertical-align: -1px; }

/* ---------- ficha comparativa ---------- */
.ficha th:first-child, .ficha td:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; }
.ficha td:first-child { color: var(--ink-2); font-size: .86rem; min-width: 170px; }
.ficha td.txt { font-size: .82rem; text-align: right; min-width: 120px; line-height: 1.3; }
.ficha th.num, .ficha td.num { min-width: 96px; }
.ficha .yh { font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; color: var(--ink); text-transform: none; letter-spacing: 0; }
.ficha .yh .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--c); margin-right: 6px; }
.big { font-family: var(--font-display); font-weight: 700; font-size: 1.12rem; }

/* ---------- destacados ---------- */
.highlights { display: grid; gap: 0; }
.hl { display: grid; grid-template-columns: 6.6rem 1fr; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.hl:first-child { border-top: 0; }
.hl-tema { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding-top: 2px; }
.hl p { margin: 0; }
.ref { font-family: var(--font-mono); font-size: .72rem; color: var(--muted); white-space: nowrap; }

/* ---------- avance por indicador ---------- */
.ind-layout { display: grid; gap: 18px; grid-template-columns: 240px minmax(0, 1fr); align-items: start; }
.tema-list { display: grid; gap: 2px; position: sticky; top: calc(env(safe-area-inset-top, 0px) + 70px); max-height: calc(100vh - 90px); overflow-y: auto; }
.tema-list button { display: flex; justify-content: space-between; gap: 8px; text-align: left; border: 0; background: transparent; color: var(--ink-2); padding: 6px 10px; border-radius: 6px; font-size: .88rem; }
.tema-list button:hover { background: var(--surface-2); color: var(--ink); }
.tema-list button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tema-list .n { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .8rem; }
.ind-tools { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin-bottom: 12px; }
.ind-tools .form-control { max-width: 340px; }
.mini { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 12px 10px; display: grid; gap: 6px; min-width: 0; align-content: start; }
.mini h3 { font-size: .92rem; font-weight: 600; margin: 0; line-height: 1.3; }
.mini .unit { color: var(--muted); font-size: .76rem; }
.mini .chart { height: 132px; min-height: 132px; }
.vals { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; font-size: .74rem; font-variant-numeric: tabular-nums; border-top: 1px solid var(--line); padding-top: 6px; }
.vals div { display: grid; text-align: center; }
.vals span:first-child { color: var(--muted); }
.vals b { font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; }
.delta { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; font-size: .8rem; color: var(--ink-2); flex-wrap: wrap; }
.delta b { color: var(--ink); font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); padding: 28px; text-align: center; border: 1px dashed var(--line-strong); border-radius: var(--radius); }

/* ---------- KPI de obras ---------- */
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
.kpi { border-left: 1px solid var(--line-strong); padding: 2px 0 2px 14px; }
.kpi .v { font-family: var(--font-display); font-weight: 800; font-stretch: 90%; font-size: 1.9rem; line-height: 1.1; }
.kpi .l { color: var(--ink-2); font-size: .85rem; }

.callout { border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface-2); padding: 12px 14px; font-size: .9rem; color: var(--ink-2); }
.callout strong { color: var(--ink); }
.loading { padding: 60px 0; text-align: center; color: var(--muted); }
.notes { margin: 0; padding-left: 1.1rem; color: var(--ink-2); display: grid; gap: 6px; max-width: 95ch; }

@media (max-width: 900px) {
  .ind-layout { grid-template-columns: 1fr; }
  .tema-list { position: static; max-height: none; display: flex; flex-wrap: wrap; gap: 4px; }
  .tema-list button { border: 1px solid var(--line); background: var(--surface); }
}
@media (max-width: 520px) {
  body { font-size: 14px; }
  .hl { grid-template-columns: 1fr; gap: 2px; }
  .filterbar { position: static; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
