:root {
  --bg: #0f1115;
  --bg-2: #181b22;
  --bg-3: #232733;
  --fg: #e6e9ef;
  --fg-2: #9aa3b2;
  --accent: #7c93ff;
  --accent-2: #5b73e0;
  --user-bg: #1f2a4a;
  --assistant-bg: #232733;
  --error: #ff6b6b;
  --ok: #4ade80;
  --radius: 14px;
  --pad: 12px;
  --shadow-sheet: 0 -8px 32px rgba(0, 0, 0, 0.4);
  --shadow-card: 0 12px 32px rgba(0,0,0,0.4);
  --code-bg: rgba(0, 0, 0, 0.35);          /* code-block bg inside assistant bubble */
  --inline-bg: rgba(255, 255, 255, 0.07);  /* inline-code bg */
  --th-bg: rgba(255, 255, 255, 0.04);      /* table header bg */
  --hover-soft: rgba(255, 255, 255, 0.08); /* generic hover wash */
  --backdrop: rgba(0, 0, 0, 0.55);
}

/* Light theme — same shape, inverted surfaces. Activated via
   <html data-theme="light"> from JS based on localStorage. */
[data-theme="light"] {
  --bg: #f7f7f5;
  --bg-2: #ffffff;
  --bg-3: #ebecef;
  --fg: #1a1d24;
  --fg-2: #6b7280;
  --accent: #5b73e0;
  --accent-2: #3f55c4;
  --user-bg: #dde4ff;
  --assistant-bg: #f0f1f4;
  --error: #c64545;
  --ok: #2f855a;
  --shadow-sheet: 0 -8px 32px rgba(0, 0, 0, 0.12);
  --shadow-card: 0 12px 32px rgba(0, 0, 0, 0.12);
  --code-bg: #ebecef;
  --inline-bg: rgba(0, 0, 0, 0.06);
  --th-bg: rgba(0, 0, 0, 0.04);
  --hover-soft: rgba(0, 0, 0, 0.05);
  --backdrop: rgba(0, 0, 0, 0.35);
}

* { 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: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

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

/* ---------- login ---------- */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 16px;
}
.login-card {
  background: var(--bg-2);
  padding: 28px 22px;
  border-radius: var(--radius);
  width: 100%;
  max-width: 340px;
  box-shadow: var(--shadow-card);
}
.login-card h1 {
  margin: 0 0 18px;
  font-size: 20px;
  font-weight: 600;
  text-align: center;
}
.login-card label {
  display: block;
  font-size: 13px;
  color: var(--fg-2);
  margin: 10px 0 4px;
}
.login-card select,
.login-card input {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--bg-3);
  background: var(--bg);
  color: var(--fg);
  outline: none;
}
.login-card select:focus,
.login-card input:focus { border-color: var(--accent); }
.login-card button {
  width: 100%;
  margin-top: 16px;
  padding: 12px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
}
.login-card button:hover { background: var(--accent-2); }
.login-card .err {
  color: var(--error);
  font-size: 13px;
  margin-top: 10px;
  min-height: 18px;
  text-align: center;
}

/* ---------- 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));
  /* 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 {
  content: "Отпусти, чтобы загрузить";
  position: absolute;
  inset: 8px;
  background: rgba(124, 147, 255, 0.18);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  pointer-events: none;
  z-index: 100;
  backdrop-filter: blur(2px);
}
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  /* 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(10px + env(safe-area-inset-top, 0px));
  padding-left: calc(14px + env(safe-area-inset-left, 0px));
  padding-right: calc(14px + env(safe-area-inset-right, 0px));
  background: var(--bg-2);
  border-bottom: 1px solid var(--bg-3);
  /* 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;
}
.topbar .who {
  flex: 0 0 auto;
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 30vw;
}

/* 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;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--bg-3);
  border: 1px solid transparent;
  color: var(--fg);
  border-radius: 999px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.project-chip:hover { border-color: var(--accent); }
.project-chip .icon { width: 16px; height: 16px; flex: 0 0 auto; opacity: 0.8; }
.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; height: 14px; opacity: 0.65; }

/* Projects list inside the projects sheet. Each row: name + meta + edit/delete. */
.project-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--bg-3);
  border-radius: 12px;
  margin-bottom: 8px;
}
.project-item.current { border-color: var(--accent); background: rgba(124,147,255,0.06); }
.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: 600; 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 {
  background: transparent;
  border: 1px solid var(--bg-3);
  color: var(--fg-2);
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.project-action-btn:hover { background: var(--bg-3); color: var(--fg); }
.project-action-btn.danger:hover { color: var(--error); border-color: var(--error); }
.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(--bg-3);
  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(--bg-3);
  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(--bg-3);
  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: rgba(124,147,255,0.10);
  border: 1px solid rgba(124,147,255,0.30);
  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(--bg-3);
  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(--bg-3);
  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(--bg-3);
  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(--bg-3);
  background: rgba(124,147,255,0.05);
}
.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(--bg-3);
}
.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: ui-monospace, SFMono-Regular, Menlo, monospace;
  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(--bg-3);
  border-radius: 10px;
  margin-bottom: 6px;
}
.sec-block.blocked { border-color: var(--error); background: rgba(255,107,107,0.06); }
.sec-block-info { flex: 1; min-width: 0; }
.sec-block-ip {
  font-family: ui-monospace, monospace;
  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: rgba(124,147,255,0.18); color: var(--accent); }
