/* ---------- Variables ---------- */
:root {
  /* Shared Defaults */
  --radius-md: 0.25rem;
  --radius-lg: 0.5rem;
  --radius-xl: 0.75rem;
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'Fira Code', monospace;

  /* Default to Dark Theme if no data-theme is present */
  --bg-app: #020617;
  --bg-panel: #0f172a;
  --bg-sidebar: #0f172a;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --accent-primary: #06b6d4;
  --accent-hover: #0891b2;
  --accent-glow: rgba(6, 182, 212, 0.5);
  --border-light: #1e293b;
  --msg-user: #0e7490;
  --msg-user-text: #ffffff;
  --msg-ai: #1e293b;
  --msg-ai-border: #334155;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5), 0 2px 4px -2px rgb(0 0 0 / 0.5);
  --shadow-glow: 0 0 15px rgba(6, 182, 212, 0.15);
  --backdrop-alpha: 0.8;
  --grid-opacity: 0.03;
  --iframe-filter: invert(1) hue-rotate(180deg);
}

/* Light Theme (Legacy Neural Slate) */
[data-theme="light"] {
  --bg-app: #f8fafc;
  --bg-panel: #ffffff;
  --bg-sidebar: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --accent-primary: #4f46e5;
  --accent-hover: #4338ca;
  --accent-glow: rgba(79, 70, 229, 0.3);
  --border-light: #e2e8f0;
  --msg-user: #e0e7ff;
  --msg-user-text: #1e1b4b;
  --msg-ai: #ffffff;
  --msg-ai-border: #f1f5f9;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-glow: 0 0 10px rgba(79, 70, 229, 0.15);
  --backdrop-alpha: 0.8;
  --grid-opacity: 0.05;
  --iframe-filter: none;
}

/* Dark Theme (Techi Cyber - Default) */
[data-theme="dark"] {
  --bg-app: #020617;
  --bg-panel: #0f172a;
  --bg-sidebar: #0f172a;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --accent-primary: #06b6d4;
  --accent-hover: #0891b2;
  --accent-glow: rgba(6, 182, 212, 0.5);
  --border-light: #1e293b;
  --msg-user: #0e7490;
  --msg-user-text: #ffffff;
  --msg-ai: #1e293b;
  --msg-ai-border: #334155;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5), 0 2px 4px -2px rgb(0 0 0 / 0.5);
  --shadow-glow: 0 0 15px rgba(6, 182, 212, 0.15);
  --backdrop-alpha: 0.8;
  --grid-opacity: 0.03;
  --iframe-filter: invert(1) hue-rotate(180deg);
}

/* Ocean Theme */
[data-theme="ocean"] {
  --bg-app: #0f172a;
  --bg-panel: #1e293b;
  --bg-sidebar: #1e293b;
  --text-main: #f0f9ff;
  --text-muted: #94a3b8;
  --accent-primary: #38bdf8;
  --accent-hover: #0ea5e9;
  --accent-glow: rgba(56, 189, 248, 0.5);
  --border-light: #334155;
  --msg-user: #0284c7;
  --msg-user-text: #ffffff;
  --msg-ai: #1e293b;
  --msg-ai-border: #475569;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5);
  --shadow-glow: 0 0 15px rgba(56, 189, 248, 0.15);
  --backdrop-alpha: 0.8;
  --grid-opacity: 0.03;
  --iframe-filter: invert(1) hue-rotate(180deg);
}

/* Forest Theme */
[data-theme="forest"] {
  --bg-app: #052e16;
  --bg-panel: #064e3b;
  --bg-sidebar: #064e3b;
  --text-main: #ecfdf5;
  --text-muted: #a7f3d0;
  --accent-primary: #34d399;
  --accent-hover: #10b981;
  --accent-glow: rgba(52, 211, 153, 0.5);
  --border-light: #065f46;
  --msg-user: #059669;
  --msg-user-text: #ffffff;
  --msg-ai: #064e3b;
  --msg-ai-border: #047857;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5);
  --shadow-glow: 0 0 15px rgba(52, 211, 153, 0.15);
  --backdrop-alpha: 0.8;
  --grid-opacity: 0.05;
  --iframe-filter: invert(1) hue-rotate(90deg);
}

