/* ---------- design tokens ----------
   Warm neutral greys with a single clay accent (in the spirit of Claude).
   --bg      page / conversation background
   --bg-2    raised surfaces: sheets, menus, dialogs, the composer
   --bg-3    quiet fills: chips, pressed / selected rows
   --border  hairlines; --border-strong for inputs and focusable outlines */
:root {
  color-scheme: dark;
  --bg: #262624;
  --bg-2: #30302e;
  --bg-3: #3a3936;
  --sidebar-bg: #1f1e1d;
  --fg: #eeede8;
  --fg-2: #a6a39b;
  --fg-3: #7f7c75;
  --muted: var(--fg-2);
  --border: rgba(222, 220, 209, 0.11);
  --border-strong: rgba(222, 220, 209, 0.2);
  --accent: #d97757;
  --accent-2: #c4613f;
  --accent-fg: #ffffff;
  --accent-soft: rgba(217, 119, 87, 0.14);
  --user-bg: #3a3936;
  --assistant-bg: transparent;
  --error: #ec7a68;
  --ok: #74c08a;
  --warn: #e3ae55;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --pad: 12px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-sheet: 0 -10px 40px rgba(0, 0, 0, 0.45);
  --shadow-card: 0 16px 48px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(222, 220, 209, 0.06);
  --shadow-composer: 0 4px 24px rgba(0, 0, 0, 0.28);
  --code-bg: #1f1e1d;                       /* code blocks and tool output */
  --inline-bg: rgba(222, 220, 209, 0.09);   /* inline-code bg */
  --th-bg: rgba(222, 220, 209, 0.05);       /* table header bg */
  --hover-soft: rgba(222, 220, 209, 0.07);  /* generic hover wash */
  --hover-strong: rgba(222, 220, 209, 0.11);
  --backdrop: rgba(10, 10, 9, 0.6);
  --focus-ring: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, "Cascadia Code", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Light theme — same shape, inverted surfaces. Activated via
   <html data-theme="light"> from JS based on localStorage. */
[data-theme="light"] {
  color-scheme: light;
  --bg: #faf9f5;
  --bg-2: #ffffff;
  --bg-3: #efede6;
  --sidebar-bg: #f3f1ea;
  --fg: #1f1e1d;
  --fg-2: #6b6860;
  --fg-3: #95918a;
  --border: rgba(31, 30, 29, 0.1);
  --border-strong: rgba(31, 30, 29, 0.18);
  --accent: #c96442;
  --accent-2: #ad5232;
  --accent-soft: rgba(201, 100, 66, 0.1);
  --user-bg: #efede6;
  --error: #c2412d;
  --ok: #2e7d4a;
  --warn: #b7791f;
  --shadow-sm: 0 1px 2px rgba(31, 30, 29, 0.06);
  --shadow-sheet: 0 -10px 40px rgba(31, 30, 29, 0.12);
  --shadow-card: 0 16px 48px rgba(31, 30, 29, 0.12), 0 0 0 1px rgba(31, 30, 29, 0.06);
  --shadow-composer: 0 4px 20px rgba(31, 30, 29, 0.07);
  --code-bg: #f3f1ea;
  --inline-bg: rgba(31, 30, 29, 0.065);
  --th-bg: rgba(31, 30, 29, 0.035);
  --hover-soft: rgba(31, 30, 29, 0.045);
  --hover-strong: rgba(31, 30, 29, 0.08);
  --backdrop: rgba(31, 30, 29, 0.32);
}

* { box-sizing: border-box; }

/* Make sure HTML `hidden` attribute always wins over component `display:flex`
   etc. Without this, .lightbox / .sheet-backdrop with `hidden` attr but
   `display:flex` in CSS stay invisible-but-clickable, intercepting taps. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

::selection { background: color-mix(in srgb, var(--accent) 32%, transparent); }
:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 70%, transparent); outline-offset: 2px; }
/* Thin, unobtrusive scrollbars (desktop). */
* { scrollbar-width: thin; scrollbar-color: var(--hover-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--hover-strong); border-radius: 999px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

button { font: inherit; }
input, textarea, button { font: inherit; color: inherit; }

/* ---------- login ---------- */
.login-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom, 0px));
  background:
    radial-gradient(ellipse 70% 50% at 50% -10%, var(--accent-soft), transparent 70%),
    var(--bg);
}
.login-card {
  background: var(--bg-2);
  padding: 32px 28px 26px;
  border-radius: 18px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-card);
}
.login-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: 0 auto 16px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-fg);
}
.login-mark svg { width: 24px; height: 24px; }
.login-card h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-align: center;
}
.login-sub {
  margin: 6px 0 22px;
  color: var(--fg-2);
  font-size: 14px;
  text-align: center;
}
.login-card label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-2);
  margin: 14px 0 6px;
}
.login-card select,
.login-card input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--fg);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.login-card select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 36px;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23908c84' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") right 12px center / 16px no-repeat;
}
.login-card select:focus,
.login-card input:focus { border-color: var(--accent); box-shadow: var(--focus-ring); }
.login-card button {
  width: 100%;
  height: 44px;
  margin-top: 20px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.login-card button:hover { background: var(--accent-2); }
.login-card button:active { transform: scale(0.99); }
.login-card button:disabled { opacity: 0.6; cursor: default; }
.login-card .err {
  color: var(--error);
  font-size: 13px;
  margin-top: 10px;
  min-height: 18px;
  text-align: center;
}
/* Secondary action: PWA install offer. Sits under the error line, so it must
   not compete with the primary "Войти" button — outline instead of filled. */
.login-card #install-btn {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--fg-2);
  font-weight: 500;
  margin-top: 6px;
}
.login-card #install-btn:hover {
  background: var(--hover-soft);
  color: var(--fg);
}
.login-card .login-hint {
  font-size: 12px;
  color: var(--fg-2);
  text-align: center;
  margin-top: 12px;
  line-height: 1.4;
}
.login-foot { margin-top: 18px; font-size: 12px; color: var(--fg-3); }
/* `hidden` must win over the rules above, which set display-affecting props. */
.login-card [hidden] { display: none; }

/* ---------- chat layout ---------- */
.app {
  display: flex;
  flex-direction: column;
  /* Three layers, last one wins on supporting browsers:
     1. 100vh — old browsers, no keyboard awareness
     2. 100dvh — modern: shrinks with URL bar, also with keyboard on Chrome
        Android (via interactive-widget=resizes-content in viewport meta)
     3. 100dvh - --kbd-inset — covers iOS Safari, where dvh ignores keyboard.
        --kbd-inset is set by the VisualViewport tracker in app.js. */
  height: 100vh;
  height: 100dvh;
  height: calc(100dvh - var(--kbd-inset, 0px));
  /* Desktop «Масштаб интерфейса» is CSS zoom, which shrinks dvh with the
     rest: divide it back so the app still fills the window. */
  height: calc((100dvh - var(--kbd-inset, 0px)) / var(--ui-zoom, 1));
  /* Belt-and-braces: if anything inside grows beyond viewport, clip it
     internally rather than push the composer below the fold. */
  overflow: hidden;
  position: relative;
}
.app.drag-over::after, .fe-overlay.fe-drop::after {
  content: "Отпустите — файл прикрепится к сообщению";
  position: absolute;
  inset: 10px;
  background: color-mix(in srgb, var(--accent) 10%, var(--bg));
  border: 1.5px dashed var(--accent);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 600;
  color: var(--accent);
  pointer-events: none;
  z-index: 100;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 52px;
  padding: 8px 12px;
  /* Push the topbar down past the iOS notch / Dynamic Island when running
     as a standalone PWA. Falls back to the regular padding everywhere else. */
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  padding-left: calc(12px + env(safe-area-inset-left, 0px));
  padding-right: calc(12px + env(safe-area-inset-right, 0px));
  background: var(--bg);
  border-bottom: 1px solid transparent;
  /* Hard-pin: never let flex shrink the topbar to nothing if the chat tries
     to grow above its share. Same fix on .composer below. */
  flex-shrink: 0;
  position: relative;
  z-index: 5;
}
.topbar .who {
  flex: 0 0 auto;
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 30vw;
  padding: 0 4px;
}

/* Project chip — shows current project name; click opens projects sheet.
   Sits between the user name and the bell, takes the leftover horizontal
   space so the project label can stretch on wider screens. */
.project-chip {
  flex: 1 1 auto;
  min-width: 0;
  height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--fg);
  border-radius: 10px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.project-chip:hover { background: var(--hover-soft); }
.project-chip:active { background: var(--hover-strong); }
.project-chip .icon { width: 16px; height: 16px; flex: 0 0 auto; color: var(--fg-2); }
.project-chip-name {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}
.project-chip-caret { width: 14px !important; height: 14px !important; opacity: 0.7; }
/* Thread chip — current conversation inside the project. Project and thread
   chips hug their names (caret right after the text) and shrink together,
   so neither collapses to "О…" on a phone; the limits ring is pushed right. */
.project-chip, .thread-chip { flex: 0 1 auto; max-width: 300px; }
.topbar .usage-btn { margin-left: auto; }
.thread-chip-badge {
  flex: 0 0 auto;
  min-width: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
}