.sec-block-source.f2b { background: rgba(255,107,107,0.18); color: var(--error); }
.sec-unblock-btn {
  background: transparent;
  border: 1px solid var(--bg-3);
  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: rgba(124,147,255,0.10);
  border: 1px solid rgba(124,147,255,0.30);
  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(--bg-3);
  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 #4ade80; }
.sec-attempt-line { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.sec-attempt-ip { font-family: ui-monospace, monospace; 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(--bg-3);
  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(--bg-3);
  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(--bg-3);
  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;
}
.msg-star {
  position: absolute;
  top: 6px;
  right: 8px;
  background: transparent;
  border: 0;
  padding: 4px;
  border-radius: 6px;
  color: var(--fg-2);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}
.msg:hover .msg-star { opacity: 0.6; }
.msg-star:hover { opacity: 1 !important; color: var(--accent); background: var(--bg-3); }
.msg-star.starred { opacity: 1; color: var(--accent); }
.msg-star .icon { width: 16px; height: 16px; display: block; }
@media (hover: none) {
  /* On touch devices show a permanent low-opacity star so it can be tapped */
  .msg-star { opacity: 0.35; }
}
/* Star is irrelevant for system + error messages — hide it there */
.msg.system .msg-star, .msg.error .msg-star, .typing .msg-star { display: none; }
/* Hide star while in selection mode (whole message is one big tap target) */
.app.selecting .msg-star { 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(--bg-3);
  color: var(--fg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  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); }

/* Bookmark items in the bookmarks sheet */
.bookmark-item {
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--bg-3);
  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(--bg-3);
  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(--bg-3);
}
.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(--bg-3);
  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(--bg-3);
  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(--bg-3);
  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(--bg-3);
  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(--bg-3);
  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(--bg-3);
  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), rgba(124,147,255,0.6));
  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;
}

/* Welcome / help — same content rendered in two places: as a special card
   in chat (auto-shown once on first empty chat) and as a sheet via menu. */
.welcome-card {
  align-self: stretch;
  background: var(--bg-2);
  border: 1px solid var(--bg-3);
  border-radius: 14px;
  padding: 18px;
  margin: 4px 0 8px;
}
.welcome-intro {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}
.welcome-tagline {
  color: var(--fg-2);
  font-size: 14px;
  margin-bottom: 14px;
}
.welcome-section {
  padding: 10px 0;
  border-top: 1px solid var(--bg-3);
}
.welcome-section:first-of-type { border-top: 0; padding-top: 4px; }
.welcome-section-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.welcome-section-title .emoji { font-size: 16px; line-height: 1; }
.welcome-section-body {
  font-size: 14px;
  line-height: 1.5;
  color: var(--fg);
}
.welcome-section-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.welcome-action-btn {
  background: var(--bg-3);
  color: var(--fg);
  border: 1px solid var(--bg-3);
  border-radius: 8px;
  padding: 6px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.welcome-action-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.welcome-footer {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--bg-3);
  color: var(--fg-2);
  font-size: 13px;
}
/* When rendered inside the sheet, drop the outer card chrome (the sheet has
   its own padding/background) but keep the inner section dividers. */
