:root {
  --bg: #f3f4f8;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --glass: rgba(255, 255, 255, 0.78);
  --line: rgba(20, 28, 60, 0.09);
  --line-strong: rgba(20, 28, 60, 0.16);
  --text: #11152b;
  --muted: #6a7088;
  --faint: #9aa0b4;
  --brand: #1b2a6b;
  --brand-ink: #ffffff;
  --accent: #e30613;
  --focus: rgba(46, 84, 230, 0.35);
  --shadow: 0 1px 2px rgba(17, 21, 43, 0.04), 0 8px 24px rgba(17, 21, 43, 0.06);
  --shadow-lg: 0 24px 64px rgba(17, 21, 43, 0.18);
  --radius: 18px;
  --s-new: #7b8196;      --s-new-bg: rgba(123, 129, 150, 0.13);
  --s-interested: #2f6bdc; --s-interested-bg: rgba(47, 107, 220, 0.12);
  --s-qualified: #6a3fd8; --s-qualified-bg: rgba(106, 63, 216, 0.12);
  --s-handoff: #d9730d;  --s-handoff-bg: rgba(217, 115, 13, 0.14);
  --s-in_progress: #0f8a8a; --s-in_progress-bg: rgba(15, 138, 138, 0.13);
  --s-won: #1f9d4c;      --s-won-bg: rgba(31, 157, 76, 0.13);
  --s-lost: #c43c3c;     --s-lost-bg: rgba(196, 60, 60, 0.12);
  --bubble-user: #eef0f6;
  --bubble-ai: #1b2a6b;
  --bubble-manager: #0f8a8a;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0e1a; --surface: #141829; --surface-2: #191e33; --glass: rgba(20, 24, 41, 0.78);
    --line: rgba(255, 255, 255, 0.08); --line-strong: rgba(255, 255, 255, 0.16);
    --text: #eef0f8; --muted: #9ba2bd; --faint: #6c7390; --brand: #8ea2ff; --brand-ink: #0b0e1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25); --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.5);
    --bubble-user: #1f2540; --bubble-ai: #2b3a85; --bubble-manager: #0e6b6b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0e1a; --surface: #141829; --surface-2: #191e33; --glass: rgba(20, 24, 41, 0.78);
  --line: rgba(255, 255, 255, 0.08); --line-strong: rgba(255, 255, 255, 0.16);
  --text: #eef0f8; --muted: #9ba2bd; --faint: #6c7390; --brand: #8ea2ff; --brand-ink: #0b0e1a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25); --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.5);
  --bubble-user: #1f2540; --bubble-ai: #2b3a85; --bubble-manager: #0e6b6b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
a { color: inherit; }

/* ── floating nav ── */
.nav {
  position: sticky; top: 12px; z-index: 20;
  margin: 12px auto 0; width: min(1240px, calc(100% - 24px));
  display: flex; align-items: center; gap: 12px;
  padding: 8px 8px 8px 14px;
  background: var(--glass);
  backdrop-filter: saturate(1.6) blur(18px); -webkit-backdrop-filter: saturate(1.6) blur(18px);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.nav__brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.nav__brand img { border-radius: 8px; }
.nav__brand strong { display: block; font-size: 14px; letter-spacing: -0.01em; }
.nav__brand span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search {
  flex: 1; display: flex; align-items: center; gap: 8px; max-width: 420px; margin-left: auto;
  padding: 0 14px; height: 38px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted);
}
.search input { flex: 1; min-width: 0; border: 0; background: none; outline: none; color: var(--text); height: 100%; }
.nav__actions { display: flex; gap: 6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 16px; border-radius: 999px; border: 1px solid transparent;
  background: var(--brand); color: var(--brand-ink); font-weight: 600; text-decoration: none; cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease, opacity 0.2s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn--ghost { background: var(--surface-2); color: var(--text); border-color: var(--line); }
.btn--ghost:hover { border-color: var(--line-strong); }
.btn--icon { width: 38px; padding: 0; background: var(--surface-2); color: var(--text); border-color: var(--line); }
.btn--sm { height: 32px; padding: 0 12px; font-size: 13px; }

/* ── page ── */
.page { width: min(1240px, calc(100% - 24px)); margin: 20px auto 48px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
}
.stat b { display: block; font-size: 28px; line-height: 1.1; letter-spacing: -0.03em; font-weight: 700; }
.stat span { color: var(--muted); font-size: 13px; }
.stat small { display: block; margin-top: 6px; color: var(--faint); font-size: 12px; }
.stat--accent b { color: var(--s-handoff); }
.stat--hot b { color: var(--accent); }

.filters { margin: 18px 0 12px; display: grid; gap: 8px; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  cursor: pointer; white-space: nowrap; font-weight: 500; transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.chip em { font-style: normal; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip[aria-pressed="true"] em { color: inherit; opacity: 0.7; }
.chips--soft .chip { height: 30px; font-size: 13px; background: transparent; }
.chips--soft .chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }

/* ── list ── */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list__head, .row {
  display: grid; grid-template-columns: minmax(180px, 1.4fr) minmax(120px, 1fr) 140px minmax(150px, 1.2fr) 180px 100px;
  gap: 14px; align-items: center; padding: 0 18px;
}
.list__head { height: 40px; color: var(--faint); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--line); }
.row { min-height: 64px; border-bottom: 1px solid var(--line); cursor: pointer; transition: background 0.15s; text-decoration: none; }
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--surface-2); }
.row.is-active { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--brand); }
.who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 700; font-size: 14px; color: #fff; background: var(--brand);
}
.who__text { min-width: 0; }
.who__text b, .who__text span, .cell { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who__text span, .muted { color: var(--muted); font-size: 12px; }
.cell--phone { font-variant-numeric: tabular-nums; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: 12px; white-space: nowrap; }
.status { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.state { display: flex; align-items: center; gap: 6px; min-width: 0; }
.empty { text-align: center; color: var(--muted); padding: 48px 0; margin: 0; }

/* ── drawer ── */
.scrim { position: fixed; inset: 0; background: rgba(8, 10, 22, 0.32); z-index: 30; opacity: 0; transition: opacity 0.25s; }
.scrim.is-open { opacity: 1; }
.drawer {
  position: fixed; top: 12px; right: 12px; bottom: 12px; z-index: 31; width: min(620px, calc(100% - 24px));
  background: var(--surface); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; overflow: hidden;
  transform: translateX(calc(100% + 24px)); transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1); visibility: hidden;
}
.drawer.is-open { transform: none; visibility: visible; }
.drawer__head { display: flex; align-items: center; gap: 14px; padding: 18px 18px 14px; border-bottom: 1px solid var(--line); }
.drawer__head .avatar { width: 48px; height: 48px; font-size: 18px; }
.drawer__title { flex: 1; min-width: 0; }
.drawer__title h2 { margin: 0; font-size: 19px; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer__title p { margin: 2px 0 0; color: var(--muted); font-size: 13px; display: flex; gap: 10px; flex-wrap: wrap; }
.drawer__title a { color: var(--brand); text-decoration: none; }
.drawer__body { flex: 1; overflow-y: auto; padding: 16px 18px 24px; display: grid; gap: 14px; align-content: start; overscroll-behavior: contain; }

.controls { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; }
.field { display: grid; gap: 4px; min-width: 0; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 500; }
.input, .select, .textarea {
  width: 100%; height: 38px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line-strong);
  background: var(--surface-2); outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.textarea { height: auto; min-height: 76px; padding: 10px 12px; resize: vertical; line-height: 1.45; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--focus); }
.switch { display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--surface-2); cursor: pointer; white-space: nowrap; font-size: 13px; }
.switch input { accent-color: var(--s-handoff); width: 16px; height: 16px; }

