/* UK Salary Context — frontend styles.
   Design-token driven, fluid (clamp), responsive grid, light + dark.
   Palette values come from the data-viz reference palette (validated). */

:root {
  /* chrome / ink */
  --plane:        #f9f9f7;
  --surface:      #fcfcfb;
  --surface-2:    #f3f2ee;
  --ink:          #0b0b0b;
  --ink-2:        #52514e;
  --muted:        #898781;
  --line:         #e1e0d9;
  --ring:         rgba(11, 11, 11, 0.10);
  --accent:       #2a78d6;
  --accent-ink:   #ffffff;
  --accent-tint:  rgba(42, 120, 214, 0.10);
  --success:      #006300;

  /* breakdown categories */
  --c-net:     #1baf7a;
  --c-tax:     #2a78d6;
  --c-ni:      #4a3aa7;
  --c-loan:    #eb6834;
  --c-pension: #eda100;
  --c-ft:      #2a78d6;
  --c-all:     #eb6834;

  /* tax bands: green = tax-free, then blue ordinal ramp (darker = higher rate) */
  --tb-free: #1baf7a;
  --tb-1:    #4e97e8;
  --tb-2:    #2a6fc9;
  --tb-3:    #17457f;
  --tb-track: #ebeae5;

  --shadow: 0 1px 2px rgba(11,11,11,.04), 0 8px 24px -12px rgba(11,11,11,.14);
  --radius: 16px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --plane:        #0d0d0d;
    --surface:      #1a1a19;
    --surface-2:    #232321;
    --ink:          #ffffff;
    --ink-2:        #c3c2b7;
    --muted:        #898781;
    --line:         #2c2c2a;
    --ring:         rgba(255, 255, 255, 0.10);
    --accent:       #3987e5;
    --accent-tint:  rgba(57, 135, 229, 0.16);
    --success:      #0ca30c;
    --c-net:     #199e70;
    --c-tax:     #3987e5;
    --c-ni:      #9085e9;
    --c-loan:    #d95926;
    --c-pension: #c98500;
    --c-ft:      #3987e5;
    --c-all:     #d95926;
    --tb-free: #199e70;
    --tb-1:    #3987e5;
    --tb-2:    #6da7ec;
    --tb-3:    #9ec5f4;
    --tb-track: #2c2c2a;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 32px -16px rgba(0,0,0,.6);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 100% -10%, var(--accent-tint), transparent 60%),
    var(--plane);
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app {
  width: min(1080px, 100% - 2.5rem);
  margin-inline: auto;
  padding-block: clamp(1.75rem, 4vw, 3.5rem);
}

/* ---- masthead ---------------------------------------------------------- */
.masthead { margin-bottom: clamp(1.5rem, 3vw, 2.5rem); }
.masthead h1 {
  margin: 0;
  font-size: clamp(1.7rem, 1rem + 3vw, 2.75rem);
  letter-spacing: -0.02em;
  line-height: 1.05;
}
.tagline {
  margin: .6rem 0 0;
  color: var(--ink-2);
  font-size: clamp(.95rem, .9rem + .3vw, 1.1rem);
  max-width: 52ch;
}
.tagline em { color: var(--ink); font-style: normal; font-weight: 600; }

/* ---- layout ------------------------------------------------------------ */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 400px) minmax(0, 1fr);
  gap: clamp(1rem, 2vw, 1.5rem);
  align-items: start;
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--ring);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(1.1rem, 2.4vw, 1.75rem);
}
.results-panel { position: relative; min-height: 420px; }

/* ---- form -------------------------------------------------------------- */
form { display: grid; gap: 1.15rem; }
.field { display: grid; gap: .4rem; min-width: 0; }
label, .field__label {
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .01em;
  color: var(--ink-2);
}

input[type=text] {
  font: inherit;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: .6rem .7rem;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input[type=text]:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }

/* hero salary input */
.field--hero label { font-size: .85rem; }
.money, .pct { position: relative; display: flex; align-items: center; }
.money__sign {
  position: absolute; left: .8rem;
  font-size: 1.5rem; color: var(--muted); pointer-events: none;
}
.money input {
  font-size: clamp(1.5rem, 1rem + 2vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  padding: .5rem .7rem .5rem 2rem;
  font-variant-numeric: tabular-nums;
}
.pct input { padding-right: 2rem; }
.pct__sign { position: absolute; right: .8rem; color: var(--muted); }

.field__err {
  margin: 0; min-height: 1em;
  font-size: .78rem; font-weight: 600; color: #d03b3b;
}

/* label row with an info trigger */
.labelrow { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.info-btn {
  display: inline-flex; align-items: center; gap: .3rem;
  font: inherit; font-size: .78rem; font-weight: 600;
  color: var(--accent); background: none; border: none; padding: .1rem .1rem;
  cursor: pointer; border-radius: 6px;
}
.info-btn:hover { text-decoration: underline; }
.info-btn__icon { flex: none; }
.info-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-tint); }

