* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.topbar {
  background: var(--brand); color: var(--brand-ink); padding: .85rem 1.25rem;
  display: flex; align-items: center; gap: .7rem;
}
.logo {
  width: 30px; height: 30px; border-radius: 7px; background: rgba(255,255,255,.16);
  display: grid; place-items: center; font-size: 1.1rem;
}
.topbar h1 { font-size: 1.05rem; font-weight: 650; margin: 0; letter-spacing: .2px; }
.topbar .spacer { flex: 1; }
.topbar a { color: rgba(255,255,255,.85); text-decoration: none; font-size: .85rem; font-weight: 500; }
.topbar a:hover { color: #fff; text-decoration: underline; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.layout { display: grid; grid-template-columns: 1.05fr .95fr; gap: 1.25rem; align-items: start; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.panel .body { padding: 1.35rem 1.4rem; }
.panel-title { font-size: .78rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--faint); margin: 0 0 .1rem; }

.section + .section { margin-top: 1.4rem; padding-top: 1.3rem; border-top: 1px solid var(--line); }
.section h3 { font-size: .95rem; margin: 0 0 .9rem; color: var(--ink); }

label { display: block; font-weight: 600; font-size: .82rem; color: var(--muted); margin-bottom: .3rem; }
.field { margin-bottom: .95rem; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
select, .inp input, .inp textarea {
  width: 100%; padding: .6rem .7rem; font-size: .98rem; color: var(--ink);
  background: var(--field); border: 1px solid var(--line-strong); border-radius: 9px;
  appearance: none;
}
select:focus, .inp input:focus, .inp textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.inp { position: relative; }
.inp.pre input { padding-left: 1.5rem; }
.inp.post input { padding-right: 2.4rem; }
.inp .adorn { position: absolute; top: 50%; transform: translateY(-50%); color: var(--faint); font-size: .92rem; pointer-events: none; }
.inp.pre .adorn { left: .7rem; }
.inp.post .adorn { right: .7rem; }
.hint {
  margin: .45rem 0 0; font-size: .8rem; display: inline-flex; align-items: center; gap: .35rem;
  padding: .18rem .5rem; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
}
.hint.village { color: var(--accent); font-weight: 600; border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.subnote { font-size: .78rem; color: var(--faint); margin: .3rem 0 0; }
.subnote strong { color: var(--muted); }

/* results */
.result-head { padding: 1.35rem 1.4rem 1.1rem; }
.loc { font-size: .82rem; color: var(--muted); margin: 0 0 .5rem; min-height: 1.1em; }
.hero { display: flex; align-items: baseline; gap: .5rem; }
.hero .amt { font-size: 2.7rem; font-weight: 800; letter-spacing: -1px; line-height: 1; font-variant-numeric: tabular-nums; }
.hero .per { color: var(--muted); font-size: 1rem; font-weight: 600; }
.hero .yr { margin-left: auto; text-align: right; color: var(--muted); font-size: .82rem; }
.hero .yr b { display: block; color: var(--ink); font-size: 1rem; font-variant-numeric: tabular-nums; }

.bar { display: flex; height: 16px; border-radius: 6px; overflow: hidden; margin: 1.1rem 1.4rem .2rem; background: var(--panel-2); gap: 2px; }
.bar .seg { height: 100%; transition: opacity .12s; cursor: default; }
.bar .seg.dim { opacity: .35; }

.legend { padding: .9rem 1.4rem 1.35rem; }
.legend table { width: 100%; border-collapse: collapse; }
.legend td { padding: .5rem .1rem; border-bottom: 1px solid var(--line); font-size: .92rem; vertical-align: middle; }
.legend tr:last-child td { border-bottom: 0; }
.legend .lab { display: flex; align-items: center; gap: .55rem; color: var(--ink); }
.legend .sw { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.legend .pct { color: var(--faint); font-size: .82rem; font-variant-numeric: tabular-nums; }
.legend .val { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--ink); }
.legend tr.total td { border-top: 2px solid var(--line-strong); border-bottom: 0; padding-top: .7rem; font-weight: 800; }
.legend tr.muted .lab, .legend tr.muted .val { color: var(--faint); }

.facts { border-top: 1px solid var(--line); padding: 1rem 1.4rem 1.3rem; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .9rem .6rem; }
@media (max-width: 420px) { .facts { grid-template-columns: 1fr 1fr; } }
/* flex so a label that wraps keeps its value aligned with the row's others */
.fact { display: flex; flex-direction: column; justify-content: space-between; }
.fact .k { font-size: .72rem; color: var(--faint); text-transform: uppercase; letter-spacing: .05em; }
.fact .v { font-size: 1rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: .05rem; }

.empty { padding: 3rem 1.4rem; text-align: center; color: var(--faint); }
.empty .big { font-size: 2rem; opacity: .35; margin-bottom: .5rem; }
.error { margin: 0 1.4rem 1rem; padding: .6rem .8rem; border-radius: 8px; font-size: .86rem;
  background: color-mix(in srgb, #e34948 14%, var(--panel)); color: var(--danger); border: 1px solid color-mix(in srgb, #e34948 35%, var(--panel)); }
.hidden { display: none; }
/* An author display rule (.btn) outranks the UA sheet's [hidden]; make the attribute win everywhere. */
[hidden] { display: none !important; }

/* tooltip */
#tip { position: fixed; z-index: 10; pointer-events: none; background: var(--ink); color: var(--panel);
  padding: .35rem .55rem; border-radius: 7px; font-size: .8rem; font-weight: 600; white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0,0,0,.25); opacity: 0; transform: translate(-50%, -120%); transition: opacity .1s; }

/* top bar additions (House Calculator nav) */
.topbar nav { display: flex; gap: .2rem; margin-left: 1rem; }
.topbar nav a, .topbar .tax-link { padding: .35rem .65rem; border-radius: 7px; }
.topbar nav a.active { background: rgba(255,255,255,.18); color: #fff; }
.topbar .user { display: flex; align-items: center; gap: .5rem; font-size: .85rem; color: rgba(255,255,255,.85); }
.topbar .user button { background: transparent; border: 1px solid rgba(255,255,255,.35); color: #fff; border-radius: 7px; padding: .25rem .6rem; font: inherit; font-size: .8rem; cursor: pointer; }
.topbar .user button:hover { background: rgba(255,255,255,.12); }
.btn { display: inline-block; padding: .6rem 1rem; border-radius: 9px; background: var(--brand); color: var(--brand-ink); font-weight: 600; text-decoration: none; }
.footer { text-align: center; color: var(--faint); font-size: .78rem; padding: 0 1rem 2rem; }
@media (max-width: 700px) { .topbar { flex-wrap: wrap; } .topbar nav { order: 3; width: 100%; margin-left: 0; } }

/* tables */
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); padding: .5rem .4rem; border-bottom: 2px solid var(--line-strong); }
table.data td { padding: .5rem .4rem; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
table.data td.num, table.data th.num { text-align: right; }

/* buttons, forms, toasts and modals used by the utils.js helpers */
.btn-secondary { background: var(--panel-2); color: var(--ink); border: 1px solid var(--line-strong); }
/* Dark text on --s-tax: ~5.6:1 light (--ink), ~4.9:1 dark (--bg); white was ~3.2:1. */
.btn-danger { background: var(--s-tax); color: var(--ink); }
@media (prefers-color-scheme: dark) { .btn-danger { color: var(--bg); } }
button.btn, .btn-secondary, .btn-danger { font: inherit; font-weight: 600; cursor: pointer; padding: .6rem 1rem; border-radius: 9px; }
button.btn:not(.btn-secondary) { border: 0; }
button.btn:disabled { opacity: .5; cursor: not-allowed; }
.form-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1rem; }
.field-error, .form-level-error { display: none; color: var(--s-tax); font-size: .8rem; margin-top: .3rem; }
.field-error.visible, .form-level-error.visible { display: block; }
.modal-overlay { position: fixed; inset: 0; z-index: 1000; display: none; align-items: center; justify-content: center; padding: 1rem; background: rgba(0,0,0,.45); }
.modal-overlay.open { display: flex; }
.modal, .confirm-dialog { background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 1.35rem 1.4rem; width: 100%; max-width: 420px; max-height: 90vh; overflow: auto; }
.modal-header h3 { margin: 0 0 .6rem; font-size: 1rem; }
.confirm-message { margin: 0; color: var(--muted); }
.toast-container { position: fixed; right: 1rem; bottom: 1rem; z-index: 1100; display: flex; flex-direction: column; gap: .5rem; }
.toast { display: flex; align-items: center; gap: .5rem; padding: .65rem .9rem; border-radius: 9px; background: var(--panel); color: var(--ink); border: 1px solid var(--line-strong); border-left: 4px solid var(--s-ins); box-shadow: var(--shadow); font-size: .9rem; }
.toast-success { border-left-color: var(--s-ins); }
.toast-error { border-left-color: var(--s-tax); }

/* calculator page */
.stack { display: grid; gap: 1.25rem; }
#error.panel { margin: 0; padding: .9rem 1.2rem; }
label.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; margin-bottom: .5rem; }
label.check input { width: auto; }
.reset-default { float: right; font-weight: 500; font-size: .75rem; color: var(--accent); text-decoration: none; }
.reset-default:hover { text-decoration: underline; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; font-weight: 600; }
.linkbtn:disabled { color: var(--faint); cursor: not-allowed; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.btn-secondary:disabled { opacity: .5; cursor: not-allowed; }
/* export dropdown + link-styled buttons; both are inert until a scenario is saved */
a.btn-secondary, summary.btn-secondary, label.btn-secondary { display: inline-block; margin-bottom: 0; text-decoration: none; list-style: none; }
summary.btn-secondary::-webkit-details-marker { display: none; }
a.btn-secondary[aria-disabled="true"], details.menu[inert] { opacity: .5; cursor: not-allowed; pointer-events: none; }
details.menu { position: relative; }
.menu-items { position: absolute; z-index: 5; margin-top: .25rem; min-width: 10rem; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line-strong); border-radius: 9px; box-shadow: var(--shadow); }
.menu-items a { padding: .5rem .9rem; color: var(--ink); text-decoration: none; font-size: .9rem; }
.menu-items a:hover { background: var(--panel-2); }
/* cash panel: rows reuse .legend and .fact; remaining cash takes .amount-* */
#dpHint { margin-bottom: .95rem; }
#cash .legend { padding-top: 0; }
#cash .facts { grid-template-columns: 1fr 1fr; }
/* doubled class beats .legend .val and .fact .v */
.amount-negative.amount-negative { color: var(--danger); }

.inp textarea { font: inherit; resize: vertical; }
#scenarioBanner ul { margin: .4rem 0 .8rem 1.1rem; padding: 0; }
