/* JARVIS HUD Theme — Mobile-First Dark + Amber/Gold */
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;600&family=Inter:wght@300;400;500;600&display=swap');

:root {
  --bg-primary: #050505;
  --bg-secondary: #0a0f1a;
  --bg-card: #0d1525;
  --bg-input: #111827;
  --border: rgba(245, 158, 11, 0.15);
  --border-active: rgba(245, 158, 11, 0.4);
  --amber: #f59e0b;
  --amber-dim: rgba(245, 158, 11, 0.6);
  --amber-glow: rgba(245, 158, 11, 0.1);
  --text-primary: #e5e7eb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --accent-blue: #3b82f6;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  --font-sans: 'Inter', -apple-system, sans-serif;
  /* Safe areas */
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html {
  /* Prevent overscroll bounce on iOS */
  overscroll-behavior: none;
  height: 100%;
  height: 100dvh;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  /* Prevent pull-to-refresh + double-tap zoom */
  touch-action: manipulation;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

/* ========== MOBILE-FIRST LAYOUT ========== */
/* Single column by default (mobile). Sidebar added on desktop via media query. */
.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: 1fr;
  height: 100vh;
  height: 100dvh;
  gap: 0;
  background: var(--bg-primary);
}

/* ========== PWA Install Button ========== */
.pwa-install-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--amber);
  color: #050505;
  border: none;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.2s;
  animation: pwa-pulse 2s ease-in-out 3;
}
.pwa-install-btn:hover { opacity: 0.85; }
.pwa-install-btn svg { flex-shrink: 0; }
@keyframes pwa-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245,158,11,0.4); }
  50% { box-shadow: 0 0 0 6px rgba(245,158,11,0); }
}

/* ========== PWA Standalone Mode ========== */
@media all and (display-mode: standalone) {
  /* Extra padding when running as installed PWA (no browser chrome) */
  .header { min-height: 52px; }
  /* Disable text selection on interactive elements for app-like feel */
  button, .tab, .conn-btn, .send-btn, .voice-btn { -webkit-user-select: none; user-select: none; }
  /* Hide install button when already installed */
  .pwa-install-btn { display: none !important; }
}

/* ========== Header ========== */
.header {
  grid-column: 1 / -1;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  padding-top: var(--sat);
  min-height: 48px;
  border-bottom: 1px solid var(--border);
  gap: 6px;
  z-index: 10;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.header-logo .arc {
  width: 24px;
  height: 24px;
  border: 2px solid var(--amber);
  border-radius: 50%;
  border-top-color: transparent;
  animation: spin 3s linear infinite;
}

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

.header-logo h1 {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--amber);
  letter-spacing: 3px;
}

.header-status {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  overflow: hidden;
}

.header-status .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-green);
  flex-shrink: 0;
}

/* Hide status text on small screens to save space */
.status-text {
  display: none;
}

/* ========== Sidebar ========== */
/* Hidden on mobile by default */
.sidebar {
  display: none;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-direction: column;
}

.sidebar-section {
  padding: 12px 14px 8px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--amber-dim);
  text-transform: uppercase;
}

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

.session-item {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all 0.15s;
}

.session-item:hover { background: var(--amber-glow); color: var(--text-primary); }
.session-item.active { background: rgba(245, 158, 11, 0.12); color: var(--amber); border-left: 2px solid var(--amber); }

.new-session-btn {
  margin: 8px;
  padding: 10px;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  font-family: var(--font-sans);
  transition: all 0.15s;
}

.new-session-btn:hover { border-color: var(--amber); color: var(--amber); }

/* Tool execution feed */
.tool-feed {
  border-top: 1px solid var(--border);
  padding: 4px 0;
  max-height: 300px;
  overflow-y: auto;
}

.tool-item {
  padding: 6px 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}

.tool-item .icon { font-size: 12px; }
.tool-item.running { color: var(--amber); }
.tool-item.success { color: var(--accent-green); }
.tool-item.error { color: var(--accent-red); }

