/* Flip Ledger — repair-bench ledger. Tabs across the top, summary strip, working panels, editor as a slide-over sheet. */
:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --ink: #141b2b;
  --muted: #5d6779;
  --line: #d7dde7;
  --accent: #2b55d6;
  --accent-ink: #ffffff;
  --accent-soft: #e2e9fb;
  --good: #137a4b;
  --good-soft: #dcf2e6;
  --bad: #b3261e;
  --bad-soft: #fbe3e1;
  --warn: #8a5a00;
  --warn-soft: #fbefd2;
  --display: "Bricolage Grotesque", "Avenir Next", system-ui, sans-serif;
  --body: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141d; --surface: #171e2b; --ink: #e8ecf4; --muted: #95a0b4; --line: #2a3446;
    --accent: #7c9bff; --accent-ink: #0d1220; --accent-soft: #1f2a48;
    --good: #5fd39a; --good-soft: #143326; --bad: #ff8a80; --bad-soft: #3a1b1b; --warn: #f1c25b; --warn-soft: #3a2e12;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 15px; line-height: 1.5; }
.num, .money { font-family: var(--mono); font-variant-numeric: tabular-nums; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); }

.wrap { max-width: 1200px; margin: 0 auto; padding: 20px 16px 72px; display: grid; gap: 20px; }

/* Top bar */
.topbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px; }
.brand { display: flex; align-items: baseline; gap: 10px; }
h1 { font-family: var(--display); font-weight: 800; font-size: clamp(26px, 4vw, 34px); line-height: 1; margin: 0; letter-spacing: -0.02em; }
.brand small { color: var(--muted); font-size: 13px; }
.top-actions { display: flex; gap: 8px; align-items: center; }
nav.tabs-main { display: flex; gap: 2px; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: none; }
nav.tabs-main a { padding: 10px 14px; text-decoration: none; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
nav.tabs-main a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }
nav.tabs-main a:hover { color: var(--ink); }

/* Buttons */
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 14px; font-weight: 500; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.danger.armed { background: var(--bad); color: var(--surface); border-color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: default; }
.linkbtn { border: 0; background: none; color: var(--accent); padding: 0; font-size: 13px; font-weight: 600; justify-self: start; }

