:root {
  --bg: #f4f5f7;
  --card: #fff;
  --text: #1d2330;
  --muted: #6b7385;
  --border: #dfe2e8;
  --primary: #2459d6;
  --ok: #1b8a4b;
  --warn: #b26a00;
  --bad: #c62f2f;
  --info: #2459d6;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 12.5px; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.ok-text { color: var(--ok); }
.bad-text { color: var(--bad); font-weight: 600; }

.topbar {
  display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 52px;
  background: #151b2c; color: #fff;
}
.topbar .brand { color: #fff; font-weight: 600; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { color: #c5cbe0; padding: 6px 12px; border-radius: 6px; }
.topbar nav a.active, .topbar nav a:hover { background: #26304a; color: #fff; text-decoration: none; }
.topbar .logout { display: flex; gap: 10px; align-items: center; }
.topbar .logout .muted { color: #9aa3bd; }
.topbar button.link { color: #c5cbe0; }

.container { max-width: 1280px; margin: 0 auto; padding: 24px; }
.wide { padding: 16px 24px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; }
.section-head h2 { margin: 0; }
.meta { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-top: 8px; color: var(--muted); }
.note { margin-top: 8px; padding: 6px 10px; background: #fffbe8; border-left: 3px solid #e8c547; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card.empty { text-align: center; color: var(--muted); padding: 32px; }
details.card > summary { cursor: pointer; list-style: none; }
details.card > summary h2 { display: inline; }
details.card > summary::before { content: "▸ "; color: var(--muted); }
details.card[open] > summary::before { content: "▾ "; }
details.card[open] > summary { margin-bottom: 12px; }

table { width: 100%; border-collapse: collapse; }
table.runs { width: max-content; min-width: 100%; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tbody tr:hover { background: #fafbfc; }
.table-wrap { padding: 0; overflow-x: auto; }
table.numeric td:not(:first-child):not(:nth-child(2)) { font-variant-numeric: tabular-nums; white-space: nowrap; }
.bad-row { background: #fff5f5; }
.runs th, .runs td { white-space: nowrap; }
.runs td.when { font-variant-numeric: tabular-nums; }
.runs td.dur { font-variant-numeric: tabular-nums; font-weight: 600; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef0f4; color: var(--muted); white-space: nowrap; }
.badge.ok { background: #e3f5ea; color: var(--ok); }
.badge.warn { background: #fff1db; color: var(--warn); }
.badge.bad { background: #fde7e7; color: var(--bad); }
.badge.info { background: #e6edfc; color: var(--info); }

.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; border: 1px solid; }
.alert ul { margin: 6px 0 0; padding-left: 20px; }
.alert.bad { background: #fff5f5; border-color: #f3c2c2; color: #8f1f1f; }
.alert.warn { background: #fff8eb; border-color: #f1d39b; color: #7a4a00; }
.alert.info { background: #eef3fe; border-color: #c6d5f7; }

button, .button {
  display: inline-block; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--border);
  background: #fff; color: var(--text); font: inherit; cursor: pointer; text-decoration: none; white-space: nowrap;
}
button:hover, .button:hover { background: #f2f4f8; text-decoration: none; }
button.primary, .button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover, .button.primary:hover { background: #1b47b0; }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
button.link { background: none; border: 0; padding: 0; color: var(--primary); }
button.link.bad-text { font-weight: 600; }
button:disabled { opacity: .6; cursor: wait; }
.actions { display: flex; gap: 8px; align-items: center; }
.actions form { margin: 0; }
.actions.sticky { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; justify-content: flex-end; z-index: 2; }

input, select, textarea {
  width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; font: inherit; background: #fff;
}
textarea { font-family: ui-monospace, monospace; font-size: 12.5px; resize: vertical; }
input[type=checkbox] { width: auto; margin: 0; }
input:disabled, select:disabled, textarea:disabled { background: #f2f3f5; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px 18px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-weight: 500; }
.field.check { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; align-self: end; padding-bottom: 8px; }
.field.check small { flex-basis: 100%; }
code.key { color: var(--muted); font-size: 11px; font-weight: 400; }
.scenarios td { vertical-align: middle; }
.scenarios input.weight { width: 80px; }
.stages td { vertical-align: middle; }
.stages .stage-n { width: 2rem; color: var(--muted); text-align: right; }
.stages input[name=stage_duration] { width: 7rem; }
.stages input[name=stage_value] { width: 6rem; }
.stages select { width: 9rem; }
.stages .stage-sustain { text-align: center; }
.stages .stage-remove { font-size: 13px; }
.danger-row td:nth-child(2) strong { color: var(--bad); }
#cart-section.disabled { opacity: .55; }
label.inline { display: inline-flex; gap: 5px; align-items: center; margin-left: 10px; }
.choices { display: flex; gap: 18px; margin-bottom: 12px; }
.choices .field.check { padding-bottom: 0; }
#schedule-at input { max-width: 280px; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stats.compact { margin: 12px 0; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.stat span { font-size: 12px; color: var(--muted); }
.stat strong { font-size: 22px; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); }
.stat.bad strong { color: var(--bad); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs .right { margin-left: auto; }
.tabs.sub { margin-bottom: 10px; }
.tabs.sub a { padding: 6px 10px; font-size: 13px; }

iframe.grafana { width: 100%; height: calc(100vh - 230px); min-height: 600px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
iframe.grafana.tall { height: calc(100vh - 130px); }

pre.log {
  background: #10141f; color: #d5dae6; padding: 14px; border-radius: var(--radius); margin: 0;
  height: calc(100vh - 260px); min-height: 400px; overflow: auto; font-size: 12px; line-height: 1.45; white-space: pre-wrap; word-break: break-all;
}
pre.inline-pre { margin: 0; white-space: pre-wrap; font-size: 12px; }

.login-page { display: grid; place-items: center; min-height: 100vh; }
.login-page main { padding: 0; }
.card.login { width: 340px; display: flex; flex-direction: column; gap: 14px; padding: 28px; }
.card.login h1 { margin-bottom: -10px; }
.card.login label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