.card { border: 1px solid var(--line); border-radius: 16px; padding: 14px; background: var(--surface); }
.card > h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--faint); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.summary { margin: 0; font-size: 14px; line-height: 1.55; white-space: pre-wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 .wide { grid-column: 1 / -1; }
.dirpick { display: flex; flex-wrap: wrap; gap: 6px; }
.dirpick label { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line-strong); cursor: pointer; font-size: 13px; user-select: none; }
.dirpick input { display: none; }
.dirpick label:has(input:checked) { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.savebar { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

.chat { display: grid; gap: 8px; max-height: 460px; overflow-y: auto; padding: 4px 2px; overscroll-behavior: contain; }
.msg { max-width: 82%; padding: 9px 12px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; font-size: 13.5px; line-height: 1.45; }
.msg small { display: block; margin-top: 4px; font-size: 11px; opacity: 0.65; }
.msg--user { background: var(--bubble-user); border-bottom-left-radius: 6px; justify-self: start; }
.msg--assistant { background: var(--bubble-ai); color: #fff; border-bottom-right-radius: 6px; justify-self: end; }
.msg--manager { background: var(--bubble-manager); color: #fff; border-bottom-right-radius: 6px; justify-self: end; }
.msg--event { justify-self: center; background: none; color: var(--muted); font-size: 12px; padding: 2px 8px; text-align: center; max-width: 92%; }
.composer { display: flex; gap: 8px; margin-top: 10px; align-items: flex-end; }
.composer .textarea { min-height: 42px; height: 42px; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.timeline li { display: grid; grid-template-columns: 92px 1fr; gap: 10px; font-size: 13px; }
.timeline time { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 50; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: 13px;
  transition: opacity 0.25s, transform 0.25s;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ── smaller screens ── */
@media (max-width: 1080px) {

  .list__head { display: none; }
  .row { grid-template-columns: 1fr auto; grid-template-areas: "who status" "tags time"; padding: 12px 16px; gap: 6px 12px; }
  .row > :nth-child(1) { grid-area: who; }
  .row > :nth-child(2), .row > :nth-child(3) { display: none; }
  .row > :nth-child(4) { grid-area: tags; }
  .row > :nth-child(5) { grid-area: status; justify-self: end; }
  .row > :nth-child(6) { grid-area: time; justify-self: end; }
}
@media (max-width: 640px) {
  .nav { flex-wrap: wrap; border-radius: 24px; padding: 10px; top: 8px; }
  .nav__brand span { display: none; }
  .search { order: 3; max-width: none; flex-basis: 100%; margin: 0; }
  .nav__actions { margin-left: auto; }
  .nav__actions .btn span { display: none; }
  .nav__actions .btn--ghost { width: 38px; padding: 0; }
  .page { width: calc(100% - 32px); }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat { padding: 12px 14px; }
  .stat b { font-size: 22px; }
  .stat:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .drawer { top: 0; right: 0; bottom: 0; width: 100%; border-radius: 0; border: 0; }
  .controls, .grid2 { grid-template-columns: 1fr; }
  .controls .switch { justify-content: center; }
  .timeline li { grid-template-columns: 1fr; gap: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ── sign-in gate: staff only ─────────────────────────── */
.gate { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: var(--bg); }
.gate[hidden] { display: none; }
.gate__card { max-width: 420px; display: grid; justify-items: center; gap: 14px; padding: 34px 28px; text-align: center; border-radius: 24px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.gate__card h1 { margin: 0; font-size: 22px; }
.gate__card p { margin: 0; color: var(--muted); line-height: 1.5; }

/* ── staff dialog (owners) ────────────────────────────── */
.modal { width: min(520px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line); border-radius: 22px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
.modal::backdrop { background: rgba(10, 14, 30, 0.45); }
.modal__body { display: grid; gap: 14px; padding: 22px; }
.modal__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal__head h2 { margin: 0; font-size: 19px; }
.staff { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.staff li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: 14px; background: var(--surface-2); }
.staff small { color: var(--faint); }
.staff-add { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
@media (max-width: 520px) { .staff-add { grid-template-columns: 1fr; } }

/* ── roles ────────────────────────────────────────────── */
.assignee { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--line); }
.assignee__k { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.assignee .select { flex: 1; }
.owner-tag { font-size: 12px; color: var(--muted); white-space: nowrap; }
.chip--mine[aria-pressed='true'] { background: var(--accent); border-color: var(--accent); color: #fff; }
.staff li { flex-wrap: wrap; }
.staff__who { display: grid; gap: 2px; }
.staff__warn { font-style: normal; font-size: 12px; color: #d9730d; }
.staff__acts { display: flex; align-items: center; gap: 8px; }
.select--sm { height: 32px; padding: 0 28px 0 10px; font-size: 13px; }
.staff-add { grid-template-columns: 1fr 1fr auto auto; }
@media (max-width: 520px) { .staff-add { grid-template-columns: 1fr; } }
.staff__acts .btn { white-space: nowrap; }
