  :root {
    --bg: #F3F4FA; --surface: #FFFFFF; --surface-2: #E8EAF3;
    --text: #2B2E52; --text-muted: #62658A; --border: #D7DAEA;
    --primary: #3D4178; --primary-dark: #2B2E52; --primary-tint: #E8EAF3;
    --accent: #E2694F; --accent-dark: #C8543C; --accent-tint: #FBE7E1; --accent-text: #B3442A;
    --shadow: 0 1px 2px rgba(20, 30, 27, 0.06);
    --radius: 10px;
    --serif: 'Inter Tight', -apple-system, BlinkMacSystemFont, sans-serif;
    --sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    /* Estados de ocupación */
    --c-od: #3D4178; --c-op: #9398D6; --c-ot: #E0A93B; --c-vac: #E2694F;
    /* Variantes para texto con contraste AA */
    --c-ot-text: #93650F; --c-vac-text: #C0492F;
  }
  html[data-theme="dark"] {
    --bg: #23253F; --surface: #2E3050; --surface-2: #383A5E;
    --text: #EDEEF9; --text-muted: #B3B6D6; --border: #454877;
    --primary: #A0A5DD; --primary-dark: #A6AAE0; --primary-tint: #282A4D;
    --accent: #F08468; --accent-dark: #F6A088; --accent-tint: #2E2036; --accent-text: #F08468;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    --c-od: #A6AAE0; --c-op: #5B609E; --c-ot: #E8B75A; --c-vac: #F08468;
    --c-ot-text: #E8B75A; --c-vac-text: #F6A088;
  }
  * { box-sizing: border-box; }
  html, body { margin: 0; padding: 0; }
  body { font-family: var(--sans); background: var(--bg); color: var(--text); line-height: 1.5; -webkit-font-smoothing: antialiased; }
  a { color: var(--primary); }
  .skip-link { position: absolute; left: -9999px; top: 0; background: var(--primary); color: #fff; padding: 10px 16px; z-index: 200; border-radius: 0 0 8px 0; }
  .skip-link:focus { left: 0; }
  .tabular { font-variant-numeric: tabular-nums; }
  .visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

  /* ---------- Barra superior (igual que el resto del sitio) ---------- */
  .topbar { position: sticky; top: 0; z-index: 60; display: flex; align-items: center; justify-content: space-between; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; row-gap: 8px; }
  .brand { display: flex; align-items: baseline; gap: 10px; }
  .brand-mark { font-family: var(--serif); font-weight: 700; font-size: 1.02rem; color: var(--primary); }
  .brand-sub { font-size: 0.76rem; color: var(--text-muted); }
  @media (max-width: 640px) { .brand-sub { display: none; } }
  .nav-tools { display: flex; align-items: center; gap: 6px; }
  .nav-link { font-family: var(--sans); font-size: 0.85rem; font-weight: 600; padding: 8px 13px; border-radius: 8px; text-decoration: none; color: var(--text-muted); border: 1px solid transparent; }
  .nav-link:hover { background: var(--surface-2); }
  .nav-link.is-active { color: var(--primary); background: var(--primary-tint); border-color: var(--border); }
  .topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: 6px; }
  .icon-btn { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 1rem; }
  .icon-btn:hover { background: var(--surface-2); }
  .btn:focus-visible, select:focus-visible, input:focus-visible, .icon-btn:focus-visible, .nav-link:focus-visible, .seg button:focus-visible, .chip:focus-visible, .chart-box [tabindex]:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
  /* Menú en móvil: se desplaza en horizontal en lugar de salirse de la pantalla */
  @media (max-width: 760px) {
    .topbar > div:last-child { width: 100%; min-width: 0; }
    .nav-tools { flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
    .nav-tools::-webkit-scrollbar { display: none; }
    .nav-link { white-space: nowrap; }
  }

  /* ---------- Cabecera de página ---------- */
  .hero { padding: 40px 24px 8px; max-width: 1180px; margin: 0 auto; display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
  .hero h1 { font-family: var(--serif); font-weight: 600; font-size: 2rem; margin: 0 0 10px; letter-spacing: -0.01em; line-height: 1.2; }
  .hero p { color: var(--text-muted); max-width: 680px; margin: 0 0 4px; font-size: 0.97rem; }
  .seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 4px; gap: 2px; }
  .seg button { font-family: var(--sans); font-size: 0.85rem; font-weight: 600; padding: 8px 15px; border-radius: 999px; border: none; background: transparent; color: var(--text-muted); cursor: pointer; white-space: nowrap; }
  .seg button[aria-pressed="true"] { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }
  .seg button:disabled { opacity: .45; cursor: not-allowed; }
  .seg.seg-sm button { font-size: 0.78rem; padding: 6px 11px; }
  .seg .sm { display: none; }
  @media (max-width: 560px) {
    .hero .seg { width: 100%; } .hero .seg button { flex: 1; padding: 8px 6px; }
    .seg .lg { display: none; } .seg .sm { display: inline; }
   
    .hero h1 { font-size: 1.6rem; }
  }

  .data-banner { max-width: 1180px; margin: 14px auto 0; padding: 0 24px; }
  .data-banner-inner { display: flex; align-items: center; gap: 10px; background: var(--accent-tint); border: 1px solid var(--border); border-radius: 8px; padding: 9px 14px; font-size: 0.8rem; color: var(--text); flex-wrap: wrap; }
  .data-banner-inner strong { color: var(--accent-text); }

  .container { max-width: 1180px; margin: 0 auto; padding: 22px 24px 60px; }

  /* ---------- Filtros ---------- */
  .filters { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
  .filters-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 14px; }
  .filters-grid > div { min-width: 0; }
  @media (max-width: 560px) { .filters-grid { grid-template-columns: 1fr 1fr; } .filters-grid > div:nth-child(-n+4), .filters-grid > div[data-only="lab"] { grid-column: span 2; } }
  .field-label { display: block; font-size: 0.78rem; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
  select { width: 100%; font-family: var(--sans); font-size: 0.92rem; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: 9px 30px 9px 10px; appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='9'><path d='M1 1l6 6 6-6' stroke='%236C6F92' stroke-width='1.6' fill='none'/></svg>"); background-repeat: no-repeat; background-position: right 10px center; }
  select:disabled { opacity: .5; cursor: not-allowed; }
  .field-hint { font-size: 0.72rem; color: var(--text-muted); margin-top: 4px; }
  .chips-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border); }
  .chips-row .field-label { margin: 0 4px 0 0; }
  .chip { font-family: var(--serif); font-size: 0.8rem; font-weight: 600; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); cursor: pointer; }
  .chip:hover { border-color: var(--primary); color: var(--primary); }
  .chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; }
  html[data-theme="dark"] .chip[aria-pressed="true"] { color: #14152A; }
  .filters-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 14px; }
  .summary { font-size: 0.86rem; color: var(--text-muted); margin: 0; }
  .summary strong { color: var(--text); }
  .btn { font-family: var(--sans); font-size: 0.85rem; font-weight: 600; padding: 9px 15px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
  .btn:hover { background: var(--surface-2); }
  .btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
  .btn-primary:hover { background: var(--primary-dark); }
  html[data-theme="dark"] .btn-primary { color: #14152A; }
  .btn-sm { font-size: 0.76rem; padding: 6px 10px; border-radius: 7px; }

  /* ---------- KPIs ---------- */
  .kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-top: 18px; }
  @media (max-width: 1000px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
  @media (max-width: 560px) { .kpis { grid-template-columns: 1fr; } }
  .kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
  .kpi h2 { font-family: var(--sans); font-size: 0.8rem; font-weight: 600; color: var(--text-muted); margin: 0; }
  .kpi .val { font-family: var(--serif); font-size: 1.9rem; font-weight: 600; letter-spacing: -0.02em; margin: 6px 0 2px; font-variant-numeric: tabular-nums; line-height: 1.15; }
  .kpi .val.name { font-size: 1.1rem; line-height: 1.3; }
  .kpi .sub { font-size: 0.8rem; color: var(--text-muted); margin: 0; font-variant-numeric: tabular-nums; }
  .kpi .note { font-size: 0.72rem; color: var(--text-muted); margin: 10px 0 0; }
  .distbar { display: flex; height: 8px; border-radius: 999px; overflow: hidden; background: var(--surface-2); margin-top: 12px; }
  .distlegend { list-style: none; padding: 0; margin: 10px 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: 3px 12px; font-size: 0.74rem; color: var(--text-muted); }
  .distlegend li { display: flex; align-items: center; gap: 6px; }
  .distlegend .dot { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }
  .distlegend .pct { margin-left: auto; color: var(--text); font-variant-numeric: tabular-nums; }

  /* ---------- Tarjetas de gráfico ---------- */
  .charts { display: grid; grid-template-columns: repeat(12, 1fr); gap: 14px; margin-top: 14px; }
  .card { grid-column: span 12; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; min-width: 0; }
  .card.span-7 { grid-column: span 7; } .card.span-5 { grid-column: span 5; }
  @media (max-width: 1000px) { .card.span-7, .card.span-5 { grid-column: span 12; } }
  .card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
  .card-head h2 { font-family: var(--serif); font-size: 1.08rem; font-weight: 600; margin: 0; }
  .card-head p { font-size: 0.8rem; color: var(--text-muted); margin: 3px 0 0; max-width: 560px; }
  .card-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
  .card-tools select { width: auto; font-size: 0.78rem; padding: 6px 28px 6px 9px; }
  .chart-box { position: relative; margin-top: 12px; min-height: 120px; }
  .chart-box svg { display: block; width: 100%; height: auto; overflow: visible; }
  .chart-note { font-size: 0.74rem; color: var(--text-muted); margin: 8px 0 0; }
  .crumbs { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; margin-top: 10px; min-height: 26px; }
  .crumbs button { font-family: var(--sans); font-size: 0.8rem; font-weight: 600; border: none; background: none; color: var(--primary); cursor: pointer; padding: 3px 0; }
  .crumbs span { color: var(--text-muted); }
  .grad-legend { display: flex; align-items: center; gap: 8px; font-size: 0.74rem; color: var(--text-muted); margin-top: 8px; }
  .grad-legend .bar { height: 8px; width: 180px; max-width: 45%; border-radius: 999px; }
  .skeleton { height: 280px; border-radius: 8px; background: linear-gradient(90deg, var(--surface-2) 0%, var(--bg) 50%, var(--surface-2) 100%); background-size: 200% 100%; animation: sk 1.4s ease-in-out infinite; }
  @keyframes sk { from { background-position: 200% 0; } to { background-position: -200% 0; } }
  @media (prefers-reduced-motion: reduce) { .skeleton, .loading-spinner { animation: none; } }

  .table-wrap { margin-top: 12px; overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
  table.data-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
  table.data-table caption { text-align: left; font-size: 0.76rem; color: var(--text-muted); padding: 8px 12px; }
  table.data-table th, table.data-table td { padding: 7px 12px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
  table.data-table thead th { background: var(--surface-2); color: var(--text-muted); font-weight: 600; font-size: 0.74rem; }
  table.data-table th:first-child, table.data-table td:first-child { text-align: left; }
  table.data-table tbody th { font-weight: 600; }
  table.data-table tbody tr:last-child > * { border-bottom: none; }

  .tip { position: fixed; z-index: 400; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.16); padding: 9px 11px; font-size: 0.78rem; min-width: 190px; max-width: 280px; display: none; }
  .tip .t { font-weight: 600; margin-bottom: 5px; font-family: var(--serif); }
  .tip .r { display: flex; justify-content: space-between; gap: 12px; align-items: center; font-variant-numeric: tabular-nums; }
  .tip .r .k { display: flex; align-items: center; gap: 6px; }
  .tip .r .dot { width: 8px; height: 8px; border-radius: 2px; }
  .tip .tot { border-top: 1px solid var(--border); margin-top: 5px; padding-top: 5px; }
  .tip .hint { color: var(--text-muted); font-size: 0.72rem; margin-top: 5px; }

  .export-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; box-shadow: var(--shadow); }
  .export-row p { margin: 0; font-size: 0.86rem; }
  .explain { margin-top: 22px; font-size: 0.8rem; color: var(--text-muted); max-width: 820px; }
  .explain dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 8px 0 0; }
  .explain dt { font-weight: 600; color: var(--text); }
  .explain dd { margin: 0; }
  .notice { margin-top: 14px; padding: 12px 16px; border-radius: 8px; background: var(--accent-tint); border: 1px solid var(--border); font-size: 0.84rem; }

  footer { border-top: 1px solid var(--border); padding: 22px 24px 40px; margin-top: 20px; }
  footer .container { padding: 0; max-width: 1180px; margin: 0 auto; }
  footer p { font-size: 0.78rem; color: var(--text-muted); max-width: 800px; margin: 0 0 8px; }

  .loading-overlay { position: fixed; inset: 0; z-index: 500; background: var(--bg); display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 14px; transition: opacity 0.25s ease; }
  .loading-overlay.hidden { opacity: 0; pointer-events: none; }
  .loading-spinner { width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--primary); animation: spin 0.8s linear infinite; }
  @keyframes spin { to { transform: rotate(360deg); } }
  .loading-text { font-family: var(--sans); font-size: 0.9rem; color: var(--text-muted); }
  .loading-text strong { color: var(--primary); font-family: var(--serif); }
  .loading-error { max-width: 560px; margin: 0 16px; padding: 24px 28px; background: #FFFBEB; border: 1px solid #F5C97A; border-radius: 12px; font-family: var(--sans); color: #1B2422; text-align: left; }
  [hidden] { display: none !important; }

  /* Accesibilidad: contraste AA de textos sobre el color primario en modo oscuro */
  html[data-theme="dark"] .btn-primary, html[data-theme="dark"] .btn-fill, html[data-theme="dark"] .annual-banner__cell,
  html[data-theme="dark"] .category-tab.is-active, html[data-theme="dark"] .skip-link, html[data-theme="dark"] .chip[aria-pressed="true"] { color: #14152A; }
