/* ==========================================================
   Effort Estimation Lab — styles
   ========================================================== */

:root {
  --bg: #f4f2ec;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --ink: #1d1c1a;
  --muted: #6c685f;
  --line: #e4e0d6;
  --accent: #0f766e;
  --accent-soft: #e3f2ef;
  --accent-ink: #ffffff;
  --warm: #c2410c;
  --warm-soft: #fdeee4;
  --good: #15803d;
  --good-soft: #e7f6ec;
  --bad: #b91c1c;
  --bad-soft: #fde8e8;
  --shadow: 0 1px 2px rgba(28, 25, 20, .05), 0 6px 20px rgba(28, 25, 20, .05);
  --radius: 14px;
  --sans: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Instrument Serif", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111413;
    --surface: #191d1c;
    --surface-2: #1f2423;
    --ink: #ebeae4;
    --muted: #9b998f;
    --line: #2c3231;
    --accent: #2dd4bf;
    --accent-soft: #15302d;
    --accent-ink: #0b1312;
    --warm: #fb923c;
    --warm-soft: #33221a;
    --good: #4ade80;
    --good-soft: #15291c;
    --bad: #f87171;
    --bad-soft: #321a1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #111413;
  --surface: #191d1c;
  --surface-2: #1f2423;
  --ink: #ebeae4;
  --muted: #9b998f;
  --line: #2c3231;
  --accent: #2dd4bf;
  --accent-soft: #15302d;
  --accent-ink: #0b1312;
  --warm: #fb923c;
  --warm-soft: #33221a;
  --good: #4ade80;
  --good-soft: #15291c;
  --bad: #f87171;
  --bad-soft: #321a1a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }

/* ---------- Layout ---------- */

.app {
  display: grid;
  grid-template-columns: 264px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 24px 16px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 11px;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center;
  font-family: var(--serif); font-size: 26px; line-height: 1;
}
.brand strong { display: block; font-size: 16px; letter-spacing: -.01em; }
.brand span { display: block; font-size: 12px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); padding: 10px 10px 6px;
}
.nav button {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  padding: 9px 10px; border: 0; border-radius: 10px;
  background: transparent; cursor: pointer;
  color: var(--muted); font-weight: 500; font-size: 14px;
}
.nav button:hover { background: var(--surface-2); color: var(--ink); }
.nav button.active { background: var(--accent-soft); color: var(--ink); }
.nav .num {
  flex: none; width: 24px; height: 24px; border-radius: 7px;
  display: grid; place-items: center;
  font-family: var(--mono); font-size: 11px;
  border: 1px solid var(--line); background: var(--surface);
}
.nav button.active .num { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.sidebar-foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 0 10px; }

.main { min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 32px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.crumb { font-size: 13px; color: var(--muted); }
.crumb b { color: var(--ink); font-weight: 600; }
.top-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.switch {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted); cursor: pointer; user-select: none;
}
.switch input { display: none; }
.switch .track {
  width: 34px; height: 20px; border-radius: 99px; background: var(--line);
  position: relative; transition: background .2s;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 14px; height: 14px; border-radius: 50%; background: var(--surface);
  box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .2s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(14px); }

.content { padding: 32px; max-width: 1240px; }