/* Threads sheet: grouped list with status badges and result previews. */
.thread-group-title {
  margin: 14px 2px 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-2);
}
.thread-group-title:first-child { margin-top: 0; }
.thread-group-toggle {
  display: flex; align-items: center; gap: 6px;
  width: 100%; padding: 0; border: 0; background: none; cursor: pointer;
  font: inherit; text-transform: inherit; letter-spacing: inherit; color: inherit;
}
.thread-item-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.thread-item-head .project-item-name {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.thread-item-meta { font-size: 12px; color: var(--fg-2); margin-top: 3px; }
.thread-item-result {
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--fg-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.thread-status {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: 5px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--bg-3);
  color: var(--fg-2);
}
.thread-status::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor;
}
.thread-status.running { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.thread-status.running::before { animation: thread-pulse 1.2s ease-in-out infinite; }
.thread-status.done { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.thread-status.error { color: var(--error); background: color-mix(in srgb, var(--error) 12%, transparent); }
@keyframes thread-pulse { 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) {
  .thread-status.running::before { animation: none; }
}
.project-item.closed { opacity: 0.6; }

/* Note in the main chat: a thread started by the main session finished. */
.msg.system.thread-note {
  display: flex; align-items: center; gap: 10px;
  max-width: min(520px, 92%);
  padding: 8px 8px 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-2);
  color: var(--fg);
  white-space: normal;
}
.thread-note-icon { width: 16px; height: 16px; flex: 0 0 auto; }
.thread-note.done .thread-note-icon { color: var(--ok); }
.thread-note.error .thread-note-icon { color: var(--error); }
.thread-note-open {
  flex: 0 0 auto;
  padding: 4px 10px;
  border: 0;
  border-radius: 999px;
  background: var(--bg-3);
  color: var(--accent);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.thread-note-open:hover { background: var(--hover-soft); }

/* Author label (shared projects, tasks from the main session). */
.msg-author {
  display: block;
  margin-bottom: 2px;
  font-size: 12px;
  font-weight: 600;
  opacity: 0.75;
}

/* Projects list inside the projects sheet. Each row: name + meta + edit/delete. */
.project-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 6px;
  transition: background 0.12s, border-color 0.12s;
}
.project-item.current { border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: var(--accent-soft); }
.project-item-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: transparent;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  padding: 0;
}
.project-item-name { font-weight: 500; font-size: 15px; }
.project-item.current .project-item-name { color: var(--accent); }
.project-item-desc { font-size: 13px; color: var(--fg-2); }
.project-item-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.project-action-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  background: transparent;
  border: 0;
  color: var(--fg-2);
  padding: 0;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.project-action-btn:hover { background: var(--hover-strong); color: var(--fg); }
.project-action-btn.danger:hover { color: var(--error); background: color-mix(in srgb, var(--error) 12%, transparent); }
.project-action-btn .icon { width: 16px; height: 16px; vertical-align: middle; }

/* Share sheet — two big action cards on top, list of existing shares below. */
.share-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 18px;
}
.share-action-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.share-action-card:hover { border-color: var(--accent); }
.share-action-card .icon { width: 20px; height: 20px; color: var(--accent); flex: 0 0 auto; }
.share-action-title { font-size: 15px; font-weight: 600; }
.share-action-sub { font-size: 13px; color: var(--fg-2); margin-top: 2px; }

.share-list-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
  padding: 0 4px;
}
.share-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 8px;
}
.share-item-main {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  padding: 0;
}
.share-item-title {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.share-item-meta { font-size: 12px; color: var(--fg-2); margin-top: 2px; }
.share-item-views {
  font-size: 12px;
  color: var(--accent);
  margin-top: 4px;
  font-weight: 500;
}
.share-item-views.zero { color: var(--fg-2); font-weight: 400; font-style: italic; }
.share-item-actions {
  display: flex;
  flex-shrink: 0;
  align-items: center;
}
/* Explicit "Revoke" button — text + icon, red on hover so it's obvious that
   the action invalidates the public link. The previous trash-icon-only
   variant looked too much like a generic delete and went unnoticed. */
.share-revoke-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-2);
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
}
.share-revoke-btn:hover {
  background: var(--error);
  color: white;
  border-color: var(--error);
}
.share-revoke-btn .icon { width: 14px; height: 14px; }

/* Lock icon prefix in share titles (password-protected shares) */
.share-lock-icon {
  width: 14px; height: 14px;
  vertical-align: -2px;
  color: var(--accent);
  margin-right: 4px;
}

/* Password warning note in the share-result modal */
.share-pw-note {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: 8px;
  margin: 6px 0 10px;
  line-height: 1.4;
}
.share-pw-note .icon {
  width: 16px; height: 16px;
  flex: 0 0 auto;
  color: var(--accent);
  margin-top: 1px;
}

/* Form fields inside modals (used by share-create modal) */
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-2);
  margin: 12px 0 4px;
}
.form-input {
  display: block;
  width: 100%;
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  outline: none;
  box-sizing: border-box;
}
.form-input:focus { border-color: var(--accent); }

/* Knowledge base panel — file/folder tree of <project>/knowledge + uploads */
.kb-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.kb-summary-tile {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.kb-summary-label {
  font-size: 11px;
  color: var(--fg-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.kb-summary-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--fg);
  margin-top: 2px;
}
.kb-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 14px 0 6px;
  padding: 0 4px;
}
.kb-empty {
  padding: 12px 14px;
  color: var(--fg-2);
  font-style: italic;
  font-size: 13px;
}
.kb-tree { display: flex; flex-direction: column; gap: 2px; }
.kb-node {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  background: transparent;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  width: 100%;
}
.kb-node:hover { background: var(--bg-3); }
.kb-node .kb-icon { width: 16px; height: 16px; flex: 0 0 auto; color: var(--fg-2); }
.kb-node-name {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kb-node-meta {
  font-size: 11px;
  color: var(--fg-2);
  flex-shrink: 0;
}
.kb-node.dir .kb-icon { color: var(--accent); }
.kb-node.dir .chevron {
  width: 14px; height: 14px;
  transition: transform 0.15s;
  color: var(--fg-2);
  flex: 0 0 auto;
}
.kb-node.expanded .chevron { transform: rotate(90deg); }
.kb-children {
  padding-left: 22px;
  border-left: 1px solid var(--border);
  margin-left: 13px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 2px;
}
.kb-children.collapsed { display: none; }
.kb-node.special {
  border: 1px dashed var(--border-strong);
  background: color-mix(in srgb, var(--accent) 5%, transparent);
}
.kb-node.special .kb-icon { color: var(--accent); }

/* Inline file viewer (for tapping a markdown/text file in the tree) */
.kb-viewer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 320;
  display: flex;
  flex-direction: column;
  padding: 24px 12px;
}
.kb-viewer-card {
  background: var(--bg-2);
  border-radius: 14px;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}
.kb-viewer-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.kb-viewer-title {
  flex: 1;
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kb-viewer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  font-size: 14px;
  line-height: 1.55;
}
.kb-viewer-body pre {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  font: inherit;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
}

/* Security panel — admin-only view of blocked IPs and recent login attempts */
.sec-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 14px 0 8px;
  padding: 0 4px;
}
.sec-section-title:first-child { margin-top: 0; }
.sec-block {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 6px;
}
.sec-block.blocked { border-color: var(--error); background: color-mix(in srgb, var(--error) 6%, transparent); }
.sec-block-info { flex: 1; min-width: 0; }
.sec-block-ip {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
}
.sec-block-meta { font-size: 12px; color: var(--fg-2); margin-top: 2px; }
.sec-block-source {
  display: inline-block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  background: var(--bg-3);
  border-radius: 4px;
  margin-right: 4px;
  vertical-align: middle;
}
.sec-block-source.app { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.sec-block-source.f2b { background: color-mix(in srgb, var(--error) 18%, transparent); color: var(--error); }
.sec-unblock-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-2);
  padding: 6px 10px;
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  flex-shrink: 0;
}
.sec-unblock-btn:hover { background: var(--accent); color: white; border-color: var(--accent); }
.sec-empty {
  padding: 12px 14px;
  color: var(--fg-2);
  font-style: italic;
  font-size: 13px;
}
.sec-hint {
  padding: 10px 12px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: 8px;
  font-size: 12px;
  color: var(--fg-2);
  margin-bottom: 6px;
  line-height: 1.45;
}
.sec-attempt {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 4px;
  font-size: 13px;
}
.sec-attempt.fail { border-left: 3px solid var(--error); }
.sec-attempt.ok { border-left: 3px solid var(--ok); }
.sec-attempt-line { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.sec-attempt-ip { font-family: var(--mono); font-weight: 600; }
.sec-attempt-user { color: var(--fg-2); font-size: 12px; }
.sec-attempt-time { color: var(--fg-2); font-size: 11px; white-space: nowrap; }
.sec-thresholds {
  font-size: 11px;
  color: var(--fg-2);
  padding: 8px 12px;
  text-align: center;
  margin-top: 8px;
  font-style: italic;
}

/* Selection-mode top bar — slides in above the chat when user taps
   "Выбрать сообщения". Replaces the topbar visually so it can't be missed. */
.selection-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--accent);
  color: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.selection-bar .selection-count { flex: 1; font-weight: 600; font-size: 14px; }
.selection-bar button {
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.3);
  color: inherit;
  font: inherit;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.selection-bar button:hover:not(:disabled) { background: rgba(255,255,255,0.28); }
.selection-bar button:disabled { opacity: 0.4; cursor: not-allowed; }
.selection-bar .selection-confirm { font-weight: 600; }

/* When selection mode is active, every chat message becomes a tap target
   with a small checkbox marker. Selected ones get an accent ring. */
.app.selecting .msg.user,
.app.selecting .msg.assistant {
  cursor: pointer;
  position: relative;
  padding-right: 36px;
}
.app.selecting .msg.user::after,
.app.selecting .msg.assistant::after {
  content: "";
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  border: 2px solid var(--fg-2);
  border-radius: 50%;
  background: var(--bg);
  box-sizing: border-box;
}
.app.selecting .msg.selected { outline: 2px solid var(--accent); outline-offset: 2px; }
.app.selecting .msg.selected::after {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: inset 0 0 0 4px var(--bg);
}
/* In selection mode disable interactive children of messages so taps select
   instead of triggering a link/image lightbox. */
.app.selecting .msg a,
.app.selecting .msg img,
.app.selecting .msg button { pointer-events: none; }

/* Result modal (after creating a share) — same look as skill share modal,
   but with a copy-link affordance. */
.share-result-url {
  display: flex;
  gap: 6px;
  align-items: stretch;
  margin: 12px 0;
}
.share-result-url input {
  flex: 1;
  padding: 10px 12px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  font: inherit;
  font-size: 13px;
}
.share-result-url button {
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}
.share-result-url button:hover { filter: brightness(1.1); }
.share-result-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.share-result-actions button {
  flex: 1;
  padding: 10px;
  background: var(--bg-3);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}
.share-result-actions button:hover { background: var(--bg); }

/* Star button on each chat message — sits at top-right corner. Hidden until
   hover/touch on desktop; on touch screens it's always visible (faded). */
.msg { position: relative; }

/* Swipe-to-reply: drag a message left, release past threshold → quote into composer.
   Implementation: JS sets inline transform on .msg during touchmove + shows a
   shared .swipe-reply-indicator element at the bubble's vertical center.

   `touch-action: pan-y` is the key bit — it tells the browser "this bubble
   only pans vertically natively; horizontal touches aren't scroll, hand them
   to JS". That lets us register touchmove as passive (no `preventDefault`),
   which keeps iOS's vertical scroll buttery instead of janky. */