/* ========== Chat Panel ========== */
.chat-panel {
  background: var(--bg-primary);
  overflow-y: auto;
  padding: 12px 10px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.chat-panel::-webkit-scrollbar { width: 3px; }
.chat-panel::-webkit-scrollbar-track { background: transparent; }
.chat-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.message {
  max-width: 92%;
  margin-bottom: 12px;
  animation: fadeIn 0.2s ease-out;
}

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

.message.user {
  margin-left: auto;
}

.message.user .bubble {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid var(--border);
  border-radius: 16px 16px 4px 16px;
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.5;
}

.message.assistant .bubble {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.04);
  border-radius: 16px 16px 16px 4px;
  padding: 12px 14px;
  font-size: 15px;
  line-height: 1.6;
}

.message.assistant .bubble p { margin-bottom: 8px; }
.message.assistant .bubble p:last-child { margin-bottom: 0; }
.message.assistant .bubble ul, .message.assistant .bubble ol { padding-left: 20px; margin-bottom: 8px; }
.message.assistant .bubble code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: rgba(245, 158, 11, 0.08);
  padding: 2px 6px;
  border-radius: 3px;
  color: var(--amber);
}
.message.assistant .bubble pre {
  background: var(--bg-secondary);
  padding: 10px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
}
.message.assistant .bubble strong { color: var(--amber); font-weight: 500; }

.message .label {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  margin-bottom: 4px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.message.user .label { text-align: right; }

/* Tool call inline */
.tool-call-inline {
  background: rgba(245, 158, 11, 0.06);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 8px 0;
  font-family: var(--font-mono);
  font-size: 11px;
}

.tool-call-inline .tool-name {
  color: var(--amber);
  font-weight: 500;
}

.tool-call-inline .tool-status {
  float: right;
  font-size: 10px;
}

/* Typing indicator */
.typing-indicator {
  display: inline-flex;
  gap: 4px;
  padding: 8px 0;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--amber-dim);
  animation: pulse 1.2s infinite;
}

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

@keyframes pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* ========== Input Bar ========== */
.input-bar {
  grid-column: 1 / -1;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 8px 10px;
  padding-bottom: max(8px, var(--sab));
  gap: 8px;
}

.voice-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
  position: relative;
}

.voice-btn svg { width: 20px; height: 20px; fill: var(--text-muted); transition: fill 0.2s; }
.voice-btn:hover { border-color: var(--amber); }
.voice-btn:hover svg { fill: var(--amber); }
.voice-btn:active { transform: scale(0.92); }

/* Voice states */
.voice-btn.listening {
  border-color: var(--accent-red);
  animation: voicePulse 1.5s infinite;
}
.voice-btn.listening svg { fill: var(--accent-red); }

.voice-btn.thinking {
  border-color: var(--amber);
  animation: voiceSpin 2s linear infinite;
}

.voice-btn.speaking {
  border-color: var(--accent-green);
}
.voice-btn.speaking svg { fill: var(--accent-green); }

@keyframes voicePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
}

@keyframes voiceSpin {
  to { border-top-color: transparent; transform: rotate(360deg); }
}

.input-text {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text-primary);
  /* 16px prevents iOS auto-zoom on focus */
  font-size: 16px;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 0.2s;
  min-width: 0;
}

.input-text:focus { border-color: var(--amber); }
.input-text::placeholder { color: var(--text-muted); }

.send-btn {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: none;
  background: var(--amber);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}

.send-btn:hover { background: #d97706; }
.send-btn:active { transform: scale(0.92); }
.send-btn:disabled { opacity: 0.3; cursor: default; transform: none; }
.send-btn svg { width: 20px; height: 20px; fill: #000; }

/* Attach button */
.attach-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.attach-btn svg { width: 18px; height: 18px; color: var(--text-muted); transition: color 0.2s; }
.attach-btn:hover { border-color: var(--amber); }
.attach-btn:hover svg { color: var(--amber); }
.attach-btn:active { transform: scale(0.92); }

/* Input wrapper with attached files */
.input-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.input-wrapper .input-text {
  width: 100%;
}

.attached-files {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 0;
}

.attached-files:empty { display: none; }

.attached-files .file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 3px 10px 3px 8px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--amber);
  margin-bottom: 4px;
  max-width: 200px;
}

