/* CheaperBlue. Visual spec: designs/DESIGN.md. Plain CSS, custom properties, single-class
   selectors (plus a few element resets). Dark is the default; light is `.theme-light` on html. */

/* ---- Fonts (self-hosted, OFL; downloaded by make setup) ------------------------------- */
@font-face {
  font-family: "Mona Sans"; font-style: normal; font-display: swap;
  font-weight: 200 900; font-stretch: 75% 125%;
  src: url(/static/fonts/mona-sans-latin.woff2) format("woff2-variations"), url(/static/fonts/mona-sans-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Mona Sans"; font-style: normal; font-display: swap;
  font-weight: 200 900; font-stretch: 75% 125%;
  src: url(/static/fonts/mona-sans-latin-ext.woff2) format("woff2-variations"), url(/static/fonts/mona-sans-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Atkinson Hyperlegible Next"; font-style: normal; font-display: swap;
  font-weight: 200 800;
  src: url(/static/fonts/atkinson-hyperlegible-next-latin.woff2) format("woff2-variations"), url(/static/fonts/atkinson-hyperlegible-next-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Atkinson Hyperlegible Next"; font-style: normal; font-display: swap;
  font-weight: 200 800;
  src: url(/static/fonts/atkinson-hyperlegible-next-latin-ext.woff2) format("woff2-variations"), url(/static/fonts/atkinson-hyperlegible-next-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ---- Tokens --------------------------------------------------------------------------- */
:root {
  --ground: #101722;
  --pane: #151E2B;
  --raised: #1B2636;
  --rule: #263244;
  --ink: #E6ECF5;
  --muted: #8D9AAD;
  --bubble-out: #2F7CF6;
  --bubble-out-ink: #FFFFFF;
  --bubble-in: #222E40;
  --aqua: #3DD6C6;  --aqua-glow: rgb(61 214 198 / 0.22);
  --iris: #8F96FF;  --iris-glow: rgb(143 150 255 / 0.22);
  --orchid: #DE7CF2; --orchid-glow: rgb(222 124 242 / 0.22);
  --peach: #FF9F6E; --peach-glow: rgb(255 159 110 / 0.22);
  --on-line: #101722;        /* text on line-color fills */
  --ok: #4ADE80;
  --caution: #EAB308;
  --down: #F25F5C;
  --on-down: #101722;
  --font-display: "Mona Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-text: "Atkinson Hyperlegible Next", system-ui, -apple-system, "Segoe UI", sans-serif;
  --rail-w: 76px;
  --side-w: 300px;
  --line: var(--muted);
  --line-glow: transparent;
  color-scheme: dark;
}
.theme-light {
  --ground: #F3F5F8;
  --pane: #FFFFFF;
  --raised: #EDF1F6;
  --rule: #D8DEE7;
  --ink: #172130;
  --muted: #5A6678;
  --bubble-in: #E4E9F0;
  --bubble-out: #1F6FE5;
  --aqua: #0E8C80;  --aqua-glow: rgb(14 140 128 / 0.22);
  --iris: #4F57D9;  --iris-glow: rgb(79 87 217 / 0.22);
  --orchid: #A23DB8; --orchid-glow: rgb(162 61 184 / 0.22);
  --peach: #C2541F; --peach-glow: rgb(194 84 31 / 0.22);
  --on-line: #FFFFFF;
  --on-down: #FFFFFF;
  color-scheme: light;
}

/* Line signal colors: set --line on an element; its parts read it. */
.line-aqua   { --line: var(--aqua);   --line-glow: var(--aqua-glow); }
.line-iris   { --line: var(--iris);   --line-glow: var(--iris-glow); }
.line-orchid { --line: var(--orchid); --line-glow: var(--orchid-glow); }
.line-peach  { --line: var(--peach);  --line-glow: var(--peach-glow); }
.line-none   { --line: var(--muted);  --line-glow: transparent; }

/* ---- Base ----------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--ground); color: var(--ink);
  font-family: var(--font-text); font-size: 14px; line-height: 1.45;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, p, ol, ul, dl, dd, blockquote { margin: 0; padding: 0; }
ol, ul { list-style: none; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.icon { width: 20px; height: 20px; flex: none; }
.icon-sm { width: 16px; height: 16px; flex: none; }
.num { font-variant-numeric: tabular-nums; }

/* ---- App shell ------------------------------------------------------------------------ */
.app { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); height: 100vh; overflow: hidden; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.content { flex: 1; min-height: 0; display: flex; }

/* Nav rail */
.rail {
  display: flex; flex-direction: column; align-items: stretch; gap: 2px;
  background: var(--ground); border-right: 1px solid var(--rule); padding: 10px 3px; min-height: 0;
}
.rail-brand { display: flex; justify-content: center; padding: 6px 0 12px; color: var(--ink); }
.rail-nav { display: flex; flex-direction: column; gap: 2px; flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.rail-item, .rail-item-active {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 0; border-radius: 8px; color: var(--muted);
}
.rail-item:hover { background: var(--raised); color: var(--ink); }
.rail-item-active { background: var(--raised); color: var(--ink); }
.rail-label { font-size: 12px; line-height: 1.4; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
/* Line and phone status: always fully visible. Names wrap; nothing is clipped or ellipsized. */
.rail-status { flex: none; margin-top: 8px; display: flex; flex-direction: column; gap: 8px; padding: 10px 3px 0; border-top: 1px solid var(--rule); }
.rail-line { display: grid; grid-template-columns: 4px minmax(0, 1fr); column-gap: 5px; row-gap: 1px; font-size: 12px; line-height: 1.4; }
.rail-line-bar { grid-row: span 2; background: var(--line); border-radius: 2px; }
.rail-line-name { color: var(--ink); overflow-wrap: anywhere; min-width: 0; }
.rail-phone { display: flex; flex-direction: column; gap: 1px; font-size: 12px; line-height: 1.4; padding-left: 2px; }
.rail-phone-name { color: var(--ink); overflow-wrap: anywhere; }

/* Status: always an icon and a word; color only when it isn't fine. */
.status { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; line-height: 1.4; color: var(--muted); white-space: nowrap; }
.status-ok { color: var(--muted); }
.icon-ok { color: var(--ok); }  /* fine: only the icon carries the color */
.status-down { color: var(--down); }
.status-caution { color: var(--caution); }
.status-wait { color: var(--muted); }
.status-muted { color: var(--muted); }

/* Offline banner: full width, loud */
.banner-slot { display: flex; flex-direction: column; }
.banner {
  display: flex; align-items: center; gap: 10px; padding: 10px 20px;
  background: var(--down); color: var(--on-down); font-size: 14px;
}
.banner-text { min-width: 0; }

/* Top bar */
.topbar {
  display: grid; grid-template-columns: auto auto 1fr auto; grid-template-areas: "title switch demo palette" "stats stats stats stats";
  align-items: center; column-gap: 16px; row-gap: 6px;
  padding: 14px 20px 12px; border-bottom: 1px solid var(--rule); background: var(--ground);
}
.view-title { grid-area: title; font-family: var(--font-display); font-weight: 700; font-stretch: 120%; font-size: 28px; line-height: 1.15; letter-spacing: 0; }
.demo-control { grid-area: demo; justify-self: end; display: flex; align-items: center; gap: 8px; }
.demo-label { font-size: 12px; color: var(--muted); }
.palette-trigger {
  grid-area: palette; display: inline-flex; align-items: center; gap: 8px; min-width: 260px;
  padding: 7px 10px; border-radius: 8px; border: 1px solid var(--rule); background: var(--pane); color: var(--muted); cursor: pointer;
}
.palette-trigger:hover { border-color: var(--muted); }
.biz-switch { grid-area: switch; display: flex; flex-wrap: wrap; gap: 6px; }
.palette-text { flex: 1; text-align: left; }
.kbd { font-family: var(--font-text); font-size: 12px; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--rule); color: var(--muted); }
.stats { grid-area: stats; display: flex; align-items: baseline; gap: 28px; }
.stat { display: inline-flex; align-items: baseline; gap: 8px; }
.stat-num { font-family: var(--font-display); font-weight: 650; font-stretch: 115%; font-size: 28px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; color: var(--muted); }

/* ---- Buttons and inputs --------------------------------------------------------------- */
.btn, .btn-primary, .btn-send, .btn-assign {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--rule);
  background: var(--raised); color: var(--ink); font-size: 14px; line-height: 1.3; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn-primary, .btn-send, .btn-assign { background: var(--line); border-color: var(--line); color: var(--on-line); font-weight: 600; }
.btn:disabled, .btn-send:disabled { background: var(--raised); border-color: var(--rule); color: var(--muted); cursor: not-allowed; font-weight: 400; }
.input, .composer-input, .stage-select {
  background: var(--raised); border: 1px solid var(--rule); border-radius: 8px; color: var(--ink); padding: 7px 10px;
}
.inline-error { color: var(--down); font-size: 14px; flex-basis: 100%; }

/* ---- Inbox ---------------------------------------------------------------------------- */
.inbox { flex: 1; display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 0; }
.list-pane, .list-pane-away { display: flex; flex-direction: column; min-height: 0; background: var(--pane); border-right: 1px solid var(--rule); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--rule); }
.chips:empty { display: none; }
.chip, .chip-active {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--rule); font-size: 12px; line-height: 1.4; color: var(--muted); white-space: nowrap;
}
.chip:hover { color: var(--ink); background: var(--raised); }
.chip-active { background: var(--raised); color: var(--ink); border-color: var(--muted); }
.chip-dot { width: 8px; height: 8px; border-radius: 999px; background: var(--line); }
.chip-count { color: var(--muted); }
.list-scroll { flex: 1; overflow-y: auto; min-height: 0; }
.conv-row, .conv-row-selected {
  display: grid; grid-template-columns: 4px minmax(0, 1fr) auto; align-items: stretch;
  border-bottom: 1px solid var(--rule); min-height: 62px;
}
.conv-row:hover { background: var(--raised); }
.conv-row-selected { background: var(--raised); }
.conv-bar { background: var(--line); }
.conv-main { display: flex; flex-direction: column; justify-content: center; gap: 2px; padding: 9px 12px; min-width: 0; }
.conv-top { display: flex; align-items: baseline; gap: 8px; }
.conv-name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 12px; color: var(--muted); }
.conv-preview { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-waiting { align-self: center; width: 8px; height: 8px; margin-right: 12px; border-radius: 999px; background: var(--ink); }
.row-tint { animation: row-tint 600ms ease-out; }
@keyframes row-tint { from { background: var(--line-glow); } to { background: transparent; } }
.empty { padding: 16px; color: var(--muted); }

.workspace, .workspace-empty { display: grid; grid-template-columns: minmax(0, 1fr) var(--side-w); min-height: 0; min-width: 0; }
.workspace-empty { grid-template-columns: 1fr; align-items: center; justify-items: center; }
.workspace-hint { color: var(--muted); }

/* Thread */
.thread { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--ground); }
.thread-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; padding: 12px 20px; border-bottom: 1px solid var(--rule); background: var(--pane); }
.back-link { display: none; align-items: center; gap: 4px; color: var(--muted); font-size: 14px; flex-basis: 100%; }
.thread-name { font-size: 18px; line-height: 1.3; font-weight: 700; }
.chip-line { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 999px; background: var(--line); color: var(--on-line); font-size: 12px; line-height: 1.4; font-weight: 600; }
.chip-unassigned { display: inline-flex; padding: 1px 10px; border-radius: 999px; border: 1px dashed var(--muted); color: var(--muted); font-size: 12px; }
.chip-tag { display: inline-flex; padding: 1px 8px; margin: 0 4px 4px 0; border-radius: 999px; border: 1px solid var(--rule); font-size: 12px; }
.stage-form { margin-left: auto; }
.stage-select { padding: 5px 8px; }
.details-toggle { display: none; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 8px; border: 1px solid var(--rule); background: var(--raised); cursor: pointer; }
.thread-scroll { flex: 1; overflow-y: auto; min-height: 0; padding: 20px 24px 8px; }
.messages { display: flex; flex-direction: column; gap: 10px; }
.msg-in, .msg-out { display: flex; flex-direction: column; max-width: 60ch; }
.msg-in { align-self: flex-start; align-items: flex-start; }
.msg-out { align-self: flex-end; align-items: flex-end; }
.bubble-in, .bubble-out { padding: 8px 13px; border-radius: 16px; font-size: 15px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble-in { background: var(--bubble-in); color: var(--ink); }
.bubble-out { background: var(--bubble-out); color: var(--bubble-out-ink); }
.msg-meta { display: flex; gap: 8px; margin-top: 3px; font-size: 12px; line-height: 1.4; color: var(--muted); }
.msg-status-ok { color: var(--muted); }
.msg-status-wait { color: var(--muted); }
.msg-status-bad { color: var(--down); }
.msg-detail { font-size: 12px; color: var(--muted); max-width: 60ch; text-align: right; }

/* ---- The From band (the one thing that glows) ----------------------------------------- */
.band-normal, .band-manual, .band-blocked-caution, .band-blocked-down, .band-offline {
  margin: 8px 20px 16px; padding: 12px 14px; border-radius: 8px; background: var(--pane);
  display: flex; flex-direction: column; gap: 10px;
}
.band-normal { border: 1px solid var(--line); box-shadow: 0 0 0 1px var(--line), 0 0 28px var(--line-glow); }
.band-manual { border: 1px dashed var(--line); }
.band-blocked-caution { border: 1px solid var(--caution); }
.band-blocked-down { border: 1px solid var(--down); }
.band-offline { border: 1px solid var(--muted); }
.band-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; font-size: 18px; line-height: 1.3; }
.band-from { font-size: 12px; color: var(--muted); }
.band-line { font-family: var(--font-display); font-weight: 700; font-stretch: 120%; color: var(--line); }
.band-line-none { color: var(--muted); }
.band-phone { color: var(--ink); font-variant-numeric: tabular-nums; }
.band-state { margin-left: auto; }
.band-admin-note { font-size: 12px; color: var(--caution); }
.band-message { font-size: 14px; }
.band-pending { padding: 8px 12px; border-left: 3px solid var(--line); background: var(--raised); border-radius: 8px; font-size: 15px; white-space: pre-wrap; }
.band-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.composer { display: flex; align-items: flex-end; gap: 10px; }
.composer-input { flex: 1; min-height: 44px; max-height: 40vh; resize: vertical; font-size: 15px; line-height: 1.45; }
.composer-buttons { display: flex; gap: 8px; }

/* ---- Facts panel ---------------------------------------------------------------------- */
.facts { background: var(--pane); border-left: 1px solid var(--rule); overflow-y: auto; min-height: 0; }
.facts-body { padding: 14px 16px 20px; }
.facts-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.pane-title { font-size: 18px; line-height: 1.3; font-weight: 700; }
.facts-close { display: none; padding: 4px; border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 8px; }
.facts-list { display: flex; flex-direction: column; }
.fact-label { display: block; font-size: 12px; line-height: 1.4; color: var(--muted); margin-top: 12px; }
.fact-value, .fact-value-num { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.fact-value-num { font-variant-numeric: tabular-nums; }
.fact-meta { font-size: 12px; color: var(--muted); }
.fact-missing { color: var(--muted); }
.fact-line { display: inline-flex; align-items: center; gap: 6px; }
.note { display: flex; flex-direction: column; padding: 6px 0; border-bottom: 1px solid var(--rule); }
.optin-form { display: flex; flex-direction: column; gap: 6px; align-items: stretch; width: 100%; margin-top: 6px; }

/* ---- Placeholder views ---------------------------------------------------------------- */
.placeholder { flex: 1; display: flex; flex-direction: column; gap: 14px; align-items: flex-start; padding: 24px 20px; background: var(--pane); }
.placeholder-text { color: var(--muted); max-width: 60ch; }

/* ---- Sign-in -------------------------------------------------------------------------- */
.signin-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; background: var(--ground); color: var(--ink); }
.signin-card { width: min(420px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 28px 24px; background: var(--pane); border: 1px solid var(--rule); border-radius: 8px; }
.signin-brand { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 650; }
.signin-title { font-family: var(--font-display); font-weight: 650; font-stretch: 115%; font-size: 28px; line-height: 1.15; }
.signin-text { color: var(--muted); }
.signin-form { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.signin-help { font-size: 12px; color: var(--muted); }

/* ---- Settings and the admin area ------------------------------------------------------- */
.settings { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; padding: 20px; background: var(--pane); }
.settings-section { display: flex; flex-direction: column; gap: 10px; padding-bottom: 18px; border-bottom: 1px solid var(--rule); max-width: 1100px; }
.settings-saved { padding: 8px 12px; border: 1px solid var(--ok); border-radius: 8px; color: var(--ink); max-width: 1100px; }
.settings-note { color: var(--muted); max-width: 70ch; }
.settings-sub { font-size: 14px; font-weight: 600; }
.settings-facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; align-items: baseline; }
.settings-form { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.settings-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; width: 100%; max-width: 720px; }
.settings-card { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--rule); border-radius: 8px; background: var(--ground); max-width: 720px; width: 100%; }
.settings-grid { display: grid; grid-template-columns: minmax(140px, max-content) minmax(0, 1fr); gap: 8px 14px; align-items: center; width: 100%; }
.settings-list { display: flex; flex-direction: column; gap: 6px; }
.settings-line, .settings-person { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--rule); border-radius: 8px; background: var(--ground); }
.settings-line-main { flex: 1 1 240px; }
.settings-usage { font-size: 12px; color: var(--muted); white-space: nowrap; }
.settings-inline { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.settings-num { width: 80px; }
.settings-check { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; }
.settings-fieldset { display: flex; flex-direction: column; gap: 6px; border: 0; }
.settings-steps { display: flex; flex-direction: column; gap: 6px; padding-left: 20px; max-width: 80ch; }

/* ---- Shared bits for the CRM views ---------------------------------------------------- */
.link { text-decoration: underline; text-underline-offset: 2px; color: var(--ink); }
.btn-save {
  display: inline-flex; align-items: center; justify-content: center; padding: 7px 14px; border-radius: 8px;
  border: 1px solid var(--ink); background: var(--ink); color: var(--ground); font-size: 14px; line-height: 1.3; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.facts-link { font-size: 12px; color: var(--muted); text-decoration: underline; text-underline-offset: 2px; margin-left: auto; margin-right: 8px; }
.fact-form { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; width: 100%; margin-top: 6px; }
.note-input { width: 100%; min-height: 52px; resize: vertical; background: var(--raised); border: 1px solid var(--rule); border-radius: 8px; color: var(--ink); padding: 7px 10px; }
.tag-list { display: flex; flex-wrap: wrap; }
.input { width: 100%; }
.conv-waiting-inline { display: inline-block; width: 8px; height: 8px; margin-left: 8px; border-radius: 999px; background: var(--ink); vertical-align: middle; }

/* ---- Contacts ------------------------------------------------------------------------- */
.contacts { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--pane); }
.contacts-tools { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--rule); }
.contacts-search { flex: 1; max-width: 420px; display: flex; align-items: center; gap: 8px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--rule); background: var(--raised); color: var(--muted); }
.search-input { flex: 1; min-width: 0; border: 0; background: transparent; color: var(--ink); padding: 7px 0; }
.search-input:focus-visible { outline: none; }
.contacts-search:focus-within { outline: 2px solid var(--ink); outline-offset: 2px; }
.contacts-results { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.filter-groups { display: flex; flex-wrap: wrap; gap: 8px 20px; padding: 10px 16px; border-bottom: 1px solid var(--rule); }
.filter-group { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.filter-label { font-size: 12px; color: var(--muted); margin-right: 2px; }
.row-count { padding: 8px 16px; font-size: 12px; color: var(--muted); }
.table-scroll { flex: 1; min-height: 0; overflow: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 1.45; }
.th, .th-wide {
  position: sticky; top: 0; z-index: 1; background: var(--pane); text-align: left; font-weight: 400;
  font-size: 12px; line-height: 1.4; color: var(--muted); padding: 8px 12px; border-bottom: 1px solid var(--rule); white-space: nowrap;
}
.th-sort { display: inline-flex; gap: 2px; color: inherit; }
.th-sort:hover { color: var(--ink); }
.sort-mark { font-size: 10px; }
.row { height: 40px; cursor: pointer; }
.row:hover { background: var(--raised); }
.row-plain { height: 40px; }
.td, .td-name, .td-num, .td-wide, .td-wide-num, .td-wide-clip {
  padding: 0 12px; height: 40px; border-bottom: 1px solid var(--rule); white-space: nowrap; vertical-align: middle;
}
.td-num, .td-wide-num { font-variant-numeric: tabular-nums; }
.td-wide-clip { max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
.row-link { font-weight: 600; }

/* Add contact: a slide-over panel */
.add-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(400px, 100vw); z-index: 30; overflow-y: auto;
  background: var(--pane); border-left: 1px solid var(--rule); transform: translateX(100%); visibility: hidden;
}
.add-panel-open { transform: none; visibility: visible; }
.add-form { display: flex; flex-direction: column; align-items: stretch; gap: 6px; padding: 14px 16px 20px; }
.line-pick { border: 0; padding: 0; margin: 6px 0 0; display: flex; flex-direction: column; gap: 6px; }
.line-option { display: grid; grid-template-columns: auto auto 1fr; justify-items: start; align-items: center; gap: 4px 8px; padding: 8px 10px; border: 1px solid var(--rule); border-radius: 8px; cursor: pointer; }
.line-option:hover { background: var(--raised); }
.line-option-meta { grid-column: 2 / -1; font-size: 12px; color: var(--muted); }
.line-option:focus-within { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ---- Contact record ------------------------------------------------------------------- */
.record { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr); min-height: 0; min-width: 0; }
.record-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 12px 20px; border-bottom: 1px solid var(--rule); background: var(--pane); }
.back-link-always { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 14px; flex-basis: 100%; }
.back-link-always:hover { color: var(--ink); }
.record-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; min-width: 0; }
.record-name { font-family: var(--font-display); font-weight: 700; font-stretch: 120%; font-size: 28px; line-height: 1.15; overflow-wrap: anywhere; }
.record-phone { color: var(--muted); font-variant-numeric: tabular-nums; }
.event-line, .event-note { display: flex; align-items: baseline; gap: 8px; font-size: 14px; color: var(--muted); max-width: 72ch; }
.event-note { color: var(--ink); }
.event-text { flex: 0 1 auto; min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.event-label { color: var(--muted); }
.event-time { font-size: 12px; color: var(--muted); white-space: nowrap; }
.event-day { align-self: center; font-size: 12px; color: var(--muted); padding: 6px 0 0; }

/* ---- Pipeline ------------------------------------------------------------------------- */
.board { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--ground); }
.board-cols { flex: 1; min-height: 0; display: flex; gap: 12px; padding: 12px 16px; overflow-x: auto; }
.col { flex: 1 0 200px; display: flex; flex-direction: column; min-height: 0; background: var(--pane); border: 1px solid var(--rule); }
.col-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--rule); font-size: 14px; line-height: 1.45; font-weight: 700; }
.col-count { font-size: 12px; font-weight: 400; color: var(--muted); font-variant-numeric: tabular-nums; }
.col-cards { flex: 1; min-height: 80px; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.col-empty { padding: 6px 4px; color: var(--muted); }
.card {
  position: relative; overflow: hidden; display: flex; flex-direction: column; gap: 4px;
  padding: 12px 12px 10px; background: var(--raised); border: 1px solid var(--rule); border-radius: 10px; cursor: grab;
}
.card-bar { position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--line); }
.card-top { display: flex; align-items: center; min-width: 0; }
.card-name { font-weight: 600; overflow-wrap: anywhere; }
.card-snippet { color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 2px; }
.card-time { font-size: 12px; color: var(--muted); }
.card-select { background: var(--pane); border: 1px solid var(--rule); border-radius: 8px; color: var(--ink); padding: 2px 6px; font-size: 12px; max-width: 130px; }
.card-ghost { opacity: 0.35; }
.card-drag { cursor: grabbing; }
.card-settle { animation: card-settle 150ms ease-out; }
@keyframes card-settle { from { transform: scale(0.97); } to { transform: none; } }
.board-error { margin: 10px 16px 0; color: var(--down); }
.board-foot { padding: 0 16px 12px; color: var(--muted); }

