/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #050508;
  --bg-surface: #0c0c14;
  --bg-card: #13132a;
  --bg-input: #161630;
  --accent: #00d4aa;
  --accent-dim: rgba(0, 212, 170, 0.15);
  --accent-glow: rgba(0, 212, 170, 0.25);
  --accent-bright: #00ffcc;
  --text: #e8ecf4;
  --text-dim: #8b95a8;
  --text-muted: #505a6e;
  --critical: #ff4757;
  --important: #ffa502;
  --monitor: #2ed573;
  --user-bubble: #1a1a50;
  --ai-bubble: #0e0e24;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }

/* === Auth Screen === */
#auth-screen {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: radial-gradient(ellipse at 50% 30%, rgba(0,212,170,0.06) 0%, transparent 70%);
}

.auth-container {
  text-align: center;
  width: 100%;
  max-width: 320px;
  padding: 20px 0;
}

.auth-logo {
  width: 96px;
  height: 96px;
  border-radius: 24px;
  margin: 0 auto 20px;
  display: block;
  box-shadow: 0 8px 40px var(--accent-glow), 0 0 80px rgba(0,212,170,0.1);
}

.auth-container h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 6px;
  background: linear-gradient(135deg, var(--accent-bright), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.auth-container p {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 32px;
}

.pin-input-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pin-input-group input {
  width: 100%;
  padding: 16px 18px;
  background: var(--bg-input);
  border: 1px solid rgba(0,212,170,0.15);
  border-radius: 14px;
  color: var(--text);
  font-size: 20px;
  text-align: center;
  letter-spacing: 6px;
  outline: none;
  transition: border-color 0.2s;
}

.pin-input-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 20px rgba(0,212,170,0.1);
}

.pin-input-group button {
  width: 100%;
  padding: 16px;
  background: var(--accent);
  color: #050508;
  border: none;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 1px;
}

.pin-input-group button:active { opacity: 0.8; transform: scale(0.97); }

.error-text {
  color: var(--critical);
  font-size: 13px;
  margin-top: 12px;
  min-height: 20px;
}

/* === Main Screen === */
#main-screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* === Header === */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  padding-top: calc(10px + var(--safe-top));
  background: var(--bg-surface);
  border-bottom: 1px solid rgba(0,212,170,0.08);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.node-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-left: -4px;
  transition: background 0.3s;
}
.node-dot.online {
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}
.node-dot.offline {
  background: var(--text-muted);
}

.header-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0,212,170,0.2);
}

.app-title {
  font-size: 17px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-bright), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

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

.model-toggle {
  display: flex;
  background: var(--bg-card);
  border-radius: 8px;
  padding: 2px;
  border: 1px solid rgba(0,212,170,0.08);
}

.toggle-btn {
  padding: 5px 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.toggle-btn.active {
  background: var(--accent);
  color: #050508;
  font-weight: 700;
}

.icon-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.2s;
}

.icon-btn:active { background: var(--bg-card); }
.icon-btn.tts-off { color: var(--text-muted); opacity: 0.4; }

/* === Watchlist Bar === */
#watchlist-bar {
  flex-shrink: 0;
  padding: 8px 16px;
  background: var(--bg-surface);
}

.watchlist-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.watchlist-scroll::-webkit-scrollbar { display: none; }

.wl-card {
  flex-shrink: 0;
  padding: 7px 12px;
  background: var(--bg-card);
  border-radius: 10px;
  border-left: 3px solid;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  animation: fadeIn 0.3s ease;
}

