/* CORTEX Chat — Redesign 2026-04-20 — Modern iMessage/WhatsApp style in beige/brown */

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

:root {
  /* Core palette — ZERO BLUE */
  --bg:          #f0ece6;
  --surface:     #e8e2da;
  --surface2:    #ede8e1;
  --card:        #faf6f0;
  --card2:       #f5f0e8;
  --border:      #d4cec4;
  --border-soft: #e0dbd2;

  /* Accent */
  --accent:      #8a6840;
  --accent2:     #a07848;
  --accent3:     #6b5230;
  --accent-dim:  rgba(138,104,64,0.12);
  --accent-glow: rgba(138,104,64,0.25);

  /* Text */
  --text:        #2a2420;
  --text-sec:    #5a5048;
  --text-dim:    #9a8f82;
  --text-ghost:  #bbb3a8;

  /* Message bubbles */
  --user-bg:     #c8b898;
  --user-bg2:    #d4c4a4;
  --user-text:   #2a2420;
  --ai-bg:       #faf6f0;
  --ai-border:   #ddd7ce;

  /* Code */
  --code-bg:     #2a2420;
  --code-text:   #e8dfd0;
  --code-border: #3d3530;

  /* State */
  --danger:      #c04040;
  --danger-dim:  rgba(192,64,64,0.15);
  --success:     #5a8040;
  --warning:     #8a7020;

  /* Sizes */
  --radius-sm:   6px;
  --radius-md:   12px;
  --radius-lg:   18px;
  --radius-xl:   24px;
  --radius-full: 999px;

  /* Shadows */
  --shadow-sm:   0 1px 4px rgba(42,36,32,0.08);
  --shadow-md:   0 4px 16px rgba(42,36,32,0.12);
  --shadow-lg:   0 8px 32px rgba(42,36,32,0.18);

  /* Transitions */
  --ease:        cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #1e1a16;
    --surface:     #262018;
    --surface2:    #2c261e;
    --card:        #302820;
    --card2:       #3a3028;
    --border:      #48403a;
    --border-soft: #3a3530;
    --text:        #ede8e0;
    --text-sec:    #b8afa4;
    --text-dim:    #7a7068;
    --text-ghost:  #504840;
    --user-bg:     #6b5230;
    --user-bg2:    #7a6040;
    --user-text:   #f0ece6;
    --ai-bg:       #2c261e;
    --ai-border:   #48403a;
    --code-bg:     #1a1612;
    --code-text:   #e8dfd0;
    --code-border: #2a2420;
    --accent-dim:  rgba(138,104,64,0.2);
    --accent-glow: rgba(138,104,64,0.3);
  }
}

/* ===================== TYPOGRAPHY ===================== */
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, 'SF Pro Text', 'Inter', 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

::selection { background: var(--accent); color: #fff; }

/* ===================== SCROLLBAR ===================== */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ===================== ANIMATIONS ===================== */
@keyframes breathe {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.95); }
}

@keyframes pulse-ring {
  0% { transform: scale(0.8); opacity: 1; }
  100% { transform: scale(2.2); opacity: 0; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(192,64,64,0.6); }
  50% { box-shadow: 0 0 0 12px rgba(192,64,64,0); }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ===================== LOGIN SCREEN ===================== */
.login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  flex-direction: column;
  gap: 32px;
  animation: fade-in 0.4s var(--ease);
}

.login-screen h1 {
  color: var(--accent);
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 8px;
  font-family: 'SF Mono', 'JetBrains Mono', monospace;
  text-shadow: 0 2px 8px var(--accent-dim);
}

.login-screen > p {
  color: var(--text-dim);
  font-size: 13px;
  letter-spacing: 0.5px;
}

.login-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 36px;
  width: 340px;
  max-width: 90vw;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow-lg);
}

.login-box input {
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
  outline: none;
}

.login-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.login-box input::placeholder { color: var(--text-dim); }

.login-box button {
  padding: 13px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: background 0.2s, transform 0.15s var(--ease-spring);
}

.login-box button:hover {
  background: var(--accent2);
  transform: scale(1.02);
}

.login-box button:active { transform: scale(0.98); }

.login-error {
  color: var(--danger);
  font-size: 12px;
  text-align: center;
  display: none;
  animation: slideIn 0.2s var(--ease);
}

/* ===================== HEADER ===================== */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  position: relative;
  z-index: 100;
}

