/*
 * The one stylesheet of the app. Mobile first: what is written without @media is the phone, the blocks at the end widen it
 * for a computer (from 900px). Colors only through the variables below; nothing is loaded from anywhere (system font).
 * Python analogy: this is the one "base template" every page inherits from; the pages themselves carry classes, not styles.
 */
:root {
  --bg: #fbf7f0;
  --card: #fffdf9;
  --line: #efe7da;
  --text: #1b2421;
  --muted: #8a8378;
  --accent: #f2b155;
  --accent-strong: #d9822b;
  --ok: #2f9e44;
  --wait-bg: #fdebd3;
  --wait-text: #a85d12;
  --danger: #c92a2a;
  --danger-bg: #fdecea;
  --bubble-in: #f2ebdf;
  --bubble-out: #fde9cc;
  --tick: #3d8bd4; /* ✓ and ✓✓: sent and read, one calm blue */

  --tabbar-h: 58px;
  --tabbar-w: 92px;
  --radius: 12px;
  --tap: 44px; /* the least height of a button or a field: a finger */
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  /* the content must not go under the bottom tab bar (nor under the iPhone's home bar) */
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}

main {
  padding: 12px 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

main.narrow { max-width: 420px; margin: 0 auto; padding-top: 32px; padding-bottom: 32px; }
body:not(:has(#tabbar)) { padding-bottom: 0; } /* the login and invitation pages have no tab bar */

h1 { font-size: 22px; line-height: 1.2; margin: 8px 0 16px; }
h2 { font-size: 18px; margin: 24px 0 8px; }
h3 { font-size: 16px; margin: 16px 0 8px; }
p { margin: 8px 0; }
small, .muted { color: var(--muted); }
small { font-size: 13px; }
mark { background: var(--wait-bg); color: var(--wait-text); border-radius: 3px; padding: 0 2px; }
code { overflow-wrap: anywhere; }

a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- buttons and fields: at least 44px high ---------- */

/*
 * Buttons come in three ranks. A button is secondary unless marked: --card background, --line border, --text text.
 * .btn-primary (filled with --accent) is the one main action of a screen (Найти, Отправить, Войти...); .btn-text is a bare
 * word (Выйти) in --muted.
 */
button,
input[type="submit"],
input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="search"],
select, textarea {
  font: inherit;
  font-size: 16px; /* under 16px iOS zooms the page in when a field gets the focus */
  color: var(--text);
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  padding: 8px 12px;
}

button, input[type="submit"] { cursor: pointer; font-weight: 600; padding: 8px 16px; }
button:hover, input[type="submit"]:hover { border-color: var(--accent); }
button:disabled, input[type="submit"]:disabled { opacity: .5; cursor: default; }

.btn-primary { background: var(--accent); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }

.btn-text { background: none; border-color: transparent; color: var(--muted); font-weight: 400; padding-left: 0; }
.btn-text:hover { background: none; border-color: transparent; color: var(--text); text-decoration: underline; }

textarea { width: 100%; resize: vertical; }
input[type="checkbox"] { width: 20px; height: 20px; vertical-align: middle; accent-color: var(--accent-strong); }
:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 1px; }

/* A form is a row that wraps: fields stretch, the button goes on when there is no room. */
main form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0; max-width: 640px; }
main form > p, main form > textarea { flex: 1 1 100%; margin: 0; }
main form > input[type="text"], main form > input[type="email"], main form > input[type="password"],
main form > select { flex: 1 1 200px; min-width: 0; }
main form > p input[type="text"], main form > p input[type="password"], main form > p input[type="email"] { width: 100%; }
main form > p label { display: block; margin-bottom: 4px; }
main form > label { display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); }
main.narrow form { max-width: none; }

details { margin: 8px 0; }
summary { cursor: pointer; min-height: var(--tap); display: flex; align-items: center; color: var(--accent-strong); }
ul { padding-left: 20px; margin: 4px 0; }

