:root {
  --navy: #252F6A;
  --navy-deep: #1A2150;
  --red: #ED1C24;
  --red-btn: #C8102E;
  --red-btn-hover: #A50D26;
  --mist: #F2F4FA;
  --ink: #141832;
  --muted: #5A607A;
  --line: #D9DDEA;
  --tint: #C9CEE8;
  --white: #FFFFFF;
  --hot: #C8102E;
  --prime: #B4590A;
  --ok: #1F7A4D;
  --r-sm: 6px;
  --r-md: 10px;
  --head: 'Outfit', 'Arial Black', Arial, sans-serif;
  --body: 'Inter', Arial, Helvetica, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.5 var(--body); color: var(--ink); background: var(--mist); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--navy); }
:focus-visible { outline: 3px solid var(--red); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--head); color: var(--navy); margin: 0; line-height: 1.15; }
h1 { font-size: 30px; font-weight: 800; letter-spacing: -0.01em; }
h2 { font-size: 20px; font-weight: 800; }
h3 { font-size: 15px; font-weight: 600; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--navy-deep); color: var(--tint); padding: 22px 14px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 22px; color: var(--white); text-decoration: none; }
.brand img { width: 38px; height: 38px; }
.brand b { font-family: var(--head); font-weight: 800; font-size: 17px; line-height: 1.05; display: block; }
.brand b span { color: var(--red); }
.brand small { color: var(--tint); font-size: 12px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--r-sm); color: var(--tint); text-decoration: none; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,0.06); color: var(--white); }
.nav a[aria-current="page"] { background: var(--white); color: var(--navy-deep); }
.nav a[aria-current="page"] .count { background: var(--navy); color: var(--white); }
.nav .count { margin-left: auto; font-size: 12px; background: rgba(255,255,255,0.1); padding: 1px 8px; border-radius: 99px; }
.side-foot { margin-top: auto; font-size: 12px; padding: 8px; }
.side-foot button { background: none; border: 0; color: var(--tint); text-decoration: underline; cursor: pointer; padding: 0; }
.main { padding: 28px 32px 60px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.tabbar { display: none; }

/* ---------- Controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--white); color: var(--navy); padding: 8px 14px; border-radius: var(--r-sm); font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--navy); }
.btn.primary { background: var(--red-btn); border-color: var(--red-btn); color: var(--white); }
.btn.primary:hover { background: var(--red-btn-hover); }
.btn.quiet { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea, .filters input, .filters select { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 10px; background: var(--white); min-width: 0; }
.field textarea { min-height: 80px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--navy); outline: none; box-shadow: 0 0 0 3px rgba(37,47,106,.15); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input[type="search"] { flex: 1 1 220px; }

/* ---------- The scoreboard: sale-date countdown (the one loud thing) ---------- */
.scoreboard { background: var(--navy-deep); border-radius: var(--r-md); padding: 18px 20px 20px; color: var(--white); margin-bottom: 26px; }
.scoreboard-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.scoreboard-head h2 { color: var(--white); }
.scoreboard-head p { margin: 0; color: var(--tint); font-size: 13.5px; }
.board { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 10px; }
.slot { background: #11173D; border: 1px solid #2D3672; border-radius: var(--r-sm); padding: 12px 12px 10px; text-decoration: none; color: var(--white); display: grid; grid-template-columns: auto 1fr; column-gap: 12px; align-items: center; }
.slot:hover { border-color: var(--tint); }
.slot .days { font-family: var(--head); font-weight: 800; font-size: 44px; line-height: .9; color: var(--red); font-variant-numeric: tabular-nums; grid-row: span 3; min-width: 1.3em; text-align: center; }
.slot .days small { display: block; font-size: 10.5px; font-family: var(--body); font-weight: 600; color: var(--tint); letter-spacing: .02em; margin-top: 4px; }
.slot b { font-size: 13.5px; }
.slot span { font-size: 12.5px; color: var(--tint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot .flags { display: flex; gap: 6px; margin-top: 4px; }
.flag { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: #2D3672; color: var(--tint); }
.flag.good { background: #1d4d3a; color: #bfe8d2; }
.flag.warn { background: #5a1520; color: #ffd0d5; }
.board-empty { color: var(--tint); font-size: 14px; }

/* ---------- Panels & stats ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.panel { background: var(--white); border: 1px solid var(--line); border-radius: var(--r-md); padding: 18px; }
.panel h2 { font-size: 16px; margin-bottom: 12px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--white); margin-bottom: 18px; }
.stat { padding: 14px 16px; border-right: 1px solid var(--line); }
.stat:last-child { border-right: 0; }
.stat b { display: block; font-family: var(--head); font-size: 26px; font-weight: 800; color: var(--navy); font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--muted); }
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar { display: grid; grid-template-columns: 130px 1fr 36px; align-items: center; gap: 10px; font-size: 13.5px; }
.bar i { display: block; height: 10px; border-radius: 3px; background: var(--navy); min-width: 2px; }
.bar i.red { background: var(--red-btn); }
.bar em { font-style: normal; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; align-items: baseline; }
.list li:first-child { border-top: 0; }
.list li .when { margin-left: auto; color: var(--muted); font-size: 12.5px; white-space: nowrap; }

/* ---------- Tags ---------- */
.tag { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 7px; border-radius: 4px; background: var(--mist); color: var(--muted); white-space: nowrap; }
.tag.HOT, .tag.TOO-LATE { background: #FDE7EA; color: var(--hot); }
.tag.PRIME { background: #FDF0E3; color: var(--prime); }
.tag.NURTURE { background: #E8EBF6; color: var(--navy); }
.tag.PAST { background: #EEE; color: #777; }
.tag.dnc { background: var(--ink); color: var(--white); }
.tag.estate { background: #EFE9F8; color: #5A3A8C; }
.tag.stale { background: #FFF3CD; color: #7A5A00; }

/* ---------- Leads table ---------- */
.table-wrap { background: var(--white); border: 1px solid var(--line); border-radius: var(--r-md); overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th { text-align: left; font-size: 12.5px; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--white); position: sticky; top: 0; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: #F7F8FC; }
td .sub { display: block; font-size: 12.5px; color: var(--muted); }
td.r, th.r { text-align: right; }

/* ---------- Kanban ---------- */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(232px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: start; }
.col { background: #E8EBF6; border-radius: var(--r-md); padding: 10px; min-height: 140px; }
.col.lane { background: #ECECF0; }
.col.drop { outline: 3px dashed var(--navy); outline-offset: -3px; }
.col-head { display: flex; align-items: baseline; gap: 8px; padding: 2px 4px 10px; }
.col-head h3 { font-size: 14px; }
.col-head span { margin-left: auto; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px 11px; margin-bottom: 8px; cursor: grab; display: block; text-decoration: none; color: var(--ink); }
.card:hover { border-color: var(--navy); }
.card.dragging { opacity: .4; }
.card .top { display: flex; gap: 6px; align-items: center; margin-bottom: 4px; }
.card .top b { font-size: 13px; color: var(--navy); }
.card .top .tag { margin-left: auto; }
.card .addr { font-size: 13.5px; font-weight: 500; }
.card .meta { font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.lanes-title { margin: 22px 0 10px; font-size: 16px; }

/* ---------- Lead detail ---------- */
.detail-head { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: start; margin-bottom: 18px; }
.detail-head .crumbs { font-size: 13px; margin-bottom: 6px; }
.detail-head .crumbs a { color: var(--muted); }
.detail-head .chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.countdown { text-align: center; background: var(--navy-deep); color: var(--white); border-radius: var(--r-md); padding: 10px 18px 12px; min-width: 120px; }
.countdown b { display: block; font-family: var(--head); font-weight: 800; font-size: 46px; line-height: 1; color: var(--red); }
.countdown span { font-size: 12px; color: var(--tint); }
.stage-bar { display: flex; gap: 0; margin-bottom: 18px; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--white); }
.stage-bar button { flex: 1 0 auto; border: 0; background: none; padding: 10px 14px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; border-right: 1px solid var(--line); white-space: nowrap; }
.stage-bar button:last-child { border-right: 0; }
.stage-bar button.done { color: var(--navy); }
.stage-bar button.current { background: var(--navy); color: var(--white); }
.stage-bar button:hover:not(.current) { background: var(--mist); }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 18px; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 14px; font-size: 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.section-head { display: flex; align-items: center; margin-bottom: 10px; }
.section-head h2 { font-size: 16px; margin: 0; }
.section-head .btn { margin-left: auto; padding: 5px 10px; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.form-grid .wide { grid-column: 1 / -1; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 0 10px 16px; border-left: 2px solid var(--line); position: relative; font-size: 14px; }
.timeline li::before { content: ''; position: absolute; left: -6px; top: 15px; width: 10px; height: 10px; border-radius: 50%; background: var(--white); border: 2px solid var(--navy); }
.timeline li.stage::before { background: var(--navy); }
.timeline li.mail::before { border-color: var(--red-btn); }
.timeline .who { font-size: 12.5px; color: var(--muted); }
.note-box { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.note-box textarea { flex: 1 1 100%; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 10px; min-height: 64px; }
.notes-raw { white-space: pre-wrap; font-size: 13px; color: var(--muted); max-height: 220px; overflow: auto; background: var(--mist); padding: 10px; border-radius: var(--r-sm); }
.stack { display: flex; flex-direction: column; gap: 18px; }

/* ---------- Dialog ---------- */
dialog { border: 0; border-radius: var(--r-md); padding: 0; width: min(520px, 94vw); box-shadow: 0 24px 60px rgba(20,24,50,.35); }
dialog::backdrop { background: rgba(20,24,50,.45); }
dialog form { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
dialog h2 { font-size: 19px; }
dialog .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; background: var(--navy-deep); padding: 20px; }
.login form { background: var(--white); border-radius: var(--r-md); padding: 30px 28px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; }
.login .mark { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.login .mark img { width: 46px; }
.login .mark b { font-family: var(--head); font-weight: 800; font-size: 21px; color: var(--navy); line-height: 1.05; }
.login .mark b span { color: var(--red); }
.err { color: var(--red-btn); font-size: 14px; min-height: 1.2em; margin: 0; }

/* ---------- Toast ---------- */
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--white); padding: 10px 16px; border-radius: var(--r-sm); font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--red-btn); }

.empty { padding: 30px; text-align: center; color: var(--muted); }
.drop-zone { border: 2px dashed var(--line); border-radius: var(--r-md); padding: 28px; text-align: center; background: var(--white); }
.drop-zone.over { border-color: var(--navy); background: #F7F8FC; }
code, .code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; background: var(--mist); padding: 1px 5px; border-radius: 4px; }
pre.code { padding: 12px; overflow-x: auto; white-space: pre; }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .main { padding: 18px 14px 96px; }
  h1 { font-size: 24px; }
  .grid2, .detail-grid { grid-template-columns: 1fr; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; background: var(--navy-deep); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 20; }
  .tabbar a { color: var(--tint); text-decoration: none; text-align: center; font-size: 11.5px; font-weight: 600; padding: 6px 2px; border-radius: var(--r-sm); }
  .tabbar a[aria-current="page"] { color: var(--white); background: rgba(255,255,255,.1); }
  .tabbar svg { display: block; margin: 0 auto 2px; }
  .kanban { grid-auto-columns: 82vw; scroll-snap-type: x mandatory; }
  .col { scroll-snap-align: start; }
  .detail-head { grid-template-columns: 1fr; }
  .countdown { justify-self: start; }
  .kv { grid-template-columns: 120px 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  .bar { grid-template-columns: 100px 1fr 30px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
td b, .list a, .slot b { white-space: nowrap; }
.mobile-only { display: none; }
@media (max-width: 900px) { .mobile-only { display: inline-flex; } }