.msg.user,
.msg.assistant { touch-action: pan-y; }
.msg.swiping { transition: none; will-change: transform; }
.msg.swipe-snap { transition: transform 0.22s cubic-bezier(0.2, 0.7, 0.3, 1); }

.swipe-reply-indicator {
  position: fixed;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 20px;
  pointer-events: none;
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 0.08s linear, transform 0.08s ease-out;
  z-index: 250;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.swipe-reply-indicator.visible {
  opacity: var(--progress, 0.5);
  transform: scale(calc(0.7 + 0.3 * var(--progress, 0)));
}
.swipe-reply-indicator.triggered {
  opacity: 1 !important;
  transform: scale(1.15) !important;
}
/* Message toolbar (copy · star · more): a small pill floating on the bubble's
   bottom edge, so it never covers text. Mouse — appears on hover; touch —
   only "⋯" (and a set star) stay visible. */
.msg-actions {
  position: absolute;
  right: 10px;
  bottom: -13px;
  z-index: 2;
  display: flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-2);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  -webkit-user-select: none;
  user-select: none;
}
/* (a user's bubble sits on the right: its bar grows to the left, inside the
   chat — anchored left it stuck out past the chat's edge and gave it a
   horizontal scroll, even while hidden) */
.msg:hover .msg-actions, .msg-actions:focus-within { opacity: 1; pointer-events: auto; }
.msg-act {
  display: grid; place-items: center;
  width: 26px; height: 22px; padding: 0;
  border: 0; border-radius: 999px;
  background: none; color: var(--fg-2); cursor: pointer;
}
.msg-act:hover { color: var(--fg); background: var(--bg-3); }
.msg-act .icon { width: 14px; height: 14px; display: block; }
.msg-star.starred { color: var(--accent); }
/* Messages get room below so the toolbar doesn't touch the next bubble. */
.msg.user, .msg.assistant { margin-bottom: 8px; }
@media (hover: none) {
  .msg-actions { opacity: 1; pointer-events: auto; box-shadow: none; }
  .msg-actions .msg-copy, .msg-actions .msg-star:not(.starred) { display: none; }
  .msg-act { color: var(--fg-2); opacity: 0.7; }
}
.msg.system .msg-actions, .msg.error .msg-actions, .typing .msg-actions,
.app.selecting .msg-actions { display: none; }

/* Tiny toast popup (used after starring + other ephemeral confirmations) */
.toast {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--fg);
  color: var(--bg);
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,0.22);
  opacity: 0;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 200;
  pointer-events: none;
  max-width: 80vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.show.clickable { pointer-events: auto; cursor: pointer; }

/* Bookmark items in the bookmarks sheet */
.bookmark-item {
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 8px;
}
.bookmark-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--fg-2);
  margin-bottom: 6px;
}
.bookmark-role {
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.bookmark-content {
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
  overflow: hidden;
  position: relative;
}
.bookmark-content.expanded { max-height: none; }
.bookmark-content::after {
  content: "";
  position: absolute;
  bottom: 0; left: 0; right: 0; height: 32px;
  background: linear-gradient(to bottom, transparent, var(--bg));
  pointer-events: none;
}
.bookmark-content.expanded::after { display: none; }
.bookmark-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.bookmark-actions button {
  padding: 4px 10px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-2);
  border-radius: 6px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.bookmark-actions button:hover { background: var(--bg-3); color: var(--fg); }
.bookmark-actions button.danger:hover { color: var(--error); border-color: var(--error); }

/* Date filter row inside the search sheet — sticks below the search input */
.search-filters {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 8px 14px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}
.search-date-row {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--fg-2);
}
.search-date-row input[type="date"] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 4px 6px;
  border-radius: 6px;
  font: inherit;
  font-size: 12px;
  color-scheme: dark light;
}
.search-quick, .search-clear {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg-2);
  padding: 4px 8px;
  border-radius: 999px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.search-quick:hover, .search-clear:hover { border-color: var(--accent); color: var(--fg); }
.search-quick.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.search-clear { margin-left: auto; }

/* Stats sheet — tile grid + bar chart for last 30 days */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}
.stats-tile {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}
.stats-tile-value { font-size: 22px; font-weight: 700; color: var(--accent); }
.stats-tile-label { font-size: 12px; color: var(--fg-2); margin-top: 2px; }
.stats-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 16px 0 8px;
  padding: 0 4px;
}
.stats-chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 100px;
  padding: 8px 4px 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.stats-bar {
  flex: 1;
  min-height: 2px;
  background: var(--accent);
  opacity: 0.5;
  border-radius: 2px 2px 0 0;
  position: relative;
}
.stats-bar:hover { opacity: 1; }
.stats-bar[data-count="0"] { background: var(--bg-3); opacity: 1; }
.stats-chart-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--fg-2);
  margin-top: 4px;
  padding: 0 4px;
}
.stats-project-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 6px;
  font-size: 14px;
}
.stats-project-name { font-weight: 600; }
.stats-project-meta { color: var(--fg-2); font-size: 12px; }

/* Admin-only: per-user comparison cards inside the stats sheet */
.admin-user-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.admin-user-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}
.admin-user-name { font-weight: 600; font-size: 15px; }
.admin-user-last { color: var(--fg-2); font-size: 12px; }
.admin-user-bar {
  position: relative;
  height: 22px;
  background: var(--bg-3);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 10px;
}
.admin-user-bar-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 60%, transparent));
  border-radius: 6px;
  transition: width 0.3s ease-out;
}
.admin-user-bar-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: white;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
.admin-user-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px 10px;
}
.admin-user-grid > div {
  text-align: center;
  padding: 4px 0;
}
.admin-user-num {
  display: block;
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
}
.admin-user-lbl {
  display: block;
  font-size: 11px;
  color: var(--fg-2);
  text-transform: lowercase;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  background: transparent;
  border: none;
  color: var(--fg-2);
  cursor: pointer;
  padding: 0 8px;
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--hover-soft); color: var(--fg); }
.icon-btn:active { background: var(--hover-strong); }
/* Close-x in the sheet header is a single tall char — make it visually balanced */
.sheet-header .icon-btn { font-size: 22px; line-height: 1; padding: 0; width: 32px; min-width: 32px; height: 32px; border-radius: 8px; font-weight: 300; }
.icon-btn.active { background: var(--hover-strong); color: var(--accent); }

/* Bell button with notification badge — iOS-style small dot at top-right corner */
.bell-btn { position: relative; }
.bell-btn .icon { width: 19px; height: 19px; }
.bell-btn .badge {
  position: absolute;
  top: 5px;
  right: 5px;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  background: var(--error);
  color: white;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  line-height: 14px;
  text-align: center;
  border: 2px solid var(--bg);
  box-sizing: content-box;
  pointer-events: none;
  animation: badge-pop 0.25s ease-out;
  transform: translate(30%, -30%);  /* sits half-outside the icon's top-right corner */
}
@keyframes badge-pop {
  0%   { transform: scale(0); }
  60%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* News items inside news sheet */
.news-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  position: relative;
}
.news-item.unread { border-color: var(--accent); }
.news-item.unread::before {
  content: "";
  position: absolute;
  top: 14px;
  left: -5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--bg-2);
}
.news-meta {
  font-size: 12px;
  color: var(--fg-2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.news-title { font-weight: 600; font-size: 15px; }
.news-body { font-size: 14px; line-height: 1.5; color: var(--fg); white-space: pre-line; }

/* Lucide-derived inline SVG icons (referenced via <use href="#i-*"/>) */
.icon {
  width: 18px;
  height: 18px;
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}
.dd-icon.icon { width: 17px; height: 17px; color: var(--fg-2); }
.dropdown-item:hover .dd-icon.icon { color: var(--fg); }
.dropdown-item.active .dd-icon.icon { color: var(--accent); }
.dropdown-item.dd-danger:hover .dd-icon.icon { color: var(--error); }

/* Hamburger menu button (3 stacked lines) */
.menu-toggle { padding: 0 9px; }
.hamburger,
.hamburger::before,
.hamburger::after {
  display: block;
  width: 18px;
  height: 1.75px;
  background: currentColor;
  border-radius: 2px;
  transition: transform 0.18s, opacity 0.18s;
}
.hamburger { position: relative; }
.hamburger::before,
.hamburger::after { content: ""; position: absolute; left: 0; }
.hamburger::before { top: -5.5px; }
.hamburger::after  { top: 5.5px; }
.menu-toggle[aria-expanded="true"] .hamburger { background: transparent; }
.menu-toggle[aria-expanded="true"] .hamburger::before { transform: translateY(5.5px) rotate(45deg); }
.menu-toggle[aria-expanded="true"] .hamburger::after  { transform: translateY(-5.5px) rotate(-45deg); }

/* Dropdown menu — pinned to the VIEWPORT (position: fixed), just under the
   topbar, right-aligned. `fixed` (not `absolute`) so it can't be clipped by
   `.app { overflow: hidden }` and doesn't shift when the chat is scrolled or
   the layout grows. `top` includes the iOS safe-area inset so it follows the
   topbar down past the notch / Dynamic Island in standalone PWA mode. The
   max-height + scroll keep a long menu reachable on short screens. */
.dropdown {
  position: fixed;
  top: calc(54px + env(safe-area-inset-top, 0px));
  right: 10px;
  min-width: 248px;
  max-height: calc(100dvh - 54px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 12px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-card);
  padding: 6px;
  z-index: 320;
  opacity: 0;
  transform: translateY(-4px) scale(0.98);
  transform-origin: top right;
  transition: opacity 0.14s ease-out, transform 0.16s var(--ease);
}
.dropdown.open { opacity: 1; transform: translateY(0) scale(1); }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 36px;
  background: transparent;
  border: none;
  color: var(--fg);
  text-align: left;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}
.dropdown-item:hover { background: var(--hover-soft); }
.dropdown-item:active { background: var(--hover-strong); }
.dropdown-item .dd-icon {
  flex-shrink: 0;
}
.dropdown-item .dd-label { flex: 1; font-size: 14px; }
.dropdown-item .dd-state {
  font-size: 12px;
  color: var(--fg-2);
  background: var(--bg-3);
  padding: 1px 8px;
  border-radius: 999px;
}
.dropdown-item.active .dd-state { background: var(--accent-soft); color: var(--accent); }
.dropdown-item.dd-danger:hover { background: color-mix(in srgb, var(--error) 10%, transparent); color: var(--error); }
.dropdown-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 6px 4px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.chat {
  flex: 1;
  /* Without min-height:0 a flex item's min size is its content height, so
     with many messages .chat refuses to shrink, overflows .app (which is
     `overflow:hidden`) and pushes the composer / shifts the layout off
     screen. This pins it so the chat scrolls internally instead. */
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 12px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  /* No scroll-behavior: smooth here — it turned every scrollTop = … into an
     animation: opening a long session rode visibly through the history and
     stopped short of the end. Smooth only where asked (the «вниз» button). */
}

/* Empty conversation (app.js tags the "пока пусто" note): a quiet greeting
   centred in the column instead of a lone grey line at the top. */
.chat > .msg.system.chat-empty-note:only-child {
  margin: auto;
  padding: 0 16px 10vh;
  max-width: 440px;
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
  color: var(--fg-2);
  animation: fadeIn 0.3s ease-out;
}
.chat > .msg.system.chat-empty-note:only-child::before {
  content: "Чем займёмся?";
  display: block;
  margin-bottom: 8px;
  font-size: 28px;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--fg);
}

