/* ════════════════════════════════════════════════════════════════════════════
   LIQUID GLASS THEME
════════════════════════════════════════════════════════════════════════════ */
:root {
  --glass-bg:        rgba(30, 30, 30, 0.45);
  --glass-bg-strong: rgba(20, 20, 20, 0.85);
  --glass-bg-soft:   rgba(255, 255, 255, 0.04);
  --glass-border:    rgba(255, 255, 255, 0.13);
  --glass-border-strong: rgba(255, 255, 255, 0.22);
  --glass-shine:     rgba(255, 255, 255, 0.06);
  --glass-blur:      blur(36px) saturate(180%);

  --accent:        #00C9FF;
  --accent-2:      #92FE9D;
  --accent-glow:   rgba(0, 201, 255, 0.28);
  --accent-dim:    rgba(0, 201, 255, 0.12);
  --ios-green:     #34C759;
  --amber:         #FFB86B;
  --amber-dim:     rgba(255, 184, 107, 0.13);
  --red:           #FF6B6B;
  --red-dim:       rgba(255, 107, 107, 0.12);

  --text:          #FFFFFF;
  --text-secondary:#D1D1D6;
  --text-muted:    rgba(255, 255, 255, 0.45);
  --text-faint:    rgba(255, 255, 255, 0.28);

  --radius-lg:     28px;
  --radius-md:     18px;
  --radius-sm:     12px;
  --radius-pill:   99px;

  --shadow-soft:   0 20px 50px rgba(0,0,0,0.45), 0 0 0 1px rgba(255,255,255,0.08) inset;
  --shadow-deep:   0 30px 70px rgba(0,0,0,0.6);

  --sidebar-w:     272px;
  --topbar-h:      62px;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; font-family: var(--font); -webkit-font-smoothing: antialiased; }

html, body {
  height: 100%;
  color: var(--text);
  background-color: #050505;
  background-image:
    radial-gradient(circle at 12% 12%, rgba(0, 201, 255, 0.16), transparent 42%),
    radial-gradient(circle at 88% 8%,  rgba(146, 254, 157, 0.07), transparent 38%),
    radial-gradient(circle at 85% 92%, rgba(120, 50, 200, 0.14), transparent 42%),
    linear-gradient(180deg, #060606 0%, #0c0c0c 100%);
  background-attachment: fixed;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.6;
}

button { cursor: pointer; border: none; background: none; font-family: inherit; color: inherit; }
input, textarea { font-family: inherit; color: inherit; background: none; border: none; outline: none; }
pre, code { font-family: 'SF Mono', 'JetBrains Mono', monospace; }

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.14); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.26); }

/* ── Glass panel base ───────────────────────────────────────────────────── */
.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  position: relative;
}
.glass-panel::after {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; height: 50%;
  background: linear-gradient(180deg, var(--glass-shine) 0%, transparent 100%);
  pointer-events: none;
  border-radius: inherit;
}

/* ── Gradient text utility ─────────────────────────────────────────────── */
.gradient-text {
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-2) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
.icon-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  transition: background 0.2s, color 0.2s, transform 0.2s;
  flex-shrink: 0;
}
.icon-btn:hover { background: rgba(255,255,255,0.08); color: var(--text); transform: translateY(-1px); }

.accent-btn {
  background: var(--accent);
  color: #04222b;
  padding: 0.65rem 1.5rem;
  border-radius: var(--radius-pill);
  font-weight: 700;
  font-size: 0.88rem;
  box-shadow: 0 4px 18px var(--accent-glow);
  transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
}
.accent-btn:hover { transform: translateY(-2px) scale(1.02); box-shadow: 0 8px 28px var(--accent-glow); }
.accent-btn:disabled { opacity: 0.4; transform: none; cursor: not-allowed; box-shadow: none; }

.ghost-btn {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
  padding: 0.65rem 1.3rem;
  border-radius: var(--radius-pill);
  font-size: 0.88rem;
  font-weight: 500;
  transition: background 0.2s, color 0.2s, transform 0.2s;
}
.ghost-btn:hover { background: rgba(255,255,255,0.12); color: var(--text); transform: translateY(-1px); }