.field__hint { font-size: .72rem; font-weight: 500; color: var(--muted); }
.field__note { margin: .3rem 0 0; font-size: .78rem; font-weight: 600; color: var(--accent); min-height: 1em; }
.field__note.is-warn { color: #b9770a; }
@media (prefers-color-scheme: dark) { .field__note.is-warn { color: #fab219; } }

/* ---- advanced panel (details/summary) ---------------------------------- */
.advanced { border-top: 1px solid var(--line); margin-top: .35rem; }
.advanced summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: .5rem;
  padding: .85rem .1rem .2rem; font-weight: 700; color: var(--ink);
  transition: color .15s;
}
.advanced summary::-webkit-details-marker { display: none; }
.advanced summary:hover { color: var(--accent); }
.advanced summary:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-tint); border-radius: 8px; }
.advanced__title { font-size: .95rem; }
.advanced__hint { font-size: .74rem; font-weight: 500; color: var(--muted); }
.advanced__chev { margin-left: auto; color: var(--muted); transition: transform .2s; }
.advanced[open] .advanced__chev { transform: rotate(180deg); }
.advanced__body { display: grid; gap: 1.1rem; padding: .6rem .1rem .3rem; }

.money--sm .money__sign { font-size: 1rem; left: .7rem; }
.money--sm input { font-size: 1rem; font-weight: 600; padding: .55rem .7rem .55rem 1.5rem; }

.loan-adv { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .5rem .9rem .9rem; margin: 0; }
.loan-adv legend { font-size: .8rem; font-weight: 700; color: var(--ink-2); padding: 0 .4rem; }
.loan-adv__plan { color: var(--accent); }
.loan-adv__hint { margin: .2rem 0 0; font-size: .82rem; color: var(--muted); }

