:root {
  --bg: #0d1117;
  --surface: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --green: #3fb950;
  --red: #f85149;
  --orange: #d29922;
  --radius: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
}

/* ── Login overlay ─────────────────────────────────────── */
#login-overlay {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
#login-overlay.hidden { display: none; }
.login-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 2rem; width: 100%; max-width: 360px;
}
.login-box h1 { font-size: 1.3rem; margin-bottom: 1.2rem; }
.login-box input {
  width: 100%; padding: .6rem .8rem; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--bg); color: var(--text);
  font-size: 1rem; margin-bottom: .8rem;
}
.login-box button { width: 100%; }
.login-error { color: var(--red); font-size: .85rem; margin-top: .5rem; min-height: 1.2em; }

/* ── Nav ───────────────────────────────────────────────── */
nav {
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem;
  position: sticky; top: 0; z-index: 10;
}
.nav-title { font-weight: 600; font-size: 1rem; margin-right: auto; }
nav a {
  color: var(--muted); text-decoration: none; font-size: .9rem; padding: .3rem .5rem;
  border-radius: 4px;
}
nav a.active, nav a:hover { color: var(--text); background: var(--border); }
#btn-logout {
  background: none; border: 1px solid var(--border); color: var(--muted);
  padding: .3rem .7rem; border-radius: 4px; cursor: pointer; font-size: .85rem;
}
#btn-logout:hover { border-color: var(--red); color: var(--red); }

/* ── Layout ────────────────────────────────────────────── */
main { padding: 1.5rem 1rem; max-width: 800px; margin: 0 auto; }
section { display: none; }
section.active { display: block; }

/* ── Shared components ─────────────────────────────────── */
button {
  background: var(--accent); color: #000; border: none; border-radius: var(--radius);
  padding: .5rem 1.2rem; font-size: .9rem; font-weight: 600; cursor: pointer;
}
button:disabled { opacity: .4; cursor: not-allowed; }
button.secondary {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
}
button.danger { background: var(--red); color: #fff; }

/* ── Dictate tab ───────────────────────────────────────── */
.dictate-center { display: flex; flex-direction: column; align-items: center; gap: 1.2rem; padding: 2rem 0; }

#mic-btn {
  width: 120px; height: 120px; border-radius: 50%;
  background: var(--surface); border: 3px solid var(--accent);
  font-size: 2.5rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: transform .15s, border-color .15s;
}
#mic-btn:hover { transform: scale(1.05); }
#mic-btn.recording {
  border-color: var(--red);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248,81,73,.5); }
  50% { box-shadow: 0 0 0 16px rgba(248,81,73,0); }
}

.mic-meter {
  width: 200px; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden;
}
.mic-meter-fill { height: 100%; background: var(--green); width: 0%; transition: width .1s; }

#timer { font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
#interim-line { font-style: italic; color: var(--muted); min-height: 1.4em; text-align: center; max-width: 600px; }
#final-text { white-space: pre-wrap; max-width: 600px; width: 100%; }
.saved-notice { color: var(--green); font-size: .85rem; }

/* ── Upload tab ────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 3rem 1rem; text-align: center; cursor: pointer; color: var(--muted);
  transition: border-color .2s, background .2s;
}
.drop-zone.over { border-color: var(--accent); background: rgba(88,166,255,.05); }
.drop-zone input { display: none; }

.progress-bar { width: 100%; height: 8px; background: var(--border); border-radius: 4px; margin-top: 1rem; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); transition: width .2s; }
.indeterminate .progress-fill { width: 40%; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }

#upload-result { margin-top: 1.5rem; }

/* ── History tab ───────────────────────────────────────── */
#search-input {
  width: 100%; padding: .6rem .8rem; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--bg); color: var(--text);
  font-size: .95rem; margin-bottom: 1rem;
}
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; margin-bottom: .75rem; cursor: pointer;
  transition: border-color .15s;
}
.card:hover { border-color: var(--accent); }
.card-meta { display: flex; gap: .6rem; align-items: center; margin-bottom: .4rem; font-size: .8rem; color: var(--muted); }
.badge { padding: .15rem .5rem; border-radius: 3px; font-size: .75rem; font-weight: 600; }
.badge.realtime { background: rgba(88,166,255,.2); color: var(--accent); }
.badge.upload { background: rgba(63,185,80,.2); color: var(--green); }
.card-text { font-size: .9rem; color: var(--muted); }
#load-more { margin-top: 1rem; width: 100%; }

/* ── Modal ─────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.5rem; width: 100%; max-width: 640px; max-height: 80vh;
  overflow-y: auto; display: flex; flex-direction: column; gap: 1rem;
}
.modal-text { white-space: pre-wrap; font-size: .95rem; flex: 1; }
.modal-actions { display: flex; gap: .7rem; }

/* ── Desktop ────────────────────────────────────────────── */
@media (min-width: 768px) {
  main { padding: 2rem; }
  nav { padding: .6rem 2rem; }
}
