:root {
  --sidebar: #2f3a25;
  --sidebar-2: #3a4730;
  --cream: #f4f0e8;
  --card: #ffffff;
  --ink: #2b2b26;
  --ink-2: #5e5c52;
  --ink-3: #8a877b;
  --line: #e6e1d6;
  --orange: #c8673a;
  --orange-soft: #f6e3d8;
  --olive: #7d8b4c;
  --olive-soft: #e5e8d6;
  --tan: #e8c4a0;
  --tan-soft: #f2dcc5;
  --good: #2e7d32;
  --bad: #c0392b;
  --warn: #b7791f;
  /* categorical (validated): meta, google, chatgpt, referral, organic */
  --c-meta: #c8673a; --c-google: #2a78d6; --c-chatgpt: #1baf7a; --c-referral: #eda100; --c-organic: #4a3aa7; --c-other: #8c8577;
  font-family: "Segoe UI", system-ui, -apple-system, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--cream); color: var(--ink); }
.hidden { display: none !important; }
a { cursor: pointer; }
button { font: inherit; }

/* ---------- login ---------- */
.login { position: fixed; inset: 0; background: var(--sidebar); display: flex; align-items: center; justify-content: center; }
.login-card { background: var(--card); padding: 36px 40px; border-radius: 10px; width: 360px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.35); }
.login-logo { font-weight: 700; color: var(--orange); font-size: 20px; }
.login-title { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 10px; }
.login-card input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; font-size: 15px; }
.login-card button { padding: 10px; background: var(--orange); color: #fff; border: 0; border-radius: 6px; font-weight: 600; cursor: pointer; }
.login-err { color: var(--bad); font-size: 13px; min-height: 16px; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: #e8e4d8; padding: 22px 14px; display: flex; flex-direction: column;
  background-image: linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px);
  background-size: 28px 28px; }