/* ---- advisory (tax-code warnings) -------------------------------------- */
.advisory { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.advisory li {
  display: flex; gap: .5rem; align-items: flex-start;
  font-size: .84rem; color: var(--ink-2);
  background: var(--surface-2); border: 1px solid var(--line);
  border-left: 3px solid #fab219; border-radius: 8px; padding: .55rem .7rem;
}
.advisory li::before { content: "⚠"; color: #b9770a; }
@media (prefers-color-scheme: dark) { .advisory li::before { color: #fab219; } }

/* ---- hero tag chip ----------------------------------------------------- */
.hero__tag {
  font-size: .68rem; font-weight: 700; letter-spacing: .02em; vertical-align: middle;
  color: var(--accent-ink); background: var(--accent); border-radius: 999px; padding: .12rem .5rem;
  text-transform: none;
}

/* ---- payoff card ------------------------------------------------------- */
.payoff { margin: 0; }
.payoff figcaption { font-size: .8rem; font-weight: 600; color: var(--ink-2); margin-bottom: .5rem; }
.payoff figcaption span { color: var(--accent); }
.payoff__headline { margin: 0 0 .8rem; font-size: 1.2rem; font-weight: 700; letter-spacing: -0.01em; }
.payoff__headline .accent { color: var(--accent); }
.payoff__headline .warn { color: #b9770a; }
@media (prefers-color-scheme: dark) { .payoff__headline .warn { color: #fab219; } }
.payoff__grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .7rem; }
.payoff__cell { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .6rem .75rem; }
.payoff__k { margin: 0 0 .15rem; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.payoff__v { margin: 0; font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.payoff__note { margin: .7rem 0 0; font-size: .78rem; color: var(--muted); }

/* segmented control */
.segmented { display: flex; flex-wrap: wrap; gap: .4rem; }
.segmented button {
  font: inherit; font-size: .85rem; font-weight: 600;
  color: var(--ink-2);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .4rem .8rem;
  cursor: pointer;
  transition: all .15s;
}
.segmented button:hover { border-color: var(--muted); color: var(--ink); }
.segmented button[aria-checked="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.segmented button:focus-visible {
  outline: none; box-shadow: 0 0 0 3px var(--accent-tint);
}

/* controls row: switch + pension */
.row--controls { grid-template-columns: 1fr auto; align-items: end; gap: 1rem; }
.field--pension { max-width: 8.5rem; }
.pct input { text-align: right; }

/* toggle switch */
.switch { display: inline-flex; align-items: center; gap: .6rem; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track {
  width: 42px; height: 24px; border-radius: 999px;
  background: var(--line); position: relative; transition: background .18s; flex: none;
}
.switch__thumb {
  position: absolute; top: 2px; left: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .18s;
}
.switch input:checked + .switch__track { background: var(--accent); }
.switch input:checked + .switch__track .switch__thumb { transform: translateX(18px); }
.switch input:focus-visible + .switch__track { box-shadow: 0 0 0 3px var(--accent-tint); }
.switch__text { font-size: .85rem; font-weight: 600; color: var(--ink-2); }

/* ---- results ----------------------------------------------------------- */
.results { display: grid; gap: clamp(1.25rem, 2.5vw, 1.75rem); transition: opacity .2s; }

.hero {
  padding-bottom: clamp(1rem, 2vw, 1.4rem);
  border-bottom: 1px solid var(--line);
}
.hero__label {
  margin: 0; font-size: .8rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
}
.hero__value {
  margin: .2rem 0 .15rem;
  font-size: clamp(2.4rem, 1.4rem + 5vw, 3.6rem);
  font-weight: 800; letter-spacing: -0.03em; line-height: 1;
}
.hero__sub { margin: 0; color: var(--ink-2); font-weight: 500; }
.hero__sub span { color: var(--ink); font-weight: 700; }
.hero__dot { margin: 0 .55rem; color: var(--muted); }
.hero__hourly {
  margin: .7rem 0 0; display: inline-flex; align-items: center; gap: .8rem;
  padding: .5rem .8rem; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface-2);
}
.hourly-pair { display: inline-flex; flex-direction: column; line-height: 1.15; }
.hourly-pair b { font-size: 1.05rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.hourly-pair small { font-size: .68rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.hourly-pair:last-child b { color: var(--c-net); }
.hourly-arrow { color: var(--muted); flex: none; }

/* breakdown bar */
.breakdown { margin: 0; }
.breakdown figcaption, .percentile figcaption {
  font-size: .8rem; font-weight: 600; color: var(--ink-2); margin-bottom: .6rem;
}
.breakdown figcaption span { color: var(--ink); font-variant-numeric: tabular-nums; }
.bar {
  display: flex; gap: 2px; height: 36px;
  border-radius: 8px; overflow: hidden; background: var(--surface-2);
}
.bar__seg {
  min-width: 3px; height: 100%;
  transition: flex-basis .4s cubic-bezier(.2,.7,.2,1);
}
.bar__seg:first-child { border-radius: 8px 0 0 8px; }
.bar__seg:last-child  { border-radius: 0 8px 8px 0; }

.legend {
  list-style: none; margin: .9rem 0 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .55rem .9rem;
}
.legend li { display: flex; align-items: baseline; gap: .5rem; font-size: .88rem; }
.legend .swatch {
  width: 11px; height: 11px; border-radius: 3px; flex: none; transform: translateY(1px);
}
.legend .k { color: var(--ink-2); }
.legend .v { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }

/* stat tiles */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
@media (max-width: 420px) { .stats { grid-template-columns: 1fr; } }
.stat {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: .85rem .95rem;
}
.stat__label {
  margin: 0 0 .3rem; font-size: .74rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
}
.stat__value { margin: 0; font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; }
.stat__note { margin: .2rem 0 0; font-size: .82rem; color: var(--ink-2); }
.stat__note.good { color: var(--success); font-weight: 600; }

/* clickable stat tile (opens the tax breakdown) */
.stat--action {
  font: inherit; text-align: left; width: 100%; cursor: pointer;
  display: block; color: inherit;
  transition: border-color .15s, box-shadow .15s, transform .15s, background .15s;
}
.stat--action .stat__label { display: flex; align-items: center; justify-content: space-between; }
.stat--action .stat__value, .stat--action .stat__note { display: block; }
.stat__cue {
  display: inline-flex; align-items: center; gap: .1rem;
  color: var(--accent); letter-spacing: 0; text-transform: none; font-size: .72rem;
  opacity: .85; transition: gap .15s, opacity .15s;
}
.stat--action:hover {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-tint);
  transform: translateY(-1px);
}
.stat--action:hover .stat__cue { opacity: 1; gap: .28rem; }
.stat--action:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }

/* percentile meter */
.percentile { margin: 0; }
.meter { position: relative; height: 40px; }
.meter__track {
  position: absolute; inset: 50% 0 auto 0; height: 8px; transform: translateY(-50%);
  border-radius: 999px;
  background: linear-gradient(90deg, var(--surface-2), var(--accent-tint) 50%, var(--accent));
  border: 1px solid var(--line);
}
.meter__marker {
  position: absolute; top: 0; height: 100%; width: 0;
  transition: left .4s cubic-bezier(.2,.7,.2,1);
}
.meter__marker span {
  position: absolute; top: 50%; left: 50%;
  width: 16px; height: 16px; border-radius: 50%;
  transform: translate(-50%, -50%);
  border: 3px solid var(--surface); box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.meter__marker--ft span  { background: var(--c-ft); }
.meter__marker--all span { background: var(--c-all); }
.meter__scale {
  display: flex; justify-content: space-between; margin-top: .3rem;
  font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums;
}
.legend--pct { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-top: .7rem; }

/* ---- overlays ---------------------------------------------------------- */
.overlay {
  position: absolute; inset: 0; border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center; gap: .7rem;
  font-weight: 600; color: var(--ink-2);
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: blur(3px);
}
.overlay--error {
  flex-direction: column; text-align: center; padding: 2rem;
  color: #d03b3b; background: color-mix(in srgb, var(--surface) 92%, transparent);
}
.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2.5px solid var(--line); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.results-panel.is-busy .results { opacity: .35; }
[hidden] { display: none !important; }

/* ---- colophon ---------------------------------------------------------- */
.colophon {
  margin-top: clamp(1.5rem, 3vw, 2.5rem);
  color: var(--muted); font-size: .82rem;
}
.colophon p { margin: 0 0 .3rem; max-width: 70ch; }
.colophon #provenance { color: var(--ink-2); }
.colophon .fine strong { color: var(--ink-2); }

/* ---- plan help dialog -------------------------------------------------- */
.dialog {
  padding: 0; border: none; background: transparent;
  max-width: min(30rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  color: var(--ink);
}
.dialog::backdrop {
  background: rgba(11, 11, 11, 0.5);
  backdrop-filter: blur(2px);
}
.dialog__panel {
  background: var(--surface);
  border: 1px solid var(--ring);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.5);
  max-height: calc(100dvh - 2rem);
  overflow: hidden auto;
}
.dialog[open] { animation: dialog-in .18s cubic-bezier(.2, .7, .2, 1); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px); } }
.dialog__head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1.1rem 1.25rem .75rem;
}
.dialog__head h2 { margin: 0; font-size: 1.15rem; letter-spacing: -0.01em; }
.dialog__close {
  flex: none; display: inline-flex; padding: .3rem; margin: -.3rem -.3rem -.3rem 0;
  color: var(--muted); background: none; border: none; border-radius: 8px; cursor: pointer;
}
.dialog__close:hover { color: var(--ink); background: var(--surface-2); }
.dialog__close:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-tint); }
.dialog__body { padding: 0 1.25rem 1.25rem; }
.dialog__body p { margin: 0 0 .9rem; color: var(--ink-2); font-size: .92rem; }
.dialog__body strong { color: var(--ink); font-weight: 650; }

.plan-list { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: .55rem; }
.plan-list li {
  display: flex; align-items: baseline; gap: .65rem;
  font-size: .9rem; color: var(--ink-2); line-height: 1.4;
}
.plan-list strong { color: var(--ink); font-weight: 650; }
.plan-tag {
  flex: none; min-width: 4.6rem; text-align: center;
  font-size: .78rem; font-weight: 700; color: var(--accent-ink);
  background: var(--accent); border-radius: 999px; padding: .18rem .55rem;
}
.plan-tag--pg { background: var(--c-loan); }
.dialog__note { font-size: .85rem !important; }
.dialog__note a { color: var(--accent); font-weight: 600; }

/* tax band breakdown */
.tax-summary {
  margin: 0 0 1.1rem !important; font-size: .95rem !important; color: var(--ink-2) !important;
}
.tax-summary strong { color: var(--ink); font-weight: 700; }
.tax-bands { display: grid; gap: 1rem; margin-bottom: 1.1rem; }
.tband { display: grid; gap: .35rem; }
.tband--empty { opacity: .55; }
.tband__top, .tband__bot { display: flex; align-items: baseline; justify-content: space-between; gap: .75rem; }
.tband__name { font-size: .9rem; font-weight: 650; color: var(--ink); display: flex; align-items: baseline; gap: .45rem; }
.tband__rate {
  font-size: .7rem; font-weight: 700; color: var(--ink-2);
  background: var(--surface-2); border-radius: 999px; padding: .1rem .45rem;
}
.tband__fill { font-size: .95rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tband__fill small { font-weight: 500; color: var(--muted); font-size: .78rem; margin-left: .35rem; }
.tband__gauge {
  height: 12px; border-radius: 999px; background: var(--tb-track);
  overflow: hidden; border: 1px solid var(--ring);
}
.tband__bar {
  height: 100%; border-radius: 999px; min-width: 0;
  transition: width .45s cubic-bezier(.2, .7, .2, 1);
}
.tband__bot { font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.tband__left { font-weight: 600; }
.tband__left.is-full { color: var(--success); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
