/* Alchat — панель оператора. Визуальный язык макета Saleskit: синий акцент, серо-синие вторичные
   тона, линейные иконки, просторные строки. Компьютер: три колонки; планшет: две + карточка
   поверх; телефон: одна. */

/* Manrope (SIL OFL 1.1, fonts/Manrope-OFL.txt) — переменный, кириллица и латиница; из бандла
   панели, без внешних CDN. */
@font-face {
  font-family: 'Manrope';
  font-style: normal;
  font-display: swap;
  font-weight: 200 800;
  src: url('/fonts/manrope-cyrillic-wght-normal.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Manrope';
  font-style: normal;
  font-display: swap;
  font-weight: 200 800;
  src: url('/fonts/manrope-latin-wght-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304,
    U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --accent: #225ffc;
  --accent-hover: #1a4fd9;
  --accent-soft: #eaf0ff;
  --accent-line: #c9d8ff;
  --text: #0b0b0a;
  /* WCAG AA: --muted ≥ 4.5:1 for small text on white (5.30), --bg (4.94) and --accent-soft (4.65);
     --icon ≥ 3:1 for icons and ticks on white (3.61), --bg (3.37) and --accent-soft (3.17). */
  --muted: #5c6c89;
  --icon: #7587ab;
  --line: #d9dfeb;
  --bg: #f4f7fd;
  --panel: #ffffff;
  --danger: #e5484d;
  --danger-text: #c62a2f;
  --danger-soft: #fff1f1;
  --warn-soft: #fff8e6;
  --note: #fff8d6;
  --note-line: #f2d675;
  --ok: #1f9d55;
  --radius: 8px;
  --radius-sm: 6px;
  font-family: 'Manrope', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
    sans-serif;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { overscroll-behavior: none; }
h1, h2, h3 { margin: 0 0 0.5em; line-height: 1.25; font-weight: 700; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; margin: 0 0 0.6rem; }
p { margin: 0 0 0.6em; }
ul { list-style: none; margin: 0; padding: 0; }
a { color: var(--accent); }

.icon { flex: none; display: block; }

button {
  font: inherit;
  font-weight: 500;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.85rem;
  cursor: pointer;
  min-height: 36px;
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
button:hover:not(:disabled) { border-color: #b9c4da; }
button:disabled { opacity: 0.55; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button.big { min-height: 48px; font-size: 1rem; font-weight: 600; border-radius: var(--radius); }
button.link { border: 0; background: none; color: var(--accent); padding: 0 0.25rem; min-height: 0; }
.icon-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;
  min-width: 36px; min-height: 36px; padding: 0 0.5rem;
  border: 0; background: none; color: var(--icon); border-radius: var(--radius-sm); cursor: pointer;
}
.icon-button:hover:not(:disabled) { color: var(--accent); background: var(--bg); }
.icon-button.active { color: var(--accent); }
input, select, textarea {
  font: inherit;
  color: inherit;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.7rem;
  background: #fff;
  min-height: 38px;
  width: 100%;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
select {
  appearance: none; -webkit-appearance: none; padding-right: 1.8rem; cursor: pointer;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236A7B9B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 0.6rem center;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgb(34 95 252 / 0.15); }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type='checkbox'] { width: auto; min-height: 0; accent-color: var(--accent); }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.pad { padding: 0.75rem 1.25rem; }
.error { color: var(--danger-text); }
.notice { background: var(--accent-soft); border-radius: var(--radius-sm); padding: 0.6rem 0.8rem; }
.break { overflow-wrap: anywhere; }
.row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.boot { display: grid; place-items: center; gap: 1rem; min-height: 100vh; padding: 2rem; text-align: center; }

/* ---- avatars, channel, status, ticks ------------------------------------------------------- */
.avatar {
  position: relative; flex: none; display: inline-grid; place-items: center;
  width: 44px; height: 44px; border-radius: 50%;
  color: #fff; font-weight: 600; font-size: 0.95rem; letter-spacing: 0.02em;
}
/* White initials stay ≥ 3.3:1 even on the light start of each gradient. */
.avatar-g0 { background: linear-gradient(135deg, #4f83f5 0%, #1f4fe0 100%); }
.avatar-g1 { background: linear-gradient(135deg, #3d8bf0 0%, #225ffc 100%); }
.avatar-g2 { background: linear-gradient(135deg, #6f73f2 0%, #3b52e6 100%); }
.avatar-g3 { background: linear-gradient(135deg, #2a98c4 0%, #2a7bf0 100%); }
.avatar-sm { width: 36px; height: 36px; font-size: 0.8rem; }
.avatar-lg { width: 80px; height: 80px; font-size: 1.7rem; }
.avatar .channel-small { position: absolute; right: -3px; bottom: -3px; }
.avatar-sm .channel-small { width: 14px; height: 14px; right: -5px; bottom: -5px; }
.avatar-sm .channel-small .icon { width: 10px; height: 10px; }

.channel {
  flex: none; display: inline-grid; place-items: center;
  width: 26px; height: 26px; border-radius: 50%;
  color: var(--muted); background: var(--bg);
}
.channel-small { width: 18px; height: 18px; border: 2px solid var(--panel); background: var(--panel); box-sizing: content-box; }
.channel-telegram { color: #229ed9; background: #e6f5fc; }
.channel-widget { color: var(--accent); background: var(--accent-soft); }
.channel-email { color: #e5762e; background: #fff1e7; }
.channel-api { color: #56627a; background: #eef1f6; }
.channel-max { color: #5b3fd6; background: #efebfd; }
.channel-small.channel-telegram, .channel-small.channel-widget,
.channel-small.channel-email, .channel-small.channel-api,
.channel-small.channel-max { background: var(--panel); }

.status { font-size: 0.72rem; font-weight: 600; border-radius: 4px; padding: 0.05rem 0.4rem; background: var(--bg); color: var(--muted); white-space: nowrap; }
.status-new { background: var(--accent-soft); color: var(--accent-hover); }
.status-open { background: #e5f6ec; color: #17703d; }
.status-closed { background: #eef1f6; color: var(--muted); }

.tick { display: inline-flex; color: var(--icon); }
.tick-read { color: var(--accent); }
.tick-failed { color: var(--danger); }

/* ---- auth ---------------------------------------------------------------------------------- */
.auth-page { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 1.5rem; padding: 1.5rem 1rem; background: var(--bg); }
.auth-logo { display: flex; align-items: center; gap: 0.6rem; font-size: 1.45rem; font-weight: 700; letter-spacing: -0.01em; }
.auth-logo img { border-radius: 9px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; }
.auth { width: min(400px, calc(100vw - 2rem)); display: grid; gap: 1rem; border: 0; border-radius: 16px; padding: 2.25rem 2rem 2rem; box-shadow: 0 12px 40px rgb(34 60 120 / 0.08); }
.auth h1 { font-size: 1.6rem; margin: 0; }
.auth h1 + p { margin: -0.5rem 0 0.25rem; }
.auth label { display: grid; gap: 0.35rem; }
.auth label span { font-size: 0.86rem; color: var(--muted); font-weight: 500; }
.auth input { min-height: 46px; padding: 0.6rem 0.85rem; }
.password { position: relative; }
.password input { padding-right: 3rem; }
.password .reveal { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.auth .big { margin-top: 0.5rem; }
.auth-aside { margin: 0; text-align: center; font-size: 0.92rem; }

/* ---- shell --------------------------------------------------------------------------------- */
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; background: var(--panel); }
.topbar {
  display: flex; align-items: center; gap: 0.9rem;
  min-height: 60px; padding: 0.5rem 1.25rem; padding-top: max(0.5rem, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar .brand { font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; display: flex; gap: 0.55rem; align-items: center; }
.topbar .brand img { border-radius: 7px; }
.topbar .spacer { flex: 1; }
.topbar .me { text-decoration: none; font-weight: 500; color: var(--text); }
.topbar .me:hover { color: var(--accent); }
/* Organization switcher (several memberships): the current organization, the others to pick. */
.topbar .org-switch { display: inline-flex; align-items: center; gap: 0.5rem; min-width: 0; }
.topbar .org-switch select { max-width: 16rem; padding-top: 0.3rem; padding-bottom: 0.3rem; font-weight: 500; }
.topbar .org-switch .error { font-size: 0.85rem; white-space: nowrap; }
.badge { background: var(--accent); color: #fff; border-radius: 999px; font-size: 0.72rem; font-weight: 700; min-width: 20px; height: 20px; padding: 0 0.4rem; display: inline-grid; place-items: center; }
.conn { width: 8px; height: 8px; border-radius: 50%; background: var(--icon); }
.conn-online { background: var(--ok); }
.conn-connecting { background: #f5a524; }
.conn-offline { background: var(--danger); }
.banner { display: flex; gap: 0.75rem; justify-content: space-between; align-items: center; padding: 0.5rem 1.25rem; }
.banner.warn { background: var(--warn-soft); border-bottom: 1px solid #f6dfa0; }
.banner.error { background: var(--danger-soft); color: var(--danger-text); }

.inbox {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr) minmax(280px, 340px);
}
.pane { min-height: 0; display: flex; flex-direction: column; background: var(--panel); }
.pane-list { border-right: 1px solid var(--line); }
.pane-card { border-left: 1px solid var(--line); overflow-y: auto; }
.pane-thread.empty { display: grid; place-items: center; }
.empty-state { display: grid; justify-items: center; gap: 0.75rem; text-align: center; }
.empty-icon { display: grid; place-items: center; width: 72px; height: 72px; border-radius: 50%; background: var(--bg); color: var(--accent); }

/* ---- list ---------------------------------------------------------------------------------- */
.search { position: relative; padding: 0.9rem 1rem 0.5rem; }
.search-icon { position: absolute; left: 1.75rem; top: calc(0.9rem + 11px); color: var(--icon); pointer-events: none; }
.search input { background: var(--bg); border-color: transparent; min-height: 42px; padding-left: 2.6rem; }
.search input:focus { background: #fff; border-color: var(--accent); }
.filters { border-bottom: 1px solid var(--line); }
.filter-bar { display: flex; align-items: center; gap: 0.5rem; padding: 0 0.75rem 0 1rem; }
.tabs { display: flex; gap: 1.1rem; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.tab {
  border: 0; border-radius: 0; background: none; padding: 0.55rem 0 0.6rem; min-height: 0;
  color: var(--muted); font-weight: 500; white-space: nowrap; border-bottom: 2px solid transparent;
}
.tab:hover:not(:disabled) { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.filter-toggle { position: relative; }
.filter-count {
  position: absolute; top: 2px; right: 0; min-width: 16px; height: 16px; border-radius: 999px;
  background: var(--accent); color: #fff; font-size: 0.65rem; font-weight: 700; display: grid; place-items: center; padding: 0 3px;
}
.filter-panel { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.4rem; padding: 0.5rem 1rem 0.75rem; }
.filter { display: grid; gap: 0.15rem; min-width: 0; }
.filter-label { font-size: 0.72rem; color: var(--muted); }
.filter select { font-size: 0.86rem; min-height: 32px; padding: 0.25rem 1.6rem 0.25rem 0.5rem; }
.case-list { flex: 1; overflow-y: auto; }
.case-row {
  position: relative; display: flex; gap: 0.85rem; align-items: flex-start; padding: 0.85rem 1rem;
  color: inherit; text-decoration: none; border-bottom: 1px solid var(--line);
}
.case-row .avatar { margin-top: 2px; }
.case-row:hover { background: #fafbfe; }
.case-row.selected { background: var(--bg); }
.case-row.selected::after { content: ''; position: absolute; top: 0; bottom: 0; right: 0; width: 3px; background: var(--accent); }
.case-row.unread .case-name { font-weight: 700; }
.case-main { flex: 1; min-width: 0; }
.case-top { display: flex; gap: 0.5rem; align-items: baseline; justify-content: space-between; }
.case-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.case-time { color: var(--muted); font-size: 0.78rem; flex: none; }
.case-preview {
  margin-top: 0.15rem; color: var(--muted); font-size: 0.9rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 1.3em;
}
.case-preview .icon { display: inline-block; vertical-align: -2px; }
.case-row.unread .case-preview { color: var(--text); }
.preview-author { color: var(--text); }
.case-meta { display: flex; gap: 0.4rem; align-items: center; margin-top: 0.35rem; font-size: 0.76rem; color: var(--muted); min-width: 0; }
.case-assignee, .case-folder { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.case-folder::before { content: '· '; }
.counter {
  flex: none; align-self: center; min-width: 22px; height: 22px; border-radius: 999px; padding: 0 0.4rem;
  background: var(--accent); color: #fff; font-size: 0.75rem; font-weight: 700; display: grid; place-items: center;
}
.more, .older { display: grid; place-items: center; padding: 0.75rem; }
.search-head { display: flex; justify-content: space-between; padding: 0.4rem 1rem; color: var(--muted); font-size: 0.85rem; }
.search-results h3 { margin: 1rem 1rem 0.4rem; }
.hit { padding: 0.6rem 1rem; border-bottom: 1px solid var(--line); }
.hit-link { color: inherit; text-decoration: none; display: block; }
.hit-contact { width: 100%; min-height: 0; padding: 0; border: 0; border-radius: 0; text-align: left; font-weight: inherit; }
.snippet { font-size: 0.9rem; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); }

/* ---- thread -------------------------------------------------------------------------------- */
.thread-head {
  display: flex; align-items: center; gap: 0.75rem; min-height: 68px;
  padding: 0.6rem 1rem 0.6rem 1.25rem; border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.thread-head .back { display: none; color: var(--muted); text-decoration: none; padding: 0.3rem; margin-left: -0.4rem; }
.thread-title { flex: 1; min-width: 8rem; }
.thread-title .case-name { font-size: 1.05rem; }
.thread-sub { display: flex; gap: 0.4rem; align-items: center; margin-top: 0.1rem; font-size: 0.8rem; color: var(--muted); }
.thread-actions { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
.thread-actions select { width: auto; max-width: 14rem; min-height: 34px; font-size: 0.9rem; }
.thread-actions button { min-height: 34px; font-size: 0.9rem; }
.card-toggle { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 1rem 1.5rem 1.25rem; display: flex; flex-direction: column; gap: 0.55rem; }

/* Bubbles (default): incoming left, ours right, no avatars. */
.msg { display: flex; gap: 0.75rem; max-width: min(680px, 85%); }
.msg-avatar { display: none; }
.msg-content { min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 0.55rem 0.85rem 0.5rem; }
.msg-in { align-self: flex-start; }
.msg-in .msg-content { border-top-left-radius: 4px; }
.msg-out { align-self: flex-end; }
.msg-out .msg-content { background: var(--accent-soft); border-color: var(--accent-line); border-top-right-radius: 4px; }
.msg-note .msg-content { background: var(--note); border: 1px dashed var(--note-line); }
.msg-system { align-self: center; }
.msg-system .msg-content { background: transparent; border-style: dashed; }
.msg-head { display: flex; gap: 0.75rem; justify-content: space-between; align-items: baseline; font-size: 0.78rem; color: var(--muted); margin-bottom: 0.15rem; }
.msg-author { font-weight: 600; }
.note-mark { display: inline-flex; align-items: center; gap: 0.2rem; color: #7d6310; }
.note-mark .icon { display: inline-block; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.97rem; line-height: 1.5; }
/* email-display: a letter as text — clickable words, signature and quote folded behind «•••». */
.msg-link { color: var(--accent); text-decoration: underline; text-decoration-color: var(--accent-line); text-underline-offset: 2px; }
.msg-link:hover { text-decoration-color: currentColor; }
.fold { margin-top: 0.3rem; font-size: 0.9rem; }
.fold summary { list-style: none; display: inline-flex; align-items: center; gap: 0.4rem; cursor: pointer; color: var(--muted); }
.fold summary::-webkit-details-marker { display: none; }
.fold-dots { display: inline-block; padding: 0 0.45rem; border-radius: 999px; background: var(--line); color: var(--muted); font-size: 0.7rem; line-height: 1.1rem; letter-spacing: 0.08em; }
.fold summary:hover .fold-dots, .fold summary:focus-visible .fold-dots { background: var(--accent-line); color: var(--text); }
.fold[open] .fold-dots { background: var(--accent-line); }
.fold-label { font-size: 0.8rem; }
.fold .fold-body { margin-top: 0.3rem; color: var(--muted); }
.quote .fold-body { border-left: 3px solid var(--line); padding-left: 0.6rem; }
/* «Как в почте»: the sanitized letter in a sandboxed iframe, as wide as a bubble may be. */
.msg:has(.letter-mail) { width: min(680px, 85%); }
.msg-content:has(.letter-mail) { flex: 1 1 auto; }
.letter-mail { margin-top: 0.2rem; }
.letter-frame { display: block; width: 100%; height: 320px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.letter-images { display: flex; flex-wrap: wrap; gap: 0.25rem 0.75rem; align-items: baseline; margin-bottom: 0.4rem; padding: 0.4rem 0.6rem; border-radius: var(--radius); background: var(--bg); color: var(--muted); font-size: 0.82rem; }
.letter-error { display: flex; flex-wrap: wrap; gap: 0.25rem 0.75rem; align-items: baseline; margin-bottom: 0.4rem; padding: 0.4rem 0.6rem; border-radius: var(--radius); background: var(--danger-soft); color: var(--danger-text); font-size: 0.82rem; }
.letter-switch { margin-top: 0.3rem; }
.letter-switch .link { font-size: 0.82rem; }
.files { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.4rem; }
.thumb { max-width: 240px; max-height: 180px; border-radius: var(--radius); display: block; }
.file {
  display: inline-flex; align-items: center; gap: 0.5rem; max-width: 100%;
  padding: 0.45rem 0.7rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
  color: var(--text); text-decoration: none; font-size: 0.9rem;
}
.file .icon { color: var(--accent); }
.file-name { overflow-wrap: anywhere; }
.file-size { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
.msg-when { display: inline-flex; align-items: center; gap: 0.3rem; white-space: nowrap; }
.delivery { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; font-size: 0.78rem; margin-top: 0.25rem; }
.delivery-failed { color: var(--danger-text); }
.divider { display: flex; align-items: center; gap: 0.75rem; color: var(--muted); font-size: 0.78rem; margin: 0.75rem 0 0.35rem; }
.divider::before, .divider::after { content: ''; flex: 1; border-top: 1px solid var(--line); }
.day-divider { color: var(--muted); font-weight: 500; }
.day-divider + .divider { margin-top: 0; }
.event { align-self: center; color: var(--muted); font-size: 0.78rem; }

/* Feed (`thread--feed`, Features.threadFeed): the Saleskit look — avatar, name and time, the text
   under them, all on the left, no bubbles. Our messages get a light background. */
.thread--feed { gap: 0.25rem; padding: 1rem 1.5rem 1.25rem; }
.thread--feed .msg { align-self: stretch; max-width: none; gap: 0.85rem; padding: 0.6rem 0.75rem; border-radius: var(--radius); }
.thread--feed .msg-avatar { display: inline-grid; width: 34px; height: 34px; font-size: 0.75rem; margin-top: 2px; }
.thread--feed .msg-content { flex: 1; background: none; border: 0; border-radius: 0; padding: 0; max-width: 720px; }
.thread--feed .msg-out { background: #f8faff; }
.thread--feed .msg-note { background: var(--note); }
.thread--feed .msg-note .msg-content { border: 0; }
.thread--feed .msg-system { align-self: stretch; }
.thread--feed .msg-system .msg-avatar { background: var(--icon); }
.thread--feed .msg-head { justify-content: flex-start; gap: 0.6rem; font-size: 0.9rem; margin-bottom: 0.2rem; }
.thread--feed .msg-author { color: var(--text); }
.thread--feed .msg-time { font-size: 0.78rem; color: var(--muted); }

/* Composer: one growing line, tools on the right, a square send button. */
.composer { border-top: 1px solid var(--line); padding: 0.75rem 1.25rem; padding-bottom: max(0.75rem, env(safe-area-inset-bottom)); display: grid; gap: 0.45rem; background: var(--panel); }
.composer-box { display: flex; align-items: flex-end; gap: 0.5rem; }
.composer textarea {
  flex: 1; resize: none; border: 0; padding: 0.55rem 0.25rem; min-height: 40px; max-height: 40vh;
  line-height: 1.45; field-sizing: content; overflow-y: auto; background: transparent;
}
.composer textarea:focus { box-shadow: none; }
/* The field has no border of its own: the focus ring goes around the whole reply box. */
.composer-box { border-radius: var(--radius); padding-left: 0.4rem; }
.composer-box:has(textarea:focus-visible) { box-shadow: 0 0 0 2px var(--accent); }
.composer-note .composer-box { background: var(--note); box-shadow: inset 0 0 0 1px var(--note-line); }
.composer-note .composer-box:has(textarea:focus-visible) { box-shadow: inset 0 0 0 1px var(--note-line), 0 0 0 2px var(--accent); }
.composer-tools { display: flex; align-items: center; gap: 0.25rem; }
.composer-tools .note-toggle { font-size: 0.86rem; }
.composer-tools .note-toggle.active { color: #7d6310; }
.tool-text { color: inherit; }
.send { width: 40px; min-width: 40px; height: 40px; padding: 0; display: grid; place-items: center; border-radius: var(--radius-sm); }
.composer-hint { color: var(--muted); margin: 0; }
.attach { cursor: pointer; }
.attach:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.uploads { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.uploads li { font-size: 0.85rem; display: inline-flex; gap: 0.25rem; align-items: center; background: var(--bg); border-radius: var(--radius-sm); padding: 0.2rem 0.3rem 0.2rem 0.6rem; }
.uploads li.error { color: var(--danger-text); background: var(--danger-soft); }

/* ---- card ---------------------------------------------------------------------------------- */
.card-head { position: relative; display: grid; justify-items: center; gap: 0.35rem; padding: 1.75rem 1.25rem 1.25rem; text-align: center; border-bottom: 1px solid var(--line); }
.card-head h2 { margin: 0.5rem 0 0; font-size: 1.15rem; overflow-wrap: anywhere; }
.card-channel { display: inline-flex; align-items: center; gap: 0.4rem; color: var(--muted); font-size: 0.86rem; }
.card-close { display: none; position: absolute; top: 0.5rem; right: 0.5rem; }
.card-section { padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); }
.fields { display: grid; gap: 0.7rem; }
.field-label { font-size: 0.76rem; color: var(--muted); margin-bottom: 0.1rem; }
.field-value { overflow-wrap: anywhere; }
.structured { white-space: pre-wrap; }
.other-threads { display: grid; gap: 0.5rem; }
.other-threads a, .other-thread { text-decoration: none; color: inherit; display: inline-flex; gap: 0.45rem; align-items: center; }
.other-threads a:hover { color: var(--accent); }

/* ---- profile ------------------------------------------------------------------------------- */
.profile { padding: 1.25rem; display: grid; gap: 1rem; max-width: 640px; width: 100%; margin: 0 auto; overflow-y: auto; }
.profile dl { margin: 0.5rem 0 1rem; display: grid; grid-template-columns: max-content 1fr; gap: 0.3rem 0.75rem; }
.profile dt { color: var(--muted); }
.profile dd { margin: 0; overflow-wrap: anywhere; }
.tg-code { font-size: 2rem; font-weight: 700; letter-spacing: 0.2em; font-variant-numeric: tabular-nums; }

/* ---- channel settings ----------------------------------------------------------------------- */
.topbar .nav-link { text-decoration: none; font-weight: 500; color: var(--text); }
.topbar .nav-link:hover { color: var(--accent); }
/* Rows by content: in the scrolling grid the tab strip (overflow-x: auto) would shrink to 1px. */
.settings { max-width: 760px; align-content: start; grid-auto-rows: max-content; }
.settings h1 { margin: 0; }
.crumbs { margin: 0; }
/* Wraps instead of scrolling: on a 390 px screen all three tab names stay visible. */
.settings-tabs { flex: none; flex-wrap: wrap; row-gap: 0.15rem; overflow: visible; border-bottom: 1px solid var(--line); }
.settings-tabs .tab { text-decoration: none; }
.settings-form { display: grid; gap: 0.9rem; }
.settings-form h2 { margin: 0.4rem 0 0; }
.settings-form h3 { margin: 0.4rem 0 0; }
.field { display: grid; gap: 0.3rem; min-width: 0; }
.field-label { font-size: 0.86rem; color: var(--muted); font-weight: 500; }
.check { display: inline-flex; gap: 0.5rem; align-items: center; cursor: pointer; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.9rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.9rem; }
.color-row { display: flex; gap: 0.5rem; }
.color-row input[type='color'] { width: 48px; flex: none; padding: 0.2rem; cursor: pointer; }
.seg { flex: none; gap: 0.5rem; }
.seg .tab { padding: 0.4rem 0.8rem; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.seg .tab.active { border-color: var(--accent); background: var(--accent-soft); }
.days { display: grid; gap: 0.4rem; }
.day { display: grid; grid-template-columns: 5.5rem 6.5rem auto 6.5rem; gap: 0.5rem; align-items: center; justify-content: start; }
.day.off { grid-template-columns: 5.5rem 1fr; }
.day-error { grid-column: 1 / -1; }
.origins li { overflow-wrap: anywhere; }
.save-status:empty { display: none; }
.saved { color: #17723f; font-weight: 500; margin: 0; } /* --ok is too light for text on white */
.channel-list li { display: flex; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; padding: 0.6rem 0; border-bottom: 1px solid var(--line); }
.channel-list li:last-child { border-bottom: 0; }
.team-head { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.settings.team { max-width: 1040px; }
.team-table { width: 100%; border-collapse: collapse; }
.team-table th { text-align: left; font-size: 0.86rem; color: var(--muted); font-weight: 500; padding: 0.4rem 0.75rem 0.4rem 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
.team-table td { padding: 0.6rem 0.75rem 0.6rem 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.team-table tr:last-child td { border-bottom: 0; }
.team-table tr.off td { opacity: 0.65; }
.team-role, .team-state { white-space: nowrap; }
.team-email span { white-space: nowrap; } /* breaks only at the <wbr> after @ and before dots */
.team-act { padding-right: 0; }
.team-actions { display: flex; gap: 0.3rem 0.75rem; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.team-actions button, .team-actions span { white-space: nowrap; }
@media (max-width: 639px) {
  /* Cards: name and email; role · folders; state; actions in a row. */
  .team-table, .team-table tbody { display: block; }
  .team-table thead { display: none; }
  .team-table tr { display: block; padding: 0.75rem 0; border-bottom: 1px solid var(--line); }
  .team-table tr:last-child { border-bottom: 0; }
  .team-table td { display: block; padding: 0.1rem 0; border-bottom: 0; }
  .team-table td.team-role, .team-table td.team-folders { display: inline; }
  .team-table td.team-folders::before { content: ' · '; color: var(--muted); }
  .team-table td.team-state { white-space: normal; color: var(--muted); }
  .team-table td.team-act { padding-top: 0.4rem; }
  .team-actions { justify-content: flex-start; }
}
fieldset.field { border: 0; padding: 0; margin: 0; }
.rules { display: grid; gap: 0.5rem; }
.rule { display: flex; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0.6rem 0.8rem; }
.rule.off { opacity: 0.65; }
.rule-main { display: grid; gap: 0.15rem; min-width: 0; flex: 1 1 260px; }
.rule-main > * { overflow-wrap: anywhere; }
.rule-text { color: var(--text); }
.rule-actions { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
button.link.danger { color: var(--danger-text); }
.rule-editor { display: grid; gap: 0.9rem; border: 1px solid var(--accent-line); background: var(--accent-soft); border-radius: var(--radius); padding: 1rem; }
.msg-auto { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.2rem; overflow-wrap: anywhere; }

/* ---- tablet: list + thread, the card slides over ------------------------------------------- */
@media (max-width: 1199px) {
  .inbox { grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); }
  .pane-card {
    position: fixed; top: 0; right: 0; bottom: 0; width: min(360px, 100%);
    z-index: 10; box-shadow: -8px 0 24px rgb(20 40 90 / 0.12);
    transform: translateX(100%);
    /* Hidden after it slides out: a closed card is out of the tab order and the a11y tree. */
    visibility: hidden; pointer-events: none;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
  }
  .inbox[data-card='on'] .pane-card,
  .pane-card[data-open='on'] { transform: none; visibility: visible; pointer-events: auto; transition: transform 0.2s ease; }
  .card-toggle, .card-close { display: inline-flex; }
}

/* ---- phone: one column, the route decides which ------------------------------------------- */
@media (max-width: 767px) {
  .inbox { grid-template-columns: minmax(0, 1fr); }
  .inbox > .pane { display: none; }
  .inbox[data-pane='list'] > .pane-list,
  .inbox[data-pane='thread'] > .pane-thread,
  .inbox[data-pane='card'] > .pane-card { display: flex; }
  .pane-card { position: static; transform: none; box-shadow: none; width: auto; border: 0; flex-direction: column; }
  .pane-list { border-right: 0; }
  .topbar { min-height: 52px; padding-left: 1rem; padding-right: 1rem; }
  .thread-head { padding: 0.5rem 0.75rem; gap: 0.6rem; min-height: 60px; }
  .thread-head .back { display: inline-flex; }
  .card-toggle { order: 1; margin-left: auto; }
  .thread-actions { order: 2; width: 100%; }
  .thread-actions select { flex: 1; max-width: none; }
  .messages { padding: 0.75rem 0.85rem 1rem; }
  .thread--feed .msg { padding: 0.5rem 0.4rem; }
  .msg { max-width: 92%; }
  .composer { padding-left: 0.75rem; padding-right: 0.75rem; }
  .tool-text { display: none; }
  .topbar .org { display: none; }
  /* The switcher stays on a phone: it is the only way to another organization. The bar has no
     room for it next to the links, so it takes a second row of its own, full width. */
  .topbar:has(.org-switch) { flex-wrap: wrap; row-gap: 0.45rem; padding-bottom: 0.6rem; }
  .topbar .org-switch { order: 10; flex: 1 1 100%; }
  .topbar .org-switch select { width: 100%; max-width: none; text-overflow: ellipsis; }
  /* The error stays visible on a phone: on its own line under the select. */
  .topbar .org-switch { flex-wrap: wrap; row-gap: 0.3rem; }
  .topbar .org-switch .error { flex-basis: 100%; white-space: normal; }
  input, select, textarea { font-size: 16px; } /* no zoom-on-focus in iOS Safari */
  .settings { padding: 0.75rem; }
  .settings .card { padding: 1rem; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .day { grid-template-columns: 4.5rem minmax(0, 1fr) auto minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
