:root {
  color-scheme: dark;
  --bg: #0c0e12;
  --bg-elevated: #13161d;
  --bg-hover: #1a1f2a;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.12);
  --text: #e8eaef;
  --text-muted: #8b93a7;
  --text-faint: #5c6478;
  --accent: #6ee7b7;
  --accent-dim: rgba(110, 231, 183, 0.12);
  --accent-glow: rgba(110, 231, 183, 0.25);
  --blue: #60a5fa;
  --amber: #fbbf24;
  --red: #f87171;
  --green: #4ade80;
  --radius: 8px;
  --radius-sm: 6px;
  --font: 'DM Sans', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.25);
  --topbar-h: 52px;
}

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

html {
  font-size: 13px;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.45;
  color: var(--text);
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(110, 231, 183, 0.08), transparent),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p {
  margin: 0;
}

button, input, select {
  font: inherit;
}

.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1rem 1.5rem;
}

/* ── Top bar ── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: var(--topbar-h);
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-mark {
  width: 28px;
  height: 28px;
  object-fit: contain;
  flex-shrink: 0;
}

.brand h1 {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand-sub {
  font-size: 0.85rem;
  color: var(--text-faint);
  margin-top: 1px;
}

.service-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.service-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}

.service-pill.ok .service-dot {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

.service-pill.ok {
  color: var(--text-muted);
  border-color: rgba(74, 222, 128, 0.2);
}

.service-pill.error .service-dot {
  background: var(--red);
  box-shadow: 0 0 6px var(--red);
}

.service-pill.error {
  color: #fca5a5;
  border-color: rgba(248, 113, 113, 0.25);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ── Auth gate ── */

.auth-gate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  padding: 1.75rem;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  text-align: center;
}

.auth-brand h1 {
  font-size: 1.35rem;
  font-weight: 600;
}

.auth-hint {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.auth-error {
  color: #fca5a5;
}

/* ── Layout ── */

.layout {
  display: grid;
  gap: 0.75rem;
}

@media (min-width: 920px) {
  .layout {
    grid-template-columns: 280px 1fr;
    align-items: start;
  }
}

.main {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
}

/* ── Panels ── */

.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel-head {
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--border);
}