[data-backend="browser"] .accent-btn { background: var(--ios-green); color: #04220f; box-shadow: 0 4px 18px rgba(52,199,89,0.3); }

/* ── Status badge ───────────────────────────────────────────────────────── */
.status-badge {
  font-size: 0.74rem;
  font-family: 'SF Mono', monospace;
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}
.status-badge.running { background: rgba(52,199,89,0.12); color: var(--ios-green); border: 1px solid rgba(52,199,89,0.25); }
.status-badge.offline  { background: var(--red-dim); color: var(--red); border: 1px solid rgba(255,107,107,0.25); }

/* ════════════════════════════════════════════════════════════════════════════
   APP SHELL
════════════════════════════════════════════════════════════════════════════ */
.app-shell { display: flex; height: 100vh; overflow: hidden; padding: 14px; gap: 14px; }

/* ════════════════════════════════════════════════════════════════════════════
   SIDEBAR
════════════════════════════════════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
}

.sidebar-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.2rem 1.1rem 0.9rem;
  position: relative; z-index: 1;
}
.brand { display: flex; align-items: center; gap: 0.55rem; }
.brand-mark { font-size: 1.15rem; color: var(--accent); filter: drop-shadow(0 0 8px var(--accent-glow)); }
.brand-text { font-weight: 800; font-size: 0.92rem; letter-spacing: 1.2px; }
.sidebar-close-btn { display: none; }

.new-chat-btn {
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  margin: 0 1rem 0.9rem;
  padding: 0.65rem 1rem;
  border-radius: var(--radius-pill);
  background: linear-gradient(145deg, rgba(255,255,255,0.1), rgba(255,255,255,0.02));
  border: 1px solid var(--glass-border);
  color: var(--text);
  font-size: 0.85rem; font-weight: 600;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
  transition: all 0.25s ease;
  position: relative; z-index: 1;
}
.new-chat-btn:hover { background: rgba(0,201,255,0.12); border-color: rgba(0,201,255,0.3); transform: translateY(-1px); box-shadow: 0 8px 20px rgba(0,0,0,0.4); }
.new-chat-btn svg { opacity: 0.8; }

.sidebar-scroll { flex: 1; overflow-y: auto; padding: 0 0.65rem; position: relative; z-index: 1; }

.sidebar-label {
  font-size: 0.66rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-faint);
  padding: 0.4rem 0.85rem 0.55rem;
}

.history-empty-msg {
  font-size: 0.78rem;
  color: var(--text-faint);
  padding: 0.5rem 0.85rem;
  line-height: 1.5;
  display: none;
}

.chat-history-list { display: flex; flex-direction: column; gap: 3px; }

.history-item {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.6rem 0.7rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  position: relative;
  border-left: 3px solid transparent;
  transition: background 0.18s, border-color 0.18s;
}
.history-item:hover { background: rgba(0,201,255,0.07); }
.history-item.active {
  background: rgba(0,201,255,0.12);
  border-left-color: var(--accent);
}
.history-item-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  box-shadow: 0 0 6px var(--accent-glow);
}
.history-item[data-backend="browser"] .history-item-dot { background: var(--ios-green); box-shadow: 0 0 6px rgba(52,199,89,0.4); }
.history-item-text { flex: 1; min-width: 0; overflow: hidden; }
.history-item-title {
  font-size: 0.83rem; color: var(--text-secondary); font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history-item.active .history-item-title { color: var(--text); }
.history-item-model {
  font-size: 0.68rem; color: var(--text-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history-item-tier { color: var(--text-secondary); font-weight: 600; }
.history-item-realname { color: var(--text-faint); font-weight: 400; margin-left: 0.2rem; }
.history-item-delete {
  width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-faint);
  opacity: 0;
  flex-shrink: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
  font-size: 0.7rem;
}
.history-item:hover .history-item-delete { opacity: 1; }
.history-item-delete:hover { background: var(--red-dim); color: var(--red); }

.sidebar-bottom {
  padding: 0.8rem 0.9rem 0.95rem;
  border-top: 1px solid rgba(255,255,255,0.08);
  position: relative; z-index: 1;
}
.sidebar-bottom-btn {
  display: flex; align-items: center; gap: 0.55rem;
  width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.82rem; font-weight: 500;
  transition: background 0.18s, color 0.18s;
}
.sidebar-bottom-btn:hover { background: rgba(255,255,255,0.07); color: var(--text); }

/* Mobile backdrop */
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 40;
  opacity: 0;
  transition: opacity 0.25s;
}

/* ════════════════════════════════════════════════════════════════════════════
   MAIN
════════════════════════════════════════════════════════════════════════════ */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 14px; overflow: hidden; }