.wl-card.critical { border-left-color: var(--critical); color: #ff6b7a; }
.wl-card.important { border-left-color: var(--important); color: #ffbe4d; }
.wl-card.monitor { border-left-color: var(--monitor); color: #5bf5a0; }

/* === Chat Area === */
#chat-area {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

#messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 100%;
  justify-content: flex-end;
}

.message {
  max-width: 85%;
  animation: messageIn 0.3s ease;
}

.message.user { align-self: flex-end; }
.message.assistant { align-self: flex-start; }

.msg-bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
}

.message.user .msg-bubble {
  background: linear-gradient(135deg, #1a1a50, #141440);
  color: white;
  border: 1px solid rgba(0,212,170,0.12);
  border-bottom-right-radius: 4px;
}

.message.assistant .msg-bubble {
  background: var(--ai-bubble);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.04);
  border-bottom-left-radius: 4px;
}

.msg-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

.message.user .msg-time { text-align: right; }

.msg-bubble p { margin-bottom: 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble strong { color: var(--accent-bright); }
.msg-bubble code {
  background: rgba(0,212,170,0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--accent-bright);
}

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

.typing-dot {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out;
}

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

/* Brief message style */
.message.brief .msg-bubble {
  background: linear-gradient(135deg, #0a1a1a, #0e0e24);
  border: 1px solid rgba(0,212,170,0.15);
}

/* Journal message style */
.message.journal .msg-bubble {
  background: linear-gradient(135deg, #1a1008, #0e0e24);
  border: 1px solid rgba(255,165,2,0.15);
}

/* === Quick Commands Bar === */
#quick-commands {
  flex-shrink: 0;
  padding: 6px 16px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

#quick-commands::-webkit-scrollbar { display: none; }

.cmd-chip {
  flex-shrink: 0;
  padding: 6px 14px;
  background: var(--bg-card);
  border: 1px solid rgba(0,212,170,0.1);
  border-radius: 20px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.cmd-chip:active {
  background: var(--accent-dim);
  transform: scale(0.96);
}

.cmd-chip.recording {
  background: rgba(255,71,87,0.15);
  border-color: var(--critical);
  color: var(--critical);
  animation: recordPulse 2s infinite;
}

/* === Input Area === */
#input-area {
  flex-shrink: 0;
  padding: 8px 16px;
  padding-bottom: calc(8px + var(--safe-bottom));
  background: var(--bg-surface);
  border-top: 1px solid rgba(0,212,170,0.08);
}

.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border-radius: 24px;
  padding: 4px 4px 4px 18px;
  border: 1px solid rgba(0,212,170,0.08);
  transition: border-color 0.2s;
}

.input-row:focus-within {
  border-color: rgba(0,212,170,0.3);
  box-shadow: 0 0 20px rgba(0,212,170,0.05);
}

#text-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-size: 15px;
  outline: none;
  padding: 8px 0;
}

#text-input::placeholder { color: var(--text-muted); }

.input-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

#send-btn {
  background: var(--accent);
  color: #050508;
}

#send-btn:active { transform: scale(0.9); }

.mic {
  background: var(--accent-dim);
  color: var(--accent);
}

.mic:active { transform: scale(0.9); }

.mic.listening {
  background: var(--critical);
  color: white;
  animation: micPulse 1.5s infinite;
}

/* === Welcome State === */
.welcome-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}

.welcome-state .welcome-icon {
  width: 72px;
  height: 72px;
  background: linear-gradient(135deg, var(--accent), #00a88a);
  border-radius: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 2px;
  color: #050508;
  margin: 0 auto 16px;
  box-shadow: 0 8px 40px var(--accent-glow), 0 0 80px rgba(0,212,170,0.08);
}

.welcome-state h2 {
  font-size: 22px;
  color: var(--text);
  margin-bottom: 8px;
}

.welcome-state p {
  font-size: 14px;
  line-height: 1.6;
}

.welcome-state strong {
  color: var(--accent);
}

/* === Voice Mode Overlay === */
#voice-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  flex-direction: column;
  z-index: 200;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  animation: fadeIn 0.25s ease;
}

.voice-header {
  flex-shrink: 0;
  padding: 22px 24px 0;
}

.voice-title {
  font-size: 17px;
  font-weight: 600;
  color: rgba(255,255,255,0.35);
  letter-spacing: 0.3px;
}

.voice-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 44px;
}

/* The Orb */
.voice-orb {
  width: 230px;
  height: 230px;
  position: relative;
  border-radius: 50%;
}