.panel { display: none; animation: fade .25s ease; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.panel-head { margin-bottom: 24px; display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.eyebrow { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); font-weight: 600; }
.panel-head h1 {
  font-family: var(--serif); font-weight: 400;
  font-size: clamp(30px, 4vw, 42px); line-height: 1.05; margin: 6px 0 8px; letter-spacing: -.01em;
}
.panel-head p { margin: 0; color: var(--muted); max-width: 640px; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface);
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Cards ---------- */

.grid-2 { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 20px; align-items: start; }
.grid-even { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.card-head h2 { font-size: 15px; margin: 0; font-weight: 700; letter-spacing: -.005em; }
.card-head .hint { font-size: 12px; color: var(--muted); }

/* ---------- Forms ---------- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; }
.field label small { font-weight: 400; color: var(--muted); margin-left: 4px; }
.fields-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 14px; }

.input {
  display: flex; align-items: center;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); overflow: hidden;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input input, .input select {
  flex: 1; width: 0; min-width: 0; border: 0; background: transparent; outline: 0;
  padding: 9px 12px; font-family: var(--mono); font-size: 14px;
}
.input select { font-family: var(--sans); cursor: pointer; }
.input .unit {
  padding: 0 12px; font-size: 12px; color: var(--muted);
  border-left: 1px solid var(--line); align-self: stretch; display: flex; align-items: center;
  background: var(--surface);
}

input.cell, select.cell {
  width: 100%; min-width: 0;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface-2); outline: 0;
  padding: 6px 8px; font-family: var(--mono); font-size: 13px;
}
input.cell:focus, select.cell:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select.cell { font-family: var(--sans); }
input[type=number] { -moz-appearance: textfield; }
input[type=number]::-webkit-inner-spin-button { opacity: .4; }

/* pill radio groups */
.pills { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.pills.nowrap { flex-wrap: nowrap; }
.pill input { position: absolute; opacity: 0; pointer-events: none; }
.pill span {
  display: inline-grid; place-items: center;
  min-width: 34px; height: 30px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: 8px;
  font-family: var(--mono); font-size: 13px; cursor: pointer;
  background: var(--surface-2); transition: all .12s;
}
.pill span:hover { border-color: var(--accent); }
.pill input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.pill input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- KPIs ---------- */

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi {
  border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
  background: var(--surface-2); position: relative; overflow: hidden;
}
.kpi::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--line); }
.kpi.accent::before { background: var(--accent); }
.kpi.warm::before { background: var(--warm); }
.kpi .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .value { font-family: var(--mono); font-size: 24px; font-weight: 600; letter-spacing: -.02em; margin: 4px 0 2px; overflow-wrap: anywhere; }
.kpi .sub { font-size: 12px; color: var(--muted); }

/* ---------- Worked solution ---------- */

.solution { border-top: 1px dashed var(--line); padding-top: 16px; }
.solution h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 12px; }
.solution h4 { font-size: 13px; margin: 14px 0 8px; color: var(--warm); }
.step {
  display: grid; grid-template-columns: 26px 1fr; gap: 10px; align-items: start;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.step:last-child { border-bottom: 0; }
.step .n {
  width: 22px; height: 22px; border-radius: 50%; margin-top: 1px;
  display: grid; place-items: center; font-size: 11px; font-weight: 700;
  background: var(--accent-soft); color: var(--accent);
}
.step .t { font-size: 13px; font-weight: 600; }
.step code {
  display: block; margin-top: 3px; font-family: var(--mono); font-size: 13px;
  color: var(--muted); overflow-wrap: anywhere;
}
.step code b { color: var(--ink); background: var(--warm-soft); padding: 1px 5px; border-radius: 5px; }

.formula {
  font-family: var(--mono); font-size: 14px;
  padding: 12px 14px; border-radius: 10px;
  background: var(--accent-soft); color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  margin: 0 0 16px; overflow-x: auto;
}
.formula sup { font-size: 10px; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 600; padding: 8px 8px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-family: var(--mono); }
td.mono { font-family: var(--mono); }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: 0; }
tr.group td {
  background: var(--surface-2); font-size: 11px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); font-weight: 700; padding: 6px 8px;
}
tr.changed td:first-child { box-shadow: inset 3px 0 var(--warm); }
tr.best td { background: var(--good-soft); }
tr.pick { cursor: pointer; }
tr.pick:hover td { background: var(--surface-2); }
tr.pick.selected td { background: var(--accent-soft); }

.q { font-weight: 500; }
.q small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; margin-top: 2px; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 99px;
  font-size: 11px; font-weight: 700; letter-spacing: .03em;
}
.tag.ok { background: var(--good-soft); color: var(--good); }
.tag.no { background: var(--bad-soft); color: var(--bad); }
.tag.neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }

/* ---------- Mode cards ---------- */

.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.mode { position: relative; cursor: pointer; }
.mode input { position: absolute; opacity: 0; }
.mode .box {
  border: 1px solid var(--line); border-radius: 12px; padding: 12px;
  background: var(--surface-2); height: 100%; transition: all .15s;
}
.mode .box strong { display: block; font-size: 14px; }
.mode .box span { display: block; font-family: var(--mono); font-size: 12px; color: var(--muted); margin-top: 4px; }
.mode input:checked + .box { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent) inset; }
.mode input:focus-visible + .box { box-shadow: 0 0 0 3px var(--accent-soft); }
.mode-desc { font-size: 13px; color: var(--muted); margin: -4px 0 16px; }

/* ---------- Bars ---------- */

.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 90px; gap: 10px; align-items: center; font-size: 13px; }
.bar-track { height: 10px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; background: var(--muted); transition: width .3s ease; }
.bar-row.on .bar-fill { background: var(--accent); }
.bar-row.best .bar-fill { background: var(--good); }
.bar-row .v { font-family: var(--mono); text-align: right; }

