/* Brand Funnel — ledger-style workspace: dark pine sidebar, paper-white work surface, one copper accent */
:root {
  --bg: #f5f6f3;
  --surface: #ffffff;
  --surface-2: #eef0ec;
  --line: #dcdfd8;
  --ink: #18201d;
  --muted: #5f6a64;
  --side: #13261f;
  --side-ink: #d8e3dc;
  --side-muted: #8fa59a;
  --accent: #b5562a;
  --accent-ink: #ffffff;
  --accent-soft: #f6e4d9;
  --ok: #1f7a4d;
  --ok-soft: #dcefe4;
  --warn: #9a6a00;
  --warn-soft: #f7ecd0;
  --bad: #b3261e;
  --bad-soft: #f8dcd9;
  --info: #2c5f8a;
  --info-soft: #dde8f2;
  --focus: #b5562a;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --display: "Fraunces", Georgia, serif;
  --r: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412; --surface: #161d1a; --surface-2: #1d2622; --line: #2b3631; --ink: #e4ebe7; --muted: #94a39b;
    --side: #0a110e; --side-ink: #d8e3dc; --side-muted: #7f978b;
    --accent: #e0814f; --accent-ink: #1a0f08; --accent-soft: #3a2418;
    --ok: #5cc28c; --ok-soft: #173326; --warn: #e2b44a; --warn-soft: #362b12; --bad: #f08a80; --bad-soft: #3d1c19; --info: #7fb2de; --info-soft: #182a3a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
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; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1, h2, h3 { margin: 0; line-height: 1.25; text-wrap: balance; }
h1 { font-family: var(--display); font-weight: 500; font-size: 26px; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.sm { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
[hidden] { display: none !important; }

/* layout */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 18px 12px; gap: 18px; }
.side-brand { display: flex; align-items: center; gap: 10px; font-weight: 600; padding: 0 8px; }
.brand-mark { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-family: var(--display); font-size: 18px; }
.brand-mark.sm { width: 30px; height: 30px; font-size: 13px; border-radius: 7px; }
.side nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side nav a { color: var(--side-ink); padding: 8px 10px; border-radius: 6px; display: flex; justify-content: space-between; align-items: center; }
.side nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.side nav a.on { background: rgba(255,255,255,.1); color: #fff; }
.side nav a.nav-add { color: var(--accent); font-weight: 500; }
.side-foot { border-top: 1px solid rgba(255,255,255,.08); padding: 12px 8px 0; display: flex; flex-direction: column; gap: 6px; }
.side-foot .muted { color: var(--side-muted); }
.side .link { color: var(--side-muted); }
.badge { background: var(--accent); color: var(--accent-ink); border-radius: 999px; font-size: 11px; padding: 0 7px; font-weight: 600; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 10px; padding: 12px max(20px, env(safe-area-inset-right)) 12px max(20px, env(safe-area-inset-left)); border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.gsearch { flex: 1; max-width: 640px; }
.gsearch input { width: 100%; }
.icon-btn { display: none; background: none; border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; }
.view { padding: 22px max(20px, env(safe-area-inset-right)) 48px max(20px, env(safe-area-inset-left)); display: flex; flex-direction: column; gap: 18px; max-width: 1400px; width: 100%; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .icon-btn { display: inline-block; }
}

/* building blocks */
.row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.gap-s { gap: 6px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); }
.grid-3 { display: grid; gap: 14px; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .grid-3 { grid-template-columns: 1fr; } }
.kpis { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.kpi span { color: var(--muted); font-size: 12px; }
.kpi strong { font-family: var(--display); font-weight: 500; font-size: 26px; font-variant-numeric: tabular-nums; }
.kpi.alert-k strong { color: var(--bad); }
a.kpi:hover { border-color: var(--accent); text-decoration: none; }
a.kpi { color: inherit; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); padding: 7px 12px; border-radius: 6px; cursor: pointer; white-space: nowrap; color: var(--ink); }
.btn:hover { border-color: var(--muted); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 500; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; }
input:not([type=checkbox]):not([type=radio]), select, textarea { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 7px 10px; min-width: 0; }
textarea { width: 100%; resize: vertical; min-height: 64px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 500; }
label input, label select, label textarea { color: var(--ink); font-size: 14px; font-weight: 400; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 13px; color: var(--ink); }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
fieldset { border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; display: grid; gap: 10px; margin: 0; }
legend { padding: 0 6px; font-weight: 600; font-size: 13px; }
.alert { padding: 10px 12px; border-radius: 6px; font-size: 13px; }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.bad { background: var(--bad-soft); color: var(--bad); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.info { background: var(--info-soft); color: var(--info); }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
td { white-space: nowrap; }
td.wrap { white-space: normal; }
th { font-size: 12px; color: var(--muted); font-weight: 500; background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.trunc { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tr.click { cursor: pointer; }
.card table th { background: transparent; position: static; }

/* stage pills */
.pill { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 999px; white-space: nowrap; font-weight: 500; background: var(--surface-2); color: var(--muted); }
.pill.s-email1, .pill.s-email2, .pill.s-email3 { background: var(--info-soft); color: var(--info); }
.pill.s-replied { background: var(--warn-soft); color: var(--warn); }
.pill.s-price_list, .pill.s-approved, .pill.s-ordered { background: var(--ok-soft); color: var(--ok); }
.pill.s-rejected { background: var(--bad-soft); color: var(--bad); }
.pill.f-repeat, .pill.f-after_colleague { background: var(--bad-soft); color: var(--bad); }
.pill.f-unique, .pill.f-first { background: var(--ok-soft); color: var(--ok); }
.pill.f-shared_unclear, .pill.f-same_day { background: var(--warn-soft); color: var(--warn); }
.overdue { color: var(--bad); font-weight: 500; }

/* stage stepper */
.stepper { display: flex; flex-wrap: wrap; gap: 0; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--surface); }
.stepper button { flex: 1 1 110px; border: 0; border-right: 1px solid var(--line); background: none; padding: 9px 8px; cursor: pointer; font-size: 12.5px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 1px; }
.stepper button:last-child { border-right: 0; }
.stepper button small { font-size: 11px; font-family: var(--mono); }
.stepper button.done { color: var(--ok); background: var(--ok-soft); }
.stepper button.cur { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.stepper button.rej.cur { background: var(--bad); color: #fff; }
.stepper button:disabled { cursor: default; }

/* funnel bars */
.fbars { display: flex; flex-direction: column; gap: 8px; }
.fbar { display: grid; grid-template-columns: 140px 1fr 60px; gap: 10px; align-items: center; font-size: 13px; }
.fbar .track { background: var(--surface-2); border-radius: 4px; height: 16px; overflow: hidden; }
.fbar .fill { height: 100%; background: var(--accent); border-radius: 4px; }
.fbar .fill.ok { background: var(--ok); }
.fbar .fill.bad { background: var(--bad); }
.fbar .fill.info { background: var(--info); }
@media (max-width: 520px) { .fbar { grid-template-columns: 100px 1fr 48px; } }

/* contact chips */
.contact-list { display: flex; flex-direction: column; gap: 6px; }
.contact { display: grid; grid-template-columns: 18px 1fr auto; gap: 8px; align-items: start; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; }
.contact .v { font-family: var(--mono); font-size: 12.5px; word-break: break-all; }
.contact .meta { font-size: 11.5px; color: var(--muted); }
.contact .star { background: none; border: 0; cursor: pointer; color: var(--line); padding: 0; font-size: 14px; line-height: 1.3; }
.contact .star.on { color: var(--accent); }
.contact .warn { color: var(--warn); font-size: 11.5px; }
.sup-card { border: 1px solid var(--line); border-radius: var(--r); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.sup-card.pref { border-color: var(--accent); }
.timeline { display: flex; flex-direction: column; }
.tl { display: grid; grid-template-columns: 12px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.tl:last-child { border-bottom: 0; }
.tl i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-top: 6px; }
.tl i.stage { background: var(--accent); }
.tl i.merge, .tl i.created { background: var(--ok); }
.tl .body { white-space: pre-wrap; word-break: break-word; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; word-break: break-word; }
.matches { border: 1px solid var(--bad); background: var(--bad-soft); border-radius: var(--r); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.matches.soft { border-color: var(--warn); background: var(--warn-soft); }
.match { background: var(--surface); border-radius: 6px; padding: 8px 10px; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px; }
.repeat-block { border: 1px dashed var(--line); border-radius: var(--r); padding: 12px; display: grid; gap: 10px; position: relative; }
.ac { position: relative; }
.ac-list { position: absolute; z-index: 30; left: 0; right: 0; top: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 260px; overflow: auto; }
.ac-list button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 7px 10px; cursor: pointer; }
.ac-list button:hover { background: var(--surface-2); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters input[type=search] { flex: 1 1 220px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 8px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 500; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(10,15,13,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 10px; width: min(560px, 100%); max-height: 90vh; overflow: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { width: min(820px, 100%); }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 6px; z-index: 60; max-width: 90vw; }
.toast.bad { background: var(--bad); color: #fff; }

/* auth pages */
body.auth { display: grid; place-items: center; padding: 20px; background: var(--side); }
.auth-card { background: var(--surface); border-radius: 12px; padding: 28px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; }
.auth-card.wide { width: min(720px, 100%); }
.auth-card form .btn { justify-content: center; }
.btn-loading { opacity: .6; pointer-events: none; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