header h1 {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 4px;
  font-family: 'SF Mono', 'JetBrains Mono', monospace;
  white-space: nowrap;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
}

header .status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-dim);
  min-width: 0;
}

header .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
  animation: breathe 3s ease-in-out infinite;
  flex-shrink: 0;
}

header .nav-links {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

header .nav-links a {
  color: var(--text-dim);
  text-decoration: none;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-family: monospace;
  letter-spacing: 0.5px;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}

header .nav-links a:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
}

/* Mode tabs in header */
.mode-tabs {
  display: flex;
  gap: 3px;
  background: var(--bg);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.mode-tab {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.8px;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}

.mode-tab:hover { color: var(--accent); background: var(--accent-dim); }

.mode-tab.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 4px var(--accent-glow);
}

.mode-tab[data-mode="claude"].active { background: #7a5a8a; }
.mode-tab[data-mode="dual"].active { background: #4a7a40; }

/* Mobile header buttons */
.btn-menu-mobile, .btn-new-mobile {
  display: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s var(--ease-spring);
}

.btn-menu-mobile {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 18px;
}

.btn-new-mobile {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 20px;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.btn-menu-mobile:hover, .btn-new-mobile:hover { transform: scale(1.08); }

/* ===================== PROVIDER BAR ===================== */
.provider-bar {
  padding: 3px 16px;
  font-size: 9px;
  color: var(--text-dim);
  background: var(--surface);
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  letter-spacing: 0.3px;
}

.provider-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 2px;
}

.provider-dot.up { background: var(--success); box-shadow: 0 0 4px rgba(90,128,64,0.5); }
.provider-dot.down { background: var(--danger); }

/* ===================== LAYOUT ===================== */
.layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ===================== SIDEBAR ===================== */
.sidebar {
  width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.28s var(--ease);
}

.sidebar-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-header span {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 600;
}

.btn-new {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  transition: background 0.2s, transform 0.15s var(--ease-spring);
  box-shadow: 0 2px 6px var(--accent-glow);
}

.btn-new:hover { background: var(--accent2); transform: scale(1.05); }
.btn-new:active { transform: scale(0.96); }

.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.conv-item {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-sec);
  transition: background 0.15s, color 0.15s;
  margin-bottom: 2px;
  border-left: 2.5px solid transparent;
  position: relative;
  animation: slideIn 0.2s var(--ease);
}

.conv-item:hover { background: var(--card); color: var(--text); }

.conv-item.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 500;
}

.conv-item .conv-time {
  font-size: 9px;
  color: var(--text-ghost);
  margin-top: 3px;
}

.conv-item .conv-del {
  float: right;
  opacity: 0;
  font-size: 14px;
  color: var(--danger);
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  transition: opacity 0.15s;
}

.conv-item:hover .conv-del { opacity: 0.7; }
.conv-item .conv-del:hover { opacity: 1 !important; }

/* ===================== MODEL BAR (sidebar bottom) ===================== */
.model-bar {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.model-bar > div:first-child {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.model-bar label {
  font-size: 10px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: color 0.15s;
}

.model-bar label:hover { color: var(--accent); }

.model-bar input[type="checkbox"] {
  width: 13px;
  height: 13px;
  accent-color: var(--accent);
  cursor: pointer;
}

.model-bar select {
  width: 100%;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-family: monospace;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
}

.model-bar select:focus { border-color: var(--accent); }

.model-bar .model-info {
  font-size: 9px;
  color: var(--text-ghost);
  display: flex;
  justify-content: space-between;
}

.mode-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.mode-row > label {
  font-size: 9px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  white-space: nowrap;
}

.mode-row select {
  flex: 1;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  cursor: pointer;
  outline: none;
}

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

/* ===================== MESSAGES AREA ===================== */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 32px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
}

/* ===================== MESSAGE BUBBLES ===================== */
.msg {
  display: flex;
  gap: 10px;
  max-width: 80%;
  animation: slideUp 0.25s var(--ease);
  margin-bottom: 2px;
}

.msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

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

/* Avatar */
.msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
  align-self: flex-end;
  margin-bottom: 18px; /* above meta line */
}

