:root {
  --bg: #f4f2ee;
  --card: #ffffff;
  --ink: #18202b;
  --ink-2: #4a5462;
  --muted: #7a8391;
  --line: #e4e0d8;
  --head: #14202e;
  --accent: #e8590c;
  --accent-ink: #ffffff;
  --late: #c92a2a;
  --ok: #2b8a3e;
  --warn-bg: #fff4e0;
  --warn-line: #f2c879;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 32, 46, .06), 0 2px 8px rgba(20, 32, 46, .04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161d; --card: #19212b; --ink: #e8ebef; --ink-2: #b5bdc8; --muted: #8893a1;
    --line: #2a3441; --head: #0b0f14; --warn-bg: #3a2c12; --warn-line: #7a5b1e;
    --late: #ff6b6b; --ok: #51cf66; --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: 80px;
}
a { color: inherit; }
h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.late { color: var(--late); font-weight: 600; }
.empty { color: var(--muted); font-style: italic; margin: 8px 0; }
.pad { padding: 16px; }
.hint { color: var(--muted); font-size: 13px; margin: -4px 0 10px; }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 10; background: var(--head); color: #fff;
  display: flex; align-items: center; gap: 24px; padding: 10px 20px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; text-decoration: none; font-size: 17px; }
.brand .mark {
  width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 800;
}
.brand.big { font-size: 24px; justify-content: center; margin-bottom: 18px; color: var(--ink); }
.brand.big .mark { width: 38px; height: 38px; font-size: 20px; }
nav.main { display: flex; gap: 4px; }
nav.main a { text-decoration: none; padding: 7px 12px; border-radius: 7px; color: #c9d1db; font-weight: 500; }
nav.main a:hover { background: rgba(255,255,255,.08); color: #fff; }
nav.main a.on { background: rgba(255,255,255,.12); color: #fff; }
.top .right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.menu { position: relative; }
.menu summary {
  list-style: none; cursor: pointer; width: 32px; height: 32px; border-radius: 50%;
  background: #2c3a4b; display: grid; place-items: center; font-weight: 700;
}
.menu summary::-webkit-details-marker { display: none; }
.menu-pop {
  position: absolute; right: 0; top: 40px; background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.18);
  min-width: 200px; padding: 8px; display: flex; flex-direction: column;
}
.menu-pop > * { padding: 8px 10px; border-radius: 6px; text-decoration: none; }
.menu-pop a:hover, .menu-pop .linkish:hover { background: var(--bg); }
.linkish { background: none; border: 0; font: inherit; color: inherit; cursor: pointer; text-align: left; width: 100%; padding: 0; }
.menu-pop form { padding: 0; }
.menu-pop form .linkish { padding: 8px 10px; border-radius: 6px; }

/* bottom tab bar (phones) */
.tabbar { display: none; }

/* ---------- layout ---------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 20px; }
.pagehead { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.pagehead p { margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.grid2 > .card + .card { margin-top: 0; }
.card.flush { padding: 0; overflow: hidden; }
.narrow { max-width: 440px; }
.count { background: var(--bg); color: var(--ink); border-radius: 20px; padding: 0 8px; font-size: 12px; letter-spacing: 0; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 26px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }

/* rows */
.row { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.card.flush .row { padding: 12px 16px; }
.row:first-of-type { border-top: 0; }
.row.hot { box-shadow: inset 3px 0 0 var(--late); padding-left: 10px; }
.row-main { min-width: 0; flex: 1 1 220px; }
.row-act { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.who { font-weight: 600; text-decoration: none; }
.who:hover { text-decoration: underline; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; color: var(--ink-2); font-size: 13px; margin-top: 2px; }
.age { color: var(--muted); }
.age.late { color: var(--late); font-weight: 600; }
.dayhead { padding: 10px 16px 6px; font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); background: var(--bg); border-top: 1px solid var(--line); }
.dayhead:first-child { border-top: 0; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer;
  font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 8px; text-decoration: none;
  border: 1px solid var(--line); background: var(--card); color: var(--ink); min-height: 38px;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; color: var(--late); border-color: var(--late); }
.btn.small { padding: 5px 10px; font-size: 13px; min-height: 32px; }
.top .btn.primary { min-height: 34px; }
.iconbtn {
  display: inline-flex; align-items: center; padding: 5px 10px; min-height: 32px; border-radius: 8px; font-size: 13px; font-weight: 600;
  text-decoration: none; border: 1px solid var(--line); background: var(--bg);
}
.iconbtn:hover { border-color: var(--muted); }
form.inline { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.wrapgap { margin-top: 10px; }

/* badges */
.src, .st, .pill {
  display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 20px;
  border: 1px solid transparent; white-space: nowrap;
}
.src { background: #eef0f3; color: #3d4652; }
.src-carfax { background: #e3edfb; color: #1c4f9c; }
.src-cars-com { background: #efe6fb; color: #5f2b9e; }
.src-offerup { background: #ddf5ec; color: #0b7354; }
.src-walk-in { background: #fdf1d8; color: #8a5a00; }
.src-facebook { background: #e5ecfa; color: #2d4f9e; }
.st { background: #eef0f3; color: #3d4652; }
.st-new { background: #fde8e8; color: #b42318; }
.st-contacted { background: #e7f0fd; color: #1d4ed8; }
.st-hot { background: #ffe4d5; color: #c2410c; }
.st-warm { background: #fef3c7; color: #92400e; }
.st-cold { background: #e0f2fe; color: #075985; }
.st-appointment-set, .st-scheduled { background: #ede9fe; color: #6d28d9; }
.st-sold, .st-showed { background: #dcfce7; color: #166534; }
.st-lost, .st-no-show, .st-cancelled { background: #eceef1; color: #6b7280; }
.pill { background: var(--bg); color: var(--ink-2); border-color: var(--line); }
@media (prefers-color-scheme: dark) {
  .src, .st { filter: saturate(.9) brightness(.92); }
}

/* quick log */
.quicklog { position: relative; }
.quicklog > summary {
  list-style: none; cursor: pointer; padding: 5px 10px; min-height: 32px; display: inline-flex; align-items: center;
  border-radius: 8px; font-size: 13px; font-weight: 600; background: var(--accent); color: #fff;
}
.quicklog > summary::-webkit-details-marker { display: none; }
.ql-form {
  position: absolute; right: 0; top: 38px; z-index: 5; width: 280px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.16);
  padding: 12px; display: grid; gap: 8px;
}

/* segmented + chips */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg.wide { display: flex; }
.seg label { flex: 1; }
.seg label, .chip { position: relative; }
.seg input, .chip input { position: absolute; left: 0; top: 0; opacity: 0; pointer-events: none; width: 1px; height: 1px; min-height: 0; padding: 0; margin: 0; }
.seg span { display: block; text-align: center; padding: 7px 10px; cursor: pointer; font-size: 13px; font-weight: 600; border-left: 1px solid var(--line); }
.seg label:first-child span { border-left: 0; }
.seg input:checked + span { background: var(--head); color: #fff; }
.seg input:focus-visible + span, .chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip span { display: inline-block; padding: 6px 12px; border-radius: 20px; border: 1px solid var(--line); cursor: pointer; font-size: 13px; font-weight: 500; background: var(--card); }
.chips.small .chip span { padding: 3px 10px; font-size: 12px; }
.chip input:checked + span { background: var(--head); border-color: var(--head); color: #fff; }

/* forms */
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%; min-height: 38px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }
.form fieldset { border: 0; padding: 0; margin: 0 0 18px; }
.form legend { font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); margin-bottom: 8px; padding: 0; }
.form label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.form label input, .form label select, .form label textarea { margin-top: 4px; font-weight: 400; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.cols legend { grid-column: 1 / -1; }
.cols .full { grid-column: 1 / -1; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stack { display: grid; gap: 12px; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
label.check input { width: auto; min-height: 0; margin: 0; }
.actions { display: flex; gap: 8px; }
.danger-zone { margin-top: 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.filters { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 8px; margin-bottom: 12px; }

/* flash */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; border: 1px solid var(--line); background: var(--card); }
.flash.ok { border-color: #b7e4c0; background: #ecf9ef; color: #1e5f2c; }
.flash.error { border-color: #f5c2c2; background: #fdeeee; color: #8f1d1d; }
.flash.warn { border-color: var(--warn-line); background: var(--warn-bg); }
.flash.warn ul { margin: 6px 0; padding-left: 18px; }
@media (prefers-color-scheme: dark) {
  .flash.ok { background: #16301d; color: #a9e5b5; border-color: #2d5a37; }
  .flash.error { background: #3a1a1a; color: #f5b5b5; border-color: #6b2b2b; }
}

/* table */
table.list { width: 100%; border-collapse: collapse; }
.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 10px 12px; background: var(--bg); border-bottom: 1px solid var(--line); }
.list td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.list tr:last-child td { border-bottom: 0; }
.list tbody tr:hover { background: color-mix(in srgb, var(--bg) 60%, transparent); }
.list td .iconbtn { margin-right: 4px; }

/* tabs */
.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tabs a { padding: 6px 14px; border-radius: 20px; text-decoration: none; font-weight: 600; font-size: 14px; color: var(--ink-2); }
.tabs a.on { background: var(--head); color: #fff; }

/* lead page */
.lead-head { align-items: flex-start; }
.back { text-decoration: none; color: var(--muted); font-size: 13px; }
.head-act { display: flex; gap: 6px; flex-wrap: wrap; }
.lead-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; align-items: start; }
.logform { display: grid; gap: 10px; }
.followrow { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.followrow label { font-size: 13px; font-weight: 600; color: var(--ink-2); flex: 1 1 180px; }
.followrow label select { margin-top: 4px; }
.followrow input { flex: 1 1 180px; width: auto; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 8px 0 10px 18px; border-left: 2px solid var(--line); margin-left: 5px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.timeline .t-call::before { background: #2b8a3e; }
.timeline .t-text::before { background: #1c7ed6; }
.timeline .t-email::before { background: #7048e8; }
.timeline .t-visit::before { background: var(--accent); }
.timeline .t-status::before, .timeline .t-system::before { background: var(--line); }
.timeline .t-status .t-body, .timeline .t-system .t-body { color: var(--ink-2); font-size: 13px; }
.t-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.t-body { margin-top: 2px; white-space: pre-wrap; }
.big { font-size: 18px; font-weight: 700; margin: 0; }
.statusgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.st-btn { font: inherit; font-size: 13px; font-weight: 600; padding: 7px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink-2); cursor: pointer; }
.st-btn.on { outline: 2px solid var(--ink); outline-offset: -2px; color: var(--ink); }
.st-btn.on.st-new { background: #fde8e8; color: #b42318; }
.st-btn.on.st-contacted { background: #e7f0fd; color: #1d4ed8; }
.st-btn.on.st-hot { background: #ffe4d5; color: #c2410c; }
.st-btn.on.st-warm { background: #fef3c7; color: #92400e; }
.st-btn.on.st-cold { background: #e0f2fe; color: #075985; }
.st-btn.on.st-appointment-set { background: #ede9fe; color: #6d28d9; }
.st-btn.on.st-sold { background: #dcfce7; color: #166534; }
.st-btn.on.st-lost { background: #eceef1; color: #6b7280; }
.details { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; }
.details dt { color: var(--muted); font-size: 13px; }
.details dd { margin: 0; word-break: break-word; }
.notes { margin-top: 12px; padding: 10px; background: var(--bg); border-radius: 8px; white-space: pre-wrap; font-size: 14px; }
.appt-mini { padding: 6px 0 8px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }

/* bars */
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 90px; gap: 10px; align-items: center; font-size: 14px; }
.bar { height: 10px; background: var(--bg); border-radius: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.bar-n { font-variant-numeric: tabular-nums; font-weight: 600; }

/* auth */
.auth { max-width: 380px; margin: 10vh auto 0; }
.inline-details { display: inline-block; }
.inline-details summary { list-style: none; }
.inline-details summary::-webkit-details-marker { display: none; }
.inline-details[open] form { margin-top: 6px; }
.inline-details input { width: 150px; }

/* ---------- phones ---------- */
@media (max-width: 760px) {
  .wrap { padding: 14px; }
  .top { padding: 10px 14px; }
  nav.main, .top .btn.primary { display: none; }
  .grid2, .lead-grid, .cols, .filters { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  h1 { font-size: 21px; }
  .hide-s { display: none; }
  .list td, .list th { padding: 10px; }
  .row-act { width: 100%; }
  .ql-form { position: fixed; left: 12px; right: 12px; top: auto; bottom: 86px; width: auto; }
  .bar-row { grid-template-columns: 90px 1fr 70px; }
  .tabbar {
    display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
    background: var(--card); border-top: 1px solid var(--line); padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a { text-align: center; text-decoration: none; padding: 10px 0; font-weight: 600; font-size: 14px; color: var(--muted); border-radius: 8px; }
  .tabbar a.on { color: var(--ink); background: var(--bg); }
  .tabbar a.add { background: var(--accent); color: #fff; font-size: 22px; line-height: 1; padding: 7px 0; margin: 0 10px; }
}

/* ---------- v2 ---------- */
.replied { border-color: #f5b48a; box-shadow: inset 4px 0 0 var(--accent), var(--shadow); margin-bottom: 16px; }
.quote { margin-top: 6px; padding: 8px 10px; background: var(--bg); border-radius: 8px; font-size: 14px; color: var(--ink); white-space: pre-wrap; }
.flash.replied-banner { border-color: #f5b48a; background: #fff1e6; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
@media (prefers-color-scheme: dark) { .flash.replied-banner { background: #3a2414; border-color: #7a4a26; } }
.pill.auto { background: #efe6fb; color: #5f2b9e; border-color: transparent; }
.timeline li.dir-in { background: color-mix(in srgb, var(--accent) 7%, transparent); border-radius: 0 8px 8px 0; }
.timeline .t-text::before { background: #1c7ed6; }

/* composer tabs */
.ctabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -4px -4px 12px; padding: 0 4px; }
.ctab { font: inherit; font-weight: 600; font-size: 14px; background: none; border: 0; padding: 8px 12px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.ctab.on { color: var(--ink); border-bottom-color: var(--accent); }
.composer .followrow { justify-content: flex-end; }
.composer .followrow label { flex: 0 1 220px; }
.cc { margin-right: auto; align-self: center; }

/* tasks */
.row.task { flex-wrap: nowrap; align-items: flex-start; }
.card.flush .row.task { padding: 10px 16px; }
.check-btn { width: 22px; height: 22px; border-radius: 6px; border: 2px solid var(--muted); background: var(--card); cursor: pointer; display: grid; place-items: center; font-size: 13px; font-weight: 800; color: #fff; padding: 0; margin-top: 2px; }
.check-btn:hover { border-color: var(--ok); }
.check-btn.on { background: var(--ok); border-color: var(--ok); }
.row.task.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-title { font-weight: 600; }
.taskadd { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 8px; margin-bottom: 14px; }
.mini-task { margin-top: 10px; gap: 6px; }
.mini-task .pair { gap: 6px; }

/* settings */
.sticky-tabs { position: sticky; top: 52px; z-index: 5; background: var(--bg); padding: 8px 0; flex-wrap: wrap; }
.tabs a:not(.on) { background: var(--card); border: 1px solid var(--line); }
#gmail, #texting, #automations, #templates, #dealer { scroll-margin-top: 110px; }
.steps { padding-left: 20px; margin: 4px 0 14px; display: grid; gap: 8px; }
.steps li { line-height: 1.5; }
.copyrow { display: flex; gap: 8px; align-items: center; margin: 6px 0; flex-wrap: wrap; }
.copyrow code { background: var(--bg); border: 1px solid var(--line); padding: 6px 10px; border-radius: 6px; font-size: 13px; word-break: break-all; }
.narrowish { max-width: 560px; }
.autos { display: grid; gap: 4px; }
.toggle { display: flex !important; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); font-weight: 400 !important; color: var(--ink) !important; }
.toggle > input { width: 20px; height: 20px; min-height: 0; margin-top: 2px; flex: none; accent-color: var(--accent); }
.toggle b { display: block; font-size: 15px; }
.toggle small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
input.tiny { width: 52px; min-height: 28px; padding: 2px 6px; display: inline-block; margin: 0 2px; text-align: center; }
.tpl { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-top: 8px; }
.tpl summary { cursor: pointer; font-weight: 600; }
.tpl form { margin-top: 10px; }
code { font-size: 12.5px; }

@media (max-width: 760px) {
  .taskadd { grid-template-columns: 1fr; }
  .tabbar { grid-template-columns: repeat(5, 1fr); }
  .tabbar a.add { margin: 0 4px; }
  .composer .followrow label { flex: 1 1 100%; }
  .sticky-tabs { top: 52px; }
}
.seqline { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
.seqopts { display: grid; gap: 12px; padding: 12px 0 12px 32px; border-bottom: 1px solid var(--line); }
.seqopts > label { font-size: 13px; font-weight: 600; color: var(--ink-2); display: grid; gap: 6px; }
.seqopts .chips { margin-top: 2px; }
.stage-list { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0 10px; }
.stage-list .pill.done { background: #dcfce7; color: #166534; border-color: transparent; }
.stage-list .pill.next { background: #fff1e6; color: #c2410c; border-color: #f5b48a; }
