:root {
  --bg: #242328;
  --card: #323138;
  --card-2: #2b2a30;
  --line: #43424a;
  --text: #ecebf0;
  --muted: #a3a1ab;
  --accent: #6dc3df;
  --fill: #405b67;
  --warn: #f09937;
  --bad: #e5626a;
  --good: #6fcf8f;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- header ---------- */
header.top {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 24px; border-bottom: 1px solid var(--line); background: var(--card-2);
}
header.top img { width: 28px; height: 28px; }
header.top .title { font-size: 17px; font-weight: 600; }
header.top .spacer { flex: 1; }
header.top .user { color: var(--muted); }
button, .btn {
  font: inherit; color: var(--text); background: transparent;
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #17222a; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }

main { max-width: 1200px; margin: 0 auto; padding: 20px 24px 48px; }
h2 { font-size: 15px; font-weight: 600; margin: 28px 0 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
h2:first-child { margin-top: 4px; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px 18px; }
.banner {
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px;
  background: rgba(240,153,55,.12); border: 1px solid rgba(240,153,55,.45); color: #f6c48c;
}

/* ---------- stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.tile .label { color: var(--muted); font-size: 12px; }
.tile .value { font-size: 24px; font-weight: 600; margin-top: 4px; }
.tile .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---------- tables ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
td.r, th.r { text-align: right; }
tr:last-child td { border-bottom: 0; }
.card h3 { margin: 0 0 8px; font-size: 14px; font-weight: 600; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.dot.on { background: var(--good); }
.dot.off { background: var(--bad); }

/* ---------- chart ---------- */
.chart-card { margin-top: 12px; }
.chart-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 6px; }
.chart-head h3 { margin: 0; }
.chart-head .spacer { flex: 1; }
.range button { padding: 3px 10px; font-size: 12px; }
.range button.active { border-color: var(--accent); color: var(--accent); }
.chart { position: relative; height: 220px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .area { fill: var(--fill); opacity: .55; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .marker { fill: var(--accent); stroke: var(--card); stroke-width: 2; }
.chart .empty { fill: var(--muted); font-size: 13px; }
.tooltip {
  position: absolute; pointer-events: none; background: #1c1b20; border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 9px; font-size: 12px; white-space: nowrap; transform: translate(-50%, -110%);
}
.tooltip .t { color: var(--muted); }

.placeholder { color: var(--muted); }
footer { color: var(--muted); font-size: 12px; margin-top: 28px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login { width: 100%; max-width: 340px; }
.login .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; justify-content: center; }
.login .brand img { width: 34px; height: 34px; }
.login .brand span { font-size: 20px; font-weight: 600; }
.login label { display: block; color: var(--muted); font-size: 12px; margin: 12px 0 4px; }
.login input {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px;
}
.login input:focus { outline: none; border-color: var(--accent); }
.login button { width: 100%; margin-top: 18px; padding: 10px; }
.login .err { color: var(--bad); margin-top: 12px; min-height: 1.4em; font-size: 13px; }

/* ---------- navigation ---------- */
nav.tabs { display: flex; gap: 4px; margin-left: 18px; flex-wrap: wrap; }
nav.tabs a {
  color: var(--muted); text-decoration: none; padding: 6px 12px; border-radius: 8px; font-weight: 500;
}
nav.tabs a:hover { color: var(--text); }
nav.tabs a.active { color: var(--text); background: var(--card); }
@media (max-width: 760px) { header.top { flex-wrap: wrap; } nav.tabs { order: 3; width: 100%; margin: 8px 0 0; } }

.toolbar { display: flex; align-items: center; gap: 10px; margin: 4px 0 14px; flex-wrap: wrap; }
.toolbar h2 { margin: 0; }
.toolbar .spacer { flex: 1; }
.summary { color: var(--muted); }
.summary b { color: var(--text); font-weight: 600; }

.banner .x { float: right; margin-left: 12px; padding: 2px 8px; font-size: 12px; }
.banner.info { background: rgba(109,195,223,.10); border-color: rgba(109,195,223,.4); color: var(--text); }

/* ---------- rigs ---------- */
.rig { margin-bottom: 10px; padding: 0; overflow: hidden; }
.rig-head {
  display: grid; grid-template-columns: 22px minmax(120px, 1.3fr) repeat(5, minmax(80px, 1fr)) 24px;
  align-items: center; gap: 10px; padding: 12px 16px; cursor: pointer;
}
.rig-head:hover { background: rgba(255,255,255,.02); }
.rig-head .name { font-weight: 600; font-size: 15px; }
.rig-head .name small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.rig-head .m { font-variant-numeric: tabular-nums; }
.rig-head .m small { display: block; color: var(--muted); font-size: 11px; }
.rig-head .chev { color: var(--muted); transition: transform .15s; }
.rig.open .rig-head .chev { transform: rotate(90deg); }
@media (max-width: 860px) {
  .rig-head { grid-template-columns: 22px 1fr 1fr 1fr 24px; }
  .rig-head .hide-sm { display: none; }
}
.rig-body { border-top: 1px solid var(--line); padding: 14px 16px 16px; display: none; }
.rig.open .rig-body { display: block; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.status-dot.on { background: var(--good); }
.status-dot.off { background: var(--bad); }
.status-dot.warn { background: var(--warn); }
.tag {
  display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; margin-left: 6px;
  border: 1px solid var(--line); color: var(--muted); font-weight: 500; vertical-align: 1px;
}
.tag.new { color: var(--accent); border-color: rgba(109,195,223,.5); }
.tag.warn { color: var(--warn); border-color: rgba(240,153,55,.5); }
.tag.bad { color: var(--bad); border-color: rgba(229,98,106,.5); }
tr.missing td { color: var(--muted); }
.hot { color: var(--warn); }
.very-hot { color: var(--bad); }

.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 14px; }
.controls .group { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.controls .sep { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }
button.danger { color: var(--bad); border-color: rgba(229,98,106,.45); }
button.danger:hover { border-color: var(--bad); }
button:disabled { opacity: .45; cursor: default; border-color: var(--line); }
select, input[type=text], input[type=password], textarea, .field input {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 9px;
}
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { width: 100%; min-height: 70px; resize: vertical; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px 18px; margin-top: 12px; font-size: 13px; }
.kv div span { color: var(--muted); margin-right: 6px; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; word-break: break-all; }
.cmds { margin-top: 14px; font-size: 13px; }
.cmds td { padding: 4px 8px; }
.st-done { color: var(--good); } .st-failed { color: var(--bad); } .st-expired { color: var(--muted); }
.st-sent, .st-queued { color: var(--accent); }
.empty-state { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty-state p { margin: 0 0 14px; }

/* ---------- lists ---------- */
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .title { font-weight: 600; }
.list-row .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.card.flush { padding: 0; }

/* ---------- modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(10,10,14,.6); display: flex; align-items: flex-start;
  justify-content: center; padding: 8vh 16px 16px; z-index: 50; overflow-y: auto;
}
.modal { width: 100%; max-width: 520px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; }
.modal h3 { margin: 0 0 12px; font-size: 16px; }
.modal .field { margin: 12px 0; }
.modal .field label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.modal .field input, .modal .field select { width: 100%; }
.modal .hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal .err { color: var(--bad); font-size: 13px; min-height: 1.2em; margin-top: 8px; }
.modal pre { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; white-space: pre-wrap; word-break: break-all; margin: 8px 0; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1c1b20; border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 16px; z-index: 60; max-width: 90vw;
}
.toast.bad { border-color: rgba(229,98,106,.6); }
.audit td { font-size: 13px; vertical-align: top; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.gpu-table { min-width: 760px; }
.gpu-table td:nth-child(2) { min-width: 190px; }
@media (max-width: 760px) { .controls .sep { display: none; } }
