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

:root {
  --bg:        #f8f9fa;
  --surface:   #ffffff;
  --border:    #e2e5e9;
  --text:      #1a1a1a;
  --text-sec:  #6b7280;
  --primary:   #2563eb;
  --primary-h: #1d4ed8;
  --danger:    #dc2626;
  --green:     #16a34a;
  --orange:    #ea580c;
  --radius:    10px;
  --shadow:    0 1px 3px rgba(0,0,0,.08);
}

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

#app {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100vh;
}

.hidden { display: none !important; }
.text-secondary { color: var(--text-sec); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border: none;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-h); }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-outline {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--bg); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Source panel ── */
#source-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.source-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.source-tabs .tab {
  flex: 1;
  padding: 14px;
  border: none;
  background: none;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-sec);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s, background .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.source-tabs .tab:hover {
  background: var(--bg);
}
.source-tabs .tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.source-tabs .tab svg {
  flex-shrink: 0;
}

.source-body { padding: 24px; }

/* ── Config sections & fields ── */
.config-section {
  margin-bottom: 20px;
}
.config-section:last-of-type {
  margin-bottom: 24px;
}
.config-section-title {
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-sec);
  margin-bottom: 10px;
}
.config-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.field-grow { flex: 1; min-width: 160px; }
.field-label {
  font-size: .75rem;
  font-weight: 500;
  color: var(--text-sec);
}
.field input[type="text"],
.field input[type="number"],
.field select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .875rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.field input:focus,
.field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.field input[type="number"] {
  width: 80px;
}

/* ── Toggle switches ── */
.toggle-group {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  cursor: pointer;
  transition: background .1s;
}
.toggle-row:hover { background: var(--bg); }
.toggle-row + .toggle-row { border-top: 1px solid var(--border); }
.toggle-info { display: flex; flex-direction: column; gap: 1px; }
.toggle-label {
  font-size: .85rem;
  font-weight: 500;
  color: var(--text);
}
.toggle-desc {
  font-size: .72rem;
  color: var(--text-sec);
}

.toggle-switch {
  -webkit-appearance: none;
  appearance: none;
  width: 40px;
  height: 22px;
  border-radius: 11px;
  background: #d1d5db;
  position: relative;
  cursor: pointer;
  transition: background .2s;
  flex-shrink: 0;
  margin: 0;
}
.toggle-switch::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
  transition: transform .2s;
}
.toggle-switch:checked {
  background: var(--primary);
}
.toggle-switch:checked::before {
  transform: translateX(18px);
}
.toggle-switch:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ── Drop zone ── */
.drop-zone {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 28px 20px;
  text-align: center;
  transition: border-color .2s, background .2s;
  cursor: pointer;
}
.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--primary);
  background: rgba(37,99,235,.04);
}
.drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.drop-zone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.drop-zone-icon {
  color: var(--text-sec);
  margin-bottom: 2px;
}
.drop-zone-text {
  font-size: .875rem;
  color: var(--text-sec);
}
.drop-zone-link {
  color: var(--primary);
  font-weight: 500;
}
.drop-zone-hint {
  font-size: .72rem;
  color: #9ca3af;
}
.drop-zone.has-file {
  border-style: solid;
  border-color: var(--green);
  background: rgba(22,163,74,.04);
  padding: 14px 20px;
}
.drop-zone.has-file .drop-zone-content { display: none; }
.drop-zone.has-file .drop-zone-file { display: flex !important; }
.drop-zone.has-file input[type="file"] { display: none; }
.drop-zone-file {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  font-size: .875rem;
  color: var(--text);
  font-weight: 500;
}
.drop-zone-clear {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--text-sec);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.drop-zone-clear:hover { color: var(--danger); }

/* ── Chip / pill selectors ── */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  display: inline-flex;
  align-items: center;
  padding: 7px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: .8rem;
  font-weight: 500;
  color: var(--text-sec);
  cursor: pointer;
  transition: all .15s;
  user-select: none;
}
.chip input { display: none; }
.chip:hover { border-color: #b0b7c3; }
.chip.selected {
  background: #eff6ff;
  border-color: var(--primary);
  color: var(--primary);
}

/* ── Large button variant ── */
.btn-lg {
  padding: 10px 24px;
  font-size: .9rem;
  gap: 8px;
}

/* ── Legacy compat (unused but kept for non-config areas) ── */
.config-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 16px;
  align-items: end;
}
.config-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: .8rem;
  color: var(--text-sec);
}
.config-row input[type="text"],
.config-row input[type="number"],
.config-row input[type="file"],
.config-row select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .875rem;
  background: var(--surface);
  color: var(--text);
}
.config-row label:has(input[type="checkbox"]) {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  font-size: .8rem;
}

