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

:root {
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  /* ---- Light theme ---- */
  /* Main content */
  --bg:             #FFFFFF;
  --bg-secondary:   #F7F7F8;
  --bg-input:       #FFFFFF;
  --bg-msg-user:    #F4F4F5;
  --bg-code:        #F7F7F8;
  --bg-thinking:    #F9F7FF;
  --border:         #E5E5E6;
  --border-focus:   #6366F1;
  --text:           #111111;
  --text-dim:       #666666;
  --text-dimmer:    #AAAAAA;
  --accent:         #6366F1;
  --accent-hover:   #4F52D8;
  --accent-light:   rgba(99,102,241,.10);
  --danger:         #DC2626;
  --send-bg:        #111111;
  --send-hover:     #333333;
  --shadow:         0 2px 12px rgba(0,0,0,.07);
  --shadow-lg:      0 8px 40px rgba(0,0,0,.12);
  --thinking-border:#6366F1;
  --scrollbar:      rgba(0,0,0,.12);

  /* Sidebar is always dark regardless of theme */
  --sb-bg:          #171717;
  --sb-border:      rgba(255,255,255,.07);
  --sb-text:        #ECECEC;
  --sb-text-dim:    #888888;
  --sb-hover:       rgba(255,255,255,.06);
  --sb-active:      rgba(255,255,255,.11);
  --sb-new-btn:     #6366F1;
  --sb-new-hover:   #4F52D8;
}

[data-theme="dark"] {
  --bg:             #1A1A1B;
  --bg-secondary:   #222224;
  --bg-input:       #222224;
  --bg-msg-user:    #2A2A2C;
  --bg-code:        #141415;
  --bg-thinking:    #1E1C2C;
  --border:         #2E2E30;
  --border-focus:   #818CF8;
  --text:           #E8E8EA;
  --text-dim:       #999999;
  --text-dimmer:    #555557;
  --accent:         #818CF8;
  --accent-hover:   #6366F1;
  --accent-light:   rgba(129,140,248,.12);
  --danger:         #F87171;
  --send-bg:        #818CF8;
  --send-hover:     #6366F1;
  --shadow:         0 2px 12px rgba(0,0,0,.3);
  --shadow-lg:      0 8px 40px rgba(0,0,0,.5);
  --thinking-border:#818CF8;
  --scrollbar:      rgba(255,255,255,.10);

  --sb-bg:          #111112;
  --sb-border:      rgba(255,255,255,.05);
  --sb-text:        #E8E8EA;
  --sb-text-dim:    #777779;
  --sb-hover:       rgba(255,255,255,.05);
  --sb-active:      rgba(255,255,255,.09);
  --sb-new-btn:     #6366F1;
  --sb-new-hover:   #4F52D8;
}

/* iOS Safari фикс: убираем bounce-scroll на корне */
html {
  height: 100%;
  height: -webkit-fill-available;
  overscroll-behavior: none;
}
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  height: 100%;
  height: -webkit-fill-available;
  overflow: hidden;
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 4px; }

/* ===== App layout ===== */
.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  height: calc(var(--real-vh, 1vh) * 100);
  overflow: hidden;
}

/* ===== Shared button inside sidebar ===== */
.nav-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: none;
  border: none;
  color: var(--sb-text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, color .12s;
  flex-shrink: 0;
}
.nav-btn:hover { background: var(--sb-hover); color: var(--sb-text); }
.nav-btn:active { background: var(--sb-active); }

/* ===== Sidebar (always dark) ===== */
.sidebar {
  width: 252px;
  min-width: 252px;
  background: var(--sb-bg);
  border-right: 1px solid var(--sb-border);
  display: flex;
  flex-direction: column;
  transition: width .22s ease, min-width .22s ease;
  overflow: hidden;
  flex-shrink: 0;
}
.sidebar.collapsed { width: 0; min-width: 0; }

.sidebar-top {
  padding: 10px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

/* Header row: logo (left) + toggle button (right) */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--sb-border);
}

/* Floating burger when sidebar is collapsed (desktop) */
.sidebar.collapsed #sidebarToggle {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 800;
  color: var(--text);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

/* Sidebar footer: theme toggle aligned to the right */
.sidebar-footer {
  padding: 8px 12px max(14px, calc(env(safe-area-inset-bottom, 0px) + 10px));
  border-top: 1px solid var(--sb-border);
  flex-shrink: 0;
  display: flex;
  justify-content: flex-end;
}

.logo {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 2px 4px;
  cursor: pointer;
  user-select: none;
  min-width: 0;
  flex: 1;
}
.logo:hover .logo-text { color: #fff; }
.logo-mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.logo-text {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.3px;
  color: var(--sb-text);
}
.logo-text em { font-style: normal; color: var(--accent); }

.btn-new-chat {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  background: var(--sb-new-btn);
  color: #fff;
  border: none;
  border-radius: 9px;
  font-family: var(--font);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background .14s, transform .1s;
  white-space: nowrap;
}
.btn-new-chat:hover  { background: var(--sb-new-hover); }
.btn-new-chat:active { transform: scale(.98); }

/* Chat list */
.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.chat-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,.10); }