.msg {
  max-width: min(720px, 88%);
  padding: 10px 14px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.55;
}

/* Markdown rendered inside assistant messages */
.msg.assistant { white-space: normal; font-size: calc(15.5px * var(--text-k, 1)); line-height: 1.65; }
.msg.assistant > *:first-child { margin-top: 0; }
.msg.assistant > *:last-child { margin-bottom: 0; }
.msg.assistant p { margin: 0 0 12px; }
.msg.assistant ul,
.msg.assistant ol { margin: 4px 0 12px; padding-left: 24px; }
.msg.assistant li { margin: 4px 0; }
.msg.assistant li::marker { color: var(--fg-2); }
.msg.assistant li > p { margin: 0; }
.msg.assistant h1,
.msg.assistant h2,
.msg.assistant h3,
.msg.assistant h4 {
  margin: 20px 0 8px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
}
.msg.assistant h1 { font-size: 1.35em; }
.msg.assistant h2 { font-size: 1.2em; }
.msg.assistant h3 { font-size: 1.05em; }
.msg.assistant h4 { font-size: 1em; }
.msg.assistant a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
  text-underline-offset: 2px;
  word-break: break-word;
}
.msg.assistant a:hover { color: var(--accent-2); }
.msg.assistant strong { font-weight: 600; }
.msg.assistant em { font-style: italic; }
.msg.assistant code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--inline-bg);
  padding: 0.12em 0.38em;
  border-radius: 5px;
}
.msg.assistant pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  padding: 12px 14px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 8px 0 14px;
  font-size: 0.86em;
  line-height: 1.5;
}
.msg.assistant pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
}
.msg.assistant blockquote {
  margin: 6px 0 10px;
  padding: 4px 12px;
  border-left: 3px solid var(--border-strong);
  color: var(--fg-2);
}
.msg.assistant hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}
.msg.assistant table {
  border-collapse: collapse;
  margin: 6px 0 10px;
  font-size: 0.95em;
  display: block;
  overflow-x: auto;
}
.msg.assistant th,
.msg.assistant td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.msg.assistant th { background: var(--th-bg); font-weight: 600; }

/* Inline images served from /api/file */
.msg.assistant img.inline-attachment {
  display: block;
  max-width: 100%;
  max-height: 60vh;
  border-radius: 10px;
  margin: 6px 0;
  background: var(--bg);
  cursor: zoom-in;
  transition: opacity 0.15s;
}
.msg.assistant img.inline-attachment:hover { opacity: 0.92; }

/* Download links to non-image files (PDF, MD, ZIP, etc.) */
.msg.assistant a.file-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  margin: 4px 4px 4px 0;
  background: var(--bg-3);
  border-radius: 10px;
  text-decoration: none;
  color: var(--fg);
  font-size: 14px;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.msg.assistant a.file-link:hover {
  background: var(--bg-2);
  border-color: var(--accent);
  color: var(--accent);
}
.msg.assistant a.file-link .icon { width: 18px; height: 18px; }

/* ---------- ask-form (interactive structured questions) ---------- */
.ask-block {
  align-self: flex-start;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 4px 0;
  max-width: min(720px, 88%);
}
.ask-form { display: flex; flex-direction: column; gap: 10px; }
.ask-question { font-weight: 600; margin-bottom: 4px; }
.ask-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.ask-option:hover { background: var(--bg-3); }
.ask-option input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.ask-option span { flex: 1; }
.ask-option:has(input:checked) {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.ask-text {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 10px 12px;
  border-radius: 10px;
  font: inherit;
  resize: none;
  min-height: 44px;
  outline: none;
}
.ask-text:focus { border-color: var(--accent); }
.ask-submit {
  align-self: flex-end;
  padding: 8px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}
.ask-submit:hover { background: var(--accent-2); }
.ask-submit:disabled { opacity: 0.5; cursor: not-allowed; }
.ask-block.ask-answered {
  opacity: 0.6;
  pointer-events: none;
}
/* answered (on submit or by «Выбрал: …» after it, app.js markAskAnswered):
   the pick stays, the rest fades, no button */
.ask-block.ask-answered .ask-option:not(:has(input:checked)) { opacity: 0.5; }
.ask-block.ask-answered .ask-submit,
.ask-block.ask-answered .ask-text:placeholder-shown { display: none; }

/* ---------- skills panel (bottom sheet) ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: var(--backdrop);
  z-index: 200;
  animation: fadeIn 0.2s ease-out;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  /* When on-screen keyboard is up, --kbd-inset (set by the virtual-keyboard /
     visual-viewport tracker in app.js) lifts the sheet so its content sits
     above the keyboard rather than under it. The tracker bakes in a small
     breathing-room buffer when the keyboard is open (Samsung's suggestion-bar
     is occasionally mis-measured by VisualViewport — the buffer hides this). */
  bottom: var(--kbd-inset, 0px);
  /* Cap height so sheet always fits in the visible area: 85% of viewport
     normally, but never larger than what's free above the keyboard. */
  max-height: min(85vh, calc(100vh - var(--kbd-inset, 0px) - 40px));
  background: var(--bg-2);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  z-index: 210;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.28s var(--ease);
  box-shadow: var(--shadow-sheet);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
/* Grab handle — a visual hint that this is a bottom sheet (phones only). */
.sheet::before {
  content: "";
  position: absolute;
  top: 6px;
  left: 50%;
  width: 36px;
  height: 4px;
  margin-left: -18px;
  border-radius: 999px;
  background: var(--border-strong);
}
.sheet.open { transform: translateY(0); }
/* Rows, cards and fields inside a sheet paint themselves with var(--bg);
   here that becomes a faint wash over the sheet surface (grouped-list look)
   rather than the page colour punched through it. */
.sheet { --bg: var(--hover-soft); }
.sheet-header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 14px 12px 10px 20px;
  border-bottom: 1px solid var(--border);
}
.sheet-title { flex: 1; font-weight: 600; font-size: 16px; letter-spacing: -0.005em; }
.sheet-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sheet-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.btn-primary {
  flex: 1;
  min-width: 180px;
  min-height: 42px;
  padding: 10px 16px;
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14.5px;
  transition: background 0.15s, transform 0.1s;
}
.btn-primary:hover { background: var(--accent-2); }
.btn-primary:active { transform: scale(0.99); }
.btn-primary:disabled { opacity: 0.55; cursor: default; }

/* Wide screens: sheets become centred dialogs instead of bottom sheets. */
@media (min-width: 760px) {
  .sheet {
    left: 50%;
    right: auto;
    top: 50%;
    bottom: auto;
    width: min(640px, calc(100vw - 48px));
    max-height: min(80vh, 760px);
    border-radius: 16px;
    padding-bottom: 0;
    box-shadow: var(--shadow-card);
    opacity: 0;
    transform: translate(-50%, -48%) scale(0.98);
    transition: opacity 0.16s ease-out, transform 0.2s var(--ease);
  }
  .sheet.open { opacity: 1; transform: translate(-50%, -50%); }
  .sheet::before { display: none; }
  .sheet-header { padding: 12px 12px 12px 20px; }
  .sheet-body { padding: 16px 20px; }
  .sheet-footer { padding: 12px 20px; }
}

.skill-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--fg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.skill-use-area {
  text-align: left;
  background: transparent;
  border: none;
  color: inherit;
  padding: 12px 14px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: inherit;
}
.skill-use-area:hover { background: var(--bg-3); }
.skill-title { font-weight: 600; font-size: 15px; }
.skill-desc { font-size: 13px; color: var(--fg-2); line-height: 1.4; }
.skill-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 14px 8px;
}
.skill-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-3);
  color: var(--fg-2);
}
.skill-tag-incoming { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.skill-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 10px 10px;
  border-top: 1px solid var(--border);
}
.skill-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: var(--bg-3);
  border: none;
  border-radius: 999px;
  color: var(--fg);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
.skill-action-btn:hover { background: var(--accent); color: white; }
.skill-action-btn .icon { width: 14px; height: 14px; }
.skill-action-revoke { background: transparent; color: var(--fg-2); }
.skill-action-revoke:hover { background: var(--error); color: white; }
.skill-action-delete { background: transparent; color: var(--fg-2); }
.skill-action-delete:hover { background: var(--error); color: white; }

/* Modal (used by share dialog) */
.modal-backdrop {
  position: fixed; inset: 0;
  background: var(--backdrop);
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  animation: fadeIn 0.15s;
}
.modal-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-card);
}
.modal-title { font-weight: 600; font-size: 16px; }
.modal-sub { padding: 0; }
.modal-list { display: flex; flex-direction: column; gap: 6px; }
.modal-choice {
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--fg);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.modal-choice:hover:not(:disabled) { background: var(--hover-soft); border-color: var(--border-strong); }
.modal-cancel {
  background: transparent;
  border: none;
  color: var(--fg-2);
  cursor: pointer;
  padding: 8px;
  font-size: 14px;
  font-family: inherit;
}
.modal-cancel:hover { color: var(--fg); }

.muted {
  color: var(--fg-2);
  font-size: 14px;
  text-align: center;
  padding: 20px;
}

