/* Rex admin. Tokens for light and dark; data colours from a colour-blind-checked categorical palette. */
:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --surface-3: #e8ebf0;
  --border: #e3e6eb;
  --border-strong: #cfd4dc;
  --text: #101828;
  --text-2: #475467;
  --text-3: #8a93a3;
  --brand: #e2462f;
  --primary: #101828;
  --primary-ink: #ffffff;
  --focus: #257de0;
  --good: #067647;
  --good-bg: #ecfdf3;
  --bad: #b42318;
  --bad-bg: #fef3f2;
  --warn: #b54708;
  --warn-bg: #fffaeb;
  --series-1: #257de0;
  --series-2: #f47230;
  --series-3: #00b894;
  --series-4: #f2a600;
  --series-5: #ee7fac;
  --series-6: #008a17;
  --series-other: #98a2b3;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.05);
  --radius: 12px;
  --side: 248px;
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-feature-settings: 'cv11', 'tnum';
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #0b0c0f;
    --surface: #14161b;
    --surface-2: #1b1e25;
    --surface-3: #242832;
    --border: #252a33;
    --border-strong: #353b47;
    --text: #f2f4f7;
    --text-2: #a4acba;
    --text-3: #6c7586;
    --brand: #ff6a52;
    --primary: #f2f4f7;
    --primary-ink: #0b0c0f;
    --focus: #338ced;
    --good: #47cd89;
    --good-bg: #0d2a1c;
    --bad: #f97066;
    --bad-bg: #3a1512;
    --warn: #fdb022;
    --warn-bg: #33240a;
    --series-1: #338ced;
    --series-2: #e76624;
    --series-3: #00a888;
    --series-4: #d28e05;
    --series-5: #e24d8b;
    --series-6: #0aac23;
    --series-other: #6c7586;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
