:root {
  --bg: #f6f7f9; --panel: #ffffff; --ink: #1c2430; --muted: #5d6b7c; --line: #e2e6ec;
  --accent: #1f5f99; --accent-ink: #ffffff; --accent-soft: #e6eef7;
  --good: #1e7a4c; --good-soft: #e3f3ea; --warn: #9a6200; --warn-soft: #fbf0d9;
  --bad: #a3322b; --bad-soft: #f8e3e1; --bar: #5b8fc7; --code: #f0f2f5;
  --radius: 8px; --shadow: 0 1px 2px rgba(20, 30, 45, .06), 0 1px 1px rgba(20, 30, 45, .04);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c; --panel: #1a2029; --ink: #e4e9f0; --muted: #98a4b3; --line: #2c3440;
    --accent: #6aa8e8; --accent-ink: #0d1520; --accent-soft: #1f2d3d;
    --good: #5cc28e; --good-soft: #17301f; --warn: #e2b252; --warn-soft: #33290f;
    --bad: #ef8a80; --bad-soft: #3a1c1a; --bar: #4f86c0; --code: #222a35;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 620; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 620; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* layout */
.topbar { background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar .inner { display: flex; align-items: center; gap: 22px; max-width: 1400px; margin: 0 auto; padding: 0 20px; height: 54px; }
.brand { font-weight: 700; color: var(--ink); white-space: nowrap; }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a { color: var(--muted); padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
.nav a.active, .nav a:hover { color: var(--ink); background: var(--accent-soft); text-decoration: none; }
.userbox { color: var(--muted); font-size: 13px; white-space: nowrap; }
.topsearch { flex: 0 1 300px; }
.topsearch input { width: 100%; }
main { max-width: 1400px; margin: 0 auto; padding: 24px 20px 60px; }
.pagehead { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } .topsearch { display: none; } }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 14px 18px 0; }
.kpi .label { color: var(--muted); font-size: 12.5px; }
.kpi .value { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; }
.section { margin-top: 22px; }

/* tables */
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; text-align: left; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--panel); position: sticky; top: 0; white-space: nowrap; }
tbody tr:hover { background: var(--accent-soft); }
td.desc { min-width: 260px; }
tr.superseded td { opacity: .5; }
tfoot td { font-weight: 650; border-top: 2px solid var(--line); }

/* forms */
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { width: 100%; min-height: 70px; }
.btn, button { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer; white-space: nowrap; color: var(--ink); display: inline-block; }
.btn:hover, button:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary, button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.small, button.small { padding: 2px 8px; font-size: 12.5px; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px 14px; }
.form-grid label, .stack label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* bits */
.badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11.5px; background: var(--code); color: var(--muted); white-space: nowrap; }
.badge.order_confirmation, .badge.call_off, .badge.high { background: var(--good-soft); color: var(--good); }
.badge.quote, .badge.rate_summary, .badge.medium { background: var(--accent-soft); color: var(--accent); }
.badge.budget, .badge.price_list, .badge.low { background: var(--warn-soft); color: var(--warn); }
.badge.none, .badge.error { background: var(--bad-soft); color: var(--bad); }
.flash { background: var(--accent-soft); border: 1px solid var(--line); padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; }
.bar { height: 8px; background: var(--code); border-radius: 4px; overflow: hidden; min-width: 80px; }
.bar > i { display: block; height: 100%; background: var(--bar); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--ink); border-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.hit { padding: 12px 0; border-bottom: 1px solid var(--line); }
.hit:last-child { border-bottom: 0; }
.hit .meta { color: var(--muted); font-size: 12.5px; }
.snippet { white-space: pre-wrap; font-family: var(--mono); font-size: 12px; background: var(--code); padding: 8px 10px; border-radius: 6px; margin-top: 6px; max-height: 170px; overflow: auto; }
.sim { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.pager { display: flex; gap: 6px; align-items: center; margin-top: 12px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
details > summary { cursor: pointer; color: var(--accent); }
.matches { background: var(--bg); border: 1px dashed var(--line); border-radius: 6px; padding: 10px; margin: 6px 0; }
.est-line input[type=text] { width: 100%; }
.est-line input.q { width: 90px; text-align: right; }
.est-line input.u { width: 64px; }
.est-line input.r { width: 100px; text-align: right; }
.est-line select { max-width: 150px; }
.htmx-request .spinner, .spinner.htmx-request { display: inline-block; }
.spinner { display: none; width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.login { max-width: 360px; margin: 10vh auto; }
.warnbox { background: var(--warn-soft); color: var(--warn); padding: 8px 12px; border-radius: 6px; font-size: 13px; }