/* ---------- settings panel ---------- */
.settings-group { margin-bottom: 18px; }
.settings-group-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--fg-2);
  margin: 4px 4px 8px;
}
/* iOS-style toggle (checkbox + sliding circle) */
.toggle-row {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 14px;
}
.toggle-row .toggle-label { flex: 1; }
.toggle-row input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.toggle-switch {
  position: relative;
  width: 42px;
  height: 24px;
  background: color-mix(in srgb, var(--fg) 20%, transparent);
  border-radius: 999px;
  transition: background 0.18s;
  flex-shrink: 0;
}
.toggle-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  transition: transform 0.18s;
}
.toggle-row input:checked + .toggle-switch {
  background: var(--accent);
}
.toggle-row input:checked + .toggle-switch::after {
  transform: translateX(18px);
}
.muted-note {
  font-size: 12px;
  color: var(--fg-2);
  padding: 6px 14px 0;
  line-height: 1.4;
}
/* Notification sounds (notify.js): a select and a ▶ preview per event kind. */
.ntf-sound-head {
  font-size: 13px; font-weight: 600; color: var(--fg);
  margin: 14px 4px 6px;
}
.ntf-sound-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px 8px 14px; margin-bottom: 6px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  font-size: 14px;
}
.ntf-sound-label { flex: 1; min-width: 0; }
.ntf-sound-select {
  flex: 0 1 170px; min-width: 0;
  padding: 7px 10px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--bg-2); color: var(--fg);
  font: inherit; font-size: 14px; cursor: pointer;
}
.ntf-sound-select:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.ntf-sound-play {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); background: var(--accent-soft); color: var(--accent);
  cursor: pointer; transition: background 0.15s, color 0.15s;
}
.ntf-sound-play svg { width: 14px; height: 14px; margin-left: 2px; }
.ntf-sound-play:hover { background: var(--accent); color: var(--accent-fg); }
.ntf-sound-play:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.ntf-sound-note b { color: var(--fg); font-weight: 600; }
.version-row {
  text-align: center;
  padding: 14px 14px 4px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.4px;
  opacity: 0.7;
  border-top: 1px solid var(--border);
  margin-top: 18px;
}

.theme-list { display: flex; gap: 10px; }
.theme-row {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
}
.theme-row:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.theme-row input[type="radio"] {
  width: 18px; height: 18px; accent-color: var(--accent); flex-shrink: 0;
}
.theme-swatch {
  width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.theme-swatch-dark { background: linear-gradient(135deg, #262624 50%, #30302e 50%); }
.theme-swatch-light { background: linear-gradient(135deg, #faf9f5 50%, #efede6 50%); }

/* ---------- search panel ---------- */
#search-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--fg);
  outline: none;
  font: inherit;
}
#search-input:focus { border-color: var(--accent); }
.search-group-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--fg-2);
  margin: 8px 4px 4px;
}
.search-hit {
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  color: var(--fg);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: inherit;
}
.search-hit:hover { background: var(--bg-3); border-color: var(--accent); }
.search-hit-title {
  font-weight: 600;
  font-size: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: baseline;
}
.search-hit-meta {
  font-weight: 400;
  font-size: 12px;
  color: var(--fg-2);
}
.search-hit-snippet {
  font-size: 13px;
  color: var(--fg-2);
  line-height: 1.45;
  word-break: break-word;
}
.search-hit-snippet mark {
  background: color-mix(in srgb, var(--accent) 28%, transparent);
  color: var(--fg);
  padding: 0 2px;
  border-radius: 3px;
}
.msg.user {
  align-self: flex-end;
  max-width: min(640px, 80%);
  padding: 10px 16px;
  background: var(--user-bg);
  border-radius: 20px;
  font-size: calc(15.5px * var(--text-k, 1));
}
.msg.assistant {
  align-self: flex-start;
  background: var(--assistant-bg);
}
.msg.error {
  align-self: center;
  max-width: min(640px, 100%);
  background: color-mix(in srgb, var(--error) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--error) 35%, transparent);
  color: var(--error);
  font-size: 14px;
  border-radius: 10px;
}
.msg.system {
  align-self: center;
  color: var(--fg-2);
  font-size: 13px;
  background: transparent;
  padding: 4px 8px;
}
.msg.tool-status {
  align-self: flex-start;
  font-style: italic;
  font-size: 12px;
  opacity: 0.75;
}

/* "Thinking" indicator: three soft dots, no bubble. */
.typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 5px;
  padding: 10px 2px;
  background: transparent;
  border-radius: var(--radius);
}
.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1); }
}

/* ---------- composer ----------
   One rounded field with the controls inside, as in Claude / ChatGPT.
   Desktop: text on top, a row of buttons below (attach · mic … send).
   Phone (≤600px): a single row — attach · text · mic · send. */
.composer {
  --composer-w: 800px;
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  grid-template-areas:
    "text  text  text  text"
    "upload mic  chip  send";
  align-items: end;
  gap: 4px;
  width: min(var(--composer-w), calc(100% - 32px));
  margin: 0 auto calc(14px + env(safe-area-inset-bottom, 0px));
  padding: 8px;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: 22px;
  box-shadow: var(--shadow-composer);
  /* Same hard-pin as .topbar — composer must always stay visible. */
  flex-shrink: 0;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer:focus-within {
  border-color: color-mix(in srgb, var(--fg) 26%, transparent);
}
.composer textarea {
  grid-area: text;
  width: 100%;
  resize: none;
  max-height: 30vh;
  min-height: 44px;
  padding: 8px 10px 4px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--fg);
  outline: none;
  font-size: calc(15.5px * var(--text-k, 1));
  line-height: 1.5;
  overflow-y: hidden;
}
.composer textarea::placeholder { color: var(--fg-3); }
.composer textarea.at-max { overflow-y: auto; }
.composer #upload-btn { grid-area: upload; }
.composer #mic-btn { grid-area: mic; }
.composer .send, .composer .stop { grid-area: send; }

.btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: none;
  border-radius: 12px;
  background: var(--bg-3);
  color: var(--fg);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, opacity 0.15s, transform 0.1s;
}
.btn:hover { background: var(--hover-strong); }
/* Buttons inside the field are quiet circles; send is the one solid control. */
.composer .btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: transparent;
  color: var(--fg-2);
}
.composer .btn:hover { background: var(--hover-soft); color: var(--fg); }
.composer .btn:active { background: var(--hover-strong); }
.composer .btn.send {
  background: var(--accent);
  color: var(--accent-fg);
}
.composer .btn.send:hover { background: var(--accent-2); color: var(--accent-fg); }
.composer .btn.send:active { transform: scale(0.94); }
/* Nothing to send yet: the arrow stays visible but recedes. */
.composer:has(textarea:placeholder-shown) .btn.send:not(:disabled) {
  background: var(--bg-3);
  color: var(--fg-3);
}
.composer .stop {
  gap: 0;
  border: 0;
  background: var(--fg);
  color: var(--bg);
}
.composer .stop:hover { background: var(--fg); color: var(--bg); opacity: 0.85; }
.composer .stop:disabled { opacity: .5; cursor: wait; }
/* The "СТОП" label stays for screen readers and the busy text swap in JS. */
.composer .stop span:last-child {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.stop-square {
  width: 11px;
  height: 11px;
  border-radius: 2.5px;
  background: currentColor;
  flex: 0 0 auto;
}
.btn.recording, .composer .btn.recording {
  background: var(--error);
  color: white;
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--error) 55%, transparent); }
  50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--error) 0%, transparent); }
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn svg { width: 20px; height: 20px; }
.composer .btn svg { width: 19px; height: 19px; }
.composer .btn.send svg, .composer .btn.stop svg { width: 18px; height: 18px; }

/* hidden file input */
.file-input { display: none; }