/* ---------- cards ---------- */

.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); margin: 8px 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  min-width: 0;
  overflow-wrap: anywhere;
}
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }
.card form { max-width: none; }

.card-link { display: flex; flex-direction: column; gap: 2px; color: var(--text); }
.card-link:hover { text-decoration: none; border-color: var(--accent); }
.card-link small { color: var(--muted); }

.notice { background: var(--wait-bg); color: var(--wait-text); border-radius: var(--radius); padding: 4px 14px; margin: 12px 0; max-width: 640px; }
.track-status { margin: 4px 0 8px; padding-left: 12px; border-left: 3px solid var(--line); }
.note-body { white-space: pre-wrap; overflow-wrap: anywhere; }

.menu { display: grid; gap: 8px; margin: 8px 0 16px; max-width: 640px; }
.menu-item {
  display: flex; align-items: center; min-height: var(--tap);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 14px; color: var(--text); font-weight: 600;
}
.menu-item:hover { text-decoration: none; border-color: var(--accent); }

/* ---------- marks ---------- */

.badge { display: inline-block; border-radius: 10px; padding: 1px 8px; font-size: 13px; white-space: nowrap; }
.badge-unread { background: var(--accent-strong); color: #fff; }
.badge-wait { background: var(--wait-bg); color: var(--wait-text); }
.badge-danger { background: var(--danger-bg); color: var(--danger); font-weight: 600; }

.photo { max-width: min(320px, 100%); height: auto; border-radius: 8px; }

/* ---------- the chat list and the chat (the screens are reworked in the next steps; here only readable) ---------- */

table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
.table-wrap { overflow-x: auto; }

/* ---------- the chats: a list of cards, and the chat beside it on a computer ---------- */

main.chats-main { padding: 0; }

/* A phone shows one of the two: the list on /chats, the chat on /chats/{id}. */
.chats-layout.view-list .chat-pane { display: none; }
.chats-layout.view-chat .chat-col { display: none; }

.chat-head {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg); border-bottom: 1px solid var(--line);
  padding: 12px 16px 6px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}
.chat-head .search-form { margin: 0 0 8px; max-width: none; }

