:root {
  --bg: #F8F9FA;
  --navy: #1F3864;
  --blue: #2E75B6;
  --blue-light: #D9E1F2;
  --text: #212529;
  --muted: #6C757D;
  --success: #198754;
  --error: #DC3545;
  --warning: #FFC107;
  --white: #FFFFFF;
  --border: #DEE2E6;
  --shadow: 0 2px 8px rgba(0,0,0,.1);
  --radius: 8px;
}

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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Loading screen ─────────────────────────────────────────── */
.loading-screen {
  position: fixed; inset: 0;
  background: var(--navy);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  flex-direction: column;
  gap: 1.5rem;
  color: var(--white);
  text-align: center;
}
.loading-screen h2 { font-size: 1.5rem; font-weight: 600; }
.loading-screen p { color: rgba(255,255,255,.7); font-size: .9rem; }

/* ── Header ─────────────────────────────────────────────────── */
.header {
  background: var(--navy);
  color: var(--white);
  padding: .75rem 1.5rem;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
}
.header-inner {
  max-width: 1400px; margin: 0 auto;
  display: flex; align-items: center; gap: 1rem;
}
.logo { font-size: 1.4rem; font-weight: 700; letter-spacing: .5px; }
.tagline { color: rgba(255,255,255,.65); font-size: .85rem; flex: 1; }

/* ── Layout ─────────────────────────────────────────────────── */
.main {
  max-width: 1400px; margin: 0 auto;
  padding: 1.5rem;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 900px) {
  .main { grid-template-columns: 1fr; }
}

/* ── Panels ─────────────────────────────────────────────────── */
.panel {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}
.panel h2 { font-size: 1rem; font-weight: 600; color: var(--navy); margin-bottom: 1rem; }