/* Sunset Theme */
[data-theme="sunset"] {
  --bg-app: #2a0a18;
  --bg-panel: #451a2d;
  --bg-sidebar: #451a2d;
  --text-main: #fff1f2;
  --text-muted: #fda4af;
  --accent-primary: #fb7185;
  --accent-hover: #f43f5e;
  --accent-glow: rgba(251, 113, 133, 0.5);
  --border-light: #831843;
  --msg-user: #be123c;
  --msg-user-text: #ffffff;
  --msg-ai: #500724;
  --msg-ai-border: #831843;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5);
  --shadow-glow: 0 0 15px rgba(251, 113, 133, 0.2);
  --backdrop-alpha: 0.8;
  --grid-opacity: 0.05;
  --iframe-filter: invert(1) sepia(100%) hue-rotate(300deg);
}

/* Matrix Theme */
[data-theme="matrix"] {
  --bg-app: #000000;
  --bg-panel: #0a0a0a;
  --bg-sidebar: #0a0a0a;
  --text-main: #00ff41;
  --text-muted: #008f11;
  --accent-primary: #00ff41;
  --accent-hover: #008f11;
  --accent-glow: rgba(0, 255, 65, 0.5);
  --border-light: #003b00;
  --msg-user: #003b00;
  --msg-user-text: #00ff41;
  --msg-ai: #0a0a0a;
  --msg-ai-border: #00ff41;
  --shadow-sm: 0 1px 2px 0 rgb(0 59 0 / 0.5);
  --shadow-md: 0 4px 6px -1px rgb(0 59 0 / 0.5);
  --shadow-glow: 0 0 10px rgba(0, 255, 65, 0.3);
  --backdrop-alpha: 0.95;
  --grid-opacity: 0.1;
  --iframe-filter: invert(1) grayscale(100%) brightness(0.8) sepia(100%) hue-rotate(50deg) saturate(500%);
}

/* ---------- Reset & Base ---------- */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  background-image:
    linear-gradient(rgba(6, 182, 212, var(--grid-opacity)) 1px, transparent 1px),
    linear-gradient(90deg, rgba(6, 182, 212, var(--grid-opacity)) 1px, transparent 1px);
  background-size: 40px 40px;
}

a {
  text-decoration: none;
  color: var(--text-muted);
  transition: color 0.15s;
}

a:hover {
  color: var(--accent-primary);
}

h3,
h4 {
  margin: 0 0 0.5rem 0;
  font-weight: 600;
}

/* ---------- Header ---------- */
header {
  height: 64px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-panel);
  background: color-mix(in srgb, var(--bg-panel), transparent calc(100% * (1 - var(--backdrop-alpha, 0.9))));
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-sm);
  z-index: 100;
  position: relative;
}

header strong {
  font-size: 1.125rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

header a.nav-link {
  font-size: 0.95rem;
  font-weight: 500;
}

/* Hamburger Button - Always visible */
.hamburger-btn {
  display: inline-flex;
  padding: 8px;
  font-size: 1.25rem;
}

/* Social Links */
.social-link {
  display: flex;
  align-items: center;
  color: var(--text-muted);
  transition: color 0.2s, transform 0.2s;
}

.social-link:hover {
  color: var(--accent-primary);
  transform: translateY(-2px);
}

.social-link svg {
  display: block;
}

/* Header Icon Buttons (mimic social links) */
.header-icon-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
  /* Minimal padding */
  color: var(--text-muted);
  transition: color 0.2s, transform 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.header-icon-btn:hover {
  color: var(--accent-primary);
  transform: translateY(-2px);
  background: transparent;
  box-shadow: none;
}

.header-icon-btn:active {
  transform: translateY(0);
}

/* Icon Buttons */
.icon-btn {
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-main);
  padding: 8px;
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: var(--bg-panel);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

/* ---------- Layout ---------- */
#layout {
  display: flex;
  height: calc(100vh - 64px);
  overflow: hidden;
}