/* attachment chip shown above the composer when a file is pending send */
.pending-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 5px 5px 12px;
  margin: 0 0 8px max(16px, calc((100% - 800px) / 2));
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  color: var(--fg);
  align-self: flex-start;
  max-width: calc(100% - 32px);
  flex-shrink: 0;
}
.pending-chip .pending-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60vw;
}
.pending-chip .pending-remove {
  background: transparent;
  border: none;
  color: var(--fg-2);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.pending-chip .pending-remove:hover {
  background: var(--hover-soft);
  color: var(--fg);
}

/* ---------- mobile ---------- */
/* Phones: a tighter composer; same two rows as on desktop. */
@media (max-width: 600px) {
  .composer {
    /* Text on top, then attach · mic · model chip · send (as on desktop). */
    width: calc(100% - 20px);
    margin-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    padding: 5px;
    gap: 2px;
    border-radius: 24px;
  }
  .composer textarea { min-height: 38px; padding: 8px 6px; font-size: calc(16px * var(--text-k, 1)); line-height: 1.4; }
  .composer .btn { width: 38px; height: 38px; }
  .pending-chip { margin-left: 10px; max-width: calc(100% - 20px); }
}

@media (max-width: 480px) {
  .msg { max-width: 92%; }
  .msg.user { max-width: 86%; }
  .chat { padding: 8px 14px 16px; }
  /* Keep the iOS safe-area insets here too — a bare `padding: 8px 10px`
     would wipe out the desktop rule's env() insets and shove the topbar
     (and the hamburger button) under the notch / Dynamic Island in a
     standalone PWA, where it's unreachable. */
  .topbar {
    min-height: 52px;
    padding: 8px 6px;
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
    padding-left: calc(6px + env(safe-area-inset-left, 0px));
    padding-right: calc(6px + env(safe-area-inset-right, 0px));
    border-bottom-color: var(--border);
  }
  .topbar .icon-btn { min-width: 40px; height: 40px; padding: 0 8px; font-size: 13px; }
  /* The user's name is in the menu; on a phone the header width goes to the
     project and thread names instead. */
  .topbar .who { display: none; }
  .topbar { gap: 2px; }
  /* Every pixel goes to the project and thread names: the limits indicator
     keeps only its ring (the number is in the sheet), the chips drop icons. */
  .usage-btn { padding: 0; width: 40px; justify-content: center; background: transparent; }
  .usage-btn-text { display: none; }
  .project-chip > .icon:first-child { display: none; }
  .project-chip, .thread-chip { height: 40px; padding: 0 6px 0 10px; gap: 4px; }
  .thread-chip .project-chip-name { color: var(--fg-2); }
  .dropdown { right: 8px; left: 8px; min-width: 0; max-width: none; }
  .dropdown-item { min-height: 44px; }

  /* Ask-form: wider block, denser options, smaller font so text doesn't wrap to 3 lines */
  .ask-block {
    max-width: 96%;
    padding: 12px 12px;
  }
  .ask-question { font-size: 15px; }
  .ask-option {
    padding: 8px 10px;
    gap: 8px;
    font-size: 14px;
    line-height: 1.35;
  }
  .ask-option input { width: 16px; height: 16px; flex-shrink: 0; }
  .ask-text { font-size: 14px; padding: 8px 10px; }
  .ask-submit { padding: 8px 18px; }
}

/* Admin: users management section in the Settings sheet (artem-only). */
.admin-users-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.admin-user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.admin-user-row .au-name {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.admin-user-row .au-display {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.admin-user-row .au-id {
  color: var(--fg-2);
  font-size: 12px;
  font-family: monospace;
}
.admin-user-row .au-pending { background: rgba(245, 158, 11, .14); color: #fbbf24; }
.admin-project-hint { color: var(--fg-2); font-size: 12px; line-height: 1.45; margin: 8px 0; }
.admin-project-select { width: 100%; margin: 6px 0 10px; }
.admin-project-members-list { display: grid; gap: 8px; }
.admin-project-member { display: flex; align-items: center; gap: 9px; font-size: 13px; }
.admin-project-member input { accent-color: var(--accent); }
#admin-project-members-status { margin-top: 8px; }
.admin-create-form .admin-project-member input { padding: 0; background: none; border: 0; }
.admin-create-form .admin-project-hint { margin: 2px 0 0; }
#admin-shared-project-select { margin-top: 12px; }

.admin-user-row .au-badge {
  font-size: 11px;
  background: var(--bg-3);
  color: var(--fg-2);
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}
.admin-user-row .au-actions {
  display: flex;
  gap: 6px;
}
.admin-user-row .au-actions button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}
.admin-user-row .au-actions button:hover {
  background: var(--bg-3);
}
.admin-user-row .au-actions .au-delete {
  color: var(--error);
}
.admin-create-form {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.admin-create-form input {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
.admin-create-form input:focus {
  outline: none;
  border-color: var(--accent);
}
.admin-form-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.admin-form-actions .btn,
.admin-form-actions .btn-primary {
  flex: 1;
  min-width: 0;
  padding: 10px;
  font-size: 14px;
}
.admin-form-error {
  color: var(--error);
}

/* ----- Menu badge ----- */
.dd-badge {
  margin-left: auto;
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

/* ----- Notifications history sheet ----- */
.notif-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.1s;
}
.notif-row:hover { background: var(--bg-2); }
.notif-row .nr-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--fg);
}
.notif-row .nr-body {
  font-size: 13px;
  color: var(--fg-2);
  line-height: 1.35;
  word-break: break-word;
}
.notif-row .nr-meta {
  display: flex;
  gap: 8px;
  font-size: 11px;
  color: var(--fg-2);
  margin-top: 2px;
  flex-wrap: wrap;
}
.notif-row .nr-tag {
  background: var(--bg-3);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: monospace;
}
.notif-row.undelivered .nr-meta::after {
  content: "не доставлено";
  color: var(--error);
  font-style: italic;
}

/* ---------- "Поделились со мной": inbox badge + viewer ---------- */
.inbox-badge {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  border-radius: 9px;
  padding: 0 5px;
}
.share-item.unread { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.inbox-view-card { max-height: 72vh; overflow: auto; text-align: left; }
.inbox-view-body { font-size: 14px; line-height: 1.5; }
.inbox-view-body img { max-width: 100%; height: auto; border-radius: 8px; }

/* "load earlier messages" pill at the top of the chat */
.load-earlier-pill {
  display: block;
  margin: 10px auto 14px;
  padding: 6px 14px;
  font-size: 13px;
  background: var(--bg-3);
  color: var(--fg-2);
  border: none;
  border-radius: 14px;
  cursor: pointer;
}
.load-earlier-pill:hover:not(:disabled) { color: var(--fg); background: var(--hover-soft); }
.load-earlier-pill:disabled { opacity: 0.6; cursor: default; }

/* Messages select and copy like any page (mouse drag, long-press with native
   handles, browser context menu). Only the toolbar buttons are excluded. */
.msg.user, .msg.assistant,
.msg.user *, .msg.assistant * {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}
.msg button, .msg .msg-actions, .msg .msg-actions * {
  -webkit-user-select: none;
  user-select: none;
}

/* Chat images keep the browser's own menu (save, copy, open); a click opens
   the lightbox. */
img.inline-attachment { cursor: zoom-in; }

/* Shared-project presence and live agent activity. */
.collab-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-2) 88%, transparent);
  font-size: 12px;
}
.collab-people { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
.collab-person {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--fg-2);
  white-space: nowrap;
}
.collab-presence-dot,
.collab-agent-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #7b8494;
  box-shadow: 0 0 0 2px color-mix(in srgb, #7b8494 18%, transparent);
}
.collab-person.online .collab-presence-dot {
  background: #27c77b;
  box-shadow: 0 0 0 2px color-mix(in srgb, #27c77b 22%, transparent);
}
.collab-agent {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--fg-2);
  text-align: right;
}
.collab-agent.active { color: var(--fg); }
.collab-agent.active .collab-agent-dot {
  background: var(--accent);
  animation: collab-pulse 1.35s ease-in-out infinite;
}
@keyframes collab-pulse {
  50% { opacity: .45; transform: scale(.78); }
}
@media (max-width: 620px) {
  .collab-bar { align-items: flex-start; flex-direction: column; gap: 5px; padding: 7px 10px; }
  .collab-agent { text-align: left; }
}

/* ---------- limits indicator (header) and sheet ---------- */
.usage-btn {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: 7px;
  height: 36px;
  padding: 0 10px 0 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--fg-2);
  font: inherit; font-size: 13px; font-weight: 500;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.usage-btn:hover { background: var(--hover-soft); color: var(--fg); }
.usage-ring { width: 18px; height: 18px; transform: rotate(-90deg); }
.usage-ring circle { fill: none; stroke-width: 4; }
.usage-ring-track { stroke: var(--hover-soft); }
.usage-ring-value {
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-dasharray: 94.25;
  stroke-dashoffset: 94.25;
  transition: stroke-dashoffset 0.4s ease, stroke 0.2s;
}
.usage-btn.warn .usage-ring-value { stroke: var(--warn); }
.usage-btn.high .usage-ring-value { stroke: var(--error); }
.usage-btn.high .usage-btn-text { color: var(--error); }

.usage-row { padding: 14px 2px; border-bottom: 1px solid var(--border); }
.usage-row:last-of-type { border-bottom: 0; }
.usage-row-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.usage-row-title { font-weight: 600; }
.usage-row-value { font-weight: 600; font-variant-numeric: tabular-nums; }
.usage-bar { height: 6px; margin: 8px 0 6px; border-radius: 999px; background: var(--hover-strong); overflow: hidden; }
.usage-bar-fill { height: 100%; border-radius: inherit; background: var(--accent); }
.usage-bar-fill.warn { background: var(--warn); }
.usage-bar-fill.high { background: var(--error); }
.usage-row-sub { font-size: 12px; color: var(--fg-2); }
.usage-note { margin-top: 12px; font-size: 12px; color: var(--fg-2); }

/* ---------- projects sheet: search and groups ---------- */
.projects-search-wrap { padding: 0 16px 8px; }
.projects-search { width: 100%; box-sizing: border-box; }
.project-group-toggle { justify-content: space-between; }
.project-group-count { font-weight: 500; opacity: 0.8; }
.project-item-meta { font-size: 12px; color: var(--fg-2); margin-top: 2px; }

/* ---------- watchdog: settings row in the threads sheet + dialog ---------- */
.watchdog-row {
  display: flex; align-items: center; gap: 10px;
  width: 100%; margin-bottom: 12px; padding: 10px 12px;
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
  background: none; color: var(--fg); font: inherit; text-align: left; cursor: pointer;
}
.watchdog-row:hover { border-color: var(--accent); }
.watchdog-row .icon { width: 18px; height: 18px; flex: 0 0 auto; color: var(--accent); }
.watchdog-row.off .icon { color: var(--fg-2); }
.watchdog-row-text { flex: 1 1 auto; min-width: 0; }
.watchdog-row-title { font-weight: 600; font-size: 14px; }
.watchdog-row-sub { font-size: 12px; color: var(--fg-2); margin-top: 2px; }
.watchdog-form { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.watchdog-check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; cursor: pointer; }
.watchdog-check input { margin-top: 3px; accent-color: var(--accent); }
.watchdog-check small { display: block; color: var(--fg-2); font-size: 12px; margin-top: 1px; }
.watchdog-nums { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.watchdog-nums .form-input { width: 100%; box-sizing: border-box; }
.thread-note.running .thread-note-icon { color: var(--warn); }

/* ---------- desktop sidebar (≥1100px) ---------- */
:root { --sidebar-w: 288px; }
.sidebar, .sidebar-open-btn, .topbar-title { display: none; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 20;
  width: var(--sidebar-w);
  flex-direction: column;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
}
/* Drag handle on the right edge (sidebar-resize.js), computer only. */
.sb-resizer {
  position: absolute; right: -4px; top: 0; bottom: 0; width: 8px; z-index: 3;
  cursor: col-resize; touch-action: none;
}
.sb-resizer::after {
  content: ""; position: absolute; left: 3px; top: 0; bottom: 0; width: 2px;
  background: transparent; transition: background 0.15s;
}
.sb-resizer:hover::after, body.sb-resizing .sb-resizer::after { background: var(--accent); }
body.sb-resizing { cursor: col-resize; user-select: none; }
body.sb-resizing iframe { pointer-events: none; }
@media (max-width: 1099px) { .sb-resizer { display: none; } }
.sidebar-head {
  display: flex; align-items: center; gap: 2px;
  min-height: 52px;
  padding: 8px 8px 4px 16px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
}
.sidebar-brand {
  flex: 1 1 auto; display: flex; align-items: center; gap: 9px;
  font-weight: 600; font-size: 15px; letter-spacing: -0.005em;
}
/* Small accent mark before the product name. */
.sidebar-brand::before {
  content: ""; width: 22px; height: 22px; border-radius: 7px; flex: 0 0 auto;
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.2' stroke-linejoin='round'%3E%3Cpath d='M12 3l1.9 5.6L19.5 10.5l-5.6 1.9L12 18l-1.9-5.6L4.5 10.5l5.6-1.9z'/%3E%3C/svg%3E") center / 14px no-repeat;
}
.sidebar-icon-btn { min-width: 34px; height: 34px; padding: 0; border-radius: 8px; color: var(--fg-2); }
.sidebar-icon-btn:hover { color: var(--fg); background: var(--hover-soft); }
.sidebar-icon-btn .icon, .sidebar-open-btn .icon { width: 18px; height: 18px; }
.sidebar-new {
  display: flex; align-items: center; gap: 10px;
  margin: 6px 8px 6px; padding: 0 8px; height: 38px;
  border: 0; border-radius: 9px;
  background: transparent; color: var(--fg);
  font: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
  transition: background 0.15s;
}
.sidebar-new:hover { background: var(--hover-soft); }
.sidebar-new:active { background: var(--hover-strong); }
.sidebar-new .icon {
  width: 22px; height: 22px; padding: 4px; border-radius: 50%;
  background: var(--accent); color: var(--accent-fg); stroke-width: 2.6;
}
.sidebar-new span { flex: 1 1 auto; text-align: left; }
/* «Новая сессия» and «Проект» side by side. */
.sidebar-new-row { display: flex; align-items: center; gap: 2px; margin: 6px 8px; }
.sidebar-new-row .sidebar-new { margin: 0; min-width: 0; white-space: nowrap; }
.sidebar-new-row .sidebar-new span { overflow: hidden; text-overflow: ellipsis; }
.sidebar-new-row kbd { display: none; }
.sidebar-new-row #sidebar-new-thread { flex: 1 1 auto; }
.sidebar-new-row .sidebar-new-project { flex: 0 0 auto; gap: 7px; padding: 0 10px 0 8px; color: var(--fg-2); font-size: 13px; }
.sidebar-new-row .sidebar-new-project:hover { color: var(--fg); }
.sidebar-new-row .sidebar-new-project .icon { background: var(--hover-strong); color: var(--fg); stroke-width: 2.2; }
.sidebar-new kbd { opacity: 0; transition: opacity 0.15s; }
.sidebar-new:hover kbd { opacity: 1; }
.sidebar kbd, .switcher kbd {
  font: 11px/1 var(--mono);
  padding: 3px 5px; border-radius: 5px;
  background: var(--hover-strong); color: var(--fg-2);
}
.sidebar-tree { flex: 1 1 auto; overflow-y: auto; padding: 4px 8px 12px; overscroll-behavior: contain; }
.sb-group {
  display: flex; align-items: center; gap: 6px; width: 100%;
  margin-top: 14px; padding: 4px 8px;
  border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 11.5px; font-weight: 500; letter-spacing: 0.02em; text-transform: none;
  color: var(--fg-3);
  border-radius: 6px;
}
.sb-group:hover { color: var(--fg-2); }
.sb-group .sb-count { margin-left: auto; font-weight: 500; }
.sb-row {
  display: flex; align-items: center; gap: 9px; width: 100%;
  min-height: 34px;
  padding: 6px 8px; border: 0; border-radius: 8px;
  background: none; color: var(--fg); cursor: pointer;
  font: inherit; font-size: 14px; text-align: left;
  transition: background 0.12s;
}
.sb-row:hover { background: var(--hover-soft); }
.sb-row:active { background: var(--hover-strong); }
.sb-row.current { background: var(--hover-strong); }
.sb-row .icon { width: 16px; height: 16px; flex: 0 0 auto; color: var(--fg-2); }
.sb-row-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-row-time { flex: 0 0 auto; font-size: 11.5px; color: var(--fg-3); }
.sb-project.current { font-weight: 500; }
/* Projects tree: the arrow before a project unfolds its sessions. */
.sb-project-wrap.has-toggle { display: flex; align-items: center; }
.sb-project-wrap.has-toggle > .sb-row { flex: 1 1 auto; min-width: 0; }
.sb-proj-toggle {
  flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 30px; margin-right: -4px; padding: 0; border: 0; border-radius: 6px;
  background: none; color: var(--fg-3); cursor: pointer;
}
.sb-proj-toggle:hover { color: var(--fg); background: var(--hover-soft); }
.sb-proj-toggle .icon { width: 13px; height: 13px; }
.org-projects .org-chev { transition: transform 0.15s; }
.org-projects .org-drop-before { box-shadow: inset 0 2px 0 var(--accent); border-radius: 0; }
.org-projects .org-drop-after { box-shadow: inset 0 -2px 0 var(--accent); border-radius: 0; }
.sb-threads { margin: 2px 0 6px 15px; padding-left: 8px; border-left: 1px solid var(--border); }
.sb-thread { font-size: 13.5px; min-height: 32px; padding: 5px 8px; color: var(--fg-2); }
.sb-thread:hover { color: var(--fg); }
.sb-thread.current { color: var(--fg); font-weight: 500; background: var(--hover-soft); }
.sb-dot { width: 6px; height: 6px; flex: 0 0 auto; border-radius: 50%; background: var(--fg-3); opacity: 0.6; }
.sb-dot.running, .sb-dot.done, .sb-dot.error { opacity: 1; }
.sb-dot.running { background: var(--accent); animation: thread-pulse 1.2s ease-in-out infinite; }
.sb-dot.done { background: var(--ok); }
.sb-dot.error { background: var(--error); }
.sb-more { font-size: 12.5px; color: var(--fg-3); }
.sidebar-foot {
  display: flex; flex-direction: column; gap: 6px;
  padding: 8px 8px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
}
.sidebar-foot-row { display: flex; align-items: center; gap: 4px; }
/* The user's menu (user-menu.js): the name with its initial. */
.sb-user {
  flex: 1 1 auto; min-width: 0; display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 8px 0 4px;
  border: 0; border-radius: 9px; background: none; color: var(--fg); font: inherit; font-size: 13.5px; cursor: pointer; position: relative;
}
.sb-user:hover, .sb-user[aria-expanded="true"] { background: var(--hover-soft); }
.sb-user:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.sb-user-av {
  flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%; display: inline-grid; place-items: center;
  background: var(--accent); color: var(--accent-fg); font-size: 12.5px; font-weight: 600;
}
.sb-user-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; font-weight: 500; }
.sb-user > .icon { width: 14px; height: 14px; color: var(--fg-3); flex: 0 0 auto; }
.sb-user-dot { position: absolute; left: 24px; top: 5px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--sidebar-bg, var(--bg)); }
.sb-user-dot[hidden] { display: none; }
.sb-user-menu { position: fixed; }
.sb-user-menu-head { padding: 7px 9px 5px; font-size: 12px; color: var(--fg-3); }
.sb-user-badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: var(--accent-fg); font-size: 11px; font-weight: 600; line-height: 18px; text-align: center; }
/* A computer: ☰ is gone — the session's actions are in «…», the rest in the
   user's menu at the sidebar's foot. The phone keeps it (mobile.css). */
