:root {
  color-scheme: dark;
  --bg: #0B0F10;
  --bg-elev: #131A1C;
  --bg-hover: #1A2427;
  --bg-card: #131A1C;
  --bg-user: #142B2E;
  --bg-thinking: #101618;
  --border: #1D292C;
  --border-user: rgba(45, 212, 191, 0.2);
  --text: #EDF4F5;
  --text-muted: #8CA3A6;
  --text-dim: #566B6E;
  --text-on-accent: #071314;
  --accent: #2DD4BF;
  --accent-bright: #5EEAD4;
  --accent-hover: #5EEAD4;
  --accent-soft: rgba(45, 212, 191, 0.14);
  --accent-glow: 0 0 14px rgba(45, 212, 191, 0.35);
  --ok: #2DD4BF;
  --warn: #FBBF24;
  --err: #F87171;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

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

::selection {
  background: rgba(45, 212, 191, 0.28);
  color: var(--text);
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  overflow-wrap: break-word;
  accent-color: var(--accent);
}

h1, h2, h3 {
  text-wrap: balance;
}

.visually-hidden {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 320px;
  block-size: 100dvh;
  overflow: clip;
}

.app-shell.memory-collapsed {
  grid-template-columns: 280px minmax(0, 1fr) 0px;
}

.app-shell.memory-collapsed .sidebar-right {
  visibility: hidden;
  overflow: clip;
  border-inline-start: 0;
}

.sidebar-left, .sidebar-right {
  display: flex;
  flex-direction: column;
  min-block-size: 0;
  background: var(--bg-elev);
  border-inline-end: 1px solid var(--border);
}

.sidebar-right {
  border-inline-end: 0;
  border-inline-start: 1px solid var(--border);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  border-block-end: 1px solid var(--border);
}

.sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-close-sidebar {
  font-size: 0.95rem;
  line-height: 1;
  padding: 0.35rem 0.55rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
}
.btn-close-sidebar:hover, .btn-close-sidebar:active {
  color: var(--text);
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.12);
}

.sidebar-backdrop {
  display: none;
}

.tablet-mobile-only {
  display: none;
}

.sidebar-header h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.brand-logo {
  display: block;
  border-radius: 6px;
  flex-shrink: 0;
}

.brand-dot {
  inline-size: 10px;
  block-size: 10px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: var(--accent-glow);
}

.sidebar-scroll {
  flex: 1 1 auto;
  min-block-size: 0;
  overflow-y: auto;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  border-block-start: 1px solid var(--border);
  font-size: 0.8rem;
}

