:root {
  --bg: #0b1020;
  --panel: #0f1530;
  --panel-2: #131a3a;
  --line: #1d264d;
  --text: #e7ecff;
  --muted: #8a93b8;
  --accent: #7c8cff;
  --accent-2: #58e2c2;
  --a: #7c8cff;
  --b: #ff8fb1;
  --danger: #ff6471;
  --ok: #4ade80;
  --warn: #fbbf24;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Outfit, Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(1200px 700px at 80% -10%, #1a2358 0%, transparent 60%),
              radial-gradient(800px 500px at -10% 110%, #2a1454 0%, transparent 55%),
              var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: 100vh;
}

/* Sidebar */
#sidebar {
  background: linear-gradient(180deg, rgba(15,21,48,0.95), rgba(11,16,32,0.9));
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 14px;
}
.brand { display: flex; gap: 10px; align-items: center; }
.brand .logo {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center;
  font-weight: 800; color: #0b1020;
  letter-spacing: -0.5px;
}
.brand-title { font-weight: 700; font-size: 16px; }
.brand-sub { color: var(--muted); font-size: 12px; }

.sidebar-section { margin-top: 8px; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.section-label {
  text-transform: uppercase; font-size: 11px; color: var(--muted);
  letter-spacing: 0.08em; padding: 4px 6px 8px;
}
.session-list {
  list-style: none; padding: 0; margin: 0;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
}
.session-list li {
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
  display: flex; flex-direction: column; gap: 2px;
}
.session-list li:hover { background: var(--panel-2); }
.session-list li.active {
  background: var(--panel-2);
  border-color: var(--accent);
}
.session-list .s-title { font-weight: 600; font-size: 13px; }
.session-list .s-meta { color: var(--muted); font-size: 11px; }

.sidebar-foot { font-size: 12px; color: var(--muted); }
.sidebar-foot .hint {
  background: rgba(124,140,255,0.07);
  border: 1px dashed rgba(124,140,255,0.25);
  padding: 10px 12px;
  border-radius: 10px;
  line-height: 1.4;
}

/* Main */
#main {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  min-height: 0;
}

#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 21, 48, 0.6);
  backdrop-filter: blur(8px);
}
#topbar .left { display: flex; align-items: center; gap: 10px; min-width: 0; }
#sessionTitle {
  margin: 0; font-size: 18px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 50vw;
}
#sessionTitle[contenteditable="true"] {
  outline: 2px solid var(--accent);
  border-radius: 6px; padding: 0 6px;
}
#topbar .right { display: flex; align-items: center; gap: 10px; }

.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px;
  font-size: 12px; color: var(--muted);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--line);
}
.status-pill .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 0 rgba(255,255,255,0.3);
}
.status-pill.connecting .dot { background: var(--warn); animation: pulse 1.2s infinite; }
.status-pill.live .dot { background: var(--ok); animation: pulse 1.4s infinite; }
.status-pill.error .dot { background: var(--danger); }
.status-pill.live { color: var(--ok); }
.status-pill.error { color: var(--danger); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(74,222,128,0.5); }
  70% { box-shadow: 0 0 0 8px rgba(74,222,128,0); }
  100% { box-shadow: 0 0 0 0 rgba(74,222,128,0); }
}

button {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease, border-color 0.15s ease;
}
button:hover { background: #1a2350; }
button:active { transform: translateY(1px); }
button.primary {
  background: linear-gradient(135deg, var(--accent), #5b6dff);
  border-color: transparent;
  color: white;
  font-weight: 600;
}
button.primary:hover { filter: brightness(1.08); }
button.danger {
  background: linear-gradient(135deg, #ff6471, #c8424d);
  border-color: transparent;
  color: white;
  font-weight: 600;
}
button.ghost {
  background: transparent;
}
button.small { padding: 4px 10px; font-size: 12px; }
button.block { width: 100%; }

/* Live captions */
#speakers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 16px 22px 0;
}
.speaker {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
  min-height: 64px;
}
.speaker-a { border-left: 3px solid var(--a); }
.speaker-b { border-left: 3px solid var(--b); }
.speaker-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.live-caption {
  margin-top: 6px;
  font-size: 18px;
  font-weight: 500;
  color: var(--text);
  min-height: 26px;
  white-space: pre-wrap;
  word-break: break-word;
}
.live-caption.translating::after {
  content: '\u258d';
  display: inline-block;
  margin-left: 2px;
  animation: blink 0.9s steps(2, start) infinite;
  color: var(--accent);
}
@keyframes blink { to { opacity: 0; } }

/* Conversation */
#conversation {
  overflow-y: auto;
  padding: 18px 22px 8px;
  display: flex; flex-direction: column; gap: 10px;
}
.turn {
  display: flex;
  width: 100%;
}
.turn.a { justify-content: flex-start; }
.turn.b { justify-content: flex-end; }

.bubble {
  max-width: 70%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 14px;
  position: relative;
  box-shadow: var(--shadow);
}
.turn.a .bubble { border-left: 3px solid var(--a); border-top-left-radius: 4px; }
.turn.b .bubble { border-right: 3px solid var(--b); border-top-right-radius: 4px; }

.bubble .who {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
  display: flex; gap: 8px; align-items: center;
}
.bubble .who .lang {
  background: rgba(124,140,255,0.15);
  color: var(--accent);
  padding: 1px 6px; border-radius: 999px; font-size: 10px;
}
.bubble .src { font-size: 14px; color: var(--muted); margin-bottom: 4px; line-height: 1.35; }
.bubble .dst { font-size: 16px; line-height: 1.4; font-weight: 500; }
.bubble .ts { font-size: 10px; color: var(--muted); margin-top: 6px; opacity: 0.8; }

/* Bottom bar */
#bottombar {
  border-top: 1px solid var(--line);
  padding: 8px 22px;
  background: rgba(15, 21, 48, 0.6);
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
}
.meta { color: var(--muted); font-size: 12px; }
.meta .sep { margin: 0 8px; opacity: 0.5; }
audio { display: none; }

@media (max-width: 800px) {
  #app { grid-template-columns: 1fr; }
  #sidebar { display: none; }
  #speakers { grid-template-columns: 1fr; }
  .bubble { max-width: 88%; }
}

/* Empty state */
.empty {
  color: var(--muted);
  text-align: center;
  padding: 40px 20px;
  font-size: 14px;
}
