/* ── Reset & base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #0f0f13;
  --surface:      #1a1a23;
  --surface2:     #22222e;
  --border:       #2e2e3e;
  --accent:       #7c6af7;
  --accent-hover: #9282ff;
  --text:         #e8e8f0;
  --text-muted:   #888899;
  --user-bg:      #1f1b4a;
  --user-border:  #4a3fa0;
  --ai-bg:        #1a1a23;
  --danger:       #e05454;
  --success:      #4caf7f;
  --warn:         #e09a30;
  --radius:       10px;
  --radius-sm:    6px;
  --font:         -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono:         'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --sidebar-w:    280px;
}

html, body {
  height: 100%;
  height: 100dvh;             /* dynamic: shrinks when browser chrome appears */
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  overflow: hidden;
}

/* ── Layout ─────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  height: 100vh;              /* fallback */
  height: 100dvh;             /* modern: dynamic viewport, respects browser UI */
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width .2s, min-width .2s;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar.hidden {
  width: 0;
  min-width: 0;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.logo {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .3px;
  color: var(--accent);
}

.sidebar-section {
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  font-size: 13px;
}

.stat-key { color: var(--text-muted); }
.stat-val { font-variant-numeric: tabular-nums; font-weight: 600; }

.input-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.text-input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  color: var(--text);
  font-size: 12px;
  outline: none;
  transition: border-color .15s;
}
.text-input:focus { border-color: var(--accent); }
.text-input.narrow { width: 60px; flex: none; }

.btn-sm {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  transition: background .15s;
}
.btn-sm.primary   { background: var(--accent); color: #fff; }
.btn-sm.primary:hover  { background: var(--accent-hover); }
.btn-sm.secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-sm.secondary:hover { background: var(--border); }
.btn-sm.danger    { background: var(--danger); color: #fff; }
.btn-sm.danger:hover { background: #c04444; }

.upload-label {
  display: inline-block;
  cursor: pointer;
}

.log-area {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  max-height: 120px;
  overflow-y: auto;
  margin-top: 6px;
  line-height: 1.5;
}

.docs-section { flex: 0 0 auto; }

.doc-list {
  max-height: 180px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.doc-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 6px;
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}
.doc-item:last-child { border-bottom: none; }
.doc-item:hover { background: var(--surface2); }

.doc-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: default;
}

.doc-del {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 2px;
  font-size: 14px;
  line-height: 1;
  transition: color .1s;
}
.doc-del:hover { color: var(--danger); }

.refresh-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 0;
}
.refresh-btn:hover { color: var(--text); }

.setting-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}
.setting-row label { font-size: 12px; color: var(--text-muted); }
.setting-row select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  color: var(--text);
  font-size: 12px;
  outline: none;
}

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

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar-title {
  flex: 1;
  font-weight: 600;
  font-size: 15px;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  line-height: 1;
  transition: color .15s, background .15s;
}
.icon-btn:hover { color: var(--text); background: var(--surface2); }