.chat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s;
  min-width: 0;
}
.chat-item:hover  { background: var(--sb-hover); }
.chat-item.active { background: var(--sb-active); }

.chat-item-icon { flex-shrink: 0; color: var(--sb-text-dim); }

.chat-item-name {
  flex: 1;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--sb-text);
}
.chat-item.active .chat-item-name { font-weight: 500; }

.chat-item-menu {
  flex-shrink: 0;
  opacity: 0;
  background: none;
  border: none;
  color: var(--sb-text-dim);
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 5px;
  font-size: 15px;
  line-height: 1;
  transition: opacity .1s, background .1s, color .1s;
}
.chat-item:hover .chat-item-menu,
.chat-item.active .chat-item-menu { opacity: 1; }
.chat-item-menu:hover { background: var(--sb-hover); color: var(--sb-text); }

.chat-list-empty {
  padding: 20px 10px;
  font-size: 13px;
  color: var(--sb-text-dim);
  text-align: center;
}


/* ===== Main ===== */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* Header */
.main-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top, 0px);
  height: calc(50px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
  transition: padding-left .22s ease;
}
/* Leave room for floating burger when sidebar is collapsed */
.sidebar.collapsed ~ .main .main-header { padding-left: 56px; }

.btn-icon {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 7px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, color .12s;
}
.btn-icon:hover { background: var(--bg-msg-user); color: var(--text); }

/* Model selector — flat, minimal */
.model-selector {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 28px 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  outline: none;
  transition: border-color .15s;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='11' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  max-width: 320px;
}
.model-selector:focus { border-color: var(--accent); }
.model-selector option { background: var(--bg-input); color: var(--text); }

/* ===== Messages container ===== */
.messages-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

/* ===== Welcome screen ===== */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px 70px;
  text-align: center;
  animation: fadeUp .3s ease;
}

.welcome-icon {
  width: 54px;
  height: 54px;
  border-radius: 15px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 18px;
}

.welcome-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.5px;
  margin-bottom: 10px;
}
.welcome-title em { font-style: normal; color: var(--accent); }

.welcome-desc {
  font-size: 15px;
  color: var(--text-dim);
  max-width: 440px;
  line-height: 1.7;
  margin-bottom: 34px;
}

.welcome-tips {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  max-width: 520px;
  width: 100%;
}

.welcome-tip {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13.5px;
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
  text-align: left;
  line-height: 1.4;
}
.welcome-tip:hover { border-color: var(--accent); color: var(--text); background: var(--accent-light); }

/* ===== Messages list ===== */
.messages-list {
  display: flex;
  flex-direction: column;
  max-width: 768px;
  width: 100%;
  margin: 0 auto;
  padding: 16px 24px 8px;
  gap: 2px;
}

/* User message — right-aligned bubble */
.message-user {
  display: flex;
  justify-content: flex-end;
  padding: 2px 0;
  animation: msgIn .18s ease;
}
.message-user .message-bubble {
  background: var(--bg-msg-user);
  border-radius: 18px 18px 4px 18px;
  padding: 10px 16px;
  max-width: 72%;
  font-size: 15px;
  line-height: 1.65;
  color: var(--text);
  word-break: break-word;
}
.message-user .message-bubble p { margin: 0; }

/* AI message — full width, no bubble */
.message-assistant {
  padding: 4px 0 14px;
  animation: msgIn .18s ease;
}
/* Extra space between user bubble and AI reply */
.message-user + .message-assistant { margin-top: 12px; }

.message-body {
  font-size: 15px;
  line-height: 1.72;
  color: var(--text);
}

/* ===== Thinking block ===== */
.thinking-block {
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--thinking-border);
  border-radius: 9px;
  overflow: hidden;
  background: var(--bg-thinking);
}

.thinking-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 9px 12px;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--accent);
  text-align: left;
  transition: background .12s;
  user-select: none;
}
.thinking-toggle:hover { background: var(--accent-light); }

.thinking-toggle-chevron {
  flex-shrink: 0;
  transition: transform .2s ease;
  color: var(--accent);
}
.thinking-block.expanded .thinking-toggle-chevron { transform: rotate(90deg); }

.thinking-toggle-label { flex: 1; }

.thinking-duration {
  font-size: 11px;
  color: var(--text-dimmer);
  font-weight: 400;
}

/* Collapsible content area */
.thinking-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height .25s ease;
}
.thinking-block.expanded .thinking-content {
  max-height: 320px;
  overflow-y: auto;
}

