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

:root {
  --bg: #fafafa; --surface: #fff; --fg: #111; --muted: #666; --border: #e5e5e5;
  --accent: #2563eb; --accent-hover: #1d4ed8; --accent-soft: #eff6ff;
  --danger: #dc2626; --shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.04);
  --radius: 12px;
}

[data-theme="dark"] {
  --bg: #0a0a0a; --surface: #161616; --fg: #f0f0f0; --muted: #999; --border: #2a2a2a;
  --accent: #3b82f6; --accent-hover: #60a5fa; --accent-soft: #172554; --danger: #f87171;
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.2);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--fg); min-height: 100vh; line-height: 1.5;
}

.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}

.topbar-inner {
  max-width: 820px; margin: 0 auto; padding: .75rem 1.25rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}

.brand { font-weight: 700; letter-spacing: -.02em; }
.topbar-right { display: flex; align-items: center; gap: .65rem; flex-wrap: wrap; justify-content: flex-end; }
.user-email { font-size: .78rem; color: var(--muted); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usage-pill {
  font-size: .75rem; font-weight: 600; padding: .3rem .65rem; border-radius: 100px;
  background: var(--accent-soft); color: var(--accent); border: 1px solid var(--border);
}

.page { max-width: 820px; margin: 0 auto; padding: 2rem 1.25rem 5rem; }
header { text-align: center; margin-bottom: 2rem; }
header h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -.03em; margin-bottom: .35rem; }
header p { color: var(--muted); font-size: .95rem; }
.platforms { display: flex; justify-content: center; gap: .5rem; margin-top: .75rem; flex-wrap: wrap; }
.platform-badge {
  font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  padding: .25rem .6rem; border: 1px solid var(--border); border-radius: 100px; color: var(--muted);
}

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1.25rem;
}

.input-row { display: flex; gap: .65rem; }
.input-row input {
  flex: 1; padding: .75rem 1rem; border: 1.5px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--fg); font-size: .95rem; outline: none;
}
.input-row input:focus { border-color: var(--accent); }

button {
  font-family: inherit; cursor: pointer; border: none; border-radius: 10px;
  font-size: .9rem; font-weight: 600; transition: background .2s, opacity .2s;
}
button:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; padding: .75rem 1.25rem; white-space: nowrap; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--muted); padding: .4rem .65rem; font-size: .8rem; border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--fg); border-color: var(--fg); }

.divider { display: flex; align-items: center; gap: .75rem; margin: 1rem 0; color: var(--muted); font-size: .78rem; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.upload-zone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .35rem; padding: 1.5rem; border: 2px dashed var(--border); border-radius: 10px;
  background: var(--bg); cursor: pointer; text-align: center; transition: border-color .2s;
}
.upload-zone:hover, .upload-zone.dragover { border-color: var(--accent); }
.upload-title { font-weight: 600; font-size: .9rem; }
.upload-hint { font-size: .78rem; color: var(--muted); max-width: 360px; }

.status { margin-top: .85rem; font-size: .85rem; color: var(--muted); min-height: 1.25rem; }
.status.error { color: var(--danger); }
.status.loading { color: var(--accent); }
.spinner {
  display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite;
  vertical-align: middle; margin-right: .4rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

.section-title {
  font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin-bottom: .85rem;
}

.history-list { display: flex; flex-direction: column; gap: .5rem; }
.history-item {
  display: flex; align-items: flex-start; gap: .75rem; padding: .85rem 1rem;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
  cursor: pointer; transition: border-color .2s, background .2s; text-align: left; width: 100%;
}
.history-item:hover, .history-item.active { border-color: var(--accent); background: var(--accent-soft); }
.history-icon {
  flex-shrink: 0; width: 32px; height: 32px; border-radius: 8px; display: flex;
  align-items: center; justify-content: center; font-size: .85rem; font-weight: 700;
  background: var(--surface); border: 1px solid var(--border);
}
.history-body { flex: 1; min-width: 0; }
.history-title { font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-meta { font-size: .78rem; color: var(--muted); margin-top: .15rem; }
.history-preview {
  font-size: .82rem; color: var(--muted); margin-top: .3rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.empty-state { text-align: center; padding: 2rem 1rem; color: var(--muted); font-size: .9rem; }

.status-badge {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .75rem; font-weight: 600; padding: .15rem .5rem;
  border-radius: 100px; white-space: nowrap;
}
.status-badge .spinner { width: 12px; height: 12px; margin-right: 0; }
.status-badge.pending,
.status-badge.downloading,
.status-badge.transcribing { background: var(--accent-soft); color: var(--accent); }
.status-badge.failed { background: #fef2f2; color: var(--danger); }
[data-theme="dark"] .status-badge.failed { background: #2d1b1b; }

.history-item.in-progress { opacity: .7; cursor: default; }
.history-item[disabled] { pointer-events: none; }
.history-item.in-progress:hover { border-color: var(--border); background: var(--bg); }

.result-header { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.result-actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.result-title { font-size: 1.1rem; font-weight: 700; letter-spacing: -.02em; }
.result-meta { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .35rem; }
.meta-chip {
  font-size: .72rem; font-weight: 600; padding: .2rem .55rem; border-radius: 100px;
  background: var(--bg); border: 1px solid var(--border); color: var(--muted);
}
.meta-chip a { color: inherit; text-decoration: none; }
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: .65rem; margin-bottom: 1.25rem; }
.stat { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: .75rem; text-align: center; }
.stat-value { font-size: 1.35rem; font-weight: 700; }
.stat-label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-top: .15rem; }

.utterances { display: flex; flex-direction: column; gap: .65rem; max-height: 520px; overflow-y: auto; }
.utterance { display: flex; gap: .75rem; padding: .75rem; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); }
.speaker-badge {
  flex-shrink: 0; width: 36px; height: 36px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; font-size: .75rem; font-weight: 700; color: #fff;
}
.utterance-top { display: flex; align-items: center; gap: .5rem; margin-bottom: .25rem; }
.speaker-name { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.timestamp { font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.utterance-text { font-size: .92rem; line-height: 1.55; }

.tabs { display: flex; gap: .35rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); padding-bottom: .5rem; }
.tab { background: none; color: var(--muted); padding: .4rem .75rem; border-radius: 8px; font-size: .82rem; font-weight: 600; }
.tab.active { background: var(--accent-soft); color: var(--accent); }

.json-view {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 1rem;
  font-family: "SF Mono", "Fira Code", monospace; font-size: .78rem; line-height: 1.6;
  max-height: 520px; overflow: auto; white-space: pre-wrap; word-break: break-word;
}
.json-key { color: #9333ea; } .json-string { color: #16a34a; } .json-number { color: #2563eb; }
.json-bool { color: #ea580c; } .json-null { color: var(--muted); }
[data-theme="dark"] .json-key { color: #c084fc; } [data-theme="dark"] .json-string { color: #4ade80; }
[data-theme="dark"] .json-number { color: #60a5fa; } [data-theme="dark"] .json-bool { color: #fb923c; }

.hidden { display: none !important; }
.theme-toggle {
  position: fixed; bottom: 1.5rem; right: 1.5rem; background: var(--surface);
  border: 1.5px solid var(--border); border-radius: 50%; width: 42px; height: 42px;
  display: flex; align-items: center; justify-content: center; color: var(--fg); box-shadow: var(--shadow);
}

@media (max-width: 560px) {
  .input-row { flex-direction: column; }
  .btn-primary { width: 100%; }
}