/* ── Messages ───────────────────────────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.welcome {
  margin: auto;
  text-align: center;
  max-width: 420px;
  color: var(--text-muted);
}
.welcome-icon { font-size: 52px; margin-bottom: 16px; }
.welcome h2 { font-size: 20px; color: var(--text); margin-bottom: 10px; }
.welcome p  { line-height: 1.6; }

.msg {
  display: flex;
  flex-direction: column;
  max-width: 820px;
  animation: fadeIn .2s ease;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.msg.user  { align-self: flex-end; align-items: flex-end; }
.msg.ai    { align-self: flex-start; align-items: flex-start; }

.msg-role {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 5px;
  color: var(--text-muted);
}

.msg.user  .msg-role { color: var(--accent); }

.msg-img {
  max-width: 260px;
  max-height: 180px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  object-fit: contain;
  margin-bottom: 6px;
  display: block;
}

.msg-bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.7;
  max-width: 100%;
  word-break: break-word;
}

.msg.user .msg-bubble {
  background: var(--user-bg);
  border: 1px solid var(--user-border);
  border-bottom-right-radius: 3px;
}

.msg.ai .msg-bubble {
  background: transparent;
  border: none;
  padding-left: 2px;
  border-bottom-left-radius: 3px;
}

.msg-bubble code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: rgba(255,255,255,.07);
  padding: 1px 5px;
  border-radius: 4px;
}

.msg-bubble pre {
  background: #0d0d14;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  overflow-x: auto;
  margin: 8px 0;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
}

.msg-bubble pre code {
  background: none;
  padding: 0;
  border-radius: 0;
}

.msg-bubble p   { margin: 6px 0; }
.msg-bubble ul,
.msg-bubble ol  { padding-left: 20px; margin: 6px 0; }
.msg-bubble li  { margin: 3px 0; }
.msg-bubble h1,
.msg-bubble h2,
.msg-bubble h3  { margin: 12px 0 6px; color: var(--text); }

.sources {
  margin-top: 8px;
}

.sources-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 3px 10px 3px 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .5px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.sources-toggle:hover {
  background: var(--surface2);
  color: var(--text);
}

.sources-caret {
  display: inline-block;
  font-size: 9px;
  transition: transform .2s;
  color: var(--accent);
}
.sources:not(.sources--collapsed) .sources-caret {
  transform: rotate(90deg);
}

.sources-count {
  background: var(--surface2);
  border-radius: 8px;
  padding: 1px 6px;
  font-size: 10px;
}

.sources-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 6px;
}
.sources--collapsed .sources-list {
  display: none;
}

.sources-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.source-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 11.5px;
  color: var(--text-muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-chip .score {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.typing-indicator {
  display: block;
  width: 120px;
  height: 2px;
  border-radius: 2px;
  margin: 10px 2px;
  background: var(--border);
  overflow: hidden;
  position: relative;
}
.typing-indicator::after {
  content: '';
  position: absolute;
  top: 0; left: -60%;
  width: 60%;
  height: 100%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: typing-sweep 1.2s ease-in-out infinite;
}
.typing-indicator span { display: none; }
@keyframes typing-sweep {
  0%   { left: -60%; }
  100% { left: 110%;  }
}

/* ── Input area ─────────────────────────────────────────────────────────── */
.input-area {
  padding: 14px 20px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 10px 10px 14px;
  transition: border-color .15s;
}
.input-wrapper:focus-within { border-color: var(--accent); }

.input-wrapper.dragover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, transparent); }

.image-preview {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  border-radius: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  max-height: 48px;
}
.image-preview img { width: 48px; height: 36px; object-fit: cover; border-radius: 6px; }
.image-preview .icon-btn { padding: 2px 6px; font-size: 13px; }

textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 14.5px;
  /* Allow vertical resize so users can expand the input area */
  resize: vertical;
  outline: none;
  line-height: 1.6;
  min-height: 36px;
  max-height: 360px;
  overflow-y: auto;
  scrollbar-width: thin;
}
textarea::placeholder { color: var(--text-muted); }

.tools-toggle-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 15px;
  color: var(--text-muted);
  transition: background .15s, border-color .15s, color .15s;
}
.tools-toggle-btn:hover { border-color: var(--accent); color: var(--accent); }
.tools-toggle-btn.active {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  border-color: var(--accent);
  color: var(--accent);
}
.pipeline-toggle-btn.active {
  background: color-mix(in srgb, #a970ff 18%, transparent);
  border-color: #a970ff;
  color: #a970ff;
}

/* Pipeline-info bar shown inside AI message when pipeline mode is active */
.pipeline-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  padding: 4px 8px;
  margin-bottom: 6px;
  background: color-mix(in srgb, #a970ff 10%, transparent);
  border-left: 2px solid #a970ff;
  border-radius: 4px;
}
.pi-label { font-weight: 600; color: #a970ff; }
.pi-specs { display: flex; flex-wrap: wrap; gap: 4px; }
.pi-chip {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text-muted);
  white-space: nowrap;
}
.pi-chip.pi-running { border-color: #f0a500; color: #f0a500; }
.pi-chip.pi-done    { border-color: var(--success); color: var(--success); }
.pi-quality { margin-left: auto; font-size: 10px; }
.pi-q-ok  { color: var(--success); }
.pi-q-med { color: #f0a500; }
.pi-q-bad { color: var(--danger, #e05252); }

.mic-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-muted);
  transition: background .15s, border-color .15s, color .15s;
}
.mic-btn svg { width: 16px; height: 16px; }
.mic-btn:hover { border-color: var(--accent); color: var(--accent); }
.mic-btn.hidden { display: none; }
.mic-btn.recording {
  border-color: var(--danger);
  color: var(--danger);
  animation: mic-pulse 1s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { background: transparent; }
  50%       { background: color-mix(in srgb, var(--danger) 18%, transparent); }
}

.send-btn {
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
}
.send-btn:hover  { background: var(--accent-hover); }
.send-btn:disabled { background: var(--border); cursor: not-allowed; }
.send-btn svg { width: 16px; height: 16px; color: #fff; }

.input-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  text-align: right;
}

/* ── Scrollbar ──────────────────────────────────────────────────────────── */
/* Base: slightly larger, rounded thumb for better visibility */
::-webkit-scrollbar       { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,0.06); border-radius: 8px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.06); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.12); }