/* ---- Audit log ------------------------------------------------------------------------ */
.audit { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--pane); }

/* ---- Command palette and the shortcut sheet ------------------------------------------- */
.palette, .sheet {
  width: min(640px, calc(100vw - 16px)); margin: 12vh auto auto; padding: 0; border: 1px solid var(--rule); border-radius: 8px;
  background: var(--pane); color: var(--ink);
}
.sheet { width: min(480px, calc(100vw - 16px)); padding: 14px 16px 16px; }
.palette::backdrop { background: rgb(8 12 18 / 0.6); }
.sheet::backdrop { background: rgb(8 12 18 / 0.6); }
.palette-input { width: 100%; border: 0; border-bottom: 1px solid var(--rule); background: transparent; color: var(--ink); padding: 14px 16px; font-size: 15px; }
.palette-input:focus-visible { outline: none; }
.palette-results { max-height: min(50vh, 440px); overflow-y: auto; padding: 4px 0; }
.palette-item { display: flex; align-items: baseline; gap: 10px; padding: 8px 16px; cursor: pointer; }
.palette-item:hover { background: var(--raised); }
.palette-item[aria-selected="true"] { background: var(--raised); box-shadow: inset 2px 0 0 var(--ink); }
.palette-dot { flex: none; align-self: center; width: 8px; height: 8px; border-radius: 999px; background: var(--line); }
.palette-label { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.palette-hint { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.palette-group { font-size: 12px; color: var(--muted); }
.palette-empty { padding: 12px 16px; color: var(--muted); }
.palette-status { padding: 0 16px; font-size: 12px; color: var(--ink); }
.palette-status:empty { display: none; }
.palette-help { padding: 8px 16px; border-top: 1px solid var(--rule); font-size: 12px; color: var(--muted); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sheet-close { display: inline-flex; padding: 4px; border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 8px; }
.shortcut-list { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; align-items: baseline; margin-bottom: 10px; }
.shortcut-keys { font-size: 12px; color: var(--muted); white-space: nowrap; }
.shortcut-what { font-size: 14px; }

/* ---- Responsive ----------------------------------------------------------------------- */
@media (max-width: 1199px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .details-toggle { display: inline-flex; }
  .facts-close { display: inline-flex; }
  .facts { position: fixed; top: 0; right: 0; bottom: 0; width: min(340px, 100vw); z-index: 20; transform: translateX(100%); visibility: hidden; }
  .facts-open { transform: none; visibility: visible; }
}
@media (max-width: 899px) {
  /* Icons only, but the rail keeps its width so line and phone status stay readable. */
  .rail-label { display: none; }
  .rail-item, .rail-item-active { padding: 10px 2px; }
  .palette-trigger { min-width: 0; }
  .palette-text { display: none; }
}
@media (max-width: 759px) {
  :root { --side-w: 100%; }
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .main { grid-row: 1; }
  .rail {
    grid-row: 2; flex-direction: column; align-items: stretch;
    border-right: 0; border-top: 1px solid var(--rule); padding: 0 6px 4px; gap: 0;
  }
  .rail-brand { display: none; }
  .rail-nav { flex-direction: row; flex: none; justify-content: space-around; overflow: visible; }
  .rail-label { display: block; font-size: 12px; }
  /* A status strip above the tab bar: each line, then the phone. Wraps, never clips. */
  .rail-status {
    order: -1; margin: 0; flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: center;
    gap: 4px 14px; padding: 5px 4px; border-top: 0; border-bottom: 1px solid var(--rule);
  }
  .rail-line { display: flex; align-items: center; gap: 5px; }
  .rail-line-bar { align-self: stretch; width: 4px; min-height: 14px; }
  .rail-phone { flex-direction: row; align-items: center; gap: 5px; padding: 0; }
  .topbar { grid-template-areas: "title palette" "switch switch" "demo demo" "stats stats"; grid-template-columns: 1fr auto; padding: 10px 14px; }
  .view-title { font-size: 22px; }
  .stats { gap: 16px; flex-wrap: wrap; }
  .stat-num { font-size: 22px; }
  .inbox { grid-template-columns: minmax(0, 1fr); }
  .list-pane-away { display: none; }
  .workspace-empty { display: none; }
  .back-link { display: inline-flex; }
  .thread-head { padding: 10px 14px; }
  .thread-scroll { padding: 14px; }
  .band-normal, .band-manual, .band-blocked-caution, .band-blocked-down, .band-offline { margin: 6px 10px 10px; }
  .msg-in, .msg-out { max-width: 85%; }
  .th-wide { display: none; }
  .td-wide, .td-wide-num, .td-wide-clip { display: none; }
  .contacts-tools { padding: 8px 10px; }
  .filter-groups { padding: 8px 10px; flex-wrap: nowrap; overflow-x: auto; }
  .filter-group { flex-wrap: nowrap; }
  .record-head { padding: 10px 14px; }
  .record-name { font-size: 22px; }
  .board-cols { padding: 10px; scroll-snap-type: x mandatory; }
  .col { flex-basis: 82vw; scroll-snap-align: start; }
  .palette { margin-top: 8px; }
  .settings { padding: 14px 10px; }
  .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .settings-facts { grid-template-columns: minmax(0, 1fr); }
}

/* Motion only answers events, and not at all if the user asks for less. */
@media (prefers-reduced-motion: reduce) {
  .row-tint { animation: none; }
  .card-settle { animation: none; }
}
