:root {
  --bg: #0f1117;
  --bg2: #1a1d27;
  --bg3: #22263a;
  --border: #2e3249;
  --text: #e2e4ef;
  --text-dim: #7b82a8;
  --accent: #6c8ef5;
  --accent-dim: #3d5099;
  --green: #4caf7d;
  --red: #e05252;
  --yellow: #e0a632;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "SF Mono", "Fira Code", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  font-size: 14px;
  line-height: 1.6;
}

/* ── Sidebar ── */
.sidebar {
  width: 200px;
  min-width: 200px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 0 4px;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px 20px;
}

.sidebar-logo-img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  border-radius: 6px;
  flex-shrink: 0;
}

.sidebar-logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.sidebar-logo-name {
  font-size: 17px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.5px;
}

.sidebar-logo-version {
  color: var(--text-dim);
  font-weight: 400;
  font-size: 10px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  vertical-align: middle;
}

.sidebar-logo-app {
  font-size: 10px;
  color: var(--text-dim);
  font-weight: 400;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  margin-top: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text-dim);
  text-decoration: none;
  transition: all 0.15s;
  font-size: 13px;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--bg3); color: var(--accent); }
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }

.sidebar-bottom { margin-top: auto; padding: 4px 0 0; border-top: 1px solid var(--border); }

#pause-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 12px;
  padding: 6px 14px;
  width: calc(100% - 24px);
  border-radius: var(--radius);
  border: 1px solid rgba(224, 166, 50, 0.35);
  background: rgba(224, 166, 50, 0.08);
  color: var(--yellow);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
}
#pause-btn:hover { background: rgba(224, 166, 50, 0.18); border-color: rgba(224, 166, 50, 0.55); }
#pause-btn.paused {
  border-color: rgba(76, 175, 125, 0.35);
  background: rgba(76, 175, 125, 0.08);
  color: var(--green);
}
#pause-btn.paused:hover { background: rgba(76, 175, 125, 0.18); border-color: rgba(76, 175, 125, 0.55); }

.sidebar-user {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px; margin-top: 2px; font-size: 11px; color: var(--muted);
}
.sidebar-user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 120px; }
.sidebar-user-logout { color: var(--muted); display: flex; align-items: center; flex-shrink: 0; opacity: 0.7; transition: opacity 0.15s; }
.sidebar-user-logout:hover { opacity: 1; color: var(--accent); }

/* ── Personality setup nag banner ── */
.nag-banner {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 20px; background: #7c5a00; color: #fde68a;
  font-size: 13px; gap: 12px; flex-shrink: 0;
}
.nag-link { color: #fde68a; font-weight: 600; text-decoration: underline; }
.nag-link:hover { color: #fff; }
.nag-dismiss {
  background: none; border: none; color: #fde68a; font-size: 18px;
  cursor: pointer; line-height: 1; padding: 0 4px; opacity: 0.8;
}
.nag-dismiss:hover { opacity: 1; }

/* ── Main content ── */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* ── Chat ── */
.chat-container { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message { display: flex; flex-direction: column; max-width: 760px; }
.message.user { align-self: flex-end; align-items: flex-end; }
.message.assistant { align-self: flex-start; align-items: flex-start; }

.message-bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user .message-bubble {
  background: var(--accent-dim);
  color: var(--text);
  border-bottom-right-radius: 2px;
}

.message.assistant .message-bubble {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 2px;
}

/* Markdown headings */
.message-bubble .md-h { margin: 10px 0 4px; font-weight: 600; line-height: 1.3; }
.message-bubble h1.md-h { font-size: 1.4em; }
.message-bubble h2.md-h { font-size: 1.2em; }
.message-bubble h3.md-h { font-size: 1.05em; }
.message-bubble h4.md-h, .message-bubble h5.md-h, .message-bubble h6.md-h { font-size: 1em; }
.message-bubble .md-h:first-child { margin-top: 0; }

/* Markdown lists */
.message-bubble .md-list { margin: 6px 0; padding-left: 22px; }
.message-bubble .md-list li { margin: 2px 0; }

/* Markdown tables */
.md-table-wrap { overflow-x: auto; margin: 8px 0; }
.md-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.md-table th, .md-table td { border: 1px solid var(--border); padding: 6px 12px; text-align: left; vertical-align: top; }
.md-table thead th { background: var(--bg3); font-weight: 600; }
.md-table tbody tr:nth-child(even) { background: color-mix(in srgb, var(--bg3) 40%, transparent); }

/* Copy response button (below assistant bubble, visible on hover) */
.copy-response-btn {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
  align-self: flex-start;
  opacity: 0;
  transition: opacity 0.15s;
}
.message.assistant:hover .copy-response-btn,
.copy-response-btn:focus { opacity: 1; }

/* Fenced code blocks inside chat bubbles */
.code-block {
  margin: 8px 0;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
  font-size: 13px;
}
.code-block:first-child { margin-top: 0; }
.code-block:last-child  { margin-bottom: 0; }

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 10px;
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  min-height: 30px;
}
.code-lang {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
}
.copy-code-btn {
  font-size: 11px !important;
  padding: 2px 8px !important;
}
.code-block pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  background: var(--bg);
  white-space: pre-wrap;
  word-break: break-all;
}
.code-block code {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  color: var(--text);
}

/* Inline code */
.inline-code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
}