/* ── Topbar ─────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  display: flex; align-items: center;
  padding: 0 0.6rem 0 0.75rem;
  position: relative; z-index: 20;
}
.topbar-hamburger { display: none; }
.topbar-spacer { flex: 1; }

@media (min-width: 769px) { .topbar-hamburger { display: none !important; } }

/* ── Model dropdown trigger ────────────────────────────────────────────── */
.model-picker { position: relative; }

.model-trigger {
  display: flex; align-items: center; gap: 0.55rem;
  padding: 0.5rem 1.1rem 0.5rem 0.85rem;
  border-radius: var(--radius-pill);
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--glass-border);
  color: var(--text);
  font-size: 0.86rem; font-weight: 600;
  transition: background 0.2s, border-color 0.2s;
}
.model-trigger:hover { background: rgba(255,255,255,0.09); border-color: var(--glass-border-strong); }

.model-trigger-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
  transition: background 0.2s, box-shadow 0.2s;
}
.model-trigger-dot.set { background: var(--accent); box-shadow: 0 0 7px var(--accent-glow); }
[data-backend="browser"] .model-trigger-dot.set { background: var(--ios-green); box-shadow: 0 0 7px rgba(52,199,89,0.45); }

#model-trigger-chevron { color: var(--text-faint); transition: transform 0.25s; }
.model-picker.open #model-trigger-chevron { transform: rotate(180deg); }
.trigger-real-name { font-size: 0.7rem; color: var(--text-faint); font-weight: 500; margin-left: 0.15rem; }

/* ── Dropdown panel ─────────────────────────────────────────────────────── */
.model-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%) translateY(-8px) scale(0.97);
  width: 380px;
  max-width: 92vw;
  border-radius: var(--radius-lg);
  background: rgba(12, 12, 14, 0.985);
  backdrop-filter: blur(48px) saturate(150%);
  -webkit-backdrop-filter: blur(48px) saturate(150%);
  box-shadow: var(--shadow-deep);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s cubic-bezier(0.16,1,0.3,1), transform 0.22s cubic-bezier(0.16,1,0.3,1);
  z-index: 50;
}
.model-picker.open .model-dropdown {
  opacity: 1; pointer-events: auto;
  transform: translateX(-50%) translateY(0) scale(1);
}

.dropdown-tabs {
  display: flex; gap: 4px;
  background: rgba(0,0,0,0.3);
  border-radius: var(--radius-pill);
  padding: 4px;
  position: relative; z-index: 1;
}
.dropdown-tab {
  flex: 1;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-pill);
  font-size: 0.8rem; font-weight: 600;
  color: var(--text-muted);
  transition: background 0.2s, color 0.2s;
}
.dropdown-tab.active { background: rgba(255,255,255,0.12); color: var(--text); }

.dropdown-status-row {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  position: relative; z-index: 1;
}
.dropdown-refresh {
  width: 26px; height: 26px; border-radius: 50%;
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem;
  transition: background 0.2s, color 0.2s, transform 0.4s;
}
.dropdown-refresh:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.dropdown-refresh.spin { transform: rotate(360deg); }

.dropdown-note {
  font-size: 0.76rem;
  color: var(--text-secondary);
  background: rgba(52,199,89,0.07);
  border: 1px solid rgba(52,199,89,0.18);
  border-left: 3px solid var(--ios-green);
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  line-height: 1.5;
  position: relative; z-index: 1;
}

.dropdown-list {
  display: flex; flex-direction: column; gap: 6px;
  max-height: 360px;
  overflow-y: auto;
  position: relative; z-index: 1;
}

.dd-model-row {
  --row-accent: var(--accent);
  display: flex; flex-direction: column; gap: 0.4rem;
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-md);
  background: rgba(255,255,255,0.035);
  border: 1px solid rgba(255,255,255,0.07);
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.dd-model-row:hover { background: rgba(0,201,255,0.08); border-color: rgba(0,201,255,0.3); transform: translateY(-1px); }

