:root {
  --bg: #17212b;
  --bg-secondary: #1e2c3a;
  --bg-card: #242f3d;
  --text: #ffffff;
  --text-muted: #7f8e9c;
  --accent: #2ea6ff;
  --accent-hover: #1d8fd8;
  --danger: #e53935;
  --warning: #f0a040;
  --border: #2b3a4a;
  --shadow: rgba(0,0,0,0.4);
  --radius: 2px;
  --radius-sm: 1px;
  --topbar-height: 52px;
  --status-green: #22c55e;
  --status-yellow: #f0c040;
  --status-red: #e53935;
}

* { 
  margin: 0; 
  padding: 0; 
  box-sizing: border-box; 
}

/* Focus: visible only — no outline on mouse clicks */
:focus {
  outline: none;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  touch-action: manipulation;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

.hidden { 
  display: none !important; 
}

/*=== Screens (login/loading/verify) ===*/
.screen {
  display: flex;
  flex: 1;
  min-height: 0;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-box {
  background: var(--bg-card);
  padding: 40px 32px;
  border-radius: var(--radius);
  box-shadow: 0 20px 60px var(--shadow);
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.login-logo { 
  font-size: 48px; 
  margin-bottom: 12px; 
}
.login-box h1 { 
  font-size: 24px; 
  margin-bottom: 4px; 
}
.login-subtitle { 
  color: var(--text-muted); 
  font-size: 14px; 
  margin-bottom: 24px; 
}
.login-box input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  margin-bottom: 16px;
  outline: none;
  transition: border-color 0.2s;
}
.login-box input:focus { 
  border-color: var(--accent); 
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-primary:hover { 
  background: var(--accent-hover); 
}
.btn-primary:disabled { 
  opacity: 0.5; 
  cursor: not-allowed; 
}

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

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 14px;
  margin-top: 12px;
  text-decoration: underline;
}

#verify-screen .login-box input {
  letter-spacing: 8px;
  text-align: center;
  font-size: 24px;
  font-weight: bold;
}

.loading-box { 
  text-align: center; 
  color: var(--text-muted); 
}
.loading-spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}
@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.4; }
  100% { opacity: 1; }
}

@keyframes wave {
  0% { transform: scaleY(0.5); }
  25% { transform: scaleY(1); }
  50% { transform: scaleY(0.5); }
  75% { transform: scaleY(1.2); }
  100% { transform: scaleY(0.5); }
}

/*=== TOP BAR ===*/
.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  padding-top: calc(6px + env(safe-area-inset-top, 0));
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  height: var(--topbar-height);
  z-index: 50;
  overflow: visible;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.3s;
}
.status-connected { 
  background: var(--status-green); 
  box-shadow: 0 0 6px var(--status-green); 
}
.status-connecting { 
  background: var(--status-yellow); 
  box-shadow: 0 0 6px var(--status-yellow); 
  animation: pulse-dot 1s ease-in-out infinite; 
}
.status-disconnected { 
  background: var(--status-red); 
  box-shadow: 0 0 6px var(--status-red); 
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.top-display {
  flex: 1;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  color: var(--text);
  padding: 2px 4px;
  border-radius: 4px;
  transition: background 0.15s;
}
.top-display:hover { 
  background: rgba(255,255,255,0.05); 
}
.top-display:active { 
  background: rgba(255,255,255,0.1); 
}

.top-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 6px 10px;
  min-width: 36px;
  min-height: 36px;
  border-radius: 4px;
  flex-shrink: 0;
  transition: all 0.15s;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.voice-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  padding: 10px 14px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 4px;
  flex-shrink: 0;
  transition: all 0.15s;
  line-height: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.voice-btn.recording {
  color: var(--danger);
  animation: pulse 1s infinite;
}

.voice-btn:hover {
  color: var(--accent);
  background: rgba(0,212,170,0.1);
}

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

.voice-timer {
  font-size: 12px;
  margin-left: 6px;
  color: var(--text-muted);
  min-width: 40px;
  text-align: center;
}

.voice-wave {
  display: flex;
  align-items: flex-end;
  height: 24px;
  margin: 0 10px;
  gap: 2px;
}

.voice-wave-bar {
  width: 2px;
  background: var(--accent);
  border-radius: 1px;
  animation: wave 1.5s ease-in-out infinite;
  opacity: 0.7;
}

.voice-wave-bar:nth-child(1) { animation-delay: 0s; height: 10px; }
.voice-wave-bar:nth-child(2) { animation-delay: 0.2s; height: 16px; }
.voice-wave-bar:nth-child(3) { animation-delay: 0.4s; height: 8px; }
.voice-wave-bar:nth-child(4) { animation-delay: 0.6s; height: 12px; }
.voice-wave-bar:nth-child(5) { animation-delay: 0.8s; height: 20px; }

/*=== MENU (dropdown from top-bar) ===*/
.menu-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 32px var(--shadow);
  z-index: 100;
  min-width: 240px;
  padding: 4px;
  -webkit-overflow-scrolling: touch;
}