/* Stats strip */
.stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.stat { background: var(--surface); padding: 14px 16px; min-width: 0; }
.label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
.stat .value { font-family: var(--mono); font-size: clamp(19px, 2.3vw, 26px); font-weight: 500; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .hint { font-size: 12px; color: var(--muted); }
.stat.hero .value { color: var(--good); }
.stat.hero.neg .value { color: var(--bad); }
@media (max-width: 900px) { .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
#rp-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 560px) { #rp-stats { grid-template-columns: minmax(0, 1fr); } }

/* Panels */
.cols { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
.cols.even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 920px) { .cols, .cols.even { grid-template-columns: minmax(0, 1fr); } }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; min-width: 0; }
.panel-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.panel-body { padding: 16px; display: grid; gap: 12px; }
h2 { font-family: var(--display); font-weight: 600; font-size: 18px; margin: 0; text-wrap: balance; }
h3 { font-size: 14px; margin: 0; }
.help { margin: 0; color: var(--muted); font-size: 13px; }
.seg { display: flex; gap: 3px; background: var(--bg); padding: 3px; border-radius: 8px; }
.seg button { border: 0; background: none; padding: 4px 10px; border-radius: 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.search { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 6px 10px; min-width: 0; width: 180px; }

/* Flip rows */
.row { display: grid; grid-template-columns: minmax(0, 2.4fr) 112px 64px repeat(3, minmax(0, 1fr)); gap: 12px; align-items: center; padding: 11px 16px; border: 0; border-bottom: 1px solid var(--line); width: 100%; text-align: left; background: none; }
.row:last-child { border-bottom: 0; }
button.row:hover { background: var(--accent-soft); }
.row.head { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; padding-block: 8px; }
.r { text-align: right; }
.item-name { font-weight: 600; overflow-wrap: anywhere; }
.item-meta { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
@media (max-width: 680px) {
  .row.head { display: none; }
  .row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "name status" "cost profit" "days days"; row-gap: 4px; }
  .row .c-name { grid-area: name; } .row .c-status { grid-area: status; text-align: right; }
  .row .c-days { grid-area: days; text-align: left; font-size: 12px; } .row .c-days::after { content: " days"; color: var(--muted); }
  .row .c-cost { grid-area: cost; text-align: left; } .row .c-sale { display: none; } .row .c-profit { grid-area: profit; }
  .row .c-cost::before { content: "Into it "; color: var(--muted); font-family: var(--body); font-size: 12px; }
}

.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.pill.repairing { background: var(--warn-soft); color: var(--warn); }
.pill.ready { background: var(--accent-soft); color: var(--accent); }
.pill.listed { background: var(--accent); color: var(--accent-ink); }
.pill.sold { background: var(--good-soft); color: var(--good); }
.pill.parted, .pill.kept { background: var(--bg); color: var(--muted); }
.age-ok { color: var(--muted); } .age-warn { color: var(--warn); font-weight: 600; } .age-bad { color: var(--bad); font-weight: 600; }
.pos { color: var(--good); } .neg { color: var(--bad); } .dim { color: var(--muted); }
.proj { font-size: 11px; color: var(--muted); display: block; font-family: var(--body); }
.empty { padding: 32px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-family: var(--display); font-size: 18px; margin-bottom: 4px; }

/* Forms */
.field { display: grid; gap: 4px; min-width: 0; }
.field label, .field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea, .cell-in { width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 7px 10px; min-width: 0; }
.field textarea { min-height: 70px; resize: vertical; }
.money-in { position: relative; }
.money-in::before { content: "$"; position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-family: var(--mono); pointer-events: none; }
.money-in input { padding-left: 22px; font-family: var(--mono); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 520px) { .grid3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.checklist { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 12px; }
@media (max-width: 520px) { .checklist { grid-template-columns: 1fr; } }
.notice { font-size: 13px; color: var(--bad); margin: 0; }

/* Verdict */
.verdict { border-radius: 10px; padding: 12px 14px; display: grid; gap: 4px; }
.verdict.good { background: var(--good-soft); } .verdict.thin { background: var(--warn-soft); } .verdict.pass { background: var(--bad-soft); }
.verdict .big { font-family: var(--display); font-weight: 800; font-size: 22px; }
.verdict.good .big { color: var(--good); } .verdict.thin .big { color: var(--warn); } .verdict.pass .big { color: var(--bad); }
.line { display: flex; justify-content: space-between; font-size: 14px; gap: 8px; }
.line.total { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 2px; font-weight: 600; }
.tally { background: var(--bg); border-radius: 10px; padding: 12px 14px; display: grid; gap: 3px; }

/* Tables */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.money, th.r { text-align: right; }
tr.clickable { cursor: pointer; } tr.clickable:hover td { background: var(--accent-soft); }

/* Chart */
.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { fill: var(--muted); font-size: 11px; font-family: var(--mono); }
.chart .grid { stroke: var(--line); }
.chart .bar-pos { fill: var(--good); } .chart .bar-neg { fill: var(--bad); }

/* Sheet */
.scrim { position: fixed; inset: 0; background: rgba(8, 12, 20, .45); z-index: 20; }
.sheet { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--surface); z-index: 21; display: flex; flex-direction: column; border-left: 1px solid var(--line); margin: 0; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--line); gap: 12px; }
.sheet-body { overflow-y: auto; padding: 18px 20px; display: grid; gap: 20px; align-content: start; flex: 1; }
.sheet-foot { display: flex; gap: 8px; justify-content: space-between; padding: 12px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }
fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 10px; min-width: 0; }
legend { font-family: var(--display); font-weight: 600; font-size: 15px; margin-bottom: 8px; padding: 0; }
.part { display: grid; grid-template-columns: minmax(0, 1fr) 100px auto; gap: 8px; align-items: center; }
.part input { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 6px 10px; width: 100%; min-width: 0; }
.part .from-bin { font-size: 11px; color: var(--muted); grid-column: 1 / -1; margin-top: -4px; }
.x { border: 0; background: none; color: var(--muted); font-size: 16px; padding: 4px 8px; border-radius: 6px; }
.x:hover { color: var(--bad); background: var(--bad-soft); }
.links { display: flex; flex-wrap: wrap; gap: 6px; }
@media (prefers-reduced-motion: no-preference) { .sheet { animation: slide .18s ease-out; } @keyframes slide { from { transform: translateX(24px); opacity: .6; } } }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 8px; font-size: 14px; z-index: 40; }
.toast.err { background: var(--bad); color: #fff; }

/* Login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: min(380px, 100%); display: grid; gap: 16px; }
.login-card .sub { margin: -8px 0 0; color: var(--muted); }

/* Challenge */
.ch-hero { padding: 20px; display: grid; gap: 14px; }
.ch-top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: end; gap: 12px 24px; }
.ch-title { font-family: var(--display); font-weight: 800; font-size: clamp(24px, 4vw, 36px); line-height: 1.05; letter-spacing: -0.02em; margin-top: 4px; }
.ch-total-wrap { text-align: right; }
.ch-total { font-size: clamp(36px, 7vw, 60px); line-height: 1; color: var(--good); font-weight: 500; }
.ch-total.neg { color: var(--bad); }
.ch-bar { height: 16px; background: var(--bg); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.ch-fill { height: 100%; background: var(--good); border-radius: 999px; transition: width .4s ease; min-width: 4px; }
.ch-next { font-size: 15px; }
.ch-ladder { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
.ch-ladder li { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; display: grid; gap: 2px; color: var(--muted); }
.ch-ladder li .money { font-size: 16px; color: var(--ink); }
.ch-ladder li small { font-size: 11px; min-height: 1em; }
.ch-ladder li.done { background: var(--good-soft); border-color: transparent; }
.ch-ladder li.done .money, .ch-ladder li.done small { color: var(--good); }
.ch-ladder li.now { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.ch-ladder li.now small { color: var(--accent); font-weight: 600; }
.ep { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto auto; gap: 12px; align-items: center; width: 100%; padding: 12px 16px; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; }
.ep:last-child { border-bottom: 0; }
.ep:hover { background: var(--accent-soft); }
.ep-num { font-family: var(--display); font-weight: 800; font-size: 15px; color: var(--accent); }
.ep-main { display: grid; gap: 2px; min-width: 0; }
.ep-result { text-align: right; }
.ep-links { display: flex; gap: 6px; }
@media (max-width: 640px) {
  .ep { grid-template-columns: 44px minmax(0, 1fr) auto; }
  .ep-links { grid-column: 2 / -1; }
  .ch-total-wrap { text-align: left; }
}
