:root {
  --fg: #1c2230; --muted: #6b7385; --faint: #9aa1b1; --line: #e4e7ed; --bg: #f5f6f8; --card: #fff;
  --accent: #2f5fd0; --accent-soft: #eaf0fd; --danger: #c0392b; --ok: #1e7a3a; --warn: #a85d00;
  --radius: 8px;
}
* { box-sizing: border-box; }
[x-cloak] { display: none !important; }
body { margin: 0; font: 14px/1.5 -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif; color: var(--fg); background: var(--bg); }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 2px 0 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h2 { font-size: 17px; margin: 0; } h3 { font-size: 15px; margin: 0; } h4 { font-size: 12px; margin: 0 0 6px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }

.top { display: flex; gap: 24px; align-items: center; padding: 10px 24px; background: #1c2230; color: #fff; flex-wrap: wrap; }
.top a { color: #d6deef; } .brand { font-weight: 700; color: #fff !important; }
.top nav { display: flex; gap: 18px; flex: 1; }
.who { margin: 0; color: #9aa6bf; } .who .link { color: #d6deef; }
main { max-width: 1240px; margin: 0 auto; padding: 18px 24px 80px; }

.muted { color: var(--muted); font-weight: normal; } .small { font-size: 12px; } .strong { font-weight: 600; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; } .pre { white-space: pre-wrap; } .break { word-break: break-all; }
.clip { max-width: 520px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clip-s { display: inline-block; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.grow { flex: 1; } .num { text-align: right; font-variant-numeric: tabular-nums; }
.flash { background: #fff8e1; border: 1px solid #f0d98a; padding: 8px 12px; border-radius: var(--radius); margin: 0 0 12px; }
.empty { color: var(--faint); text-align: center; padding: 28px 0 !important; }
.hint { color: var(--faint); font-size: 12px; }

/* buttons */
button, .btn { font: inherit; padding: 6px 14px; border-radius: 6px; border: 1px solid var(--accent); background: var(--accent); color: #fff; cursor: pointer; display: inline-block; line-height: 1.4; }
button:disabled { opacity: .6; cursor: default; }
.btn { background: #fff; color: var(--accent); border-color: #c9d5f2; }
.btn:hover { background: var(--accent-soft); text-decoration: none; }
.small.btn, .btn.small { padding: 3px 10px; font-size: 12.5px; }
button.link { background: none; border: none; padding: 0; color: var(--accent); }
button.icon { background: none; border: none; color: var(--muted); padding: 2px 6px; font-size: 14px; }
.danger { color: var(--danger) !important; }

/* page head + kpis */
.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.summary { margin: -6px 0 12px; color: var(--muted); }
.amt + .amt::before { content: " · "; color: var(--faint); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 18px; }
.kpis > div { background: var(--card); padding: 10px 14px; display: flex; flex-direction: column; }
.kpis b { font-size: 17px; font-weight: 600; } .kpis > div > span { color: var(--muted); font-size: 12px; }

/* chips */
.chip { display: inline-block; padding: 0 8px; border-radius: 10px; font-size: 12px; font-weight: normal; background: #eef0f4; color: #4b5263; line-height: 20px; white-space: nowrap; }
.s-active, .d-accepted { background: #e3f4e8; color: var(--ok); }
.s-sampling { background: var(--accent-soft); color: var(--accent); }
.s-paused, .d-staged { background: #fff1de; color: var(--warn); }
.s-closed, .d-cancelled { color: var(--faint); }
.d-rejected { background: #fde8e6; color: var(--danger); }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--fg); text-decoration: none; }
.tabs a.on { color: var(--fg); border-bottom-color: var(--accent); font-weight: 600; }
.tabs a span { color: var(--faint); font-weight: normal; font-size: 12px; margin-left: 2px; }
.bar { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }

/* tables */
table.list { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table.list th, table.list td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list th { font-weight: 500; font-size: 12px; color: var(--muted); background: #fafbfc; white-space: nowrap; }
table.list th.num, table.list td.num { text-align: right; }
.rowlink { cursor: pointer; } .rowlink:hover td { background: #f8f9fc; }
tr.dim td { color: var(--faint); }
tbody.expanded > tr:first-child td { background: #f6f8fd; border-bottom-color: transparent; }
tr.detail > td { background: #f6f8fd; padding: 4px 16px 16px !important; }
.chev { color: var(--faint); width: 20px; font-size: 16px; }
.chev span { display: inline-block; transition: transform .15s; }
.chev.up span { transform: rotate(90deg); }
.mixbar { display: inline-flex; width: 64px; height: 8px; border-radius: 4px; overflow: hidden; vertical-align: middle; margin-right: 6px; background: #eef0f4; }
.mixbar i { display: block; height: 100%; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.editable { border-bottom: 1px dashed #b7c3dd; cursor: text; padding: 0 2px; }
.editable:hover { background: var(--accent-soft); }
.inline-edit input { width: auto; padding: 2px 6px; font-size: 13px; text-align: right; }
.money-edit { display: inline-flex; gap: 4px; align-items: center; }
.money-edit select { width: auto; padding: 2px 4px; font-size: 13px; }
.money-edit button { padding: 2px 8px; }
.price { margin: 4px 0 0; font-size: 14px; display: flex; gap: 8px; align-items: baseline; }
.clip-cell { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px 28px; padding-top: 6px; }
table.mini { border-collapse: collapse; width: 100%; }
table.mini td { padding: 2px 6px 2px 0; font-size: 13px; }
dl { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; margin: 0; font-size: 13px; }
dt { color: var(--muted); } dd { margin: 0; min-width: 0; }
dl.wide { grid-template-columns: 90px 1fr; gap: 10px 16px; font-size: 14px; margin-bottom: 14px; }
.notes { white-space: pre-wrap; font-size: 13px; color: #424a5b; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; margin-top: 10px; }
.detail-actions { margin-top: 10px; }
.copyable { cursor: copy; } .copyable:hover { background: var(--accent-soft); }

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.card-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.cards .card { margin: 0; } .cards .card p { margin: 0 0 8px; }
.narrow { max-width: 360px; margin: 60px auto; display: flex; flex-direction: column; gap: 12px; }
.older { margin-top: 10px; color: var(--muted); } .older summary { cursor: pointer; }

/* rendered markdown */
.md { font-size: 13.5px; line-height: 1.6; overflow-wrap: anywhere; }
.md.folded { max-height: 220px; overflow: hidden; -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); }
.md h1, .md h2, .md h3 { font-size: 14px; margin: 12px 0 4px; display: block; }
.md p, .md ul, .md ol { margin: 4px 0 8px; } .md ul, .md ol { padding-left: 20px; }
.md code { font-family: ui-monospace, monospace; font-size: 12px; background: #f1f3f6; padding: 0 4px; border-radius: 3px; }
.md pre { background: #f1f3f6; padding: 8px 10px; border-radius: 6px; overflow-x: auto; }
.md table { border-collapse: collapse; margin: 6px 0; font-size: 12.5px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; vertical-align: top; }

/* forms */
input, select, textarea { font: inherit; padding: 6px 9px; border: 1px solid #cdd2dc; border-radius: 6px; background: #fff; width: 100%; color: var(--fg); }
input:focus, select:focus, textarea:focus { outline: 2px solid #c9d7f7; border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 3px; }
.flabel { font-size: 12px; color: var(--muted); }
.upload input[name=note] { flex: 1; min-width: 220px; width: auto; } .upload input[type=file] { width: auto; }

/* drawer */
.scrim { position: fixed; inset: 0; background: rgba(20, 25, 35, .35); z-index: 10; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(620px, 100vw); background: var(--card); z-index: 11; box-shadow: -8px 0 30px rgba(0, 0, 0, .12); transition: transform .18s ease; }
.drawer.off { transform: translateX(100%); }
.drawer form { display: flex; flex-direction: column; height: 100%; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.drawer-body { flex: 1; overflow-y: auto; padding: 6px 20px 20px; }
.drawer-foot { display: flex; gap: 10px; align-items: center; padding: 12px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.drawer .error { color: var(--danger); margin: 0; width: 100%; }
fieldset { border: none; padding: 0; margin: 14px 0 0; }
legend { font-size: 12px; font-weight: 600; color: var(--fg); padding: 0; margin-bottom: 8px; }
.fgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.fgrid label.wide { grid-column: 1 / -1; }
.models-edit { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.mrow { display: grid; grid-template-columns: 2fr 1.2fr 1fr 70px 28px; gap: 6px; align-items: center; width: 100%; }
.mhead span { font-size: 11px; color: var(--faint); }

@media (max-width: 760px) {
  main { padding: 12px 16px 60px; }
  table.list { display: block; overflow-x: auto; }
  .fgrid { grid-template-columns: 1fr; }
}