/* ── Meeting header ── */
#meeting-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
}
.header-left { display: flex; align-items: center; gap: 12px; }
.header-left h1 { font-size: 1.1rem; font-weight: 600; }
.header-right { display: flex; align-items: center; gap: 12px; }

#meeting-meta { display: flex; gap: 10px; align-items: center; font-size: .8rem; color: var(--text-sec); }

.rec-dot {
  width: 12px; height: 12px;
  background: var(--danger);
  border-radius: 50%;
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .3; }
}

.badge {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  background: #dbeafe;
  color: var(--primary);
}
.badge.batch { background: #fef3c7; color: var(--orange); }
.badge.completed { background: #dcfce7; color: var(--green); }

/* ── Participants ── */
#participants { display: flex; gap: 0; align-items: center; flex-shrink: 0; }
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem; font-weight: 600; color: #fff;
  margin-left: -6px;
  border: 2px solid var(--surface);
  flex-shrink: 0;
}
.avatar:first-child { margin-left: 0; }
.avatar-overflow {
  background: #6b7280;
  font-size: .65rem;
}

/* ── Processing banner ── */
#processing-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
  font-size: .9rem;
  color: var(--text-sec);
}

#processing-text {
  line-height: 1.6;
}

.stage-label {
  color: var(--primary);
  font-weight: 500;
}

.stage-dots {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.stage-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
  transition: background .3s, box-shadow .3s;
}

.stage-dot.done {
  background: var(--primary);
}

.stage-dot.active {
  background: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 30%, transparent);
  animation: pulse-dot 1.2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 30%, transparent); }
  50%      { box-shadow: 0 0 0 6px color-mix(in srgb, var(--primary) 10%, transparent); }
}

.stage-dot[title] { cursor: help; }

.stage-metrics {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.stage-metric {
  display: inline-block;
  padding: 2px 0;
}

.spinner {
  width: 20px; height: 20px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Transcript ── */
#transcript {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-y: auto;
  max-height: 60vh;
  padding: 12px 0;
}

.entry {
  display: flex;
  gap: 12px;
  padding: 14px 20px;
}
.entry + .entry { border-top: 1px solid var(--border); }

.entry .avatar { flex-shrink: 0; margin-left: 0; }

.entry-body { flex: 1; min-width: 0; }
.entry-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.entry-speaker { font-weight: 600; font-size: .875rem; }
.entry-time    { font-size: .75rem; color: var(--text-sec); }
.lang-tag {
  padding: 1px 6px;
  border-radius: 4px;
  font-size: .65rem;
  font-weight: 500;
  background: #f3f4f6;
  color: var(--text-sec);
  border: 1px solid var(--border);
}

.entry-text { font-size: .9rem; line-height: 1.55; }
.entry-text.partial { color: var(--text-sec); font-style: italic; }

/* ── Results panel ── */
#results-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
}

.results-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}
.results-header h2 { font-size: 1.15rem; font-weight: 600; }
.results-header p  { font-size: .8rem; color: var(--text-sec); margin-top: 2px; }

.results-icon {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; font-weight: 700;
  flex-shrink: 0;
}
.success-icon { background: #dcfce7; color: var(--green); }
.error-icon   { background: #fee2e2; color: var(--danger); }

#results-transcript { margin-bottom: 20px; }
#results-transcript h3,
#results-downloads h3 {
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-sec);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 12px;
}

#results-transcript-body {
  max-height: 45vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 0;
}

.result-segment {
  padding: 10px 16px;
}
.result-segment + .result-segment {
  border-top: 1px solid var(--border);
}
.result-seg-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.result-speaker {
  font-weight: 600;
  font-size: .8rem;
}
.result-time {
  font-size: .7rem;
  color: var(--text-sec);
}
.result-seg-header .lang-tag {
  margin-left: 0;
}
.result-segment p {
  margin-top: 4px;
  font-size: .9rem;
  line-height: 1.5;
}

/* ── Pipeline metrics ── */
#pipeline-metrics { margin-bottom: 20px; }
#pipeline-metrics h3 {
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-sec);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 12px;
}
.pipeline-bars { display: flex; flex-direction: column; gap: 8px; }
.pipeline-row {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  align-items: center;
  gap: 10px;
}
.pipeline-label { font-size: .8rem; font-weight: 500; color: var(--text); }
.pipeline-bar-track {
  height: 8px;
  background: #f3f4f6;
  border-radius: 4px;
  overflow: hidden;
}
.pipeline-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  min-width: 4px;
  transition: width .3s ease;
}
.pipeline-detail { font-size: .75rem; color: var(--text-sec); white-space: nowrap; }
.pipeline-total {
  margin-top: 8px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text);
  text-align: right;
}