@media (min-width: 601px) { .topbar #menu-btn, .topbar #dropdown { display: none !important; } }
.sidebar-settings {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px;
  border: 0; border-radius: 8px; background: none; color: var(--fg-2); font: inherit; font-size: 13px; cursor: pointer;
}
.sidebar-settings .icon { width: 16px; height: 16px; }
.sidebar-settings:hover { color: var(--fg); background: var(--hover-soft); }
.sidebar-settings:focus-visible { outline: none; box-shadow: var(--focus-ring); }
@media (max-width: 759px) { .sidebar-settings { display: none; } }  /* the phone keeps its own way in */
.sidebar-usage {
  display: grid; grid-template-columns: auto 1fr auto; gap: 7px 10px; align-items: center;
  width: 100%; padding: 10px 10px; border: 1px solid var(--border); border-radius: 10px;
  background: transparent; color: var(--fg); font: inherit; font-size: 12px; cursor: pointer;
  transition: background 0.15s;
}
.sidebar-usage:hover { background: var(--hover-soft); }
.sidebar-usage .usage-bar { margin: 0; height: 4px; }
.sidebar-usage .sb-usage-label { color: var(--fg-2); }
.sidebar-usage .sb-usage-value { font-variant-numeric: tabular-nums; font-weight: 500; color: var(--fg-2); min-width: 28px; text-align: right; }

@media (min-width: 1100px) {
  body:not(.sidebar-collapsed) .sidebar { display: flex; }
  body:not(.sidebar-collapsed) .app { margin-left: var(--sidebar-w); }
  /* The sidebar replaces the project/thread chips; the header shows where you are. */
  body:not(.sidebar-collapsed) .topbar .project-chip,
  body:not(.sidebar-collapsed) .topbar .who { display: none; }
  body:not(.sidebar-collapsed) .topbar-title {
    display: block; flex: 1 1 auto; min-width: 0; padding-left: 8px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 14.5px; font-weight: 500;
  }
  .topbar-title > span:first-child { color: var(--fg-2); }
  .topbar-title .sep { color: var(--fg-3); font-weight: 400; margin: 0 7px; }
  /* The session's working folder under the title (static/app.js renderSidebar). */
  .topbar-title.has-cwd { line-height: 1.2; }
  .topbar-title .topbar-cwd {
    display: block; font: 400 11.5px/1.25 var(--mono); color: var(--fg-3);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  body.sidebar-collapsed .sidebar-open-btn { display: inline-flex; }
}

/* ---------- quick switcher (Ctrl+K) ---------- */
.switcher-backdrop {
  position: fixed; inset: 0; z-index: 60;
  display: flex; justify-content: center; align-items: flex-start;
  padding-top: 12vh; background: var(--backdrop);
}
.switcher {
  width: min(600px, calc(100vw - 24px));
  border: 1px solid var(--border); border-radius: 16px;
  background: var(--bg-2); box-shadow: var(--shadow-card);
  overflow: hidden;
}
.switcher input {
  width: 100%; box-sizing: border-box; padding: 14px 16px;
  border: 0; border-bottom: 1px solid var(--border); outline: none;
  background: transparent; color: var(--fg); font: inherit; font-size: 16px;
}
.switcher-list { max-height: 52vh; overflow-y: auto; padding: 6px; }
.switcher-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border: 0; border-radius: 8px;
  background: none; color: var(--fg); font: inherit; font-size: 14px; text-align: left; cursor: pointer;
}
.switcher-item .icon { width: 16px; height: 16px; color: var(--fg-2); flex: 0 0 auto; }
.switcher-item.active { background: var(--hover-strong); }
.switcher-item .sw-kind { margin-left: auto; font-size: 12px; color: var(--fg-2); }
.switcher-empty { padding: 14px; color: var(--fg-2); font-size: 14px; }
.switcher-foot { display: flex; gap: 14px; padding: 8px 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--fg-2); }

