/* === 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;
  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;
}

.auth-icon {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, var(--accent), #00a88a);
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 2px;
  color: #050508;
  margin: 0 auto 20px;
  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;
  gap: 10px;
}

.pin-input-group input {
  flex: 1;
  padding: 14px 18px;
  background: var(--bg-input);
  border: 1px solid rgba(0,212,170,0.15);
  border-radius: 12px;
  color: var(--text);
  font-size: 18px;
  text-align: center;
  letter-spacing: 4px;
  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 {
  padding: 14px 24px;
  background: var(--accent);
  color: #050508;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.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;
}

.logo {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent), #00a88a);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #050508;
  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 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; }