.dd-model-head { display: flex; align-items: center; gap: 0.5rem; }
.dd-model-name { font-size: 0.88rem; font-weight: 700; color: var(--text); }
.dd-model-real-name { font-size: 0.68rem; color: var(--text-faint); font-weight: 500; }
.dd-model-badge {
  font-size: 0.6rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--row-accent);
  background: color-mix(in srgb, var(--row-accent) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--row-accent) 30%, transparent);
  padding: 0.1rem 0.45rem;
  border-radius: var(--radius-pill);
}
.dd-model-installed { font-size: 0.68rem; font-weight: 600; color: var(--ios-green); margin-left: auto; }
.dd-model-desc { font-size: 0.76rem; color: var(--text-muted); line-height: 1.4; }
.dd-model-meta { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.dd-model-tag {
  font-size: 0.66rem; font-weight: 600;
  padding: 0.12rem 0.5rem;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--row-accent) 12%, transparent);
  color: color-mix(in srgb, var(--row-accent) 82%, var(--text));
  border: 1px solid color-mix(in srgb, var(--row-accent) 24%, transparent);
}
.dd-model-size { font-size: 0.68rem; color: var(--text-faint); font-family: 'SF Mono', monospace; margin-left: auto; }
.dd-model-tag.slow { background: var(--amber-dim); color: var(--amber); border-color: rgba(255,184,107,0.32); }

/* ════════════════════════════════════════════════════════════════════════════
   CHAT AREA
════════════════════════════════════════════════════════════════════════════ */
.chat-area {
  flex: 1;
  min-height: 0;
  border-radius: var(--radius-lg);
  background: rgba(15,15,15,0.35);
  border: 1px solid rgba(255,255,255,0.07);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.75rem 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.3rem;
  scroll-behavior: smooth;
}

/* ── Empty state ────────────────────────────────────────────────────────── */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  gap: 0.4rem;
  pointer-events: none;
}
.empty-state.visible { pointer-events: auto; }
.empty-glyph {
  font-size: 2.8rem;
  color: var(--accent);
  filter: drop-shadow(0 0 20px var(--accent-glow));
  margin-bottom: 0.75rem;
  animation: glyph-pulse 3.2s ease-in-out infinite;
}
@keyframes glyph-pulse {
  0%, 100% { filter: drop-shadow(0 0 12px var(--accent-glow)); }
  50%       { filter: drop-shadow(0 0 30px rgba(0,201,255,0.45)); }
}
.empty-title { font-size: 1.9rem; font-weight: 800; letter-spacing: -0.01em; margin-bottom: 0.4rem; }
.empty-sub { font-size: 0.92rem; color: var(--text-muted); margin-bottom: 1.6rem; max-width: 360px; line-height: 1.55; }

/* ── Message bubbles ────────────────────────────────────────────────────── */
.message { display: flex; max-width: 720px; margin: 0 auto; width: 100%; }

.message.system { justify-content: center; }
.message.system > * {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 0.6rem 1.1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  max-width: 480px;
  text-align: center;
  line-height: 1.5;
}

.message.user { flex-direction: column; align-items: flex-end; gap: 0.45rem; }
.message.user .msg-text {
  background: linear-gradient(135deg, var(--accent) 0%, #00a8e8 100%);
  color: #04222b;
  border-radius: 20px 20px 4px 20px;
  padding: 0.7rem 1.1rem;
  max-width: 600px;
  font-size: 0.9rem;
  line-height: 1.55;
  word-break: break-word;
  box-shadow: 0 6px 18px rgba(0,201,255,0.18);
}
[data-backend="browser"] .message.user .msg-text {
  background: linear-gradient(135deg, var(--ios-green) 0%, #28a745 100%);
  color: #04220f;
  box-shadow: 0 6px 18px rgba(52,199,89,0.2);
}

.msg-image { max-width: 260px; max-height: 200px; border-radius: var(--radius-sm); object-fit: cover; border: 1px solid var(--glass-border); align-self: flex-end; }
.msg-file-tag { font-size: 0.75rem; color: var(--text-secondary); background: rgba(255,255,255,0.06); border: 1px solid var(--glass-border); padding: 0.28rem 0.8rem; border-radius: var(--radius-pill); align-self: flex-end; }
.msg-file-tag.error { color: var(--red); border-color: rgba(255,107,107,0.3); }

.message.assistant { flex-direction: row; align-items: flex-start; gap: 0.75rem; }
.model-icon {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-dim);
  border: 1px solid rgba(0,201,255,0.28);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0; margin-top: 0.1rem;
  box-shadow: 0 0 14px var(--accent-glow);
}
[data-backend="browser"] .model-icon { background: rgba(52,199,89,0.12); border-color: rgba(52,199,89,0.28); color: var(--ios-green); box-shadow: 0 0 14px rgba(52,199,89,0.25); }

.msg-bubble { flex: 1; min-width: 0; }

.thinking-status { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; margin-bottom: 0.2rem; height: 1.3rem; }
.thinking-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 8px var(--accent-glow);
  flex-shrink: 0;
  animation: thinking-pulse 1.2s ease-in-out infinite;
}
[data-backend="browser"] .thinking-dot { background: var(--ios-green); box-shadow: 0 0 8px rgba(52,199,89,0.4); }
@keyframes thinking-pulse { 0%, 100% { transform: scale(0.7); opacity: 0.55; } 50% { transform: scale(1.2); opacity: 1; } }

