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

:root {
  --bg: #0a0a0f;
  --surface: #12121a;
  --surface2: #1a1a28;
  --border: #2a2a40;
  --text: #e0e0f0;
  --text-dim: #7070a0;
  --accent: #4466ff;
  --accent2: #7744ff;
  --idle-color: #1a2a6c;
  --listen-color: #2244cc;
  --speak-color1: #4466ff;
  --speak-color2: #8844ff;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Auth overlay ────────────────────────────────── */
#auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.auth-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-box h2 {
  text-align: center;
  font-size: 1.5rem;
  letter-spacing: 0.15em;
  color: var(--accent);
}

.auth-box input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 12px 16px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.auth-box input:focus {
  border-color: var(--accent);
}

.auth-box button {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  padding: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.auth-box button:hover { background: #3355ee; }

.auth-switch {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.auth-switch span {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

#auth-error {
  font-size: 0.9rem;
  font-weight: 500;
  padding: 8px;
  background: rgba(255,50,50,0.1);
  border-radius: 6px;
  color: #ff6666;
  font-size: 0.85rem;
  text-align: center;
  min-height: 1.2em;
}

/* ── Top bar ─────────────────────────────────────── */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  flex-shrink: 0;
}

#logo {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.3em;
  color: var(--accent);
}

#topbar-right {
  display: flex;
  gap: 10px;
  align-items: center;
}

#lang-toggle, #logout-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 6px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.2s;
}

#lang-toggle:hover, #logout-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Main area ───────────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── Center panel ────────────────────────────────── */
#center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  position: relative;
  padding: 20px;
}

/* ── Orb ─────────────────────────────────────────── */
#orb-wrapper {
  position: relative;
  width: 280px;
  height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#orb {
  width: 240px;
  height: 240px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #1a2a6c 0%, #0d1035 70%);
  box-shadow: 0 0 40px rgba(30, 50, 180, 0.3), 0 0 80px rgba(30, 50, 180, 0.15);
  animation: idle-pulse 3s ease-in-out infinite;
  transition: all 0.4s ease;
  cursor: pointer;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

#orb-icon {
  width: 72px;
  height: 72px;
  opacity: 0.7;
  animation: fp-breathe 3s ease-in-out infinite;
  pointer-events: none;
}

#orb-tap-hint {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 2px;
  color: rgba(255,255,255,0.35);
  text-transform: uppercase;
  pointer-events: none;
}

#orb.listening #orb-icon,
#orb.speaking #orb-icon { opacity: 0; }
#orb.listening #orb-tap-hint,
#orb.speaking #orb-tap-hint { opacity: 0; }

@keyframes fp-breathe {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  50% { opacity: 0.8; transform: scale(1.05); }
}

#orb.listening {
  background: radial-gradient(circle at 40% 35%, #2244dd 0%, #1133bb 60%);
  box-shadow: 0 0 60px rgba(50, 100, 255, 0.5), 0 0 120px rgba(50, 100, 255, 0.25);
  animation: listen-pulse 1s ease-in-out infinite;
}

#orb.speaking {
  background: radial-gradient(circle at 40% 35%, var(--speak-color1) 0%, var(--speak-color2) 60%);
  box-shadow: 0 0 80px rgba(100, 80, 255, 0.6), 0 0 160px rgba(100, 80, 255, 0.3);
  animation: speak-wave 0.6s ease-in-out infinite alternate;
}

@keyframes idle-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 40px rgba(30, 50, 180, 0.3), 0 0 80px rgba(30, 50, 180, 0.15); }
  50% { transform: scale(1.03); box-shadow: 0 0 55px rgba(30, 50, 180, 0.4), 0 0 100px rgba(30, 50, 180, 0.2); }
}

@keyframes listen-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

@keyframes speak-wave {
  from { transform: scale(1); }
  to { transform: scale(1.07); }
}

#orb-status {
  position: absolute;
  bottom: -32px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.78rem;
  letter-spacing: 0.15em;
  color: var(--text-dim);
  white-space: nowrap;
}

/* ── Thinking phrase ─────────────────────────────── */
#thinking-phrase {
  font-size: 0.9rem;
  color: var(--text-dim);
  font-style: italic;
  min-height: 1.4em;
  text-align: center;
  max-width: 400px;
}

/* ── Input bar ───────────────────────────────────── */
#input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 600px;
  padding: 0 0 20px;
  flex-shrink: 0;
}

#msg-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  padding: 12px 16px;
  font-size: 0.95rem;
  outline: none;
  resize: none;
  transition: border-color 0.2s;
  line-height: 1.4;
  max-height: 120px;
  overflow-y: auto;
}