#results-downloads { margin-bottom: 20px; }

#results-file-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.download-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .8rem;
  color: var(--primary);
  text-decoration: none;
  transition: background .15s;
}
.download-link:hover {
  background: #eff6ff;
}
.download-link::before {
  content: "\2193";
  font-weight: 700;
}

.results-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ── Error overlay ── */
#error-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.error-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(0,0,0,.15);
  padding: 32px;
  max-width: 420px;
  width: 100%;
  text-align: center;
}
.error-card .results-icon {
  margin: 0 auto 16px;
}
.error-card h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 8px;
}
.error-card p {
  font-size: .875rem;
  color: var(--text-sec);
  margin-bottom: 20px;
  line-height: 1.5;
}

/* ── Bottom bar ── */
#bottom-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
  box-shadow: var(--shadow);
}
.stats { display: flex; gap: 16px; font-size: .8rem; color: var(--text-sec); }
.actions { display: flex; gap: 8px; }

/* ── Translation results ── */
#results-translation, #results-summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
#results-translation h3, #results-summary h3 {
  font-size: 1rem;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.translation-lang-section { margin-bottom: 16px; }
.translation-lang-section h4 {
  font-size: .85rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--primary);
  margin-bottom: 8px;
}
.translation-text {
  font-size: .9rem;
  line-height: 1.6;
  color: var(--text);
  padding: 12px;
  background: var(--bg);
  border-radius: 6px;
}

/* ── Summary results ── */
.summary-section { margin-bottom: 16px; }
.summary-section h4 {
  font-size: .85rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-sec);
  margin-bottom: 8px;
}
.summary-section p { font-size: .9rem; line-height: 1.6; }
.chip-group-display { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-display {
  display: inline-block;
  padding: 4px 10px;
  font-size: .8rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
}
.action-list { list-style: none; padding: 0; }
.action-list li {
  padding: 8px 12px;
  border-left: 3px solid var(--primary);
  margin-bottom: 6px;
  background: var(--bg);
  border-radius: 0 6px 6px 0;
  font-size: .88rem;
}
.entity-type-group {
  margin-bottom: 12px;
}
.entity-type-label {
  display: block;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--primary);
  margin-bottom: 6px;
}
.entity-items {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.entity-item {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 4px 10px;
  font-size: .84rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.entity-context { font-size: .75rem; }
.sentiment-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: .82rem;
  font-weight: 500;
}
.sentiment-positive { background: #dcfce7; color: #166534; }
.sentiment-negative { background: #fee2e2; color: #991b1b; }
.sentiment-neutral  { background: #f3f4f6; color: #374151; }
.sentiment-mixed    { background: #fef3c7; color: #92400e; }

/* ── Transcript tabs ── */
#transcript-tabs-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.transcript-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  background: var(--bg);
  padding: 0 4px;
}
.transcript-tab {
  padding: 10px 20px;
  font-size: .88rem;
  font-weight: 500;
  color: var(--text-sec);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.transcript-tab:hover {
  color: var(--text);
}
.transcript-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.transcript-tab-panels {
  padding: 16px 20px;
  max-height: 480px;
  overflow-y: auto;
}
.transcript-tab-panel {
  display: none;
}
.transcript-tab-panel.active {
  display: block;
}

/* ── AI post-processing section ── */
.ai-subsection {
  margin-bottom: 14px;
}
.ai-subsection .field-label {
  display: block;
  margin-bottom: 6px;
}

/* ── Translation config (mic controls) ── */
.translate-config {
  padding: 0 14px 8px;
}

/* ── Inline translation entries (stream) ── */
.entry.entry-translation {
  padding: 4px 20px 4px 64px;
  background: #f8fafc;
  border-top: none;
  gap: 8px;
}
.entry.entry-translation + .entry:not(.entry-translation) {
  border-top: 1px solid var(--border);
}
.translation-indicator {
  flex-shrink: 0;
  margin-top: 2px;
  opacity: .6;
}
.entry-translation .entry-text {
  font-size: .84rem;
  color: var(--primary);
  font-style: italic;
}
.translation-tag {
  background: #eff6ff;
  color: var(--primary);
  border-color: var(--primary);
}
