/* NiSea Desk v2 — design system and the app's styles (web/index.html + web/app/).
   Tokens first (light, then dark once: data-theme="dark", set by web/app/theme.js),
   then components in screen order. Plain CSS, no build step. See docs/DESIGN.md. */

/* ---------- 1. Tokens ---------- */

:root {
  color-scheme: light;
  /* Type: caption (ticks, meta under bubbles), footnote (times, pills), sub (secondary text, chips, owner lines),
     body (lists, sheets), bubble (message text), input (16 px on touch: no zoom on iOS), headline (names), large (page titles) */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --fs-caption: 11px; --fs-footnote: 12px; --fs-sub: 13px; --fs-body: 14px; --fs-bubble: 15px; --fs-input: 15px;
  --fs-headline: 17px; --fs-title: 22px; --fs-large: 28px;
  --lh-tight: 1.25; --lh: 1.42; --fw-medium: 500; --fw-semibold: 600; --fw-bold: 700;
  /* Space (4-point), radius, size (desktop control, touch target, app bar, list, thread reading width) */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;
  --r-xs: 6px; --r-sm: 8px; --r-md: 10px; --r-lg: 14px; --r-bubble: 18px; --r-pill: 999px;
  --ctl: 32px; --tap: 44px; --appbar-h: 52px; --list-w: 400px; --read-w: 760px;
  /* Motion */
  --dur-fast: 120ms; --dur: 180ms; --dur-slow: 260ms; --ease: cubic-bezier(.2, .8, .2, 1); --ease-out: cubic-bezier(.16, 1, .3, 1);
  /* Colour (light): surfaces and text */
  --c-bg: #f5f5f7; --c-surface: #ffffff; --c-surface-blur: rgba(255, 255, 255, .82); --c-thread: #ffffff; --c-elevated: #ffffff;
  --c-group: #f5f5f7; --c-field: #ffffff; --c-fill: rgba(118, 118, 128, .12); --c-fill-strong: rgba(118, 118, 128, .2);
  --c-hover: rgba(118, 118, 128, .08); --c-selected: rgba(23, 96, 58, .09); --c-border: rgba(0, 0, 0, .08); --c-border-strong: rgba(0, 0, 0, .15);
  --c-text: #1d1d1f; --c-text-2: #5c5c61; --c-text-3: #6a6a6f; --c-scroll: rgba(0, 0, 0, .18); --c-backdrop: rgba(0, 0, 0, .22);
  /* accent and states */
  --c-accent: #17603a; --c-accent-hover: #124d2e; --c-accent-text: #17603a; --c-accent-soft: rgba(23, 96, 58, .1); --c-on-accent: #ffffff;
  --c-brand: #17603a;
  --c-focus: rgba(23, 96, 58, .25); --c-warn: #a35a00; --c-warn-soft: #fff3e0; --c-danger: #d70015; --c-danger-soft: #fdeced; --c-ok: #248a3d;
  /* bubbles */
  --b-client: #e9e9eb; --b-client-fg: #1d1d1f; --b-bot: #e4f2e9; --b-bot-fg: #0f2f1d; --b-person: #17603a; --b-person-fg: #ffffff;
  --b-phone: #3f7a57; --b-phone-fg: #ffffff; --b-note: #fff6d2; --b-note-fg: #3d3200; --b-note-border: #efdf9c; --b-note-label: #8a6c00;
  /* tags: a hue, its text mixed toward --tag-mix */
  --tag-mix: #000000; --tag-mix-amount: 30%; --tag-bg-amount: 13%;
  --hue-teal: #0f8f8a; --hue-blue: #0a6ed8; --hue-indigo: #5856d6; --hue-pink: #d63384; --hue-orange: #e07b00; --hue-green: #2f9e44; --hue-red: #e5383b;
  /* Shadow; media placeholders */
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .05), 0 0 0 .5px rgba(0, 0, 0, .04);
  --shadow-2: 0 4px 14px rgba(0, 0, 0, .08), 0 1px 3px rgba(0, 0, 0, .05);
  --shadow-3: 0 18px 50px rgba(0, 0, 0, .16), 0 4px 12px rgba(0, 0, 0, .06);
  --media-dim: 1;
}

/* Dark: data-theme="dark" (chosen, or Auto on a dark system — web/app/theme.js); what is not here is as in light */
:root[data-theme="dark"] {
  color-scheme: dark;
  --c-bg: #0f0f11; --c-surface: #1c1c1e; --c-surface-blur: rgba(28, 28, 30, .82); --c-thread: #151517; --c-elevated: #2a2a2d;
  --c-group: #232326; --c-field: #232326; --c-fill: rgba(118, 118, 128, .24); --c-fill-strong: rgba(118, 118, 128, .34);
  --c-hover: rgba(118, 118, 128, .14); --c-selected: rgba(111, 207, 151, .14); --c-border: rgba(255, 255, 255, .08); --c-border-strong: rgba(255, 255, 255, .16);
  --c-text: #f5f5f7; --c-text-2: #b8b8bd; --c-text-3: #a1a1a6; --c-scroll: rgba(255, 255, 255, .2); --c-backdrop: rgba(0, 0, 0, .5);
  --c-accent-hover: #1d7a4a; --c-accent-text: #6fcf97; --c-accent-soft: rgba(111, 207, 151, .14); --c-focus: rgba(111, 207, 151, .35);
  --c-brand: #8fd3a8;
  --c-warn: #ffb547; --c-warn-soft: rgba(255, 159, 10, .15); --c-danger: #ff6b63; --c-danger-soft: rgba(255, 69, 58, .15); --c-ok: #4cd964;
  --b-client: #2c2c2e; --b-client-fg: #f5f5f7; --b-bot: #173323; --b-bot-fg: #d6efe0; --b-phone: #2f5f45;
  --b-note: #3a3216; --b-note-fg: #f3e7bd; --b-note-border: #5a4c1e; --b-note-label: #d9bf68;
  --tag-mix: #ffffff; --tag-mix-amount: 45%; --tag-bg-amount: 22%;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4), 0 0 0 .5px rgba(255, 255, 255, .05);
  --shadow-2: 0 6px 18px rgba(0, 0, 0, .45), 0 0 0 .5px rgba(255, 255, 255, .06);
  --shadow-3: 0 22px 60px rgba(0, 0, 0, .6), 0 0 0 .5px rgba(255, 255, 255, .08);
  --media-dim: .86;
}

/* Touch and narrow screens: bigger targets, 16 px inputs */
@media (pointer: coarse), (max-width: 759px) {
  :root { --ctl: var(--tap); --fs-input: 16px; --fs-bubble: 16px; --fs-body: 15px; }
}
@media (min-width: 760px) and (max-width: 1099px) {
  :root { --list-w: 320px; }
}