a { color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
p { margin: 0; }
code, .mono { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 12.5px; }
.muted { color: var(--text-2); }
.hint { color: var(--text-3); font-size: 12.5px; margin-top: 4px; }
.empty { color: var(--text-3); padding: 18px 0; text-align: center; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); min-height: 100vh; }
.shell.bare { grid-template-columns: 1fr; }
.shell.bare .side, .shell.bare .topbar { display: none; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--border); padding: 18px 12px; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; padding: 2px 8px 20px; font-weight: 700; font-size: 17px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 15px; }
.brand small { font-weight: 500; color: var(--text-3); font-size: 13px; }
.nav-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); padding: 16px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; text-decoration: none; color: var(--text-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current='page'] { background: var(--surface-2); color: var(--text); font-weight: 600; }
.nav a span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav svg { width: 17px; height: 17px; flex: none; }
.nav .dot-state { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; margin: 0 4.5px; }
.nav .dot-state.good { background: var(--good); }
.nav .dot-state.bad { background: var(--bad); }
.side-foot { margin-top: auto; padding-top: 16px; display: grid; gap: 4px; }
.side-foot button { justify-content: flex-start; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 28px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; min-height: 58px; }
.crumbs { display: flex; align-items: center; gap: 8px; color: var(--text-3); font-weight: 500; min-width: 0; }
.crumbs a { text-decoration: none; color: var(--text-2); }
.crumbs b { color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.updated { color: var(--text-3); font-size: 12.5px; white-space: nowrap; }
.menu-button { display: none; }
#app { padding: 24px 28px 64px; max-width: 1400px; width: 100%; }

/* ---------- controls ---------- */
button, .button { font: inherit; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; box-shadow: var(--shadow); white-space: nowrap; }
button:hover, .button:hover { background: var(--surface-2); }
button:disabled { opacity: 0.55; cursor: default; }
button.primary, .button.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
button.primary:hover, .button.primary:hover { opacity: 0.9; background: var(--primary); }
button.danger { color: var(--bad); }
button.small { padding: 4px 9px; font-size: 13px; }
button.ghost { border-color: transparent; box-shadow: none; background: transparent; color: var(--text-2); }
button.ghost:hover { background: var(--surface-2); color: var(--text); }
button svg { width: 16px; height: 16px; }
.segment { display: inline-flex; padding: 3px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--border); }
.segment button { border: 0; box-shadow: none; background: transparent; padding: 4px 11px; font-size: 13px; color: var(--text-2); border-radius: 6px; }
.segment button[aria-pressed='true'] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(16 24 40 / 0.1); font-weight: 600; }
label { display: block; font-weight: 500; font-size: 13px; margin-bottom: 5px; }
input, select, textarea { font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); color: var(--text); }
textarea { min-height: 110px; resize: vertical; font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 12.5px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin-bottom: 16px; }
.fields .full { grid-column: 1 / -1; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
fieldset.source { border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin: 0 0 16px; }
fieldset.source legend { padding: 0 6px; font-weight: 600; }

/* ---------- page parts ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .sub { color: var(--text-2); margin-top: 6px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.plain::before { display: none; }
.pill.good { color: var(--good); background: var(--good-bg); border-color: transparent; }
.pill.bad { color: var(--bad); background: var(--bad-bg); border-color: transparent; }
.pill.warn { color: var(--warn); background: var(--warn-bg); border-color: transparent; }
.pill.running { color: var(--focus); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 0 0 22px; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 9px 12px; text-decoration: none; color: var(--text-2); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); }
.tabs a[aria-current='page'] { color: var(--text); border-bottom-color: var(--text); font-weight: 600; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head p { color: var(--text-3); font-size: 12.5px; margin-top: 2px; }
.layout { display: grid; gap: 16px; margin-bottom: 16px; }
.layout.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.layout.wide-left { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack > * + * { margin-top: 16px; }
.notice { padding: 10px 14px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--border); margin-bottom: 14px; color: var(--text-2); }
.notice.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.notice.good { background: var(--good-bg); color: var(--good); border-color: transparent; }
.secret { border: 1px solid var(--warn); background: var(--warn-bg); border-radius: 10px; padding: 14px 16px; margin-bottom: 16px; display: grid; gap: 8px; }
.secret code { font-size: 14px; word-break: break-all; color: var(--text); }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius); min-height: 112px; }
.skeleton.tall { min-height: 300px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -20px -18px; }
.card-head + .table-wrap, .table-wrap.flush-top { margin-top: 0; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th { text-align: left; font-size: 12px; font-weight: 500; color: var(--text-3); padding: 8px 12px; border-bottom: 1px solid var(--border); border-top: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
th:first-child, td:first-child { padding-left: 20px; }
th:last-child, td:last-child { padding-right: 20px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.link { cursor: pointer; }
tr.link:hover td { background: var(--surface-2); }
.cell-bar { display: flex; align-items: center; gap: 10px; justify-content: flex-end; }
.cell-bar .track { width: 90px; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 12px; box-shadow: var(--shadow); min-height: 112px; overflow: hidden; }
.stat-label { color: var(--text-2); font-size: 12.5px; font-weight: 500; padding-right: 88px; }
.stat-value { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; margin: 6px 0 4px; font-variant-numeric: tabular-nums; }
.stat-foot { display: flex; gap: 8px; align-items: center; font-size: 12px; flex-wrap: wrap; }
.stat-sub { color: var(--text-3); }
.stat .spark { position: absolute; right: 12px; top: 14px; width: 84px; height: 30px; }
.delta { font-weight: 600; padding: 1px 6px; border-radius: 6px; font-size: 11.5px; }
.delta.good { color: var(--good); background: var(--good-bg); }
.delta.bad { color: var(--bad); background: var(--bad-bg); }
.delta.flat { color: var(--text-2); background: var(--surface-2); }

/* ---------- charts ---------- */
.chart { position: relative; }
.plot { position: relative; min-height: 120px; }
.plot svg { display: block; overflow: visible; }
svg .grid { stroke: var(--border); stroke-width: 1; }
svg .axis { fill: var(--text-3); font-size: 11px; font-variant-numeric: tabular-nums; }
svg .line { fill: none; stroke: var(--c); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg .area { fill: var(--c); opacity: 0.1; stroke: none; }
svg .dot { fill: var(--c); stroke: var(--surface); stroke-width: 2; }
svg .dot.small { stroke-width: 1.5; }
svg .cross { stroke: var(--text-3); stroke-width: 1; }
svg .hit { fill: transparent; cursor: crosshair; }
.legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: 12.5px; color: var(--text-2); margin-bottom: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--c); flex: none; }
.key.line { height: 3px; width: 14px; border-radius: 2px; }
.tip { position: absolute; z-index: 20; pointer-events: none; background: var(--text); color: var(--bg); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 6px 20px rgb(0 0 0 / 0.2); min-width: 140px; }
.tip-title { font-weight: 600; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.tip-row span { flex: 1; opacity: 0.8; }
.tip-row b { font-variant-numeric: tabular-nums; }

.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.bars li { display: flex; align-items: center; gap: 12px; min-width: 0; }
.rank { width: 18px; color: var(--text-3); font-size: 12px; text-align: right; flex: none; font-variant-numeric: tabular-nums; }
.thumb { width: 30px; height: 42px; border-radius: 5px; background: var(--surface-2); overflow: hidden; flex: none; display: grid; place-items: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb.logo { width: 46px; height: 30px; padding: 3px; background: #1d2129; }
.thumb.logo img { object-fit: contain; }
.bar-text { flex: 1; min-width: 0; display: grid; gap: 4px; }
.bar-label { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-sub { color: var(--text-3); font-size: 12px; margin-top: -4px; }
.track { display: block; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.fill { display: block; height: 100%; background: var(--c); border-radius: 0 3px 3px 0; }
.bar-value { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 64px; text-align: right; }

.segmented { position: relative; }
.seg-bar { display: flex; gap: 2px; height: 14px; border-radius: 4px; overflow: hidden; margin: 6px 0 16px; }
.seg-bar span { background: var(--c); min-width: 3px; }
.seg-legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; }
.seg-legend li { display: grid; grid-template-columns: 10px 1fr auto 72px; gap: 10px; align-items: center; }
.seg-legend b { font-variant-numeric: tabular-nums; }
.seg-legend .muted { text-align: right; font-size: 12.5px; }

.heat-wrap { position: relative; overflow-x: auto; }
.heat { display: grid; grid-template-columns: 34px repeat(24, minmax(14px, 1fr)); gap: 3px; min-width: 520px; }
.heat-hour { font-size: 10.5px; color: var(--text-3); text-align: left; }
.heat-day { font-size: 11.5px; color: var(--text-2); align-self: center; }
.heat-cell { aspect-ratio: 1.3; border-radius: 3px; background: color-mix(in srgb, var(--series-1) var(--a), var(--surface-2)); }
.heat-cell:hover { outline: 2px solid var(--text); outline-offset: -1px; }
.heat-scale { display: flex; align-items: center; gap: 8px; justify-content: flex-end; font-size: 11.5px; color: var(--text-3); margin-top: 10px; }
.heat-scale i { width: 120px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, var(--surface-2), var(--series-1)); }

/* ---------- operators overview ---------- */
.op-name { display: flex; align-items: center; gap: 10px; }
.op-avatar { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; font-weight: 700; background: var(--surface-3); color: var(--text); flex: none; }
.op-name small { display: block; color: var(--text-3); font-size: 12px; }
td .spark { display: block; }

/* ---------- jobs ---------- */
.timeline { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.timeline > div { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.timeline b { display: block; font-size: 15px; margin-top: 2px; }

/* ---------- row preview ---------- */
.row-preview + .row-preview { margin-top: 24px; }
.row-preview h3 { display: flex; gap: 8px; align-items: baseline; margin-bottom: 10px; }
.cards { display: grid; grid-auto-flow: column; grid-auto-columns: 128px; gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.pcard { display: grid; gap: 4px; font-size: 12.5px; min-width: 0; align-content: start; }
.poster { position: relative; aspect-ratio: 2 / 3; border-radius: 8px; overflow: hidden; background: var(--surface-2); display: grid; place-items: center; margin-bottom: 4px; }
.poster img { width: 100%; height: 100%; object-fit: cover; }
.poster img.logo { object-fit: contain; padding: 18px; background: #1d2129; }
.poster .badge { position: absolute; left: 6px; top: 6px; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 4px; background: rgb(0 0 0 / 0.65); color: #fff; text-transform: uppercase; letter-spacing: 0.03em; }
.pcard b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard .muted { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- sign in ---------- */
.signin-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.signin { width: min(400px, 100%); }
.signin .brand { justify-content: center; padding-bottom: 24px; font-size: 20px; }
.signin h1 { margin-bottom: 4px; }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 270px; z-index: 30; transform: translateX(-100%); transition: transform 0.2s; box-shadow: 0 0 40px rgb(0 0 0 / 0.25); }
  .shell.menu-open .side { transform: none; }
  .menu-button { display: inline-flex; }
  .layout.two, .layout.wide-left { grid-template-columns: 1fr; }
  #app { padding: 18px 16px 48px; }
  .topbar { padding: 10px 16px; }
}
@media (max-width: 520px) {
  .updated { display: none; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat .spark { display: none; }
  .stat-label { padding-right: 0; }
  .stat-value { font-size: 21px; }
  .topbar .segment button { padding: 4px 8px; }
}
