/* Design tokens mirrored from tb3-pipeline-designer/static/style.css */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --bg:          #0e1118;
  --bg2:         #151922;
  --bg3:         #1c2333;
  --bg4:         #222d3d;

  --border:      #2a3547;
  --border2:     #374761;

  --blue:        #4f8ef7;
  --blue-dim:    #1e3a6e;
  --blue-pale:   rgba(79,142,247,0.10);
  --blue-glow:   rgba(79,142,247,0.20);

  --teal:        #2dd4bf;
  --teal-dim:    #0d4a42;
  --teal-pale:   rgba(45,212,191,0.10);

  --amber:       #f59e0b;
  --amber-dim:   #4a3008;
  --amber-pale:  rgba(245,158,11,0.10);

  --red:         #ef4444;
  --red-dim:     #4a1010;
  --red-pale:    rgba(239,68,68,0.10);

  --text:        #e2e8f0;
  --text-dim:    #7d8d9e;
  --text-mute:   #7a8a9a;

  --ui:   'Inter', system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;

  --r-sm: 4px;
  --r:    6px;
  --r-lg: 10px;
}

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

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui);
  font-size: 13px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar       { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

.label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.mono { font-family: var(--mono); }

/* ── Form elements ─────────────────────────────────────────────────────── */
input[type=text], input[type=password], select, textarea {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: var(--ui);
  font-size: 13px;
  padding: 8px 10px;
  outline: none;
  width: 100%;
  transition: border-color 0.15s;
  appearance: none;
  -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px var(--blue-pale);
}
input::placeholder, textarea::placeholder { color: var(--text-mute); }
select option { background: var(--bg3); }
select:not([size]):not([multiple]) {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%237d8d9e' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
textarea { resize: vertical; min-height: 260px; font-family: var(--ui); }

input[type=range] { accent-color: var(--blue); width: 100%; }
input[type=checkbox] { accent-color: var(--blue); width: auto; }

/* Client-facing demo mode keeps advanced tuning fixed in app.js. */
body[data-demo-mode="true"] [data-demo-hidden] { display: none !important; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--ui);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: var(--r);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  user-select: none;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:hover { background: #6b9ef8; box-shadow: 0 0 20px var(--blue-glow); }
.btn-outline { background: transparent; color: var(--text); border-color: var(--border2); }
.btn-outline:hover { border-color: var(--text-dim); background: var(--bg3); }
.btn-danger { background: transparent; color: var(--red); border-color: var(--red-dim); }
.btn-danger:hover { background: var(--red-pale); border-color: var(--red); }
.btn-sm { font-size: 11px; padding: 5px 10px; }

/* ── Layout ────────────────────────────────────────────────────────────── */
.app-header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-title { font-size: 15px; font-weight: 600; }
.app-title .accent { color: var(--blue); }
.app-version { font-size: 10px; font-weight: 500; color: var(--text-mute); margin-left: 6px; vertical-align: 2px; }
.model-label { font-size: 10px; font-weight: 600; color: var(--accent); margin-left: 6px; vertical-align: 2px; padding: 1px 6px; border: 1px solid var(--accent); border-radius: 4px; }
.header-spacer { flex: 1; }

.main {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(320px, 1fr);
  align-items: start;
  gap: 16px;
  padding: 16px 20px;
  max-width: 1400px;
  margin: 0 auto;
}
@media (max-width: 980px) { .main { grid-template-columns: 1fr; } .main .full { grid-column: auto; } }

.col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.card-text { grid-column: 1; }
.side { grid-column: 2; }
.full { grid-column: 1 / -1; }
@media (max-width: 980px) { .card-text, .side { grid-column: auto; } }

.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card-head { display: flex; align-items: center; gap: 10px; }
.card-head .label { flex: 1; }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 140px; }
.check-row { display: flex; align-items: center; gap: 6px; color: var(--text-dim); font-size: 12px; }
.check-row input { margin: 0; }

.hint { font-size: 11px; color: var(--text-mute); }

/* ── Status dot ────────────────────────────────────────────────────────── */
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-mute);
  flex-shrink: 0;
}
.status-dot.ok { background: var(--teal); box-shadow: 0 0 6px var(--teal); }
.status-dot.bad { background: var(--red); box-shadow: 0 0 6px var(--red); }
.status-dot.warn { background: var(--amber); }
.status-wrap { display: flex; align-items: center; gap: 7px; font-size: 11px; color: var(--text-dim); }