/* ---------- 2. Base ---------- */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--c-bg); color: var(--c-text); font-family: var(--font); font-size: var(--fs-body); line-height: var(--lh);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; -webkit-tap-highlight-color: transparent; text-rendering: optimizeLegibility;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
a { color: var(--c-accent-text); text-decoration: none; }
/* The NiSea logo: nisea-logo.png as a mask, so its colour follows the theme (--c-brand). Height set where it stands. */
.logo { display: block; aspect-ratio: 447 / 139; background: var(--c-brand); -webkit-mask: url(/nisea-logo.png) center / contain no-repeat; mask: url(/nisea-logo.png) center / contain no-repeat; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
svg { flex: none; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--c-accent-text); outline-offset: 2px; border-radius: var(--r-xs); }
* { scrollbar-width: thin; scrollbar-color: var(--c-scroll) transparent; }
[hidden] { display: none !important; }
.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; }
.num { font-variant-numeric: tabular-nums; }
/* One line, cut with an ellipsis */
.row__name, .row__preview, .thread-head__name > span:first-child, .viewer__bar span, .file__name, .list-row__title > span:first-child,
.list-row__text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 3. Controls: buttons, segmented, text fields, switch ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: var(--ctl); padding: 0 14px;
  border: 0; border-radius: var(--r-md); background: var(--c-fill); color: var(--c-text); font-size: var(--fs-sub); font-weight: var(--fw-semibold);
  white-space: nowrap; transition: background-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), opacity var(--dur-fast);
}
.btn:hover { background: var(--c-fill-strong); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; transform: none; }
.btn--primary { background: var(--c-accent); color: var(--c-on-accent); }
.btn--primary:hover { background: var(--c-accent-hover); }
.btn--plain { background: transparent; color: var(--c-accent-text); padding: 0 8px; }
.btn--plain:hover { background: var(--c-accent-soft); }
.btn--block { width: 100%; height: var(--tap); font-size: var(--fs-body); }

.icon-btn {
  display: inline-grid; place-items: center; width: var(--ctl); height: var(--ctl); border: 0; border-radius: var(--r-pill);
  background: transparent; color: var(--c-text-2); transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast);
}
.icon-btn:hover { background: var(--c-hover); color: var(--c-text); }
.icon-btn[aria-expanded="true"] { background: var(--c-fill); color: var(--c-text); }
.icon-btn svg { width: 20px; height: 20px; }

.segmented { display: inline-flex; gap: 2px; padding: 2px; background: var(--c-fill); border-radius: 9px; }
.segmented button {
  height: 28px; padding: 0 12px; border: 0; border-radius: 7px; background: transparent; font-size: var(--fs-sub); font-weight: var(--fw-medium);
  color: var(--c-text-2); transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast), box-shadow var(--dur-fast);
}
.segmented button[aria-pressed="true"], .segmented button[aria-current="page"] {
  background: var(--c-surface); color: var(--c-text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .04);
}
:root[data-theme="dark"] .segmented button[aria-pressed="true"],
:root[data-theme="dark"] .segmented button[aria-current="page"] { background: var(--c-fill-strong); }
.segmented--small button { height: 24px; padding: 0 10px; font-size: var(--fs-footnote); }

/* A text field in focus */
.composer__box:focus-within, .field input:focus, .field textarea:focus, .fieldset:focus-within { border-color: var(--c-accent); box-shadow: 0 0 0 3px var(--c-focus); }
textarea::placeholder { color: var(--c-text-3); }

/* iOS-style switch: <input type="checkbox" role="switch" class="switch"> */
.switch {
  appearance: none; -webkit-appearance: none; flex: none; position: relative; width: 51px; height: 31px; margin: 0;
  border-radius: var(--r-pill); background: var(--c-fill-strong); cursor: pointer; transition: background-color var(--dur) var(--ease);
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, .15), 0 1px 1px rgba(0, 0, 0, .16); transition: transform var(--dur) var(--ease-out);
}
.switch:checked { background: var(--c-accent); }
.switch:checked::after { transform: translateX(20px); }
.switch:disabled { opacity: .5; cursor: default; }

/* ---------- 4. App shell ---------- */

.app { display: grid; grid-template-rows: var(--appbar-h) auto 1fr; height: 100vh; height: 100dvh; overflow: hidden; }
.appbar {
  position: relative; z-index: 5; display: flex; align-items: center; gap: var(--sp-3); padding: 0 var(--sp-4);
  background: var(--c-surface); border-bottom: 1px solid var(--c-border);
}
.appbar__brand { display: flex; align-items: center; gap: var(--sp-2); font-size: 15px; font-weight: var(--fw-semibold); letter-spacing: -.01em; white-space: nowrap; }
.appbar__brand .logo { height: 20px; }
.appbar__brand span { font-weight: var(--fw-medium); color: var(--c-text-2); }
.appbar__nav { margin-left: var(--sp-3); }
.appbar__spacer { flex: 1; }
.appbar__tools { display: flex; align-items: center; gap: var(--sp-1); }

/* The bot's state, always visible in the app bar (A2) */
.botstate {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border: 0; border-radius: var(--r-pill);
  background: transparent; color: var(--c-text-2); font-size: var(--fs-footnote); font-weight: var(--fw-medium);
}
.botstate:hover { background: var(--c-hover); }
.botstate::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c-ok); }
.botstate--off { color: var(--c-warn); background: var(--c-warn-soft); }
.botstate--off::before { background: var(--c-warn); }

.me-btn { display: inline-grid; place-items: center; width: var(--ctl); height: var(--ctl); padding: 0; border: 0; border-radius: 50%; background: transparent; }
.me-btn .avatar { width: 30px; height: 30px; font-size: 12px; }
.main { display: grid; grid-template-columns: var(--list-w) minmax(0, 1fr); min-height: 0; }

.banner {
  display: flex; align-items: center; justify-content: center; gap: var(--sp-2); min-height: 34px; padding: 6px var(--sp-4);
  font-size: var(--fs-sub); font-weight: var(--fw-medium); text-align: center;
}
.banner svg { width: 16px; height: 16px; }
.banner--offline { background: var(--c-warn-soft); color: var(--c-warn); }
.banner .btn--plain { height: 26px; color: inherit; text-decoration: underline; }

/* ---------- 5. Avatar, pills, tags, badges ---------- */

