:root {
  --sidebar: #3f4a2a;
  --sidebar-2: #3a4730;
  --cream: #fbf5ec;
  --card: #ffffff;
  --ink: #2b2b26;
  --ink-2: #5e5c52;
  --ink-3: #8a877b;
  --line: #e6e1d6;
  --orange: #b8542b;
  --orange-soft: #f6e3d8;
  --olive: #6b7d3f;
  --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-heading: Montserrat, "Open Sans", sans-serif;
  --font-body: "Open Sans", "Segoe UI", system-ui, -apple-system, Helvetica, Arial, sans-serif;
  font-family: var(--font-body);
}
* { 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-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; }
.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; }

/* ---------- Build-Print additions ---------- */
.wordmark { display: grid; grid-template-columns: auto; justify-items: center; font-family: Montserrat, "Open Sans", sans-serif; line-height: 1; gap: 2px; }
.wordmark .roof { width: 54px; height: 14px; border-top: 4px solid var(--orange); border-radius: 3px; transform: perspective(40px) rotateX(38deg); margin-bottom: 2px; }
.wordmark .adu { font-weight: 800; font-size: 30px; color: #8fa354; letter-spacing: .02em; }
.wordmark .bp { font-weight: 700; font-size: 14px; color: #e0885c; }
.wordmark .bp i { font-style: normal; color: #8fa354; margin: 0 2px; }
.wordmark.big .roof { width: 84px; height: 20px; border-top-width: 6px; }
.wordmark.big .adu { font-size: 48px; color: var(--olive); }
.wordmark.big .bp { font-size: 22px; color: var(--orange); }
.wordmark.big .bp i { color: var(--olive); }
.login-card { align-items: stretch; }
.login-card .wordmark { margin-bottom: 8px; }
.login-title { text-align: center; }
.op-picker { padding: 0 0 14px; }
.op-picker select { width: 100%; padding: 7px 8px; border-radius: 6px; border: 0; font-weight: 700; font-size: 13px; background: var(--cream); color: var(--ink); }
#nav a.disabled { opacity: .45; cursor: not-allowed; }
#nav .nav-label { margin-top: 14px; }
.who { font-size: 11px; color: #cfd3c0; margin-bottom: 6px; line-height: 1.35; }
.who b { display: block; color: #fff; }
.topbar-title { font-family: var(--font-heading); }
.page-head h1 { font-family: var(--font-heading); }
.panel h3 { font-family: var(--font-heading); }

/* gates strip */
.gates { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.gate { background: var(--card); border-radius: 8px; padding: 14px 16px; box-shadow: 0 1px 2px rgba(0,0,0,.05); border-left: 5px solid var(--ink-3); }
.gate.passed { border-left-color: var(--good); }
.gate.blocked { border-left-color: var(--bad); }
.gate.upcoming { border-left-color: var(--tan); }
.gate .g-name { font-family: var(--font-heading); font-weight: 700; font-size: 13px; }
.gate .g-state { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; margin: 4px 0; }
.gate.passed .g-state { color: var(--good); } .gate.blocked .g-state { color: var(--bad); } .gate.upcoming .g-state { color: var(--warn); }
.gate .g-items { font-size: 12px; color: var(--ink-2); }
.gate .g-block { font-size: 11px; color: var(--ink-3); margin-top: 6px; }

/* phase progress */
.phases { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.phase { background: var(--card); border-radius: 8px; padding: 12px 16px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.phase.current { outline: 2px solid var(--olive); }
.phase .p-name { font-weight: 700; font-size: 12px; display: flex; justify-content: space-between; }
.phase .p-days { color: var(--ink-3); font-weight: 500; }
.bar-track { height: 8px; background: var(--cream); border-radius: 4px; margin: 8px 0 6px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--olive); border-radius: 4px; }
.phase .p-meta { font-size: 11px; color: var(--ink-2); display: flex; gap: 10px; flex-wrap: wrap; }

.day-pill { display: inline-flex; align-items: center; gap: 8px; background: var(--card); border-radius: 20px; padding: 6px 14px; font-weight: 700; font-size: 13px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.day-pill span { font-weight: 500; color: var(--ink-3); font-size: 11px; }
.head-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

/* requirement rows */
tr.req { cursor: pointer; }
tr.req:hover td { background: #fbf8f2; }
.badge.not_started { background: #ececec; color: #666; }
.badge.in_progress { background: #f3ead0; color: #6b5320; }
.badge.submitted { background: var(--orange-soft); color: #8a3d18; }
.badge.accepted { background: #dcedd9; color: #23591f; }
.badge.returned { background: #fbe3dc; color: #8a2b16; }
.badge.waived { background: var(--olive-soft); color: #3f4d24; }
.badge.gate-tag { background: var(--sidebar); color: #fff; }
.badge.tier { background: var(--tan-soft); color: #6b4a2b; }
.badge.certified { background: #dcedd9; color: #23591f; }
.badge.conditional { background: #f3ead0; color: #6b5320; }
.week-head td { background: var(--cream); font-weight: 700; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); }
.muted { color: var(--ink-3); }
.small { font-size: 11px; }

/* drawer */
.drawer { position: fixed; inset: 0; background: rgba(30,30,20,.35); z-index: 50; display: flex; justify-content: flex-end; }
.drawer-panel { width: min(640px, 100%); background: var(--cream); height: 100%; overflow-y: auto; padding: 26px 28px 40px; position: relative; box-shadow: -10px 0 30px rgba(0,0,0,.2); }
.drawer-close { position: absolute; top: 12px; right: 14px; background: none; border: 0; font-size: 26px; cursor: pointer; color: var(--ink-3); }
.drawer h2 { font-family: var(--font-heading); margin: 0 0 4px; font-size: 18px; }
.drawer .kv { display: grid; grid-template-columns: 130px 1fr; gap: 4px 10px; font-size: 12px; margin: 10px 0 14px; }
.drawer .kv b { color: var(--ink-2); font-weight: 600; }
.drawer .panel { margin-bottom: 14px; }
.ev { border-left: 3px solid var(--olive); padding: 6px 10px; margin: 6px 0; background: var(--card); border-radius: 0 6px 6px 0; font-size: 12px; }
.ev.signal { border-left-color: var(--orange); }
.ev .t { font-weight: 700; } .ev .m { color: var(--ink-3); font-size: 11px; }
.rv { padding: 8px 10px; margin: 6px 0; background: var(--card); border-radius: 6px; font-size: 12px; border-left: 3px solid var(--ink-3); }
.rv.accept { border-left-color: var(--good); } .rv.return { border-left-color: var(--bad); } .rv.waive { border-left-color: var(--warn); }
.rv .internal { margin-top: 4px; padding: 4px 8px; background: #f3ead0; border-radius: 4px; font-size: 11px; color: #6b5320; }
.form { display: flex; flex-direction: column; gap: 8px; }
.form input, .form select, .form textarea { padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font: inherit; font-size: 13px; background: #fff; }
.form textarea { min-height: 64px; }
.btn { padding: 8px 14px; border: 0; border-radius: 6px; font-weight: 700; cursor: pointer; font-size: 13px; background: var(--olive); color: #fff; }
.btn.orange { background: var(--orange); } .btn.ghost { background: var(--card); color: var(--ink); border: 1px solid var(--line); } .btn.red { background: var(--bad); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.rule { font-size: 12px; background: var(--card); padding: 8px 10px; border-radius: 6px; border: 1px dashed var(--line); margin: 6px 0 10px; }
.err { color: var(--bad); font-size: 12px; margin-top: 6px; }
.ok-msg { color: var(--good); font-size: 12px; margin-top: 6px; }

/* academy */
.academy-frame { width: 100%; height: calc(100vh - 260px); min-height: 520px; border: 0; border-radius: 8px; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.locked { background: var(--card); border-radius: 8px; padding: 26px; text-align: center; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.locked h3 { font-family: Montserrat, sans-serif; margin: 0 0 6px; }

/* certification */
.cert-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.cert { background: var(--card); border-radius: 8px; padding: 14px 16px; box-shadow: 0 1px 2px rgba(0,0,0,.05); border-top: 3px solid var(--ink-3); }
.cert.certified { border-top-color: var(--good); } .cert.in_progress { border-top-color: var(--olive); } .cert.conditional { border-top-color: var(--warn); }
.cert .c-name { font-family: var(--font-heading); font-weight: 700; font-size: 13px; }
.cert .c-meta { font-size: 11px; color: var(--ink-3); margin: 4px 0 8px; }

/* activity */
.activity { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.activity li { padding: 6px 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 120px 1fr; gap: 10px; }
.activity li:last-child { border-bottom: 0; }
.activity .when { color: var(--ink-3); font-size: 11px; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 14px; }
  .brand { padding: 0 8px 0 0; }
  #nav { display: flex; flex-wrap: wrap; gap: 2px; }
  #nav .nav-label { display: none; }
  .sidebar-foot { margin-left: auto; }
  .row, .gates, .phases { grid-template-columns: 1fr; }
  .content { padding: 14px 16px 40px; }
  .drawer .kv { grid-template-columns: 1fr; }
}

/* ---------- brand & admin ---------- */
.brand-logo { max-width: 160px; max-height: 64px; display: block; margin: 0 auto 4px; }
.brand-text { font-family: var(--font-heading); font-weight: 800; font-size: 18px; color: #fff; text-align: center; line-height: 1.15; }
.powered { font-size: 9px; letter-spacing: .08em; text-transform: uppercase; color: rgba(255,255,255,.55); text-align: center; margin-top: 4px; }
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-logo { height: 34px; max-width: 120px; background: #fff; border-radius: 6px; padding: 3px 6px; }
.logo-thumb { width: 36px; height: 36px; object-fit: contain; background: #fff; border-radius: 6px; border: 1px solid var(--line); display: inline-block; }
.swatch { display: inline-block; width: 16px; height: 16px; border-radius: 4px; margin-right: 4px; border: 1px solid rgba(0,0,0,.12); vertical-align: middle; }
.logo-thumb.swatch { width: 36px; height: 36px; }
.form.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.form.grid3 { display: grid; grid-template-columns: 1fr 1.3fr .9fr; gap: 8px; margin-bottom: 8px; }
.fld { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--ink-2); font-weight: 600; }
.fld input, .fld select, .fld textarea { font-weight: 400; }
.fld.color .cwrap { display: flex; gap: 6px; align-items: center; }
.fld.color input[type=color] { width: 44px; height: 34px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.fld.color input[type=text] { width: 96px; }
.brand-preview { display: grid; grid-template-columns: 90px 1fr; height: 70px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.brand-preview .pv-side { display: flex; align-items: center; justify-content: center; padding: 6px; font-size: 11px; text-align: center; }
.brand-preview .pv-side img { max-width: 78px; max-height: 56px; }
.brand-preview .pv-main { display: flex; flex-direction: column; gap: 8px; justify-content: center; padding: 10px; }
.brand-preview .pv-btn { color: #fff; font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 5px; width: max-content; }
.brand-preview .pv-bar { height: 8px; background: rgba(0,0,0,.08); border-radius: 4px; overflow: hidden; }
.brand-preview .pv-bar i { display: block; height: 100%; }
.urow { display: grid; grid-template-columns: 1.4fr 1fr .8fr auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.btn.small { padding: 4px 8px; font-size: 11px; }
.temp-box { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin-top: 10px; font-size: 12px; }
.temp { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.temp code { font-size: 13px; font-weight: 700; background: var(--cream); padding: 1px 6px; border-radius: 4px; }
@media (max-width: 900px) { .form.grid2, .form.grid3, .urow { grid-template-columns: 1fr; } }

/* ---------- connections ---------- */
.cx { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; }
.cx-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 8px; }
.cx-status { text-align: right; min-width: 160px; font-size: 11px; }
.cx .btn-row select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; font: inherit; font-size: 12px; background: #fff; }
.cx-msg { font-size: 12px; margin-top: 6px; }
.fld span i { font-style: normal; font-size: 10px; }