/* Outer glow blob */
.voice-orb::before {
  content: '';
  position: absolute;
  inset: -30px;
  border-radius: 50%;
  background: radial-gradient(
    circle at 40% 35%,
    rgba(0, 255, 200, 0.85),
    rgba(0, 212, 170, 0.55) 38%,
    rgba(0, 110, 90, 0.2) 62%,
    transparent 80%
  );
  filter: blur(28px);
  animation: orbBreath 3.5s ease-in-out infinite;
  will-change: transform, opacity;
}

/* Inner bright highlight */
.voice-orb::after {
  content: '';
  position: absolute;
  inset: 35px;
  border-radius: 50%;
  background: radial-gradient(
    circle at 36% 30%,
    rgba(200, 255, 245, 1),
    rgba(0, 235, 190, 0.55) 45%,
    transparent 80%
  );
  filter: blur(10px);
  animation: orbBreath 3.5s ease-in-out infinite 0.3s;
  will-change: transform, opacity;
}

/* Listening — morphing blob */
.voice-orb.orb-listening::before {
  filter: blur(22px);
  animation: orbListen 0.65s ease-in-out infinite;
  background: radial-gradient(
    circle at 40% 35%,
    rgba(0, 255, 210, 0.95),
    rgba(0, 220, 175, 0.65) 35%,
    rgba(0, 130, 105, 0.25) 62%,
    transparent 80%
  );
}
.voice-orb.orb-listening::after {
  animation: orbListen 0.65s ease-in-out infinite 0.1s;
}

/* Processing — slow spin */
.voice-orb.orb-processing::before {
  animation: orbProcess 2.8s linear infinite;
  background: radial-gradient(
    circle at 40% 35%,
    rgba(80, 220, 200, 0.75),
    rgba(0, 175, 155, 0.45) 40%,
    rgba(0, 75, 65, 0.15) 65%,
    transparent 80%
  );
  filter: blur(30px);
  opacity: 0.8;
}
.voice-orb.orb-processing::after {
  animation: orbProcess 2.8s linear infinite reverse;
  opacity: 0.55;
}

/* Speaking — fast pulse */
.voice-orb.orb-speaking::before {
  filter: blur(22px);
  animation: orbSpeak 0.55s ease-in-out infinite;
  background: radial-gradient(
    circle at 38% 32%,
    rgba(0, 255, 225, 0.95),
    rgba(0, 225, 178, 0.7) 35%,
    rgba(0, 145, 115, 0.28) 60%,
    transparent 80%
  );
}
.voice-orb.orb-speaking::after {
  animation: orbSpeak 0.55s ease-in-out infinite 0.15s;
}

.voice-status {
  font-size: 15px;
  color: rgba(255,255,255,0.3);
  font-weight: 400;
  letter-spacing: 0.3px;
  text-align: center;
}

/* Bottom bar */
.voice-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 36px;
  padding: 20px 32px;
  padding-bottom: calc(28px + var(--safe-bottom));
}

.voice-mic-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: rgba(255,255,255,0.09);
  border: 1.5px solid rgba(255,255,255,0.14);
  color: rgba(255,255,255,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.25s;
}

.voice-mic-btn:active { transform: scale(0.93); }

.voice-mic-btn.listening {
  background: rgba(255, 71, 87, 0.2);
  border-color: var(--critical);
  color: var(--critical);
  animation: micPulse 1.5s infinite;
}

.voice-close-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  border: 1.5px solid rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.voice-close-btn:active { background: rgba(255,255,255,0.13); }

/* Orb keyframes */
@keyframes orbBreath {
  0%, 100% { transform: scale(0.94); opacity: 0.72; }
  50% { transform: scale(1.06); opacity: 1; }
}

@keyframes orbListen {
  0%   { transform: scale(1.08); border-radius: 50%; opacity: 1; }
  20%  { transform: scale(1.18); border-radius: 47% 53% 55% 45% / 48% 52% 55% 45%; }
  40%  { transform: scale(1.12); border-radius: 53% 47% 46% 54% / 52% 48% 46% 54%; }
  60%  { transform: scale(1.22); border-radius: 46% 54% 53% 47% / 55% 45% 50% 50%; }
  80%  { transform: scale(1.14); border-radius: 55% 45% 47% 53% / 47% 53% 52% 48%; }
  100% { transform: scale(1.08); border-radius: 50%; opacity: 1; }
}