.thinking-content-inner {
  padding: 10px 14px 12px;
  font-size: 13px;
  line-height: 1.68;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
  border-top: 1px solid var(--border);
  font-style: italic;
}

/* Pulse dots for "still thinking" state */
.thinking-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 2px;
}
.thinking-dots span {
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulseDot 1.3s ease-in-out infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: .18s; }
.thinking-dots span:nth-child(3) { animation-delay: .36s; }

/* ===== Streaming text (plain during streaming) ===== */
.stream-text {
  white-space: pre-wrap;
  word-break: break-word;
}

/* ===== Markdown ===== */
.message-body p { margin-bottom: 10px; }
.message-body p:last-child { margin-bottom: 0; }
.message-body h1,.message-body h2,.message-body h3,
.message-body h4,.message-body h5,.message-body h6 { margin: 18px 0 8px; font-weight: 700; }
.message-body h1 { font-size: 28px; }
.message-body h2 { font-size: 23px; }
.message-body h3 { font-size: 19px; }
.message-body h4 { font-size: 16px; }
.message-body h5,.message-body h6 { font-size: 13.5px; }
.message-body hr { margin: 15px 0; border: none; border-top: 1px solid #545454; }
.message-body ul,.message-body ol { margin: 6px 0 10px 20px; }
.message-body li { margin-bottom: 3px; }
.message-body blockquote {
  border-left: 3px solid var(--accent);
  padding: 4px 14px;
  margin: 10px 0;
  color: var(--text-dim);
  font-style: italic;
}
.table-wrapper { overflow-x: auto; max-width: 100%; margin: 12px 0; }
.message-body table { border-collapse: collapse; width: max-content; min-width: 100%; font-size: 14px; }
.message-body th,.message-body td { border: 1px solid var(--border); padding: 6px 12px; text-align: left; white-space: nowrap; }
.message-body th { background: var(--bg-secondary); font-weight: 600; }
.table-wrapper + p { margin-top: 0; }
.message-body a { color: var(--accent); text-decoration: none; }
.message-body a:hover { text-decoration: underline; }

.message-body code:not(pre code) {
  background: var(--bg-code);
  border: 1px solid var(--border);
  padding: 2px 5px;
  border-radius: 4px;
  font-family: 'JetBrains Mono','Fira Code',monospace;
  font-size: 13px;
}

.code-block {
  margin: 12px 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 7px 14px;
  font-size: 11.5px;
  color: var(--text-dimmer);
  font-family: 'JetBrains Mono','Fira Code',monospace;
}
.code-copy-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dimmer);
  cursor: pointer;
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 5px;
  font-family: var(--font);
  transition: border-color .12s, color .12s, background .12s;
}
.code-copy-btn:hover { border-color: var(--accent); color: var(--text); }
.code-block pre { margin: 0; padding: 14px; overflow-x: auto; background: var(--bg) !important; }
[data-theme="dark"] .code-block pre { background: var(--bg-code) !important; }
.code-block pre code {
  font-family: 'JetBrains Mono','Fira Code','Cascadia Code',monospace;
  font-size: 13px;
  background: none !important;
  border: none !important;
  padding: 0 !important;
}

/* ===== Message footer (copy button) ===== */
.message-footer {
  margin-top: 10px;
  display: flex;
  gap: 6px;
}

.btn-copy-msg {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-dimmer);
  font-family: var(--font);
  font-size: 12px;
  cursor: pointer;
  transition: border-color .13s, color .13s, background .13s;
  line-height: 1;
}
.btn-copy-msg:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}
.btn-copy-msg svg { flex-shrink: 0; }

/* Streaming cursor */
.cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  margin-left: 1px;
  vertical-align: text-bottom;
  animation: blink .85s step-end infinite;
}

/* Error */
.message-error {
  display: flex;
  gap: 8px;
  padding: 11px 14px;
  background: rgba(220,38,38,.06);
  border: 1px solid rgba(220,38,38,.18);
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--danger);
  line-height: 1.5;
}

/* ===== Input area ===== */
.input-container {
  padding: 10px 24px 16px;
  /* На iOS с home bar — отступ снизу включает safe area */
  padding-bottom: max(16px, calc(env(safe-area-inset-bottom, 0px) + 10px));
  flex-shrink: 0;
  max-width: 816px;
  width: 100%;
  margin: 0 auto;
}

.input-wrap {
  position: relative;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: 13px;
  padding: 12px 56px 12px 16px;
  min-height: 80px;
  transition: border-color .15s, box-shadow .15s;
  box-shadow: var(--shadow);
}
.input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.msg-input {
  display: block;
  width: 100%;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  resize: none;
  min-height: 56px;
  max-height: 200px;
  overflow-y: auto;
  padding: 0;
}
.msg-input::placeholder { color: var(--text-dimmer); }
.msg-input::-webkit-scrollbar { display: none; }
.msg-input { scrollbar-width: none; }