.avatar {
  display: inline-grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 50%;
  background: linear-gradient(180deg, #a5a5ab 0%, #86868c 100%); color: #fff; font-size: 15px; font-weight: var(--fw-semibold); letter-spacing: .02em; user-select: none;
}
.avatar--lg { width: 72px; height: 72px; font-size: 26px; }
.avatar--test { background: linear-gradient(180deg, #b7a6e0 0%, #8f7cc8 100%); }
.avatar--bot { background: linear-gradient(180deg, #2a8a57 0%, #17603a 100%); }
.avatar--bot svg { width: 60%; height: 60%; }

/* Small labels on one line: the owner pill, the waiting marker, tags, the hand-over reason */
.pill, .waiting, .tag, .reason {
  display: inline-flex; align-items: center; gap: 5px; flex: none; white-space: nowrap; line-height: 1;
  font-size: var(--fs-footnote); font-weight: var(--fw-semibold);
}
/* Owner pill — the one answer to "who speaks to the client now?" (A1) */
.pill { height: 22px; padding: 0 9px; border-radius: var(--r-pill); }
.pill svg { width: 13px; height: 13px; }
.pill--lg { height: 28px; padding: 0 12px; font-size: var(--fs-sub); gap: 6px; }
.pill--lg svg { width: 15px; height: 15px; }
.pill--bot { background: var(--c-accent-soft); color: var(--c-accent-text); }
.pill--bot-off, .pill--team { background: var(--c-fill); color: var(--c-text-2); }
.pill--me { background: var(--c-accent); color: var(--c-on-accent); }
.pill--person { background: var(--c-fill); color: var(--c-text); font-weight: var(--fw-medium); }
.pill--closed { background: transparent; color: var(--c-text-3); box-shadow: inset 0 0 0 1px var(--c-border-strong); font-weight: var(--fw-medium); }
.pill__face {
  display: inline-grid; place-items: center; width: 16px; height: 16px; margin-left: -4px; border-radius: 50%;
  background: var(--c-text-3); color: #fff; font-size: 8.5px; font-weight: var(--fw-bold);
}
.pill--lg .pill__face { width: 20px; height: 20px; margin-left: -6px; font-size: 10px; }
.pill__face[data-face]::before { content: attr(data-face); }   /* initials are decoration: not part of the pill's words */
/* Waiting — the client is owed an answer (MODEL "waiting"); its own marker, whoever the owner is */
.waiting { color: var(--c-warn); font-variant-numeric: tabular-nums; }
.waiting::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.waiting--lg { font-size: var(--fs-sub); }

/* Tags: people's own coloured labels; colour never carries meaning alone. The reason: derived by the desk, never a tag. */
.tag, .reason { gap: 4px; height: 20px; padding: 0 7px; border-radius: var(--r-xs); font-size: 11.5px; }
.tag, .test-badge { background: color-mix(in srgb, var(--h) var(--tag-bg-amount), transparent); color: color-mix(in srgb, var(--h), var(--tag-mix) var(--tag-mix-amount)); }
.tag--teal { --h: var(--hue-teal); }
.tag--blue { --h: var(--hue-blue); }
.tag--indigo, .test-badge { --h: var(--hue-indigo); }
.tag--pink { --h: var(--hue-pink); }
.tag--orange { --h: var(--hue-orange); }
.tag--green { --h: var(--hue-green); }
.tag--red { --h: var(--hue-red); }
.tag__x {
  display: inline-grid; place-items: center; width: 14px; height: 14px; margin-right: -3px; padding: 0;
  border: 0; border-radius: 50%; background: transparent; color: inherit; opacity: .7;
}
.tag__x:hover { opacity: 1; background: color-mix(in srgb, var(--h) 20%, transparent); }
.tag__x svg { width: 10px; height: 10px; }
.reason { border: 0; background: transparent; color: var(--c-text-2); box-shadow: inset 0 0 0 1px var(--c-border-strong); font-weight: var(--fw-medium); }
.reason svg { width: 12px; height: 12px; opacity: .8; }
.thread-head__state .reason { height: 24px; font-size: var(--fs-footnote); }

/* Test conversations: "Oleg [TEST 12]" shows the bracket part as a quiet badge (M2) */
.test-badge {
  display: inline-flex; align-items: center; flex: none; height: 18px; padding: 0 6px; margin-left: 6px; border-radius: 5px;
  font-size: 10.5px; font-weight: var(--fw-bold); letter-spacing: .04em; vertical-align: 2px;
}

/* ---------- 6. Inbox: filter bar, search, rows ---------- */

.inbox { display: flex; flex-direction: column; min-height: 0; background: var(--c-surface); border-right: 1px solid var(--c-border); }
.inbox__head { display: flex; flex-direction: column; gap: 10px; padding: var(--sp-3) var(--sp-3) var(--sp-2); }
.inbox__list { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 2px var(--sp-2) var(--sp-6); }
/* The bot-off notice and the active reason filter: a soft bar, its action at the end */
.inbox__notice, .active-filter { display: flex; align-items: center; margin: 0 var(--sp-1); border-radius: var(--r-md); font-size: var(--fs-sub); }
.inbox__notice { gap: var(--sp-2); padding: 8px 12px; background: var(--c-warn-soft); color: var(--c-warn); font-weight: var(--fw-medium); }
.active-filter { gap: 6px; padding: 4px 4px 4px 12px; background: var(--c-accent-soft); color: var(--c-accent-text); }
.active-filter b { font-weight: var(--fw-semibold); }
.inbox__notice .btn--plain, .active-filter .btn--plain { margin-left: auto; height: 26px; }
.inbox__notice .btn--plain { color: inherit; font-weight: var(--fw-semibold); }
#active-filter:empty, #notice:empty { display: none; }

.search { position: relative; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--c-text-3); pointer-events: none; }
.search input {
  width: 100%; height: 34px; padding: 0 32px; border: 0; border-radius: var(--r-md); background: var(--c-fill);
  font-size: var(--fs-input); transition: box-shadow var(--dur-fast);
}
.search input:focus { box-shadow: 0 0 0 3px var(--c-focus); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search__clear {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%); display: grid; place-items: center;
  width: 26px; height: 26px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--c-text-3);
}
.search__clear svg { position: static; transform: none; width: 15px; height: 15px; }

.filters { display: flex; gap: 2px; margin: 0 -12px; padding: 2px 12px; overflow-x: auto; scrollbar-width: none; scroll-padding: 0 12px; }
.filters::-webkit-scrollbar { display: none; }
.filters.is-overflow { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); }
.filters.is-overflow.is-end { -webkit-mask-image: none; mask-image: none; }
@media (min-width: 760px) { .filters { flex-wrap: wrap; row-gap: 2px; overflow: visible; } .filters.is-overflow { -webkit-mask-image: none; mask-image: none; } }
.chip {
  position: relative; flex: none; display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 8px;
  border: 0; border-radius: var(--r-pill); background: transparent; color: var(--c-text-2); font-size: var(--fs-sub); font-weight: var(--fw-medium);
  white-space: nowrap; transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast);
}
.chip::after { content: ""; position: absolute; inset: -6px -1px; } /* larger hit area */
.chip:hover { background: var(--c-hover); color: var(--c-text); }
.tests-switch { margin: 0 var(--sp-4) var(--sp-2); width: fit-content; }
.chip[aria-pressed="true"] { background: var(--c-accent-soft); color: var(--c-accent-text); font-weight: var(--fw-semibold); }
.chip__count { min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--r-pill); background: var(--c-accent); color: var(--c-on-accent); font-size: 11px; font-weight: var(--fw-semibold); display: inline-grid; place-items: center; }
.chip__count--warn { background: var(--c-warn); color: #fff; }

.row {
  position: relative; display: grid; grid-template-columns: 40px minmax(0, 1fr); column-gap: 12px; align-items: start;
  width: 100%; padding: 10px 10px 10px 8px; border: 0; border-radius: 12px; background: transparent; text-align: left;
  transition: background-color var(--dur-fast) var(--ease);
}
.row:hover { background: var(--c-hover); }
.row[aria-current="true"] { background: var(--c-selected); }
.row + .row::before { content: ""; position: absolute; top: 0; left: 60px; right: 10px; height: 1px; background: var(--c-border); }
.row:hover::before, .row[aria-current="true"]::before,
.row:hover + .row::before, .row[aria-current="true"] + .row::before { opacity: 0; }
.row__main { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.row__top { display: flex; align-items: baseline; gap: var(--sp-2); min-width: 0; }
.row__name { flex: 1; min-width: 0; font-size: var(--fs-body); font-weight: var(--fw-semibold); letter-spacing: -.005em; }
.row__time { flex: none; font-size: var(--fs-footnote); color: var(--c-text-3); font-variant-numeric: tabular-nums; }
.row__preview { font-size: var(--fs-sub); color: var(--c-text-2); }
.row__by { color: var(--c-text-3); }
/* Labels wrap to a second line rather than being cut; a third line is not shown */
.row__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-top: 6px; min-width: 0; max-height: 48px; overflow: hidden; }
.row__meta .tag, .row__meta .reason { height: 18px; font-size: 11px; }
a.row, a.list-row { color: inherit; }
a.row:hover, a.list-row:hover { text-decoration: none; }
.row:focus-visible, .list-row:focus-visible { outline-offset: -2px; border-radius: 12px; }
.inbox__more, .older { display: flex; justify-content: center; padding: var(--sp-3) 0; font-size: var(--fs-sub); color: var(--c-text-3); }
.older { padding: var(--sp-2) 0 0; }

/* ---------- 7. Thread: header, timeline, bubbles, lines ---------- */

.thread {
  position: relative; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr);
  min-height: 0; min-width: 0; background: var(--c-thread);
}
/* The header and the composer: frosted bars over the timeline */
.thread-head, .composer {
  position: relative; z-index: 2; background: var(--c-surface-blur);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
}
.thread-head { display: flex; align-items: center; gap: var(--sp-3); min-height: 60px; padding: 10px var(--sp-4) 10px var(--sp-5); border-bottom: 1px solid var(--c-border); }
.thread-head__back { display: none; margin-left: -8px; color: var(--c-accent-text); }
.thread-head__back svg { width: 24px; height: 24px; }
.thread-head__who { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--sp-3); padding: 0; border: 0; background: transparent; text-align: left; }
.thread-head__text { min-width: 0; }
.thread-head__name {
  display: flex; align-items: center; min-width: 0;
  font-size: var(--fs-headline); font-weight: var(--fw-semibold); letter-spacing: -.015em; line-height: var(--lh-tight);
}
.thread-head__sub { display: flex; align-items: center; gap: 6px; margin-top: 3px; font-size: var(--fs-footnote); color: var(--c-text-2); white-space: nowrap; overflow: hidden; }
.thread-head__state { display: flex; align-items: center; gap: var(--sp-3); }
.thread-head__actions { display: flex; align-items: center; gap: var(--sp-2); }
.thread-head__pill-m { display: none; align-items: center; gap: var(--sp-2); }
/* A narrow header (a tablet, a small window): the state goes under the name, secondary actions into More — nothing leaves the screen */
.thread-head { container: thead / inline-size; }
@container thead (max-width: 640px) {
  .thread-head__sub, .thread-head__state, .thread-head__actions .btn:not(.btn--primary) { display: none; }
  .thread-head__pill-m { display: flex; flex-wrap: wrap; row-gap: 4px; margin-top: 3px; }
}

