:root {
  color-scheme: light;
  --bg: #f3f6f9;
  --surface: #fcfcfb;
  --surface-2: #f1f4f7;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #6b6a66;
  --border: rgba(11, 11, 11, 0.10);
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --brand: #0e639c;
  --brand-2: #0a3d62;
  --good: #0ca30c;
  --good-text: #006300;
  --bad: #d03b3b;
  --bad-text: #b02525;
  --warn: #fab219;
  --warn-text: #8a5a00;
  --unk: #8a8984;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #232321;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #9b9a94;
    --border: rgba(255, 255, 255, 0.10);
    --grid: #2c2c2a;
    --axis: #383835;
    --good-text: #3fc23f;
    --bad-text: #f07070;
    --warn-text: #fab219;
    --unk: #8a8984;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --text: #f0efec; --text-2: #c3c2b7; --muted: #9b9a94;
  --border: rgba(255,255,255,.10); --grid: #2c2c2a; --axis: #383835; --good-text: #3fc23f; --bad-text: #f07070;
  --warn-text: #fab219; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
button, input { font: inherit; color: inherit; }

.btn { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 7px 12px; cursor: pointer; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; color: inherit; border-color: rgba(255,255,255,.35); }
.icon-btn { width: 36px; height: 36px; border-radius: 8px; border: 1px solid rgba(255,255,255,.3); background: transparent; color: #fff;
  cursor: pointer; font-size: 18px; display: inline-grid; place-items: center; }
.icon-btn:hover, .btn.ghost:hover { background: rgba(255,255,255,.12); }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
.login-card { width: min(360px, 100%); background: var(--surface); border-radius: 16px; padding: 28px 24px; box-shadow: 0 10px 40px rgba(0,0,0,.25);
  display: grid; gap: 12px; text-align: center; }
.login-card img { margin: 0 auto; border-radius: 14px; }
.login-card label { display: grid; gap: 4px; text-align: left; font-weight: 600; font-size: 13px; }
.login-card input { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); font-size: 16px; }
.err { color: var(--bad-text); min-height: 1em; margin: 0; font-size: 13px; }

/* ---------- header ---------- */
.top { position: sticky; top: 0; z-index: 20; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: linear-gradient(120deg, var(--brand), var(--brand-2)); color: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.15); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.brand img { border-radius: 7px; }
.datenav { display: flex; align-items: center; gap: 6px; margin-inline: auto; }
.datenav input { height: 36px; border-radius: 8px; border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.12);
  color: #fff; padding: 0 8px; color-scheme: dark; }
.actions { display: flex; align-items: center; gap: 8px; position: relative; }
.seg { display: inline-flex; border: 1px solid rgba(255,255,255,.35); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; color: #fff; padding: 7px 10px; cursor: pointer; font-size: 12px; font-weight: 600; }
.seg button[aria-pressed="true"] { background: #fff; color: var(--brand-2); }
.menu { position: absolute; right: 0; top: 44px; background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.2); min-width: 250px; padding: 6px; z-index: 30; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }
.menu-user { padding: 8px 10px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); margin-bottom: 4px; }

/* ---------- layout ---------- */
.wrap { max-width: 1200px; margin: 0 auto; padding: 16px; display: grid; gap: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.foot { text-align: center; margin: 0; }

/* ---------- now bar ---------- */
.nowbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); }
.nowbar .lead { font-weight: 700; margin-right: 4px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px;
  background: var(--surface-2); border: 1px solid var(--border); cursor: pointer; max-width: 100%; }
