:root {
  --paper: #f2f5f3;
  --surface: #ffffff;
  --ink: #101923;
  --muted: #66727f;
  --line: #d7dfdf;
  --teal: #07847d;
  --teal-dark: #05645f;
  --cyan: #19d4c8;
  --blue: #2d5be3;
  --amber: #c67a13;
  --red: #ba3b42;
  --shadow: 0 18px 48px rgba(20, 39, 48, 0.08);
  font-family: "IBM Plex Sans", "Noto Sans SC", "PingFang SC", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    linear-gradient(rgba(16, 25, 35, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(16, 25, 35, 0.025) 1px, transparent 1px),
    var(--paper);
  background-size: 24px 24px;
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }

:focus-visible {
  outline: 3px solid rgba(45, 91, 227, 0.25);
  outline-offset: 2px;
}

.app-header {
  min-height: 104px;
  padding: 22px clamp(22px, 3vw, 48px) 17px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
}

.eyebrow, .section-kicker {
  margin: 0 0 5px;
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--teal-dark);
}

h1, h2 { margin: 0; letter-spacing: -0.03em; }
h1 { font-size: clamp(27px, 2.6vw, 40px); line-height: 1; font-weight: 760; }
h2 { font-size: 20px; line-height: 1.2; }

.system-state {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 4px rgba(198, 122, 19, 0.12);
}
.pulse-dot.online { background: var(--teal); box-shadow: 0 0 0 4px rgba(7, 132, 125, 0.12); }
.pulse-dot.error { background: var(--red); box-shadow: 0 0 0 4px rgba(186, 59, 66, 0.12); }

.signal-tape {
  height: 7px;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  background: var(--ink);
  overflow: hidden;
}
.signal-tape span:nth-child(3n + 1) { background: var(--cyan); }
.signal-tape span:nth-child(4n + 2) { background: var(--teal); }

.workspace {
  width: min(1680px, 100%);
  margin: 0 auto;
  padding: 22px;
  display: grid;
  grid-template-columns: minmax(330px, 410px) minmax(0, 1fr);
  gap: 20px;
  min-height: calc(100vh - 111px);
}

.panel {
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.intake-panel {
  align-self: start;
  padding: 22px;
  position: sticky;
  top: 18px;
  max-height: calc(100vh - 40px);
  overflow: auto;
}

.panel-heading, .overview-topline, .results-toolbar, .recent-heading, .pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.count-chip {
  padding: 6px 9px;
  border-radius: 8px;
  background: #e6f3f1;
  color: var(--teal-dark);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  font-weight: 700;
}

.field-label {
  display: block;
  margin: 18px 0 7px;
  font-size: 12px;
  font-weight: 700;
  color: #3e4b57;
}

.text-input, textarea, .compact-input {
  width: 100%;
  border: 1px solid #c9d3d4;
  background: #fbfdfc;
  color: var(--ink);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.text-input { height: 42px; padding: 0 12px; border-radius: 10px; }
textarea {
  resize: vertical;
  min-height: 220px;
  padding: 13px;
  border-radius: 12px;
  font: 13px/1.6 "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
}
.text-input:focus, textarea:focus, .compact-input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(7, 132, 125, 0.1);
  outline: none;
}

.input-audit {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  margin: 10px 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--line);
}
.input-audit span { padding: 9px 7px; background: #f8faf9; color: var(--muted); font-size: 11px; text-align: center; }
.input-audit b { display: block; margin-bottom: 2px; color: var(--ink); font: 700 15px "IBM Plex Mono", monospace; }

.primary-button, .secondary-button, .page-button, .action-button {
  border: 0;
  border-radius: 10px;
  font-weight: 720;
  transition: transform 120ms ease, background 120ms ease;
}
.primary-button {
  width: 100%;
  min-height: 48px;
  padding: 0 14px 0 17px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--ink);
  color: white;
  box-shadow: 4px 4px 0 var(--cyan);
}
.primary-button:hover:not(:disabled) { transform: translate(-1px, -1px); }
.button-arrow { color: var(--cyan); font-size: 18px; }
.field-help { margin: 12px 1px 0; color: var(--muted); font-size: 11px; line-height: 1.5; }