.timeline { overflow-y: auto; overscroll-behavior: contain; padding: var(--sp-2) var(--sp-5) var(--sp-6); scroll-behavior: smooth; }
.timeline__inner { display: flex; flex-direction: column; width: 100%; max-width: var(--read-w); margin: 0 auto; }
.day { align-self: center; margin: var(--sp-5) 0 var(--sp-2); font-size: var(--fs-footnote); font-weight: var(--fw-semibold); color: var(--c-text-3); }

/* A message: optional author, the bubble (or media), the meta line */
.msg { display: flex; flex-direction: column; align-items: flex-start; max-width: min(76%, 560px); margin-top: 2px; }
.msg--out { align-self: flex-end; align-items: flex-end; }
.msg--first { margin-top: var(--sp-3); }
.msg__author { display: flex; align-items: center; gap: 4px; margin: 0 12px 3px; font-size: var(--fs-footnote); font-weight: var(--fw-medium); color: var(--c-text-3); }
.msg__author svg { width: 12px; height: 12px; }
.msg__body { display: flex; align-items: center; gap: 6px; max-width: 100%; }
.msg--out .msg__body { flex-direction: row-reverse; }
.msg__stack { display: flex; flex-direction: column; gap: 3px; min-width: 0; max-width: 100%; }
.msg--out .msg__stack { align-items: flex-end; }
.msg__meta { display: flex; align-items: center; gap: 4px; margin: 3px 12px 0; font-size: var(--fs-caption); color: var(--c-text-3); font-variant-numeric: tabular-nums; }

