:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e4e9;
  --ink: #1b1f27;
  --ink-2: #4a5160;
  --ink-3: #7b8292;
  --accent: #2f6fde;
  --accent-ink: #ffffff;
  --accent-soft: rgba(47, 111, 222, 0.12);
  --grid: #eceef2;
  --good: #1f8a4c;
  --warn: #b7791f;
  --bad: #c53b3b;
  --idle: #8a909c;
  --track: #e8eaef;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #171a21;
    --border: #262a33;
    --ink: #e8eaf0;
    --ink-2: #b3b8c4;
    --ink-3: #7e8594;
    --accent: #5b8ff0;
    --accent-ink: #0b0d12;
    --accent-soft: rgba(91, 143, 240, 0.16);
    --grid: #22262e;
    --good: #3fb871;
    --warn: #e0a640;
    --bad: #ec6a6a;
    --idle: #7e8594;
    --track: #262a33;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a21;
  --border: #262a33;
  --ink: #e8eaf0;
  --ink-2: #b3b8c4;
  --ink-3: #7e8594;
  --accent: #5b8ff0;
  --accent-ink: #0b0d12;
  --accent-soft: rgba(91, 143, 240, 0.16);
  --grid: #22262e;
  --good: #3fb871;
  --warn: #e0a640;
  --bad: #ec6a6a;
  --idle: #7e8594;
  --track: #262a33;
  --shadow: none;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
}
body {
  background: var(--bg);
  color: var(--ink);
  font:
    15px/1.45 system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1 {
  font-size: 18px;
  margin: 0;
}
h2 {
  font-size: 15px;
  margin: 0 0 12px;
  font-weight: 600;
}
.muted {
  color: var(--ink-3);
}
.small {
  font-size: 13px;
}
.label {
  font-size: 12px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  max-width: 1100px;
  margin: 0 auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.brand > div {
  min-width: 0;
}
#mach-sub {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px 40px;
  display: grid;
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.card-head h2 {
  margin: 0;
}

.btn {
  font: inherit;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
  min-height: 40px;
}
.btn:hover {
  border-color: var(--ink-3);
}
.btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.btn.ghost {
  background: transparent;
}
.btn.sm {
  padding: 4px 10px;
  min-height: 32px;
  font-size: 13px;
}

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
}
.state-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}
.state-text {
  font-size: 20px;
  font-weight: 600;
}
.btns {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--idle);
  flex: none;
}
.dot.folding {
  background: var(--good);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--good) 22%, transparent);
}
.dot.paused {
  background: var(--warn);
}
.dot.finishing {
  background: var(--accent);
}
.dot.offline {
  background: var(--bad);
}

.tiles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.tile .hero {
  font-size: 30px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}
.tile .value {
  font-size: 15px;
  margin-top: 6px;
  overflow-wrap: anywhere;
}
@media (max-width: 800px) {
  .tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 420px) {
  .tile .hero {
    font-size: 24px;
  }
}

.banner {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--bad);
  background: color-mix(in srgb, var(--bad) 10%, var(--surface));
}

.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.seg button {
  font: inherit;
  font-size: 13px;
  background: transparent;
  color: var(--ink-2);
  border: 0;
  padding: 5px 10px;
  cursor: pointer;
}
.seg button.on {
  background: var(--accent-soft);
  color: var(--ink);
  font-weight: 600;
}

.chart {
  position: relative;
  height: 220px;
}
.chart svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.chart .axis text {
  fill: var(--ink-3);
  font-size: 11px;
}
.chart .grid line {
  stroke: var(--grid);
}
.chart .line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.chart .area {
  fill: var(--accent-soft);
}
.chart .cross {
  stroke: var(--ink-3);
  stroke-dasharray: 3 3;
}
.chart .marker {
  fill: var(--accent);
  stroke: var(--surface);
  stroke-width: 2;
}
.chart .empty {
  fill: var(--ink-3);
  font-size: 13px;
}
.tip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  white-space: nowrap;
  transform: translate(-50%, -110%);
}
.tip b {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.units {
  display: grid;
  gap: 10px;
}
.unit {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}
.unit-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  align-items: baseline;
}
.unit-title {
  font-weight: 600;
}
.badge {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
  border: 1px solid var(--border);
  color: var(--ink-2);
}
.badge.RUN {
  color: var(--good);
  border-color: currentColor;
}
.badge.PAUSE,
.badge.WAIT {
  color: var(--warn);
  border-color: currentColor;
}
.bar {
  height: 8px;
  border-radius: 4px;
  background: var(--track);
  margin: 10px 0 8px;
  overflow: hidden;
}
.bar > div {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.6s;
}
.unit-meta {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 4px 14px;
  font-size: 13px;
}
.unit-meta span {
  color: var(--ink-3);
}
.unit-meta b {
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.table-wrap {
  overflow-x: auto;
}
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.tbl th,
.tbl td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.tbl th {
  font-size: 12px;
  color: var(--ink-3);
  font-weight: 500;
}
#hw {
  margin-top: 10px;
}

.pre {
  margin: 0;
  max-height: 420px;
  overflow: auto;
  background: var(--bg);
  border-radius: 8px;
  padding: 12px;
  font:
    12px/1.5 ui-monospace,
    SFMono-Regular,
    Menlo,
    Consolas,
    monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 340px;
  display: grid;
  gap: 10px;
}
.login-card h1 {
  font-size: 22px;
}
.login-card p {
  margin: 0 0 8px;
}
input[type="password"] {
  font: inherit;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
}
.error {
  color: var(--bad);
  min-height: 1.4em;
  margin: 0;
}
