/* Algorical web app. One stylesheet, no build step. Colours are tokens; dark mode follows the system unless the user picks. */
:root {
  --bg: #f4f6f8; --surface: #ffffff; --surface-2: #f0f2f5; --line: #e2e6ea; --line-strong: #c9d0d7;
  --text: #14181d; --muted: #5a6572; --faint: #86909b;
  --accent: #0b7a62; --accent-hover: #09664f; --accent-fg: #ffffff; --accent-soft: #e2f4ee; --accent-text: #08634e;
  --out: #d6f1e6; --in: #ffffff; --chat-bg: #edf1f0; --note-bg: #fff6dc; --note-line: #ecd48a;
  --danger: #b42318; --danger-soft: #fdecea; --warn: #7a4e00; --warn-soft: #fff3d1; --info: #1d5fd1;
  --shadow: 0 1px 2px rgba(16, 24, 32, .06), 0 4px 16px rgba(16, 24, 32, .06);
  --shadow-lg: 0 12px 40px rgba(16, 24, 32, .18);
  --radius: 12px; --radius-sm: 8px;
  --topbar: 56px; --navbar: 58px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1215; --surface: #161b20; --surface-2: #1d242b; --line: #28313a; --line-strong: #3a4651;
    --text: #e8ecf0; --muted: #9ca8b4; --faint: #75818d;
    --accent: #36c49c; --accent-hover: #52d6b0; --accent-fg: #052b20; --accent-soft: #123228; --accent-text: #72e2c1;
    --out: #164237; --in: #1d242b; --chat-bg: #11161a; --note-bg: #332a10; --note-line: #5d4b1a;
    --danger: #f97066; --danger-soft: #3b1c1a; --warn: #f2b84b; --warn-soft: #352a10; --info: #6aa4ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1215; --surface: #161b20; --surface-2: #1d242b; --line: #28313a; --line-strong: #3a4651;
  --text: #e8ecf0; --muted: #9ca8b4; --faint: #75818d;
  --accent: #36c49c; --accent-hover: #52d6b0; --accent-fg: #052b20; --accent-soft: #123228; --accent-text: #72e2c1;
  --out: #164237; --in: #1d242b; --chat-bg: #11161a; --note-bg: #332a10; --note-line: #5d4b1a;
  --danger: #f97066; --danger-soft: #3b1c1a; --warn: #f2b84b; --warn-soft: #352a10; --info: #6aa4ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 20px; line-height: 1.25; letter-spacing: -.01em; }
h2 { font-size: 17px; line-height: 1.3; letter-spacing: -.005em; }
h3 { font-size: 14px; line-height: 1.3; }
a { color: var(--accent-text); }
button, input, select, textarea { font: inherit; color: inherit; }
svg.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: -48px; background: var(--accent); color: var(--accent-fg); padding: 8px 12px; border-radius: 8px; z-index: 100; text-decoration: none; }
.skip:focus { top: 8px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.bad-text { color: var(--danger); }
.small { font-size: 13px; }
.xs { font-size: 12px; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.stack { display: grid; gap: 12px; }
.hidden { display: none !important; }
.trunc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Buttons and fields */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font-weight: 550; cursor: pointer; transition: background .15s, border-color .15s, transform .05s; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 40px; padding: 0; }
.btn.icon.sm { width: 32px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn.busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.busy::after { content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--accent-fg); border-right-color: transparent; animation: spin .7s linear infinite; }
.btn:not(.primary).busy::after { border-color: var(--muted); border-right-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

.field { display: grid; gap: 6px; }
.field > label, .label { font-weight: 600; font-size: 13px; }
.field .help { color: var(--muted); font-size: 12.5px; }
.field .err { color: var(--danger); font-size: 12.5px; min-height: 0; }
.input, select.input, textarea.input {
  width: 100%; min-height: 42px; padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text); transition: border-color .15s, box-shadow .15s;
}
textarea.input { resize: vertical; line-height: 1.45; }
.input::placeholder { color: var(--faint); }
.input:hover { border-color: var(--faint); }
.input:focus-visible, .input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); border-radius: var(--radius-sm); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input[disabled] { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
.with-action { position: relative; }
.with-action .input { padding-right: 44px; }
.with-action .btn { position: absolute; right: 4px; top: 4px; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--accent-soft); color: var(--accent-text); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 6px; font-size: 12px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.chip button { all: unset; cursor: pointer; display: grid; place-items: center; width: 16px; height: 16px; border-radius: 4px; }
.chip button:hover { background: var(--line); }
.chip button:focus-visible { outline: 2px solid var(--accent); }
.chip button svg { width: 12px; height: 12px; }

.avatar { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; color: #fff; font-weight: 650; font-size: 15px; letter-spacing: .02em; user-select: none; }
.avatar.sm { width: 22px; height: 22px; font-size: 10px; }
.avatar.lg { width: 64px; height: 64px; font-size: 24px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.callout { display: flex; gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--muted); font-size: 13px; align-items: flex-start; }
.callout.warn { background: var(--warn-soft); color: var(--warn); }
.callout.bad { background: var(--danger-soft); color: var(--danger); }
.callout.ok { background: var(--accent-soft); color: var(--accent-text); }
.callout svg { margin-top: 2px; }

/* Shell */
.app { height: 100vh; height: 100dvh; display: grid; grid-template-rows: var(--topbar) minmax(0, 1fr); }
.topbar { display: flex; align-items: center; gap: 16px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; font-size: 16px; color: var(--text); text-decoration: none; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #0a3a73)); display: grid; place-items: center; color: var(--accent-fg); }
.logo svg { width: 16px; height: 16px; stroke-width: 2.4; }
.company { color: var(--muted); font-size: 13px; padding-left: 16px; border-left: 1px solid var(--line); }
.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav a { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 550; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { color: var(--accent-text); background: var(--accent-soft); }
.spacer { flex: 1; }
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; border-radius: 50%; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-pop { position: absolute; right: 0; top: 46px; min-width: 240px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 8px; z-index: 40; }
.menu-pop .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.menu-pop .btn { width: 100%; justify-content: flex-start; }
main { min-height: 0; min-width: 0; }

/* Auth and centred pages */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); background: var(--bg); }
.auth-brand { padding: 56px; display: flex; flex-direction: column; justify-content: space-between; color: #fff; background: radial-gradient(1200px 600px at 0% 0%, #12a37f 0%, transparent 60%), linear-gradient(160deg, #063d31, #0a2f4d); }
.auth-brand .brand { color: #fff; }
.auth-brand .logo { background: rgba(255, 255, 255, .18); }
.auth-brand h1 { font-size: 34px; line-height: 1.15; letter-spacing: -.02em; max-width: 14em; }
.auth-brand ul { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 14px; max-width: 28em; }
.auth-brand li { display: flex; gap: 12px; color: rgba(255, 255, 255, .88); }
.auth-brand li svg { margin-top: 3px; color: #7ff0cd; }
.auth-form { display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 400px; display: grid; gap: 18px; }
.code-input { text-align: center; font-size: 26px; letter-spacing: .5em; font-variant-numeric: tabular-nums; padding-left: calc(12px + .5em); }
.center-page { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.center-card { width: 100%; max-width: 440px; padding: 28px; display: grid; gap: 18px; }

/* Inbox layout */
.inbox { height: 100%; display: grid; grid-template-columns: 340px minmax(0, 1fr) 0; background: var(--surface); transition: grid-template-columns .2s ease; }
.inbox[data-details="open"] { grid-template-columns: 340px minmax(0, 1fr) 320px; }
.pane { min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.pane-list { border-right: 1px solid var(--line); background: var(--surface); }
.pane-details { border-left: 1px solid var(--line); background: var(--surface); overflow: hidden; }
.list-head { padding: 16px 16px 8px; display: grid; gap: 12px; }
.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 12px; color: var(--faint); }
.search .input { padding-left: 38px; }
.seg { display: flex; padding: 3px; background: var(--surface-2); border-radius: 10px; gap: 2px; }
.seg button { flex: 1; min-height: 32px; border: 0; background: transparent; border-radius: 8px; font-weight: 550; color: var(--muted); cursor: pointer; font-size: 13px; }
.seg button[aria-pressed="true"], .seg button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.convos { overflow-y: auto; flex: 1; padding: 4px 8px 16px; list-style: none; margin: 0; }
.convo { display: flex; gap: 12px; width: 100%; padding: 10px 10px; border: 0; background: transparent; text-align: left; border-radius: 10px; cursor: pointer; align-items: flex-start; }
.convo:hover { background: var(--surface-2); }
.convo[aria-current="true"] { background: var(--accent-soft); }
.convo .top { display: flex; gap: 8px; align-items: baseline; }
.convo .name { font-weight: 600; }
.convo .time { margin-left: auto; font-size: 12px; color: var(--faint); white-space: nowrap; }
.convo .preview { color: var(--muted); font-size: 13.5px; }
.convo .meta { display: flex; gap: 6px; align-items: center; margin-top: 4px; flex-wrap: wrap; }
.skel { background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 6px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.pane-thread { background: var(--chat-bg); position: relative; }
.thread-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); min-height: 64px; }
.thread-head .title { font-weight: 650; }
/* Which ad brought the customer, and Meta's free window after it (src/modules/ads). */
.ad-line { gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.ad-chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--surface-2); color: var(--muted); max-width: 100%; min-width: 0; white-space: nowrap; overflow: hidden; }
.ad-label-short { display: none; }
@media (max-width: 760px) { .ad-label { display: none; } .ad-label-short { display: inline; } }
.ad-chip a, .ad-chip strong { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.ad-chip .i, .ad-row .i { width: 12px; height: 12px; flex: none; }
.ad-row { padding: 2px 0; }
.ad-filter { margin-top: 8px; }
.back { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 16px 20px 8px; display: flex; flex-direction: column; gap: 2px; scroll-behavior: smooth; }
.day { align-self: center; margin: 14px 0 8px; padding: 3px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-size: 12px; font-weight: 550; }
.bubble { max-width: min(70%, 560px); padding: 8px 12px 6px; border-radius: 14px; background: var(--in); border: 1px solid var(--line); align-self: flex-start; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 1px 1px rgba(0, 0, 0, .04); }
.bubble.out { align-self: flex-end; background: var(--out); border-color: color-mix(in srgb, var(--accent) 22%, var(--line)); }
.bubble.first { margin-top: 8px; }
.bubble .foot { display: flex; justify-content: flex-end; align-items: center; gap: 4px; margin-top: 2px; font-size: 11px; color: var(--faint); }
.bubble.out .foot { color: var(--muted); }
.bubble .foot svg { width: 14px; height: 14px; }
.bubble .foot .read { color: var(--info); }
.bubble .foot .bad { color: var(--danger); }
.bubble .fail { margin-top: 4px; font-size: 12px; color: var(--danger); }
.bubble.media { font-style: italic; color: var(--muted); }
/* Web addresses and phone numbers in a message (linked() in app.js): underlined, so a link never shows by colour alone. */
.bubble a { text-decoration: underline; text-underline-offset: 2px; }
.jump { position: absolute; right: 20px; bottom: 150px; z-index: 5; box-shadow: var(--shadow); }
.empty { margin: auto; text-align: center; max-width: 360px; padding: 32px 20px; display: grid; gap: 10px; justify-items: center; color: var(--muted); }
.empty .ring { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-text); }
.empty .ring svg { width: 26px; height: 26px; }
.empty h2 { color: var(--text); }

.composer { background: var(--surface); border-top: 1px solid var(--line); padding: 10px 16px 12px; display: grid; gap: 8px; }
.composer .box { display: flex; gap: 8px; align-items: flex-end; border: 1px solid var(--line-strong); border-radius: 14px; padding: 6px 6px 6px 12px; background: var(--surface); transition: border-color .15s, box-shadow .15s; }
.composer .box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.composer textarea { flex: 1; border: 0; background: transparent; resize: none; max-height: 160px; min-height: 28px; padding: 6px 0; line-height: 1.45; outline: none; }
.composer .tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.win { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.win.low { color: var(--warn); }
.draftbar { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-text); font-size: 13px; }
.draftbar .x { margin-left: auto; }
.tplpanel { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 10px; background: var(--surface-2); max-height: 46vh; overflow: auto; }
.tplpick { display: grid; gap: 6px; }
.tplopt { text-align: left; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; display: grid; gap: 2px; }
.tplopt[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
/* The quick reply chosen with the arrow keys in the reply box. */
.tplopt[aria-selected="true"] { border-color: var(--accent); background: var(--accent-soft); }
#qrlist { max-height: 34vh; }
.tplopt .n { font-weight: 600; display: flex; gap: 8px; align-items: center; }
.tplprev { white-space: pre-wrap; background: var(--out); border-radius: 12px; padding: 10px 12px; font-size: 14px; border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--line)); }
.closed { display: grid; gap: 10px; }

/* Details */
.details-head { display: flex; align-items: center; padding: 10px 14px 10px 16px; border-bottom: 1px solid var(--line); min-height: 64px; }
.details-body { overflow-y: auto; padding: 16px; display: grid; gap: 20px; align-content: start; }
.profile { display: grid; justify-items: center; gap: 6px; text-align: center; }
.section { display: grid; gap: 8px; }
.section > h3 { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.note { padding: 8px 10px; border-radius: 10px; background: var(--note-bg); border: 1px solid var(--note-line); font-size: 13.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.note .by { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.scrim { display: none; }

/* Settings */
.settings { height: 100%; overflow-y: auto; background: var(--bg); }
.settings-inner { max-width: 980px; margin: 0 auto; padding: 24px 20px 48px; display: grid; gap: 20px; }
.settings-grid { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 24px; align-items: start; }
.subnav { display: grid; gap: 2px; position: sticky; top: 0; }
.subnav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 550; }
.subnav a:hover { background: var(--surface-2); color: var(--text); }
.subnav a[aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.panel { display: grid; gap: 16px; }
.panel-head { display: grid; gap: 4px; }
.list-rows { display: grid; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); }
.list-row:first-child { border-top: 0; }
.form-grid { display: grid; gap: 14px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.copy { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; background: var(--surface-2); padding: 8px 10px; border-radius: 8px; overflow-wrap: anywhere; }
.steps { display: grid; gap: 0; }
.step { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); align-items: flex-start; }
.step:first-child { border-top: 0; }
.tick { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line-strong); display: grid; place-items: center; flex: none; margin-top: 1px; }
.tick.done { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.tick svg { width: 13px; height: 13px; stroke-width: 3; }
.progress { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.activity-icon { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); flex: none; }

/* Dialog and toasts */
dialog { border: 0; border-radius: 16px; padding: 22px; width: min(420px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
dialog::backdrop { background: rgba(8, 12, 16, .5); backdrop-filter: blur(2px); }
dialog h2 { margin-bottom: 8px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 200; display: grid; gap: 8px; width: min(440px, calc(100vw - 24px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; gap: 10px; align-items: center; padding: 11px 14px; border-radius: 12px; background: #1b2128; color: #f2f5f7; box-shadow: var(--shadow-lg); animation: rise .2s ease; font-size: 14px; }
.toast.bad { background: #8f1d14; }
.toast.ok svg { color: #6fe0bf; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* Mid widths: details become a drawer */
@media (max-width: 1180px) {
  .inbox, .inbox[data-details="open"] { grid-template-columns: 320px minmax(0, 1fr); }
  .pane-details { position: fixed; top: var(--topbar); right: 0; bottom: 0; width: min(360px, 100vw); transform: translateX(100%); visibility: hidden; transition: transform .2s ease, visibility .2s; z-index: 30; }
  .inbox[data-details="open"] .pane-details { transform: none; visibility: visible; box-shadow: var(--shadow-lg); }
  .inbox[data-details="open"] .scrim { display: block; position: fixed; inset: var(--topbar) 0 0 0; background: rgba(8, 12, 16, .35); z-index: 25; }
}
/* Phones */
@media (max-width: 760px) {
  body { font-size: 16px; }
  .auth { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
  .company, .nav { display: none; }
  .topbar { padding: 0 12px; gap: 10px; }
  .app { grid-template-rows: var(--topbar) minmax(0, 1fr) var(--navbar); }
  .app.no-nav { grid-template-rows: minmax(0, 1fr); }
  .app.no-nav .topbar { display: none; }
  .bottomnav { display: flex; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .bottomnav a { flex: 1; display: grid; justify-items: center; align-content: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 600; }
  .bottomnav a[aria-current="page"] { color: var(--accent-text); }
  .inbox, .inbox[data-details="open"] { grid-template-columns: minmax(0, 1fr); }
  .inbox[data-view="list"] .pane-thread { display: none; }
  .inbox[data-view="thread"] .pane-list { display: none; }
  .pane-list { border-right: 0; }
  .back { display: inline-flex; }
  .thread-head { padding: 8px 10px; gap: 8px; }
  .thread-head .btn:not(.icon) { width: 40px; padding: 0; }
  .thread-head .btn:not(.icon) span { display: none; }
  .messages { padding: 12px 12px 6px; }
  .bubble { max-width: 86%; }
  .pane-details { width: 100vw; top: 0; }
  .inbox[data-details="open"] .scrim { inset: 0; }
  .composer { padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); }
  .jump { bottom: 170px; right: 12px; }
  .settings-grid { grid-template-columns: 1fr; gap: 14px; }
  .subnav { display: flex; overflow-x: auto; position: static; padding-bottom: 4px; }
  .subnav a { white-space: nowrap; }
  .form-grid.two { grid-template-columns: 1fr; }
  .settings-inner { padding: 16px 12px 32px; }
  .card-pad { padding: 16px; }
  .list-row { flex-wrap: wrap; }
  .toasts { bottom: 76px; }
}
.bottomnav { display: none; }
@media (max-width: 760px) { .bottomnav { display: flex; } .app.no-nav .bottomnav { display: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; scroll-behavior: auto !important; } }

/* Channels, attachments, code */
.chan { display: inline-flex; align-items: center; padding: 1px 7px; border-radius: 6px; font-size: 11px; font-weight: 650; letter-spacing: .02em; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.chan-whatsapp { background: #e1f6ea; color: #0b6b3a; border-color: #bfe8d0; }
.chan-messenger { background: #e6f0ff; color: #1857c4; border-color: #c6dbff; }
.chan-instagram { background: #fde8f3; color: #a3195b; border-color: #f7c6e0; }
:root[data-theme="dark"] .chan-whatsapp { background: #11352a; color: #7be3b4; border-color: #1d5a45; }
:root[data-theme="dark"] .chan-messenger { background: #14284a; color: #8db8ff; border-color: #234172; }
:root[data-theme="dark"] .chan-instagram { background: #3d1730; color: #ff9ccf; border-color: #66274f; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .chan-whatsapp { background: #11352a; color: #7be3b4; border-color: #1d5a45; }
  :root:not([data-theme="light"]) .chan-messenger { background: #14284a; color: #8db8ff; border-color: #234172; }
  :root:not([data-theme="light"]) .chan-instagram { background: #3d1730; color: #ff9ccf; border-color: #66274f; }
}
.attach { margin: 2px 0 6px; }
.attach-img { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; }
.code { margin: 0; padding: 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; user-select: all; }
details > summary { list-style-position: inside; }

/* Comments filter tabs are links; reply-button chips inside a bubble; the composer's button row */
.seg a { flex: 1; display: grid; place-items: center; min-height: 32px; padding: 0 12px; border-radius: 8px; font-weight: 550; color: var(--muted); text-decoration: none; font-size: 13px; white-space: nowrap; }
.seg a[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.seg a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.bubble .chips { margin-top: 6px; }
.bubble.out .chip { background: transparent; border-color: currentColor; color: inherit; opacity: .9; }
.btnslot { display: grid; gap: 4px; padding: 0 2px 8px; }

/* Plan and usage */
.meter { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.meter > span.high { background: color-mix(in srgb, var(--danger) 55%, var(--accent)); }
.meter > span.full { background: var(--danger); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat { padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.stat-n { font-size: 22px; font-weight: 700; }

/* "Show older conversations" at the end of the inbox list */
.convos li.more { display: grid; padding: 8px 12px 14px; }

/* Two-step sign-in: the QR code stays dark on white in both themes (phone cameras need the contrast) */
.qr { width: 200px; height: 200px; padding: 6px; background: #fff; border: 1px solid var(--line); border-radius: 12px; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
.code.codes { columns: 2; column-gap: 24px; font-size: 14px; letter-spacing: .04em; }

/* Inbox basics: status tabs with counts, unread counts, close and snooze */
.status-row { gap: 8px; align-items: center; flex-wrap: wrap; }
.status-tabs { display: flex; gap: 4px; flex: 1 1 auto; flex-wrap: wrap; min-width: 0; }
.status-tab { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 10px; border: 1px solid transparent; background: transparent; border-radius: 999px; font-size: 13px; font-weight: 550; color: var(--muted); cursor: pointer; }
.status-tab:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.status-tab[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-text); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.status-tab:disabled { opacity: .55; cursor: default; }
.status-tab .count { font-size: 12px; font-variant-numeric: tabular-nums; opacity: .85; }
.convo.unread .name { font-weight: 750; }
.convo.unread .preview { color: var(--text); }
.unread-count, .nav-unread, .nav-tickets { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--accent-fg); font-size: 11.5px; font-weight: 700; display: inline-grid; place-items: center; font-variant-numeric: tabular-nums; }
/* The hidden attribute wins over a class that sets display (buttons, badges) */
[hidden] { display: none !important; }
.badge .i { width: 12px; height: 12px; }
.menu.snooze > summary { border-radius: 8px; }
.menu.snooze .menu-pop { min-width: 260px; display: grid; gap: 2px; }
.menu.snooze .menu-pop .btn { width: 100%; }
.snooze-pick { display: grid; gap: 6px; padding: 8px 6px 4px; margin-top: 4px; border-top: 1px solid var(--line); }
.snooze-pick .input { min-height: 36px; flex: 1; min-width: 0; }
.menu-pop .snooze-pick .btn { width: auto; flex: none; justify-content: center; }
.toast-act { all: unset; cursor: pointer; font-weight: 700; color: #6fe0bf; padding: 2px 6px; border-radius: 6px; }
.toast-act:focus-visible { outline: 2px solid #6fe0bf; }
.install-hint { align-items: center; }
@media (max-width: 760px) { .menu.snooze .menu-pop { right: -48px; } }

/* Links to the public policies: under the sign-in form and at the foot of Settings */
.auth-col { width: 100%; max-width: 400px; display: grid; gap: 18px; }
.legal-links { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; }
.legal-links a { color: var(--muted); text-decoration: none; }
.legal-links a:hover { color: var(--text); text-decoration: underline; }
.settings-foot { padding-top: 12px; border-top: 1px solid var(--line); }

/* Public pages (public/legal, and the Facebook data deletion status page): one readable column, no script needed */
.doc-page { min-height: 100vh; min-height: 100dvh; height: auto; background: var(--bg); }
.doc-top { display: flex; align-items: center; gap: 12px 24px; flex-wrap: wrap; padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--line); }
.doc-top .legal-links { font-size: 14px; }
.doc-top .legal-links a[aria-current="page"] { color: var(--text); font-weight: 600; }
.doc { max-width: 780px; margin: 0 auto; padding: 32px 20px 64px; }
.doc h1 { font-size: 28px; line-height: 1.2; margin-bottom: 6px; }
.doc h2 { font-size: 19px; margin: 32px 0 8px; }
.doc h3 { font-size: 15px; margin: 20px 0 6px; }
.doc p, .doc ul, .doc ol, .doc dl, .doc .table-wrap { margin: 0 0 12px; }
.doc ul, .doc ol { padding-left: 22px; }
.doc li { margin: 4px 0; }
.doc .lede { color: var(--muted); margin-bottom: 20px; }
.doc .table-wrap { overflow-x: auto; }
.doc table { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--surface); }
.doc th, .doc td { text-align: left; vertical-align: top; padding: 8px 10px; border: 1px solid var(--line); }
.doc th { background: var(--surface-2); font-weight: 600; }
.doc td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.doc .callout { margin: 0 0 16px; font-size: 14px; }
.doc .facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; }
.doc .facts dt { color: var(--muted); }
.doc .facts dd { margin: 0; }
.doc-form { display: grid; gap: 6px; max-width: 420px; margin: 24px 0 16px; }
.doc-form label { font-weight: 600; font-size: 14px; }
.doc-foot { margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
/* A blank the owner fills in before publishing (docs/YOUR-ACTIONS.md): easy to spot on the page and in the source */
.fill { background: var(--warn-soft); color: var(--warn); border-radius: 4px; padding: 0 4px; font-weight: 600; }
@media print { .doc-top, .doc-form { display: none; } .doc { padding: 0; } .doc-page { background: #fff; } }
/* Booking pages (/b/<slug>, src/modules/bookings/page-html.ts): services and people as tappable rows, times as pills */
.book-page { max-width: 640px; }
.book-list { display: grid; gap: 8px; margin: 0 0 16px; }
.book-item { display: grid; gap: 2px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); text-decoration: none; }
.book-item:hover { border-color: var(--accent); }
.book-day { border: 0; padding: 0; margin: 0 0 8px; }
.book-day legend { font-weight: 600; font-size: 14px; padding: 0; margin-bottom: 6px; }
.book-times { display: flex; flex-wrap: wrap; gap: 8px; }
.book-times label { position: relative; }
.book-times input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.book-times span { display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-size: 14px; font-variant-numeric: tabular-nums; }
.book-times input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.book-times input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.book-form label[for] { display: block; font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.book-form .input { max-width: 420px; }
.book-code code { font-size: 22px; letter-spacing: 1px; padding: 6px 10px; border-radius: var(--radius-sm); background: var(--surface-2); }
.book-foot { margin-top: 32px; }
/* The WhatsApp catalog: a cart a customer sent from it, a product message's items, and the composer's product picker */
.chip > .i { width: 12px; height: 12px; }
.cart { margin: 2px 0 4px; display: grid; gap: 4px; padding: 8px 10px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); white-space: normal; min-width: min(260px, 100%); }
.cart-head { font-weight: 600; display: flex; gap: 6px; align-items: center; }
.cart-head .i { width: 16px; height: 16px; }
.cart-line { display: flex; gap: 8px; font-size: 13px; min-width: 0; }
.cart-total { border-top: 1px solid var(--line); padding-top: 4px; font-weight: 600; display: flex; justify-content: space-between; font-size: 13px; }
.prodpick { display: grid; gap: 6px; max-height: 32vh; overflow: auto; }
.prodopt { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); cursor: pointer; text-align: left; color: inherit; font: inherit; }
.prodopt[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
.prodopt img { width: 36px; height: 36px; object-fit: cover; border-radius: 6px; flex: none; }
/* A segment's rules, side by side where there is room */
.rule-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
/* Reports: tables of figures that scroll sideways on a phone, rows named in their first cell */
.report-h { font-size: 17px; margin: 0; }
.report-sub { font-size: 14px; margin: 4px 0 0; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.report-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.report-table th, .report-table td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.report-table thead th { color: var(--muted); font-weight: 600; font-size: 12px; }
.report-table th:first-child { text-align: left; white-space: normal; min-width: 140px; font-weight: 600; }
.report-table tbody tr:last-child th, .report-table tbody tr:last-child td { border-bottom: 0; }
.report-dl { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: 6px 14px; margin: 12px 0 0; font-size: 13px; }
.report-dl dt { font-weight: 600; }
.report-dl dd { margin: 0; color: var(--muted); }
@media (max-width: 760px) { .report-dl { grid-template-columns: 1fr; } .report-dl dd { margin-bottom: 6px; } }

/* Contact fields (Contacts, Fields): values edited where they are in the contacts table, and the editors for each type. */
.fcells { flex: 1 1 100%; display: flex; flex-wrap: wrap; gap: 8px 12px; margin-left: 52px; }
.fcell { min-width: 130px; max-width: 280px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); display: grid; gap: 2px; }
.fcell-v { display: flex; align-items: center; gap: 6px; min-height: 28px; font-size: 13.5px; overflow-wrap: anywhere; }
.fcell-edit { display: grid; gap: 6px; }
.choices { display: flex; flex-wrap: wrap; gap: 6px 12px; max-height: 180px; overflow: auto; }
.choice { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; cursor: pointer; }
@media (max-width: 640px) { .fcells { margin-left: 0; } }

/* Tickets (src/modules/tickets): rows that open the ticket, the history, and the button on a message that makes one. */
.ticket-row { text-decoration: none; color: inherit; }
.ticket-row:hover { background: var(--surface-2); }
.tk-mini .list-row { padding: 8px 0; gap: 8px; flex-wrap: wrap; }
.tk-solved { margin-top: 4px; }
.tk-event { display: flex; justify-content: space-between; gap: 12px; font-size: 13.5px; padding: 6px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.tk-event:first-child { border-top: 0; }
.msg-act { all: unset; cursor: pointer; display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 4px; opacity: 0; color: var(--muted); }
.bubble:hover .msg-act, .msg-act:focus-visible { opacity: 1; }
.msg-act:focus-visible { outline: 2px solid var(--accent); }
@media (hover: none) { .msg-act { opacity: .55; } }

/* Surveys (src/modules/surveys): bars for a count out of a total, the days as columns, the hours of a day. */
.sv-bar { display: grid; grid-template-columns: minmax(90px, 160px) 1fr minmax(70px, auto); gap: 10px; align-items: center; font-size: 13px; }
.sv-bar-l { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sv-bar-n { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.sv-days, .sv-hours { display: flex; align-items: flex-end; gap: 3px; height: 72px; padding: 4px 0; }
.sv-day, .sv-hour { flex: 1 1 0; min-width: 3px; max-width: 28px; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.sv-day > span, .sv-hour > span { display: block; width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; }
.sv-hour { max-width: 34px; font-size: 10px; color: var(--muted); }
.sv-hour em { font-style: normal; line-height: 1.4; }
@media (max-width: 560px) { .sv-bar { grid-template-columns: minmax(70px, 110px) 1fr minmax(60px, auto); } }
.chan-web { background: #fff4e5; color: #8a4b00; border-color: #f6d9b0; }
:root[data-theme="dark"] .chan-web { background: #3a2a12; color: #ffc97a; border-color: #634619; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .chan-web { background: #3a2a12; color: #ffc97a; border-color: #634619; }
}

/* The flow canvas (Settings, Automations, Open canvas): a full-screen dialog with the add-a-step buttons on the left, boxes and arrows in the
   middle and the selected step's form on the right. Arrows are one SVG under the boxes; boxes are plain elements so they can be focused. */
dialog.fc-dlg { width: 100vw; height: 100vh; height: 100dvh; max-width: none; max-height: none; padding: 0; border-radius: 0; overflow: hidden; }
dialog.fc-dlg[open] { display: flex; flex-direction: column; }
.fc-bar { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface); }
.fc-titles { display: flex; flex-wrap: wrap; gap: 8px; flex: 1 1 360px; }
.fc-titles .input { flex: 1 1 200px; min-width: 0; }
.fc-bar > .row:last-child { flex: 1 1 100%; }
.fc-status { padding: 6px 14px; font-size: 13px; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--line); }
.fc-status.warn { background: var(--warn-soft); color: var(--warn); }
.fc-status.bad { background: var(--danger-soft); color: var(--danger); }
.fc-main { flex: 1; min-height: 0; display: grid; grid-template-columns: 168px minmax(0, 1fr) 400px; }
.fc-pal { display: flex; flex-direction: column; gap: 6px; padding: 12px; border-right: 1px solid var(--line); overflow: auto; background: var(--surface); }
.fc-pal .btn { justify-content: flex-start; }
.fc-side { padding: 14px; border-left: 1px solid var(--line); overflow: auto; background: var(--surface); display: flex; flex-direction: column; gap: 12px; }
.fc-view { position: relative; overflow: auto; background-color: var(--bg); background-image: radial-gradient(var(--line-strong) 1px, transparent 1px); background-size: 22px 22px; cursor: grab; }
.fc-view.pan { cursor: grabbing; user-select: none; }
.fc-sizer { position: relative; }
.fc-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.fc-edges { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; }
.fc-edge { fill: none; stroke: var(--line-strong); stroke-width: 2; stroke-linejoin: round; }
.fc-edge.branch { stroke: var(--info); }
.fc-edge.back { stroke: var(--warn); stroke-dasharray: 6 4; }
.fc-edge.toend { stroke-dasharray: 2 5; }
.fc-edge.sel, .fc-edge.drag { stroke: var(--accent); stroke-width: 2.5; }
.fc-arrow { fill: var(--line-strong); }
.fc-arrow.sel { fill: var(--accent); }
.fc-node { --k: var(--line-strong); position: absolute; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line-strong); border-top: 4px solid var(--k); border-radius: 10px; box-shadow: var(--shadow); cursor: pointer; touch-action: none; user-select: none; }
.fc-node.sel { outline: 2px solid var(--accent); outline-offset: 2px; }
.fc-node:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.fc-node.drag { box-shadow: var(--shadow-lg); z-index: 5; cursor: grabbing; }
.fc-node.lost { opacity: .75; border-style: dashed; }
.fc-node.bad { border-color: var(--danger); }
.fc-send, .fc-ask { --k: var(--accent); }
.fc-wait { --k: var(--warn); }
.fc-condition, .fc-switch { --k: var(--info); }
.fc-set, .fc-tag { --k: var(--faint); }
.fc-repeat { --k: var(--warn); }
.fc-handoff { --k: var(--danger); }
.fc-head { display: flex; align-items: center; gap: 6px; padding: 5px 8px 0; font-size: 13px; }
.fc-head svg.i { width: 15px; height: 15px; }
.fc-no { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.fc-tag { font-size: 11px; padding: 0 6px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.fc-tag.warn { background: var(--warn-soft); color: var(--warn); }
.fc-count { font-size: 11px; padding: 0 6px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.fc-words { flex: 1; min-height: 0; padding: 2px 8px; font-size: 12px; line-height: 1.35; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.fc-ports { display: flex; height: 26px; border-top: 1px solid var(--line); }
.fc-port { flex: 1 1 0; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 4px; padding: 0 2px; border: 0; border-left: 1px solid var(--line); background: transparent; font-size: 11px; color: var(--muted); cursor: crosshair; touch-action: none; }
.fc-port:first-child { border-left: 0; }
.fc-port.fixed { cursor: default; }
.fc-port:hover:not(.fixed) { background: var(--accent-soft); color: var(--accent-text); }
.fc-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line-strong); border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line-strong); flex: none; }
.fc-port:not(.fixed) .fc-dot { background: var(--info); }
.fc-port.back .fc-dot { background: var(--warn); }
.fc-plabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fc-start, .fc-end { position: absolute; display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); border: 1px solid var(--accent); font-size: 13px; user-select: none; }
.fc-start { width: 220px; border-radius: 14px; }
.fc-start .xs { color: var(--muted); line-height: 1.3; }
.fc-end { width: 140px; justify-content: center; background: var(--surface-2); color: var(--muted); border-color: var(--line-strong); }
@media (max-width: 960px) {
  .fc-main { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) minmax(0, 46%); }
  .fc-pal { flex-direction: row; flex-wrap: nowrap; align-items: center; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px; }
  .fc-pal .btn { flex: none; }
  .fc-side { border-left: 0; border-top: 1px solid var(--line); }
}

/* The phone apps and phone use (src/modules/inbox/phone.ts, mobile/README.md) */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
/* Set up this device: get the app, turn on alerts, send a test */
.setup-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.setup-step { display: flex; gap: 12px; align-items: flex-start; }
.setup-mark { flex: none; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; margin-top: 1px; }
.setup-step.done .setup-mark { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.setup-step.done strong { color: var(--muted); }
/* Today */
button.stat.today-stat { text-align: left; font: inherit; color: inherit; cursor: pointer; }
button.stat.today-stat:hover { border-color: var(--accent); }
.stat.warn { background: var(--warn-soft); }
.stat.bad { background: var(--danger-soft); }
.stat.warn .stat-n { color: var(--warn); }
.stat.bad .stat-n { color: var(--danger); }
/* A file or a voice note on its way, above the reply box */
.filebar, .voicebar { display: flex; gap: 10px; align-items: center; padding: 8px 10px; margin-bottom: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.file-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; flex: none; }
.voice-time { font-variant-numeric: tabular-nums; font-weight: 600; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); flex: none; animation: rec 1s ease-in-out infinite alternate; }
@keyframes rec { to { opacity: .3; } }
.attach-menu > summary { border-radius: 8px; }
.attach-menu .menu-pop { top: auto; bottom: 40px; left: 0; right: auto; min-width: 200px; display: grid; gap: 2px; }
@media (max-width: 760px) {
  /* While the keyboard is up, the app is as tall as what can be seen (fitViewport in app.js), so the reply box stays above it. */
  html.keyboard .app { height: var(--app-h, 100dvh); }
  html.keyboard .composer { padding-bottom: 8px; }
  /* Eight places at most: the bar scrolls sideways on a narrow phone rather than squeezing them. */
  .bottomnav { overflow-x: auto; scrollbar-width: none; }
  .bottomnav a { flex: 1 0 auto; min-width: 58px; padding: 0 4px; }
  .attach-menu > summary span { display: none; }
}

/* The segment rule builder (Contacts, Segments): a group of rules, and groups inside it. */
.seg-group { display: grid; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.seg-group.nested { background: var(--surface-2); margin-left: 12px; }
.seg-row { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.seg-kind { flex: 0 0 210px; max-width: 100%; }
.seg-edit { flex: 1 1 320px; min-width: 0; }

/* Help from Algorical (the ? in the top bar): a wider dialog, one row per way to reach a person. */
dialog.help-dlg { width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto; }
.help-way { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.help-way .btn { text-decoration: none; }
.auth-help { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.auth-help .btn { text-decoration: none; }
/* The demo page's trap for bots: off screen, never seen or reached with the keyboard by a person. */
.demo-trap { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.demo-form { max-width: 640px; }

/* Live chat with Algorical's own team (openSupportChat): a panel over the corner of any screen, the whole width on a phone. */
.help-btn { position: relative; }
.help-count { position: absolute; top: 2px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--accent); color: var(--accent-fg); font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; }
.help-count[hidden] { display: none; }
.support-chat { position: fixed; right: 16px; bottom: 16px; z-index: 60; width: min(380px, calc(100vw - 32px)); height: min(560px, calc(100dvh - 96px)); display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow-lg); }
.sc-head { display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 14px; border-bottom: 1px solid var(--line); }
.sc-list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; background: var(--bg); }
.sc-intro { align-self: center; text-align: center; max-width: 280px; padding: 8px 0; }
.sc-msg { max-width: 85%; padding: 8px 10px 5px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); align-self: flex-start; display: grid; gap: 4px; overflow-wrap: anywhere; }
.sc-msg.mine { align-self: flex-end; background: var(--out); border-color: color-mix(in srgb, var(--accent) 22%, var(--line)); }
.sc-msg.pending { opacity: .6; }
.sc-text { white-space: pre-wrap; }
.sc-note { margin: 0; padding: 6px 14px 0; }
.sc-compose { display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px 10px; }
.sc-compose .input { flex: 1; min-height: 42px; max-height: 140px; resize: vertical; }
.sc-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #1f9d55; vertical-align: middle; }
@media (max-width: 640px) {
  .support-chat { right: 8px; left: 8px; bottom: 72px; width: auto; height: min(560px, calc(100dvh - 140px)); }
}
/* Algorical's support team inside a company that let them in (src/modules/support/access.ts): said on every screen. */
.app.visiting .topbar { box-shadow: inset 0 -3px 0 var(--warn); }
.visit-badge { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; border: 0; font: inherit; white-space: nowrap; }
.visit-badge svg { width: 13px; height: 13px; }
@media (max-width: 640px) { .visit-badge span { display: none; } }