.bubble { padding: 8px 13px 9px; border-radius: var(--r-bubble); font-size: var(--fs-bubble); line-height: 1.38; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble--client { background: var(--b-client); color: var(--b-client-fg); }
.bubble--bot { background: var(--b-bot); color: var(--b-bot-fg); }
.bubble--person { background: var(--b-person); color: var(--b-person-fg); }
.bubble--phone { background: var(--b-phone); color: var(--b-phone-fg); }
.bubble--note { background: var(--b-note); color: var(--b-note-fg); box-shadow: inset 0 0 0 1px var(--b-note-border); border-radius: var(--r-lg); }
.bubble--media { padding: 4px; }
.bubble--marker { font-style: italic; }
.bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.bubble--client a, .bubble--bot a { color: var(--c-accent-text); }
.bubble a.file { color: inherit; text-decoration: none; }

/* Not sent / not delivered: the bubble shows it, the meta line says why (K1) */
.msg--cancelled .bubble { background: transparent; color: var(--c-text-2); box-shadow: inset 0 0 0 1px var(--c-border-strong); }
.msg--cancelled .bubble--person, .msg--cancelled .bubble--bot { border: 1px dashed var(--c-border-strong); box-shadow: none; }
.msg--sending .bubble { opacity: .72; }
.msg__alert { display: grid; place-items: center; flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--c-danger); color: #fff; }
.msg__alert svg { width: 14px; height: 14px; }
.msg__alert--unknown svg { width: 13px; height: 13px; }

/* Delivery: quiet ticks, words only when something is wrong */
.tick { display: inline-flex; align-items: center; color: var(--c-text-3); }
.tick svg { width: 16px; height: 11px; }
.tick--read { color: var(--c-accent-text); }
.tick--faint { opacity: .55; }
.tick--wait svg { width: 11px; height: 11px; }
.delivery { max-width: 100%; margin: 3px 12px 0; font-size: var(--fs-footnote); font-weight: var(--fw-medium); line-height: 1.4; text-align: right; }
.delivery > * { vertical-align: middle; }
.delivery--bad, .delivery--unknown { color: var(--c-danger); }
.delivery--retrying { color: var(--c-warn); }
.delivery .btn--plain { display: inline-flex; height: 22px; margin-left: 4px; padding: 0 6px; font-size: var(--fs-footnote); }
.delivery svg { width: 12px; height: 12px; }
.spin { animation: spin 1s linear infinite; }

/* The owner change: one line, in words (MODEL "What people see") */
.line { display: flex; align-items: center; gap: var(--sp-3); margin: var(--sp-4) 0 var(--sp-2); font-size: var(--fs-sub); color: var(--c-text-2); text-align: center; }
.line::before, .line::after { content: ""; flex: 1; min-width: 16px; height: 1px; background: var(--c-border); }
.line__text { max-width: 82%; }
.line__time { color: var(--c-text-3); font-size: var(--fs-footnote); margin-left: 4px; font-variant-numeric: tabular-nums; }
.line__lead { padding: 0; border: 0; background: none; color: var(--c-accent-text); font-weight: var(--fw-semibold); }
.line__lead:hover { text-decoration: underline; }

/* Bot error: the only bot step that becomes its own line */
.errline {
  align-self: center; display: inline-flex; align-items: center; gap: 6px; max-width: 90%; margin: var(--sp-3) 0 2px; padding: 6px 12px;
  border-radius: var(--r-md); background: var(--c-danger-soft); color: var(--c-danger); font-size: var(--fs-sub); font-weight: var(--fw-medium);
}
.errline svg { width: 15px; height: 15px; }
.errline__time { opacity: .7; font-weight: 400; font-size: var(--fs-footnote); }

/* "How the bot decided" — folded under the bot's message (O1, O2) */
.decided { margin: 2px 8px 0; font-size: var(--fs-footnote); max-width: 440px; }
.decided > summary {
  display: inline-flex; align-items: center; gap: 3px; padding: 3px 4px; border-radius: var(--r-xs);
  list-style: none; cursor: pointer; color: var(--c-text-3); font-weight: var(--fw-medium); user-select: none;
}
.decided > summary::-webkit-details-marker { display: none; }
.decided > summary:hover { color: var(--c-text-2); }
.decided > summary svg { width: 12px; height: 12px; transition: transform var(--dur) var(--ease); }
.decided[open] > summary svg { transform: rotate(90deg); }
.decided__steps {
  margin: 4px 0 0; padding: 10px 14px 10px 12px; list-style: none; border-radius: var(--r-md);
  background: var(--c-group); color: var(--c-text-2); line-height: 1.45; text-align: left;
}
.decided__steps li { position: relative; padding-left: 14px; }
.decided__steps li + li { margin-top: 4px; }
.decided__steps li::before { content: ""; position: absolute; left: 0; top: 7px; width: 5px; height: 5px; border-radius: 50%; background: var(--c-text-3); opacity: .6; }
.decided__steps li.is-key::before { background: var(--c-accent-text); opacity: 1; }
.decided__steps q { color: var(--c-text); }
.msg--steps .decided { margin-top: 0; }

/* ---------- 8. Attachments: image, viewer, voice, file, location ---------- */

.media-img {
  display: block; padding: 0; border: 0; width: 260px; max-width: 100%; border-radius: var(--r-bubble); overflow: hidden;
  background: var(--c-fill); cursor: zoom-in; box-shadow: inset 0 0 0 1px var(--c-border);
}
.media-img img { display: block; width: 100%; height: auto; filter: brightness(var(--media-dim)); transition: transform var(--dur-slow) var(--ease); }
.media-img:hover img { transform: scale(1.015); }
.media-video { width: 260px; max-width: 100%; overflow: hidden; border-radius: var(--r-bubble); background: #000; }
.media-video video { display: block; width: 100%; max-height: 360px; }
.file-wait { display: flex; align-items: center; gap: 8px; padding: 8px 12px; font-size: var(--fs-sub); opacity: .75; }
.file-wait svg { width: 15px; height: 15px; }

.viewer {
  position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-3);
  padding: 64px var(--sp-4) var(--sp-6); background: rgba(10, 10, 12, .9); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  animation: fade-in var(--dur) var(--ease) both;
}
.viewer img {
  max-width: min(100%, 1100px); max-height: calc(100% - 60px); border-radius: var(--r-lg); box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
  animation: zoom-in var(--dur-slow) var(--ease-out) both;
}
.viewer__bar {
  position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4);
  color: rgba(255, 255, 255, .85); font-size: var(--fs-sub);
}
.viewer__bar span { flex: 1; min-width: 0; }
.viewer .icon-btn { color: rgba(255, 255, 255, .85); width: var(--tap); height: var(--tap); }
.viewer .icon-btn:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.viewer__caption { max-width: 640px; color: rgba(255, 255, 255, .8); font-size: var(--fs-body); text-align: center; }

.voice { display: flex; align-items: center; gap: 10px; width: 260px; max-width: 100%; padding: 8px 14px 8px 8px; }
.voice__play {
  display: grid; place-items: center; flex: none; width: 34px; height: 34px; padding: 0; border: 0; border-radius: 50%;
  background: var(--c-accent); color: #fff; transition: transform var(--dur-fast) var(--ease);
}
.voice__play:active { transform: scale(.92); }
.voice__play svg { width: 16px; height: 16px; }
.voice__wave { flex: 1; display: flex; align-items: center; gap: 2px; height: 28px; padding: 0; border: 0; background: none; cursor: pointer; }
.voice__wave i { flex: 1; min-width: 2px; max-width: 3px; border-radius: 2px; background: currentColor; opacity: .28; transition: opacity var(--dur-fast); }
.voice__wave i.on { opacity: 1; color: var(--c-accent-text); }
.voice__time { flex: none; min-width: 30px; font-size: var(--fs-footnote); font-variant-numeric: tabular-nums; opacity: .7; text-align: right; }

.file { display: flex; align-items: center; gap: 12px; width: 270px; max-width: 100%; padding: 8px 12px 8px 8px; }
.file__icon {
  position: relative; flex: none; display: grid; place-items: end center; width: 34px; height: 42px; padding-bottom: 6px;
  border-radius: 5px 12px 5px 5px; background: #e5484d; color: #fff; font-size: 9px; font-weight: var(--fw-bold); letter-spacing: .04em;
}
.file__icon::before { content: ""; position: absolute; top: 0; right: 0; width: 11px; height: 11px; border-radius: 0 0 0 4px; background: rgba(255, 255, 255, .35); }
.file__text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.file__name { font-size: var(--fs-sub); font-weight: var(--fw-semibold); }
.file__size { font-size: var(--fs-footnote); opacity: .65; }
.file__dl { flex: none; opacity: .6; }
.file__dl svg { width: 18px; height: 18px; }
.file:hover .file__dl { opacity: 1; }

.loc {
  display: block; width: 260px; max-width: 100%; overflow: hidden; border-radius: 14px; color: inherit;
  background: var(--c-surface); box-shadow: inset 0 0 0 1px var(--c-border);
}
.loc:hover { text-decoration: none; }
.loc__map { display: block; width: 100%; height: 110px; filter: brightness(var(--media-dim)); }
.loc__text { display: flex; align-items: center; gap: 8px; padding: 8px 12px 9px; }
.loc__text svg { width: 16px; height: 16px; color: var(--c-danger); }
.loc__name { flex: 1; min-width: 0; font-size: var(--fs-sub); font-weight: var(--fw-semibold); line-height: 1.25; }
.loc__name small { display: block; font-weight: 400; color: var(--c-accent-text); font-size: var(--fs-footnote); }

/* ---------- 9. Composer ---------- */

