/* Castra Konsultkalkyl — mobile first.
   One idea carries the colour scheme: everything that *leaves* the consultant's
   share is a warm tone, and the part that stays is the only cool one. You can
   read the doughnut without reading the legend. */

:root {
  --orange:   #F4581E;
  --orange-d: #C8410F;
  --cream:    #FDF4EE;
  --card:     #FFFFFF;
  --ink:      #1A1410;
  --ink-2:    #6B5D53;
  --line:     #EFE1D6;
  --green:    #1E7A5A;
  --red:      #C0392B;

  /* Chart, in the order the money leaves. */
  --c-salary:   #F4581E;
  --c-fee:      #FF8A3D;
  --c-pension:  #FFB861;
  --c-vacation: #E3C579;
  --c-other:    #A8836B;
  --c-pot:      #1E7A5A;

  --r: 16px;
  --pad: 16px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto,
        "Helvetica Neue", Arial, sans-serif;
  /* Digits must not jitter while a slider is dragged. */
  font-variant-numeric: tabular-nums;
  padding-bottom: env(safe-area-inset-bottom);
}

.wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 var(--pad); }

/* --- header --------------------------------------------------------------- */
.topbar {
  background: var(--orange);
  color: #fff;
  padding: 14px 0;
  position: sticky; top: 0; z-index: 20;
  box-shadow: 0 2px 14px rgba(196, 65, 15, .18);
}
.topbar .wrap { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.topbar h1 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -.01em; }
.topbar h1 span { font-weight: 400; opacity: .9; }
.locked { margin: 0; font-size: 14px; opacity: .95; }
.lock {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  background: rgba(255,255,255,.22); padding: 2px 7px; border-radius: 999px;
  margin-left: 6px;
}

/* --- hero ----------------------------------------------------------------- */
.hero {
  background: var(--card);
  border-radius: var(--r);
  padding: 22px var(--pad);
  margin: 16px 0;
  text-align: center;
  box-shadow: 0 1px 3px rgba(26,20,16,.06);
  border: 1px solid var(--line);
}
.hero-label { margin: 0; font-size: 14px; color: var(--ink-2); }
.hero-value {
  margin: 4px 0 2px;
  font-size: clamp(38px, 12vw, 58px);
  font-weight: 800; line-height: 1.05; letter-spacing: -.03em;
  color: var(--orange);
}
.hero-sub { margin: 0 0 14px; font-size: 13px; color: var(--ink-2); }