/* The search box: a magnifier inside the field on the left, no button. */
.search-field { position: relative; flex: 1 1 100%; min-width: 0; }
.search-field .icon { position: absolute; left: 12px; top: 50%; width: 20px; height: 20px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-field input[type="text"] { width: 100%; padding-left: 40px; border-radius: 22px; }

/* One line always; what does not fit is scrolled sideways (no bar), and a soft fade at the right edge says there is more
   (app.js sets .more-right only while something is hidden there). */
.chips { display: flex; flex-wrap: nowrap; gap: 8px; overflow-x: auto; white-space: nowrap; padding: 2px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips.more-right {
  -webkit-mask-image: linear-gradient(to right, black calc(100% - 32px), transparent);
  mask-image: linear-gradient(to right, black calc(100% - 32px), transparent);
}
.chip {
  flex: none; display: inline-flex; align-items: center; min-height: var(--tap);
  padding: 0 14px; border-radius: 22px; white-space: nowrap;
  background: var(--card); border: 1px solid var(--line); color: var(--text);
}
.chip:hover { text-decoration: none; border-color: var(--accent); }
.chip.active { background: var(--text); border-color: var(--text); color: var(--bg); }

.sync-line { font-size: 12px; color: var(--muted); padding: 0 0 4px; }
.sync-line.problem { color: var(--danger); }

.chat-list { padding: 8px 12px 16px; }
.chat-list .empty { padding: 24px 4px; color: var(--muted); }

.chat-card {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 8px; color: var(--text);
}
.chat-card:hover { text-decoration: none; border-color: var(--accent); }
.chat-card.active { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }

.chat-thumb { position: relative; flex: none; width: var(--thumb, 52px); height: var(--thumb, 52px); margin: 6px 0 0 6px; }
.chat-thumb-solo { margin: 0; } /* only the interlocutor's picture: no item picture, no corner to leave room for */
.chat-item-img { display: block; width: var(--thumb, 52px); height: var(--thumb, 52px); border-radius: 10px; object-fit: cover; background: var(--line); }
.chat-avatar {
  position: absolute; top: -6px; left: -6px; width: 24px; height: 24px;
  border-radius: 50%; object-fit: cover; border: 2px solid var(--card); background: var(--line);
}
.chat-avatar-big { position: static; width: var(--thumb, 52px); height: var(--thumb, 52px); border: 0; }
.chat-avatar-big.chat-avatar-letter { font-size: 20px; }
.chat-avatar-letter { display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: var(--muted); }

.chat-main { flex: 1 1 auto; min-width: 0; }
.chat-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.chat-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-time { flex: none; font-size: 13px; color: var(--muted); }
.chat-time .tick { margin-right: 4px; }
.chat-item, .chat-last { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.chat-item { display: flex; gap: 6px; font-size: 13px; color: var(--muted); }
.chat-item-title { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item-price { flex: none; font-weight: 600; color: var(--text); }
.chat-last { color: var(--muted); }
.chat-card.unread .chat-last { color: var(--text); font-weight: 700; }
.chat-count {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
  background: var(--accent-strong); color: #fff; font-size: 12px; font-weight: 600;
}
.chat-tags { margin-top: 4px; }
.chat-more { padding: 16px; text-align: center; color: var(--muted); min-height: 80px; }

/* ---------- the open chat: header on top, the feed scrolling in its own box, the input at the bottom ---------- */

/* The window does not scroll on a chat page: the pane has the height of the screen (minus the tab bar on a phone), so the input
   is always in view and the header never goes away while older messages load. */
/* 100dvh shrinks with the keyboard in Chrome (the viewport meta asks for it); iOS Safari does not shrink it, so app.js puts the
   height of the visible part into --vvh and the smaller of the two wins. With the keyboard open (html.kb) the tab bar is under
   it anyway: it is hidden and the chat takes the whole visible height. */
.chats-layout.view-chat { height: calc(100vh - var(--tabbar-h) - 1px - env(safe-area-inset-bottom)); height: calc(min(100dvh, var(--vvh, 100dvh)) - var(--tabbar-h) - 1px - env(safe-area-inset-bottom)); }
html.kb #tabbar { display: none; }
html.kb body { padding-bottom: 0; }
html.kb .chats-layout.view-chat { height: min(100dvh, var(--vvh, 100dvh)); }
html.kb .composer { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
.chat-pane { padding: 0; height: 100%; overflow: hidden; }
.pane-body { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); height: 100%; min-height: 0; }
.chat-stack { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

.chat-top {
  position: relative; z-index: 6; flex: none;
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 6px 8px 6px max(4px, env(safe-area-inset-left));
  padding-right: max(8px, env(safe-area-inset-right));
  --thumb: 40px;
}
.chat-back, .chat-menu summary {
  flex: none; width: var(--tap); height: var(--tap); min-height: var(--tap);
  display: flex; align-items: center; justify-content: center; color: var(--text);
}
.chat-back:hover, .chat-menu summary:hover { text-decoration: none; color: var(--accent-strong); }
.chat-top .chat-thumb { margin: 0; }
.chat-top .icon { width: 24px; height: 24px; }
.chat-top-text { flex: 1 1 auto; min-width: 0; }
.chat-top-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-top-item { display: block; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-top-price { font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.chat-top-item:hover { color: var(--accent-strong); }

.chat-menu { margin: 0; flex: none; }
.chat-menu summary { list-style: none; cursor: pointer; border-radius: 50%; }
.chat-menu summary::-webkit-details-marker { display: none; }
.chat-menu[open] summary { background: var(--line); }
.chat-menu-panel {
  position: absolute; right: 8px; top: 100%; z-index: 30;
  width: min(320px, calc(100% - 16px)); max-height: 70vh; max-height: 70dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .18); padding: 0 14px 12px;
}
.chat-menu-panel > :first-child { margin-top: 4px; }
.menu-row {
  display: flex; align-items: center; width: 100%; min-height: var(--tap); padding: 0 2px;
  border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: none;
  color: var(--text); font-size: 16px; font-weight: 400; text-align: left; cursor: pointer;
}
.menu-row:hover { color: var(--accent-strong); text-decoration: none; background: none; }
.chat-menu-panel form { max-width: none; }

#reply-line:empty { display: none; }
#reply-line .reply-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px;
  margin: 0; padding: 6px 12px; background: var(--wait-bg); color: var(--wait-text); font-size: 14px;
}
#reply-line .reply-row form { margin: 0; }
#reply-line input[type="submit"] { min-height: 32px; padding: 2px 12px; font-weight: 400; }
#reply-line .badge-wait { background: none; padding: 0; font-weight: 600; }
#reply-line small { color: var(--wait-text); }

.chat-body { position: relative; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.chat-scroll {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; padding: 8px 12px;
  padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right));
}
.chat-scroll > * { flex: none; }
#messages { display: flex; flex-direction: column; margin-top: auto; } /* a short chat sits at the bottom, like in a messenger */
#messages > #older, #messages > #history-start { text-align: center; padding: 8px 0; }
.chat-empty { margin: auto; color: var(--muted); text-align: center; }

.msg {
  position: relative; max-width: 75%; margin: 2px 0; padding: 6px 10px 4px;
  border-radius: 16px; overflow-wrap: anywhere;
}
.msg[data-dir="in"] { align-self: flex-start; margin-left: 44px; border-bottom-left-radius: 4px; background: var(--bubble-in); }
.msg[data-dir="out"] { align-self: flex-end; border-bottom-right-radius: 4px; background: var(--bubble-out); }

/* The customer's picture beside the last bubble of a row of theirs (--avatar or --letter come from the list, see ChatPages.kt). */
.msg-avatar {
  position: absolute; left: -44px; bottom: 0; width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background-color: var(--line); background-image: var(--avatar, none); background-size: cover; background-position: center;
  color: var(--muted); font-weight: 700; font-size: 15px;
}
.msg-avatar::after { content: var(--letter, ""); }
.msg[data-dir="in"]:has(+ .msg[data-dir="in"]) > .msg-avatar { visibility: hidden; }

.msg-system { align-self: center; max-width: 85%; margin: 6px 0; padding: 0; text-align: center; font-size: 13px; color: var(--muted); }
.msg[data-dir="in"] + .msg[data-dir="out"], .msg[data-dir="out"] + .msg[data-dir="in"] { margin-top: 8px; }
.msg-text { white-space: pre-line; }
.msg-time { display: block; text-align: right; font-size: 11px; line-height: 1.3; color: var(--muted); margin-top: 2px; }
.tick { color: var(--tick); font-size: 12px; font-weight: 700; letter-spacing: -1px; }
.msg-time .tick { margin-left: 2px; }
.msg .photo { display: block; margin-top: 4px; max-width: 100%; }
.day {
  align-self: center; margin: 10px 0 6px; padding: 2px 10px; border-radius: 10px;
  background: var(--line); color: var(--muted); font-size: 12px;
}

.pending-title { margin: 12px 0 4px; font-size: 13px; font-weight: 400; color: var(--muted); text-align: right; }
.pending {
  max-width: 75%; margin: 4px 0 4px auto; padding: 8px 12px; overflow-wrap: anywhere;
  background: var(--card); border: 1px dashed var(--accent-strong); border-radius: 16px;
}
.pending .msg-text { white-space: pre-line; }
.pending-state { margin-top: 2px; font-size: 12px; color: var(--muted); }
.pending-state.failed { color: var(--danger); }
.pending-mark { font-weight: 700; }
.pending form { display: inline-flex; margin: 6px 6px 0 0; }
.pending input[type="submit"] { min-height: 36px; padding: 4px 14px; }

.fab {
  position: absolute; right: 16px; bottom: 12px; z-index: 15;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .2);
}
.fab[hidden] { display: none; }

/* The input: always at the bottom. The field grows with the text (app.js), the buttons stay at its bottom edge. */
main form.composer {
  position: relative; flex: none; flex-wrap: nowrap; align-items: flex-end; gap: 8px; max-width: none; margin: 0;
  padding: 8px 12px; background: var(--bg); border-top: 1px solid var(--line);
  padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right));
}
main form.composer > textarea.composer-text {
  flex: 1 1 0; min-width: 0; width: auto; resize: none; overflow-y: auto;
  min-height: var(--tap); max-height: 150px; padding: 10px 14px; border-radius: 22px; line-height: 1.3;
}
.icon-btn {
  flex: none; width: var(--tap); height: var(--tap); padding: 0; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn .icon { width: 22px; height: 22px; }
.plus-btn { color: var(--muted); background: none; opacity: .6; }
.plus-btn:hover { border-color: var(--line); }
.composer-count { position: absolute; right: 20px; top: -20px; font-size: 12px; color: var(--muted); background: var(--bg); padding: 0 6px; border-radius: 8px; }
.composer-count.over { color: var(--danger); font-weight: 600; }
.quick-btn { color: var(--accent-strong); }
.quick-btn[aria-expanded="true"] { background: var(--wait-bg); border-color: var(--accent); }
.send-btn { background: var(--accent); border-color: var(--accent); color: var(--text); }
.send-btn:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.composer-error { flex: none; margin: 0; padding: 6px 12px; background: var(--danger-bg); color: var(--danger); }

/* Quick replies: the panel opens above the input (the replies themselves come later: a `.quick-reply` with `data-text`). */
.quick-panel {
  position: absolute; left: 12px; right: 12px; bottom: 100%; z-index: 20; margin-bottom: 6px;
  max-height: 40vh; max-height: 40dvh; overflow-y: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .18); padding: 8px 12px;
}
.quick-empty { margin: 8px 0; color: var(--muted); text-align: center; }
.quick-reply { display: block; width: 100%; text-align: left; font-weight: 400; margin: 4px 0; }

.pane-empty { color: var(--muted); }

/* ---------- the panel of the client: a sheet from the bottom on a phone, over the chat from 900px, a column from 1280px ---------- */

.client-panel {
  position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column; background: var(--bg);
  transform: translateY(100%); visibility: hidden; transition: transform .2s ease, visibility 0s linear .2s;
}
.pane-body.client-open .client-panel { transform: none; visibility: visible; transition: transform .2s ease; }
.client-panel-head {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: max(6px, env(safe-area-inset-top)) 8px 6px 16px;
}
.client-panel-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 16px 24px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}
.client-panel-body > :first-child { margin-top: 12px; }
.client-panel form { max-width: none; }

