:root {
  --ink: #1a1a1a;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #eff6ff;
  --accent-glow: rgba(37, 99, 235, 0.3);
  --bg: #f9fafb;
  --card: #ffffff;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 4px 12px rgba(16, 24, 40, 0.08), 0 8px 24px rgba(16, 24, 40, 0.06);
}

/* Follows the OS-level preference by default. A logged-in choice from the
   toggle (data-theme, persisted in localStorage) overrides this either way. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #e5e7eb;
    --muted: #9ca3af;
    --line: #2d3340;
    --accent: #3b82f6;
    --accent-dark: #60a5fa;
    --accent-soft: rgba(59, 130, 246, 0.14);
    --accent-glow: rgba(59, 130, 246, 0.35);
    --bg: #0f1115;
    --card: #1a1d24;
    --success: #4ade80;
    --success-bg: rgba(74, 222, 128, 0.15);
    --danger: #f87171;
    --danger-bg: rgba(248, 113, 113, 0.15);
    --warning: #fbbf24;
    --warning-bg: rgba(251, 191, 36, 0.15);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.45), 0 8px 30px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  --ink: #e5e7eb;
  --muted: #9ca3af;
  --line: #2d3340;
  --accent: #3b82f6;
  --accent-dark: #60a5fa;
  --accent-soft: rgba(59, 130, 246, 0.14);
  --accent-glow: rgba(59, 130, 246, 0.35);
  --bg: #0f1115;
  --card: #1a1d24;
  --success: #4ade80;
  --success-bg: rgba(74, 222, 128, 0.15);
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.15);
  --warning: #fbbf24;
  --warning-bg: rgba(251, 191, 36, 0.15);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.45), 0 8px 30px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg);
  background-image: radial-gradient(640px circle at 12% -8%, var(--accent-soft), transparent 60%);
  background-repeat: no-repeat;
  color: var(--ink);
  line-height: 1.5;
  transition: background-color 0.15s ease, color 0.15s ease;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 760px;
  margin: 0 auto;
  padding: 3rem 1.5rem 4rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.4rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  flex-shrink: 0;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  box-shadow: 0 3px 10px var(--accent-glow);
  color: white;
}

.brand-mark svg {
  width: 19px;
  height: 19px;
}

header h1 {
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}

#theme-toggle {
  position: relative;
  background: transparent;
  box-shadow: none;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#theme-toggle:hover:not(:disabled) {
  background: var(--accent-soft);
  color: var(--ink);
  border-color: var(--accent);
}

#theme-toggle svg {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  transform: translate(-50%, -50%);
  transition: opacity 0.2s ease, transform 0.3s ease;
}

#theme-toggle .icon-moon {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.5) rotate(-90deg);
}

#theme-toggle.is-dark .icon-sun {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.5) rotate(90deg);
}

#theme-toggle.is-dark .icon-moon {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1) rotate(0deg);
}

.subtitle {
  color: var(--muted);
  font-size: 1.02rem;
  max-width: 46ch;
  margin: 0 0 2rem;
}

section {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 2.25rem 1.5rem;
  border: 2px dashed var(--line);
  border-radius: 10px;
  background: var(--bg);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.dropzone:hover,
.dropzone.is-dragover,
.dropzone:focus-within {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.dropzone-icon {
  width: 26px;
  height: 26px;
  color: var(--muted);
  transition: color 0.15s ease;
}

.dropzone:hover .dropzone-icon,
.dropzone.is-dragover .dropzone-icon,
.dropzone:focus-within .dropzone-icon {
  color: var(--accent);
}

.dropzone-text {
  color: var(--ink);
  font-weight: 500;
  font-size: 0.95rem;
}

.dropzone-link {
  color: var(--accent);
  text-decoration: underline;
}

.dropzone-hint {
  color: var(--muted);
  font-size: 0.8rem;
}

#upload-btn {
  align-self: flex-start;
}

.how-it-works {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}

.how-step {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.how-step-num {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
}

.how-arrow {
  width: 14px;
  height: 14px;
  color: var(--line);
  flex-shrink: 0;
}

button {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: white;
  border: none;
  padding: 0.65rem 1.3rem;
  border-radius: 7px;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 2px 8px var(--accent-glow);
  transition: box-shadow 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
}

button:hover:not(:disabled) {
  box-shadow: 0 4px 14px var(--accent-glow);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

.error {
  color: var(--danger);
  margin: 0.75rem 0 0;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.progress-track {
  margin-top: 1.1rem;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.progress-fill {
  width: 40%;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  animation: indeterminate 1.4s ease-in-out infinite;
}

@keyframes indeterminate {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(250%);
  }
}

#status-section:not([hidden]),
#result-section:not([hidden]),
#error-section:not([hidden]) {
  animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.result-header h2 {
  font-size: 1.15rem;
  margin: 0;
  word-break: break-word;
}

.stats-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.85rem 0 0;
}

.stat-pill {
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
}

.stat-pill strong {
  color: var(--ink);
  font-weight: 700;
}

.summary-block {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  padding: 0.85rem 1rem;
  font-size: 0.98rem;
  line-height: 1.6;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-icon {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
}

.badge-completed {
  background: var(--success-bg);
  color: var(--success);
}

.badge-failed {
  background: var(--danger-bg);
  color: var(--danger);
}

.badge-queued,
.badge-processing {
  background: var(--warning-bg);
  color: var(--warning);
}

h3 {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 1.25rem 0 0.5rem;
}

.h3-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

section > h3:first-child {
  margin-top: 0;
}

ul {
  margin: 0;
  padding-left: 1.25rem;
}

.action-list {
  list-style: none;
  padding-left: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.action-list li:not(.muted) {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.65rem 0.85rem;
  background: var(--bg);
  border-radius: 0 8px 8px 0;
  border-left: 3px solid var(--accent);
}

.action-list input[type="checkbox"] {
  flex-shrink: 0;
  margin-top: 0.2rem;
}

.action-body {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
  min-width: 0;
}

.action-task {
  font-weight: 500;
}

.action-meta {
  display: flex;
  gap: 0.9rem;
  flex-wrap: wrap;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.meta-icon {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

.muted {
  color: var(--muted);
  list-style: none;
}

.transcript-details {
  margin-top: 1.25rem;
  border-top: 1px solid var(--line);
  padding-top: 1rem;
}

.transcript-details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
}

#result-transcript {
  white-space: pre-wrap;
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0.75rem;
}

#new-upload-btn,
#retry-btn {
  background: transparent;
  box-shadow: none;
  color: var(--accent);
  border: 1px solid var(--accent);
}

#new-upload-btn {
  margin-bottom: 1.25rem;
}

#retry-btn {
  margin-top: 1.25rem;
}

#new-upload-btn:hover,
#retry-btn:hover {
  background: var(--accent-soft);
}

.result-filename {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 0.5rem;
  word-break: break-word;
}

/* Recent meetings: a side tab pinned to the viewport edge, opening a
   slide-in panel — kept out of the main flow so it reads as a lookup
   tool, not part of the primary upload -> result path. */