.composer { padding: var(--sp-2) var(--sp-5) calc(var(--sp-3) + env(safe-area-inset-bottom)); border-top: 1px solid var(--c-border); }
.composer__inner { max-width: var(--read-w); margin: 0 auto; }
.composer--empty { display: none; }
.composer__bar { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); min-height: 28px; margin-bottom: 6px; }
.composer__window {
  display: inline-flex; align-items: center; gap: 5px; font-size: var(--fs-footnote); color: var(--c-text-3);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.composer__window svg { width: 13px; height: 13px; }
.composer__window--soon { color: var(--c-warn); font-weight: var(--fw-semibold); }
.cw-short { display: none; }
.composer__hint { margin: 0 4px 6px; font-size: var(--fs-footnote); color: var(--c-text-2); }

.composer__box {
  display: flex; align-items: flex-end; gap: var(--sp-2); padding: 4px 4px 4px 14px; border: 1px solid var(--c-border-strong); border-radius: 20px;
  background: var(--c-field); transition: border-color var(--dur-fast), box-shadow var(--dur-fast), background-color var(--dur);
}
.composer__box textarea {
  flex: 1; min-width: 0; height: 30px; max-height: 168px; margin: 0; padding: 5px 0; border: 0; outline: none; resize: none;
  background: transparent; font-size: var(--fs-input); line-height: 1.35;
}
.composer--note .composer__box { background: var(--b-note); border-color: var(--b-note-border); }
.composer--note .composer__box:focus-within { border-color: var(--b-note-label); box-shadow: 0 0 0 3px color-mix(in srgb, var(--b-note-label) 25%, transparent); }
.composer--note textarea { color: var(--b-note-fg); }

.send {
  position: relative; display: grid; place-items: center; flex: none; width: 30px; height: 30px; padding: 0; border: 0; border-radius: var(--r-pill);
  background: var(--c-accent); color: #fff; transition: background-color var(--dur-fast), transform var(--dur-fast) var(--ease), opacity var(--dur-fast);
}
.send::after { content: ""; position: absolute; inset: -7px; } /* 44 px hit area around a quiet 30 px button */
.send svg { width: 18px; height: 18px; }
.send:hover { background: var(--c-accent-hover); }
.send:active { transform: scale(.92); }
.send:disabled { background: var(--c-fill); color: var(--c-text-3); transform: none; }
.send--wide { width: auto; padding: 0 14px; font-size: var(--fs-sub); font-weight: var(--fw-semibold); }
.composer--note .send { background: var(--b-note-label); }
.composer--note .send:disabled { background: color-mix(in srgb, var(--b-note-label) 18%, transparent); color: color-mix(in srgb, var(--b-note-label) 70%, transparent); }

/* Reply not possible: say why, offer the way out (K7, A7) */
.composer__blocked { display: flex; align-items: flex-start; gap: var(--sp-3); padding: 12px 14px; border-radius: var(--r-lg); background: var(--c-group); }
.composer__blocked > svg { width: 20px; height: 20px; margin-top: 1px; color: var(--c-text-3); }
.composer__blocked--window > svg { color: var(--c-warn); }
.composer__blocked-text { flex: 1; min-width: 0; font-size: var(--fs-sub); color: var(--c-text-2); line-height: 1.45; }
.composer__blocked-text strong { display: block; margin-bottom: 2px; color: var(--c-text); font-size: var(--fs-body); font-weight: var(--fw-semibold); }
.composer__blocked-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-2); }

/* ---------- 10. Contact sheet ---------- */

.sheet-backdrop { position: fixed; inset: 0; z-index: 30; background: var(--c-backdrop); animation: fade-in var(--dur) var(--ease) both; }
.sheet {
  position: fixed; z-index: 31; top: calc(var(--appbar-h) + 10px); right: 10px; bottom: 10px; width: 384px; max-width: calc(100vw - 20px);
  display: flex; flex-direction: column; border-radius: var(--r-lg); background: var(--c-elevated); box-shadow: var(--shadow-3); overflow: hidden;
  animation: sheet-in var(--dur-slow) var(--ease-out) both;
}
.sheet__head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); min-height: 52px; padding: 8px 10px 8px 16px; }
.sheet__title { font-size: var(--fs-headline); font-weight: var(--fw-semibold); }
.sheet__tools { display: flex; align-items: center; gap: 4px; }
.sheet__body { flex: 1; overflow-y: auto; padding: 0 0 var(--sp-6); }
.sheet__hero { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 4px 16px 18px; text-align: center; }
.sheet__name { margin-top: 8px; font-size: var(--fs-title); font-weight: var(--fw-semibold); letter-spacing: -.02em; line-height: 1.2; }
.sheet__phone { color: var(--c-text-2); font-size: var(--fs-body); font-variant-numeric: tabular-nums; }
.sheet__state { display: flex; align-items: center; gap: var(--sp-3); margin-top: 8px; }

.group-title { margin: 18px 16px 6px 30px; font-size: var(--fs-sub); font-weight: var(--fw-semibold); color: var(--c-text-2); }
.group { margin: 0 16px; border-radius: 12px; background: var(--c-group); overflow: hidden; }
.field { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: var(--sp-3); align-items: baseline; min-height: 44px; padding: 11px 14px; }
.field + .field { box-shadow: inset 0 1px 0 var(--c-border); }
.field__label { font-size: var(--fs-sub); color: var(--c-text-2); }
.field__value { font-size: var(--fs-body); overflow-wrap: anywhere; }
.field__value--empty { color: var(--c-text-3); }
.field input, .field textarea {
  width: 100%; margin: -6px 0; padding: 5px 8px; border: 1px solid var(--c-border-strong); border-radius: var(--r-sm);
  background: var(--c-field); font-size: var(--fs-input);
}
.field textarea { resize: vertical; min-height: 56px; line-height: 1.35; }
.field--conflict { background: var(--c-warn-soft); }
.field__conflict { grid-column: 1 / -1; margin-top: 4px; font-size: var(--fs-footnote); color: var(--c-warn); line-height: 1.4; }
.field__conflict b { font-weight: var(--fw-semibold); }
.field__conflict-actions { display: flex; gap: var(--sp-2); margin-top: 8px; }
.field__conflict-actions .btn { height: 28px; font-size: var(--fs-footnote); }

.lead { display: flex; align-items: center; gap: var(--sp-3); padding: 12px 14px; }
.lead__no { font-size: var(--fs-headline); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.lead__who { font-size: var(--fs-sub); color: var(--c-text-2); }
.lead__icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: var(--c-accent-soft); color: var(--c-accent-text); flex: none; }
.lead__icon svg { width: 18px; height: 18px; }

.tags-edit { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 10px 12px; }
.tags-edit input { flex: 1; min-width: 110px; height: 28px; padding: 0 6px; border: 0; outline: none; background: transparent; font-size: var(--fs-input); }

/* ---------- 11. Menus, popovers, dialog, toasts ---------- */