/* ---------- read-only role and owner-only links (classes of <body>, set by the server) ---------- */

body.readonly form[method="post"]:not([action="/logout"]):not([action="/sync/refresh"]) { display: none; }
body.no-owner .owner-only { display: none; }

/* ---------- the bottom tab bar ---------- */

#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); /* the home bar of an iPhone */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  view-transition-name: tabbar; /* stays in place while the page below it changes */
}

.tab {
  position: relative; flex: 1 1 0; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--tabbar-h);
  color: var(--muted); font-size: 11px; line-height: 1.1;
}
.tab:hover { text-decoration: none; color: var(--text); }
.tab[aria-current="page"] { color: var(--accent-strong); font-weight: 600; }
.tab .icon { width: 24px; height: 24px; }
.tab img { width: 26px; height: 26px; border-radius: 6px; opacity: .75; }
.tab[aria-current="page"] img { opacity: 1; outline: 2px solid var(--accent-strong); outline-offset: 1px; }

.count {
  position: absolute; top: 4px; left: calc(50% + 6px);
  min-width: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent-strong); color: #fff;
  font-size: 11px; font-weight: 600; line-height: 18px; text-align: center;
}
.count[hidden] { display: none; }

::view-transition-old(root), ::view-transition-new(root) { animation-duration: .15s; }