.thinking-label {
  background: linear-gradient(90deg, var(--text-faint) 0%, var(--text) 50%, var(--text-faint) 100%);
  background-size: 200% 100%;
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
  animation: thinking-shimmer 1.8s linear infinite;
  font-weight: 500;
}
@keyframes thinking-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.thinking-status.done { margin-bottom: 0.45rem; }
.thinking-status.done .thinking-dot { display: none; }
.thinking-status.done .thinking-label {
  animation: none; background: none;
  -webkit-text-fill-color: var(--text-faint); color: var(--text-faint);
  font-size: 0.76rem; font-weight: 400;
}
.msg-bubble .msg-text { font-size: 0.9rem; line-height: 1.65; color: var(--text); word-break: break-word; }
.msg-bubble .msg-text.error { color: var(--red); }

.msg-text.streaming::after { content: '▋'; animation: blink 0.8s step-end infinite; color: var(--accent); margin-left: 2px; }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

.msg-bubble .msg-text p { margin-bottom: 0.6rem; }
.msg-bubble .msg-text p:last-child { margin-bottom: 0; }
.msg-bubble .msg-text h1, .msg-bubble .msg-text h2, .msg-bubble .msg-text h3 { margin: 0.9rem 0 0.35rem; color: var(--text); font-weight: 700; }
.msg-bubble .msg-text ul, .msg-bubble .msg-text ol { padding-left: 1.35rem; margin-bottom: 0.45rem; }
.msg-bubble .msg-text li { margin-bottom: 0.2rem; }
.msg-bubble .msg-text code { background: rgba(255,255,255,0.07); border: 1px solid var(--glass-border); padding: 0.1em 0.38em; border-radius: 4px; font-size: 0.83em; color: var(--accent); }
.msg-bubble .msg-text pre { background: #0a0a0a; border: 1px solid var(--glass-border); border-radius: var(--radius-sm); padding: 0.9rem 1rem; overflow-x: auto; margin: 0.65rem 0; }
.msg-bubble .msg-text pre code { background: none; border: none; padding: 0; color: inherit; font-size: 0.82rem; }
.msg-bubble .msg-text blockquote { border-left: 3px solid var(--accent); padding: 0.3rem 0.85rem; margin: 0.45rem 0; color: var(--text-muted); }
.msg-bubble .msg-text table { border-collapse: collapse; width: 100%; margin: 0.65rem 0; font-size: 0.84rem; }
.msg-bubble .msg-text th, .msg-bubble .msg-text td { border: 1px solid var(--glass-border); padding: 0.35rem 0.7rem; text-align: left; }
.msg-bubble .msg-text th { background: rgba(255,255,255,0.05); font-weight: 600; }

/* ── Input area ─────────────────────────────────────────────────────────── */
.input-area { padding: 0.7rem 1.1rem 1rem; flex-shrink: 0; }

.file-error {
  font-size: 0.76rem; color: var(--red);
  background: var(--red-dim); border: 1px solid rgba(255,107,107,0.25);
  padding: 0.4rem 0.9rem; border-radius: var(--radius-sm); margin-bottom: 0.55rem;
}
.file-preview-row { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-bottom: 0.6rem; }
.queue-badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-size: 0.72rem; color: var(--text-muted);
  background: rgba(255,255,255,0.06); border: 1px solid var(--glass-border);
  padding: 0.3rem 0.75rem; border-radius: var(--radius-pill);
  margin-bottom: 0.55rem;
}
.queue-badge::before { content: '⏳'; font-size: 0.8rem; }

