/* Dark (the original Lead Engine's navy-black) is the default for every app;
   the Theme button can switch to light (localStorage ui_theme). */
:root {
  --bg: #0b1120; --surface: #131c2e; --surface-2: #1a2438; --line: #273349; --line-strong: #384663;
  --text: #e5e9f0; --text-2: #9aa7bd; --muted: #8492a8;
  --accent: #3b82f6; --accent-ink: #fff; --accent-soft: #172a4d; --track: #1e3354;
  --series: #3b82f6; --series-dim: #1d4ed8;
  --good: #22c55e; --good-ink: #4ade80; --warning: #f59e0b; --warning-ink: #fbbf24;
  --serious: #ec835a; --critical: #ef4444; --critical-ink: #f87171;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --radius: 10px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f8f9fa; --line: #e3e5e9; --line-strong: #cfd3d9;
  --text: #15171a; --text-2: #4f5560; --muted: #7b818c;
  --accent: #1f7cff; --accent-ink: #ffffff; --accent-soft: #e5efff; --track: #d7e6fb;
  --series: #2a78d6; --series-dim: #9ec5f4;
  --good: #0ca30c; --good-ink: #0b6e0b; --warning: #fab219; --warning-ink: #8a5a00;
  --serious: #ec835a; --critical: #d03b3b; --critical-ink: #b42b2b;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
/* Sidebar + phone top bar: the old Lead Engine's navy panel, in both themes. */
:root { --side-bg: #131c2e; --side-line: #273349; --side-hover: #1a2438; --side-text: #9aa7bd; --side-head: #64748b; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: .01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ── Layout ─────────────────────────────────────────── */
.app { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
/* The sidebar is pinned to the viewport; only the nav list scrolls, so every item
   stays reachable on short laptop screens while brand + footer stay put. */
.side {
  background: var(--side-bg); border-right: 1px solid var(--side-line); color: var(--side-text); padding: 14px 10px 10px; position: sticky; top: 0;
  height: 100vh; height: 100dvh; display: flex; flex-direction: column; min-height: 0;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 12px; color: #fff; font-weight: 600; font-size: 17px; flex: none; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; }
.brand-mark svg { width: 16px; height: 16px; }
/* Company logo (Targetpoint) with the app's name under it. */
.brand:has(.brand-logo), .side-brand:has(.brand-logo) { flex-direction: column; align-items: flex-start; gap: 4px; padding-bottom: 14px; }
.brand-logo { height: 32px; width: auto; flex: none; display: block; margin-left: -2px; }
.brand-app { font-size: 13.5px; font-weight: 600; color: #e2e8f0; padding-left: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
/* On light cards (sign-in, first login) the dark-text logo; in the dark theme the white one. */
.logo-on-light { display: none; } :root[data-theme="light"] .logo-on-light { display: block; } :root[data-theme="light"] .logo-on-dark { display: none; }
.topbar .brand-mini { width: 22px; height: 22px; flex: none; }
.card-logo img { height: 30px; width: auto; }
.nav {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 1px;
  margin: 0 -4px; padding: 0 4px 8px; scrollbar-width: thin; scrollbar-color: var(--side-line) transparent;
}
.nav::-webkit-scrollbar { width: 6px; }
.nav::-webkit-scrollbar-thumb { background: var(--side-line); border-radius: 3px; }
.nav-head { padding: 12px 10px 4px; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--side-head); }
.nav-head:first-child { padding-top: 2px; }
.nav-fold { display: flex; align-items: center; gap: 6px; width: 100%; background: none; border: 0; cursor: pointer; font-family: inherit; text-align: left; border-radius: 6px; }
.nav-fold:hover { color: #fff; }
.nav-fold:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.nav-fold .chev { margin-left: auto; font-size: 12px; transition: transform .15s; }
.nav-group.folded .chev { transform: rotate(-90deg); }
.nav-group.folded .nav-items { display: none; }
.nav-group:not(.folded) .group-badge { display: none; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; color: var(--side-text); font-weight: 500; flex: none; min-width: 0;
}
.nav a:hover { background: var(--side-hover); color: #fff; }
.nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.nav a.active { background: color-mix(in srgb, #3b82f6 16%, transparent); color: #fff; }
.nav a.active svg { color: #3b82f6; }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .badge-slot { margin-left: auto; }
.side-foot { flex: none; border-top: 1px solid var(--side-line); padding: 10px 6px 2px; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.side-foot .who { display: flex; align-items: center; gap: 10px; color: #fff; min-width: 0; }
.who-txt { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.who-role { color: #8b919c; font-size: 12px; text-transform: capitalize; }
.side-actions { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.side-actions a, .side-actions button { background: none; border: 0; color: #8b919c; padding: 2px 0; cursor: pointer; font-size: 13px; }
.side-actions a:hover, .side-actions button:hover { color: #fff; }
.side-scrim { display: none; }

/* Short screens (most laptops at 125–150% scaling): tighten the sidebar further. */
@media (max-height: 760px) {
  .side { padding-top: 10px; }
  .brand { padding-bottom: 8px; }
  .nav a { padding: 6px 10px; }
  .nav-head { padding: 8px 10px 2px; }
}

main { padding: 24px 28px 60px; max-width: 1400px; width: 100%; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .spacer { flex: 1; }

.topbar { display: none; }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 40; left: 0; top: 0; width: 260px; max-width: 85vw; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 8px 0 30px rgba(0,0,0,.35); }
  .side-scrim.open { display: block; position: fixed; inset: 0; z-index: 39; background: rgba(10, 12, 16, .45); }
  .nav a { padding: 9px 10px; }
  .topbar {
    display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--side-bg); border-bottom: 1px solid var(--side-line); color: #fff;
    position: sticky; top: 0; z-index: 30;
  }
  .topbar button { background: none; border: 0; color: #fff; padding: 4px; cursor: pointer; display: flex; }
  .topbar svg { width: 22px; height: 22px; }
  main { padding: 16px 16px 60px; }
}

/* ── Primitives ─────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; min-width: 0;
}
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.card-head .spacer { flex: 1; }
.grid { display: grid; gap: 14px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1100px) { .cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) { .cols-2, .cols-3 { grid-template-columns: 1fr; } }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text); padding: 7px 12px; border-radius: 8px; cursor: pointer; font-weight: 500;
  font-size: 14px; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn.danger { color: var(--critical-ink); }
.btn:disabled { opacity: .5; cursor: default; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; padding: 3px; }
.seg button { border: 0; background: none; padding: 5px 14px; border-radius: 6px; cursor: pointer; color: var(--text-2); font-weight: 500; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

input[type=text], input[type=number], input[type=date], input[type=password], input[type=search], input[type=email],
input[type=url], input[type=tel], input:not([type]), select, textarea {
  border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 7px 10px; width: 100%;
  min-width: 0;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-2); font-weight: 500; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 99px;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--line); white-space: nowrap;
}
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.crit { background: color-mix(in srgb, var(--critical) 14%, transparent); color: var(--critical-ink); border-color: transparent; }
.badge.warn { background: color-mix(in srgb, var(--warning) 20%, transparent); color: var(--warning-ink); border-color: transparent; }
.badge.ok { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good-ink); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }

.status { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 600; }
.status svg { width: 15px; height: 15px; flex: none; }
.status.ok { color: var(--good-ink); }
.status.warn { color: var(--warning-ink); }
.status.crit { color: var(--critical-ink); }
.status.off { color: var(--muted); }

table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.r, .tbl th.r { text-align: right; }
.table-wrap { overflow-x: auto; }

.empty { color: var(--muted); padding: 18px 4px; text-align: center; font-size: 14px; }

/* ── KPI tiles ──────────────────────────────────────── */
.section-title { display: flex; align-items: baseline; gap: 10px; margin: 22px 0 10px; }
.section-title h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.tile { padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; cursor: default; }
.tile.clickable { cursor: pointer; }
.tile.clickable:hover { border-color: var(--accent); }
.tile-label { font-size: 13px; color: var(--text-2); font-weight: 500; display: flex; gap: 6px; align-items: center; }
.tile-value { font-size: 28px; font-weight: 600; line-height: 1.1; }
.tile-value .of { font-size: 15px; color: var(--muted); font-weight: 500; }
.tile-foot { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; min-height: 18px; }
.delta { font-weight: 600; }
.delta.good { color: var(--good-ink); }
.delta.bad { color: var(--critical-ink); }
.meter { height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.meter.warn > i { background: var(--warning); }
.meter.crit > i { background: var(--critical); }
.meter.done > i { background: var(--good); }

.hero { display: flex; align-items: flex-end; gap: 18px; flex-wrap: wrap; }
.hero-value { font-size: 48px; font-weight: 600; line-height: 1; }

/* ── Chart ──────────────────────────────────────────── */
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .target-line { stroke: var(--text-2); stroke-width: 1.5; stroke-dasharray: 4 4; }
.chart .bar { fill: var(--series); }
.chart .bar.dim { fill: var(--series-dim); }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .hit:hover + .bar, .chart .bar.hover { filter: brightness(1.15); }
.tooltip {
  position: absolute; pointer-events: none; background: var(--text); color: var(--bg); padding: 6px 9px; border-radius: 6px;
  font-size: 12.5px; white-space: nowrap; transform: translate(-50%, -110%); z-index: 5;
}
details.table-view summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-top: 8px; }

/* ── Funnel ─────────────────────────────────────────── */
.funnel-row { display: grid; grid-template-columns: 110px 1fr 70px 90px; align-items: center; gap: 10px; padding: 5px 0; font-size: 14px; }
.funnel-bar { height: 14px; background: var(--track); border-radius: 0 4px 4px 0; position: relative; }
.funnel-bar > i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--series); border-radius: 0 4px 4px 0; min-width: 2px; }

/* ── Checklist & tasks ──────────────────────────────── */
.check { display: flex; align-items: flex-start; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.check:last-child { border-bottom: 0; }
.check input[type=checkbox] { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); flex: none; cursor: pointer; }
.check .body { flex: 1; min-width: 0; }
.check .title { font-weight: 500; }
/* Long unbroken words (website addresses, e-mails) wrap instead of running out of the box. */
.check .title, .check .sub, .pb-text, .card-head h3, .tile-foot, .kv dd { overflow-wrap: anywhere; }
/* Inside tables a long badge may take two lines rather than widening the whole table. */
.tbl td .badge { white-space: normal; text-align: left; }
/* Selects in editable tables keep a usable width — the table scrolls sideways instead of squeezing them. */
.tbl td select { min-width: 100px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.region-picks { display: grid; grid-template-columns: repeat(2, max-content); gap: 3px 12px; }
.region-picks label { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.check.done .title { color: var(--muted); text-decoration: line-through; }
.check .sub { font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.prio-1 { box-shadow: inset 3px 0 0 var(--critical); padding-left: 10px; }
.progress-ring { font-size: 13px; color: var(--text-2); font-weight: 600; }

/* ── Pipeline board ─────────────────────────────────── */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 12px; }
.col { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 170px); min-width: 0; }
.col-head { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.col-head .row { justify-content: space-between; }
.col-body { padding: 8px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; min-height: 80px; }
.col.drop { outline: 2px dashed var(--accent); outline-offset: -4px; }
.lead-card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; cursor: pointer; font-size: 13.5px; }
.lead-card:hover { border-color: var(--accent); }
.lead-card .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lead-card .meta { color: var(--muted); font-size: 12.5px; display: flex; gap: 8px; flex-wrap: wrap; margin-top: 3px; }
.lead-card.stale { box-shadow: inset 3px 0 0 var(--warning); }

/* ── Drawer ─────────────────────────────────────────── */
.scrim { position: fixed; inset: 0; background: rgba(10, 12, 16, .45); z-index: 50; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--bg); z-index: 51;
  overflow-y: auto; box-shadow: -8px 0 30px rgba(0,0,0,.2); display: flex; flex-direction: column;
}
.drawer-head { position: sticky; top: 0; background: var(--surface); border-bottom: 1px solid var(--line); padding: 14px 18px; display: flex; gap: 10px; align-items: flex-start; z-index: 2; }
.drawer-body { padding: 16px 18px 40px; display: flex; flex-direction: column; gap: 14px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.kv .ai-an-cell { grid-column: 2; }
.ai-an { margin-top: -2px; }
.ai-an summary { display: inline-block; cursor: pointer; color: var(--accent); font-size: 13px; list-style: none; user-select: none; }
.ai-an summary::-webkit-details-marker { display: none; }
.ai-an summary::after { content: ' ▸'; }
.ai-an[open] summary::after { content: ' ▾'; }
.ai-an dl { display: grid; grid-template-columns: 92px 1fr; gap: 4px 10px; margin: 6px 0 0; padding: 8px 10px; font-size: 13px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; }
.ai-an dt { color: var(--muted); }
.ai-an dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 640px) { .kv .ai-an-cell { grid-column: 1 / -1; } .ai-an dl { grid-template-columns: 1fr; gap: 0 0; } .ai-an dd { margin-bottom: 6px; } }
.stage-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.stage-picker button { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 99px; padding: 4px 11px; font-size: 13px; cursor: pointer; }
.stage-picker button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.timeline { display: flex; flex-direction: column; gap: 8px; }
.tl-item { border-left: 2px solid var(--line-strong); padding: 2px 0 2px 10px; font-size: 13.5px; }
.tl-item.in { border-color: var(--good); }
.tl-item.out { border-color: var(--accent); }
.tl-item .when { color: var(--muted); font-size: 12px; }
.tl-item .txt { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ── Engine ─────────────────────────────────────────── */
.prov { display: flex; flex-direction: column; gap: 8px; }
.prov .summary { font-size: 14px; }
.prov.crit { border-color: color-mix(in srgb, var(--critical) 50%, var(--line)); }
.prov.warn { border-color: color-mix(in srgb, var(--warning) 60%, var(--line)); }
.stat-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.stat-row > div { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.stat-row .k { font-size: 12px; color: var(--muted); }
.stat-row .v { font-size: 17px; font-weight: 600; }

/* ── Login ──────────────────────────────────────────── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 28px; display: flex; flex-direction: column; gap: 14px; }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 8px; z-index: 60; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.toast.err { background: var(--critical); color: #fff; }

/* ── v2: team & follow-up ───────────────────────────── */
.drawer.wide { width: min(880px, 100vw); }
.seg.wrap { flex-wrap: wrap; }
.page-tabs { display: flex; gap: 2px; margin: -8px 0 18px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.page-tabs a { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; margin-bottom: -1px; color: var(--text-2); font-weight: 500;
  border-bottom: 2px solid transparent; white-space: nowrap; text-decoration: none; }
.page-tabs a:hover { color: var(--text); }
.page-tabs a.on { color: var(--text); border-bottom-color: var(--accent); }
.prio {
  display: inline-grid; place-items: center; min-width: 32px; height: 24px; padding: 0 6px; border-radius: 6px; flex: none;
  font-size: 12.5px; font-weight: 600; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.prio.mid { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.prio.hi { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.queue-row { align-items: center; }
.queue-row .prio { margin-top: 1px; }
.rep-filter { min-width: 140px; }
@media (max-width: 760px) {
  .queue-row { flex-wrap: wrap; }
  .queue-row .btn { margin-left: 42px; }
}

/* ─── Inbox ─────────────────────────────────────────────────────────────────── */
.inbox { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); gap: 14px; height: calc(100vh - 150px); min-height: 420px; }
.inbox-list { overflow: auto; padding: 4px; }
.inbox-thread { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.conv { display: block; padding: 9px 10px; border-radius: 8px; color: inherit; border-bottom: 1px solid var(--line); }
.conv:hover { background: var(--surface-2); }
.conv.on { background: var(--accent-soft); }
.conv .sub { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; align-items: center; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.thread-head { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.msgs { flex: 1; overflow: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; background: var(--surface-2); }
.msg { max-width: 78%; display: flex; flex-direction: column; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.msg .bubble { padding: 8px 11px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface); border: 1px solid var(--line); }
.msg.out .bubble { background: var(--accent-soft); border-color: transparent; }
.msg.out .bubble.tpl { background: var(--surface); border-style: dashed; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.reply { padding: 10px 14px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.reply textarea { resize: vertical; min-height: 44px; }
@media (max-width: 860px) {
  .inbox { grid-template-columns: 1fr; height: auto; }
  .inbox-list { max-height: 40vh; }
  .inbox-thread { min-height: 70vh; }
}

/* ─── Leaderboard & playbook ────────────────────────────────────────────────── */
.lb-row { display: grid; grid-template-columns: 22px minmax(110px, 170px) 1fr 52px; gap: 4px 10px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line); }
.lb-row:last-child { border-bottom: 0; }
.lb-row.me .lb-name { color: var(--accent); font-weight: 600; }
.lb-rank { color: var(--muted); font-variant-numeric: tabular-nums; }
.lb-bar { height: 8px; background: var(--track); border-radius: 4px; overflow: hidden; }
.lb-bar i { display: block; height: 100%; background: var(--series); border-radius: 4px; }
.lb-detail { grid-column: 2 / -1; }
.lb-row strong { text-align: right; }
.pb-text { white-space: pre-wrap; line-height: 1.6; }

/* ─── Enrich ────────────────────────────────────────────────────────────────── */
.en-card { scroll-margin-top: 16px; transition: border-color .15s, box-shadow .15s; }
.en-card.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.en-card.done { opacity: .6; }
.en-card.done:hover, .en-card.done:focus-within { opacity: 1; }
.person { padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); }
.person.active { border-color: var(--accent); }
.person.new { border-style: dashed; border-color: var(--good); }
.person.done { padding: 7px 12px; opacity: .8; }
.copy-tile { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px; padding: 10px 14px; border-radius: 10px; text-align: left;
  cursor: pointer; background: var(--surface-2); border: 1px solid var(--line-strong); }
.copy-tile:hover { border-color: var(--accent); background: var(--accent-soft); }
.copy-tile:disabled { opacity: .45; cursor: not-allowed; }
.copy-tile .k { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.copy-tile .v { display: block; font-size: 17px; font-weight: 600; overflow-wrap: anywhere; line-height: 1.3; }
.copy-tile .go { margin-left: auto; flex-shrink: 0; padding: 6px 12px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-size: 13px; font-weight: 600; }
.chip { display: inline-block; margin: 2px 4px 2px 0; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }
input.en-phone { font-size: 17px; padding: 10px 12px; border: 2px solid var(--accent); }
input.missing { border-color: var(--warning); }
input.flash { border-color: var(--good) !important; }
kbd { font-size: 11px; padding: 1px 5px; border-radius: 4px; border: 1px solid var(--line-strong); background: var(--surface-2); }

/* Profile pictures */
.avatar { border-radius: 50%; flex: none; vertical-align: middle; object-fit: cover; }
.avatar.ini { display: inline-grid; place-items: center; background: var(--accent); color: #fff; font-weight: 600; line-height: 1; }
.who { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }

/* ── Product catalogue (Settings → Products) ───────────── */
.prod-thumb { width: 44px; height: 44px; object-fit: contain; border-radius: 6px; background: #fff; border: 1px solid var(--line); display: block; }
.prod-thumb-btn { padding: 0; border: 0; background: none; cursor: pointer; display: block; }
.prod-photo { width: 100%; max-height: 340px; object-fit: contain; background: #000; border-radius: var(--radius); border: 1px solid var(--line); }
.prod-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.prod-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; text-align: left; cursor: pointer; font: inherit; color: inherit; }
.prod-card:hover { border-color: var(--accent); }
.prod-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.prod-card-img { aspect-ratio: 4 / 3; background: #000; border-bottom: 1px solid var(--line); overflow: hidden; }
.prod-card-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.prod-card-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.prod-card-name { color: var(--text-2); }
.prod-card-specs { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prod-card-price { margin-top: auto; padding-top: 6px; font-size: 17px; font-weight: 600; }
@media (max-width: 600px) { .prod-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } .prod-card-body { padding: 8px 10px 10px; } }

/* ── Performance ───────────────────────────────────────── */
.perf-bar { display: inline-block; height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; vertical-align: middle; }
.perf-bar i { display: block; height: 100%; border-radius: 3px; background: var(--muted); }
.perf-bar i.ok { background: var(--good); } .perf-bar i.accent { background: var(--accent); }
.perf-bar i.warn { background: var(--warning); } .perf-bar i.crit { background: var(--critical); }
.perf-score { font-weight: 600; font-variant-numeric: tabular-nums; }
.perf-score.ok { color: var(--good-ink); } .perf-score.accent { color: var(--accent); }
.perf-score.warn { color: var(--warning-ink); } .perf-score.crit { color: var(--critical-ink); } .perf-score.off { color: var(--muted); }
.perf-grade { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; font-weight: 600; color: #fff; background: var(--muted); }
.perf-grade.ok { background: var(--good); } .perf-grade.accent { background: var(--accent); }
.perf-grade.warn { background: var(--warning); color: #1a1a1a; } .perf-grade.crit { background: var(--critical); }
.perf-grade.big { width: 52px; height: 52px; border-radius: 12px; font-size: 26px; }
.perf-team tbody tr { cursor: pointer; }
.perf-team tbody tr:hover td, .perf-team tbody tr.on td { background: var(--accent-soft); }
.perf-kpi { text-align: right; }
.perf-kpi-v { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.perf-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.good-txt { color: var(--good-ink); } .bad-txt { color: var(--critical-ink); }
@media (max-width: 600px) { .perf-grid { grid-template-columns: 1fr; } .perf-kpi { text-align: left; } }
.perf-mini { display: block; color: inherit; }
.perf-mini:hover { border-color: var(--accent); }

/* ─── Phones & small tablets (Sales Manager and OA — OA loads this file as base.css) ─── */
.ib-back { display: none; }
@media (max-width: 860px) {
  /* 16px text in fields: iPhones zoom the whole page into anything smaller when it's tapped. */
  input, select, textarea { font-size: 16px; }
  main { padding: 14px 12px 70px; }
  h1 { font-size: 20px; }
  .page-head { gap: 8px; margin-bottom: 14px; }
  .page-head input[type="search"], .page-head .rep-filter { max-width: none !important; flex: 1 1 100%; }
  .btn { min-height: 38px; }
  .btn.sm { min-height: 34px; padding: 5px 10px; }
  /* Filter tabs: one row you can swipe instead of several wrapped rows. */
  .seg, .seg.wrap { max-width: 100%; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .seg::-webkit-scrollbar { display: none; }
  .seg button { flex: none; white-space: nowrap; padding: 7px 12px; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .tile { padding: 12px 13px; }
  .tile-value { font-size: 24px; }
  .card { padding: 13px; }
  .drawer-head { padding: 12px 14px; }
  .drawer-body { padding: 14px 14px 60px; }
  .form-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  /* WhatsApp inbox: the list, or one conversation full screen with a Back button. */
  .inbox { display: block; height: auto; min-height: 0; }
  .inbox-list { max-height: none; }
  .inbox .inbox-thread { display: none; }
  .inbox.show-thread .inbox-list { display: none; }
  .inbox.show-thread .inbox-thread { display: flex; height: calc(100dvh - 130px); min-height: 380px; }
  .ib-back { display: inline-flex; }
  .msg { max-width: 88%; }
}
/* Tables read as stacked cards on a phone: one card per row, each value with its column name
   (labels are set by labelTables() in core.js; tables with input fields keep their table layout). */
@media (max-width: 640px) {
  table.m-cards thead { display: none; }
  table.m-cards, table.m-cards tbody, table.m-cards tfoot, table.m-cards tr, table.m-cards td { display: block; width: auto !important; }
  table.m-cards tr { padding: 10px 2px; border-bottom: 1px solid var(--line); }
  table.m-cards tbody tr:last-child { border-bottom: 0; }
  table.m-cards tfoot tr { border-top: 1px solid var(--line); border-bottom: 0; }
  table.m-cards td { border: 0; padding: 3px 0; display: flex; gap: 6px 12px; justify-content: space-between; align-items: baseline; flex-wrap: wrap; text-align: right; white-space: normal; }
  table.m-cards td::before { content: attr(data-label); flex: none; margin-right: auto; max-width: 48%; text-align: left; color: var(--muted); font-size: 12px; font-weight: 500; }
  table.m-cards td:not([data-label])::before, table.m-cards td[data-label=""]::before { display: none; }
  table.m-cards td:first-child { justify-content: flex-start; text-align: left; font-weight: 600; font-size: 15px; }
  table.m-cards td:first-child::before { display: none; }
  table.m-cards td:empty { display: none; }
  .table-wrap:has(> table.m-cards) { overflow: visible; }
}

/* ─── Home pages (Today, Team overview) on phones ─── */
.m-only { display: none; }
.rep-card { padding: 12px 0; border-bottom: 1px solid var(--line); }
.rep-card:first-child { padding-top: 2px; }
.rep-card:last-child { border-bottom: 0; padding-bottom: 0; }
.rc-head, .rc-foot { display: flex; align-items: center; gap: 8px; }
.rc-head .spacer, .rc-foot .spacer { flex: 1; }
.rc-head .who { font-weight: 600; min-width: 0; }
.rc-score { font-size: 20px; font-weight: 600; min-width: 28px; text-align: right; }
.rc-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin: 10px 0; }
.rc-stat { background: var(--track); border-radius: 8px; padding: 6px 4px; text-align: center; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.rc-stat .num { font-size: 17px; font-weight: 600; line-height: 1.2; }
.rc-stat .num small { font-size: 11px; color: var(--muted); font-weight: 500; }
.rc-stat > span:last-child { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rc-bars { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 12px; margin-bottom: 8px; font-size: 12px; color: var(--text-2); }
.rc-bars > div { display: grid; grid-template-columns: minmax(0, 1fr) 30px 22px; align-items: center; gap: 5px; }
.rc-bars .num { text-align: right; }
@media (max-width: 640px) {
  .m-only { display: block; }
  .m-hide { display: none !important; }
  .btn.m-only { display: flex; width: 100%; justify-content: center; margin-top: 8px; }
  /* Title on its own line, the page's buttons share the next row. */
  .home-head > div:first-child { flex: 1 1 100%; }
  .home-head .spacer { display: none; }
  .home-head .btn { flex: 1 1 0; justify-content: center; }
  /* Tiles: two per row, a lone last tile takes the whole row; the "vs yesterday" note is dropped to keep them short. */
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tiles > .tile:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .tile { padding: 10px 12px; gap: 3px; }
  .tile-label { font-size: 12.5px; line-height: 1.3; }
  .tile-value { font-size: 22px; }
  .tile-foot { font-size: 12px; min-height: 0; }
  .tile-foot .vs { display: none; }
  /* Work queue: first 5 rows until "Show more"; the short "Log" button leaves room for the company name. */
  .queue-list:not(.all) > .queue-row:nth-child(n+6) { display: none; }
  .queue-row { align-items: center; padding: 10px 2px; }
  .queue-row .btn { flex: none; }
}
/* Home-page tiles share the whole row instead of leaving an empty slot at the end. */
.tiles.fit { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
/* Team table: the focus tag sits on the name's line; the name opens that rep's follow-ups. */
.team-tbl .rep-cell { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.team-tbl .rep-cell a { color: inherit; }
.team-tbl .rep-cell a:hover { color: var(--accent); }
.team-tbl td { vertical-align: middle; }
.team-tbl .rep-cell .badge { white-space: nowrap; }
.team-tbl th, .team-tbl td { padding-left: 5px; padding-right: 5px; }
.team-tbl th { letter-spacing: .02em; }