.help-sheet-content { padding: 0; }
.help-sheet-content .welcome-card { background: transparent; border: 0; padding: 0; margin: 0; }
.icon-btn {
  background: transparent;
  border: none;
  color: var(--fg-2);
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
.icon-btn:hover { background: var(--bg-3); color: var(--fg); }
/* 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: 4px 10px; }
.icon-btn.active { background: var(--bg-3); color: var(--accent); }

/* Bell button with notification badge — iOS-style small dot at top-right corner */
.bell-btn { position: relative; padding: 8px 10px; }
.bell-btn .icon { width: 22px; height: 22px; }
.bell-btn .badge {
  position: absolute;
  top: 1px;
  right: 1px;
  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-2);
  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(--bg-3);
  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); }

/* 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: 18px; height: 18px; 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: 8px 10px; }
.hamburger,
.hamburger::before,
.hamburger::after {
  display: block;
  width: 20px;
  height: 2px;
  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: -6px; }
.hamburger::after  { top: 6px; }
.menu-toggle[aria-expanded="true"] .hamburger { background: transparent; }
.menu-toggle[aria-expanded="true"] .hamburger::before { transform: translateY(6px) rotate(45deg); }
.menu-toggle[aria-expanded="true"] .hamburger::after  { transform: translateY(-6px) 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(56px + env(safe-area-inset-top, 0px));
  right: 8px;
  min-width: 240px;
  max-height: calc(100dvh - 56px - 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(--bg-3);
  border-radius: 12px;
  box-shadow: var(--shadow-card);
  padding: 6px;
  z-index: 320;
  opacity: 0;
  transform: translateY(-6px) scale(0.98);
  transition: opacity 0.15s ease-out, transform 0.15s ease-out;
}
.dropdown.open { opacity: 1; transform: translateY(0) scale(1); }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--fg);
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}
.dropdown-item:hover { background: var(--bg-3); }
.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);
  padding: 2px 8px;
  border-radius: 999px;
}
.dropdown-item.active .dd-state { background: rgba(124,147,255,0.18); color: var(--accent); }
.dropdown-item.dd-danger:hover { background: rgba(255,107,107,0.12); color: var(--error); }
.dropdown-divider {
  border: none;
  border-top: 1px solid var(--bg-3);
  margin: 4px 0;
}

/* APK update banner — shown only inside TWA when server has newer APK version */
.apk-update-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: white;
  border-bottom: 1px solid var(--bg-3);
}
.apk-update-text { flex: 1; min-width: 0; }
.apk-update-title { font-size: 14px; font-weight: 600; }
.apk-update-sub { font-size: 12px; opacity: 0.85; }
.apk-update-btn {
  background: white;
  color: var(--accent-2);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  flex-shrink: 0;
}
.apk-update-btn:hover { opacity: 0.92; }
.apk-update-close {
  background: rgba(255,255,255,0.18);
  border: none;
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

/* Long-task banner: appears between topbar and chat, persistent across reloads */
.task-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: linear-gradient(90deg, var(--user-bg), var(--bg-2));
  border-bottom: 1px solid var(--bg-3);
}
.task-banner-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--bg-3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.task-banner-text { flex: 1; min-width: 0; }
.task-banner-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
}
.task-banner-meta {
  font-size: 12px;
  color: var(--fg-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.task-banner-stop {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: var(--error);
  color: white;
  border: none;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  font-family: inherit;
}
.task-banner-stop:hover { background: #b82d2d; }
.task-banner-stop .icon { width: 14px; height: 14px; }

.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: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

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

/* Markdown rendered inside assistant messages */
.msg.assistant { white-space: normal; }
.msg.assistant > *:first-child { margin-top: 0; }
.msg.assistant > *:last-child { margin-bottom: 0; }
.msg.assistant p { margin: 0 0 8px; }
.msg.assistant ul,
.msg.assistant ol { margin: 4px 0 8px; padding-left: 22px; }
.msg.assistant li { margin: 2px 0; }
.msg.assistant li > p { margin: 0; }
.msg.assistant h1,
.msg.assistant h2,
.msg.assistant h3,
.msg.assistant h4 {
  margin: 12px 0 6px;
  font-weight: 600;
  line-height: 1.25;
}
.msg.assistant h1 { font-size: 1.25em; }
.msg.assistant h2 { font-size: 1.15em; }
.msg.assistant h3 { font-size: 1.05em; }
.msg.assistant h4 { font-size: 1em; }
.msg.assistant a {
  color: var(--accent);
  text-decoration: underline;
  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: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: var(--inline-bg);
  padding: 1px 5px;
  border-radius: 4px;
}
.msg.assistant pre {
  background: var(--code-bg);
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 6px 0 10px;
  font-size: 0.92em;
  line-height: 1.4;
}
.msg.assistant pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
}
.msg.assistant blockquote {
  margin: 6px 0 10px;
  padding: 4px 12px;
  border-left: 3px solid var(--bg-3);
  color: var(--fg-2);
}
.msg.assistant hr {
  border: none;
  border-top: 1px solid var(--bg-3);
  margin: 10px 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(--bg-3);
  padding: 4px 8px;
  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; }

/* ---------- image lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  opacity: 0;
  transition: opacity 0.18s ease-out;
}
.lightbox.open { opacity: 1; }
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  cursor: zoom-out;
}
.lightbox-toolbar {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  gap: 8px;
  z-index: 410;
}
.lightbox-action {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
}
.lightbox-action:hover { background: rgba(255, 255, 255, 0.22); }
.lightbox-action .icon { width: 22px; height: 22px; }

/* 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(--bg-3);
  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(--bg-3);
  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: rgba(124, 147, 255, 0.08);
}
.ask-text {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--bg-3);
  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;
}

/* ---------- skills panel (bottom sheet) ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: var(--backdrop);
  z-index: 200;
  animation: fadeIn 0.2s ease-out;
}
@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: 80% of viewport
     normally, but never larger than what's free above the keyboard. */
  max-height: min(80vh, calc(100vh - var(--kbd-inset, 0px) - 40px));
  background: var(--bg-2);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  z-index: 210;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.2s ease-out;
  box-shadow: var(--shadow-sheet);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.sheet.open { transform: translateY(0); }
.sheet-header {
  display: flex;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--bg-3);
}
.sheet-title { flex: 1; font-weight: 600; font-size: 16px; }
.sheet-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sheet-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-top: 1px solid var(--bg-3);
  flex-wrap: wrap;
}
.btn-primary {
  flex: 1;
  min-width: 180px;
  padding: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  font-size: 15px;
}
.btn-primary:hover { background: var(--accent-2); }