.menu {
  position: fixed; z-index: 45; min-width: 220px; max-width: calc(100vw - 16px); padding: 5px; border-radius: 12px;
  background: var(--c-elevated); box-shadow: var(--shadow-3); animation: pop-in var(--dur) var(--ease-out) both; transform-origin: top right;
}
.menu__label { padding: 6px 10px 4px; font-size: var(--fs-footnote); font-weight: var(--fw-semibold); color: var(--c-text-3); }
.menu__item {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 34px; padding: 6px 10px;
  border: 0; border-radius: 8px; background: transparent; text-align: left;
}
.menu__item:hover, .menu__item:focus-visible { background: var(--c-accent); color: #fff; outline: none; }
.menu__item:hover .menu__sub, .menu__item:focus-visible .menu__sub { color: rgba(255, 255, 255, .8); }
.menu__item svg { width: 17px; height: 17px; opacity: .75; }
.menu__item .avatar { width: 26px; height: 26px; font-size: 10px; }
.menu__sub { margin-left: auto; padding-left: 12px; font-size: var(--fs-footnote); color: var(--c-text-3); }
.menu__sep { height: 1px; margin: 5px 8px; background: var(--c-border); }
.menu__item[aria-current="true"] { font-weight: var(--fw-semibold); }
.menu__item:disabled { opacity: .45; }
.menu__item:disabled:hover { background: transparent; color: inherit; }
.menu__row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: 6px 10px; }
.menu__me { padding: 8px 10px 6px; }
.menu__me b { display: block; }
.menu__me span { font-size: var(--fs-footnote); color: var(--c-text-3); }

/* Action sheet: the same menu, from the bottom, on phones */
.action-sheet { position: fixed; inset: 0; z-index: 45; }
.action-sheet__backdrop { position: absolute; inset: 0; background: var(--c-backdrop); animation: fade-in var(--dur) var(--ease) both; }
.menu--sheet {
  position: absolute; left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); min-width: 0; max-width: none; max-height: 80vh;
  overflow-y: auto; padding: 6px; border-radius: var(--r-lg); animation: sheet-rise var(--dur-slow) var(--ease-out) both;
}
.menu--sheet .menu__item { min-height: 50px; padding: 8px 14px; font-size: 17px; }
.menu--sheet .menu__label { padding: 8px 14px 4px; }
.menu--sheet .menu__cancel { justify-content: center; margin-top: 6px; background: var(--c-fill); font-weight: var(--fw-semibold); }
.menu--sheet .menu__cancel:hover { background: var(--c-fill-strong); color: inherit; }

.dialog {
  width: min(360px, calc(100vw - 32px)); padding: 22px 20px 16px; border: 0; border-radius: var(--r-lg);
  background: var(--c-elevated); color: var(--c-text); box-shadow: var(--shadow-3); text-align: center;
}
.dialog::backdrop { background: var(--c-backdrop); }
.dialog[open] { animation: pop-in var(--dur) var(--ease-out) both; }
.dialog h2 { margin: 0 0 6px; font-size: var(--fs-headline); font-weight: var(--fw-semibold); }
.dialog p { margin: 0 0 18px; font-size: var(--fs-sub); color: var(--c-text-2); line-height: 1.45; }
.dialog__actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
.dialog__actions .btn { height: 38px; font-size: var(--fs-body); }

.toasts {
  position: fixed; z-index: 70; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); width: max-content; max-width: calc(100vw - 32px); pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px; max-width: 460px; padding: 10px 14px 10px 12px; border-radius: 14px;
  background: rgba(36, 36, 38, .94); color: #f5f5f7; -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); box-shadow: var(--shadow-3);
  line-height: 1.35; pointer-events: auto; animation: toast-in var(--dur-slow) var(--ease-out) both;
}
.toast.is-leaving { animation: toast-out var(--dur) var(--ease) both; }
.toast svg { width: 18px; height: 18px; flex: none; }
.toast--error svg { color: #ff6b63; }
.toast--ok svg { color: #7fd1a0; }
.toast .btn--plain { height: 26px; color: #7fd1a0; margin-left: 4px; }

/* ---------- 12. Empty, offline, loading ---------- */

.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 220px; padding: var(--sp-10) var(--sp-6);
  text-align: center; color: var(--c-text-2);
}
.empty--fill { height: 100%; }
.empty__icon { display: grid; place-items: center; width: 52px; height: 52px; margin-bottom: 8px; border-radius: 50%; background: var(--c-fill); color: var(--c-text-3); }
.empty__icon svg { width: 24px; height: 24px; }
.empty__icon > svg[viewBox='0 0 192 192'] { width: 52px; height: 52px; opacity: .9; }
.empty__title { font-size: var(--fs-headline); font-weight: var(--fw-semibold); color: var(--c-text); }
.empty__text { max-width: 300px; font-size: var(--fs-sub); line-height: 1.45; }

.skeleton { border-radius: var(--r-sm); background: var(--c-fill); animation: pulse 1.4s ease-in-out infinite; }
/* Placeholders show only when loading takes a moment: a quick answer does not blink */
@keyframes appear { from { opacity: 0; } to { opacity: 1; } }
.inbox__loading, .timeline__loading, .skeleton--card, .thread-head__who[aria-busy] { animation: appear .2s ease-out .3s both; }
#list.is-stale { opacity: .55; pointer-events: none; transition: opacity var(--dur-fast) .1s; }
.inbox__loading, .timeline__loading { display: flex; flex-direction: column; gap: 12px; padding: 12px 8px; }
.inbox__loading .skeleton { height: 56px; border-radius: 12px; }
.timeline__loading .skeleton { width: 46%; height: 40px; border-radius: var(--r-bubble); }
.timeline__loading .skeleton--out { align-self: flex-end; width: 38%; }
.skeleton--line { display: block; width: 160px; height: 14px; }
.skeleton--card { height: 60px; margin: 12px 16px; }
.thread-head__who .avatar.skeleton { background: var(--c-fill); }
.thread__empty { grid-row: 1 / -1; }
.noscript { padding: 24px; }

/* ---------- 13. Bot page ---------- */

.page { grid-column: 1 / -1; overflow-y: auto; padding: var(--sp-8) var(--sp-6) var(--sp-10); background: var(--c-bg); }
.page__inner { max-width: 720px; margin: 0 auto; }
.page__title { margin: 0 0 var(--sp-5); font-size: var(--fs-large); font-weight: var(--fw-bold); letter-spacing: -.02em; line-height: 1.15; }
.section-title {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); margin: var(--sp-8) 4px var(--sp-2);
  font-size: var(--fs-headline); font-weight: var(--fw-semibold); letter-spacing: -.01em;
}
.section-title small { font-size: var(--fs-sub); font-weight: 400; color: var(--c-text-3); }

.card { border-radius: var(--r-lg); background: var(--c-surface); box-shadow: var(--shadow-1); overflow: hidden; }
.botswitch { display: flex; align-items: center; gap: var(--sp-4); padding: 18px 20px; }
.botswitch__text { flex: 1; min-width: 0; }
.botswitch__title { font-size: var(--fs-headline); font-weight: var(--fw-semibold); }
.botswitch__desc { margin-top: 2px; font-size: var(--fs-sub); color: var(--c-text-2); line-height: 1.45; }
.botswitch--sub { box-shadow: inset 0 1px 0 var(--c-border); }
.botswitch--numbers { align-items: flex-end; }
.botswitch--numbers textarea { display: block; width: 100%; margin-top: 8px; padding: 6px 8px; border: 1px solid var(--c-border-strong);
  border-radius: var(--r-sm); background: var(--c-field); font: inherit; font-size: var(--fs-input); resize: vertical; }
.botswitch__by { padding: 10px 20px; font-size: var(--fs-footnote); color: var(--c-text-3); box-shadow: inset 0 1px 0 var(--c-border); }

.list-row {
  display: flex; align-items: center; gap: var(--sp-3); width: 100%; min-height: 60px; padding: 10px 16px;
  border: 0; background: transparent; text-align: left; transition: background-color var(--dur-fast);
}
.list-row + .list-row { box-shadow: inset 0 1px 0 var(--c-border); }
.list-row:hover { background: var(--c-hover); }
.list-row__main { flex: 1; min-width: 0; }
.list-row__title { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-body); font-weight: var(--fw-semibold); min-width: 0; }
.list-row__text { display: block; margin-top: 1px; font-size: var(--fs-sub); color: var(--c-text-2); }
.list-row__side {
  flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 4px;
  font-size: var(--fs-footnote); color: var(--c-text-3); font-variant-numeric: tabular-nums;
}
.list-row__chev { color: var(--c-text-3); opacity: .6; }
.list-row__chev svg { width: 14px; height: 14px; }
.list-row--static { cursor: default; }
.list-row--static:hover { background: transparent; }
.problem__icon { display: grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: 9px; background: var(--c-danger-soft); color: var(--c-danger); }
.problem__icon svg { width: 17px; height: 17px; }
.list-row__text--bad { color: var(--c-danger); }

