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

:root {
  --bg:            #09090f;
  --bg-panel:      #0e0e17;
  --bg-surface:    #13131f;
  --bg-hover:      #1a1a28;
  --border:        rgba(255,255,255,0.06);
  --border-md:     rgba(255,255,255,0.10);
  --border-strong: rgba(255,255,255,0.16);
  --accent:        #6366f1;
  --accent-dim:    rgba(99,102,241,0.12);
  --accent-glow:   rgba(99,102,241,0.25);
  --green:         #22c55e;
  --green-dim:     rgba(34,197,94,0.10);
  --amber:         #f59e0b;
  --red:           #ef4444;
  --text-1:        #e2e2f0;
  --text-2:        #8080a0;
  --text-3:        #3d3d58;
  --sans:          'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono:          'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  --r-sm:  5px;
  --r-md:  9px;
  --r-lg:  13px;
}

html, body { height: 100%; overflow: hidden; }
#app { height: 100%; overflow: hidden; display: flex; flex-direction: column; }

body {
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-1);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ── Top bar ────────────────────────────────────────────────────── */
#topbar {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.tb-left { display: flex; align-items: center; gap: 14px; }
.tb-right { display: flex; align-items: center; gap: 10px; }

.logo { display: flex; align-items: center; gap: 8px; }
.tb-key-short { display: none; }
.logo-mark { font-size: 15px; color: var(--accent); line-height: 1; }
.logo-name {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.01em;
  color: var(--text-1);
}

.model-tag {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
  padding: 2px 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 4px;
}

/* ── Usage indicator ────────────────────────────────────────────── */
.usage-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: var(--r-sm);
  font-size: 12px;
  font-weight: 500;
  background: var(--green-dim);
  border: 1px solid rgba(34,197,94,0.20);
  color: var(--green);
  transition: all 200ms ease;
}

.usage-indicator.exhausted {
  background: rgba(239,68,68,0.08);
  border-color: rgba(239,68,68,0.20);
  color: var(--red);
}

.usage-indicator.byok {
  background: var(--accent-dim);
  border-color: rgba(99,102,241,0.25);
  color: var(--accent);
}

.usage-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  animation: dot-pulse 2.5s ease-in-out infinite;
}

.usage-indicator.exhausted .usage-dot,
.usage-indicator.byok .usage-dot { animation: none; }

@keyframes dot-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ── BYOK strip ─────────────────────────────────────────────────── */
.byok-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.byok-label {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-2);
  white-space: nowrap;
}

.byok-input {
  width: 300px;
  height: 28px;
  background: var(--bg);
  border: 1px solid var(--border-md);
  border-radius: var(--r-sm);
  padding: 0 10px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-1);
  outline: none;
  transition: border-color 150ms ease;
}
.byok-input:focus { border-color: var(--accent); }
.byok-input.error { border-color: var(--red); }

.byok-hint {
  font-size: 11px;
  color: var(--text-3);
  margin-left: 2px;
}

/* ── Main layout ────────────────────────────────────────────────── */
#layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────────── */
#sidebar {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.sidebar-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-3);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.history-list::-webkit-scrollbar { width: 3px; }
.history-list::-webkit-scrollbar-track { background: transparent; }
.history-list::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 2px; }

.sidebar-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 48px 16px;
  text-align: center;
  color: var(--text-3);
}

.sidebar-empty p { font-size: 12px; color: var(--text-2); }
.muted { font-size: 11px !important; color: var(--text-3) !important; }

.history-item {
  padding: 9px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 150ms ease;
  margin-bottom: 2px;
}

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

.history-item.active {
  background: var(--accent-dim);
  border-color: rgba(99,102,241,0.22);
}

.hi-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.hi-time {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-3);
  margin-bottom: 4px;
}

.hi-preview {
  font-size: 11px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Workspace ──────────────────────────────────────────────────── */
#workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  border-right: 1px solid var(--border);
}

.ws-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Upload state ───────────────────────────────────────────────── */
#state-upload {
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.drop-zone {
  width: 100%;
  max-width: 460px;
  border: 1.5px dashed var(--border-md);
  border-radius: var(--r-lg);
  padding: 52px 36px;
  text-align: center;
  cursor: pointer;
  background: var(--bg-surface);
  transition: all 200ms ease;
  position: relative;
  overflow: hidden;
}

.drop-zone::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 0%, rgba(99,102,241,0.06) 0%, transparent 70%);
  pointer-events: none;
}

.drop-zone:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
  box-shadow: 0 0 0 1px var(--accent-dim), 0 12px 36px rgba(0,0,0,0.4);
}

.drop-zone.dragover {
  border-color: var(--accent);
  border-style: solid;
  background: var(--accent-dim);
  box-shadow: 0 0 0 2px var(--accent-glow), 0 20px 48px rgba(0,0,0,0.5);
  transform: scale(1.01);
}

.dz-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  position: relative;
  z-index: 1;
}

