/* QueueFlow dashboard. One stylesheet, no build step.
   Colors are tokens on :root and redefined for dark mode. */

:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eceef2;
  --ink: #1a1d23;
  --muted: #626b78;
  --rule: #dce0e6;
  --rule-soft: #e9ecf0;
  --accent: #0e6b70;
  --on-accent: #ffffff;
  --accent-soft: #d8ecec;
  --focus: #0e6b70;
  --danger: #b4232c;
  --danger-soft: #f8e3e4;

  --st-pending: #4a5f8a;
  --st-pending-soft: #e4e9f3;
  --st-created: #4a5f8a;
  --st-created-soft: #e4e9f3;
  --st-scheduled: #6b4fb6;
  --st-scheduled-soft: #ebe5f7;
  --st-running: #0e6b70;
  --st-running-soft: #d8ecec;
  --st-retrying: #9a6400;
  --st-retrying-soft: #f6ead0;
  --st-completed: #2e7d4f;
  --st-completed-soft: #dcefe3;
  --st-failed: #b4232c;
  --st-failed-soft: #f8e3e4;
  --st-partially_failed: #b3551c;
  --st-partially_failed-soft: #f8e6da;
  --st-cancelled: #6b7280;
  --st-cancelled-soft: #e8eaee;
  --st-skipped: #6b7280;
  --st-skipped-soft: #e8eaee;

  --sans: "Avenir Next", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "SF Mono", "Cascadia Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 4px;
  --gutter: 16px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171c;
    --surface: #1b1f26;
    --surface-2: #232831;
    --ink: #e4e7ec;
    --muted: #8a93a2;
    --rule: #2a3039;
    --rule-soft: #222831;
    --accent: #5cc0c4;
    --on-accent: #0f1a1b;
    --accent-soft: #163538;
    --focus: #7fd3d6;
    --danger: #f0737a;
    --danger-soft: #3a1e21;

    --st-pending: #93a6d1;
    --st-pending-soft: #222c3f;
    --st-created: #93a6d1;
    --st-created-soft: #222c3f;
    --st-scheduled: #a994e6;
    --st-scheduled-soft: #2a2340;
    --st-running: #5cc0c4;
    --st-running-soft: #163538;
    --st-retrying: #e0a528;
    --st-retrying-soft: #3a2e12;
    --st-completed: #63c08a;
    --st-completed-soft: #173424;
    --st-failed: #f0737a;
    --st-failed-soft: #3a1e21;
    --st-partially_failed: #ee9565;
    --st-partially_failed-soft: #3a2619;
    --st-cancelled: #9aa3b2;
    --st-cancelled-soft: #262b33;
    --st-skipped: #9aa3b2;
    --st-skipped-soft: #262b33;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

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

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

code, pre, .mono, time {
  font-family: var(--mono);
  font-size: 12.5px;
}

time { font-variant-numeric: tabular-nums; }

.skip {
  position: absolute;
  left: -999px;
  top: 8px;
  background: var(--surface);
  padding: 6px 10px;
  border: 1px solid var(--rule);
  z-index: 10;
}
.skip:focus { left: 8px; }

/* Top bar ------------------------------------------------------------ */

.top {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 var(--gutter);
  height: 48px;
  border-bottom: 1px solid var(--rule);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  color: var(--ink);
  font-weight: 600;
  letter-spacing: -0.01em;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: none;
}
.brand:hover { text-decoration: none; }
.brand svg { width: 16px; height: 16px; display: block; }

