:root {
  --bg: #f5f6f8; --card: #ffffff; --ink: #1c1f24; --muted: #66707d; --line: #e2e6ea;
  --brand: #0b5fa5; --brand-ink: #ffffff; --accent: #e07b00; --ok: #1e8e3e; --bad: #c62828; --warn: #b26a00;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 1px 8px rgba(0,0,0,.04);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171b; --card: #1d2126; --ink: #e8ebef; --muted: #9aa4b1; --line: #2c333b;
    --brand: #4d9fe0; --brand-ink: #0c1218; --accent: #ffa33a; --ok: #4ccb6a; --bad: #ff6b6b; --warn: #ffb74d;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.45; color: var(--ink); background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 .75rem; }
h2 { font-size: 1.15rem; margin: 0 0 .5rem; }
h3 { font-size: 1rem; margin: 0 0 .4rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mt { margin-top: 1rem; } .mb { margin-bottom: 1rem; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: .75rem; }

/* nav */
.nav { background: var(--brand); color: var(--brand-ink); position: sticky; top: 0; z-index: 20; box-shadow: var(--shadow); }
.nav .inner { max-width: 1240px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 1rem; min-height: 52px; flex-wrap: wrap; }
.nav .brand { font-weight: 700; color: var(--brand-ink); font-size: 1.05rem; white-space: nowrap; display: flex; align-items: center; gap: .5rem; }
.nav .brand .logo { height: 28px; width: auto; max-width: 120px; border-radius: 4px; background: #fff; padding: 2px; }
.nav .who { display: flex; align-items: center; gap: .5rem; color: var(--brand-ink); }
.nav .who a { color: var(--brand-ink); }
.btn.ghost { background: transparent; color: var(--brand-ink); border-color: rgba(255,255,255,.5); }
.foot { max-width: 1240px; margin: 2rem auto 1rem; padding: 0 16px; color: var(--muted); font-size: .78rem; text-align: center; }
.nav .links { display: flex; gap: .15rem; flex: 1; flex-wrap: wrap; }
.nav .links a { color: var(--brand-ink); padding: .45rem .65rem; border-radius: 6px; opacity: .9; }
.nav .links a.active, .nav .links a:hover { background: rgba(255,255,255,.18); text-decoration: none; opacity: 1; }
.nav .pill { background: var(--accent); color: #fff; border-radius: 999px; padding: 0 .45rem; font-size: .75rem; margin-left: .25rem; }
.nav .who select { background: rgba(255,255,255,.15); color: var(--brand-ink); border: 1px solid rgba(255,255,255,.35); border-radius: 6px; padding: .3rem .4rem; font-size: .85rem; }
.nav .who option { color: #000; }
.nav .burger { display: none; background: none; border: 1px solid rgba(255,255,255,.5); color: var(--brand-ink); border-radius: 6px; padding: .3rem .55rem; font-size: 1.1rem; margin-left: auto; }
@media (max-width: 820px) {
  .nav .burger { display: inline-block; }
  .nav .links { display: none; width: 100%; flex-direction: column; padding-bottom: .5rem; }
  .nav .links.open { display: flex; }
  .nav .who { width: 100%; padding-bottom: .5rem; }
}

.container { max-width: 1240px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 1rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.tight { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }

.kpi { padding: 12px 14px; }
.kpi .v { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.kpi .l { color: var(--muted); font-size: .85rem; }

/* flash */
.flash { padding: .6rem .9rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash.ok { background: color-mix(in srgb, var(--ok) 12%, var(--card)); border-color: var(--ok); }
.flash.err { background: color-mix(in srgb, var(--bad) 12%, var(--card)); border-color: var(--bad); }

/* badges */
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .76rem; font-weight: 600; letter-spacing: .02em; color: #fff; background: var(--muted); white-space: nowrap; }
.badge.new { background: #2f6fd1; } .badge.quoting { background: #b26a00; } .badge.quoted { background: #6f42c1; }
.badge.negotiation { background: #d9541e; } .badge.won { background: var(--ok); } .badge.lost { background: var(--bad); } .badge.dropped { background: #7a8592; }
.badge.urgent { background: var(--bad); } .badge.high { background: var(--accent); } .badge.normal, .badge.low { background: var(--muted); }
.badge.soft { background: var(--line); color: var(--ink); font-weight: 500; }
.conf { font-variant-numeric: tabular-nums; }
.conf.hi { color: var(--ok); } .conf.mid { color: var(--warn); } .conf.lo { color: var(--bad); }

/* buttons + forms */
.btn { display: inline-block; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: .45rem .8rem; border-radius: 8px; cursor: pointer; font: inherit; font-size: .9rem; line-height: 1.2; text-decoration: none; }
.btn:hover { border-color: var(--brand); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.ok { color: var(--ok); border-color: var(--ok); }
.btn.sm { padding: .25rem .55rem; font-size: .8rem; }
.btn.ai::before { content: "\2726 "; color: var(--accent); }
input, select, textarea { font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .55rem; width: 100%; max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand); }
input[type=checkbox], input[type=radio] { width: auto; }
textarea { min-height: 90px; resize: vertical; }
label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: .2rem; }
.field { min-width: 0; }
.form-grid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); align-items: end; }
.form-grid .wide { grid-column: 1 / -1; }
.inline-form { display: inline; }
.filters { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); align-items: end; }
.actions { display: flex; gap: .4rem; flex-wrap: wrap; }

/* tables */
.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tbl th, .tbl td { padding: .5rem .5rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl tr:hover td { background: color-mix(in srgb, var(--brand) 5%, transparent); }
.tbl input, .tbl select { padding: .3rem .4rem; font-size: .88rem; }
.tbl .w-qty { width: 5.5rem; } .tbl .w-rate { width: 7rem; } .tbl .w-unit { width: 5rem; } .tbl .w-status { width: 7rem; }
.tbl-wrap { overflow-x: auto; }
@media (max-width: 720px) {
  .tbl.stack thead { display: none; }
  .tbl.stack tr { display: block; border: 1px solid var(--line); border-radius: 8px; margin-bottom: .6rem; padding: .35rem .5rem; background: var(--card); }
  .tbl.stack td { display: flex; gap: .6rem; justify-content: space-between; border: 0; padding: .28rem 0; text-align: left !important; white-space: normal; }
  .tbl.stack td::before { content: attr(data-label); color: var(--muted); font-size: .78rem; flex: 0 0 38%; }
  .tbl.stack td.no-label::before { content: none; }
  .tbl.stack td.no-label { display: block; }
  .tbl.stack .w-qty, .tbl.stack .w-rate, .tbl.stack .w-unit, .tbl.stack .w-status { width: auto; }
  .tbl input, .tbl select { width: 100%; }
}

/* bars */
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); }
.bar.bad > span { background: var(--bad); }

/* timeline */
.tl { list-style: none; margin: 0; padding: 0; }
.tl li { padding: .5rem 0 .5rem 1rem; border-left: 3px solid var(--line); margin-left: .3rem; }
.tl li .k { font-size: .78rem; font-weight: 600; text-transform: uppercase; color: var(--muted); }
.tl li.email_in { border-color: var(--brand); } .tl li.email_out, .tl li.quote_sent { border-color: var(--accent); } .tl li.close { border-color: var(--bad); }
.tl pre { white-space: pre-wrap; font: inherit; margin: .2rem 0 0; }

/* search dropdown */
.ps-wrap { position: relative; }
.ps-list { position: absolute; z-index: 30; left: 0; right: 0; top: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); max-height: 260px; overflow-y: auto; display: none; }
.ps-list.open { display: block; }
.ps-list div { padding: .4rem .6rem; cursor: pointer; border-bottom: 1px solid var(--line); font-size: .88rem; }
.ps-list div:hover, .ps-list div.hl { background: color-mix(in srgb, var(--brand) 10%, transparent); }
.ps-list .m { color: var(--muted); font-size: .78rem; }
.ps-chosen { font-size: .82rem; color: var(--ok); margin-top: .2rem; }

/* dialog */
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog .dlg { padding: 16px; }
dialog h2 { margin-top: 0; }

/* tabs (details) */
details.card summary { cursor: pointer; font-weight: 600; }
details.card[open] summary { margin-bottom: .6rem; }

/* narrative */
.narrative { line-height: 1.55; }
.narrative h3, .narrative h4 { margin-top: 1rem; }

/* quote print */
.quote { background: #fff; color: #000; max-width: 900px; margin: 0 auto; padding: 24px; }
.quote .hdr { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; border-bottom: 2px solid #000; padding-bottom: .5rem; margin-bottom: 1rem; }
.quote .tbl th, .quote .tbl td { border-bottom: 1px solid #999; color: #000; }
@media print { .nav, .noprint { display: none !important; } body { background: #fff; } .container { padding: 0; max-width: none; } .card { border: 0; box-shadow: none; } }

/* dashboard: funnel, stage tiles, trend, board */
.funnel { display: grid; gap: .45rem; }
.fstep { display: grid; grid-template-columns: minmax(120px, 160px) 1fr 48px; gap: .6rem; align-items: center; }
.flabel span { display: block; line-height: 1.1; }
.fbar { position: relative; height: 26px; background: var(--line); border-radius: 6px; overflow: hidden; }
.fbar > span { display: block; height: 100%; background: var(--brand); border-radius: 6px 4px 4px 6px; opacity: .85; }
.fbar > em { position: absolute; inset: 0; display: flex; align-items: center; padding-left: .5rem; font-style: normal; font-size: .82rem; color: var(--ink); mix-blend-mode: normal; text-shadow: 0 0 6px var(--card); }
.fconv { text-align: right; font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.stages { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
.stage-tile { display: block; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 8px; text-decoration: none; color: var(--ink); }
.stage-tile:hover { border-color: var(--brand); text-decoration: none; }
.stage-tile .v { font-size: 1.3rem; font-weight: 700; margin-top: .2rem; }
.trend { display: grid; grid-template-columns: repeat(6, 1fr); gap: .5rem; height: 150px; align-items: end; }
.tcol { display: flex; flex-direction: column; align-items: stretch; height: 100%; }
.tbars { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 3px; border-bottom: 1px solid var(--line); padding: 0 4px; }
.tbars span { display: block; width: 22%; min-height: 2px; border-radius: 3px 3px 0 0; }
.t-rec { background: color-mix(in srgb, var(--muted) 55%, transparent); }
.t-won { background: var(--ok); }
.t-lost { background: var(--bad); }
.tlab { text-align: center; font-size: .8rem; margin-top: .25rem; }
.tnum { text-align: center; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 1rem; margin-top: .4rem; color: var(--muted); }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: middle; margin-right: .3rem; }
.board { display: grid; gap: .75rem; grid-template-columns: repeat(4, minmax(220px, 1fr)); overflow-x: auto; align-items: start; }
.bcol { background: color-mix(in srgb, var(--line) 45%, var(--bg)); border-radius: 10px; padding: .5rem; min-height: 200px; }
.bhead { display: flex; justify-content: space-between; align-items: center; padding: .25rem .3rem .5rem; }
.bcard { display: block; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .6rem; margin-bottom: .5rem; color: var(--ink); text-decoration: none; box-shadow: var(--shadow); }
.bcard:hover { border-color: var(--brand); text-decoration: none; }
.bcard.stale { border-left: 3px solid var(--warn); }
@media (max-width: 900px) { .board { grid-template-columns: repeat(4, 240px); } .fstep { grid-template-columns: 100px 1fr 40px; } }