.dz-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1px solid var(--accent-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  transition: all 200ms ease;
}

.drop-zone:hover .dz-icon,
.drop-zone.dragover .dz-icon {
  background: rgba(99,102,241,0.2);
  box-shadow: 0 0 20px var(--accent-glow);
}

.dz-title {
  display: block;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-1);
  margin-bottom: 5px;
}

.dz-sub {
  display: block;
  font-size: 13px;
  color: var(--text-2);
}

.dz-formats { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }

.fmt {
  font-family: var(--mono);
  font-size: 10px;
  padding: 2px 7px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-3);
}

/* ── Processing state ───────────────────────────────────────────── */
#state-processing {
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.proc-card {
  width: 100%;
  max-width: 460px;
  background: var(--bg-surface);
  border: 1px solid var(--border-md);
  border-radius: var(--r-lg);
  padding: 28px 28px 24px;
}

.proc-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.proc-name {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 240px;
}

.proc-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
}

.proc-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid var(--accent-dim);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

/* ── Pipeline ───────────────────────────────────────────────────── */
.pipeline {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr auto;
  align-items: center;
  margin-bottom: 24px;
}

.pipe-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
}

.pipe-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-3);
  transition: color 300ms ease;
}

.pipe-node.active .pipe-label { color: var(--accent); }
.pipe-node.done .pipe-label { color: var(--green); }

.pipe-dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--border-strong);
  position: relative;
  transition: all 300ms ease;
}

.pipe-node.active .pipe-dot {
  border-color: var(--accent);
  background: var(--accent-dim);
  box-shadow: 0 0 0 4px var(--accent-glow);
  animation: pipe-pulse 1.6s ease-in-out infinite;
}

@keyframes pipe-pulse {
  0%, 100% { box-shadow: 0 0 0 4px var(--accent-glow); }
  50%       { box-shadow: 0 0 0 8px rgba(99,102,241,0.05); }
}

.pipe-node.done .pipe-dot {
  border-color: var(--green);
  background: var(--green-dim);
}

.pipe-node.done .pipe-dot::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 9px;
  height: 5px;
  border-left: 2px solid var(--green);
  border-bottom: 2px solid var(--green);
  transform: translate(-50%, -60%) rotate(-45deg);
}

.pipe-track {
  height: 2px;
  background: var(--border-strong);
  margin-bottom: 17px; /* nudge to align with dot center */
  position: relative;
  overflow: hidden;
}

.pipe-fill {
  position: absolute;
  left: 0; top: 0;
  height: 100%;
  width: 0%;
  background: var(--green);
  transition: width 500ms ease;
}

/* ── Waveform ───────────────────────────────────────────────────── */
.waveform {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 44px;
  padding: 0 14px;
  background: var(--bg);
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
}

.waveform-bar {
  flex: 1;
  max-width: 4px;
  min-width: 2px;
  background: var(--accent);
  border-radius: 2px;
  opacity: 0.65;
  animation: wave-bar 0.9s ease-in-out infinite;
}

@keyframes wave-bar {
  0%, 100% { height: 6px; }
  50%       { height: 100%; }
}

/* ── Result state ───────────────────────────────────────────────── */
#state-result { flex-direction: column; }

.result-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-panel);
}

.result-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-2);
  overflow: hidden;
}

.result-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-actions { display: flex; gap: 6px; flex-shrink: 0; }

.transcript-text {
  flex: 1;
  overflow-y: auto;
  padding: 22px 22px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.85;
  color: var(--text-1);
  white-space: pre-wrap;
  word-break: break-word;
}

.transcript-text::-webkit-scrollbar { width: 3px; }
.transcript-text::-webkit-scrollbar-track { background: transparent; }
.transcript-text::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 2px; }

/* ── Analysis panel ─────────────────────────────────────────────── */
#analysis-panel {
  width: 296px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  overflow: hidden;
}

.panel-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-3);
}

.analysis-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
}

.as-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  animation: dot-pulse 1s ease-in-out infinite;
}

.analysis-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 32px 24px;
  text-align: center;
  color: var(--text-3);
}

.analysis-empty p {
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.6;
  max-width: 180px;
}

.analysis-content {
  flex: 1;
  overflow-y: auto;
}

.analysis-content::-webkit-scrollbar { width: 3px; }
.analysis-content::-webkit-scrollbar-track { background: transparent; }
.analysis-content::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 2px; }

.a-section { padding: 14px; }