.attached-files .file-chip .file-icon { font-size: 13px; }

.attached-files .file-chip .file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attached-files .file-chip .file-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 0 2px;
  line-height: 1;
  transition: color 0.15s;
  min-width: 24px;
  min-height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.attached-files .file-chip .file-remove:hover { color: var(--accent-red); }

/* ========== Welcome screen ========== */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  gap: 14px;
  padding: 20px;
}

.welcome .logo-ring {
  width: 64px;
  height: 64px;
  border: 3px solid var(--amber);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 3s linear infinite;
}

.welcome h2 {
  font-family: var(--font-mono);
  font-size: 22px;
  color: var(--amber);
  letter-spacing: 6px;
  font-weight: 300;
}

.welcome p {
  color: var(--text-muted);
  font-size: 13px;
  max-width: 320px;
  line-height: 1.6;
}

/* ========== Settings Modal ========== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  backdrop-filter: blur(4px);
}

/* Mobile: full-screen bottom sheet */
.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-active);
  border-bottom: none;
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
  box-shadow: 0 -8px 40px rgba(0,0,0,0.5);
  animation: modalSlideUp 250ms ease-out;
  -webkit-overflow-scrolling: touch;
}

@keyframes modalSlideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

/* Bottom sheet drag handle (visual cue for mobile) */
.modal::before {
  content: '';
  display: block;
  width: 40px;
  height: 4px;
  background: var(--text-muted);
  border-radius: 2px;
  margin: 10px auto 0;
  opacity: 0.5;
}

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

.modal-header h2 {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--amber);
  letter-spacing: 2px;
  text-transform: uppercase;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  transition: color 0.15s;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover { color: var(--text-primary); }

.modal-tabs {
  display: flex;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.modal-tabs::-webkit-scrollbar { display: none; }

.modal-tabs .tab {
  background: none;
  border: none;
  padding: 12px 14px;
  color: var(--text-muted);
  font-size: 13px;
  font-family: var(--font-mono);
  letter-spacing: 1px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
  min-height: 44px;
}

.modal-tabs .tab.active {
  color: var(--amber);
  border-bottom-color: var(--amber);
}
.modal-tabs .tab:hover { color: var(--text-primary); }

.modal-body {
  padding: 16px;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

.setting-group {
  margin-bottom: 18px;
}

.setting-group label {
  display: block;
  font-size: 13px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}

.setting-group select,
.setting-group input[type="text"] {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--text-primary);
  /* 16px prevents iOS auto-zoom */
  font-size: 16px;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 0.15s;
  min-height: 48px;
}

.setting-group select:focus { border-color: var(--amber); }

.setting-group select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.setting-group input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  outline: none;
  margin: 4px 0;
}

.setting-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--amber);
  cursor: pointer;
  border: 3px solid var(--bg-secondary);
}

.slider-val {
  float: right;
  color: var(--amber);
  font-weight: 500;
}

.slider-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  display: block;
}

.setting-group input[type="checkbox"] {
  accent-color: var(--amber);
  margin-right: 8px;
  width: 20px;
  height: 20px;
  vertical-align: middle;
}

.test-voice-btn {
  width: 100%;
  padding: 14px;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid var(--amber);
  border-radius: 10px;
  color: var(--amber);
  font-size: 14px;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: all 0.15s;
  margin-top: 8px;
  min-height: 48px;
}
.test-voice-btn:hover { background: rgba(245, 158, 11, 0.2); }
.test-voice-btn:active { transform: scale(0.97); }

