:root {
  --bg: #0f172a;
  --bg-elev: #111827;
  --bg-card: #1e293b;
  --line: #334155;
  --ink: #e5e7eb;
  --muted: #94a3b8;
  --accent: #2563eb;
  --accent-2: #3b82f6;
  --danger: #f87171;
  --ok: #34d399;
  --warn: #fbbf24;
  --pad: max(16px, env(safe-area-inset-left));
  --pad-r: max(16px, env(safe-area-inset-right));
  --pad-t: max(12px, env(safe-area-inset-top));
  --pad-b: max(16px, env(safe-area-inset-bottom));
  --tap: 44px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: #93c5fd; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: var(--pad-t) var(--pad-r) 12px var(--pad);
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { font-weight: 700; font-size: 1.15rem; color: var(--ink); }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 600;
  background: var(--bg-card);
  border: 1px solid var(--line);
}
.pill.ok { color: var(--ok); border-color: #065f46; }
.pill.down { color: var(--danger); border-color: #7f1d1d; }
.pill.cpu { color: var(--warn); }
.pill.dot::before {
  content: "";
  width: 8px; height: 8px; border-radius: 50%;
  background: currentColor;
}

.page {
  max-width: 920px;
  margin: 0 auto;
  padding: 16px var(--pad-r) calc(24px + var(--pad-b)) var(--pad);
}
.page.editor-page {
  max-width: 1100px;
  padding-bottom: calc(96px + var(--pad-b));
}

h1 { font-size: 1.4rem; margin: 0 0 8px; }
h2 { font-size: 1.05rem; margin: 20px 0 10px; font-weight: 650; }
.muted { color: var(--muted); font-size: .92rem; }
.err { color: var(--danger); }

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 16px 0;
}
.btn {
  min-height: var(--tap);
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 650;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn.secondary { background: var(--bg-card); border: 1px solid var(--line); color: var(--ink); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn.danger { background: #7f1d1d; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
}
.card.running { border-color: var(--accent); }

.job-card h3 { margin: 0 0 4px; font-size: 1.02rem; }
.job-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 650;
  background: var(--bg-card);
}
.chip.queued { color: var(--muted); }
.chip.running, .chip.recording { color: #93c5fd; background: #1e3a5f; }
.chip.paused { color: var(--warn); }
.chip.done { color: var(--ok); }
.chip.error, .chip.cancelled { color: var(--danger); }
.job-progress { margin: 6px 0 10px; color: var(--muted); font-size: .9rem; }
.job-stats { margin: 0 0 8px; color: var(--muted); font-size: .88rem; }
.job-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.job-actions .btn { min-height: var(--tap); padding: 8px 12px; font-size: .9rem; }

.pulse {
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), #60a5fa, var(--accent));
  background-size: 200% 100%;
  animation: pulse 1.4s linear infinite;
  margin: 8px 0;
}
@keyframes pulse { to { background-position: -200% 0; } }

.drawer summary {
  list-style: none;
  min-height: var(--tap);
  display: flex;
  align-items: center;
  font-weight: 650;
  cursor: pointer;
}
.drawer summary::-webkit-details-marker { display: none; }
.field { margin: 10px 0; }
.field label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 4px; }
.field input, .field select {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-card);
}
.hint { font-size: .8rem; color: var(--muted); margin: 4px 0 0; }
.listing a {
  display: block;
  min-height: var(--tap);
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--pad-b));
  transform: translateX(-50%);
  background: #0b1220;
  border: 1px solid var(--line);
  padding: 12px 16px;
  border-radius: 12px;
  z-index: 50;
  max-width: 90vw;
  min-width: 220px;
}
.toast-msg { display: block; }
.toast-bar {
  display: block;
  height: 4px;
  background: var(--line);
  border-radius: 99px;
  margin-top: 8px;
  overflow: hidden;
}
.toast-bar > i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent-2);
  border-radius: 99px;
}

/* Record sheet */
.sheet {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet-body {
  width: 100%;
  max-width: 520px;
  background: var(--bg-elev);
  border-radius: 20px 20px 0 0;
  padding: 20px var(--pad) calc(20px + var(--pad-b));
  text-align: center;
}
.rec-time { font-size: 2.4rem; font-variant-numeric: tabular-nums; margin: 8px 0 16px; }
.rec-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: #ef4444;
  display: inline-block;
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: .2; } }

/* Editor */
.editor-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
@media (min-width: 900px) {
  .editor-layout { grid-template-columns: 220px 1fr; align-items: start; }
  .speakers { position: sticky; top: 72px; }
}
.speakers { background: var(--bg-elev); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.spk-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 8px;
  border-radius: 10px;
}
.spk-chip.on { background: var(--bg-card); }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 12px; }

.doc { display: flex; flex-direction: column; gap: 14px; }
.para {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px 12px 12px;
  border-left-width: 4px;
}
.para.hit { outline: 2px solid #1e3a5f; }
.para.cur { outline: 2px solid var(--warn); }
.para-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.para-head button {
  background: none;
  border: 0;
  color: var(--muted);
  min-height: 32px;
  padding: 0 6px;
  font-weight: 650;
}
.para [contenteditable] {
  outline: none;
  line-height: 1.45;
  min-height: 1.4em;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.toolbar .btn { min-height: var(--tap); }

.player-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--bg-elev);
  border-top: 1px solid var(--line);
  padding: 10px var(--pad-r) calc(10px + var(--pad-b)) var(--pad);
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 10px;
}
.player-bar audio { flex: 1; height: 36px; }
.player-bar .btn { min-width: var(--tap); }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--pad);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
}
.login-card h1 { margin-bottom: 4px; }
.login-card label {
  display: block;
  font-size: .82rem;
  color: var(--muted);
  margin: 12px 0 4px;
}
.login-card input {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-card);
}
.login-card .btn { width: 100%; margin-top: 16px; }

.empty {
  text-align: center;
  padding: 40px 12px;
  color: var(--muted);
}

.menu {
  position: relative;
}
.menu-list {
  position: absolute;
  right: 0;
  top: 100%;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 12px;
  min-width: 160px;
  z-index: 30;
  overflow: hidden;
}
.menu-list a, .menu-list button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  color: var(--ink);
  padding: 12px 14px;
  min-height: var(--tap);
}

.findbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.findbar input { flex: 1; min-width: 140px; min-height: var(--tap); padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-card); }

.summary-box {
  white-space: pre-wrap;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  line-height: 1.45;
}

.hidden { display: none !important; }
.file-btn { position: relative; overflow: hidden; }
.file-btn.busy { opacity: .55; pointer-events: none; }
.file-btn input[type=file] {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}
