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

:root {
  --bg:        #f1f5f9;
  --surface:   #ffffff;
  --border:    #e2e8f0;
  --text:      #0f172a;
  --text-sec:  #64748b;
  --primary:   #1e3a5f;
  --primary-h: #162d4a;
  --primary-bg:#eff6ff;
  --accent:    #2563eb;
  --accent-h:  #1d4ed8;
  --accent-bg: #dbeafe;
  --danger:    #dc2626;
  --green:     #16a34a;
  --green-bg:  #dcfce7;
  --orange:    #ea580c;
  --amber:     #d97706;
  --sidebar-w: 300px;
  --header-h:  64px;
  --radius:    8px;
  --shadow:    0 1px 3px rgba(15,23,42,.06), 0 1px 2px rgba(15,23,42,.04);
  --shadow-md: 0 4px 6px rgba(15,23,42,.06), 0 2px 4px rgba(15,23,42,.04);
}

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

/* ── Full-height shell ── */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

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

/* ── App header (navy bar) ── */
#app-header {
  height: var(--header-h);
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 24px;
  flex-shrink: 0;
}
.app-brand { display: flex; align-items: center; gap: 12px; }
.brand-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: rgba(255,255,255,.15);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.brand-title { font-size: 1rem; font-weight: 600; color: #fff; line-height: 1.2; }
.brand-subtitle { font-size: .7rem; color: rgba(255,255,255,.65); letter-spacing: .02em; }

/* ── Two-column layout (fills remaining viewport) ── */
#layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ── Side panel ── */
#side-panel {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-h));
  position: sticky;
  top: var(--header-h);
}
.side-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px 12px;
}
.side-header h2 {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-sec);
}
.side-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  border-radius: 11px;
  background: var(--accent-bg);
  font-size: .72rem;
  font-weight: 600;
  color: var(--accent);
  padding: 0 6px;
}

/* ── Status summary strip ── */
.side-summary {
  display: flex;
  gap: 12px;
  padding: 0 20px 12px;
  font-size: .7rem;
  color: var(--text-sec);
}
.side-summary-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.side-summary-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.summary-dot-processing { background: var(--accent); }
.summary-dot-completed  { background: var(--green); }
.summary-dot-failed     { background: var(--danger); }

.side-list {
  flex: 1;
  overflow-y: auto;
  border-top: 1px solid var(--border);
}
.side-empty {
  padding: 32px 20px;
  text-align: center;
  font-size: .82rem;
  color: var(--text-sec);
}
.side-upload-btn {
  margin: 12px 16px 16px;
}

/* ── Side panel job items ── */
.side-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 20px;
  cursor: pointer;
  transition: background .1s;
  border-left: 3px solid transparent;
}
.side-item + .side-item { border-top: 1px solid var(--border); }
.side-item:hover { background: var(--bg); }
.side-item.active {
  background: var(--primary-bg);
  border-left-color: var(--accent);
}
.side-item-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 5px;
}
.side-dot-queued     { background: #cbd5e1; }
.side-dot-processing { background: var(--accent); animation: pulse-side 1.4s ease-in-out infinite; }
.side-dot-completed  { background: var(--green); }
.side-dot-failed     { background: var(--danger); }

@keyframes pulse-side {
  0%, 100% { opacity: 1; }
  50%      { opacity: .3; }
}

.side-item-body {
  flex: 1;
  min-width: 0;
}
.side-item-name {
  display: block;
  font-size: .82rem;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.side-item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}
.side-item-status {
  font-size: .7rem;
  color: var(--text-sec);
}
.side-item-time {
  font-size: .65rem;
  color: #94a3b8;
}

/* ── Main content ── */
#main-content {
  flex: 1;
  min-width: 0;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  height: calc(100vh - var(--header-h));
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border: none;
  border-radius: 6px;
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-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; }
.btn-sm { padding: 6px 12px; font-size: .78rem; }
.btn-lg { padding: 10px 24px; font-size: .88rem; gap: 8px; }

/* ── Upload panel ── */
#upload-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  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: 6px;
  font-size: .85rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.field input:focus, .field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.field input[type="number"] { width: 80px; }
.field input:disabled, .field select:disabled {
  background: var(--bg);
  color: var(--text-sec);
  cursor: not-allowed;
}

/* ── Toggle switches ── */
.toggle-group {
  border: 1px solid var(--border);
  border-radius: 6px;
  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: #cbd5e1;
  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,.12);
  transition: transform .2s;
}
.toggle-switch:checked { background: var(--accent); }
.toggle-switch:checked::before { transform: translateX(18px); }

.translate-sub-options {
  padding: 8px 14px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

/* ── Drop zone ── */
.drop-zone {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 28px 20px;
  text-align: center;
  transition: border-color .2s, background .2s;
  cursor: pointer;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(37,99,235,.03);
}
.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: .85rem; color: var(--text-sec); }
.drop-zone-link { color: var(--accent); font-weight: 500; }
.drop-zone-hint { font-size: .72rem; color: #94a3b8; }
.drop-zone.has-files {
  border-style: solid;
  border-color: var(--accent);
  background: rgba(37,99,235,.03);
  padding: 14px 20px;
}
.drop-zone.has-files .drop-zone-content { display: none; }
.drop-zone.has-files input[type="file"] { display: none; }

/* ── File list ── */
.file-list {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  font-size: .85rem;
}
.file-item + .file-item { border-top: 1px solid var(--border); }
.file-item-icon { color: var(--accent); flex-shrink: 0; }
.file-item-name { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item-size { font-size: .75rem; color: var(--text-sec); }
.file-item-remove {
  background: none; border: none; font-size: 1.1rem;
  color: var(--text-sec); cursor: pointer; padding: 0 4px; line-height: 1;
}
.file-item-remove:hover { color: var(--danger); }
.file-list-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  background: var(--bg);
  font-size: .75rem;
  color: var(--text-sec);
}

/* ── 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: #94a3b8; }
.chip.selected {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Results dashboard ── */
#results-dashboard {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.dashboard-header {
  display: flex;
  align-items: center;
  gap: 12px;
}
.dashboard-header h2 {
  font-size: 1.05rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dashboard-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}