.modal-footer {
  padding: 12px 16px;
  padding-bottom: max(12px, var(--sab));
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

.save-settings-btn {
  padding: 12px 28px;
  background: var(--amber);
  border: none;
  border-radius: 8px;
  color: #000;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 48px;
}
.save-settings-btn:hover { background: #d97706; }
.save-settings-btn:active { transform: scale(0.97); }

/* ========== Header Service Dots ========== */
.header-services {
  display: inline-flex;
  gap: 4px;
  margin-left: 6px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  transition: background 0.15s;
  min-height: 32px;
  align-items: center;
}
.header-services:hover { background: rgba(245, 158, 11, 0.1); }
.svc-dot {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: #fff;
  background: var(--text-muted);
  transition: background 0.3s;
}
.svc-dot.ok { background: var(--accent-green); }
.svc-dot.warn { background: var(--amber); }
.svc-dot.err { background: var(--accent-red); }

/* ========== Connection Cards ========== */
.conn-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
  transition: border-color 0.2s;
}
.conn-card:hover { border-color: var(--border-active); }
.conn-header {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  flex-wrap: wrap;
}
.conn-header strong { flex: 1; min-width: 0; }
.conn-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.conn-dot.ok { background: var(--accent-green); }
.conn-dot.warn { background: var(--amber); }
.conn-dot.err { background: var(--accent-red); }
.conn-status-text {
  font-size: 12px;
  color: var(--text-muted);
}
.conn-detail {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 6px;
  padding-left: 20px;
  word-break: break-word;
}
.conn-btn {
  margin-top: 10px;
  padding: 10px 18px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--amber);
  font-size: 13px;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: all 0.15s;
  min-height: 44px;
}
.conn-btn:hover {
  background: rgba(245, 158, 11, 0.1);
  border-color: var(--amber);
}
.conn-btn:active { transform: scale(0.97); }
.conn-qr {
  text-align: center;
  padding: 12px 0;
}
.conn-qr img {
  max-width: 220px;
  border-radius: 8px;
}

/* ========== Wake Word — Header Indicator ========== */
.wake-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
  margin-left: 6px;
  display: inline-block;
  vertical-align: middle;
  box-shadow: 0 0 0 0 transparent;
}
.wake-indicator.armed {
  background: var(--amber);
  animation: wakePulse 2.2s ease-in-out infinite;
}
.wake-indicator.triggered {
  background: var(--amber);
  animation: wakePulse 0.9s ease-in-out infinite;
  box-shadow: 0 0 12px var(--amber);
}
.wake-indicator.muted {
  background: var(--text-muted);
  opacity: 0.5;
}
@keyframes wakePulse {
  0%,100% { box-shadow: 0 0 0 0 var(--amber-dim); }
  50%     { box-shadow: 0 0 0 6px transparent; }
}

