  :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;
    --diff-pos: #1E7F4F; --diff-neg: #B23A3A;
    --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;
  }
  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;
    --diff-pos: #4CBE83; --diff-neg: #E89595;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  }
  * { 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; }

  .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; }
  .btn { font-family: var(--sans); font-size: 0.85rem; font-weight: 600; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
  .btn:hover { background: var(--surface-2); }
  .btn:focus-visible, select:focus-visible, input:focus-visible, .icon-btn:focus-visible, .nav-link:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
  .btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
  .btn-primary:hover { background: var(--primary-dark); }
  .btn-sm { padding: 6px 10px; font-size: 0.78rem; }
  .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); }

  .container { max-width: 1180px; margin: 0 auto; padding: 28px 24px 80px; }
  .page-intro { max-width: 720px; margin-bottom: 18px; }
  .page-intro h1 { font-family: var(--serif); font-weight: 600; font-size: 1.6rem; margin: 0 0 8px; }
  .page-intro p { color: var(--text-muted); margin: 0; font-size: 0.93rem; }

  .data-banner { margin-bottom: 26px; }
  .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); }

  .section { margin-bottom: 34px; }
  .section-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; border-bottom: 1px solid var(--border); padding-bottom: 8px; flex-wrap: wrap; }
  .section-num { font-family: var(--serif); color: var(--accent-text); font-size: 0.85rem; font-weight: 600; }
  .section-head h2 { font-family: var(--serif); font-weight: 600; font-size: 1.15rem; margin: 0; }
  .section-head .section-note { margin-left: auto; font-size: 0.8rem; color: var(--text-muted); }

  .scenario-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; }
  .scenario-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
  .scenario-card__head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
  .scenario-card__title { font-family: var(--serif); font-weight: 600; font-size: 0.95rem; }
  .scenario-card__remove { border: none; background: transparent; color: var(--text-muted); font-size: 0.9rem; cursor: pointer; width: 26px; height: 26px; border-radius: 6px; }
  .scenario-card__remove:hover { background: var(--surface-2); color: var(--diff-neg); }
  .scenario-card__body { padding: 14px 16px 18px; }

  .add-scenario-row { display: flex; justify-content: center; margin-top: 16px; }

  .field { margin-bottom: 13px; }
  .field-label-row { display: flex; align-items: center; gap: 6px; margin-bottom: 5px; }
  .field-label { font-size: 0.81rem; font-weight: 600; color: var(--text); }
  select, input[type="number"] {
    width: 100%; font-family: var(--sans); font-size: 0.9rem; color: var(--text);
    background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: 8px 9px; appearance: none;
  }
  select { 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='%235D6864' stroke-width='1.6' fill='none' fill-rule='evenodd'/></svg>"); background-repeat: no-repeat; background-position: right 9px center; padding-right: 28px; }
  .field-readonly { font-size: 0.9rem; padding: 8px 9px; border-radius: 7px; background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }
  .info-btn { width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-muted); font-size: 0.65rem; font-weight: 700; cursor: pointer; line-height: 1; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
  .info-btn:hover { background: var(--primary-tint); color: var(--primary); border-color: var(--primary); }
  .info-text { display: none; font-size: 0.76rem; color: var(--text-muted); background: var(--surface-2); border-left: 3px solid var(--primary); border-radius: 0 6px 6px 0; padding: 7px 9px; margin: -4px 0 10px; }
  .info-text.open { display: block; }
  .info-text .anexo { color: var(--accent-text); font-weight: 600; }

  .toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  .switch { position: relative; width: 38px; height: 21px; flex-shrink: 0; }
  .switch input { opacity: 0; width: 0; height: 0; }
  .switch-track { position: absolute; inset: 0; background: var(--border); border-radius: 999px; cursor: pointer; transition: background 0.15s ease; }
  .switch-track::before { content: ""; position: absolute; width: 15px; height: 15px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform 0.15s ease; box-shadow: 0 1px 2px rgba(0,0,0,0.25); }
  .switch input:checked + .switch-track { background: var(--primary); }
  .switch input:checked + .switch-track::before { transform: translateX(17px); }
  .subfield { margin-top: 9px; padding-top: 9px; border-top: 1px dashed var(--border); }

  .breakdown-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
  table.breakdown { width: 100%; border-collapse: collapse; font-size: 0.86rem; min-width: 480px; }
  table.breakdown th, table.breakdown td { padding: 9px 13px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
  table.breakdown th:first-child, table.breakdown td:first-child { text-align: left; white-space: normal; }
  table.breakdown thead th { font-size: 0.74rem; color: var(--text-muted); font-weight: 600; background: var(--surface-2); }
  table.breakdown tbody tr:last-child td { border-bottom: none; }
  table.breakdown tfoot td { font-weight: 700; border-top: 2px solid var(--border); background: var(--surface-2); }
  .th-scenario { display: flex; align-items: center; gap: 6px; justify-content: flex-end; }
  .th-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

  .results-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 12px; }
  .result-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
  .result-card__label { font-size: 0.76rem; color: var(--text-muted); font-weight: 600; margin-bottom: 5px; display: flex; align-items: center; gap: 6px; }
  .result-card__value { font-family: var(--serif); font-size: 1.35rem; font-weight: 600; font-variant-numeric: tabular-nums; }

  .annual-banner { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1px; background: var(--border); border-radius: var(--radius); overflow: hidden; margin-top: 6px; box-shadow: var(--shadow); }
  .annual-banner__cell { background: var(--primary); color: #fff; padding: 16px 18px; }
  .annual-banner__label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.03em; opacity: 0.88; margin-bottom: 5px; display: flex; align-items: center; gap: 6px; }
  .annual-banner__value { font-family: var(--serif); font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
  .annual-banner__cell--diff { background: var(--primary-dark); }

  .chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; }
  .chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
  .chart-card h3 { font-family: var(--serif); font-size: 0.9rem; margin: 0 0 8px; font-weight: 600; }
  .chart-empty { color: var(--text-muted); font-size: 0.82rem; text-align: center; padding: 30px 0; }
  .chart-canvas-wrap { position: relative; height: 210px; }

  .net-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 14px; }
  @media (max-width: 640px) { .net-controls { grid-template-columns: 1fr; } }
  .slider-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 13px 15px; box-shadow: var(--shadow); }
  .slider-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 7px; }
  .slider-head label { font-size: 0.83rem; font-weight: 600; }
  .slider-value { font-family: var(--serif); font-weight: 700; color: var(--primary); font-size: 0.92rem; }
  input[type="range"] { width: 100%; height: 24px; accent-color: var(--primary); }

  .reset-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; background: var(--primary-tint); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; }
  .reset-row p { margin: 0; font-size: 0.85rem; color: var(--text-muted); }
  .reset-row strong { color: var(--text); }
  .reset-row .actions { display: flex; gap: 10px; flex-wrap: wrap; }

  .badge-required { color: var(--diff-neg); font-size: 0.75rem; margin-left: 4px; }

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

  #printArea { display: none; }
  @media print {
    body > *:not(#printArea) { display: none !important; }
    #printArea { display: block !important; font-family: var(--sans); color: #111; }
    #printArea h1 { font-family: var(--serif); font-size: 1.4rem; margin: 0 0 2px; }
    #printArea .print-meta { font-size: 0.8rem; color: #555; margin-bottom: 18px; }
    #printArea table { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin-bottom: 18px; }
    #printArea th, #printArea td { border: 1px solid #ccc; padding: 6px 9px; text-align: right; }
    #printArea th:first-child, #printArea td:first-child { text-align: left; }
    #printArea .print-annual { font-weight: 700; background: #f0f0f0; }
    #printArea .print-disclaimer { font-size: 0.72rem; color: #666; margin-top: 24px; border-top: 1px solid #ccc; padding-top: 10px; }
  }

  /* 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; }
  }

  /* 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; }

/* Colores de escenario con contraste suficiente (WCAG AA) para texto y fondos */
:root { --sc-fg-0: #3d4178; --sc-bg-0: #3d4178; --sc-fg-1: #a94e3b; --sc-bg-1: #a94e3b; --sc-fg-2: #5666a9; --sc-bg-2: #5666a9; --sc-fg-3: #825d8d; --sc-bg-3: #825d8d; --sc-fg-4: #397269; --sc-bg-4: #397269; }
html[data-theme="dark"] { --sc-fg-0: #a3a7e6; --sc-bg-0: #a3a7e6; --sc-fg-1: #F08468; --sc-bg-1: #F08468; --sc-fg-2: #8C9DE8; --sc-bg-2: #8C9DE8; --sc-fg-3: #C29AD0; --sc-bg-3: #C29AD0; --sc-fg-4: #6FC3B5; --sc-bg-4: #6FC3B5; }

/* Avisos de la calculadora */
.field-warning { margin-top: 8px; padding: 8px 10px; border-radius: 8px; font-size: 0.82rem; line-height: 1.45; background: var(--accent-tint, #fbe9e4); color: var(--text); border: 1px solid var(--border); }
select:disabled { opacity: 0.7; cursor: not-allowed; }
.scenario-card__body > .field-warning:first-child { margin: 0 0 16px; }

/* Reserva el espacio de las tarjetas de escenario mientras se generan (evita desplazamientos, CLS) */
.scenario-grid:empty { min-height: 926px; }
@media (min-width: 700px) { .scenario-grid:empty { min-height: 454px; } }