.msg.user .msg-avatar {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.msg.ai .msg-avatar {
  background: var(--card);
  border: 1.5px solid var(--border);
  color: var(--accent);
  font-size: 15px;
}

/* User avatars by name */
.msg-avatar[data-user="jonathan"] { background: linear-gradient(135deg, #8a6840, #a07848); }
.msg-avatar[data-user="reine"]    { background: linear-gradient(135deg, #8a4060, #a05070); }
.msg-avatar[data-user="anthony"]  { background: linear-gradient(135deg, #6840a0, #8050c0); }
.msg-avatar[data-user="zlata"]    { background: linear-gradient(135deg, #40808a, #50a0b0); }
.msg-avatar[data-user="loic"]     { background: linear-gradient(135deg, #4a8040, #60a050); }

.msg-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  max-width: 100%;
}

/* Bubble */
.msg-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  line-height: 1.65;
  font-size: 13.5px;
  position: relative;
  word-break: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
}

.msg.user .msg-bubble {
  background: linear-gradient(135deg, var(--user-bg), var(--user-bg2));
  color: var(--user-text);
  border-bottom-right-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.msg.ai .msg-bubble {
  background: var(--ai-bg);
  border: 1px solid var(--ai-border);
  color: var(--text);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

/* Message body images */
.msg-bubble img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  margin: 6px 0;
  display: block;
}

/* Inline code */
.msg-bubble code {
  background: rgba(42,36,32,0.1);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: 'SF Mono', 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--accent3);
}

.msg.user .msg-bubble code {
  background: rgba(42,36,32,0.15);
  color: var(--user-text);
}

/* Code blocks */
.msg-bubble pre {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: 8px 0;
  border: 1px solid var(--code-border);
  font-size: 12px;
  line-height: 1.5;
  position: relative;
}

.msg-bubble pre code {
  background: none;
  padding: 0;
  color: var(--code-text);
  font-size: 12px;
}

/* ===================== ACTION BUTTONS (copy/tts) ===================== */
.msg-actions {
  display: flex;
  gap: 4px;
  position: absolute;
  top: 6px;
  right: 6px;
  opacity: 0;
  transition: opacity 0.15s;
}

.msg-bubble:hover .msg-actions { opacity: 1; }

.btn-copy, .btn-tts {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 3px 7px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 10px;
  line-height: 1;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  white-space: nowrap;
}

/* Legacy: keep positional selectors working for existing JS */
.btn-copy {
  position: absolute;
  top: 4px;
  right: 4px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, border-color 0.15s;
}

.btn-tts {
  position: absolute;
  top: 4px;
  right: 36px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, border-color 0.15s;
}

.msg-bubble:hover .btn-copy,
.msg-bubble:hover .btn-tts { opacity: 0.7; }

.btn-copy:hover, .btn-tts:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
  opacity: 1 !important;
}

.btn-copy.copied {
  color: var(--success);
  border-color: var(--success);
  opacity: 1 !important;
}

.btn-tts.speaking {
  color: var(--danger);
  border-color: var(--danger);
  opacity: 1 !important;
}

/* ===================== MESSAGE META ===================== */
.msg-meta {
  font-size: 9.5px;
  color: var(--text-ghost);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 2px;
}

.msg.user .msg-meta { justify-content: flex-end; }
.msg.ai .msg-meta { justify-content: flex-start; }

.msg-ts { font-size: 9px; }

/* Model indicator under AI messages */
.msg-model-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 8.5px;
  color: var(--text-ghost);
  background: var(--surface);
  border: 1px solid var(--border-soft);
  padding: 1px 6px;
  border-radius: var(--radius-full);
  font-family: monospace;
  letter-spacing: 0.2px;
}

/* ===================== THINKING BLOCK ===================== */
.msg-thinking {
  font-size: 11px;
  color: var(--text-dim);
  font-style: italic;
  padding: 6px 12px;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-soft);
}

.thinking-pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: breathe 1.2s ease-in-out infinite;
  flex-shrink: 0;
}

/* ===================== SHELL RESULTS ===================== */
.shell-result {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin-top: 8px;
  font-family: 'SF Mono', 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--code-text);
}

.shell-result .shell-cmd {
  color: var(--accent);
  font-size: 10px;
  margin-bottom: 6px;
  opacity: 0.9;
}

.shell-result pre {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  color: var(--code-text);
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ===================== TYPING INDICATOR ===================== */
.typing {
  display: none;
  align-self: flex-start;
  padding: 4px 0 4px 44px;
}

.typing.show { display: flex; }

.typing-dots {
  display: flex;
  gap: 5px;
  padding: 11px 16px;
  background: var(--ai-bg);
  border: 1px solid var(--ai-border);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  display: block;
  animation: bounce 1.4s ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

/* ===================== WELCOME SCREEN ===================== */
.welcome-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  color: var(--text-dim);
  padding: 32px;
  text-align: center;
}

.welcome-screen h2 {
  color: var(--accent);
  font-size: 28px;
  font-weight: 300;
  letter-spacing: 8px;
  font-family: 'SF Mono', 'JetBrains Mono', monospace;
}

.welcome-screen p {
  font-size: 13px;
  max-width: 440px;
  line-height: 1.7;
  color: var(--text-sec);
}

.welcome-screen .shortcuts {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 600px;
}

.welcome-screen .shortcut {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 9px 16px;
  border-radius: var(--radius-full);
  cursor: pointer;
  font-size: 12px;
  transition: border-color 0.2s, color 0.2s, background 0.2s, transform 0.15s var(--ease-spring);
  color: var(--text-sec);
}

.welcome-screen .shortcut:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
  transform: scale(1.03);
}

.welcome-screen .shortcut:active { transform: scale(0.97); }

/* ===================== INPUT AREA ===================== */
.input-area {
  padding: 10px 24px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

/* Mobile toggles (shown only on mobile) */
.input-toggles {
  display: none;
  gap: 10px;
  padding: 0 4px 6px;
  font-size: 9px;
  color: var(--text-dim);
}

.input-toggles label {
  display: flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
}

.input-toggles input[type="checkbox"] {
  width: 13px;
  height: 13px;
  accent-color: var(--accent);
}

/* File preview */
.file-preview {
  display: none;
  padding: 4px 4px 8px;
}

.file-preview.show {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.file-preview-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 5px 10px;
  font-size: 11px;
  color: var(--text-dim);
  max-width: 260px;
}

.file-preview-item img {
  max-height: 44px;
  max-width: 72px;
  border-radius: var(--radius-sm);
  object-fit: cover;
}

.file-preview-item .file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}

.file-preview-item .file-remove {
  cursor: pointer;
  color: var(--danger);
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
  transition: opacity 0.15s;
}

.file-preview-item .file-remove:hover { opacity: 0.7; }

/* Input wrapper */
.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 6px 6px 6px 10px;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim), var(--shadow-sm);
}

.input-wrap textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  padding: 6px 4px;
  resize: none;
  max-height: 150px;
  min-height: 34px;
  line-height: 1.55;
  outline: none;
  align-self: center;
}

.input-wrap textarea::placeholder { color: var(--text-dim); }

/* File attach button */
.btn-file {
  background: transparent;
  border: none;
  color: var(--text-dim);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 17px;
  transition: color 0.2s, background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-file:hover { color: var(--accent); background: var(--accent-dim); }

/* Microphone button — circular, beautiful */
.btn-mic {
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--text-dim);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 17px;
  transition: all 0.2s var(--ease);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}

.btn-mic:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
  transform: scale(1.08);
}