@keyframes orbProcess {
  0%   { transform: rotate(0deg) scale(0.88); opacity: 0.6; }
  50%  { transform: rotate(180deg) scale(1.0); opacity: 0.85; }
  100% { transform: rotate(360deg) scale(0.88); opacity: 0.6; }
}

@keyframes orbSpeak {
  0%, 100% { transform: scale(1.02); opacity: 0.88; }
  40%  { transform: scale(1.22); opacity: 1; }
  70%  { transform: scale(0.95); opacity: 0.8; }
}

/* === Voice Journal Overlay === */
#journal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5,5,8,0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}

.journal-recorder {
  text-align: center;
  padding: 40px;
}

.journal-timer {
  font-size: 48px;
  font-weight: 300;
  color: var(--accent-bright);
  font-variant-numeric: tabular-nums;
  margin-bottom: 8px;
}

.journal-status {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 32px;
}

.journal-record-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--critical);
  border: 4px solid rgba(255,255,255,0.2);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin: 0 auto 24px;
  transition: all 0.2s;
  animation: recordPulse 2s infinite;
}

.journal-record-btn.stopped {
  background: var(--accent);
  animation: none;
}

.journal-cancel-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 8px 16px;
}

.journal-transcript {
  margin-top: 20px;
  max-width: 320px;
  padding: 16px;
  background: var(--bg-card);
  border-radius: 12px;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.5;
  max-height: 120px;
  overflow-y: auto;
}

/* === Files Overlay === */
#files-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}

.files-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

.files-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  padding-top: calc(12px + var(--safe-top));
  background: var(--bg-surface);
  border-bottom: 1px solid rgba(0,212,170,0.08);
  flex-shrink: 0;
  gap: 12px;
}

.files-back-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  border-radius: 8px;
  flex-shrink: 0;
}

.files-back-btn:active {
  background: var(--bg-card);
}

.files-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
}

.files-header-spacer {
  width: 36px;
  flex-shrink: 0;
}

/* File list */
.files-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  -webkit-overflow-scrolling: touch;
}

.file-folder {
  padding: 12px 20px 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px 12px 32px;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}

.file-item:active {
  background: var(--bg-card);
}

.file-size {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-left: 12px;
}

/* File editor */
.file-editor-header {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  padding-top: calc(10px + var(--safe-top));
  background: var(--bg-surface);
  border-bottom: 1px solid rgba(0,212,170,0.08);
  flex-shrink: 0;
  gap: 10px;
}

.file-editor-title {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-save-btn {
  padding: 6px 16px;
  background: var(--accent);
  color: #050508;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

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

.file-save-btn.saved {
  background: var(--monitor);
}

.file-editor-textarea {
  flex: 1;
  width: 100%;
  padding: 16px 20px;
  padding-bottom: calc(16px + var(--safe-bottom));
  background: var(--bg);
  color: var(--text);
  border: none;
  outline: none;
  resize: none;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 13px;
  line-height: 1.6;
  -webkit-overflow-scrolling: touch;
  tab-size: 2;
}

.file-editor-textarea::placeholder {
  color: var(--text-muted);
}

#files-list-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

#files-editor-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.files-loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  font-size: 14px;
}

/* === Animations === */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 71, 87, 0.4); }
  50% { box-shadow: 0 0 0 12px rgba(255, 71, 87, 0); }
}

@keyframes recordPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 71, 87, 0.3); }
  50% { box-shadow: 0 0 0 16px rgba(255, 71, 87, 0); }
}

/* === Responsive === */
@media (min-width: 768px) {
  #main-screen {
    max-width: 480px;
    margin: 0 auto;
    border-left: 1px solid rgba(0,212,170,0.06);
    border-right: 1px solid rgba(0,212,170,0.06);
  }
}

/* === Scrollbar (desktop) === */
#chat-area::-webkit-scrollbar { width: 4px; }
#chat-area::-webkit-scrollbar-track { background: transparent; }
#chat-area::-webkit-scrollbar-thumb { background: rgba(0,212,170,0.15); border-radius: 2px; }