/* Sidebar */
#sidebar {
  width: 320px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-light);
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  flex-shrink: 0;
  transition: transform 0.3s ease;
  z-index: 90;
}

#sidebar.collapsed {
  transform: translateX(-100%);
}

/* Sidebar Overlay - Works on all screen sizes */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 64px;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 85;
  backdrop-filter: blur(4px);
}

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

/* Main Content */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px;
  overflow: hidden;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.scroll-y {
  overflow-y: auto !important;
}

hr {
  border: 0;
  height: 1px;
  background: var(--border-light);
  margin: 0;
}

/* ---------- Chat Area ---------- */
/* ---------- Chat Area ---------- */
.chat-container {
  flex: 1;
  display: flex;
  gap: 16px;
  overflow: hidden;
  margin-bottom: 16px;
  min-height: 0;
  /* Important for nested flex scroll */
}

.chat-pane {
  flex: 1;
  background: var(--bg-panel);
  border-radius: var(--radius-xl);
  padding: 20px;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-light);
  scroll-behavior: smooth;
}

.chat-pane.hidden {
  display: none !important;
}

.model-selector-group.hidden {
  display: none !important;
}

/* Compare Mode specific adjustments */
.compare-mode .chat-pane {
  border-color: var(--accent-primary);
  /* Optional hint */
}

/* Model Status Headers inside Chat */
.model-status-header {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-main);
  padding-left: 4px;
  border-left: 3px solid var(--accent-primary);
  line-height: 1.2;
}

.chat-header-pane.hidden {
  display: none !important;
}

/* Active Button State (for Compare/Toggle) */
button.active {
  background: var(--bg-panel);
  color: var(--accent-primary);
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-glow);
}


.msg {
  max-width: 80%;
  margin-bottom: 16px;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  line-height: 1.6;
  word-wrap: break-word;
  font-size: 0.95rem;
  position: relative;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.msg.user {
  background: var(--msg-user);
  color: var(--msg-user-text);
  margin-left: auto;
  border-bottom-right-radius: 4px;
}

.msg.model,
.msg.assistant {
  background: var(--msg-ai);
  border: 1px solid var(--msg-ai-border);
  margin-right: auto;
  border-bottom-left-radius: 4px;
}

/* Markdown Styles inside messages */
.msg p {
  margin: 0.5em 0;
}

.msg p:first-child {
  margin-top: 0;
}

.msg p:last-child {
  margin-bottom: 0;
}

.msg code {
  font-family: 'Fira Code', monospace;
  font-size: 0.9em;
  background: rgba(0, 0, 0, 0.06);
  padding: 2px 4px;
  border-radius: 4px;
}

.msg pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.5em 0;
}

.msg pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}

/* ---------- Inputs & Controls ---------- */
label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

input,
textarea,
select {
  width: 100%;
  padding: 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  font-size: 14px;
  font-family: var(--font-mono);
  background: var(--bg-app);
  color: var(--text-main);
  transition: border 0.15s, box-shadow 0.15s, background 0.15s;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent-primary);
  background: var(--bg-panel);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

textarea {
  resize: vertical;
}

/* Model Search */
.model-search-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 400px;
}

#modelSearch {
  padding: 8px 12px;
  font-family: var(--font-sans);
}

#modelSelect {
  height: auto;
  min-height: 180px;
  font-size: 0.85rem;
  padding: 4px;
}

#modelSelect option {
  padding: 6px 8px;
  border-radius: 4px;
  margin: 2px 0;
}

/* Ranges */
input[type="range"] {
  padding: 0;
  height: 6px;
  background: var(--border-light);
  border-radius: 3px;
  appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  background: var(--accent-primary);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.1);
}

/* Buttons */
button {
  background: var(--accent-primary);
  color: white;
  border: none;
  cursor: pointer;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 0.9rem;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-glow);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