.skill-item {
  background: var(--bg);
  border: 1px solid var(--bg-3);
  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: rgba(124,147,255,0.15); color: var(--accent); }
.skill-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 10px 10px;
  border-top: 1px solid var(--bg-3);
}
.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(--bg-3);
  border-radius: 14px;
  padding: 18px 16px;
  width: 100%;
  max-width: 360px;
  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(--bg-3);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--fg);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.modal-choice:hover:not(:disabled) { background: var(--accent); color: white; border-color: var(--accent); }
.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(--bg-3);
  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: var(--bg-3);
  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;
}
.version-row {
  text-align: center;
  padding: 14px 14px 4px;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 11px;
  letter-spacing: 0.4px;
  opacity: 0.7;
  border-top: 1px solid var(--bg-3);
  margin-top: 18px;
}

/* Settings link row (e.g., download APK) */
.settings-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--bg-3);
  border-radius: 10px;
  text-decoration: none;
  color: var(--fg);
  transition: border-color 0.15s, background 0.15s;
}
.settings-link:hover {
  border-color: var(--accent);
  background: var(--bg-3);
}
.settings-link .icon { width: 22px; height: 22px; color: var(--accent); flex-shrink: 0; }
.settings-link-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.settings-link-title { font-weight: 600; font-size: 14px; }
.settings-link-sub { font-size: 12px; color: var(--fg-2); line-height: 1.3; }

/* Plain instructions card (no link, just a hint) */
.settings-card {
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--bg-3);
  border-radius: 10px;
  margin-top: 6px;
}
.settings-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}
.settings-card-title .icon { width: 18px; height: 18px; color: var(--accent); }
.settings-card-body { font-size: 13px; color: var(--fg-2); line-height: 1.45; }
.settings-card-body b { color: var(--fg); font-weight: 600; }