#history-tab {
  position: fixed;
  top: 50%;
  right: 0;
  transform: translateY(-50%) rotate(180deg);
  writing-mode: vertical-rl;
  border-radius: 8px 0 0 8px;
  padding: 1rem 0.5rem;
  z-index: 20;
}

#history-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 29;
}

#history-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: min(320px, 85vw);
  background: var(--card);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  padding: 1.5rem;
  overflow-y: auto;
  z-index: 30;
}

.history-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.history-panel-header h3 {
  margin: 0;
}

#history-close-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  padding: 0 0.25rem;
}

#history-close-btn:hover {
  color: var(--ink);
}

#history-list {
  padding-left: 0;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.5rem;
  margin: 0 -0.5rem;
  border-radius: 8px;
  cursor: pointer;
  list-style: none;
  border-bottom: 1px solid var(--line);
  transition: background-color 0.15s ease;
}

.history-item:hover {
  background: var(--bg);
}

.history-main {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.history-title {
  word-break: break-word;
}

.history-time {
  color: var(--muted);
  font-size: 0.75rem;
}

.history-item:last-child {
  border-bottom: none;
}

.history-item:hover .history-title {
  color: var(--accent);
}

.site-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 2.5rem;
}

.site-footer a {
  color: var(--muted);
  text-decoration: underline;
}

.site-footer a:hover {
  color: var(--accent);
}

/* ---- v2: recording, actions, ask, search ---- */
.secondary-btn {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: none;
}
.secondary-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.danger-btn:hover:not(:disabled) { border-color: var(--danger); color: var(--danger); }
.record-row { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.record-row .secondary-btn { flex: 0 0 auto; }
#record-btn.is-recording { border-color: var(--danger); color: var(--danger); }
#record-btn.is-recording::before { content: ""; }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.result-actions button { width: auto; padding: 8px 14px; font-size: 0.875rem; }
.ask-form { display: flex; gap: 8px; }
.ask-form input {
  flex: 1; min-width: 0; padding: 10px 12px; font: inherit; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
}
.ask-form button { width: auto; flex: 0 0 auto; }
.ask-answer {
  margin-top: 10px; padding: 12px 14px; border-radius: 8px; white-space: pre-wrap;
  background: var(--accent-soft); border: 1px solid var(--line);
}
.seg { display: flex; gap: 10px; padding: 3px 0; line-height: 1.5; }
.seg-time { color: var(--accent); font-variant-numeric: tabular-nums; flex: 0 0 auto; }
#history-search {
  width: calc(100% - 32px); margin: 0 16px 8px; padding: 8px 10px; font: inherit; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
}
.history-snippet { display: block; color: var(--muted); font-size: 0.8rem; margin-top: 2px; }
.history-snippet mark { background: var(--warning-bg); color: inherit; border-radius: 2px; }
#history-more { margin: 8px 16px; width: calc(100% - 32px); }

/* ---- v3: chapters, sources, ask-all, live recording ---- */
.record-hint { font-size: 0.8rem; margin: 6px 0 0; }
.ask-all { margin-top: 28px; }
.chapter-list { list-style: none; padding: 0; }
.chapter-list li { display: flex; gap: 10px; padding: 4px 0; cursor: pointer; }
.chapter-list li:hover .chapter-title { color: var(--accent); }
.sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.source-chip {
  font-size: 0.78rem; padding: 3px 8px; border-radius: 999px; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); color: var(--muted);
}
.source-chip:hover { border-color: var(--accent); color: var(--accent); }
.seg.is-flash { background: var(--warning-bg); border-radius: 4px; }

.usage-note,
.answer-note {
  margin: 8px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}