/* ── Sessions sidebar ───────────────────────────────────────── */
.session-item {
  display: flex; flex-direction: column; gap: .2rem;
  padding: .6rem .75rem;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s;
}
.session-item:hover { background: var(--blue-light); border-color: var(--blue); }
.session-item.active { background: var(--blue-light); border-color: var(--blue); }
.session-item-top { display: flex; align-items: center; gap: .4rem; }
.session-item .fname { font-size: .85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.delete-btn {
  flex-shrink: 0;
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: .8rem; padding: .1rem .3rem;
  border-radius: 4px; line-height: 1;
  opacity: 0; transition: opacity .15s, color .15s;
}
.session-item:hover .delete-btn { opacity: 1; }
.delete-btn:hover { color: var(--error); background: #ffe0e0; }
.session-item .fmeta { font-size: .75rem; color: var(--muted); }
.session-item .fstatus { font-size: .72rem; padding: .1rem .4rem; border-radius: 4px; display: inline-block; width: fit-content; }
.status-badge-completed { background: #d1f5e0; color: var(--success); }
.status-badge-error { background: #ffe0e0; color: var(--error); }
.status-badge-other { background: #e8eaf6; color: var(--blue); }

.sessions-empty { font-size: .85rem; color: var(--muted); padding: .5rem 0; }

/* ── Upload drop zone ───────────────────────────────────────── */
.upload-section { margin-top: 1rem; }
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--blue);
  background: var(--blue-light);
}
.drop-icon { font-size: 2rem; margin-bottom: .5rem; }
.drop-zone h3 { font-size: .95rem; color: var(--navy); margin-bottom: .25rem; }
.drop-zone p { font-size: .78rem; color: var(--muted); }
#file-input { display: none; }

/* ── Progress bar ───────────────────────────────────────────── */
.progress-wrap { margin-top: .75rem; }
.progress-bar {
  height: 8px; background: var(--border);
  border-radius: 4px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: var(--blue);
  border-radius: 4px;
  transition: width .3s ease;
  width: 0%;
}
.progress-label { font-size: .78rem; color: var(--muted); margin-top: .3rem; text-align: right; }
.progress-block { min-width: 180px; }
.progress-meta { display: flex; justify-content: space-between; margin-top: .3rem; }
.progress-meta span { font-size: .78rem; color: var(--muted); }
.eta { color: var(--blue) !important; font-weight: 500; }
.audio-dur { font-size: .78rem; color: var(--muted); margin-top: .15rem; }

/* ── Steps nav ──────────────────────────────────────────────── */
.steps-nav {
  display: flex; gap: 0;
  background: var(--bg);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.step-chip {
  flex: 1; min-width: 100px;
  text-align: center;
  padding: .55rem .5rem;
  font-size: .78rem;
  color: var(--muted);
  background: var(--bg);
  border-right: 1px solid var(--border);
  cursor: default;
  transition: background .2s, color .2s;
  white-space: nowrap;
}
.step-chip:last-child { border-right: none; }
.step-chip.done { background: #d1f5e0; color: var(--success); }
.step-chip.active { background: var(--blue); color: var(--white); font-weight: 600; }

/* ── Status card ────────────────────────────────────────────── */
.status-card {
  display: flex; align-items: center; gap: 1rem;
  background: var(--blue-light);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}
.status-card.error { background: #ffe0e0; }
.status-info { flex: 1; }
.status-info h3 { font-size: 1rem; color: var(--navy); margin-bottom: .2rem; }
.status-info p { font-size: .85rem; color: var(--muted); }

/* ── Spinner ────────────────────────────────────────────────── */
.spinner {
  width: 32px; height: 32px; flex-shrink: 0;
  border: 3px solid rgba(46,117,182,.25);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .45rem .9rem;
  font-size: .85rem; font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: background .15s, border-color .15s, opacity .15s;
  text-decoration: none;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: var(--white); border-color: var(--blue); }
.btn-primary:hover:not(:disabled) { background: #255f99; border-color: #255f99; }
.btn-secondary { background: var(--white); color: var(--blue); border-color: var(--blue); }
.btn-secondary:hover:not(:disabled) { background: var(--blue-light); }
.btn-danger { background: var(--white); color: var(--error); border-color: var(--error); }
.btn-danger:hover:not(:disabled) { background: #ffe0e0; }
.btn-sm { padding: .3rem .6rem; font-size: .78rem; }

/* ── Speaker table ──────────────────────────────────────────── */
.speakers-table-wrap { overflow-x: auto; margin-bottom: 1rem; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
thead th {
  background: var(--navy); color: var(--white);
  padding: .55rem .75rem; text-align: left; font-weight: 600;
}
tbody tr:nth-child(even) { background: var(--blue-light); }
tbody td { padding: .5rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.name-input {
  width: 100%; border: 1px solid var(--border); border-radius: 4px;
  padding: .3rem .5rem; font-size: .85rem;
}
.name-input:focus { outline: none; border-color: var(--blue); }
.play-btn {
  background: var(--blue); color: var(--white);
  border: none; border-radius: 4px;
  width: 28px; height: 28px;
  cursor: pointer; font-size: .9rem;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.play-btn:hover { background: #255f99; }
.play-btn.playing { background: var(--success); }

/* ── Passages ────────────────────────────────────────────────── */
.passages-list { display: flex; flex-wrap: wrap; gap: .2rem; max-width: 260px; }
.passage-btn {
  background: var(--blue-light); color: var(--navy);
  border: 1px solid #b0c4e8; border-radius: 4px;
  padding: .1rem .35rem;
  font-size: .7rem; font-family: monospace;
  cursor: pointer; white-space: nowrap;
  transition: background .15s, color .15s;
}
.passage-btn:hover { background: var(--blue); color: var(--white); }
.passage-btn.playing { background: var(--success); border-color: var(--success); color: var(--white); }
.passages-more { font-size: .7rem; color: var(--muted); padding: .1rem .2rem; align-self: center; }

/* ── Merge ───────────────────────────────────────────────────── */
.merge-select {
  border: 1px solid var(--border); border-radius: 4px;
  padding: .28rem .35rem; font-size: .78rem;
  background: var(--white); color: var(--text);
  max-width: 140px;
}
tr.row-merged { background: #fafafa !important; }
tr.row-merged td { opacity: .65; }
tr.row-merged .merge-select { border-color: var(--warning); opacity: 1; }
tr.row-merged .name-input { color: var(--muted); font-style: italic; }

/* ── Bruit probable ──────────────────────────────────────────── */
.noise-badge {
  font-size: .68rem; background: #fff3cd; color: #856404;
  border: 1px solid #ffc107; border-radius: 4px;
  padding: .05rem .3rem; white-space: nowrap;
}

/* ── Transcript ─────────────────────────────────────────────── */
.transcript-content {
  display: flex; flex-direction: column; gap: .75rem;
  max-height: 600px; overflow-y: auto;
  padding-right: .25rem;
}
.segment {
  border-left: 3px solid var(--blue-light);
  padding: .5rem .75rem;
  border-radius: 0 6px 6px 0;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.segment:hover { border-color: var(--blue); background: var(--blue-light); }
.seg-header { display: flex; gap: .75rem; align-items: baseline; margin-bottom: .25rem; }
.seg-speaker { font-weight: 600; color: var(--navy); font-size: .85rem; }
.seg-time { font-size: .75rem; color: var(--muted); font-family: monospace; }
.seg-text { font-size: .9rem; line-height: 1.5; }

/* ── CR editor ──────────────────────────────────────────────── */
.cr-layout {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;
  margin-bottom: 1rem;
}
@media (max-width: 800px) { .cr-layout { grid-template-columns: 1fr; } }
.cr-pane label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: .4rem; text-transform: uppercase; letter-spacing: .5px; }
.cr-textarea {
  width: 100%; height: 500px;
  border: 1px solid var(--border); border-radius: 6px;
  padding: .75rem; font-size: .85rem; font-family: monospace;
  resize: vertical;
  line-height: 1.6;
}
.cr-textarea:focus { outline: none; border-color: var(--blue); }
.cr-preview {
  height: 500px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 6px;
  padding: .75rem 1rem;
  font-size: .9rem; line-height: 1.6;
}
.cr-preview h1 { font-size: 1.4rem; color: var(--navy); margin: .5rem 0; }
.cr-preview h2 { font-size: 1.1rem; color: var(--blue); margin: 1rem 0 .4rem; }
.cr-preview h3 { font-size: .95rem; color: var(--navy); margin: .8rem 0 .3rem; }
.cr-preview p { margin-bottom: .5rem; }
.cr-preview ul, .cr-preview ol { margin: .4rem 0 .4rem 1.5rem; }
.cr-preview li { margin-bottom: .2rem; }
.cr-preview table { font-size: .85rem; width: 100%; margin: .5rem 0; }
.cr-preview th { background: var(--blue); color: var(--white); padding: .4rem .6rem; }
.cr-preview td { padding: .35rem .6rem; border: 1px solid var(--border); }
.cr-preview tr:nth-child(even) td { background: var(--blue-light); }
.cr-preview hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }

/* ── Section header ─────────────────────────────────────────── */
.section-header {
  display: flex; align-items: center; gap: .75rem;
  margin-bottom: 1rem; flex-wrap: wrap;
}
.section-header h3 { font-size: 1.05rem; color: var(--navy); flex: 1; }

/* ── Alert ──────────────────────────────────────────────────── */
.alert {
  padding: .75rem 1rem;
  border-radius: 6px;
  font-size: .85rem;
  margin-bottom: 1rem;
}
.alert-error { background: #ffe0e0; color: var(--error); border: 1px solid #f5c6cb; }
.alert-success { background: #d1f5e0; color: var(--success); border: 1px solid #c3e6cb; }
.alert-info { background: var(--blue-light); color: var(--blue); border: 1px solid #bee5f5; }

/* ── Audio element ──────────────────────────────────────────── */
audio { height: 32px; margin-top: .25rem; }

/* ── Queue badge ────────────────────────────────────────────── */
.queue-badge {
  display: inline-block; background: var(--warning); color: #333;
  border-radius: 999px; padding: .1rem .5rem; font-size: .75rem; font-weight: 600;
}

/* ── Utilities ──────────────────────────────────────────────── */
.hidden { display: none !important; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.flex-gap { display: flex; gap: .5rem; flex-wrap: wrap; }