.top nav {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  flex: 1;
  height: 100%;
  min-width: 0;
  /* Scrollable on narrow screens, but never show a scrollbar: on macOS with
     "always show scroll bars" the bar rendered inside the 48px bar. */
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.top nav::-webkit-scrollbar { display: none; }
.top nav a {
  color: var(--muted);
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  height: 100%;
}
.top nav a:hover { color: var(--ink); text-decoration: none; }
.top nav a[aria-current="page"] {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

.top-right {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12.5px;
  flex: none;
}

button.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
button.link:hover { text-decoration: underline; }

/* Layout ---------------------------------------------------------------- */

main {
  max-width: 1180px;
  padding: 20px var(--gutter) 48px;
  margin: 0 auto;
}
main:focus { outline: none; }

.view-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin: 0 0 16px;
}
.view-head h1 {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}
.view-head .meta {
  color: var(--muted);
  font-size: 12.5px;
  display: flex;
  align-items: center;
  gap: 12px;
}

h2 {
  font-size: 14px;
  font-weight: 600;
  margin: 28px 0 8px;
}
h2:first-child { margin-top: 0; }

.note { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }

.crumbs { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }

/* Panels and tables ------------------------------------------------------ */

.panel {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
th, td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--rule-soft);
  vertical-align: top;
  white-space: nowrap;
}
th {
  font-weight: 500;
  color: var(--muted);
  font-size: 12.5px;
  background: var(--surface);
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; }
td.wrap { white-space: normal; }
td.trunc {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}
td a.id, a.id { font-family: var(--mono); font-size: 12.5px; }

.zero { color: var(--muted); }

/* Status ----------------------------------------------------------------- */

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 1px 8px 1px 6px;
  border-radius: 999px;
  font-size: 12.5px;
  line-height: 18px;
  color: var(--st-color, var(--muted));
  background: var(--st-soft, var(--surface-2));
  white-space: nowrap;
}
.status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.status[data-status="skipped"]::before,
.status[data-status="cancelled"]::before {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px currentColor;
}
.status[data-status="running"]::before { animation: pulse 1.6s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}
@media (prefers-reduced-motion: reduce) {
  .status[data-status="running"]::before { animation: none; }
}

[data-status="pending"]  { --st-color: var(--st-pending);  --st-soft: var(--st-pending-soft); }
[data-status="created"]  { --st-color: var(--st-created);  --st-soft: var(--st-created-soft); }
[data-status="scheduled"]{ --st-color: var(--st-scheduled);--st-soft: var(--st-scheduled-soft); }
[data-status="running"]  { --st-color: var(--st-running);  --st-soft: var(--st-running-soft); }
[data-status="retrying"] { --st-color: var(--st-retrying); --st-soft: var(--st-retrying-soft); }
[data-status="completed"]{ --st-color: var(--st-completed);--st-soft: var(--st-completed-soft); }
[data-status="failed"]   { --st-color: var(--st-failed);   --st-soft: var(--st-failed-soft); }
[data-status="partially_failed"] { --st-color: var(--st-partially_failed); --st-soft: var(--st-partially_failed-soft); }
[data-status="cancelled"]{ --st-color: var(--st-cancelled);--st-soft: var(--st-cancelled-soft); }
[data-status="skipped"]  { --st-color: var(--st-skipped);  --st-soft: var(--st-skipped-soft); }

/* Age bar on the overview */

.age {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 160px;
}
.age .bar {
  height: 6px;
  width: 96px;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
  flex: none;
}
.age .bar i {
  display: block;
  height: 100%;
  background: var(--st-pending);
  border-radius: 3px;
}
.age.hot .bar i { background: var(--st-retrying); }
.age.critical .bar i { background: var(--st-failed); }

/* Totals ledger */

.ledger {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
.ledger > div {
  padding: 10px 14px;
  border-right: 1px solid var(--rule-soft);
  border-bottom: 1px solid var(--rule-soft);
}
.ledger .n {
  font-size: 20px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  display: block;
}
.ledger .l { color: var(--muted); font-size: 12.5px; }

/* Live indicator */

.live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
}
.live::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.live[data-on="true"]::before {
  background: var(--accent);
  animation: pulse 1.6s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) {
  .live[data-on="true"]::before { animation: none; }
}