/* Messages pane: subtle dark thumb matching theme */
.messages::-webkit-scrollbar { width: 10px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.06); border-radius: 8px; }
.messages::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.12); }

/* Textarea scrollbars: slightly narrower */
textarea::-webkit-scrollbar { width: 8px; height: 8px; }
textarea::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 6px; }
textarea::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.16); }

/* ── Notification toast ──────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 13px;
  z-index: 9999;
  animation: toastIn .2s ease;
  max-width: 340px;
}
.toast.success { border-color: var(--success); color: var(--success); }
.toast.error   { border-color: var(--danger);  color: var(--danger);  }
.toast.info    { border-color: var(--accent);  }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ── Toggle switch ───────────────────────────────────────────────────────── */
.toggle-label-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  user-select: none;
}
.toggle-label-wrap input[type=checkbox] { display: none; }
.toggle-track {
  width: 30px; height: 16px;
  background: var(--border);
  border-radius: 8px;
  position: relative;
  transition: background .2s;
  flex-shrink: 0;
}
.toggle-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #fff;
  transition: transform .2s;
}
.toggle-label-wrap input:checked ~ .toggle-track { background: var(--accent); }
.toggle-label-wrap input:checked ~ .toggle-track .toggle-thumb { transform: translateX(14px); }

/* ── Tool call / result blocks ───────────────────────────────────────────── */
.tool-block {
  font-size: 12px;
  border-radius: 6px;
  margin: 6px 0;
  overflow: hidden;
  border: 1px solid var(--border);
}
.tool-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--surface2);
  cursor: pointer;
  user-select: none;
}
.tool-icon  { font-size: 13px; }
.tool-name  { font-weight: 600; color: var(--accent); flex: 1; }
.tool-caret { color: var(--text-muted); font-size: 10px; transition: transform .15s; }
.tool-block.open .tool-caret { transform: rotate(90deg); }
.tool-body {
  display: none;
  padding: 8px 10px;
  background: var(--surface);
  font-family: monospace;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-muted);
  max-height: 260px;
  overflow-y: auto;
}
.tool-block.open .tool-body { display: block; }
.tool-result-line {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px 3px;
  background: var(--surface2);
  border-top: 1px solid var(--border);
  font-size: 11px;
  font-family: monospace;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tool-result-ok    { color: var(--success); flex-shrink: 0; }
.tool-result-error { color: var(--danger);  flex-shrink: 0; }
.tool-result-text  { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Session list in sidebar ──────────────────────────────────────────────── */
.sessions-section { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.session-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.no-sessions { color: var(--text-muted); font-size: 12px; padding: 6px 0; }
.session-item {
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .12s;
  border: 1px solid transparent;
}
.session-item:hover  { background: var(--surface2); }
.session-item.active { background: rgba(108,142,245,.15); border-color: rgba(108,142,245,.35); }
.session-item-title  { font-size: 13px; color: var(--text); line-height: 1.35; word-break: break-word; }
.session-item.active .session-item-title { color: var(--accent); }
.session-item-date   { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ── New Session button in topbar ────────────────────────────────────────── */
.new-session-btn {
  background: rgba(108,142,245,.15);
  border: 1px solid rgba(108,142,245,.4);
  color: var(--accent);
  border-radius: 6px;
  padding: 5px 13px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.new-session-btn:hover { background: rgba(108,142,245,.28); border-color: var(--accent); }

/* ── Admin link in sidebar ─────────────────────────────────────────────────── */
.sidebar-admin-link {
  display: block;
  margin: auto 0 0;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 12px;
  transition: color .15s, background .15s;
}
.sidebar-admin-link:hover { color: var(--accent); background: var(--surface2); }

/* ── Mobile sidebar backdrop ────────────────────────────────────────────────── */
.sidebar-backdrop { display: none; }

/* ── Mobile / PWA responsive ────────────────────────────────────────────────── */
@media (max-width: 767px) {

  /* Fill exactly the visible area on Android Chrome & iOS Safari */
  html, body {
    height: -webkit-fill-available; /* iOS Safari fallback */
  }
  .layout {
    height: -webkit-fill-available; /* iOS Safari fallback */
    height: 100dvh;
    /* Lock layout to screen – no body scroll */
    position: fixed;
    inset: 0;
  }

  /* main must shrink so messages + input stay within the viewport */
  .main {
    min-height: 0;
    overflow: hidden;
  }
  .messages {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Sidebar: fixed overlay drawer that slides in from the left */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100%;
    height: 100dvh;
    width: 80vw !important;
    min-width: 0 !important;
    max-width: 320px;
    z-index: 200;
    transform: translateX(-105%);
    transition: transform .25s cubic-bezier(.4,0,.2,1) !important;
    box-shadow: 4px 0 32px rgba(0,0,0,.6);
    overflow-y: auto;
    overflow-x: hidden;
  }

  /* Hidden state on mobile = stay off-screen (don't collapse to width 0) */
  .sidebar.hidden {
    width: 80vw !important;
    min-width: 0 !important;
    max-width: 320px;
    overflow: auto !important;
    transform: translateX(-105%) !important;
  }

  /* When opened on mobile */
  .sidebar.mobile-open {
    transform: translateX(0) !important;
  }

  /* Semi-transparent backdrop behind drawer */
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 199;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s;
  }
  .sidebar-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
  }

  /* Always show the open-sidebar (hamburger) button on mobile */
  #showSidebarBtn {
    display: flex !important;
  }

  /* Topbar: add padding-top for iOS status bar in standalone PWA mode */
  .topbar {
    padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  }
  .topbar-title { font-size: 14px; }

  .new-session-btn {
    font-size: 12px;
    padding: 5px 10px;
  }

  /* Messages: tighter on small screen */
  .messages {
    padding: 14px 12px;
    gap: 14px;
  }
  .msg { max-width: 96%; }
  .msg-bubble { padding: 10px 13px; }

  /* Input: safe area for Android nav bar + iOS home indicator */
  .input-area {
    padding: 10px 12px;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }

  /* Hide keyboard hint on mobile */
  .input-hint { display: none; }

  /* Welcome screen: compact */
  .welcome-icon { font-size: 40px; margin-bottom: 12px; }
  .welcome h2   { font-size: 17px; }
  .welcome p    { font-size: 13px; }
}

/* ── GPS status badge ───────────────────────────────────────────────────────── */
.gps-badge {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  cursor: default;
  transition: background .4s;
}
.gps-off       { display: none; }
.gps-denied    { background: var(--danger); }
.gps-acquiring { background: var(--warn); animation: gps-pulse 1.4s ease-in-out infinite; }
.gps-active    { background: var(--success); }
@keyframes gps-pulse { 0%,100% { opacity:1; } 50% { opacity:.25; } }

/* ── Standalone PWA tweaks (home-screen installed) ──────────────────────────── */
@media (display-mode: standalone) {
  .topbar {
    padding-top: max(10px, env(safe-area-inset-top));
  }
  .input-area {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}