.sidebar.busy .new-chat-btn,
.sidebar.busy .history-item {
  opacity: 0.5;
  pointer-events: none;
}
.file-chip {
  display: flex; align-items: center; gap: 0.38rem;
  background: rgba(255,255,255,0.06); border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill); padding: 0.22rem 0.65rem 0.22rem 0.3rem;
  font-size: 0.76rem; color: var(--text-secondary);
}
.chip-thumb { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; }
.chip-remove {
  width: 16px; height: 16px; border-radius: 50%;
  background: rgba(255,255,255,0.08); color: var(--text-faint);
  font-size: 9px; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background 0.15s, color 0.15s;
}
.chip-remove:hover { background: var(--red); color: #fff; }

.input-row {
  display: flex; align-items: flex-end; gap: 0.5rem;
  border-radius: var(--radius-pill);
  padding: 0.55rem 0.6rem 0.55rem 0.85rem;
  box-shadow: var(--shadow-soft);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input-row:focus-within { border-color: rgba(0,201,255,0.4); box-shadow: var(--shadow-soft), 0 0 0 3px var(--accent-dim); }
[data-backend="browser"] .input-row:focus-within { border-color: rgba(52,199,89,0.4); box-shadow: var(--shadow-soft), 0 0 0 3px rgba(52,199,89,0.14); }

.attach-btn {
  color: var(--text-muted); padding: 0.3rem; border-radius: 50%;
  flex-shrink: 0; transition: color 0.2s, background 0.2s; margin-bottom: 2px;
}
.attach-btn:hover { color: var(--accent); background: var(--accent-dim); }

.user-input {
  flex: 1; min-height: 22px; max-height: 140px; resize: none;
  font-size: 0.9rem; line-height: 1.5; color: var(--text); overflow-y: auto;
}
.user-input::placeholder { color: var(--text-faint); }
.user-input:disabled { cursor: not-allowed; }

.send-btn {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent); color: #04222b;
  font-size: 1rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-bottom: 1px;
  box-shadow: 0 4px 14px var(--accent-glow);
  transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
}
.send-btn:hover:not(:disabled) { transform: scale(1.08); }
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; box-shadow: none; }
[data-backend="browser"] .send-btn { background: var(--ios-green); color: #04220f; box-shadow: 0 4px 14px rgba(52,199,89,0.28); }

.input-hint { font-size: 0.68rem; color: var(--text-faint); margin-top: 0.5rem; text-align: center; }

.chat-area.drag-over .input-row { border-color: var(--accent); box-shadow: var(--shadow-soft), 0 0 0 4px var(--accent-dim); }

/* ════════════════════════════════════════════════════════════════════════════
   MODAL SCREENS  (install / loading / error)
════════════════════════════════════════════════════════════════════════════ */
.modal-screen {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(16px);
  padding: 1.5rem;
}
.modal-card {
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-deep);
  padding: 2.25rem;
  max-width: 480px; width: 100%;
  display: flex; flex-direction: column; gap: 1.1rem;
}
.modal-icon-wrap {
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--accent-dim); border: 1px solid rgba(0,201,255,0.25);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; color: var(--accent);
  margin-bottom: 0.15rem; position: relative; z-index: 1;
}
.modal-icon-wrap.error { background: var(--red-dim); border-color: rgba(255,107,107,0.25); color: var(--red); }
.modal-icon-wrap.offline { background: var(--amber-dim); border-color: rgba(255,184,107,0.3); color: var(--amber); }
[data-backend="browser"] .modal-icon-wrap { background: rgba(52,199,89,0.12); border-color: rgba(52,199,89,0.25); color: var(--ios-green); }
.spinning { animation: spin 1.3s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.modal-card h2 { font-size: 1.3rem; font-weight: 800; position: relative; z-index: 1; }
.modal-card p { font-size: 0.88rem; color: var(--text-muted); line-height: 1.6; position: relative; z-index: 1; }

.cmd-block { background: rgba(0,0,0,0.35); border: 1px solid var(--glass-border); border-radius: var(--radius-sm); padding: 0.85rem 1rem; position: relative; z-index: 1; }
.cmd-label { font-size: 0.72rem; color: var(--text-faint); display: block; margin-bottom: 0.35rem; }
.cmd-text { font-family: 'SF Mono', monospace; font-size: 0.84rem; color: var(--accent); word-break: break-all; }

.progress-label-row { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--text-muted); position: relative; z-index: 1; }
.progress-track { height: 6px; background: rgba(255,255,255,0.08); border-radius: var(--radius-pill); overflow: hidden; position: relative; z-index: 1; }
.progress-fill { height: 100%; background: var(--accent); border-radius: var(--radius-pill); transition: width 0.3s ease; box-shadow: 0 0 10px var(--accent-glow); }
.progress-fill.browser { background: var(--ios-green); box-shadow: 0 0 10px rgba(52,199,89,0.4); }
.loading-file { font-size: 0.7rem; color: var(--text-faint); font-family: 'SF Mono', monospace; word-break: break-all; min-height: 1rem; position: relative; z-index: 1; }