#msg-input:focus { border-color: var(--accent); }

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

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  flex-shrink: 0;
  transition: border-color 0.2s, background 0.2s;
}

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

.icon-btn.active {
  background: var(--accent);
  border-color: var(--accent);
}

#file-input { display: none; }

/* ── Sidebar ─────────────────────────────────────── */
#sidebar {
  width: 300px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width 0.3s;
  overflow: hidden;
  flex-shrink: 0;
}

#sidebar.collapsed {
  width: 0;
  border-left: none;
}

#sidebar-header {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#sidebar-header span {
  font-size: 0.8rem;
  letter-spacing: 0.15em;
  color: var(--text-dim);
  text-transform: uppercase;
}

#sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px;
}

#sidebar-toggle:hover { color: var(--text); }

#chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#chat-history::-webkit-scrollbar { width: 4px; }
#chat-history::-webkit-scrollbar-track { background: transparent; }
#chat-history::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.msg {
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.85rem;
  line-height: 1.5;
  max-width: 100%;
  word-break: break-word;
}

.msg.user {
  background: var(--surface2);
  border: 1px solid var(--border);
  align-self: flex-end;
  color: var(--text);
}

.msg.assistant {
  background: rgba(68, 102, 255, 0.08);
  border: 1px solid rgba(68, 102, 255, 0.2);
  align-self: flex-start;
  color: var(--text);
}

.msg .route-badge {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ── Sidebar open toggle (floating) ──────────────── */
#sidebar-open-btn {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 8px 0 0 8px;
  color: var(--text-dim);
  width: 24px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.7rem;
  z-index: 10;
  transition: color 0.2s;
}

#sidebar-open-btn:hover { color: var(--text); }
#sidebar-open-btn.hidden { display: none; }

/* ── File preview ────────────────────────────────── */
#file-preview {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.8rem;
  color: var(--text-dim);
  max-width: 600px;
}

#file-preview.visible { display: flex; }

#file-preview-name { flex: 1; truncate: ellipsis; overflow: hidden; white-space: nowrap; }

#file-preview-remove {
  cursor: pointer;
  color: var(--text-dim);
  font-size: 1rem;
  line-height: 1;
}

#file-preview-remove:hover { color: #ff6666; }

/* ── Center input layout ─────────────────────────── */
#center-bottom {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0 24px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 600px) {
  #sidebar { display: none; }
  #sidebar-open-btn { display: none; }
  #orb { width: 180px; height: 180px; }
  #orb-wrapper { width: 220px; height: 220px; }
}

/* ── Messages Preview Zone ─────────────────────────────────────────── */
#messages-preview {
  flex: 1;
  width: 100%;
  max-width: 480px;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0 16px 16px;
  min-height: 120px;
  max-height: 280px;
}

/* Dark gradient at TOP fading to transparent */
#messages-preview::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 70%;
  background: linear-gradient(to bottom, var(--bg) 0%, transparent 100%);
  z-index: 2;
  pointer-events: none;
}

#messages-preview-inner {
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  z-index: 1;
}

/* Preview message bubbles */
.preview-msg {
  font-size: 12px;
  line-height: 1.4;
  padding: 7px 12px;
  border-radius: 12px;
  max-width: 82%;
  color: rgba(255,255,255,0.65);
  animation: msgAppear 0.3s ease;
}
.preview-msg.user {
  align-self: flex-end;
  background: rgba(80,100,220,0.2);
  border: 1px solid rgba(80,100,220,0.25);
  border-radius: 12px 12px 3px 12px;
}
.preview-msg.assistant {
  align-self: flex-start;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px 12px 12px 3px;
}

#preview-tap-hint {
  text-align: center;
  font-size: 9px;
  letter-spacing: 1.5px;
  color: rgba(255,255,255,0.15);
  margin-top: 6px;
  position: relative;
  z-index: 3;
}

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

/* ── Full Chat Overlay ─────────────────────────────────────────────── */
#chat-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 90;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease;
}
#chat-overlay.hidden { display: none; }

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

#chat-overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: 13px;
  letter-spacing: 2px;
  color: rgba(255,255,255,0.5);
}
#chat-overlay-close {
  background: none; border: none;
  color: rgba(255,255,255,0.5);
  font-size: 18px; cursor: pointer;
  padding: 4px 8px;
}
#chat-overlay-close:hover { color: #fff; }

#chat-history-overlay {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#chat-overlay-bottom {
  padding: 8px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