/* ========== Wake Activation Bar ========== */
.wake-activation-bar {
  position: fixed;
  bottom: max(80px, calc(64px + var(--sab)));
  left: 10px;
  right: 10px;
  top: auto;
  transform: none;
  background: var(--bg-card);
  border: 1px solid var(--border-active);
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  z-index: 1500;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6), 0 0 24px var(--amber-glow);
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  animation: wakeBarSlideUp 300ms ease-out;
}
@keyframes wakeBarSlideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}
.wake-activation-btn {
  background: var(--amber);
  border: none;
  color: #000;
  padding: 12px 28px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: all 0.15s;
  min-height: 48px;
  width: 100%;
}
.wake-activation-btn:hover { background: #d97706; }
.wake-activation-btn:active { transform: scale(0.97); }

/* ========== Hands-Free FAB — Voice Conversation Button ========== */
.wake-fab {
  position: fixed;
  bottom: max(96px, calc(84px + var(--sab)));
  right: 20px;
  z-index: 1500;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: none;
  background: radial-gradient(circle at 30% 30%, #2a2a2a 0%, #111 70%, #000 100%);
  color: #fff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  box-shadow:
    0 8px 32px rgba(0,0,0,0.6),
    0 0 0 1px rgba(245,158,11,0.4),
    inset 0 1px 0 rgba(255,255,255,0.08);
  transition: transform 0.2s ease, box-shadow 0.3s ease;
  -webkit-tap-highlight-color: transparent;
  overflow: visible;
}
.wake-fab:hover {
  transform: translateY(-2px);
  box-shadow:
    0 12px 40px rgba(0,0,0,0.7),
    0 0 0 1px rgba(245,158,11,0.7),
    0 0 24px rgba(245,158,11,0.25),
    inset 0 1px 0 rgba(255,255,255,0.1);
}
.wake-fab:active { transform: scale(0.94); }

/* Core holds the orb + waves */
.wake-fab-core {
  position: relative;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}
/* Central pulsing orb (the "sphere") */
.wake-fab-orb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fbbf24 0%, #f59e0b 50%, #b45309 100%);
  box-shadow: 0 0 12px rgba(245,158,11,0.7), 0 0 4px rgba(251,191,36,0.9);
  animation: orbBreath 2.4s ease-in-out infinite;
}
@keyframes orbBreath {
  0%,100% { transform: scale(1); opacity: 1; }
  50%     { transform: scale(1.12); opacity: 0.85; }
}
/* Sound waves radiating from the orb */
.wake-fab-wave {
  position: absolute;
  top: 50%;
  left: 50%;
  border: 2px solid rgba(245,158,11,0.7);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: waveRadiate 2.4s ease-out infinite;
  opacity: 0;
}
.wake-fab-wave-1 { width: 20px; height: 20px; animation-delay: 0s; }
.wake-fab-wave-2 { width: 20px; height: 20px; animation-delay: 0.8s; }
.wake-fab-wave-3 { width: 20px; height: 20px; animation-delay: 1.6s; }
@keyframes waveRadiate {
  0%   { width: 14px; height: 14px; opacity: 0.8; border-width: 2px; }
  100% { width: 42px; height: 42px; opacity: 0; border-width: 0.5px; }
}

/* Text label below the icon */
.wake-fab-text {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: rgba(245,158,11,0.9);
  margin-top: 1px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

/* ACTIVE state (ConvAI connected, conversation in progress) */
.wake-fab.armed {
  background: radial-gradient(circle at 30% 30%, #3a2410 0%, #1a0f05 70%, #000 100%);
  box-shadow:
    0 0 40px rgba(245,158,11,0.6),
    0 8px 32px rgba(0,0,0,0.7),
    0 0 0 2px rgba(245,158,11,0.9),
    inset 0 1px 0 rgba(255,255,255,0.15);
  animation: fabArmedPulse 1.8s ease-in-out infinite;
}
.wake-fab.armed .wake-fab-orb {
  background: radial-gradient(circle at 30% 30%, #fef3c7 0%, #fbbf24 50%, #d97706 100%);
  box-shadow: 0 0 18px rgba(251,191,36,0.9), 0 0 6px #fef3c7;
  animation-duration: 1.2s;
}
.wake-fab.armed .wake-fab-wave {
  animation-duration: 1.4s;
  border-color: rgba(251,191,36,0.9);
}
.wake-fab.armed .wake-fab-text {
  color: #fef3c7;
}
@keyframes fabArmedPulse {
  0%,100% { box-shadow: 0 0 30px rgba(245,158,11,0.4), 0 8px 32px rgba(0,0,0,0.7), 0 0 0 2px rgba(245,158,11,0.9), inset 0 1px 0 rgba(255,255,255,0.15); }
  50%     { box-shadow: 0 0 60px rgba(245,158,11,0.8), 0 8px 32px rgba(0,0,0,0.7), 0 0 0 2px rgba(251,191,36,1), inset 0 1px 0 rgba(255,255,255,0.2); }
}

/* OFF state (idle) - same as default but with slightly reduced intensity */
.wake-fab.off { opacity: 0.95; }

/* Legacy label (hidden — we use .wake-fab-text instead) */
.wake-fab-label { display: none; }

/* Mobile tweak */
@media (max-width: 480px) {
  .wake-fab {
    width: 72px;
    height: 72px;
    bottom: max(88px, calc(76px + var(--sab)));
    right: 16px;
  }
}

/* ========== Sphere Overlay ========== */
.sphere-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: radial-gradient(circle at center, rgba(5,5,5,0.92), rgba(5,5,5,0.98));
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: opacity 180ms ease-out;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  will-change: opacity;
  /* Safe areas */
  padding-top: var(--sat);
  padding-bottom: var(--sab);
}
.sphere-overlay.active {
  display: flex;
  opacity: 1;
}
.sphere-canvas {
  width: 65vmin;
  height: 65vmin;
  max-width: 420px;
  max-height: 420px;
  filter: drop-shadow(0 0 50px var(--amber-dim));
  will-change: transform;
}
@keyframes sphereBreathe {
  0%,100% { transform: scale(0.97); }
  50%     { transform: scale(1.04); }
}
.sphere-overlay.state-armed .sphere-canvas {
  animation: sphereBreathe 4s ease-in-out infinite;
}
.sphere-caption {
  font-family: var(--font-mono);
  color: var(--amber);
  font-size: 14px;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-top: 20px;
  min-height: 22px;
}
.sphere-transcript {
  color: var(--text-secondary);
  font-size: 16px;
  font-family: var(--font-sans);
  margin-top: 12px;
  padding: 0 20px;
  max-width: min(500px, 90vw);
  text-align: center;
  line-height: 1.5;
  min-height: 48px;
  max-height: 80px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.sphere-close {
  position: absolute;
  top: max(16px, var(--sat));
  right: max(16px, var(--sar));
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid var(--border-active);
  color: var(--amber);
  font-size: 30px;
  font-weight: 300;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  line-height: 1;
  z-index: 1;
}
.sphere-close:active {
  transform: scale(0.9);
  background: rgba(245, 158, 11, 0.25);
}

/* Sphere state animations */
.sphere-overlay.state-thinking .sphere-canvas {
  animation: spherePulse 1.5s ease-in-out infinite;
  filter: drop-shadow(0 0 60px rgba(59,130,246,0.5));
}
.sphere-overlay.state-speaking .sphere-canvas {
  filter: drop-shadow(0 0 70px rgba(245,158,11,0.7));
}
@keyframes spherePulse {
  0%,100% { transform: scale(0.95); opacity: 0.85; }
  50%     { transform: scale(1.08); opacity: 1; }
}

/* Reminder notification flash */
@keyframes reminderFlash {
  0%,100% { background-color: transparent; }
  50% { background-color: rgba(245, 158, 11, 0.08); }
}
.msg.system.reminder { animation: reminderFlash 0.5s ease 3; }

/* Voice/Settings buttons — larger touch targets on mobile */
.voice-toggle,
.settings-btn {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ================================================================== */
/* ==================== DESKTOP OVERRIDES (769px+) ================== */
/* ================================================================== */
@media (min-width: 769px) {
  .app {
    grid-template-rows: 48px 1fr 64px;
    grid-template-columns: 280px 1fr;
    gap: 1px;
    background: rgba(245, 158, 11, 0.05);
  }

  .sidebar {
    display: flex;
  }

  .header {
    padding: 0 20px;
  }

  .header-logo .arc {
    width: 28px;
    height: 28px;
  }

  .header-logo h1 {
    font-size: 16px;
    letter-spacing: 4px;
  }

  .header-status {
    font-size: 11px;
    gap: 8px;
  }

  .status-text {
    display: inline;
  }

  .chat-panel {
    padding: 20px 24px;
  }

  .message {
    max-width: 85%;
    margin-bottom: 16px;
  }

  .message.user .bubble,
  .message.assistant .bubble {
    font-size: 14px;
  }

  .message.assistant .bubble pre {
    font-size: 12px;
  }

  .input-bar {
    padding: 0 16px;
    gap: 12px;
  }

  .voice-btn {
    width: 40px;
    height: 40px;
  }
  .voice-btn svg { width: 18px; height: 18px; }

  .input-text {
    border-radius: 10px;
    padding: 10px 16px;
    font-size: 14px;
  }

  .send-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
  }
  .send-btn svg { width: 18px; height: 18px; }

  .welcome .logo-ring {
    width: 80px;
    height: 80px;
  }

  .welcome h2 {
    font-size: 24px;
  }

  .welcome p {
    max-width: 400px;
  }

  /* Desktop modal: centered card, not bottom sheet */
  .modal-overlay {
    align-items: center;
  }

  .modal {
    width: 520px;
    max-height: 85vh;
    border-radius: 12px;
    border: 1px solid var(--border-active);
    animation: modalFadeIn 200ms ease-out;
  }

  .modal::before {
    display: none;
  }

  @keyframes modalFadeIn {
    from { opacity: 0; transform: scale(0.96); }
    to   { opacity: 1; transform: scale(1); }
  }

  .modal-header {
    padding: 16px 20px;
  }

  .modal-body {
    padding: 16px 20px;
  }

  .modal-footer {
    padding: 12px 20px;
  }

  .setting-group select,
  .setting-group input[type="text"] {
    padding: 8px 12px;
    font-size: 13px;
    min-height: 36px;
  }

  .setting-group input[type="range"]::-webkit-slider-thumb {
    width: 16px;
    height: 16px;
    border: 2px solid var(--bg-secondary);
  }

  .test-voice-btn {
    padding: 10px;
    font-size: 13px;
    min-height: 40px;
  }

  .save-settings-btn {
    padding: 8px 24px;
    font-size: 13px;
    min-height: 40px;
  }

  /* Desktop sphere */
  .sphere-canvas {
    width: min(55vmin, 480px);
    height: min(55vmin, 480px);
    filter: drop-shadow(0 0 60px var(--amber-dim));
  }

  .sphere-caption {
    font-size: 15px;
    margin-top: 28px;
  }

  .sphere-transcript {
    font-size: 17px;
    margin-top: 14px;
    padding: 0 24px;
    max-width: min(600px, 90vw);
  }

  .sphere-close {
    width: 44px;
    height: 44px;
    font-size: 28px;
  }
  .sphere-close:hover {
    background: rgba(245, 158, 11, 0.2);
    transform: scale(1.08);
  }

  /* Desktop wake activation bar: centered top */
  .wake-activation-bar {
    bottom: auto;
    top: 56px;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    flex-direction: row;
    gap: 14px;
    width: auto;
    padding: 12px 18px;
    animation: wakeBarSlideDown 300ms ease-out;
  }
  @keyframes wakeBarSlideDown {
    from { transform: translate(-50%, -20px); opacity: 0; }
    to   { transform: translate(-50%, 0);     opacity: 1; }
  }
  .wake-activation-btn {
    width: auto;
    padding: 8px 18px;
    font-size: 13px;
    min-height: 40px;
  }

  .header-services {
    margin-left: 12px;
    gap: 5px;
  }
}

/* ========== Small phone tweaks (under 380px) ========== */
@media (max-width: 380px) {
  .header-logo h1 {
    font-size: 12px;
    letter-spacing: 2px;
  }
  .header-logo .arc {
    width: 20px;
    height: 20px;
  }
  .svc-dot {
    width: 16px;
    height: 16px;
    font-size: 8px;
  }
  .voice-toggle,
  .settings-btn {
    font-size: 16px !important;
  }
  .input-bar {
    gap: 6px;
    padding: 6px 8px;
    padding-bottom: max(6px, var(--sab));
  }
  .voice-btn {
    width: 44px;
    height: 44px;
  }
  .send-btn {
    width: 44px;
    height: 44px;
  }
  .attach-btn {
    width: 38px;
    height: 38px;
  }
}

/* ========== Landscape phone ========== */
@media (max-height: 500px) and (orientation: landscape) {
  .sphere-canvas {
    width: 40vmin;
    height: 40vmin;
  }
  .sphere-caption {
    margin-top: 10px;
    font-size: 12px;
  }
  .sphere-transcript {
    font-size: 14px;
    margin-top: 8px;
  }
}