.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(--bg-3);
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
}
.theme-row:has(input:checked) {
  border-color: var(--accent);
  background: var(--user-bg);
}
.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(--bg-3);
  flex-shrink: 0;
}
.theme-swatch-dark { background: linear-gradient(135deg, #0f1115 50%, #232733 50%); }
.theme-swatch-light { background: linear-gradient(135deg, #f7f7f5 50%, #ebecef 50%); }

.voice-list { display: flex; flex-direction: column; gap: 8px; }
.voice-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--bg-3);
  border-radius: 10px;
  cursor: pointer;
}
.voice-row:has(input:checked) {
  border-color: var(--accent);
  background: rgba(124, 147, 255, 0.08);
}
.voice-row input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  flex-shrink: 0;
}
.voice-info { flex: 1; min-width: 0; }
.voice-title { font-weight: 600; font-size: 14px; }
.voice-note { font-size: 12px; color: var(--fg-2); margin-top: 2px; }
.voice-preview {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--bg-3);
  background: var(--bg-3);
  color: var(--fg);
  cursor: pointer;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.voice-preview:hover { background: var(--accent); color: white; }
.voice-preview:disabled { opacity: 0.5; cursor: wait; }

/* ---------- search panel ---------- */
#search-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--bg-3);
  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(--bg-3);
  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: rgba(124, 147, 255, 0.28);
  color: var(--fg);
  padding: 0 2px;
  border-radius: 3px;
}
.msg.user {
  align-self: flex-end;
  background: var(--user-bg);
  border-bottom-right-radius: 4px;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--assistant-bg);
  border-bottom-left-radius: 4px;
}
.msg.error {
  align-self: center;
  background: rgba(255, 107, 107, 0.12);
  border: 1px solid var(--error);
  color: var(--error);
  font-size: 14px;
}
.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;
}

.typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 4px;
  padding: 10px 14px;
  background: var(--assistant-bg);
  border-radius: var(--radius);
}
.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--fg-2);
  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.2; }
  40% { opacity: 1; }
}

/* ---------- composer ---------- */
.composer {
  display: flex;
  gap: 8px;
  padding: 10px;
  /* Add iOS home-indicator inset on top of the regular padding so the
     composer sits clear of the bottom gesture area in standalone mode. */
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  padding-left: calc(10px + env(safe-area-inset-left, 0px));
  padding-right: calc(10px + env(safe-area-inset-right, 0px));
  background: var(--bg-2);
  border-top: 1px solid var(--bg-3);
  align-items: flex-end;
  /* Same hard-pin as .topbar — composer must always stay visible. */
  flex-shrink: 0;
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 30vh;
  min-height: 44px;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--bg-3);
  background: var(--bg);
  outline: none;
  line-height: 1.4;
  overflow-y: hidden;
}
.composer textarea.at-max { overflow-y: auto; }
.composer textarea:focus { border-color: var(--accent); }

.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;
}
.btn:hover { background: var(--hover-soft); }
.btn.send { background: var(--accent); color: white; }
.btn.send:hover { background: var(--accent-2); }
.btn.recording {
  background: var(--error);
  color: white;
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,107,107,0.6); }
  50% { box-shadow: 0 0 0 8px rgba(255,107,107,0); }
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn svg { width: 20px; height: 20px; }

/* 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: 6px 6px 6px 12px;
  margin: 0 10px 6px;
  background: var(--bg-3);
  border-radius: 999px;
  font-size: 13px;
  color: var(--fg);
  align-self: flex-start;
  max-width: calc(100% - 20px);
}
.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 ---------- */
@media (max-width: 480px) {
  .msg { max-width: 92%; }
  /* 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 {
    padding: 8px 10px;
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
    padding-left: calc(10px + env(safe-area-inset-left, 0px));
    padding-right: calc(10px + env(safe-area-inset-right, 0px));
  }
  .topbar .icon-btn { padding: 6px 8px; font-size: 13px; }
  .dropdown { right: 6px; min-width: calc(100vw - 12px); max-width: 320px; }
  .composer { padding: 8px; gap: 6px; }
  .btn { width: 42px; height: 42px; }

  /* 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(--bg-3);
  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-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(--bg-3);
  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: #d96570;
}
.admin-create-form {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--bg-3);
  border-radius: 10px;
}
.admin-create-form input {
  background: var(--bg-2);
  border: 1px solid var(--bg-3);
  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: #d96570;
}

/* ----- Menu badge (used for Ideas counter on submitted-pending items) ----- */
.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;
}

/* ----- Ideas list sheet ----- */
.idea-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--bg-3);
  border-radius: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.1s;
}
.idea-row:hover { background: var(--bg-2); }
.idea-row .ir-title {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.3;
  color: var(--fg);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.idea-row .ir-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--fg-2);
  flex-wrap: wrap;
}