/* ---------- a computer: the tab bar becomes a narrow column on the left, the content takes the rest ---------- */

@media (min-width: 900px) {
  /* The tab bar is the left column of a grid and sticks to the top of the window with the height of the window, so it never
     ends where a long page ends (and, unlike `fixed`, it takes its own place: nothing to pad around). */
  body:has(#tabbar) { display: grid; grid-template-columns: var(--tabbar-w) minmax(0, 1fr); padding-bottom: 0; }
  body:has(#tabbar) > main { grid-column: 2; grid-row: 1; min-width: 0; }

  #tabbar {
    position: sticky; top: 0; bottom: auto; left: auto; right: auto;
    grid-column: 1; grid-row: 1; align-self: start;
    width: var(--tabbar-w);
    height: 100vh; height: 100dvh;
    flex-direction: column; justify-content: flex-start; gap: 4px;
    border-top: 0; border-right: 1px solid var(--line);
    padding: 12px 0 0;
  }
  .tab { flex: 0 0 auto; min-height: 64px; font-size: 12px; }
  .tab-more { order: -1; margin-bottom: 8px; }  /* the raven goes first, on top */
  .tab img { width: 32px; height: 32px; }
  .count { top: 6px; left: calc(50% + 8px); }

  main { padding: 24px 32px; }
  main.chats-main { padding: 0; }
  main.narrow { padding-top: 64px; }

  /* Two columns: the list (the column scrolls by itself, its search and chips stay on top) and the open chat beside it. */
  .chats-layout { display: grid; grid-template-columns: 360px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); align-items: start; height: 100vh; height: 100dvh; }
  .chats-layout.view-chat { height: 100vh; height: 100dvh; } /* no tab bar below on a computer: it overrides the phone's height */
  .chats-layout.view-list .chat-pane, .chats-layout.view-chat .chat-col { display: block; }
  .chat-col {
    position: sticky; top: 0; align-self: start;
    height: 100vh; height: 100dvh; overflow-y: auto; overscroll-behavior: contain;
    border-right: 1px solid var(--line);
  }
  .chat-back { display: none; }
  .msg { max-width: 60%; }
  .pending { max-width: 60%; }
  .client-panel {
    position: absolute; inset: 0 0 0 auto; z-index: 35; width: min(380px, 100%);
    border-left: 1px solid var(--line); box-shadow: -6px 0 24px rgba(0, 0, 0, .12);
    transform: translateX(100%);
  }
  .chat-top { padding-left: 14px; }
  .chip { padding: 0 12px; font-size: 15px; } /* the column is 360px wide: a little tighter, still one line (the rest scrolls) */
  .pane-empty { display: flex; align-items: center; justify-content: center; min-height: 60vh; }
  h1 { font-size: 26px; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px; }
}

@media (min-width: 1280px) {
  /* The panel is the third column: closed it takes no room. */
  .pane-body { grid-template-columns: minmax(0, 1fr) 0; }
  .pane-body.client-open { grid-template-columns: minmax(0, 1fr) 340px; }
  .client-panel { position: static; width: auto; min-width: 0; overflow: hidden; transform: none; box-shadow: none; z-index: auto; }
  .pane-body:not(.client-open) .client-panel { visibility: hidden; }
}

@media (min-width: 1500px) {
  .cards { grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); }
}
