/* Layout: 左侧导航 + 顶栏 + 视图区。手机上导航变成顶部横向滚动条。 */
:root {
  --bg: #f2f5f4; --panel: #ffffff; --sunk: #eaefed; --ink: #17201f; --muted: #5a6866; --line: #d8e0dd;
  --accent: #0f6b62; --accent-ink: #ffffff; --accent-soft: #dcefeb;
  --ok: #1d7a3e; --ok-soft: #e1f3e6; --warn: #9a5b00; --warn-soft: #fbefd9; --err: #b3261e; --err-soft: #fbe4e2;
  --idle: #6b7472; --idle-soft: #eceeed; --code-bg: #eef2f1;
  --f-display: "Bricolage Grotesque", "Noto Sans SC", system-ui, sans-serif;
  --f-body: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root {
  --bg: #0f1514; --panel: #161f1e; --sunk: #121a19; --ink: #e3ebe9; --muted: #95a4a1; --line: #283432;
  --accent: #4fc2b3; --accent-ink: #0b1513; --accent-soft: #163a36;
  --ok: #5fd08a; --ok-soft: #173426; --warn: #f0b552; --warn-soft: #3a2c12; --err: #f28b82; --err-soft: #3d1c1a;
  --idle: #8d9896; --idle-soft: #222c2b; --code-bg: #0b1110; color-scheme: dark; } }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.6 var(--f-body); }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.3; text-wrap: balance; }
h1 { font: 700 22px var(--f-display); }
h2 { font: 700 16px var(--f-display); }
h3 { font-size: 14px; font-weight: 700; }
p { margin: 0; }
code, .mono { font-family: var(--f-mono); font-size: .9em; }
.muted { color: var(--muted); }
a { color: var(--accent); }

button, .btn { font: 500 14px var(--f-body); color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 14px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button:disabled { opacity: .55; cursor: progress; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, select, textarea { font: 14px var(--f-body); color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0; }
textarea { font-family: var(--f-mono); font-size: 13px; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }

/* shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100%; }
.nav { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { padding: 0 8px 14px; display: grid; gap: 2px; }
.brand b { font: 800 18px var(--f-display); letter-spacing: -.01em; }
.brand span { font-size: 12px; color: var(--muted); }
.nav a { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; }
.nav a:hover { background: var(--sunk); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.nav a em { font-style: normal; font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; white-space: nowrap; }
.nav-group { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 14px 10px 4px; }
.nav-foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 0 10px; }

main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; padding: 16px max(16px, 2.2vw); border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 2; }
.topbar .sub { font-size: 13px; color: var(--muted); }
.user { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; }
.view { padding: 20px max(16px, 2.2vw) 48px; display: grid; gap: 16px; align-content: start; max-width: 1200px; width: 100%; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; display: grid; gap: 12px; min-width: 0; }
.panel-head { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: space-between; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }

.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; display: grid; gap: 4px; align-content: start; min-width: 0; }
.tile .k { font-size: 12px; color: var(--muted); }
.tile .v { font: 700 20px var(--f-display); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile .d { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 500; white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.err { background: var(--err-soft); color: var(--err); }
.pill.idle { background: var(--idle-soft); color: var(--idle); }

/* stages */
.stages { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stage { padding: 12px 14px; border-top: 4px solid var(--idle-soft); display: grid; gap: 6px; align-content: start; }
.stage + .stage { border-left: 1px dashed var(--line); }
.stage.current { border-top-color: var(--accent); background: var(--accent-soft); border-radius: 0 0 8px 8px; }
.stage .n { font-size: 12px; color: var(--muted); }
.stage ul { margin: 0; padding-left: 18px; font-size: 13px; color: var(--muted); }

/* tables */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 8px 12px; border-top: 1px solid var(--line); vertical-align: top; }
thead th { border-top: 0; background: var(--sunk); font-size: 12px; color: var(--muted); font-weight: 500; letter-spacing: .04em; position: sticky; top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--sunk); }
.empty { padding: 28px 12px; text-align: center; color: var(--muted); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.toolbar input[type=search] { width: min(320px, 100%); }
.code { background: var(--code-bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font: 12.5px/1.55 var(--f-mono); white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; max-height: 460px; overflow: auto; }
.result-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 12.5px; color: var(--muted); }

.notice { border-left: 3px solid var(--warn); background: var(--warn-soft); padding: 10px 14px; border-radius: 0 8px 8px 0; font-size: 13.5px; }
.notice.info { border-color: var(--accent); background: var(--accent-soft); }
.plan { display: grid; gap: 10px; }
.plan li { margin-bottom: 4px; }
.form-preview { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; opacity: .65; }

.toast { position: fixed; right: 16px; bottom: 16px; background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 8px; font-size: 13px; z-index: 10; max-width: calc(100% - 32px); }

/* login */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login { width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 26px; display: grid; gap: 16px; }
.login .err { color: var(--err); font-size: 13px; min-height: 1.2em; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .nav { position: static; height: auto; flex-direction: row; overflow-x: auto; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line); align-items: center; }
  .brand { padding: 0 8px 0 0; } .brand span { display: none; }
  .nav a { white-space: nowrap; } .nav-group, .nav-foot { display: none; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
  .stages { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stage:nth-child(3) { border-left: 0; }
}
@media (max-width: 480px) {
  .grid-4, .stages { grid-template-columns: 1fr; }
  .stage + .stage { border-left: 0; }
}

/* ---- v0.4 additions ---- */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 12px; color: var(--muted); }
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 700; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; align-items: end; }
.form-grid .wide { grid-column: 1 / -1; }
.bars { display: grid; gap: 4px; }
.bar { display: grid; grid-template-columns: minmax(80px, 160px) 1fr 90px; gap: 10px; align-items: center; font-size: 13px; }
.bar .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.bar .track { display: block; height: 12px; background: var(--sunk); border-radius: 3px; overflow: hidden; }
.bar .fill { display: block; height: 100%; background: var(--accent); border-radius: 3px; min-width: 2px; }
.bar .fill.err { background: var(--err); }
.bar .val { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--f-mono); font-size: 12.5px; }
.confirm { border: 1px solid var(--warn); background: var(--warn-soft); border-radius: 8px; padding: 12px 14px; display: grid; gap: 10px; }
.confirm h3 { color: var(--warn); }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.secret { font-family: var(--f-mono); font-size: 13px; background: var(--code-bg); border: 1px dashed var(--accent); border-radius: 8px; padding: 10px 12px; overflow-wrap: anywhere; }
td.neg { color: var(--err); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12.5px; border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; background: var(--panel); cursor: pointer; }
.chip[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.chip b { font-variant-numeric: tabular-nums; }
.scroll-y { max-height: 520px; overflow: auto; }
@media (max-width: 600px) { .bar { grid-template-columns: 90px 1fr 70px; } }

/* price editor */
.price-table td { padding: 4px 8px; vertical-align: middle; }
.price-table input { width: 100%; min-width: 0; padding: 5px 8px; }
.price-table input[type=date] { min-width: 140px; }
.price-table td:last-child { width: 1%; white-space: nowrap; }
.price-table .empty { padding: 18px 12px; }