.btn-send {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--send-bg);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .14s, transform .1s, opacity .15s;
}
.btn-send:hover:not(.inactive) { background: var(--send-hover); }
.btn-send:active:not(.inactive) { transform: scale(.93); }
.btn-send.inactive { opacity: .28; cursor: default; }

/* Режим "Стоп" — кнопка в акцентном цвете */
.btn-send.is-stop {
  background: var(--accent);
  opacity: 1;
  cursor: pointer;
}
.btn-send.is-stop:hover { background: var(--accent-hover); }
.btn-send.is-stop .icon-send { display: none !important; }
.btn-send.is-stop .icon-stop { display: block !important; }

.input-hint {
  font-size: 11.5px;
  color: var(--text-dimmer);
  text-align: center;
  margin-top: 8px;
}

/* ===== Context menu ===== */
.context-menu {
  position: fixed;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  display: none;
  flex-direction: column;
  gap: 2px;
  z-index: 1000;
  box-shadow: var(--shadow-lg);
  min-width: 150px;
}
.context-menu.visible { display: flex; }

.ctx-item {
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 13.5px;
  padding: 8px 12px;
  border-radius: 7px;
  text-align: left;
  cursor: pointer;
  transition: background .1s;
}
.ctx-item:hover { background: var(--bg-secondary); }
.ctx-item.ctx-danger { color: var(--danger); }
.ctx-item.ctx-danger:hover { background: rgba(220,38,38,.07); }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  backdrop-filter: blur(4px);
}
.modal-overlay.visible { display: flex; }

.modal {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  width: 360px;
  box-shadow: var(--shadow-lg);
  animation: modalIn .18s ease;
}
.modal h3 { font-size: 15.5px; font-weight: 600; margin-bottom: 16px; }

.modal-input {
  width: 100%;
  background: var(--bg-secondary);
  border: 1.5px solid var(--border);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  padding: 9px 12px;
  border-radius: 8px;
  outline: none;
  transition: border-color .15s;
}
.modal-input:focus { border-color: var(--accent); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.btn-modal-cancel,.btn-modal-ok {
  padding: 8px 16px;
  border-radius: 8px;
  font-family: var(--font);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: background .12s;
}
.btn-modal-cancel { background: var(--bg-secondary); border-color: var(--border); color: var(--text); }
.btn-modal-cancel:hover { border-color: var(--text-dim); }
.btn-modal-ok { background: var(--accent); color: #fff; }
.btn-modal-ok:hover { background: var(--accent-hover); }

/* ===== Animations ===== */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(.96); }
  to   { opacity: 1; transform: scale(1); }
}
@keyframes blink {
  0%,100% { opacity: 1; }
  50%      { opacity: 0; }
}
@keyframes pulseDot {
  0%,80%,100% { transform: scale(.55); opacity: .35; }
  40%         { transform: scale(1); opacity: 1; }
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
.spinning { animation: spin .6s linear infinite; }

/* ===== Sidebar backdrop ===== */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 640;
  backdrop-filter: blur(1px);
  -webkit-backdrop-filter: blur(1px);
}
.sidebar-backdrop.visible { display: block; }

/* ===== Mobile ===== */
@media (max-width: 640px) {
  /* Sidebar overlays from left edge.
     IMPORTANT: use `left` instead of `transform` so that position:fixed children
     (the floating burger) are still positioned relative to the viewport. */
  .sidebar {
    position: fixed;
    top: 0; bottom: 0;
    left: -260px; /* hidden off-screen */
    width: 260px !important;
    min-width: 260px !important;
    z-index: 650;
    transition: left .22s ease;
  }
  .sidebar.mobile-open { left: 0; box-shadow: var(--shadow-lg); }
  /* collapsed class not used on mobile, but keep reset just in case */
  .sidebar.collapsed { left: -260px; }

  /* Floating burger when sidebar is closed on mobile.
     Works because parent has no transform → fixed children use viewport coords. */
  .sidebar:not(.mobile-open) #sidebarToggle {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 800;
    color: var(--text);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
  }

  /* Indent header so model selector doesn't hide under burger */
  .main .main-header { padding-left: 56px; }
  .sidebar.mobile-open ~ .sidebar-backdrop ~ .main .main-header { padding-left: 16px; }

  .messages-list { padding: 10px 14px 6px; }

  .input-container {
    padding: 8px 12px;
    padding-bottom: max(12px, calc(env(safe-area-inset-bottom, 0px) + 8px));
  }

  .welcome { padding: 20px 16px 40px; }
  .welcome-tips { grid-template-columns: 1fr; }
  .welcome-title { font-size: 22px; }
  .welcome-desc { font-size: 14px; }

  .msg-input { font-size: 16px; }
  .model-selector { font-size: 14px; }
}