.modal-actions { display: flex; gap: 0.65rem; justify-content: flex-end; margin-top: 0.25rem; position: relative; z-index: 1; }
.error-detail { font-size: 0.78rem; font-family: 'SF Mono', monospace; color: var(--text-muted); white-space: pre-wrap; background: rgba(0,0,0,0.35); border: 1px solid var(--glass-border); border-radius: var(--radius-sm); padding: 0.75rem; max-height: 160px; overflow-y: auto; position: relative; z-index: 1; }

/* ════════════════════════════════════════════════════════════════════════════
   SETTINGS PANEL
════════════════════════════════════════════════════════════════════════════ */
.settings-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(6px); z-index: 220; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
#settings-panel.open ~ .settings-overlay { opacity: 1; pointer-events: all; }

#settings-panel {
  position: fixed; top: 14px; right: 14px; bottom: 14px;
  width: min(420px, calc(100vw - 28px));
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-deep);
  z-index: 230;
  display: flex; flex-direction: column;
  transform: translateX(calc(100% + 30px));
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
  overflow: hidden;
}
#settings-panel.open { transform: translateX(0); }

.settings-header { display: flex; align-items: center; justify-content: space-between; padding: 1.2rem 1.4rem; border-bottom: 1px solid rgba(255,255,255,0.08); position: relative; z-index: 1; }
.settings-header h3 { font-weight: 800; font-size: 1.05rem; }
.settings-body { flex: 1; overflow-y: auto; padding: 1.4rem; display: flex; flex-direction: column; gap: 1.4rem; position: relative; z-index: 1; }
.settings-label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.84rem; font-weight: 600; color: var(--text); }
.settings-hint { font-size: 0.76rem; font-weight: 400; color: var(--text-muted); line-height: 1.45; }
.settings-input { background: rgba(0,0,0,0.35); border: 1px solid var(--glass-border); border-radius: var(--radius-sm); padding: 0.6rem 0.85rem; font-size: 0.86rem; color: var(--text); transition: border-color 0.2s; width: 100%; }
.settings-input:focus { border-color: var(--accent); }
.settings-textarea { resize: vertical; min-height: 88px; }
.settings-section-title { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-faint); }
.settings-locked-note {
  font-size: 0.78rem; line-height: 1.55; color: var(--text-secondary);
  background: var(--red-dim); border: 1px solid rgba(255,107,107,0.25);
  border-left: 3px solid var(--red);
  padding: 0.65rem 0.85rem; border-radius: var(--radius-sm);
}
.settings-code { background: #0a0a0a; border: 1px solid var(--glass-border); border-radius: var(--radius-sm); padding: 0.85rem 1rem; font-size: 0.73rem; color: var(--text-muted); line-height: 1.65; white-space: pre-wrap; word-break: break-all; }

/* ════════════════════════════════════════════════════════════════════════════
   RESPONSIVE
════════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .app-shell { padding: 0; gap: 0; }
  .main { gap: 0; }

  .sidebar {
    position: fixed; top: 10px; left: 10px; bottom: 10px;
    z-index: 60; transform: translateX(-110%);
    width: 280px;
    border-radius: var(--radius-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close-btn { display: flex; }
  .sidebar-backdrop.visible { display: block; opacity: 1; }

  .topbar { border-radius: 0; margin: 0; }
  .topbar-hamburger { display: flex !important; }
  .chat-area { border-radius: 0; }

  .model-dropdown { left: auto; right: -8px; transform: translateY(-8px) scale(0.97); width: 92vw; }
  .model-picker.open .model-dropdown { transform: translateY(0) scale(1); }

  .empty-title { font-size: 1.5rem; }
  .messages { padding: 1.25rem 0.8rem 0.8rem; }
  .input-area { padding: 0.6rem 0.8rem 0.85rem; }
  .message.user .msg-text { max-width: 88vw; }

  #settings-panel { top: 0; right: 0; bottom: 0; border-radius: 0; width: 100vw; }
}