.status {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px; border-radius: 999px;
  font-size: 14px; font-weight: 600;
  background: #EAF6F1; color: var(--green);
}
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; flex: none; }
.status.neutral { background: #F3EEE9; color: var(--ink-2); }
.status.over    { background: #FBEAE7; color: var(--red); }

.summary {
  margin: 14px auto 0; max-width: 46ch;
  font-size: 14px; line-height: 1.55; color: var(--ink-2);
}

/* --- cards ---------------------------------------------------------------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: var(--pad);
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(26,20,16,.05);
}
.card h2 {
  margin: 0 0 14px; font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .09em; color: var(--ink-2);
}

/* --- inputs --------------------------------------------------------------- */
.presets { display: flex; gap: 8px; margin-bottom: 18px; }
.presets button {
  flex: 1; min-height: 44px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: #FBF6F2; color: var(--ink);
  font: inherit; font-weight: 600; font-size: 14px;
}
.presets button:hover { border-color: var(--orange); color: var(--orange-d); }
.presets button[aria-pressed="true"] { background: var(--orange); border-color: var(--orange); color: #fff; }

.field { margin-bottom: 18px; }
.field > label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.inline { display: flex; align-items: center; gap: 12px; }

input[type="range"] {
  flex: 1 1 auto; min-width: 0;
  -webkit-appearance: none; appearance: none;
  height: 44px; background: transparent; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px; background: #F0E3D8;
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; background: #F0E3D8; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--orange); border: 3px solid #fff; margin-top: -10px;
  box-shadow: 0 1px 4px rgba(196,65,15,.4);
}
input[type="range"]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--orange); border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(196,65,15,.4);
}
input[type="range"]:focus-visible { outline: 2px solid var(--orange); outline-offset: 4px; border-radius: 6px; }

.numbox {
  flex: 0 0 auto; display: flex; align-items: center; gap: 5px;
  background: #FBF6F2; border: 1px solid var(--line); border-radius: 10px;
  padding: 0 10px; min-height: 46px;
}
.numbox input {
  width: 5.6em; border: 0; background: transparent; color: inherit;
  font: inherit; font-weight: 700; font-variant-numeric: tabular-nums;
  text-align: right; padding: 10px 0; min-height: 44px;
}
.numbox input:focus { outline: none; }
.numbox:focus-within { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(244,88,30,.15); }
.numbox .unit { font-size: 13px; color: var(--ink-2); white-space: nowrap; }
/* The spinner arrows are too small to hit and steal width on mobile. */
.numbox input::-webkit-outer-spin-button,
.numbox input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.numbox input[type=number] { -moz-appearance: textfield; }

.field-accent { padding: 14px; margin: 0 -2px 18px; background: #FFF6F1; border: 1px solid #F9DCCC; border-radius: 12px; }

.ghostbtn {
  margin-top: 10px; min-height: 44px; padding: 0 14px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 10px; font: inherit; font-weight: 600; font-size: 14px; cursor: pointer;
}
.ghostbtn:hover { border-color: var(--orange); color: var(--orange-d); }

.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.saved { font-size: 13px; color: var(--green); font-weight: 600; }

.advanced { margin-top: 6px; border-top: 1px solid var(--line); padding-top: 12px; }
.advanced summary { cursor: pointer; font-size: 14px; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.hint { margin: 8px 0 0; font-size: 12.5px; line-height: 1.5; color: var(--ink-2); }

/* --- result rows ---------------------------------------------------------- */
.rows { margin: 0; }
.row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 14px;
  padding: 11px 0; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row dt { margin: 0; font-size: 14.5px; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.row dd { margin: 0; font-weight: 700; font-size: 16px; white-space: nowrap; }
.row.strong dd { color: var(--orange); font-size: 18px; }
.row.total { border-top: 2px solid var(--ink); border-bottom: 0; margin-top: 4px; padding-top: 12px; }
.row.total dt { color: var(--ink); font-weight: 700; }
.row.total dd { font-size: 18px; }
.row dd.neg { color: var(--red); }

.tag {
  font-size: 11px; font-weight: 700; letter-spacing: .05em;
  background: var(--orange); color: #fff; padding: 2px 7px; border-radius: 999px;
}
.tag.soft { background: #F3EEE9; color: var(--ink-2); }

.sw { width: 11px; height: 11px; border-radius: 3px; flex: none; display: inline-block; }
.sw[data-k="salary"]   { background: var(--c-salary); }
.sw[data-k="fee"]      { background: var(--c-fee); }
.sw[data-k="pension"]  { background: var(--c-pension); }
.sw[data-k="vacation"] { background: var(--c-vacation); }
.sw[data-k="other"]    { background: var(--c-other); }
.sw[data-k="pot"]      { background: var(--c-pot); }

/* --- chart ---------------------------------------------------------------- */
.chartwrap { display: grid; gap: 16px; }
#chart { width: 100%; max-width: 300px; margin: 0 auto; display: block; }
#chart path { transition: d .25s ease, opacity .2s ease; }
.chart-mid { font-size: 17px; font-weight: 800; fill: var(--ink); }
.chart-midlabel { font-size: 8px; fill: var(--ink-2); letter-spacing: .06em; text-transform: uppercase; }

.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.legend li { display: flex; align-items: center; gap: 9px; font-size: 14px; }
.legend .key { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.legend .name { flex: 1; color: var(--ink-2); }
.legend .val { font-weight: 700; white-space: nowrap; }
.legend .pct { color: var(--ink-2); font-size: 13px; min-width: 3.4em; text-align: right; }

/* --- footer --------------------------------------------------------------- */
.foot { padding: 8px 16px 32px; }
.foot p { margin: 0 0 8px; font-size: 12.5px; line-height: 1.6; color: var(--ink-2); }
.disclaimer { border-top: 1px solid var(--line); padding-top: 10px; }

/* --- desktop: inputs left, results right ---------------------------------- */
@media (min-width: 900px) {
  :root { --pad: 24px; }
  .layout {
    display: grid;
    grid-template-columns: minmax(340px, 420px) 1fr;
    grid-template-areas: "hero hero" "input result";
    gap: 0 24px;
    align-items: start;
  }
  .hero { grid-area: hero; padding: 30px 24px; }
  .col-input  { grid-area: input; position: sticky; top: 74px; }
  .col-result { grid-area: result; }
  .topbar h1 { font-size: 22px; }
  .chartwrap { grid-template-columns: 300px 1fr; align-items: center; }
}

@media (prefers-reduced-motion: reduce) {
  #chart path { transition: none; }
}