.chip span.t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- status badges (icon + label, never colour alone) ---------- */
.st { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; font-size: 12px; white-space: nowrap; }
.st i { width: 16px; height: 16px; border-radius: 50%; display: inline-grid; place-items: center; font-style: normal;
  font-size: 10px; color: #fff; flex: none; }
.st.success { color: var(--good-text); } .st.success i { background: var(--good); }
.st.failed { color: var(--bad-text); }  .st.failed i { background: var(--bad); }
.st.missed { color: var(--warn-text); } .st.missed i { background: var(--warn); color: #0b0b0b; }
.st.unknown { color: var(--muted); }    .st.unknown i { background: var(--unk); }

/* ---------- tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.tile .k { font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.tile .v { font-size: 28px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .s { font-size: 12px; color: var(--muted); }
.tile .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.tile.rate { display: flex; align-items: center; gap: 12px; }
.tile.rate svg { flex: none; }

/* ---------- trend chart ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend b { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart .axis line { stroke: var(--axis); }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .sel text { fill: var(--text); font-weight: 700; }
.chart .col { cursor: pointer; }
.chart .col .hit { fill: transparent; }
.chart .col:hover .hit, .chart .col.sel .hit { fill: var(--surface-2); }
.tableview { margin-top: 10px; font-size: 13px; }
.tableview summary { cursor: pointer; color: var(--text-2); }
table.tbl { border-collapse: collapse; width: 100%; margin-top: 8px; font-variant-numeric: tabular-nums; }
table.tbl th, table.tbl td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: right; }
table.tbl th:first-child, table.tbl td:first-child { text-align: left; }
.tableview > div { overflow-x: auto; }

/* ---------- jobs ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.filters input[type=search] { padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); min-width: 180px; }
.chk { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; cursor: pointer; }
.jobs { display: grid; gap: 0; }
.jobs-head, .job-row { display: grid; grid-template-columns: minmax(180px, 1.3fr) 2fr 110px 150px; gap: 12px; align-items: center; }
.jobs-head { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 0 8px 8px; border-bottom: 1px solid var(--border); }
.job { border-bottom: 1px solid var(--border); }
.job-row { padding: 10px 8px; cursor: pointer; border-radius: 8px; }
.job-row:hover { background: var(--surface-2); }
.job-name { font-weight: 600; overflow-wrap: anywhere; }
.job-name small { display: block; font-weight: 400; color: var(--muted); }
.counts { display: flex; gap: 10px; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--text-2); }
.counts b { font-weight: 700; }
.last { font-size: 12px; }
.last .tm { color: var(--muted); display: block; margin-top: 2px; }
.empty { padding: 30px 10px; text-align: center; color: var(--muted); }

/* 24h timeline strip */
.tl { position: relative; height: 26px; margin: 0 6px; }
.tl .track { position: absolute; left: 0; right: 0; top: 12px; height: 2px; background: var(--grid); border-radius: 1px; }
.tl .tick { position: absolute; top: 9px; width: 1px; height: 8px; background: var(--axis); }
.tl .mk { position: absolute; top: 1px; width: 24px; height: 24px; margin-left: -12px; display: grid; place-items: center; cursor: pointer; }
.tl .mk b { display: block; width: 12px; height: 12px; box-shadow: 0 0 0 2px var(--surface); }
.tl .mk.success b { background: var(--good); border-radius: 50%; }
.tl .mk.failed b { background: var(--bad); width: 11px; height: 11px; border-radius: 2px; transform: rotate(45deg); }
.tl .mk.missed b { background: var(--surface); border: 3px solid var(--warn); border-radius: 50%; }
.tl .mk.unknown b { background: var(--unk); width: 10px; height: 10px; }
.tl-axis { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); padding: 0 2px; }

.runs { padding: 4px 8px 14px; }
.run { display: grid; grid-template-columns: 110px 200px 1fr; gap: 12px; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); margin-top: 6px; font-size: 13px; }
.run .when b { font-variant-numeric: tabular-nums; }
.run .msg { color: var(--text-2); overflow-wrap: anywhere; }
.run .msg .step { color: var(--text); font-weight: 600; display: block; }
.hist-link { margin-top: 8px; font-size: 12px; }
.hist-link button { background: none; border: 0; color: var(--brand); cursor: pointer; padding: 0; text-decoration: underline; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .hist-link button { color: #6cb6ef; } }

/* ---------- tooltip / toast / dialog ---------- */
.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.18); max-width: 260px; }
.tip .row { display: flex; justify-content: space-between; gap: 14px; }
.tip .row span:last-child { font-weight: 700; font-variant-numeric: tabular-nums; }
.toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60;
  background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px; box-shadow: 0 6px 24px rgba(0,0,0,.3); max-width: calc(100% - 32px); }
.dlg { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); max-width: min(420px, calc(100% - 32px)); }
.dlg::backdrop { background: rgba(0,0,0,.45); }
.dlg ol { padding-left: 20px; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .jobs-head { display: none; }
  .job-row { grid-template-columns: 1fr auto; grid-template-areas: "name last" "tl tl" "counts counts"; gap: 6px 12px; }
  .job-row .job-name { grid-area: name; } .job-row .last { grid-area: last; text-align: right; }
  .job-row .tlw { grid-area: tl; } .job-row .counts { grid-area: counts; }
  .run { grid-template-columns: 1fr; gap: 4px; }
}
@media (max-width: 620px) {
  .top { gap: 8px; }
  .datenav { order: 3; width: 100%; margin: 0; }
  .datenav input { flex: 1; min-width: 0; }
  .actions { margin-left: auto; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile.rate { grid-column: span 2; }
  .tile .v { font-size: 24px; }
  .filters, .filters input[type=search] { width: 100%; min-width: 0; }
  .wrap { padding: 12px 16px 24px; gap: 12px; }
}