/* Forms ------------------------------------------------------------------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: end;
  margin-bottom: 12px;
}
.filters label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12.5px;
  color: var(--muted);
}

input, select, button {
  font: inherit;
  color: var(--ink);
}
input[type="text"], input[type="password"], input[type="datetime-local"], select {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 5px 8px;
  min-height: 32px;
  min-width: 140px;
}
input[type="datetime-local"] { font-family: var(--mono); font-size: 12.5px; }

.btn {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 5px 12px;
  min-height: 32px;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.5; cursor: default; }

.pager {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12.5px;
}

/* Detail pages ------------------------------------------------------------ */

.detail {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 860px) {
  .detail { grid-template-columns: 1fr; }
}

dl.facts {
  margin: 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0;
}
dl.facts dt, dl.facts dd {
  padding: 7px 12px;
  margin: 0;
  border-bottom: 1px solid var(--rule-soft);
}
dl.facts dt { color: var(--muted); white-space: nowrap; }
dl.facts dd { overflow-wrap: anywhere; }
dl.facts dt:last-of-type, dl.facts dd:last-of-type { border-bottom: 0; }

pre.json {
  margin: 0;
  padding: 12px;
  overflow: auto;
  max-height: 420px;
  line-height: 1.5;
  white-space: pre;
  tab-size: 2;
}
pre.err {
  margin: 0;
  padding: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--danger);
  background: var(--danger-soft);
  border-color: var(--danger);
}

.stack > * + * { margin-top: 16px; }

.title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.title-row h1 { margin: 0; }
.title-row .mono { color: var(--muted); }

/* Diagram ----------------------------------------------------------------- */

.diagram {
  padding: 16px;
  overflow: auto;
  min-height: 120px;
}
.diagram svg { height: auto; }
.legend {
  display: flex;
  gap: 8px 14px;
  flex-wrap: wrap;
  padding: 8px 12px;
  border-top: 1px solid var(--rule-soft);
}

/* States ------------------------------------------------------------------ */

.state {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
}
.state strong { color: var(--ink); font-weight: 500; display: block; margin-bottom: 4px; }
.state.error { color: var(--danger); }
.state.error strong { color: var(--danger); }
.state .btn { margin-top: 10px; }

.inline-error {
  color: var(--danger);
  font-size: 12.5px;
  margin-top: 6px;
}

/* Token gate --------------------------------------------------------------- */

#gate {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--gutter);
  z-index: 20;
}
#gate[hidden] { display: none; }
.gate-card {
  width: 100%;
  max-width: 420px;
  padding: 24px;
}
.gate-card h1 {
  font-size: 18px;
  margin: 0 0 4px;
  font-weight: 600;
}
.gate-card p { margin: 8px 0 0; color: var(--muted); line-height: 1.5; }
.gate-card form { margin-top: 16px; display: grid; gap: 10px; }
.gate-card label { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
.gate-card input { width: 100%; font-family: var(--mono); }
.gate-card .row { display: flex; gap: 10px; align-items: center; }
.gate-card .msg { color: var(--danger); min-height: 1.4em; font-size: 12.5px; }
.gate-card .fine { font-size: 12px; margin-top: 14px; }

@media (max-width: 640px) {
  .top { gap: 12px; }
  .top-right span.hide-sm { display: none; }
  th, td { padding: 7px 8px; }
  .age { min-width: 120px; }
  .age .bar { width: 60px; }
}

/* Actions ----------------------------------------------------------------- */

.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn.danger { border-color: var(--st-failed); color: var(--st-failed); }
.btn.danger:hover { background: var(--st-failed-soft); }
.btn.small { padding: 2px 9px; min-height: 26px; font-size: 12.5px; }

dialog#confirm {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 20px 22px;
  max-width: 440px;
  width: calc(100% - 32px);
}
dialog#confirm::backdrop { background: rgba(10, 12, 16, 0.45); }
dialog#confirm h2 { margin: 0 0 8px; font-size: 16px; }
dialog#confirm p { margin: 0 0 16px; color: var(--muted); line-height: 1.5; }
dialog#confirm .row { display: flex; gap: 10px; }

#flash {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--surface);
  padding: 9px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  z-index: 20;
  max-width: calc(100% - 32px);
}
#flash[data-kind="error"] { background: var(--st-failed); color: #fff; }