button:disabled {
  background: var(--border-light);
  color: var(--text-muted);
  cursor: not-allowed;
  transform: none;
}

button.secondary {
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-main);
}

button.secondary:hover:not(:disabled) {
  background: var(--bg-panel);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  box-shadow: var(--shadow-glow);
}

/* Quick Models Chips */
#quickModelsView {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

#quickModelsView button {
  font-size: 0.8rem;
  padding: 6px 10px;
  background: rgba(6, 182, 212, 0.1);
  color: var(--accent-primary);
  border: 1px solid var(--accent-primary);
  opacity: 0.8;
}

#quickModelsView button:hover {
  background: rgba(6, 182, 212, 0.2);
  border-color: var(--accent-primary);
  transform: none;
  box-shadow: var(--shadow-glow);
}

/* Model Badges */
.model-badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 3px;
  margin-left: 6px;
  font-weight: 600;
}

.badge-recommended {
  background: rgba(34, 197, 94, 0.2);
  color: #22c55e;
  border: 1px solid #22c55e;
}

.badge-downloaded {
  background: rgba(59, 130, 246, 0.2);
  color: #3b82f6;
  border: 1px solid #3b82f6;
}

/* Storage Info */
.storage-info {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 0.85rem;
  font-family: var(--font-mono);
}

.storage-bar {
  height: 6px;
  background: var(--bg-app);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 6px;
}

.storage-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-hover));
  transition: width 0.3s ease;
}

/* Download Button */
.download-btn {
  font-size: 0.75rem;
  padding: 4px 8px;
  margin-left: 8px;
  background: rgba(34, 197, 94, 0.1);
  color: #22c55e;
  border: 1px solid #22c55e;
}

.download-btn:hover {
  background: rgba(34, 197, 94, 0.2);
}

/* Delete Button on Quick Models */
.quick-model-item {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.delete-model-btn {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  border: 1px solid #ef4444;
  padding: 4px 8px;
  font-size: 0.75rem;
  margin-left: 4px;
}

.delete-model-btn:hover {
  background: rgba(239, 68, 68, 0.2);
  transform: scale(1.05);
}

/* Confirmation Dialog */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 200;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow-md);
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-main);
}

.modal-message {
  color: var(--text-muted);
  margin-bottom: 20px;
  line-height: 1.5;
}

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

.modal-buttons button {
  padding: 8px 16px;
}

/* ---------- System Prompt Section ---------- */
.system-prompt-section {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
  overflow: hidden;
  transition: all 0.3s ease;
}

.system-prompt-header {
  padding: 12px 16px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
  transition: background 0.2s;
}

.system-prompt-header:hover {
  background: var(--bg-app);
}

.system-prompt-header h4 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
}

.collapse-icon {
  font-size: 0.8rem;
  color: var(--text-muted);
  transition: transform 0.3s ease;
  display: inline-block;
}

.system-prompt-section:not(.collapsed) .collapse-icon {
  transform: rotate(90deg);
}

.prompt-preview {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 300px;
}

.system-prompt-section:not(.collapsed) .prompt-preview {
  display: none;
}

.system-prompt-content {
  padding: 0 16px 16px 16px;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
}

.system-prompt-section:not(.collapsed) .system-prompt-content {
  max-height: 400px;
  opacity: 1;
  padding: 0 16px 16px 16px;
}

.system-prompt-section.collapsed .system-prompt-content {
  padding: 0 16px;
}

#promptPresets {
  margin-bottom: 8px;
}

#systemPrompt {
  width: 100%;
  min-height: 80px;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  line-height: 1.5;
}

#promptCharCount {
  font-size: 0.75rem;
}

/* Mobile adjustments for system prompt */
@media (max-width: 768px) {
  .prompt-preview {
    max-width: 150px;
  }

  .system-prompt-header {
    padding: 10px 12px;
  }

  #editPromptBtn {
    padding: 4px 8px;
    font-size: 0.8rem;
  }
}

/* ---------- Input Bar ---------- */
#inputBar {
  display: flex;
  gap: 12px;
  background: var(--bg-panel);
  padding: 16px;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-light);
  position: relative;
}