.panel-head h2 {
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.panel-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.panel-submit {
  position: sticky;
  top: 0.5rem;
}

/* ── Form ── */

.compact-form {
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.field-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field-group-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0.35rem 0 0;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.field-row-4 {
  grid-template-columns: 1fr 1fr;
}

@media (min-width: 920px) {
  .field-row-4 {
    grid-template-columns: 1fr 1fr;
  }
}

.field-check {
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.92rem;
  color: var(--text-muted);
  cursor: pointer;
}

.field-check input {
  width: auto;
  margin: 0;
}

input[type='text'],
input[type='number'],
input[type='file'],
select {
  width: 100%;
  padding: 0.4rem 0.55rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus {
  border-color: rgba(110, 231, 183, 0.45);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

input[type='file'] {
  padding: 0.35rem;
  font-size: 0.85rem;
}

input[type='file']::file-selector-button {
  padding: 0.25rem 0.5rem;
  margin-right: 0.5rem;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--bg-hover);
  color: var(--text-muted);
  font-size: 0.82rem;
  cursor: pointer;
}

.input-row {
  display: flex;
  gap: 0.35rem;
}

.input-row input {
  flex: 1;
  min-width: 0;
}

.advanced {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.advanced summary {
  padding: 0.4rem 0.55rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  list-style: none;
}

.advanced summary::-webkit-details-marker {
  display: none;
}

.advanced summary::before {
  content: '▸ ';
  font-size: 0.75rem;
  color: var(--text-faint);
}

.advanced[open] summary::before {
  content: '▾ ';
}

.advanced-body {
  padding: 0.55rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: rgba(0, 0, 0, 0.15);
}

.form-note {
  font-size: 0.85rem;
  margin: 0;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius-sm);
}

.form-note.success {
  color: var(--accent);
  background: var(--accent-dim);
}

.form-note.error {
  color: #fca5a5;
  background: rgba(248, 113, 113, 0.1);
}

/* ── Buttons ── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.92rem;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: linear-gradient(180deg, #6ee7b7 0%, #34d399 100%);
  color: #052e1a;
  border-color: rgba(110, 231, 183, 0.3);
}

.btn-primary:hover {
  filter: brightness(1.06);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.btn-sm {
  padding: 0.25rem 0.55rem;
  font-size: 0.82rem;
}

.btn-block {
  width: 100%;
  margin-top: 0.25rem;
}

/* ── Queue ── */

.panel-queue {
  overflow: hidden;
}

.queue-grid {
  display: grid;
  gap: 0;
}

@media (min-width: 640px) {
  .queue-grid {
    grid-template-columns: 1fr 1fr;
  }

  .queue-col-wide {
    grid-column: 1 / -1;
    border-top: 1px solid var(--border);
  }
}

.queue-col {
  padding: 0.65rem 0.75rem;
  min-height: 4.5rem;
}

@media (min-width: 640px) {
  .queue-col:first-child {
    border-right: 1px solid var(--border);
  }
}

.queue-title {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin-bottom: 0.5rem;
}

.queue-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.queue-dot.running {
  background: var(--amber);
  box-shadow: 0 0 8px rgba(251, 191, 36, 0.5);
}

.queue-dot.queued {
  background: var(--blue);
  box-shadow: 0 0 8px rgba(96, 165, 250, 0.35);
}

.queue-dot.recent {
  background: var(--green);
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.35);
}

.job-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.job-list-compact {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.35rem;
}

.job-row {
  width: 100%;
  text-align: left;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.job-row:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.job-row:focus-visible {
  outline: 2px solid var(--accent-dim);
  outline-offset: 1px;
}

.job-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.job-row-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.btn-cancel {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  padding: 0;
  border: 1px solid rgba(248, 113, 113, 0.35);
  border-radius: 4px;
  background: rgba(248, 113, 113, 0.1);
  color: var(--red);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-cancel:hover {
  background: rgba(248, 113, 113, 0.22);
  border-color: rgba(248, 113, 113, 0.55);
}

.job-title-wrap {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  min-width: 0;
  flex: 1;
}

.job-row .job-title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.job-row .job-id {
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
  flex-shrink: 0;
}

.job-title-wrap .job-id {
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--text-faint);
}

.job-row .job-meta {
  font-size: 0.78rem;
  color: var(--text-faint);
  margin-top: 0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.job-row .job-progress {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--amber);
  margin-top: 0.3rem;
  line-height: 1.35;
}

.job-row.status-processing {
  border-left: 2px solid var(--amber);
}

.job-row.status-pending {
  border-left: 2px solid var(--blue);
}

.job-row.status-done {
  border-left: 2px solid var(--green);
}

.job-row.status-failed {
  border-left: 2px solid var(--red);
}

.job-row.status-cancelled {
  border-left: 2px solid var(--text-faint);
  opacity: 0.85;
}

.empty-note {
  font-size: 0.82rem;
  color: var(--text-faint);
  font-style: italic;
  margin: 0;
}

.empty-note[hidden] {
  display: none;
}

/* ── Status badges ── */

.badge {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.badge.pending {
  background: rgba(96, 165, 250, 0.15);
  color: var(--blue);
}

.badge.processing {
  background: rgba(251, 191, 36, 0.15);
  color: var(--amber);
}

.badge.done {
  background: rgba(74, 222, 128, 0.15);
  color: var(--green);
}

.badge.failed {
  background: rgba(248, 113, 113, 0.15);
  color: var(--red);
}

.badge.cancelled {
  background: rgba(139, 147, 167, 0.15);
  color: var(--text-muted);
}

/* ── Detail panel ── */

.panel-detail {
  animation: slideIn 0.2s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.detail-body {
  padding: 0.75rem;
}

.detail-meta {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  line-height: 1.5;
}

.detail-meta code {
  font-family: var(--mono);
  font-size: 0.78rem;
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--accent);
}

.detail-meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.65rem;
}

.detail-meta-row .btn {
  margin-left: auto;
}

#detail-heading {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-line {
  font-family: var(--mono);
  font-size: 0.78rem;
  padding: 0.45rem 0.6rem;
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.15);
  border-radius: var(--radius-sm);
  color: var(--amber);
  margin-bottom: 0.75rem;
}

.detail-section-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin: 0.85rem 0 0.45rem;
}

.detail-section-title:first-child {
  margin-top: 0;
}

.stage-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.stage-table th,
.stage-table td {
  padding: 0.35rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.stage-table th {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
}

.stage-table td:last-child {
  font-family: var(--mono);
  color: var(--text-muted);
}

.stage-table tfoot .stage-total td {
  border-top: 1px solid var(--border-strong);
  border-bottom: none;
  font-weight: 600;
  color: var(--text);
}

.stage-table tfoot .stage-total td:last-child {
  color: var(--accent);
}

.dialogue-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.dialogue-item {
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
}

.dialogue-head {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.dialogue-speaker {
  font-size: 0.82rem;
  font-weight: 600;
}

.dialogue-time {
  font-size: 0.72rem;
  color: var(--text-faint);
  font-family: var(--mono);
}

.dialogue-text {
  margin: 0.35rem 0 0;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
}

.diagnostics-summary {
  font-size: 0.82rem;
  color: var(--text-muted);
  padding: 0.45rem 0.6rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  line-height: 1.45;
}

.error-panel {
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius-sm);
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.25);
  color: #fca5a5;
  font-size: 0.88rem;
  margin-bottom: 0.75rem;
}

.debug-block {
  margin-top: 0.45rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.debug-block summary {
  padding: 0.4rem 0.55rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
  background: var(--bg);
  user-select: none;
}

.debug-block-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.debug-block-summary .btn-copy-json {
  flex-shrink: 0;
}

.btn-copy-json.copied {
  color: var(--accent);
  border-color: rgba(110, 231, 183, 0.35);
}

.debug-block pre {
  margin: 0;
  padding: 0.55rem;
  max-height: 18rem;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.45;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text-muted);
}

.empty-inline {
  font-size: 0.82rem;
  color: var(--text-faint);
  font-style: italic;
}