/* ── Segments preview ──────────────────────────────────────────────────── */
.segments-list { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow-y: auto; }
.segment-item {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 7px 10px;
  font-size: 12px;
  display: flex;
  gap: 8px;
  align-items: baseline;
}
.segment-item .seg-idx { font-family: var(--mono); color: var(--blue); flex-shrink: 0; }
.segment-item .seg-chars { font-family: var(--mono); color: var(--text-mute); flex-shrink: 0; font-size: 11px; }
.segment-item .seg-text { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.segment-item.active { border-color: var(--blue); background: var(--blue-pale); }
.segment-item.short { border-color: var(--amber-dim); }
.segment-item .seg-warn { color: var(--amber); font-size: 11px; flex-shrink: 0; cursor: help; }
.segment-item.done .seg-idx { color: var(--teal); }
.segment-item.error { border-color: var(--red); }

/* ── Preprocessing preview (debug) ─────────────────────────────────────── */
.preprocess-list { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; }
.pp-item {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.pp-head { display: flex; gap: 8px; align-items: baseline; }
.pp-head .seg-idx { font-family: var(--mono); color: var(--blue); }
.pp-head .hint { margin-left: auto; }
.pp-line { display: grid; grid-template-columns: 42px 1fr; gap: 8px; align-items: baseline; }
.pp-line .pp-tag {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-mute);
  text-align: right;
}
.pp-line .pp-text { color: var(--text-dim); word-break: break-word; }
.pp-line.pp-final .pp-text { color: var(--teal); }
.pp-line.pp-error .pp-text { color: var(--red); }

/* ── Mode switch ───────────────────────────────────────────────────────── */
.mode-switch { display: flex; border: 1px solid var(--border2); border-radius: var(--r); overflow: hidden; }
.mode-switch button {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-family: var(--ui);
  font-size: 12px;
  font-weight: 500;
  padding: 7px 16px;
  cursor: pointer;
}
.mode-switch button.active { background: var(--blue-dim); color: var(--text); }
.seg-mode-row { gap: 12px; }
.seg-mode-row .label { flex-shrink: 0; }

/* ── Player ────────────────────────────────────────────────────────────── */
.player-area { display: flex; flex-direction: column; gap: 10px; }
audio { width: 100%; height: 36px; }

.live-player {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 8px 12px;
}
.live-player .time { font-family: var(--mono); font-size: 11px; color: var(--text-dim); min-width: 88px; text-align: right; }
.progress {
  flex: 1;
  height: 4px;
  background: var(--bg4);
  border-radius: 2px;
  overflow: hidden;
}
.progress > span { display: block; height: 100%; width: 0%; background: var(--blue); transition: width 0.2s linear; }
.live-badge {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--teal);
  border: 1px solid var(--teal-dim);
  background: var(--teal-pale);
  border-radius: 999px;
  padding: 2px 8px;
}
.live-badge.buffering { color: var(--amber); border-color: var(--amber-dim); background: var(--amber-pale); }

/* ── Stats ─────────────────────────────────────────────────────────────── */
.stats-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 6px 12px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 92px;
}
.chip .chip-label { font-size: 9px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-mute); }
.chip .chip-value { font-family: var(--mono); font-size: 14px; color: var(--text); }
.chip .chip-value.accent { color: var(--teal); }

.stats-table { width: 100%; border-collapse: collapse; font-size: 11px; font-family: var(--mono); }
.stats-table th {
  text-align: right;
  font-family: var(--ui);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-mute);
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
}
.stats-table td { text-align: right; padding: 4px 8px; color: var(--text-dim); border-bottom: 1px solid var(--border); }
.stats-table th:first-child, .stats-table td:first-child { text-align: left; }

details.stats-details summary { cursor: pointer; color: var(--text-dim); font-size: 11px; user-select: none; }

/* ── Error banner ──────────────────────────────────────────────────────── */
.error-banner {
  background: var(--red-pale);
  border: 1px solid var(--red-dim);
  border-radius: var(--r);
  color: var(--red);
  padding: 8px 12px;
  font-size: 12px;
  word-break: break-word;
}
.error-banner.warn {
  background: var(--amber-pale);
  border-color: var(--amber-dim);
  color: var(--amber);
}

/* ── Reference audio drop area ─────────────────────────────────────────── */
.file-drop {
  border: 1.5px dashed var(--border2);
  border-radius: var(--r);
  padding: 18px 14px;
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.file-drop:hover, .file-drop.drag-over {
  border-color: var(--blue);
  background: var(--blue-pale);
}
.file-drop.uploading { opacity: 0.6; pointer-events: none; }

/* ── File drop (text upload) ───────────────────────────────────────────── */
.file-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.char-count { font-family: var(--mono); font-size: 11px; color: var(--text-mute); }