/* Watchdog's request to the main session — a quiet line, not a big bubble. */
.msg.system.watchdog-ask { font-style: italic; }


/* Wide screens: keep the conversation in a readable centred column (the
   scrollbar stays at the window edge), and stop the header chips from
   stretching across the whole bar. Kept last so it wins over the base
   .chat / .composer rules. */
@media (min-width: 960px) {
  .chat { padding-inline: max(16px, calc((100% - 784px) / 2)); }
}

/* ---------- assistant reply as in Claude Code / Codex ----------
   The reply is not a bubble: text runs the width of the column, tool calls
   are compact cards (static/turn-view.js). */
.msg.assistant {
  max-width: 100%;
  width: 100%;
  background: transparent;
  padding: 2px 0 6px;
  border-radius: 0;
}
.seg-text > *:first-child { margin-top: 0; }
.seg-text > *:last-child { margin-bottom: 0; }
.seg-text + .seg-text, .tool-card + .seg-text, .thinking-card + .seg-text { margin-top: 14px; }
.seg-text + .tool-card, .seg-text + .thinking-card { margin-top: 12px; }

.tool-card, .thinking-card {
  --tc-border: var(--border);
  border: 1px solid var(--tc-border);
  border-radius: 10px;
  background: transparent;
  margin: 6px 0;
  font-size: 13.5px;
  line-height: 1.5;
  overflow: hidden;
  transition: border-color 0.15s;
}
.tool-card + .tool-card { margin-top: 6px; }
.tool-card:hover { border-color: var(--border-strong); }
.tool-card > summary, .thinking-card > summary {
  display: flex; align-items: center; gap: 8px;
  min-height: 36px;
  padding: 6px 10px 6px 12px;
  cursor: pointer; list-style: none; user-select: none;
  min-width: 0;
  transition: background 0.12s;
}
.tool-card > summary::-webkit-details-marker,
.thinking-card > summary::-webkit-details-marker { display: none; }
.tool-card > summary:hover { background: var(--hover-soft); }
.tc-dot {
  width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto;
  background: var(--fg-3);
}
.tool-card[data-state="run"] .tc-dot { background: var(--accent); animation: tc-pulse 1s ease-in-out infinite; }
.tool-card[data-state="ok"] .tc-dot { background: var(--ok); }
.tool-card[data-state="err"] .tc-dot { background: var(--error); }
.tool-card[data-state="err"] { border-color: color-mix(in srgb, var(--error) 38%, transparent); }
@keyframes tc-pulse { 50% { opacity: 0.3; } }
.tc-name { font-weight: 600; flex: 0 0 auto; color: var(--fg); }
.tc-sum {
  flex: 1 1 auto; min-width: 0; color: var(--fg-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--mono); font-size: 12.5px;
}
.tc-meta { flex: 0 0 auto; color: var(--fg-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.tc-add { color: var(--ok); }
.tc-del { color: var(--error); }
.tc-note { color: var(--fg-2); }
.tc-chev { width: 14px; height: 14px; flex: 0 0 auto; color: var(--fg-3); transition: transform .18s var(--ease); }
details[open] > summary .tc-chev { transform: rotate(90deg); }

/* Thinking: a quiet expandable line, no frame — as in Claude Code. */
.thinking-card { border: 0; border-radius: 0; margin: 2px 0; overflow: visible; }
.thinking-card > summary {
  display: inline-flex; min-height: 28px; padding: 2px 6px 2px 0; gap: 6px;
  color: var(--fg-2); border-radius: 6px;
}
.thinking-card > summary:hover { color: var(--fg); }
.th-label { color: inherit; font-style: normal; font-size: 13.5px; flex: 0 1 auto; }
.thinking-card > .tc-md {
  margin: 4px 0 6px 2px; padding: 2px 0 2px 14px;
  border-left: 2px solid var(--border-strong);
  color: var(--fg-2); font-size: 14px; line-height: 1.6;
}

.tc-body { border-top: 1px solid var(--tc-border); }
.tc-body:empty { display: none; }
/* Higher specificity than `.msg.assistant pre`, so cards don't inherit the
   markdown code-block margins, radius and frame. */
.msg.assistant pre.tc-cmd, .msg.assistant pre.tc-out,
.tc-cmd, .tc-out {
  margin: 0; padding: 9px 12px;
  border: 0; border-radius: 0;
  font: 12.5px/1.55 var(--mono);
  white-space: pre-wrap; word-break: break-word;
  background: var(--code-bg);
  max-height: 340px; overflow: auto;
}
.msg.assistant pre.tc-cmd, .tc-cmd { background: transparent; max-height: 160px; }
.tc-prompt { color: var(--fg-3); user-select: none; }
.tc-out.tc-err { color: var(--error); }
.tc-cmd + .tc-result .tc-out { border-top: 1px solid var(--tc-border); }
.tc-empty { padding: 8px 12px; color: var(--fg-2); font-size: 12.5px; }
.tc-line { padding: 8px 12px; color: var(--fg-2); }
.tc-file { padding: 8px 12px 4px; font: 12px var(--mono); color: var(--fg-2); }
.tc-sep { height: 1px; background: var(--tc-border); }
.tc-md { padding: 8px 12px; }
.tc-md > *:first-child { margin-top: 0; }
.tc-md > *:last-child { margin-bottom: 0; }
.tc-sub > summary { padding: 8px 12px; cursor: pointer; color: var(--fg-2); }

.tc-diff {
  font: 12.5px/1.55 var(--mono);
  max-height: 420px; overflow: auto;
  padding: 4px 0;
  background: var(--code-bg);
}
.dl { display: flex; white-space: pre-wrap; word-break: break-word; }
.dl-s { flex: 0 0 26px; text-align: center; color: var(--fg-3); user-select: none; }
.dl-t { flex: 1 1 auto; min-width: 0; padding-right: 12px; }
.dl.add { background: color-mix(in srgb, var(--ok) 13%, transparent); }
.dl.add .dl-s { color: var(--ok); }
.dl.del { background: color-mix(in srgb, var(--error) 13%, transparent); }
.dl.del .dl-s { color: var(--error); }
.dl.fold { color: var(--fg-2); font-style: italic; background: var(--hover-soft); }

/* Task list: `.msg.assistant ul` would add its markdown margins and indent. */
.msg.assistant ul.tc-todos, .tc-todos { list-style: none; margin: 0; padding: 8px 12px 9px; }
.msg.assistant .tc-todos li, .tc-todos li { display: flex; align-items: baseline; gap: 9px; margin: 0; padding: 2px 0; line-height: 1.5; }
.todo-mark { flex: 0 0 14px; text-align: center; color: var(--fg-3); font-size: 12px; }
.todo-completed { color: var(--fg-2); text-decoration: line-through; text-decoration-color: var(--fg-3); }
.todo-completed .todo-mark { color: var(--ok); text-decoration: none; }
.todo-in_progress { font-weight: 500; }
.todo-in_progress .todo-mark { color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  .sheet, .dropdown, .tc-chev, .tool-card[data-state="run"] .tc-dot, .typing span { transition: none; animation: none; }
}

/* Copy button on code blocks and quotes in replies (code-copy.js). */
.has-code-copy { position: relative; }
.code-copy {
  position: absolute; top: 6px; right: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; padding: 0;
  border: 1px solid var(--border); border-radius: 7px;
  background: var(--bg-2); color: var(--fg-2); cursor: pointer;
  opacity: 0; transition: opacity 0.12s;
}
.code-copy svg { width: 15px; height: 15px; }
.has-code-copy:hover > .code-copy, .code-copy:focus-visible, .code-copy.done { opacity: 1; }
.code-copy:hover { color: var(--fg); border-color: var(--border-strong); }
.code-copy.done { color: var(--ok); }
@media (pointer: coarse) { .code-copy { opacity: 0.85; } }
.msg.assistant blockquote.has-code-copy { padding-right: 40px; }

/* «Вышла новая версия» (pwa-update.js) */
.pwa-update {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  z-index: 1000; display: flex; align-items: center; gap: 10px;
  padding: 8px 8px 8px 16px; border-radius: 14px;
  background: var(--bg-2); border: 1px solid var(--border-strong); box-shadow: var(--shadow-composer);
  color: var(--fg); font-size: 14px; white-space: nowrap;
}
.pwa-update-go { border: 0; border-radius: 10px; padding: 6px 12px; background: var(--accent); color: var(--accent-fg); font: inherit; cursor: pointer; }
.pwa-update-x { border: 0; background: transparent; color: var(--fg-2); font-size: 18px; width: 28px; height: 28px; border-radius: 50%; cursor: pointer; }
.pwa-update-x:hover { background: var(--hover-soft); }

/* «Настройки → Вид» */
.view-pref { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.view-pref-label { font-size: 14px; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 3px; border-radius: 12px; background: var(--bg-3); }
.seg button { border: 0; background: none; color: var(--fg-2); font: inherit; font-size: 13.5px; padding: 8px 4px; border-radius: 9px; cursor: pointer; min-height: 36px; }
.seg button:hover { color: var(--fg); }
.seg button.on { background: var(--bg); color: var(--fg); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
#view-prefs .view-pref-label, #view-prefs > .muted-note { padding: 0 4px; }

/* «Push: только срочное / все» in «Настройки» → «Уведомления» (app.js). */
.push-mode { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 8px 0 2px; font-size: 14px; }
.push-mode-label { color: var(--fg-2); }
.push-mode label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.push-mode input { accent-color: var(--accent); }
/* «Спросить автора» under a question of an ask form (static/ask-steps.js, app.js) */
.ask-author {
  display: inline-flex; align-items: center; gap: 8px; align-self: flex-start;
  padding: 6px 12px; border: 1px dashed var(--border-strong, var(--border)); border-radius: 999px;
  font-size: 13px; color: var(--fg-2); cursor: pointer; user-select: none;
}
.ask-author input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.ask-author.on { border-style: solid; border-color: var(--accent); color: var(--fg); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.ask-option.off { opacity: .5; cursor: default; }
button.ask-author-btn { border: 1px dashed var(--border-strong, var(--border)); background: transparent; color: var(--fg-2); font: inherit; font-size: 13px; padding: 8px 12px; border-radius: 10px; cursor: pointer; }
button.ask-author-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--fg); }
.ask-answered button.ask-author-btn { display: none; }
@media (max-width: 600px) { .ask-author { padding: 9px 14px; font-size: 14px; } }