.recent-heading { margin: 24px 0 9px; padding-top: 17px; border-top: 1px solid var(--line); font-size: 12px; font-weight: 750; }
.text-button { padding: 4px; border: 0; background: none; color: var(--teal-dark); font-size: 11px; font-weight: 700; }
.run-list { display: grid; gap: 7px; }
.run-card {
  width: 100%;
  padding: 11px 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: white;
  color: var(--ink);
}
.run-card:hover, .run-card.active { border-color: var(--teal); background: #f1faf8; }
.run-card strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.run-card small { color: var(--muted); font-size: 10px; }
.run-card .status-badge { grid-row: span 2; align-self: center; }

.operations-panel { min-width: 0; display: grid; grid-template-rows: auto minmax(480px, 1fr); gap: 20px; }
.overview { padding: 22px 24px 20px; }
.overview-topline { align-items: flex-start; }
.muted { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.run-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.action-button, .secondary-button, .page-button {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid #cbd5d6;
  background: white;
  color: #33404b;
  font-size: 11px;
}
.action-button:hover:not(:disabled), .secondary-button:hover:not(:disabled), .page-button:hover:not(:disabled) { border-color: var(--teal); color: var(--teal-dark); }
.action-button.danger { color: var(--red); }

.progress-track { height: 8px; margin: 22px 0 16px; overflow: hidden; border-radius: 999px; background: #e5ebea; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--teal); transition: width 350ms ease; }
.metric-strip { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.metric-strip div { min-width: 0; padding: 11px 13px; background: #fbfdfc; }
.metric-strip span { display: block; color: var(--muted); font-size: 10px; }
.metric-strip strong { display: block; margin-top: 3px; font: 720 19px "IBM Plex Mono", monospace; font-variant-numeric: tabular-nums; }
.notice { margin-top: 12px; padding: 10px 12px; border: 1px solid #ead3aa; border-radius: 9px; background: #fff8eb; color: #81510e; font-size: 11px; }

.results { min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden; }
.results-toolbar { padding: 19px 22px 14px; border-bottom: 1px solid var(--line); }
.filter-bar { display: flex; gap: 8px; align-items: center; }
.compact-input { width: auto; min-width: 130px; height: 34px; padding: 0 9px; border-radius: 8px; font-size: 11px; }
.table-shell { min-width: 0; min-height: 0; overflow: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 11px; }
th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 10px 12px;
  background: #f4f7f6;
  border-bottom: 1px solid var(--line);
  color: #5c6873;
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: left;
}
td { padding: 11px 12px; border-bottom: 1px solid #e8eded; vertical-align: middle; }
tbody tr:hover td { background: #f8fbfa; }
.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.video-cell { max-width: 250px; }
.video-cell a, .video-cell strong { display: block; overflow: hidden; color: var(--ink); font: 700 11px "IBM Plex Mono", monospace; text-overflow: ellipsis; white-space: nowrap; text-decoration: none; }
.video-cell a:hover { color: var(--teal-dark); text-decoration: underline; }
.video-cell small { display: block; margin-top: 3px; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.status-badge { display: inline-flex; align-items: center; min-height: 22px; padding: 0 7px; border-radius: 999px; background: #eef1f1; color: #59646e; font: 700 9px "IBM Plex Mono", monospace; text-transform: uppercase; }
.status-badge.completed { background: #e1f5ef; color: #067066; }
.status-badge.processing, .status-badge.running { background: #e6edff; color: #234ebf; }
.status-badge.retrying, .status-badge.queued { background: #fff3dc; color: #995d0d; }
.status-badge.failed, .status-badge.partial { background: #ffe8e9; color: #a42b33; }
.status-badge.unavailable, .status-badge.paused { background: #f2eafa; color: #6d3b93; }
.error-detail { max-width: 220px; color: var(--red); font-size: 9px; }
.empty-row td { height: 180px; text-align: center; color: var(--muted); }
.pagination { padding: 11px 15px; border-top: 1px solid var(--line); color: var(--muted); font: 10px "IBM Plex Mono", monospace; }
.pagination div { display: flex; gap: 6px; }

.gate { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 20px; background: rgba(12, 20, 28, 0.72); backdrop-filter: blur(8px); }
.gate-card { width: min(420px, 100%); padding: 30px; border-radius: 18px; background: white; box-shadow: 0 24px 90px rgba(0, 0, 0, 0.28); }
.gate-card h2 { font-size: 25px; }
.gate-card p:not(.section-kicker) { margin: 10px 0 20px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.gate-card .primary-button { margin-top: 14px; }
.error-text { color: var(--red) !important; }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 20; max-width: 380px; padding: 12px 15px; border-radius: 10px; background: var(--ink); color: white; box-shadow: var(--shadow); font-size: 12px; opacity: 0; transform: translateY(8px); pointer-events: none; transition: 160ms ease; }
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--red); }

@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
  .intake-panel { position: static; max-height: none; }
  .operations-panel { grid-template-rows: auto minmax(600px, 1fr); }
}

@media (max-width: 680px) {
  .app-header { align-items: flex-start; flex-direction: column; }
  .workspace { padding: 12px; }
  .panel { border-radius: 13px; }
  .overview-topline, .results-toolbar { align-items: stretch; flex-direction: column; }
  .run-actions, .filter-bar { justify-content: flex-start; }
  .filter-bar { flex-wrap: wrap; }
  .compact-input { flex: 1 1 120px; }
  .metric-strip { grid-template-columns: repeat(2, 1fr); }
  .metric-strip div:last-child { grid-column: span 2; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
