/* ============================================
   DESIGN SYSTEM — Dark-first premium UI
   ============================================ */

:root {
  /* Gradient accent */
  --grad: linear-gradient(135deg, #a78bfa 0%, #6366f1 50%, #4f46e5 100%);
  --grad-hover: linear-gradient(135deg, #c4b5fd 0%, #818cf8 50%, #6366f1 100%);
  --accent: #818cf8;
  --accent-dim: rgba(129, 140, 248, 0.12);
  --accent-glow: rgba(129, 140, 248, 0.25);

  /* Surfaces — dark */
  --bg: #09090b;
  --surface-0: #0c0c0f;
  --surface-1: #131318;
  --surface-2: #1a1a22;
  --surface-3: #23232e;
  --surface-raised: #18181f;

  /* Text */
  --text: #f0f0f5;
  --text-secondary: #9494a8;
  --text-muted: #5c5c72;

  /* Borders */
  --border: rgba(255,255,255,0.06);
  --border-hover: rgba(255,255,255,0.12);
  --border-accent: rgba(129, 140, 248, 0.3);

  /* Semantic */
  --success: #34d399;
  --error: #f87171;
  --warning: #fbbf24;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.6);
  --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.15);

  /* Layout */
  --sidebar-width: 320px;
  --topbar-height: 3.25rem;
  --radius: 10px;
  --radius-lg: 14px;

  /* Motion */
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --fast: 120ms;
  --normal: 200ms;

  /* Fonts */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'JetBrains Mono', monospace;
}

[data-theme="light"] {
  --bg: #f5f5f7;
  --surface-0: #ffffff;
  --surface-1: #f8f8fa;
  --surface-2: #eeeff2;
  --surface-3: #e4e5ea;
  --surface-raised: #ffffff;
  --text: #1a1a2e;
  --text-secondary: #6b6b80;
  --text-muted: #9e9eb0;
  --border: rgba(0,0,0,0.07);
  --border-hover: rgba(0,0,0,0.14);
  --accent-dim: rgba(99, 102, 241, 0.08);
  --accent-glow: rgba(99, 102, 241, 0.15);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.12);
  --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.08);
}

/* ============================================
   RESET + BASE
   ============================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

/* Global scrollbar styling */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 5px; }

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  overflow: hidden;
  display: grid;
  grid-template-rows: var(--topbar-height) 1fr;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-areas: "topbar topbar" "sidebar main";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body.sidebar-collapsed { grid-template-columns: 0 1fr; }
body.sidebar-collapsed .sidebar { transform: translateX(calc(-1 * var(--sidebar-width))); }

a { color: var(--accent); text-decoration: none; }
input, textarea, button, select { font-family: inherit; font-size: inherit; }

/* ============================================
   TOP BAR
   ============================================ */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: 1rem;
  background: var(--surface-0);
  border-bottom: 1px solid var(--border);
  z-index: 50;
  height: var(--topbar-height);
  backdrop-filter: blur(12px);
}

.topbar-left { display: flex; align-items: center; gap: 0.6rem; flex-shrink: 0; }

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

.topbar-title {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: var(--grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.topbar-center { flex: 1; display: flex; justify-content: center; }

.topbar-search {
  position: relative;
  width: 100%;
  max-width: 380px;
}

.topbar-search .search-icon {
  position: absolute;
  left: 0.7rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.topbar-search input {
  width: 100%;
  height: 2rem;
  border-radius: 8px;
  padding: 0 2.5rem 0 2.1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.8rem;
  outline: none;
  transition: border-color var(--fast), box-shadow var(--fast), background var(--fast);
}

.topbar-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
  background: var(--surface-1);
}

.topbar-search input::placeholder { color: var(--text-muted); }

.search-kbd {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text-muted);
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  pointer-events: none;
}

.topbar-right { display: flex; align-items: center; gap: 0.15rem; flex-shrink: 0; }

.sidebar-toggle, .icon-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background var(--fast), color var(--fast), border-color var(--fast);
}

.sidebar-toggle:hover, .icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

[data-theme="dark"] .icon-moon,
[data-theme="light"] .icon-sun { display: none; }

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  background: var(--surface-0);
  border-right: 1px solid var(--border);
  overflow: hidden;
  transition: transform var(--normal) var(--ease);
  z-index: 40;
}

.sidebar-upload {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.sidebar-list::-webkit-scrollbar { width: 4px; }
.sidebar-list::-webkit-scrollbar-track { background: transparent; }
.sidebar-list::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 4px; }

.list-header { padding: 0.75rem 0.85rem 0.35rem; }

.list-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

/* ============================================
   DROP ZONE
   ============================================ */
#drop-zone {
  position: relative;
  border: 1.5px dashed var(--border-hover);
  border-radius: var(--radius);
  padding: 0.85rem;
  cursor: pointer;
  transition: border-color var(--fast), background var(--fast), box-shadow var(--normal);
  overflow: hidden;
}

#drop-zone::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--grad);
  opacity: 0;
  transition: opacity var(--normal);
  border-radius: var(--radius);
}

#drop-zone:hover, #drop-zone.dragover {
  border-color: var(--accent);
  box-shadow: var(--shadow-glow);
}

#drop-zone:hover::before, #drop-zone.dragover::before { opacity: 0.05; }