/* ---------- Notes / details ---------- */

details.notes {
  margin-top: 20px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); overflow: hidden;
}
details.notes summary {
  cursor: pointer; padding: 14px 20px; font-weight: 600; font-size: 14px; list-style: none;
  display: flex; justify-content: space-between; align-items: center;
}
details.notes summary::-webkit-details-marker { display: none; }
details.notes summary::after { content: "+"; font-family: var(--mono); color: var(--muted); font-size: 18px; }
details.notes[open] summary::after { content: "–"; }
details.notes .body { padding: 0 20px 18px; color: var(--muted); font-size: 14px; }
details.notes .body h4 { color: var(--ink); margin: 14px 0 6px; font-size: 14px; }
details.notes .body ul { margin: 0; padding-left: 18px; }
details.notes .body li { margin: 3px 0; }

.callout {
  border-radius: 12px; padding: 12px 14px; font-size: 13px;
  background: var(--warm-soft); color: var(--ink); margin-bottom: 16px;
  border: 1px solid color-mix(in srgb, var(--warm) 25%, transparent);
}
.callout.ok { background: var(--good-soft); border-color: color-mix(in srgb, var(--good) 30%, transparent); }

.muted { color: var(--muted); }
.mt { margin-top: 16px; }

/* ---------- Overview ---------- */

.hero {
  border-radius: 20px; padding: 36px; margin-bottom: 24px;
  background:
    radial-gradient(circle at 90% 10%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 45%),
    radial-gradient(circle at 10% 100%, color-mix(in srgb, var(--warm) 14%, transparent), transparent 40%),
    var(--surface);
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.hero h1 { font-family: var(--serif); font-weight: 400; font-size: clamp(34px, 5vw, 56px); line-height: 1; margin: 8px 0 14px; letter-spacing: -.02em; }
.hero h1 em { color: var(--accent); }
.hero p { color: var(--muted); max-width: 620px; margin: 0 0 20px; font-size: 16px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.tile {
  text-align: left; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
  padding: 18px; box-shadow: var(--shadow); transition: transform .15s, border-color .15s;
}
.tile:hover { transform: translateY(-2px); border-color: var(--accent); }
.tile .num { font-family: var(--mono); font-size: 12px; color: var(--accent); }
.tile h3 { margin: 6px 0 6px; font-size: 16px; }
.tile p { margin: 0 0 10px; font-size: 13px; color: var(--muted); }
.tile code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--line); padding: 3px 7px; border-radius: 6px; }

/* ---------- Delphi flow ---------- */

.flow { display: flex; flex-direction: column; gap: 0; position: relative; }
.flow .fstep {
  display: flex; gap: 12px; align-items: center;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); font-size: 13px; font-weight: 500;
}
.flow .fstep b {
  flex: none; width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 12px;
}
.flow .fstep.loop { border-color: var(--warm); }
.flow .fstep.loop b { background: var(--warm); }
.flow .arrow { height: 14px; width: 2px; background: var(--line); margin-left: 23px; }
.round-badge { font-family: var(--mono); font-size: 12px; padding: 4px 10px; border-radius: 99px; background: var(--warm-soft); color: var(--warm); font-weight: 600; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

.menu-btn { display: none; }

/* ---------- Responsive ---------- */

@media (max-width: 1080px) {
  .grid-2, .grid-even { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .top-actions { gap: 6px; }
  .top-actions .print-btn { display: none; }
  .sidebar {
    position: fixed; z-index: 20; left: 0; top: 0; width: 280px;
    transform: translateX(-100%); transition: transform .25s; box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 15; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 12px 16px; }
  .content { padding: 20px 16px; }
  .hero { padding: 24px; }
  .modes { grid-template-columns: 1fr; }
  .fields-2 { grid-template-columns: minmax(0, 1fr); }
  .switch .sw-long { display: none; }
  .crumb { display: none; }
  .card { padding: 16px; }
  .bar-row { grid-template-columns: 80px 1fr 70px; }
}

/* ---------- Print ---------- */

@media print {
  .sidebar, .topbar, .btn, .btn-row, .toast { display: none !important; }
  .app { display: block; }
  .content { padding: 0; max-width: none; }
  .card, .hero { box-shadow: none; break-inside: avoid; }
  details.notes { display: none; }
  body { background: #fff; }
}
#fp_rows input.cell { min-width: 58px; }