.brand { padding: 8px 10px 26px; }
.brand-name { display: flex; flex-direction: column; line-height: 1; font-size: 26px; font-weight: 300; color: var(--tan); }
.brand-name span:nth-child(1), .brand-name span:nth-child(4) { font-weight: 600; color: #e9b58a; }
.nav-label { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: #9fa58f; padding: 0 10px 8px; }
#nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 6px; color: #d8d5c8; font-size: 13px; font-weight: 600; text-decoration: none; }
#nav a i { font-style: normal; width: 14px; text-align: center; opacity: .8; }
#nav a.active { background: var(--cream); color: var(--ink); }
#nav a:hover:not(.active) { background: var(--sidebar-2); }
.sidebar-foot { margin-top: auto; padding: 10px; }
.linkbtn { background: none; border: 0; color: #9fa58f; font-size: 12px; cursor: pointer; padding: 0; }
.linkbtn:hover { color: #fff; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { background: var(--sidebar); color: #fff; padding: 14px 26px; display: flex; justify-content: space-between; align-items: center; }
.topbar-title { font-weight: 700; font-size: 16px; letter-spacing: .02em; }
.topbar-sub { font-size: 11px; color: #b8bca8; }
.topbar-controls { display: flex; gap: 10px; }
.select { background: #fff; color: var(--ink); border-radius: 6px; padding: 5px 10px; display: flex; flex-direction: column; min-width: 140px; }
.select span { font-size: 9px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.select select { border: 0; font-weight: 700; font-size: 13px; background: transparent; outline: none; padding: 0; }
.demo-banner { background: var(--tan); color: #4a3a2a; text-align: center; font-size: 12px; font-weight: 600; padding: 7px; }
.freshness { display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 8px 26px 0; font-size: 11px; color: var(--ink-3); }
.freshness .src { display: inline-flex; align-items: center; gap: 6px; }
.freshness .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); display: inline-block; }
.freshness .dot.err { background: var(--bad); }
.freshness .dot.none { background: var(--ink-3); }
.freshness .err-text { color: var(--bad); font-weight: 600; }

.content { padding: 18px 26px 40px; display: flex; flex-direction: column; gap: 16px; }
.page-head { display: flex; justify-content: space-between; align-items: baseline; }
.page-head h1 { margin: 0; font-size: 24px; letter-spacing: .02em; }
.page-head .sub { font-size: 12px; color: var(--ink-3); }

/* ---------- cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.card { background: var(--card); border-radius: 8px; padding: 14px 16px 12px; border-top: 3px solid var(--orange); box-shadow: 0 1px 2px rgba(0,0,0,.05); position: relative; }
.card:nth-child(5n+2) { border-top-color: var(--olive); }
.card:nth-child(5n+3) { border-top-color: var(--tan); }
.card:nth-child(5n+4) { border-top-color: var(--sidebar); }
.card:nth-child(5n+5) { border-top-color: var(--ink-3); }
.card .label { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-2); font-weight: 700; display: flex; justify-content: space-between; gap: 6px; }
.card .value { font-size: 26px; font-weight: 700; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.card .delta { font-size: 11px; font-weight: 600; color: var(--ink-3); }
.card .delta.good { color: var(--good); }
.card .delta.bad { color: var(--bad); }
.chip { font-size: 9px; letter-spacing: .06em; text-transform: uppercase; padding: 2px 6px; border-radius: 10px; background: var(--cream); color: var(--ink-2); white-space: nowrap; cursor: help; font-weight: 600; }
.chip.mtd { background: var(--orange-soft); color: #8a3d18; }
.chip.cohort, .chip.trailing_6m { background: var(--olive-soft); color: #44512a; }
.chip.as_of { background: var(--tan-soft); color: #6b4a2b; }

/* ---------- panels ---------- */
.row { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
.row.r21 { grid-template-columns: 3fr 2fr; }
.row.r1 { grid-template-columns: 1fr; }
.panel { background: var(--card); border-radius: 8px; padding: 16px 18px; box-shadow: 0 1px 2px rgba(0,0,0,.05); min-width: 0; }
.panel h3 { margin: 0; font-size: 13px; letter-spacing: .03em; text-transform: uppercase; }
.panel .sub { font-size: 11px; color: var(--ink-3); margin: 2px 0 10px; }
.chart-wrap { position: relative; height: 230px; }
.chart-wrap.tall { height: 300px; }
.legend { display: flex; gap: 14px; font-size: 11px; color: var(--ink-2); margin-bottom: 6px; flex-wrap: wrap; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.empty { color: var(--ink-3); font-size: 13px; padding: 30px 0; text-align: center; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { text-align: left; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); padding: 6px 8px; border-bottom: 1px solid var(--line); }
td { padding: 8px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
td.num, th.num { text-align: right; }
tr:last-child td { border-bottom: 0; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 700; background: var(--cream); color: var(--ink-2); }
.badge.signed { background: var(--olive-soft); color: #3f4d24; }
.badge.contract_sent { background: #e9e4d6; color: #4a4436; }
.badge.estimate { background: #f3ead0; color: #6b5320; }
.badge.appointment { background: var(--orange-soft); color: #8a3d18; }
.badge.lead { background: #ececec; color: #555; }
.badge.ok { background: #dcedd9; color: #23591f; }
.badge.review { background: #fbe3dc; color: #8a2b16; }
.badge.missing { background: #ececec; color: #666; }
.badge.current { background: #dcedd9; color: #23591f; }
.badge.overdue { background: #fbe3dc; color: #8a2b16; }
.table-wrap { overflow-x: auto; }

/* funnel */
.funnel { display: flex; flex-direction: column; gap: 10px; }
.funnel .stage { display: grid; grid-template-columns: 110px 1fr 50px; align-items: center; gap: 10px; font-size: 12px; }
.funnel .bar { height: 22px; border-radius: 4px; background: var(--olive); min-width: 2px; }
.funnel .n { text-align: right; font-weight: 700; }
.funnel .drop { font-size: 10px; color: var(--bad); font-weight: 600; margin-left: 120px; }
.funnel .drop.muted { color: var(--ink-3); font-weight: 500; }

/* schedule */
.sched { display: flex; flex-direction: column; gap: 8px; }
.sched .job { display: grid; grid-template-columns: 80px 1fr 40px; align-items: center; gap: 10px; font-size: 12px; }
.sched .track { height: 10px; background: var(--cream); border-radius: 5px; position: relative; overflow: hidden; }
.sched .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--orange); border-radius: 5px; }
.sched .fill.permitting { background: var(--tan); }
.sched .d { text-align: right; color: var(--ink-3); font-size: 11px; }
.note { font-size: 11px; color: var(--ink-3); margin-top: 8px; }
.suppressed-note { font-size: 11px; color: var(--ink-3); font-style: italic; }