/* ============================================================
   FRESHNESS + OFFLINE
   ------------------------------------------------------------
   Cached data with no visible age is worse than no data: it looks
   current. Everything below exists so the app can never quietly
   present stale content as live.

   States come from ageClass() in app.js:
     fresh  <90s      ok  <30m      warn  <6h      stale  >6h
     none   never synced          offline  no connection
   Colour escalates only at `warn`; `fresh` and `ok` stay quiet so
   the normal case is calm and only the exceptional case draws the eye.
   ============================================================ */

.freshness {
  font: inherit;
  font-size: 10px;
  letter-spacing: .04em;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1.6;
  white-space: nowrap;
  transition: color .25s, border-color .25s, background .25s;
}
.freshness:hover { border-color: var(--text-muted); }
.freshness:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.freshness.fresh   { color: var(--accent); border-color: var(--accent-dim);
                     background: var(--accent-dim); }
.freshness.ok      { color: var(--text-dim); border-color: rgba(139,149,168,.25); }
.freshness.warn    { color: var(--important); border-color: rgba(255,165,2,.35);
                     background: rgba(255,165,2,.08); }
.freshness.stale   { color: var(--critical); border-color: rgba(255,71,87,.4);
                     background: rgba(255,71,87,.1); }
.freshness.offline { color: var(--critical); border-color: rgba(255,71,87,.4);
                     background: rgba(255,71,87,.1); }
.freshness.none    { color: var(--text-muted); border-color: rgba(80,90,110,.35); }

/* Per-surface ages (watchlist rows, file lists). Same scale, quieter. */
.wl-meta-age, .files-age {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: .03em;
}
.wl-meta-age.fresh,   .files-age.fresh   { color: var(--accent); }
.wl-meta-age.ok,      .files-age.ok      { color: var(--text-dim); }
.wl-meta-age.warn,    .files-age.warn    { color: var(--important); }
.wl-meta-age.stale,   .files-age.stale   { color: var(--critical); }
.wl-meta-age.offline, .files-age.offline { color: var(--critical); }

/* Shell update chip — a new build is cached and waiting. Never auto-reloads:
   swapping the page under someone mid-sentence is worse than being one build behind. */
.update-chip {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 60;
  max-width: calc(100vw - 32px);
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--accent-dim);
  color: var(--accent);
  font-size: 12px;
  line-height: 1.4;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(0,0,0,.5), 0 0 0 1px rgba(0,212,170,.08);
}
.update-chip:hover { background: var(--bg-input); }

/* Data / freshness sheet — per-surface ages and the privacy wipe. */
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 70;
  max-height: 78vh;
  overflow-y: auto;
  padding: 18px 18px calc(22px + env(safe-area-inset-bottom, 0px));
  background: var(--bg-surface);
  border-top: 1px solid var(--accent-dim);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -10px 40px rgba(0,0,0,.6);
  animation: sheet-up .22s ease-out;
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
.sheet h3 { margin: 0 0 12px; font-size: 13px; letter-spacing: .06em; color: var(--text); }
.sheet .sheet-row {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 12px; padding: 7px 0; border-bottom: 1px solid rgba(139,149,168,.12);
  font-size: 12px; color: var(--text-dim);
}
.sheet .sheet-row:last-of-type { border-bottom: 0; }
.sheet .sheet-note { margin-top: 12px; font-size: 11px; line-height: 1.55; color: var(--text-muted); }
.sheet .sheet-actions { display: flex; gap: 10px; margin-top: 14px; }
.sheet button {
  flex: 1; padding: 10px; border-radius: 10px; font-size: 12px; cursor: pointer;
  background: var(--bg-input); border: 1px solid rgba(139,149,168,.25); color: var(--text);
}
.sheet button.danger { color: var(--critical); border-color: rgba(255,71,87,.35); }
.sheet button:hover { background: var(--bg-card); }
.sheet .sheet-row-label { color: var(--text-dim); }
.sheet .sheet-row-value { color: var(--text); font-variant-numeric: tabular-nums; text-align: right; }
/* Watchlist empty state — distinct from "offline", which the freshness pill conveys. */
.wl-empty { padding: 14px 2px; font-size: 12px; color: var(--text-muted); text-align: center; }