.drop-zone-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  position: relative;
  text-align: center;
}

.drop-zone-icon { color: var(--text-muted); flex-shrink: 0; }

.drop-zone-text { text-align: center; }

#drop-zone p {
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--text);
  margin-bottom: 0.1rem;
  position: relative;
}

.drop-zone-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
  position: relative;
}

.diarize-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.diarize-toggle input {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
}

/* ============================================
   TRANSCRIPTION LIST
   ============================================ */
#transcription-list {
  display: flex;
  flex-direction: column;
  padding: 0.2rem 0.4rem;
  gap: 1px;
}

.transcription-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: background var(--fast), border-color var(--fast);
  animation: fadeSlideIn 0.2s var(--ease);
}

.transcription-item:hover {
  background: var(--surface-2);
}

.transcription-item.active {
  background: var(--accent-dim);
  border-left-color: var(--accent);
}

.item-info { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; flex: 1; }

.item-filename {
  font-weight: 600;
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.item-meta {
  font-size: 0.65rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.item-right { display: flex; align-items: center; gap: 0.4rem; flex-shrink: 0; margin-left: 0.4rem; }

.item-status { font-size: 0.65rem; font-weight: 600; white-space: nowrap; }

.status-done { color: var(--success); }
.status-error { color: var(--error); }
.status-pending, .status-extracting, .status-transcribing { color: var(--accent); }

.item-warn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  background: var(--warning, #d97706);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1;
  cursor: help;
}

.postprocess-warning {
  margin: 0.5rem 0 1rem;
  padding: 0.5rem 0.75rem;
  border-left: 3px solid var(--warning, #d97706);
  background: color-mix(in srgb, var(--warning, #d97706) 12%, transparent);
  border-radius: 0.25rem;
  font-size: 0.8rem;
}

.postprocess-warning-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.15rem 0;
}

.postprocess-retry {
  background: transparent;
  border: 1px solid var(--warning, #d97706);
  color: var(--warning, #d97706);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 0.25rem;
  cursor: pointer;
}

.postprocess-retry:hover:not(:disabled) {
  background: var(--warning, #d97706);
  color: #fff;
}

.postprocess-retry:disabled { opacity: 0.6; cursor: wait; }

.item-progress { width: 50px; }
.item-progress progress {
  width: 100%;
  height: 3px;
  border-radius: 3px;
  margin: 0;
  -webkit-appearance: none;
  appearance: none;
  background: var(--surface-3);
  border: none;
  display: block;
}
.item-progress progress::-webkit-progress-bar { background: var(--surface-3); border-radius: 3px; }
.item-progress progress::-webkit-progress-value { background: var(--grad); border-radius: 3px; }

.item-actions { display: flex; gap: 0.15rem; align-items: center; }

.item-delete, .item-retry {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0.1rem 0.25rem;
  border-radius: 4px;
  line-height: 1;
}

.item-delete { color: var(--text-muted); font-size: 0.95rem; }
.item-delete:hover { color: var(--error); background: rgba(248,113,113,0.1); }
.item-delete.confirming { color: var(--error); font-size: 0.6rem; font-weight: 700; }

.item-retry {
  color: var(--accent);
  font-size: 0.65rem;
  font-weight: 600;
  border: 1px solid var(--border);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}
.item-retry:hover { background: var(--accent-dim); border-color: var(--accent); }

/* ============================================
   EMPTY STATE
   ============================================ */
#transcript-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  position: relative;
}

.empty-state-glow {
  position: absolute;
  width: 300px;
  height: 300px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
  filter: blur(60px);
  pointer-events: none;
  animation: pulseGlow 4s ease-in-out infinite alternate;
}

@keyframes pulseGlow {
  from { opacity: 0.3; transform: scale(0.9); }
  to { opacity: 0.6; transform: scale(1.1); }
}

.empty-state-icon { position: relative; margin-bottom: 1rem; }

.empty-state-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.35rem;
  position: relative;
}

.empty-state-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  position: relative;
}

.empty-state {
  cursor: pointer;
  transition: background var(--normal);
  border-radius: var(--radius-lg);
}

.empty-state:hover { background: var(--surface-1); }

.empty-state.dragover {
  background: var(--accent-dim);
  outline: 2px dashed var(--accent);
  outline-offset: -8px;
}

/* ============================================
   MAIN CONTENT
   ============================================ */
.main-content {
  grid-area: main;
  overflow: hidden;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

/* ============================================
   SKELETON LOADING
   ============================================ */
.skeleton-item { display: flex; flex-direction: column; gap: 0.35rem; padding: 0.55rem 0.65rem; }

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: 4px;
  height: 0.7rem;
}

.skeleton-title { width: 65%; }
.skeleton-meta { width: 35%; height: 0.55rem; }

@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.transcription-item.removing {
  animation: collapseOut 0.25s ease forwards;
}

@keyframes collapseOut {
  to { opacity: 0; max-height: 0; padding: 0; margin: 0; overflow: hidden; }
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
  body { grid-template-columns: 1fr; grid-template-areas: "topbar" "main"; }
  .sidebar {
    position: fixed; left: 0; top: var(--topbar-height); bottom: 0;
    width: var(--sidebar-width); z-index: 100;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
}