.footer-links {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.btn-link {
  background: transparent;
  border: 0;
  padding: 0;
  font: inherit;
  cursor: pointer;
}

.login-page {
  min-block-size: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.25rem;
}

.login-card {
  inline-size: min(400px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.login-title {
  margin: 0 0 1rem;
  font-size: 1.15rem;
}

.login-error {
  margin: 0 0 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  background: rgba(249, 112, 102, 0.14);
  color: var(--err);
  font-size: 0.88rem;
}

.login-info {
  margin: 0 0 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  background: rgba(50, 213, 131, 0.14);
  color: var(--ok);
  font-size: 0.88rem;
}

.login-links {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-block-start: 1rem;
  padding-block-start: 0.75rem;
  border-block-start: 1px solid var(--border);
  font-size: 0.85rem;
}

.footer-link {
  color: var(--text-muted);
  text-decoration: none;
}

.footer-link:hover {
  color: var(--text);
}

.health-pill {
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 0.75rem;
}

.health-pill.is-ok { color: var(--ok); }
.health-pill.is-warn { color: var(--warn); }

.notebook-group {
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0.5rem;
  background: rgba(255, 255, 255, 0.015);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.notebook-group:hover {
  background: var(--bg-hover);
}

.notebook-group.is-active {
  border-color: var(--border-user);
  background: rgba(20, 43, 46, 0.35);
}

.notebook-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin-block-end: 0.35rem;
}

.notebook-title {
  font-weight: 600;
  font-size: 0.9rem;
  min-inline-size: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.session-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  border-radius: 8px;
  padding-inline: 0.45rem;
}

.session-item:hover {
  background: var(--bg-hover);
}

.session-item.is-current {
  background: var(--accent-soft);
  border: 1px solid rgba(45, 212, 191, 0.18);
}

.session-item-actions {
  display: flex;
  align-items: center;
  gap: 0.1rem;
  opacity: 0.65;
  transition: opacity 0.15s ease;
}

.session-item:hover .session-item-actions,
.session-item.is-current .session-item-actions {
  opacity: 1;
}

.session-link {
  flex: 1 1 auto;
  min-inline-size: 0;
  padding-block: 0.35rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Main chat */
.chat-main {
  position: relative;
  display: flex;
  flex-direction: column;
  min-inline-size: 0;
  min-block-size: 0;
  background: var(--bg);
}

/* Prompt Navigator Rail */
.prompt-nav-rail {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  max-height: 65vh;
  overflow-y: auto;
  padding: 6px 4px;
  scrollbar-width: none;
}

.prompt-nav-rail::-webkit-scrollbar {
  display: none;
}

.prompt-nav-rail:empty {
  display: none;
}

.prompt-nav-dot {
  width: 6px;
  height: 6px;
  min-height: 6px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.prompt-nav-dot:hover,
.prompt-nav-dot.is-active {
  background: #e2e8f0;
  transform: scale(1.6);
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.45);
}

.prompt-nav-dot.is-active {
  background: var(--accent);
  box-shadow: var(--accent-glow);
}

.prompt-nav-tooltip {
  position: absolute;
  left: 30px;
  z-index: 30;
  width: 280px;
  max-width: calc(100vw - 60px);
  background: #202229;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 0.65rem 0.8rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  pointer-events: none;
}

.pnt-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 0.3rem;
  line-height: 1.35;
}

.pnt-preview {
  font-size: 0.76rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.35;
  margin-bottom: 0.45rem;
}

.pnt-footer {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: #7c8594;
}

.msg-footer-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.6rem;
  padding-top: 0.45rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.btn-branch-chat {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.6rem;
  border-radius: 8px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-branch-chat:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.btn-branch-chat:disabled {
  opacity: 0.5;
  cursor: wait;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-block-size: 56px;
  padding: 0.6rem 1.25rem;
  border-block-end: 1px solid var(--border);
  background: var(--bg-elev);
  flex-shrink: 0;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-inline-size: 0;
  flex: 1 1 auto;
}

.chat-header-titles {
  min-inline-size: 0;
  flex: 1 1 auto;
}

.header-brand-icon {
  display: none;
  border-radius: 6px;
  flex-shrink: 0;
}

.chat-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-subtitle {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  flex-shrink: 0;
}

.header-icon-action {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.messages-scroller {
  position: relative;
  flex: 1 1 auto;
  min-block-size: 0;
  overflow-y: auto;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
  padding: 1.25rem;
  scroll-padding-bottom: 150px;
}

.messages-container {
  max-inline-size: 860px;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-block-end: 145px;
}

.scroll-top-sentinel, .scroll-bottom-sentinel {
  block-size: 1px;
  inline-size: 1px;
  visibility: hidden;
}

.scroll-to-bottom {
  position: absolute;
  inset-inline-end: 1.25rem;
  inset-block-end: calc(100% + 10px);
  z-index: 25;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  inline-size: 36px;
  block-size: 36px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(19, 26, 28, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(6px);
  transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease, border-color 0.15s ease, color 0.15s ease;
}

.scroll-to-bottom.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.scroll-to-bottom:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: var(--accent-glow);
}

.empty-state {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.empty-state h2 {
  margin-block: 0 0.5rem;
  font-size: 1.15rem;
}

.empty-summary {
  margin-block-start: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  background: var(--bg-thinking);
  border: 1px solid var(--border);
  font-size: 0.9rem;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-inline-size: 0;
}

.msg-user {
  padding: 0.85rem 1.1rem;
  border-radius: 16px;
  border: 1px solid var(--border-user);
  background: var(--bg-user);
}

.msg-assistant {
  padding: 0.4rem 0 1rem;
  border: none;
  border-radius: 0;
  background: transparent;
  border-block-end: 1px solid rgba(29, 41, 44, 0.55);
}

.msg-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.msg-author {
  font-weight: 600;
}

.btn-tts {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 0.15rem 0.5rem;
  font-size: 0.75rem;
  cursor: pointer;
}

.btn-tts:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.btn-tts.is-playing {
  color: var(--err);
  border-color: var(--err);
  background: rgba(248, 113, 113, 0.12);
}

.thinking-box, .tools-box {
  background: var(--bg-thinking);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.45rem 0.7rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.thinking-pre {
  margin: 0.45rem 0 0;
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 0.78rem;
}

.tools-list {
  margin: 0.4rem 0 0;
  padding-inline-start: 1.2rem;
}

.attachments-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.att-thumb img {
  display: block;
  max-inline-size: 220px;
  max-block-size: 160px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.att-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border-radius: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 0.82rem;
}

.msg-body {
  min-inline-size: 0;
  line-height: 1.6;
  overflow-wrap: break-word;
}

.msg-body p {
  margin: 0 0 0.7rem;
  text-wrap: pretty;
}
.msg-body p:last-child { margin-block-end: 0; }
.msg-body h1, .msg-body h2, .msg-body h3, .msg-body h4, .msg-body h5, .msg-body h6 {
  margin: 1rem 0 0.45rem;
  color: var(--text);
  font-weight: 600;
  line-height: 1.35;
}
.msg-body h1 { font-size: 1.32rem; }
.msg-body h2 { font-size: 1.18rem; }
.msg-body h3 { font-size: 1.06rem; }
.msg-body h4, .msg-body h5, .msg-body h6 { font-size: 0.96rem; }
.msg-body h1:first-child, .msg-body h2:first-child, .msg-body h3:first-child { margin-block-start: 0.1rem; }

.msg-body ul, .msg-body ol {
  margin: 0.35rem 0 0.75rem;
  padding-inline-start: 1.45rem;
}
.msg-body li {
  margin-block-end: 0.3rem;
  line-height: 1.6;
  text-wrap: pretty;
}
.msg-body li::marker {
  color: var(--accent);
}
.msg-body blockquote {
  margin: 0.65rem 0;
  padding: 0.45rem 0.9rem;
  border-inline-start: 3px solid var(--accent);
  background: rgba(45, 212, 191, 0.06);
  color: var(--text-muted);
  border-radius: 0 8px 8px 0;
}
.msg-body hr {
  border: 0;
  border-block-start: 1px solid var(--border);
  margin: 1rem 0;
}
.md-table-wrap {
  overflow-x: auto;
  margin: 0.75rem 0;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.msg-body table {
  inline-size: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.msg-body th, .msg-body td {
  padding: 0.45rem 0.7rem;
  border-block-end: 1px solid var(--border);
  text-align: start;
}
.msg-body th {
  background: var(--bg-elev);
  color: var(--text);
  font-weight: 600;
}
.msg-body pre {
  background: #0E1416;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.84rem;
}
.msg-body code {
  font-family: var(--mono);
  background: rgba(45, 212, 191, 0.1);
  color: var(--accent-bright);
  padding: 0.12rem 0.35rem;
  border-radius: 5px;
  font-size: 0.88em;
  overflow-wrap: anywhere;
}
.msg-body pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  overflow-wrap: normal;
}
.msg-body a {
  color: var(--accent);
  overflow-wrap: anywhere;
}

/* Code Blocks with Syntax Highlighting */
.code-block {
  margin: 0.85rem 0;
  background: #0E1416;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  font-family: var(--mono);
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.85rem;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  user-select: none;
}

.code-lang {
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #8b949e;
}

.code-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-copy-code {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  color: #c9d1d9;
  font-size: 0.75rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-copy-code:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.25);
}

.btn-copy-code.copied {
  color: #98c379;
  border-color: #98c379;
  background: rgba(152, 195, 121, 0.12);
}

.code-pre {
  margin: 0;
  padding: 0.85rem 1rem;
  overflow-x: auto;
  background: transparent;
  font-size: 0.88rem;
  line-height: 1.55;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.code-content {
  display: block;
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
  white-space: pre;
  background: transparent;
  padding: 0;
  font-size: inherit;
}

/* Syntax Highlighting Tokens (VS Code / One Dark aesthetic) */
.tok-comment   { color: #6a737d; font-style: italic; }
.tok-string    { color: #98c379; }  /* green */
.tok-keyword   { color: #c678dd; font-weight: 600; }  /* purple / magenta */
.tok-builtin   { color: #e5c07b; }  /* gold / yellow */
.tok-function  { color: #61afef; }  /* blue / cyan */
.tok-number    { color: #d19a66; }  /* orange */
.tok-boolean   { color: #d19a66; font-weight: 600; }
.tok-decorator { color: #56b6c2; }  /* cyan */
.tok-tag       { color: #e06c75; font-weight: 600; }  /* red-pink */
.tok-attr      { color: #d19a66; }  /* orange */
.tok-property  { color: #e06c75; }  /* red-pink / object keys */
.tok-operator  { color: #56b6c2; }  /* cyan */
.tok-variable  { color: #e5c07b; }

/* Composer (Glass Input Dock) */
.composer {
  position: absolute;
  inset-inline: 0;
  inset-block-end: 0;
  z-index: 20;
  background: linear-gradient(to top, rgba(11, 15, 16, 0.96) 65%, rgba(11, 15, 16, 0));
  padding: 0.35rem 1.25rem max(0.75rem, env(safe-area-inset-bottom, 0px));
  pointer-events: none;
}

.composer > * {
  pointer-events: auto;
}

.composer-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  max-inline-size: 860px;
  margin: 0 auto 0.45rem;
}

.composer-box {
  max-inline-size: 860px;
  margin: 0 auto;
  background: rgba(19, 26, 28, 0.86);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 0.5rem 0.75rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.composer-box:focus-within {
  border-color: rgba(45, 212, 191, 0.55);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(45, 212, 191, 0.2);
}

.composer-main-row {
  display: flex;
  align-items: flex-end;
  gap: 0.4rem;
}

.composer-main-row textarea {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  resize: none;
  min-block-size: 32px;
  max-block-size: 136px;
  padding: 0.25rem 0.35rem;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
}

.composer-main-row textarea::placeholder {
  color: var(--text-dim);
}

.composer-icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 50%;
  color: var(--text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
  user-select: none;
}

.composer-icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.composer-icon-btn.is-recording {
  background: rgba(248, 113, 113, 0.2);
  color: var(--err);
  box-shadow: 0 0 0 calc(2px + var(--mic-level, 0) * 10px) rgba(248, 113, 113, 0.35);
  animation: mic-pulse 1.6s infinite ease-in-out;
}

@keyframes mic-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* Circular Glowing Turquoise Send Button */
.composer-send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--text-on-accent);
  border: none;
  cursor: pointer;
  box-shadow: var(--accent-glow);
  transition: background 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
}

.composer-send-btn:hover {
  background: var(--accent-bright);
  box-shadow: 0 0 18px rgba(94, 234, 212, 0.55);
}

.composer-send-btn:active {
  transform: scale(0.92);
}

.composer-send-btn.is-streaming {
  background: var(--err);
  color: #fff;
  box-shadow: 0 0 14px rgba(248, 113, 113, 0.35);
}

.composer-send-btn.is-streaming:hover {
  background: #ef4444;
  box-shadow: 0 0 18px rgba(248, 113, 113, 0.5);
}

.composer-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding-top: 0.35rem;
  border-top: 1px solid rgba(29, 41, 44, 0.7);
  margin-top: 0.2rem;
}

.composer-meta-left {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.45rem;
  min-inline-size: 0;
}

.model-badge, .model-badge-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  font-size: 0.76rem;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.04);
  padding: 0.24rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.model-badge-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border-user);
}

.model-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(45, 212, 191, 0.75);
  flex-shrink: 0;
}

/* Styled Search Switch Pill */
.search-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
  padding: 0.24rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
}

.search-switch:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.search-switch:has(input:checked) {
  background: var(--accent-soft);
  border-color: rgba(45, 212, 191, 0.45);
  color: var(--accent-bright);
  box-shadow: 0 0 10px rgba(45, 212, 191, 0.18);
}

/* Memory panel */
.memory-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
}

.memory-card h3, .memory-section-head h3 {
  margin: 0 0 0.4rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.memory-summary-text {
  margin: 0;
  font-size: 0.85rem;
  white-space: pre-wrap;
}

.memory-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.fact-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.fact-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
}

.fact-item.is-global {
  border-color: var(--border-user);
}

.fact-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-block-end: 0.25rem;
}

.fact-badge {
  font-size: 0.72rem;
  color: var(--accent);
}

.fact-text {
  margin: 0;
  font-size: 0.84rem;
}

.fact-empty {
  color: var(--text-muted);
  font-size: 0.84rem;
}

/* Buttons & Modals */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 0.45rem 0.9rem;
  font-size: 0.88rem;
  font-family: inherit;
  cursor: pointer;
  background: var(--bg-card);
  color: var(--text);
}

.btn-sm {
  padding: 0.28rem 0.65rem;
  font-size: 0.8rem;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text-on-accent);
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: var(--accent-glow);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #f87171;
}
.btn-danger:hover, .btn-danger:active {
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
}

.btn-ghost {
  background: transparent;
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.06);
}

.btn.is-recording {
  border-color: var(--err);
  color: var(--err);
}

.icon-btn {
  background: transparent;
  border: 0;
  color: var(--text);
  cursor: pointer;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  font-size: 1rem;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.icon-btn-muted {
  color: var(--text-muted);
}

.modal-dialog {
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  inline-size: min(500px, 92dvw);
}

.modal-dialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.modal-form h2 {
  margin: 0 0 0.25rem;
  font-size: 1.1rem;
}

.modal-form label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.modal-form input[type="text"],
.modal-form input[type="password"],
.modal-form input[type="email"],
.modal-form input[type="number"],
.modal-form select,
.modal-form textarea {
  inline-size: 100%;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-block-start: 0.5rem;
}

.modal-wide {
  inline-size: min(740px, 95dvw);
  max-block-size: 90dvh;
  overflow-y: auto;
}

.model-pill-btn {
  max-inline-size: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.models-modal {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.models-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.models-modal-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.models-section h3 {
  margin: 0 0 0.5rem;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.models-banner {
  padding: 0.55rem 0.8rem;
  border-radius: 8px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  font-size: 0.85rem;
}

.models-hint {
  margin: 0.4rem 0 0.75rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.gpu-grid, .aux-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.6rem;
}

.gpu-card, .aux-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
  font-size: 0.82rem;
}

.gpu-card-title, .aux-card-title {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  margin-block-end: 0.35rem;
}

.vram-bar {
  block-size: 8px;
  border-radius: 999px;
  background: var(--bg);
  overflow: hidden;
  margin-block: 0.35rem;
}

.vram-bar-fill {
  block-size: 100%;
  background: var(--accent);
}

.model-switch-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.model-switch-row select {
  flex: 1 1 auto;
  min-inline-size: 0;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.tune-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.tune-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.tune-grid input[type="text"],
.tune-grid input[type="number"],
.tune-grid select {
  inline-size: 100%;
  padding: 0.42rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}

.tune-full {
  grid-column: 1 / -1;
}

.tune-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  padding-block: 0.25rem;
}

.models-add-box {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
  background: rgba(255, 255, 255, 0.02);
  font-size: 0.85rem;
}

.models-add-box summary {
  cursor: pointer;
  font-weight: 600;
}

.mobile-only {
  display: none;
}

@media (max-width: 1024px) {
  .tablet-mobile-only {
    display: inline-flex;
  }
  .app-shell {
    grid-template-columns: 240px minmax(0, 1fr);
  }
  .sidebar-right {
    display: none;
  }
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(3px);
    z-index: 39;
    opacity: 0;
    transition: opacity 0.2s ease;
  }
  .app-shell.memory-open-mobile .sidebar-backdrop {
    display: block;
    opacity: 1;
  }
  .app-shell.memory-open-mobile .sidebar-right {
    display: flex;
    position: fixed;
    inset-block: 0;
    inset-inline-end: 0;
    inline-size: min(320px, 88dvw);
    z-index: 40;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.55);
    animation: slideInRight 0.2s ease-out;
  }
  @keyframes slideInRight {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
  }
}

@media (max-width: 767.98px) {
  .desktop-only {
    display: none !important;
  }
  .mobile-only {
    display: inline-flex;
  }
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar-left {
    display: none;
  }
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.68);
    backdrop-filter: blur(4px);
    z-index: 39;
    opacity: 0;
    transition: opacity 0.2s ease;
  }
  .app-shell.sidebar-open-mobile .sidebar-backdrop,
  .app-shell.memory-open-mobile .sidebar-backdrop {
    display: block;
    opacity: 1;
  }
  .app-shell.sidebar-open-mobile .sidebar-left {
    display: flex;
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    inline-size: min(300px, 86dvw);
    z-index: 40;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.6);
    animation: slideInLeft 0.2s ease-out;
  }
  @keyframes slideInLeft {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
  }

  /* Компактная мобильная шапка в одну строку ~54px */
  .chat-header {
    min-block-size: 54px;
    block-size: 54px;
    padding: 0.35rem 0.65rem;
    gap: 0.45rem;
  }
  .chat-header-left {
    gap: 0.45rem;
  }
  .header-brand-icon {
    display: block;
  }
  .header-menu-btn {
    padding: 0.3rem;
    min-inline-size: 36px;
    min-block-size: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .chat-title {
    font-size: 0.96rem;
  }
  .chat-header-actions {
    gap: 0.35rem;
    flex-wrap: nowrap;
  }
  .header-icon-action {
    padding: 0.35rem 0.45rem;
    min-inline-size: 36px;
    min-block-size: 36px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
  }
  .memory-count-badge {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--accent);
    background: var(--accent-soft);
    padding: 0.05rem 0.38rem;
    border-radius: 999px;
    line-height: 1.3;
  }

  /* Убираем боковую шкалу навигации и раскрываем ленту на всю ширину */
  .prompt-nav-rail,
  .prompt-nav-tooltip {
    display: none !important;
  }
  .messages-scroller {
    padding: 0.75rem 0.85rem;
    scroll-padding-bottom: 135px;
  }
  .messages-container {
    gap: 0.75rem;
    padding-block-end: 135px;
  }
  .msg-user {
    padding: 0.75rem 0.9rem;
    border-radius: 14px;
  }
  .msg-assistant {
    padding: 0.35rem 0 0.9rem;
  }

  /* Мобильный закреплённый Input Dock и кнопка Вниз */
  .composer {
    padding: 0.3rem 0.65rem max(0.55rem, env(safe-area-inset-bottom, 0px));
  }
  .composer-box {
    border-radius: 20px;
    padding: 0.42rem 0.6rem;
  }
  .composer-meta-left {
    gap: 0.35rem;
  }
  .scroll-to-bottom {
    inset-inline-end: 0.75rem;
    inset-block-end: calc(100% + 8px);
  }
}

@media (pointer: coarse) {
  .scroll-to-bottom::after,
  .composer-icon-btn::after {
    content: "";
    position: absolute;
    inset: -4px;
  }
}
