/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', monospace;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 150ms ease;
}

[data-theme="dark"] {
  --bg: #0a0a0f;
  --bg-card: #12121a;
  --bg-card-hover: #1a1a26;
  --bg-input: #1a1a26;
  --bg-topbar: #0e0e16;
  --border: #2a2a3a;
  --text: #e4e4ef;
  --text-muted: #8888a0;
  --text-heading: #f0f0ff;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --primary-bg: rgba(99, 102, 241, 0.1);
  --danger: #ef4444;
  --danger-hover: #f87171;
  --success: #22c55e;
  --warning: #f59e0b;
  --info: #3b82f6;
}

[data-theme="light"] {
  --bg: #f8f9fc;
  --bg-card: #ffffff;
  --bg-card-hover: #f3f4f6;
  --bg-input: #f3f4f6;
  --bg-topbar: #ffffff;
  --border: #e2e4ea;
  --text: #1f2937;
  --text-muted: #6b7280;
  --text-heading: #111827;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-bg: rgba(99, 102, 241, 0.08);
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --warning: #d97706;
  --info: #2563eb;
}

html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

h1, h2, h3 { color: var(--text-heading); font-weight: 600; line-height: 1.3; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }

pre {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  white-space: pre-wrap;
  word-break: break-word;
}

code {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  background: var(--bg-input);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  height: 56px;
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text-heading);
}
.topbar-logo:hover { color: var(--primary); }

.topbar-version {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-input);
  padding: 2px 8px;
  border-radius: 4px;
}

.topbar-spacer { flex: 1; }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-profile {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.topbar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
}

.topbar-name { font-size: 0.875rem; }
.topbar-link { font-size: 0.875rem; color: var(--text-muted); }
.topbar-link:hover { color: var(--primary); }
.topbar-role {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
  background: var(--primary-bg);
  padding: 2px 6px;
  border-radius: 4px;
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  transition: var(--transition);
}
.theme-toggle:hover { color: var(--text); border-color: var(--text-muted); }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: none; }

/* ===== Content ===== */
.content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px;
}

/* ===== Page Header ===== */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.page-meta { font-size: 0.875rem; color: var(--text-muted); margin-top: 4px; }
.page-actions { display: flex; gap: 8px; align-items: center; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-hover); color: white; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-muted); }

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { background: var(--danger-hover); color: white; }

.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn-lg { padding: 12px 28px; font-size: 1rem; }
.btn-full { width: 100%; justify-content: center; }

/* ===== Status Badge ===== */
.status-badge {
  font-size: 0.75rem;
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 500;
  text-transform: capitalize;
}
.status-ready { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.status-failed { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.status-processing { background: rgba(59, 130, 246, 0.15); color: var(--info); }
.status-uploaded { background: rgba(245, 158, 11, 0.15); color: var(--warning); }

/* ===== Stats Grid ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== Section ===== */
.section { margin-bottom: 32px; }
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

/* ===== Upload List ===== */
.upload-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.upload-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  transition: var(--transition);
}
.upload-card:hover { background: var(--bg-card-hover); color: var(--text); }

.upload-card-icon { color: var(--text-muted); flex-shrink: 0; }
.upload-card-info { flex: 1; min-width: 0; }
.upload-card-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.upload-card-meta { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state .btn { margin-top: 16px; }

/* ===== Upload Form ===== */
.upload-page { max-width: 600px; margin: 0 auto; }
.upload-form { margin-bottom: 16px; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  margin-bottom: 16px;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-bg);
}

.dropzone-icon { color: var(--text-muted); margin-bottom: 12px; }
.dropzone-text { font-weight: 500; margin-bottom: 4px; }
.dropzone-hint { font-size: 0.8rem; color: var(--text-muted); }
.dropzone-input { display: none; }

.file-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.875rem;
}
.file-info-name { font-weight: 500; }
.file-info-size { color: var(--text-muted); }

.upload-note {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.hidden { display: none !important; }

/* ===== Spinner ===== */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { display: inline-block; }

/* ===== Transcript ===== */
.transcript-section {
  margin-bottom: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.transcript-toggle {
  padding: 14px 20px;
  cursor: pointer;
  font-weight: 500;
  background: var(--bg-card);
  list-style: none;
}
.transcript-toggle::-webkit-details-marker { display: none; }
.transcript-toggle::before {
  content: "\25B6";
  display: inline-block;
  margin-right: 8px;
  font-size: 0.7rem;
  transition: transform 0.2s;
}
details[open] .transcript-toggle::before { transform: rotate(90deg); }

.transcript-content {
  padding: 16px 20px;
  max-height: 400px;
  overflow-y: auto;
  background: var(--bg-input);
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
  line-height: 1.7;
}

/* ===== Alert ===== */
.alert {
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  margin-bottom: 24px;
  font-size: 0.875rem;
}
.alert-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--danger);
}

/* ===== Outputs Grid ===== */
.outputs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(460px, 1fr));
  gap: 20px;
}

.output-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.output-card-inner { display: flex; flex-direction: column; height: 100%; }

.output-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  flex-wrap: wrap;
  gap: 8px;
}

.output-card-type {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-heading);
}

.output-card-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.output-card-body {
  padding: 16px 18px;
  flex: 1;
  max-height: 350px;
  overflow-y: auto;
}

.output-text {
  font-family: var(--font);
  font-size: 0.875rem;
  line-height: 1.7;
  color: var(--text);
}

/* ===== Landing ===== */
.landing {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
}

.landing-hero {
  text-align: center;
  max-width: 640px;
  margin-bottom: 64px;
}

.landing-title {
  font-size: 3rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), #a855f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 16px;
}

.landing-subtitle {
  font-size: 1.15rem;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 32px;
}

.landing-features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 24px;
  max-width: 800px;
  width: 100%;
}

.feature-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  text-align: center;
}
.feature-card h3 { margin: 12px 0 8px; }
.feature-card p { font-size: 0.875rem; color: var(--text-muted); }
.feature-icon { color: var(--primary); }

/* ===== Unauthorized ===== */
.unauthorized {
  text-align: center;
  padding: 64px 24px;
}
.unauthorized h1 { margin-bottom: 12px; }
.unauthorized p { color: var(--text-muted); margin-bottom: 24px; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .topbar { padding: 0 16px; gap: 8px; }
  .topbar-name { display: none; }
  .content { padding: 20px 16px; }
  .outputs-grid { grid-template-columns: 1fr; }
  .landing-title { font-size: 2rem; }
  .page-header { flex-direction: column; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .topbar-version { display: none; }
  .stats-grid { grid-template-columns: 1fr; }
}
