:root {
  --bg: #0f172a;          /* slate-900, same base as Trend Scout */
  --panel: #111c33;
  --panel-2: #16223d;
  --line: #24314f;
  --line-2: #2f3d5f;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --faint: #64748b;
  --accent: #ef4444;      /* fire-alarm red */
  --accent-2: #f87171;
  --accent-ink: #fff;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --info: #60a5fa;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.num, td.money, .kpi .v { font-variant-numeric: tabular-nums; }
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: #0b1222; border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; text-decoration: none; }
.brand img { width: 30px; height: 30px; }
.brand b { display: block; font-size: 15px; letter-spacing: -.01em; }
.brand small { display: block; color: var(--faint); font-size: 11px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--panel-2); color: var(--text); }
.nav a.on { background: var(--panel-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .sep { height: 1px; background: var(--line); margin: 10px 6px; }
.side .me { margin-top: auto; padding: 10px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.side .me b { color: var(--text); display: block; font-size: 13px; }
.side .me button { margin-top: 6px; }
main { min-width: 0; padding: 26px 32px 80px; max-width: 1280px; }

.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.head h1 { font-size: 22px; letter-spacing: -.02em; margin: 0; }
.head .sub { color: var(--muted); margin-top: 2px; }
.crumbs { color: var(--faint); font-size: 12px; margin-bottom: 4px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--text); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--panel-2); cursor: pointer; text-decoration: none; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #dc2626; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--info); cursor: pointer; text-decoration: none; }
.link:hover { text-decoration: underline; }

input, select, textarea { width: 100%; background: #0b1222; border: 1px solid var(--line-2); border-radius: 8px; padding: 9px 11px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--info); box-shadow: 0 0 0 3px rgba(96,165,250,.15); }
textarea { min-height: 84px; resize: vertical; }
input[type=date] { color-scheme: dark; }
label.f { display: flex; flex-direction: column; gap: 5px; }
label.f > span { font-size: 12px; font-weight: 600; color: var(--muted); }
label.f > span em { color: var(--accent-2); font-style: normal; }
label.f small { color: var(--faint); font-size: 12px; }
.ro { padding: 9px 0; font-weight: 600; }

.toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input { max-width: 340px; }
.toolbar select { width: auto; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 5px 11px; border-radius: 999px; border: 1px solid var(--line-2); background: transparent; cursor: pointer; font-size: 13px; color: var(--muted); }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ---------- surfaces ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.card > h2, .card > header { font-size: 14px; margin: 0; padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card > header h2 { font-size: 14px; margin: 0; }
.card .body { padding: 16px; }
.empty { padding: 26px 16px; color: var(--faint); text-align: center; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); font-weight: 600; background: var(--panel); position: sticky; top: 0; }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--panel-2); }
tbody tr:last-child td { border-bottom: 0; }
td.money, th.money { text-align: right; }
.tablewrap { overflow-x: auto; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #1e293b; color: var(--muted); white-space: nowrap; }
.badge.good { background: rgba(52,211,153,.12); color: var(--good); }
.badge.warn { background: rgba(251,191,36,.12); color: var(--warn); }
.badge.bad { background: rgba(248,113,113,.14); color: var(--bad); }
.badge.info { background: rgba(96,165,250,.14); color: var(--info); }

/* ---------- dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { padding: 16px; text-decoration: none; display: block; }
.kpi:hover { border-color: var(--line-2); }
.kpi .l { font-size: 12px; color: var(--muted); font-weight: 500; }
.kpi .v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin: 4px 0 2px; }
.kpi .s { font-size: 12px; color: var(--faint); }
.kpi.alert .v { color: var(--bad); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.stack { display: grid; gap: 16px; }
.opp { list-style: none; margin: 0; padding: 0; }
.opp li { padding: 11px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.opp li:last-child { border-bottom: 0; }
.opp .t { font-weight: 500; }
.opp .d { color: var(--faint); font-size: 12px; white-space: pre-line; }
.tabs { display: flex; gap: 2px; padding: 8px 8px 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 8px 12px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.tabs .n { margin-left: 6px; font-size: 11px; background: #1e293b; padding: 1px 6px; border-radius: 999px; }
.tabs button.on .n { background: var(--accent); color: #fff; }

/* ---------- forms & detail ---------- */
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.form .wide { grid-column: 1 / -1; }
.formbar { display: flex; gap: 8px; justify-content: space-between; padding: 14px 16px; border-top: 1px solid var(--line); background: var(--panel); position: sticky; bottom: 0; border-radius: 0 0 var(--radius) var(--radius); }
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; margin: 0; }
.kv dt { color: var(--faint); font-size: 12px; padding-top: 2px; }
.kv dd { margin: 0; white-space: pre-line; word-break: break-word; }
.err { color: var(--bad); margin-top: 10px; }

.lines { width: 100%; }
.lines td, .lines th { padding: 6px 4px; border: 0; background: none; }
.lines tbody tr { cursor: default; }
.lines tbody tr:hover td { background: none; }
.lines input { padding: 7px 9px; }
.lines .qty { width: 80px; } .lines .price { width: 120px; } .lines .ext { width: 110px; text-align: right; padding-top: 14px; } .lines .x { width: 34px; }
.totals { margin-left: auto; width: 280px; margin-top: 8px; }
.totals div { display: flex; justify-content: space-between; padding: 3px 0; color: var(--muted); }
.totals div.g { color: var(--text); font-weight: 700; font-size: 16px; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 4px; }

/* ---------- assistant ---------- */
.chat { display: flex; flex-direction: column; height: calc(100vh - 140px); min-height: 420px; }
.msgs { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 760px; padding: 11px 14px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: #1e3a8a; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg .acts { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.msg.thinking { color: var(--muted); font-style: italic; }
.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.composer textarea { min-height: 46px; max-height: 160px; }
.starters { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 18px 4px; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(800px 400px at 50% -10%, rgba(239,68,68,.12), transparent), var(--bg); }
.auth .card { width: 100%; max-width: 380px; padding: 28px; }
.auth h1 { font-size: 20px; margin: 14px 0 4px; }
.auth p { color: var(--muted); margin: 0 0 18px; }
.auth form { display: grid; gap: 12px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: #f8fafc; color: #0f172a; padding: 10px 16px; border-radius: 8px; font-weight: 500; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; box-shadow: var(--shadow); max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--bad); color: #fff; }

/* ---------- printable quote ---------- */
.print-page { background: #fff; color: #111827; min-height: 100vh; }
.print-page .sheet { max-width: 800px; margin: 0 auto; padding: 48px 40px; }
.print-page .bar { background: var(--bg); padding: 12px; display: flex; justify-content: center; gap: 8px; }
.print-page header.q { display: flex; justify-content: space-between; border-bottom: 3px solid #b91c1c; padding-bottom: 16px; margin-bottom: 24px; }
.print-page header.q h1 { margin: 0; font-size: 22px; }
.print-page header.q .co { color: #4b5563; font-size: 13px; }
.print-page .qt { text-align: right; }
.print-page .qt h2 { margin: 0; color: #b91c1c; letter-spacing: .1em; font-size: 20px; }
.print-page .to { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 24px; font-size: 13px; }
.print-page .to h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #6b7280; margin: 0 0 4px; }
.print-page table th { background: #f3f4f6; color: #374151; position: static; }
.print-page table td, .print-page table th { border-color: #e5e7eb; }
.print-page tbody tr { cursor: default; }
.print-page tbody tr:hover td { background: none; }
.print-page .totals div { color: #374151; }
.print-page .totals div.g { color: #111827; border-color: #d1d5db; }
.print-page .scope { white-space: pre-line; margin: 20px 0; font-size: 13px; }
.print-page .sign { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 48px; font-size: 12px; color: #4b5563; }
.print-page .sign div { border-top: 1px solid #9ca3af; padding-top: 6px; }
@media print { .print-page .bar { display: none; } .print-page .sheet { padding: 0; } @page { margin: 16mm; } }

/* ---------- mobile ---------- */
.mobilebar { display: none; }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  main { padding: 16px 16px 96px; }
  .mobilebar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: #0b1222; border-top: 1px solid var(--line); z-index: 20; padding-bottom: env(safe-area-inset-bottom); }
  .mobilebar a { flex: 1; text-align: center; padding: 8px 2px; color: var(--muted); text-decoration: none; font-size: 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
  .mobilebar a.on { color: var(--text); }
  .mobilebar svg { width: 20px; height: 20px; }
  .grid2, .detail { grid-template-columns: 1fr; }
  .form { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 110px 1fr; }
  .hide-sm { display: none; }
  .chat { height: calc(100vh - 170px); }
  .toolbar input { max-width: none; }
}

/* ---------- refinements ---------- */
.btn svg { width: 16px; height: 16px; flex: none; }
.kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.opp li > div:last-child:not(:first-child) { display: flex; gap: 4px; flex-wrap: nowrap; flex: none; }
.print-page .bar .btn:not(.primary) { color: var(--text); }
@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px; }
  .kpi .v { font-size: 20px; }
  .head .actions { width: 100%; }
  .head .actions .btn { flex: 1; justify-content: center; }
}

/* ---------- inspection report form ---------- */
.hidden { display: none !important; }
.savestate { align-self: center; color: var(--faint); font-size: 12px; }
.rpt { display: grid; gap: 16px; }
.rpt .card > h2, .rpt .card > header { font-size: 15px; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; flex: none; }
.seg button { background: transparent; border: 0; padding: 7px 11px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 13px; min-width: 46px; }
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button.on.pass { background: rgba(52,211,153,.18); color: var(--good); }
.seg button.on.fail { background: rgba(248,113,113,.22); color: var(--bad); }
.seg button.on.na { background: #1e293b; color: var(--text); }
.ckgroup { margin-bottom: 18px; }
.ckgroup:last-child { margin-bottom: 0; }
.ckhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.ckhead b { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.ckrow { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.ckrow .cknote { grid-column: 1 / -1; }
.devsummary { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.pill { background: #1e293b; border-radius: 999px; padding: 3px 10px; font-size: 12px; color: var(--muted); }
.pill b { color: var(--text); }
.pill em { color: var(--bad); font-style: normal; }
.pill.ok { color: var(--good); } .pill.warn { color: var(--warn); } .pill.bad { color: var(--bad); }
.devtools { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.devtools input[type=search] { max-width: 360px; }
.chk { display: flex; gap: 6px; align-items: center; white-space: nowrap; color: var(--muted); }
.chk input { width: auto; }
.devlist { display: grid; gap: 6px; }
.dev { display: grid; grid-template-columns: 160px 110px minmax(140px, 1fr) 150px auto minmax(120px, 1fr) 34px; gap: 6px; align-items: center; padding: 6px; border: 1px solid var(--line); border-radius: 8px; }
.dev.failed { border-color: rgba(248,113,113,.5); background: rgba(248,113,113,.05); }
.dev input, .dev select { padding: 7px 9px; }
.devadd { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.devadd select { width: auto; }
canvas.sig { width: 100%; max-width: 600px; aspect-ratio: 600 / 180; background: #f8fafc; border-radius: 8px; border: 1px solid var(--line-2); touch-action: none; display: block; cursor: crosshair; }
.f .link { align-self: flex-start; margin-top: 4px; font-size: 13px; }
.rptbar { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 8px; padding: 12px 0; margin-top: 16px; background: linear-gradient(transparent, var(--bg) 30%); }
@media (max-width: 1100px) {
  .dev { grid-template-columns: 1fr 1fr; }
  .dev .loc, .dev .note { grid-column: 1 / -1; }
  .dev .seg { justify-self: start; }
  .dev .x { justify-self: end; }
}
@media (max-width: 900px) {
  .rptbar { bottom: 58px; }
  .rptbar .btn { flex: 1; justify-content: center; }
  .seg button { padding: 9px 12px; }
  .devtools { flex-wrap: wrap; }
}

/* ---------- printable inspection report ---------- */
.draftnote { background: #fef3c7; color: #92400e; text-align: center; padding: 8px; font-weight: 700; letter-spacing: .1em; }
.rpt-print { font-size: 12.5px; }
.rpt-print .qt h2 { font-size: 16px; }
.rpt-print h3.sec { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: #b91c1c; margin: 22px 0 8px; border-bottom: 1px solid #e5e7eb; padding-bottom: 4px; }
.rpt-print dl.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 16px; margin: 0; }
.rpt-print dl.grid dt { font-size: 10.5px; color: #6b7280; text-transform: uppercase; letter-spacing: .04em; }
.rpt-print dl.grid dd { margin: 0; font-weight: 600; }
.rpt-print table { font-size: 12px; }
.rpt-print th, .rpt-print td { padding: 5px 8px; }
.rpt-print tr.grp td { background: #f9fafb; font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: #4b5563; }
.rpt-print .f { color: #b91c1c; font-weight: 700; }
.rpt-print .p { color: #047857; font-weight: 600; }
.rpt-print .w { color: #b45309; }
.rpt-print .verdict { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 8px 0 4px; }
.rpt-print .verdict > div { border: 1px solid #e5e7eb; border-radius: 8px; padding: 10px 12px; }
.rpt-print .verdict span { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: #6b7280; }
.rpt-print .verdict b { font-size: 15px; }
.rpt-print .tag { padding: 1px 8px; border-radius: 4px; }
.rpt-print .tag.blue { background: #dbeafe; color: #1e40af; }
.rpt-print .tag.yellow { background: #fef9c3; color: #854d0e; }
.rpt-print .tag.red { background: #fee2e2; color: #b91c1c; }
.rpt-print ol.defs { margin: 0; padding-left: 20px; }
.rpt-print ol.defs li { margin-bottom: 3px; }
.rpt-print .remarks, .rpt-print .cert { white-space: pre-line; }
.rpt-print .sigs { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 18px; }
.rpt-print .sigs img { height: 64px; display: block; }
.rpt-print .sigs .blank { height: 64px; }
.rpt-print .sigs .line { border-top: 1px solid #9ca3af; padding-top: 6px; font-size: 12px; color: #374151; }
.rpt-print .foot { margin-top: 26px; font-size: 11px; color: #6b7280; }
@media print { .draftnote { -webkit-print-color-adjust: exact; print-color-adjust: exact; } .rpt-print tr { break-inside: avoid; } .rpt-print .tag, .rpt-print tr.grp td { -webkit-print-color-adjust: exact; print-color-adjust: exact; } }
@media (max-width: 700px) { .rpt-print dl.grid { grid-template-columns: 1fr 1fr; } .rpt-print .verdict { grid-template-columns: 1fr 1fr; } .print-page .sheet { padding: 24px 16px; } .print-page .bar { flex-wrap: wrap; } }
