:root {
  --bg: #0b0f1a;
  --bg-elev: #141a2b;
  --bg-card: #1a2135;
  --border: #2a3350;
  --text: #e6e9f2;
  --text-dim: #9aa3bd;
  --primary: #10b981;
  --primary-hover: #0ea371;
  --accent: #6366f1;
  --danger: #ef4444;
  --radius: 12px;
  font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

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

/* The `hidden` attribute must beat class-level `display:flex/grid` rules
   (e.g. .recorder, .preview) — otherwise hidden panels stay visible. */
[hidden] { display: none !important; }

body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

body.centered {
  display: flex;
  align-items: center;
  justify-content: center;
  background-image:
    radial-gradient(ellipse at 20% 30%, rgba(99, 102, 241, 0.12) 0%, transparent 55%),
    radial-gradient(ellipse at 80% 70%, rgba(16, 185, 129, 0.10) 0%, transparent 55%);
}

/* ─── Cards / login ─────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.login-card {
  width: min(90vw, 360px);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.brand { font-size: 1.5rem; text-align: center; }
.subtitle { color: var(--text-dim); text-align: center; margin-bottom: 0.5rem; font-size: 0.9rem; }

.field { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; color: var(--text-dim); }
.field input, select {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  font-size: 0.95rem;
  outline: none;
}
.field input:focus, select:focus { border-color: var(--accent); }

/* ─── Buttons ───────────────────────────────────────────────── */
.btn {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 8px;
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #04140d; font-weight: 600; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.call { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.error {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  font-size: 0.85rem;
}

/* ─── Topbar ─────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.3rem;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand-sm { font-weight: 700; font-size: 1.05rem; }
.me { display: flex; align-items: center; gap: 1rem; }
.me-name { font-weight: 600; }
.me-lang { display: flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--text-dim); }
.me-lang select { padding: 0.35rem 0.5rem; font-size: 0.85rem; }

.conn-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--text-dim);
  box-shadow: 0 0 0 2px rgba(255,255,255,0.05);
}
.conn-dot.online { background: var(--primary); }
.conn-dot.offline { background: var(--danger); }

/* ─── Layout ─────────────────────────────────────────────────── */
.layout { max-width: 1000px; margin: 0 auto; padding: 1.5rem 1.3rem; }
.view { }
#homeView { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 720px) { #homeView { grid-template-columns: 1fr; } }

.section-title { font-size: 1rem; margin-bottom: 0.8rem; color: var(--text-dim); font-weight: 600; }

/* ─── User list ──────────────────────────────────────────────── */
.user-list { list-style: none; display: flex; flex-direction: column; gap: 0.6rem; }
.user-list .empty { color: var(--text-dim); font-size: 0.9rem; padding: 0.8rem 0; }
.user-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
}
.user-row .u-info { display: flex; align-items: center; gap: 0.6rem; }
.user-row .u-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--primary));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 0.9rem;
}
.user-row .u-name { font-weight: 600; }
.user-row .u-lang { font-size: 0.75rem; color: var(--text-dim); }
.user-row .u-badge {
  font-size: 0.7rem; color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 999px; padding: 0.1rem 0.5rem;
}

.muted { color: var(--text-dim); font-size: 0.9rem; }

/* ─── Voice panel ────────────────────────────────────────────── */
.voice-panel { display: flex; flex-direction: column; gap: 1rem; }

.clone-status { display: flex; align-items: center; gap: 0.55rem; font-size: 0.95rem; font-weight: 500; }
.clone-status .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-dim); flex: none; }
.clone-status .dot.ok { background: var(--primary); }
.clone-status .dot.off { background: var(--text-dim); }

.reading-box {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem;
}
.reading-label { font-size: 0.78rem; color: var(--text-dim); margin-bottom: 0.5rem; }
.reading-text { font-size: 0.98rem; line-height: 1.5; }

.recorder, .clone-actions, .preview-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.preview { display: flex; flex-direction: column; gap: 0.7rem; }
.preview audio { width: 100%; }

.voice-hint { font-size: 0.8rem; line-height: 1.4; }

/* ─── Call view ──────────────────────────────────────────────── */
.call-card { display: flex; flex-direction: column; gap: 1rem; min-height: 60vh; }
.call-header { display: flex; align-items: center; justify-content: space-between; }
.call-peer { display: flex; align-items: center; gap: 0.7rem; }
.call-peer-name { font-weight: 700; font-size: 1.1rem; }
.call-peer-status { font-size: 0.8rem; color: var(--text-dim); }
.call-timer { font-family: monospace; font-size: 1.1rem; color: var(--text-dim); }

.transcript {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.5rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  min-height: 40vh;
  max-height: 55vh;
}
.transcript-empty { color: var(--text-dim); font-size: 0.9rem; margin: auto; text-align: center; }

.bubble {
  max-width: 78%;
  padding: 0.55rem 0.8rem;
  border-radius: 14px;
  border: 1px solid var(--border);
}
.bubble.mine { align-self: flex-end; background: rgba(16,185,129,0.12); border-color: rgba(16,185,129,0.35); }
.bubble.theirs { align-self: flex-start; background: var(--bg-card); }
.b-who { font-size: 0.7rem; color: var(--text-dim); margin-bottom: 0.2rem; }
.b-orig { font-size: 0.98rem; line-height: 1.35; }
.b-trans { font-size: 0.85rem; color: var(--text-dim); margin-top: 0.15rem; font-style: italic; }
.b-trans:empty { display: none; }

.call-controls { display: flex; justify-content: center; gap: 0.8rem; }
.call-controls .btn { padding: 0.7rem 2rem; font-size: 1rem; }
.btn.active { background: var(--danger); border-color: var(--danger); color: #fff; }

/* Speaking indicator */
.speaking-row {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.82rem; color: var(--text-dim);
  padding: 0 0.4rem;
}
.speaking-dots { display: inline-flex; gap: 3px; }
.speaking-dots i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--primary);
  animation: speakpulse 1s infinite ease-in-out;
}
.speaking-dots i:nth-child(2) { animation-delay: 0.15s; }
.speaking-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes speakpulse {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ─── Overlays (incoming / outgoing) ─────────────────────────── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 40;
}
.incoming-card {
  width: min(90vw, 340px);
  display: flex; flex-direction: column; align-items: center; gap: 0.8rem;
  text-align: center;
}
.incoming-avatar {
  width: 72px; height: 72px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--primary));
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; font-weight: 700; color: #fff;
}
.incoming-name { font-size: 1.3rem; font-weight: 700; }
.incoming-sub { color: var(--text-dim); font-size: 0.9rem; }
.incoming-actions { display: flex; gap: 0.8rem; margin-top: 0.5rem; }
.incoming-actions .btn { padding: 0.6rem 1.5rem; }

/* ─── Toast ──────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  background: var(--bg-card); border: 1px solid var(--border);
  padding: 0.7rem 1.1rem; border-radius: 10px; font-size: 0.9rem;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4); z-index: 50;
}
.toast.err { border-color: rgba(239,68,68,0.5); color: #fca5a5; }