.message-meta {
  font-size: 11px;
  color: var(--text-dim);
  padding: 4px 4px 0;
}

/* Tool indicators */
.tool-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-dim);
  align-self: flex-start;
  max-width: 500px;
}

.tool-indicator .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s infinite;
  flex-shrink: 0;
}

.tool-indicator.done .dot { background: var(--green); animation: none; }
.tool-indicator.error .dot { background: var(--red); animation: none; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* Confirmation modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 480px;
  width: 90%;
}

.modal h3 { margin-bottom: 8px; color: var(--yellow); font-size: 15px; }
.modal .modal-desc {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 12px;
  margin: 12px 0 20px;
  white-space: pre-wrap;
  word-break: break-word;
}

.modal-buttons { display: flex; gap: 10px; justify-content: flex-end; }

/* Input bar */
.chat-input-wrap {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  padding: 10px 14px;
  resize: none;
  min-height: 42px;
  max-height: 200px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.15s;
}

.chat-input:focus { border-color: var(--accent-dim); }

/* ── Buttons ── */
.btn {
  padding: 8px 16px;
  border-radius: var(--radius);
  border: none;
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  transition: opacity 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.4; cursor: default; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-danger  { background: var(--red);    color: #fff; }
.btn-ghost   { background: var(--bg3);    color: var(--text); border: 1px solid var(--border); }
.btn-small   { padding: 4px 10px; font-size: 12px; }

/* ── Generic page content ── */
.page { padding: 32px; overflow-y: auto; flex: 1; }
.page h1 { font-size: 20px; margin-bottom: 24px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--text-dim); font-weight: 500; font-size: 11px; text-transform: uppercase; }
tr:hover td { background: var(--bg2); }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.form-input {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 8px 12px;
  outline: none;
}
.form-input:focus { border-color: var(--accent-dim); }

/* Badges */
.badge {
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
}
.badge-green { background: rgba(76,175,125,0.15); color: var(--green); }
.badge-red   { background: rgba(224,82,82,0.15);  color: var(--red); }
.badge-blue  { background: rgba(108,142,245,0.15); color: var(--accent); }

/* Status bar */
.status-bar {
  padding: 6px 24px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  gap: 16px;
  align-items: center;
}

.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--green);
  display: inline-block;
}

.status-dot.offline { background: var(--red); }
.status-dot.paused  { background: var(--yellow); }

/* Scrollbars */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Typing indicator */
.typing { display: flex; gap: 4px; align-items: center; padding: 4px 0; }
.typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: bounce 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0.6); } 40% { transform: scale(1); } }

/* Filter bar */
.filter-bar { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; align-items: flex-end; }
.filter-bar .form-input { width: auto; }

/* Tab buttons */
.tab-btn {
  padding: 8px 20px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-btn:hover:not(.active) { color: var(--text); }

/* Metadata cards */
.meta-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; }
.meta-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.meta-value { font-size: 14px; font-weight: 500; word-break: break-all; }

/* Pagination */
.pagination { display: flex; gap: 6px; justify-content: flex-end; margin-top: 16px; }
.page-btn {
  padding: 4px 10px;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
.page-btn.active { background: var(--accent-dim); color: var(--text); border-color: var(--accent-dim); }
.page-btn:hover:not(.active) { border-color: var(--accent-dim); }

/* ── Settings page ───────────────────────────────────────────────────────── */
.settings-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
  letter-spacing: 0.2px;
}