.a-hd {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.a-icon {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.a-icon-notes   { background: var(--accent-dim);             border: 1px solid rgba(99,102,241,0.22);  color: var(--accent); }
.a-icon-summary { background: var(--green-dim);               border: 1px solid rgba(34,197,94,0.18);   color: var(--green);  }
.a-icon-actions { background: rgba(245,158,11,0.10);          border: 1px solid rgba(245,158,11,0.18);  color: var(--amber);  }

.a-hd span {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-1);
}

.a-body {
  font-size: 12px;
  line-height: 1.75;
  color: var(--text-2);
}

.a-body ul { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 4px; }

.a-body li {
  padding: 5px 8px 5px 18px;
  position: relative;
  background: var(--bg-surface);
  border-radius: 4px;
  border: 1px solid var(--border);
  font-size: 12px;
  line-height: 1.6;
}

.a-body li::before {
  content: '·';
  position: absolute;
  left: 7px;
  color: var(--accent);
  font-weight: bold;
  font-size: 14px;
  line-height: 1.4;
}

.a-body li.action-item::before {
  content: counter(action-counter);
  counter-increment: action-counter;
  font-size: 10px;
  font-weight: 700;
  color: var(--amber);
  top: 6px;
  line-height: 1;
}

.a-body.actions-list { counter-reset: action-counter; }

.a-divider { height: 1px; background: var(--border); }

/* ── Buttons ────────────────────────────────────────────────────── */
.btn-sm {
  height: 28px;
  padding: 0 12px;
  border-radius: var(--r-sm);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 150ms ease;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  font-family: var(--sans);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-md);
  color: var(--text-2);
}
.btn-outline:hover { background: var(--bg-hover); color: var(--text-1); border-color: var(--border-strong); }

.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: #5254d4; }

.btn-ghost { background: transparent; color: var(--text-2); border: none; }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-1); }

.btn-primary {
  height: 36px;
  padding: 0 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--sans);
  transition: background 150ms ease;
}
.btn-primary:hover { background: #5254d4; }

.btn-ghost-lg {
  height: 36px;
  padding: 0 16px;
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border-md);
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--sans);
  transition: all 150ms ease;
}
.btn-ghost-lg:hover { background: var(--bg-hover); color: var(--text-1); }

.icon-btn {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  transition: all 150ms ease;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-2); }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: inherit;
  font-family: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 0;
}

/* ── Modal ──────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-md);
  border-radius: var(--r-lg);
  padding: 34px 32px;
  max-width: 380px;
  width: 90%;
  text-align: center;
  box-shadow: 0 40px 80px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.04);
  animation: modal-in 200ms ease-out;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-icon { font-size: 26px; color: var(--accent); margin-bottom: 14px; }

.modal-box h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-1);
  margin-bottom: 8px;
}

.modal-box p {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.65;
  margin-bottom: 20px;
}

.modal-input {
  width: 100%;
  height: 36px;
  background: var(--bg);
  border: 1px solid var(--border-md);
  border-radius: var(--r-sm);
  padding: 0 12px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-1);
  outline: none;
  margin-bottom: 16px;
  transition: border-color 150ms ease;
}
.modal-input:focus { border-color: var(--accent); }
.modal-input.error { border-color: var(--red); }

.modal-btns {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 16px;
}

.modal-link {
  font-size: 12px;
  color: var(--text-3);
  text-decoration: none;
}
.modal-link:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

/* ── Animations ─────────────────────────────────────────────────── */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fade-up { animation: fade-up 280ms ease-out forwards; }

/* ── Utility ────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 900px) {
  #sidebar { width: 180px; }
  #analysis-panel { width: 240px; }
}

@media (max-width: 680px) {
  #sidebar { display: none; }
  #analysis-panel { width: 200px; }
  .model-tag { display: none; }
  .byok-hint { display: none; }
}

@media (max-width: 520px) {
  /* Header: allow wrap so elements don't overlap */
  #topbar {
    height: auto;
    min-height: 48px;
    flex-wrap: wrap;
    padding: 8px 12px;
    gap: 6px;
  }

  .tb-right { gap: 6px; }

  /* Compact usage badge */
  .usage-indicator {
    font-size: 11px;
    padding: 2px 8px;
  }

  /* Compact BYOK button */
  #byok-toggle {
    font-size: 11px;
    padding: 0 10px;
  }

  .tb-key-full { display: none; }
  .tb-key-short { display: inline; }

  /* BYOK strip scrolls horizontally on narrow screens */
  .byok-strip { flex-wrap: wrap; gap: 6px; }
  .byok-input { width: 100%; max-width: 260px; }

  /* Usage badge: never wrap text internally */
  .usage-indicator { white-space: nowrap; }

  /* Upload state: push content slightly above dead center */
  #state-upload { padding-bottom: 80px; }

  /* Drop zone less padding */
  .drop-zone { padding: 36px 20px; }

  /* Analysis panel hidden by default (shown below transcript in result state) */
  #analysis-panel { display: none; }

  /* ── Mobile result layout: stack transcript + analysis vertically ── */
  #layout.mobile-results {
    flex-direction: column;
    overflow-y: hidden;
  }

  #layout.mobile-results #workspace {
    flex: 0 0 45vh;
    min-height: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow: hidden;
  }

  #layout.mobile-results #analysis-panel {
    display: flex;
    flex: 1;
    min-height: 0;
    width: 100%;
    border-top: none;
  }
}