.menu-item {
  display: block;
  width: 100%;
  padding: 14px 18px;
  min-height: 48px;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
  text-align: left;
  border-radius: 4px;
  transition: background 0.15s;
}
.menu-item:hover { 
  background: rgba(0,212,170,0.1); 
  color: var(--accent); 
}
.menu-divider { 
  height: 1px; 
  background: var(--border); 
  margin: 4px 8px; 
}

/*=== Page content (router fills) ===*/
.page-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  padding-top: var(--topbar-height);
}

.page-content > .page {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-overflow-scrolling: touch;
}
.page-content > .page.hidden-page {
  display: none;
}

/*=== Toast notifications ===*/
.toast-container {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: 90vw;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  box-shadow: 0 8px 32px var(--shadow);
  pointer-events: auto;
  cursor: pointer;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  transition: opacity 0.3s ease, transform 0.3s ease;
  min-width: 200px;
  max-width: 400px;
}

.toast-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.toast-hiding {
  opacity: 0;
  transform: translateY(-10px) scale(0.95);
}

.toast-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.toast-text {
  font-size: 14px;
  color: var(--text);
  line-height: 1.3;
}

.toast-info { 
  border-color: var(--accent); 
  background: linear-gradient(135deg, var(--bg-card), rgba(0,212,170,0.08));
}

.toast-success { 
  border-color: #00d4aa; 
  background: linear-gradient(135deg, var(--bg-card), rgba(0,212,170,0.12));
}

.toast-error { 
  border-color: var(--danger); 
  background: linear-gradient(135deg, var(--bg-card), rgba(255,107,107,0.1));
}

.toast-warning { 
  border-color: #f0c040; 
  background: linear-gradient(135deg, var(--bg-card), rgba(240,192,64,0.1));
}

/*=== Scrollbar ===*/
::-webkit-scrollbar { 
  width: 6px; 
}
::-webkit-scrollbar-track { 
  background: transparent; 
}
::-webkit-scrollbar-thumb { 
  background: var(--border); 
  border-radius: 2px; 
}
::-webkit-scrollbar-thumb:hover { 
  background: var(--text-muted); 
}

/*=== Mobile ===*/
@media (max-width: 600px) {
  .login-box { 
    padding: 32px 20px; 
  }
}

/*=== Tablet (768px+) ===*/
@media (min-width: 768px) {
  .login-box {
    max-width: 440px;
    padding: 48px 40px;
  }
  .login-box h1 {
    font-size: 28px;
  }
  .top-bar {
    padding: 8px 20px;
    gap: 12px;
  }
  .top-btn,
  .voice-btn {
    padding: 12px 16px;
  }
  .menu-dropdown {
    min-width: 280px;
  }
  .page-content {
    max-width: 768px;
    margin: 0 auto;
    width: 100%;
  }
  .toast-container {
    bottom: 40px;
  }
  .toast {
    max-width: 500px;
  }
}