/* ── Model picker modal list items ────────────────────────────────────────── */
.mp-item { padding: 7px 14px; font-size: 13px; cursor: pointer; border-radius: 4px; color: var(--text-dim); }
.mp-item:hover, .mp-item.mp-focused { background: var(--bg3); color: var(--text); }
.mp-item.mp-selected { color: var(--accent); }

/* ── Help page ────────────────────────────────────────────────────────────── */
.help-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: 100%;
}

.help-toc {
  width: 220px;
  min-width: 220px;
  padding: 24px 16px;
  border-right: 1px solid var(--border);
  background: var(--bg2);
  overflow-y: auto;
  flex-shrink: 0;
}

.toc-list {
  list-style: none;
  font-size: 13px;
  line-height: 1.4;
}

.toc-list li { margin-bottom: 2px; }

.toc-list a {
  display: block;
  padding: 4px 8px;
  color: var(--text-dim);
  text-decoration: none;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.toc-list a:hover { color: var(--text); background: var(--bg3); }
.toc-list a.toc-active { color: var(--accent); background: rgba(108,142,245,0.08); }

.toc-list ul {
  list-style: none;
  padding-left: 12px;
  margin-top: 2px;
}

.toc-list ul a { font-size: 12px; }

.help-content {
  flex: 1;
  overflow-y: auto;
  padding: 32px 40px;
  max-width: 900px;
}

.help-content section {
  margin-bottom: 48px;
  scroll-margin-top: 32px;
}

.help-content h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.help-content h2 {
  font-size: 15px;
  font-weight: 600;
  margin-top: 24px;
  margin-bottom: 10px;
  color: var(--text);
  scroll-margin-top: 32px;
}

.help-content h3 {
  font-size: 13px;
  font-weight: 600;
  margin-top: 20px;
  margin-bottom: 8px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.help-content p { margin-bottom: 10px; line-height: 1.7; }

.help-content ul, .help-content ol {
  padding-left: 20px;
  margin-bottom: 10px;
  line-height: 1.7;
}

.help-content li { margin-bottom: 4px; }

.help-content dl { margin-bottom: 12px; }
.help-content dt { font-weight: 600; margin-top: 10px; color: var(--text); }
.help-content dd { padding-left: 16px; color: var(--text-dim); }

.help-content pre {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-family: var(--mono);
  font-size: 12px;
  overflow-x: auto;
  margin: 10px 0;
  white-space: pre-wrap;
  word-break: break-all;
}

.help-content code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
}

.help-content pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
}

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

.help-content kbd {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  color: var(--text);
}

.help-note {
  background: rgba(108,142,245,0.08);
  border: 1px solid rgba(108,142,245,0.25);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 13px;
}

/* Help API table — more compact than the default table */
.help-api-table { font-size: 12px; margin-bottom: 16px; }
.help-api-table th { font-size: 11px; }
.help-api-table td { padding: 7px 12px; vertical-align: top; }

/* HTTP method badges */
.http-get  { color: var(--green);  font-weight: 700; font-family: var(--mono); font-size: 11px; }
.http-post { color: var(--accent); font-weight: 700; font-family: var(--mono); font-size: 11px; }
.http-put  { color: var(--yellow); font-weight: 700; font-family: var(--mono); font-size: 11px; }
.http-del  { color: var(--red);    font-weight: 700; font-family: var(--mono); font-size: 11px; }

/* ── Help TOC collapse toggle (mobile) ───────────────────────────────────── */
.toc-toggle {
  display: none;
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 14px;
  text-align: left;
  cursor: pointer;
}
@media (max-width: 768px) {
  .toc-toggle { display: block; }
}

/* ── Prompt mode toggle ───────────────────────────────────────────────────── */
.prompt-mode-toggle { display: flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.pm-btn { flex: 1; padding: 6px 8px; font-size: 12px; border: none; border-right: 1px solid var(--border); background: var(--bg2); color: var(--text-dim); cursor: pointer; transition: background 0.15s, color 0.15s; }
.pm-btn:last-child { border-right: none; }
.pm-btn.active { background: var(--accent); color: #fff; }
.pm-btn:hover:not(.active) { background: var(--bg3); color: var(--text); }

/* ── Usage page stat cards ────────────────────────────────────────────────── */
.stat-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; }
.stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-dim); margin-bottom: 6px; }
.stat-value { font-size: 22px; font-weight: 700; color: var(--text); font-family: var(--mono); }

/* ── Responsive layout ────────────────────────────────────────────────────── */
.app-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 150;
}

.mobile-header {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
}