.idea-status-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  background: var(--bg-3);
  color: var(--fg-2);
}
.idea-status-badge[data-status="draft"] {
  background: rgba(120, 120, 120, 0.2);
  color: var(--fg-2);
}
.idea-status-badge[data-status="submitted"] {
  background: rgba(255, 180, 50, 0.2);
  color: #d99320;
}
.idea-status-badge[data-status="approved"] {
  background: rgba(80, 200, 120, 0.2);
  color: #4ca36a;
}
.idea-status-badge[data-status="rejected"] {
  background: rgba(217, 101, 112, 0.2);
  color: #d96570;
}
.idea-status-badge[data-status="done"] {
  background: rgba(99, 175, 105, 0.25);
  color: #4ca36a;
}

.idea-id {
  font-family: monospace;
  font-size: 11px;
  background: var(--bg-3);
  color: var(--fg-2);
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  user-select: all;
  word-break: break-all;
  max-width: 100%;
}
.idea-id:hover { background: var(--bg-2); color: var(--fg); }

/* ----- Notifications history sheet ----- */
.notif-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--bg-3);
  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: #d96570;
  font-style: italic;
}

/* ----- Single-idea chat sheet ----- */
#idea-chat-sheet { padding-bottom: 0; }
.idea-chat-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--bg-3);
  background: var(--bg);
  flex-wrap: wrap;
}
.idea-chat-meta .idea-author {
  color: var(--fg-2);
  font-size: 12px;
}
.idea-chat-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  background: var(--bg-2);
  min-height: 300px;
  overflow-x: hidden;
  overflow-y: auto;
  flex: 1;
  min-width: 0;
}
.idea-msg {
  max-width: 85%;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  min-width: 0;
}
.idea-msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: white;
}
.idea-msg.assistant {
  align-self: flex-start;
  background: var(--bg);
  border: 1px solid var(--bg-3);
  color: var(--fg);
}
.idea-msg.system {
  align-self: center;
  background: transparent;
  color: var(--fg-2);
  font-style: italic;
  font-size: 12px;
  text-align: center;
  max-width: 100%;
}
.idea-msg .idea-msg-time {
  display: block;
  font-size: 10px;
  opacity: 0.7;
  margin-top: 4px;
}
.idea-composer {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--bg-3);
  background: var(--bg);
}
.idea-composer textarea {
  flex: 1;
  background: var(--bg-2);
  border: 1px solid var(--bg-3);
  color: var(--fg);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  min-height: 40px;
  max-height: 140px;
}
.idea-composer textarea:focus { outline: none; border-color: var(--accent); }
.idea-composer .btn-primary,
.idea-composer .idea-mic-btn,
.idea-composer .idea-attach-btn {
  flex: 0 0 auto;
  min-width: 40px;
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.idea-composer .idea-mic-btn,
.idea-composer .idea-attach-btn {
  border: 1px solid var(--bg-3);
}

.idea-pending-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin: 0 14px;
  background: var(--bg);
  border: 1px solid var(--bg-3);
  border-radius: 10px;
  font-size: 13px;
  color: var(--fg-2);
}
.idea-pending-file .ipf-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.idea-pending-file .ipf-cancel {
  background: transparent;
  border: none;
  color: var(--fg-2);
  font-size: 18px;
  line-height: 1;
  padding: 2px 8px;
  cursor: pointer;
  border-radius: 4px;
}
.idea-pending-file .ipf-cancel:hover { background: var(--bg-3); color: var(--fg); }
.idea-pending-file .icon { width: 16px; height: 16px; flex: 0 0 auto; }
.idea-actions {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--bg-3);
  background: var(--bg);
  flex-wrap: wrap;
}
.idea-actions .btn,
.idea-actions .btn-primary {
  flex: 1;
  min-width: 120px;
}

/* ---------- "Поделились со мной": 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: rgba(124, 147, 255, 0.08); }
.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; }

/* Disable native long-press / text-selection on chat bubbles so the JS
   long-press timer can open our share menu instead of Android's text
   selection callout. Code blocks stay selectable so users can copy code. */
.msg.user, .msg.assistant {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.msg.assistant pre, .msg.assistant code,
.msg.assistant pre *, .msg.assistant code * {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

/* Chat images: suppress Android Chrome's native image context menu / drag UI
   so our long-press menu (Share / Send to user) can take over. The pointer
   listener in app.js opens the menu; the contextmenu listener preventsDefaults. */
img.inline-attachment {
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  -webkit-user-select: none;
  user-select: none;
}