/* ---------- 14. Login ---------- */

.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: var(--sp-6) var(--sp-4); background: var(--c-bg); }
.login__card { width: 100%; max-width: 340px; display: flex; flex-direction: column; align-items: center; text-align: center; }
.login h1 { margin: 0 0 28px; display: flex; flex-direction: column; align-items: center; gap: 10px; font-size: var(--fs-headline); font-weight: var(--fw-medium); color: var(--c-text-2); }
.login h1 .logo { height: 56px; }
.login form { width: 100%; display: flex; flex-direction: column; gap: var(--sp-3); }
.fieldset {
  display: flex; flex-direction: column; border: 1px solid var(--c-border-strong); border-radius: var(--r-md);
  background: var(--c-field); overflow: hidden; transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.fieldset input { height: var(--tap); padding: 0 14px; border: 0; background: transparent; font-size: var(--fs-input); }
.fieldset input + input { box-shadow: inset 0 1px 0 var(--c-border); }
.fieldset--error { border-color: var(--c-danger); }
.form-error { min-height: 18px; margin: 0; font-size: var(--fs-sub); color: var(--c-danger); }

/* ---------- 15. Mobile: list → full-screen thread ---------- */

@media (max-width: 759px) {
  /* Not on a phone: the app bar in a thread, the list beside the thread, the header's desktop parts, reasons in rows */
  .app[data-pane="thread"] .appbar, .app[data-pane="thread"] .inbox, .app[data-pane="list"] .thread, .botstate, .appbar__brand span,
  .thread-head__who .avatar, .thread-head__sub, .thread-head__state, .thread-head__actions .btn:not(.btn--primary), .row__meta .reason { display: none; }
  .app[data-pane="thread"] { grid-template-rows: auto 1fr; }
  .appbar { padding: 0 var(--sp-3); gap: var(--sp-2); }
  .appbar__nav { margin-left: var(--sp-1); }
  .appbar .segmented button { height: 32px; padding: 0 12px; }

  .main { grid-template-columns: minmax(0, 1fr); }
  .inbox { border-right: 0; }
  .inbox__head { padding: var(--sp-2) var(--sp-3); }
  .search input { height: 38px; }
  .chip { height: 34px; }
  .row { padding: 12px 10px 12px 8px; }

  /* compact header: name, pill (+ waiting) under it, at most one primary action, the rest in the ⋯ sheet */
  .thread-head { gap: var(--sp-1); min-height: 56px; padding: calc(4px + env(safe-area-inset-top)) var(--sp-1) 6px 0; }
  .thread-head__back { display: inline-grid; margin-left: 0; }
  .thread-head__who { gap: var(--sp-2); padding-left: 2px; }
  .thread-head__name { font-size: 16px; }
  .thread-head__pill-m { display: flex; flex-wrap: wrap; row-gap: 4px; margin-top: 3px; }
  .thread-head__pill-m .pill { height: 20px; padding: 0 8px; font-size: var(--fs-caption); }
  .thread-head__pill-m .pill svg { width: 12px; height: 12px; }
  .thread-head__pill-m .waiting { font-size: var(--fs-caption); }
  .thread-head__actions { gap: 0; }
  .thread-head__actions .btn--primary { position: relative; height: 32px; padding: 0 14px; border-radius: var(--r-pill); font-size: var(--fs-sub); }
  .thread-head__actions .btn--primary::after { content: ""; position: absolute; inset: -6px -2px; } /* 44 px hit area */
  .thread-head__actions .icon-btn { width: var(--tap); height: var(--tap); color: var(--c-accent-text); }
  .thread-head__actions .icon-btn svg { width: 22px; height: 22px; }

  .timeline { padding: var(--sp-1) var(--sp-3) var(--sp-5); }
  .msg { max-width: 86%; }
  .composer { padding: var(--sp-2) var(--sp-3) calc(var(--sp-2) + env(safe-area-inset-bottom)); }
  .composer__box textarea { height: 34px; padding: 7px 0; }
  .send { width: 34px; height: 34px; }
  .send--wide { width: auto; }

  .sheet { inset: 0; width: auto; max-width: none; border-radius: 0; animation-name: sheet-up; }
  .sheet__head { padding-top: calc(8px + env(safe-area-inset-top)); }
  .page { padding: var(--sp-5) var(--sp-4) var(--sp-8); }
  .page__title { font-size: 26px; }
  .botswitch { padding: 16px; }
  .toasts { bottom: calc(84px + env(safe-area-inset-bottom)); }
  .media-img, .media-video, .voice, .file, .loc { width: 240px; }
}

@media (max-width: 400px) {
  .appbar__theme { display: none; }
  .appbar .segmented button { padding: 0 10px; }
  .field { grid-template-columns: 88px minmax(0, 1fr); }
  .media-img, .voice, .file, .loc { width: 220px; }
}
@media (max-width: 360px) {
  .cw-long { display: none; }
  .cw-short { display: inline; }
}
@media (max-width: 340px) {
  .appbar__brand { display: none; }
  .appbar__nav { margin-left: 0; }
  .thread-head__actions .btn--primary { padding: 0 10px; }
  .msg { max-width: 90%; }
}

/* ---------- 16. Motion ---------- */

@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes zoom-in { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
@keyframes pop-in { from { opacity: 0; transform: scale(.97) translateY(-4px); } to { opacity: 1; transform: none; } }
@keyframes sheet-in { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes sheet-rise { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px) scale(.98); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .5; } }

/* Only things that arrive while you watch animate in; what is already there just appears */
.anim-in { animation: msg-in var(--dur-slow) var(--ease-out) both; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