#userInput {
  flex: 1;
  border: 1px solid transparent;
  background: var(--bg-app);
  min-height: 44px;
}

#userInput:focus {
  background: var(--bg-sidebar);
  border-color: var(--accent-primary);
}

.input-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Button Text/Icon for responsive design */
.btn-text {
  display: inline;
}

.btn-icon {
  display: none;
}

/* ---------- Status Bar ---------- */
#status {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  min-height: 1.4em;
  display: flex;
  align-items: center;
  gap: 8px;
}

#tokenStatus {
  margin-bottom: 12px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  font-size: 0.85rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  display: block;
}

/* ---------- Browser Specific ---------- */
#browserFrame {
  width: 100%;
  height: 60vh;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  background: white;
  margin-bottom: 16px;
  filter: var(--iframe-filter, none);
}

/* ---------- Animations ---------- */
.cursor-blink {
  animation: blink 1s step-end infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* ---------- Loading Spinner ---------- */
.loading-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-light);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ---------- MOBILE RESPONSIVE ---------- */
@media (max-width: 768px) {
  header {
    padding: 0 12px;
    gap: 12px;
  }

  header strong {
    font-size: 1rem;
  }

  header a.nav-link {
    display: none;
  }

  #sidebar {
    position: fixed;
    top: 64px;
    left: 0;
    bottom: 0;
    width: 85%;
    max-width: 320px;
    transform: translateX(-100%);
    border-right: none;
    box-shadow: var(--shadow-md);
  }

  #sidebar:not(.collapsed) {
    transform: translateX(0);
  }

  #closeSidebarBtn {
    display: inline-flex;
  }

  #main {
    padding: 12px;
    width: 100%;
  }

  #chat {
    padding: 12px;
    margin-bottom: 12px;
  }

  .msg {
    max-width: 90%;
    font-size: 0.9rem;
    padding: 10px 12px;
  }

  #inputBar {
    padding: 12px;
    gap: 8px;
    flex-direction: column;
  }

  .input-buttons {
    flex-direction: row;
    width: 100%;
  }

  .input-buttons button {
    flex: 1;
    padding: 12px;
  }

  #userInput {
    width: 100%;
    min-height: 44px;
    font-size: 16px;
    /* Prevents zoom on iOS */
  }

  /* Show icons instead of text on mobile */
  .btn-text {
    display: none;
  }

  .btn-icon {
    display: inline;
    font-size: 1.2rem;
  }

  #status {
    font-size: 0.8rem;
  }

  #tokenStatus {
    font-size: 0.75rem;
    padding: 6px 10px;
  }

  /* Hide social links on very small screens */
  @media (max-width: 480px) {
    .social-link svg {
      width: 16px;
      height: 16px;
    }

    header a.nav-link {
      display: none;
    }
  }

  /* Compare Mode Mobile Stack */
  .chat-container {
    flex-direction: column;
  }

  #chatHeaderContainer {
    flex-direction: column;
    gap: 4px !important;
  }

  #tokenStatusContainer {
    flex-direction: column;
    gap: 4px !important;
  }
}

/* Tablet adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
  #sidebar {
    width: 280px;
  }

  #main {
    padding: 16px;
  }

  .msg {
    max-width: 85%;
  }
}

/* ---------- Level 2: Assistant Mode ---------- */
.mode-switcher select {
  font-size: 0.9rem;
  padding: 6px 10px;
  background: var(--bg-app);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s;
}

.mode-switcher select:hover {
  border-color: var(--accent-primary);
}

.mode-switcher select:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

/* Tools Panel */
#toolsPanel {
  margin-top: 16px;
  animation: fadeIn 0.3s ease-out;
}

#toolsPanel h3 {
  margin: 12px 0 8px 0;
  font-size: 0.95rem;
  color: var(--text-main);
}

#toolsList div {
  padding: 6px 8px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  transition: all 0.2s;
}

#toolsList div:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border-light);
}