.card-header h3 {
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-sec);
}

/* ── Split-pane transcript / translation ── */
#transcript-split-container {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  position: relative;
}
#transcript-split-container > .transcript-pane {
  flex: 1 1 60%;
  min-width: 200px;
}
#transcript-split-container > .translation-pane {
  flex: 0 0 auto;
  min-width: 200px;
}
.pane-label {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-sec);
  margin-right: 8px;
}
.pane-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}
.pane-tabs {
  display: flex;
  gap: 0;
  padding: 0 16px;
  border-bottom: 2px solid var(--border);
  background: #f8fafc;
}
.pane-tab {
  padding: 10px 20px;
  font-size: .85rem;
  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;
}
.pane-tab:hover { color: var(--text); }
.pane-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.pane-body {
  padding: 16px 20px;
  max-height: 520px;
  overflow-y: auto;
}
.pane-tab-panel { display: none; }
.pane-tab-panel.active { display: block; }
.translated-text { color: var(--accent); }

/* ── Resize handle ── */
.pane-resize-handle {
  width: 6px;
  cursor: col-resize;
  background: var(--border);
  flex-shrink: 0;
  position: relative;
  z-index: 2;
  transition: background .15s;
}
.pane-resize-handle:hover,
.pane-resize-handle.dragging {
  background: var(--accent);
}
.pane-resize-handle::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 28px;
  border-radius: 1px;
  background: rgba(0,0,0,.12);
}
.pane-resize-handle:hover::after,
.pane-resize-handle.dragging::after {
  background: rgba(255,255,255,.5);
}

/* ── Retry section ── */
.retry-section { padding: 16px 0; text-align: center; }
.retry-section .retry-btn { margin-top: 8px; }

/* ── Transcript segments ── */
.result-segment { padding: 10px 0; }
.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); }
.lang-tag {
  padding: 1px 6px;
  border-radius: 4px;
  font-size: .65rem;
  font-weight: 500;
  background: var(--bg);
  color: var(--text-sec);
  border: 1px solid var(--border);
}
.result-segment p { margin-top: 4px; font-size: .9rem; line-height: 1.5; }

/* ── Summary sections ── */
#summary-body, #actions-body, #metrics-body, #downloads-body {
  padding: 20px;
}
.summary-section { margin-bottom: 18px; }
.summary-section:last-child { margin-bottom: 0; }
.summary-section h4 {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-sec);
  margin-bottom: 8px;
  font-weight: 600;
}
.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 items ── */
.action-list { list-style: none; padding: 0; }
.action-list li {
  padding: 10px 14px;
  border-left: 3px solid var(--accent);
  margin-bottom: 8px;
  background: var(--accent-bg);
  border-radius: 0 6px 6px 0;
  font-size: .88rem;
  line-height: 1.5;
}
.action-list li strong { color: var(--primary); }
.action-deadline { font-size: .75rem; color: var(--text-sec); margin-left: 4px; }

.action-alert {
  border-left-color: var(--amber);
  background: #fffbeb;
}
.action-alert::before {
  content: "\26A0";
  margin-right: 8px;
}

/* ── Entities ── */
.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(--accent);
  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; color: var(--text-sec); }

/* ── Sentiment ── */
.sentiment-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: .82rem;
  font-weight: 500;
}
.sentiment-positive { background: var(--green-bg); color: #166534; }
.sentiment-negative { background: #fee2e2; color: #991b1b; }
.sentiment-neutral  { background: var(--bg); color: #374151; }
.sentiment-mixed    { background: #fef3c7; color: #92400e; }

/* ── Pipeline metrics ── */
.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: var(--bg);
  border-radius: 4px;
  overflow: hidden;
}
.pipeline-bar-fill {
  height: 100%;
  background: var(--accent);
  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;
}

/* ── Download links ── */
.download-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(--accent);
  text-decoration: none;
  transition: background .15s;
}
.download-link:hover { background: var(--accent-bg); }
.download-link::before { content: "\2193"; font-weight: 700; }

/* ── Badge ── */
.job-card-badge {
  padding: 2px 10px;
  border-radius: 12px;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  white-space: nowrap;
  flex-shrink: 0;
}
.badge-queued     { background: var(--bg); color: #64748b; }
.badge-processing { background: var(--accent-bg); color: var(--accent); }
.badge-completed  { background: var(--green-bg); color: #166534; }
.badge-failed     { background: #fee2e2; color: #991b1b; }

/* ── Error overlay ── */
#error-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.error-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 32px;
  max-width: 420px;
  width: 100%;
  text-align: center;
}
.error-card h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: 8px; }
.error-card p { font-size: .85rem; color: var(--text-sec); margin-bottom: 20px; line-height: 1.5; }
.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;
  margin: 0 auto 16px;
}
.error-icon { background: #fee2e2; color: var(--danger); }

/* ── Spinner ── */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  flex-shrink: 0;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ── */
@media (max-width: 768px) {
  #layout { flex-direction: column; }
  #side-panel {
    width: 100%;
    height: auto;
    max-height: 260px;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  #main-content {
    height: auto;
    padding: 16px 12px;
  }
  .config-grid { flex-direction: column; }
  .pane-tab { padding: 8px 12px; font-size: .8rem; }
  .pipeline-row { grid-template-columns: 80px 1fr auto; }
}