.hamburger-btn {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  border-radius: 4px;
  transition: background 0.15s;
}
.hamburger-btn:hover { background: var(--bg3); }
.hamburger-btn svg { width: 20px; height: 20px; }

.mobile-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

.mobile-install-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
  margin-left: auto;
}
.mobile-install-btn:hover { background: var(--bg3); color: var(--accent); }

/* ── Mobile tab select (replaces tab bar on small screens) ───────────────── */
.tab-select-wrap {
  display: none;
  position: relative;
  margin-bottom: 24px;
}

.tab-select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 36px 10px 14px;
  cursor: pointer;
  outline: none;
}
.tab-select:focus { border-color: var(--accent-dim); }

.tab-select-arrow {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
  font-size: 13px;
}

@media (max-width: 768px) {
  .tab-select-wrap { display: block; }
}

/* ── Tab bar (settings + others) ─────────────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }
.tab-bar .tab-btn { flex-shrink: 0; }

/* ── Usage page header ────────────────────────────────────────────────────── */
.usage-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  gap: 12px;
  flex-wrap: wrap;
}
.usage-header-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

@media (max-width: 768px) {
  html, body { overflow: hidden; }

  .sidebar {
    position: fixed;
    left: -220px;
    top: 0;
    height: 100%;
    z-index: 200;
    transition: left 0.25s ease;
    overflow-y: auto;
    width: 200px;
  }

  .sidebar.open { left: 0; }

  .sidebar-overlay.visible { display: block; }

  .mobile-header { display: flex; }

  .app-body { width: 100%; }

  /* Page padding */
  .page { padding: 16px; }
  .page h1 { margin-bottom: 16px; }

  /* Chat */
  .chat-messages { padding: 12px 16px; }
  .status-bar { padding: 6px 12px; flex-wrap: wrap; gap: 6px; font-size: 10px; }

  /* Prevent iOS auto-zoom on input focus (triggered when font-size < 16px) */
  input, textarea, select, .form-input, .chat-input, .tab-select {
    font-size: 16px !important;
  }

  /* Chat input — textarea full-width row, buttons on second row */
  .chat-input-wrap {
    flex-wrap: wrap;
    padding: 8px 12px;
    gap: 6px;
  }
  .chat-input-wrap .chat-input {
    flex: 1 1 100%;
    min-height: 80px;
    max-height: 160px;
    order: 1;
  }
  #attach-btn { order: 2; }
  #clear-btn  { order: 3; }
  #send-btn   { order: 4; margin-left: auto; }

  /* Modals slide up from bottom */
  .modal-overlay { align-items: flex-end; }
  .modal {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: var(--radius) var(--radius) 0 0 !important;
    margin: 0;
  }

  /* Help page stacks with collapsible TOC */
  .help-layout { flex-direction: column; overflow: auto; }
  .help-toc {
    width: 100%; min-width: unset;
    border-right: none; border-bottom: 1px solid var(--border);
    overflow: hidden;
    padding: 12px 16px;
  }
  .help-toc .toc-list, .help-toc .form-input { display: none; }
  .help-toc.toc-collapsed .toc-list,
  .help-toc.toc-collapsed .form-input { display: none; }
  .help-toc:not(.toc-collapsed) .toc-list,
  .help-toc:not(.toc-collapsed) .form-input { display: block; margin-top: 10px; }
  .help-content { padding: 20px 16px; }

  /* Tab bar scrollable */
  .tabs { overflow-x: auto; flex-wrap: nowrap; }

  /* Filter bar: inputs fill available width, pairs stack two-per-row */
  .filter-bar { gap: 6px; }
  .filter-bar .form-group { flex: 1 1 calc(50% - 6px); min-width: 120px; }
  .filter-bar .form-input { width: 100% !important; min-width: 0; box-sizing: border-box; }
  .filter-bar-actions { flex: 1 1 100%; }

  /* Chats page: action buttons wrap below content on narrow screens */
  .chat-row { flex-wrap: wrap !important; }
  .chat-row-actions { flex: 1 1 100% !important; padding-left: 27px; }

  /* Agent detail header: name + buttons wrap */
  .agent-detail-header { flex-wrap: wrap !important; gap: 12px; }
  .agent-detail-header > div:last-child { flex-shrink: 0; }

  /* Fullscreen prompt editor on mobile */
  .pe-kbd-hint { display: none; }
  #pe-textarea { padding: 16px !important; font-size: 14px !important; }
}
