:root {
  --bg: #0b1020;
  --bg-soft: #111838;
  --panel: #161f45;
  --panel-soft: #1c274f;
  --border: #27335f;
  --text: #e4eaff;
  --text-dim: #8b97c6;
  --accent: #7aa2ff;
  --accent-soft: #4f7bff33;
  --ok: #3ddc84;
  --warn: #ffb84d;
  --err: #ff5c7a;
  --pending: #4a5680;
  --running: #7aa2ff;
  --running-glow: rgba(122, 162, 255, 0.6);
  --success: #3ddc84;
  --error: #ff5c7a;
  --skipped: #586088;
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at top, #17204a 0%, var(--bg) 55%);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 20px 28px;
  background: rgba(13, 19, 44, 0.7);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand h1 { font-size: 18px; margin: 0; }
.brand .subtitle { margin: 0; color: var(--text-dim); font-size: 12px; }
.logo {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #7aa2ff, #4f7bff);
  display: grid; place-items: center;
  font-weight: 700;
  box-shadow: 0 0 24px rgba(122, 162, 255, 0.4);
}
.back {
  font-size: 24px; margin-right: 10px;
  color: var(--text-dim);
}
.tabs { display: flex; gap: 6px; margin-left: auto; }
.tabs button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
}
.tabs button.active {
  background: var(--accent-soft);
  color: var(--text);
  border-color: var(--accent);
}
.status-pill {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
}
.status-pill.ok { color: var(--ok); border-color: var(--ok); }
.status-pill.err { color: var(--err); border-color: var(--err); }

main { padding: 28px; max-width: 1400px; margin: 0 auto; }

.view { display: none; }
.view.active { display: block; }

.toolbar {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filters { display: flex; gap: 12px; align-items: flex-end; }
.filters label {
  display: flex;
  flex-direction: column;
  font-size: 11px;
  color: var(--text-dim);
  gap: 4px;
}
.filters select,
.filters button {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
}
.filters button { cursor: pointer; }

.queue-stats { display: flex; gap: 12px; }
.queue-stats > div {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 110px;
}
.queue-stats span { font-size: 20px; font-weight: 600; }
.queue-stats small { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

.transcription-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}
.transcription-table th,
.transcription-table td {
  text-align: left;
  padding: 14px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.transcription-table th {
  background: var(--panel-soft);
  color: var(--text-dim);
  font-weight: 500;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
}
.transcription-table tbody tr:hover { background: rgba(122, 162, 255, 0.05); }
.transcription-table td.empty { text-align: center; color: var(--text-dim); padding: 24px; }
.transcription-table a.open-btn {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
}
.transcription-table a.open-btn:hover { background: var(--accent-soft); }

.progress {
  width: 100%;
  height: 6px;
  background: var(--bg-soft);
  border-radius: 3px;
  overflow: hidden;
  margin: 6px 0;
}
.progress > div {
  height: 100%;
  background: linear-gradient(90deg, #3ddc84, #7aa2ff);
  transition: width 0.4s ease;
}

.status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  border: 1px solid currentColor;
}
.status-badge.received { color: var(--text-dim); }
.status-badge.queued { color: var(--warn); }
.status-badge.running { color: var(--running); }
.status-badge.completed { color: var(--ok); }
.status-badge.failed { color: var(--err); }
.status-badge.cancelled { color: var(--text-dim); }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
}
.card h3 { margin: 0 0 14px; font-size: 14px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.6px; }

.system-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
.system-grid .wide { grid-column: 1 / -1; }
.system-grid ul { list-style: none; padding: 0; margin: 0; }
.system-grid li { padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.system-grid li:last-child { border-bottom: none; }
.system-grid li.empty { color: var(--text-dim); }

/* ---------- Detail page ---------- */
.detail-page main { display: grid; gap: 20px; }
.detail-main {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 20px;
}
.detail-main .card { height: 100%; }
.detail-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; grid-column: 1 / -1; }
.detail-summary small { color: var(--text-dim); text-transform: uppercase; font-size: 10px; }
.detail-summary .status-pill { display: inline-block; margin-top: 6px; }
.detail-summary .progress { width: 100%; }

.detail-actions { display: flex; gap: 8px; margin-left: auto; }
.detail-actions button, .detail-actions a {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
}
.detail-actions a.primary {
  background: linear-gradient(135deg, #7aa2ff, #4f7bff);
  border-color: transparent;
  color: #0b1020;
  font-weight: 600;
}

.pipeline-card { grid-column: 1 / -1; }
.pipeline-canvas {
  position: relative;
  min-height: 240px;
  padding: 30px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  overflow-x: auto;
}
.pipeline-canvas .node {
  position: relative;
  min-width: 130px;
  padding: 16px 14px;
  border-radius: var(--radius-sm);
  background: var(--panel-soft);
  border: 2px solid var(--pending);
  text-align: center;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.3s ease;
  z-index: 2;
}
.pipeline-canvas .node:hover { transform: translateY(-2px); }
.pipeline-canvas .node.selected { box-shadow: 0 0 0 3px rgba(122, 162, 255, 0.5); }
.pipeline-canvas .node .title { font-size: 12px; font-weight: 600; }
.pipeline-canvas .node .meta { font-size: 10px; color: var(--text-dim); margin-top: 4px; }
.pipeline-canvas .node.pending { border-color: var(--pending); color: var(--text-dim); }
.pipeline-canvas .node.running {
  border-color: var(--running);
  color: var(--running);
  animation: pulse 1.4s infinite;
}
.pipeline-canvas .node.success { border-color: var(--success); color: var(--success); }
.pipeline-canvas .node.error { border-color: var(--error); color: var(--error); }
.pipeline-canvas .node.skipped { border-color: var(--skipped); color: var(--skipped); opacity: 0.6; }

.pipeline-canvas .connector {
  flex: 0 0 28px;
  height: 2px;
  background: var(--border);
  position: relative;
  z-index: 1;
}
.pipeline-canvas .connector.active {
  background: linear-gradient(90deg, var(--running), var(--success));
}
.pipeline-canvas .connector.done { background: var(--success); }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 var(--running-glow); }
  70% { box-shadow: 0 0 0 10px rgba(122, 162, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(122, 162, 255, 0); }
}

.step-details { min-height: 220px; }
.step-details pre {
  background: var(--bg-soft);
  padding: 12px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-size: 11px;
  color: var(--text-dim);
}
.step-details .empty { color: var(--text-dim); }

.logs-card { grid-column: 1 / -1; }
.logs-card pre {
  background: var(--bg-soft);
  padding: 14px;
  border-radius: var(--radius-sm);
  max-height: 260px;
  overflow-y: auto;
  font-size: 12px;
  color: #b8c4ef;
  white-space: pre-wrap;
  margin: 0;
}

@media (max-width: 900px) {
  .detail-main { grid-template-columns: 1fr; }
  .detail-summary { grid-template-columns: repeat(2, 1fr); }
  .pipeline-canvas { flex-direction: column; align-items: stretch; }
  .pipeline-canvas .connector {
    width: 2px;
    height: 20px;
    margin: 0 auto;
  }
  .topbar { flex-direction: column; align-items: flex-start; }
  .detail-actions { margin-left: 0; }
  main { padding: 16px; }
}