.btn-mic.recording {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  animation: mic-pulse 1.2s ease-in-out infinite;
  transform: scale(1.05);
}

/* Send button */
.btn-send {
  background: var(--accent);
  color: #fff;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  font-weight: 700;
  transition: background 0.2s, transform 0.15s var(--ease-spring), box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.btn-send:hover {
  background: var(--accent2);
  transform: scale(1.1);
  box-shadow: 0 4px 14px var(--accent-glow);
}

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

.btn-send:disabled {
  background: var(--border);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-stop {
  background: var(--danger) !important;
  box-shadow: 0 2px 8px var(--danger-dim) !important;
}

/* ===================== STATS BAR ===================== */
.stats-bar {
  padding: 4px 16px;
  font-size: 9px;
  color: var(--text-ghost);
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--border-soft);
  background: var(--surface);
  flex-shrink: 0;
  font-family: monospace;
  letter-spacing: 0.3px;
}

/* ===================== SIDEBAR OVERLAY (mobile) ===================== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 998;
  opacity: 0;
  transition: opacity 0.28s var(--ease);
  backdrop-filter: blur(2px);
}

.sidebar-overlay.visible { opacity: 1; }

/* ===================== MOBILE ===================== */
@media (max-width: 768px) {
  /* Sidebar slides in from left */
  .sidebar {
    display: flex !important;
    position: fixed;
    top: 0;
    left: 0;
    width: 82vw;
    max-width: 320px;
    height: 100dvh;
    z-index: 999;
    box-shadow: var(--shadow-lg);
    transform: translateX(-100%);
    transition: transform 0.28s var(--ease);
  }

  .sidebar.mobile-open { transform: translateX(0) !important; }

  .layout { flex-direction: column; }

  /* Show mobile buttons in header */
  .btn-new-mobile,
  .btn-menu-mobile { display: flex; }

  /* Hide desktop nav links */
  header .nav-links { display: none !important; }
  .provider-bar { display: none !important; }
  .stats-bar { display: none !important; }
  .input-toggles { display: flex; gap: 8px; padding: 2px 4px 6px; font-size: 8.5px; }

  /* Messages */
  .messages { padding: 8px 10px; gap: 3px; }
  .msg { max-width: 96% !important; gap: 6px; }

  .msg-bubble {
    font-size: 13.5px;
    padding: 9px 12px;
    max-width: calc(100vw - 70px) !important;
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
  }

  .msg-bubble pre {
    font-size: 10px;
    max-width: calc(100vw - 80px) !important;
    overflow-x: auto !important;
    white-space: pre-wrap !important;
    word-break: break-all !important;
  }

  .msg-avatar { width: 28px !important; height: 28px !important; font-size: 11px !important; }

  /* Header compact */
  header { padding: 0 10px; height: 48px; gap: 8px; }
  header h1 { font-size: 12px; letter-spacing: 2px; }
  header .status { font-size: 8px; gap: 3px; }
  .mode-tabs { gap: 2px; }
  .mode-tab { padding: 3px 9px; font-size: 9px; }

  /* Input */
  .input-area { padding: 6px 10px 10px; }
  .input-wrap { padding: 4px 4px 4px 8px; border-radius: var(--radius-lg); gap: 6px; }
  .input-wrap textarea { font-size: 15px; min-height: 32px; }

  .btn-send, .btn-mic { width: 34px !important; height: 34px !important; font-size: 15px !important; }
  .btn-file { width: 32px !important; height: 32px !important; font-size: 15px !important; }

  /* Welcome */
  .welcome-screen { padding: 20px 16px; gap: 14px; }
  .welcome-screen h2 { font-size: 20px; letter-spacing: 4px; }
  .welcome-screen p { font-size: 12px; }
  .welcome-screen .shortcut { font-size: 11px !important; padding: 7px 12px !important; }

  /* File preview */
  .file-preview-item img { max-height: 36px; max-width: 56px; }

  /* Copy/TTS always slightly visible on touch */
  .btn-copy, .btn-tts { opacity: 0.35 !important; padding: 2px 5px; font-size: 9px; }

  /* Shell output */
  .shell-result { max-width: calc(100vw - 40px) !important; overflow-x: auto !important; font-size: 10px !important; }
  .shell-result pre { white-space: pre-wrap !important; word-break: break-all !important; }

  /* Typing indicator */
  .typing { padding-left: 34px; }

  /* Model bar compact */
  .model-bar { padding: 4px 8px; font-size: 9px; }
  .model-bar > div:first-child { flex-wrap: wrap; gap: 6px !important; }
  .model-bar .model-info { display: none; }
}

/* ===================== TABLES ===================== */
.msg-bubble table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 12px;
  display: block;
  overflow-x: auto;
  max-width: 100%;
}

.msg-bubble th {
  background: var(--surface);
  padding: 6px 10px;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid var(--border);
  color: var(--accent);
  white-space: nowrap;
}

.msg-bubble td {
  padding: 5px 10px;
  border-bottom: 1px solid var(--border-soft);
}

.msg-bubble tr:last-child td { border-bottom: none; }
.msg-bubble tr:hover td { background: var(--accent-dim); }

/* ===================== ERROR STATE ===================== */
.msg-error {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--danger-dim);
  border: 1px solid rgba(192,64,64,0.25);
  border-radius: var(--radius-md);
  color: var(--danger);
  font-size: 13px;
}

.btn-retry {
  background: var(--danger);
  color: #fff;
  border: none;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  transition: opacity 0.15s;
  margin-left: auto;
  white-space: nowrap;
}

.btn-retry:hover { opacity: 0.85; }

/* ===================== FOCUS & A11Y ===================== */
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
