:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c1f24;
  --text-muted: #666d78;
  --border: #e2e4e8;
  --primary: #2563eb;
  --primary-text: #ffffff;
  /* Status palette from the dataviz skill's validated reference (fixed —
     never themed; same hex in light/dark, both clear 3:1 on their surface). */
  --success: #0ca30c;
  --danger: #d03b3b;
  --warning: #fab219;
  --offline: #9aa1ac;
  --chart-series: #2a78d6;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121417;
    --surface: #1c1f24;
    --text: #eef0f2;
    --text-muted: #9aa1ac;
    --border: #2c3036;
    --primary: #3b82f6;
    --success: #0ca30c;
    --danger: #d03b3b;
    --warning: #fab219;
    --offline: #5b626d;
    --chart-series: #3987e5;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand { font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.1rem; }
.topbar nav { display: flex; gap: 14px; flex-wrap: wrap; }
.topbar nav a { color: var(--text-muted); text-decoration: none; font-size: 0.9rem; }
.topbar nav a:hover { color: var(--primary); }

.content { max-width: 640px; margin: 0 auto; padding: 16px; }

h1 { font-size: 1.3rem; margin: 4px 0 16px; }
h2 { font-size: 1.05rem; margin: 24px 0 10px; color: var(--text-muted); }

.gate-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.gate-btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 22px 14px;
  min-height: 110px;
  font-size: 1rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
  position: relative;
}
.gate-btn:active { transform: scale(0.97); }
.gate-btn .place { display: block; font-weight: 400; font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }
.gate-btn .badge {
  position: absolute; top: 12px; right: 12px;
  font-size: 0.7rem; font-weight: 700; padding: 3px 8px; border-radius: 999px;
}

.gate-btn.state-idle { border-color: var(--primary); }
.gate-btn.state-idle .badge { display: none; }

.gate-btn.state-busy {
  background: color-mix(in srgb, var(--warning) 12%, var(--surface));
  border-color: var(--warning);
  cursor: wait;
}
.gate-btn.state-busy .badge { background: var(--warning); color: #fff; }

.gate-btn.state-offline {
  background: color-mix(in srgb, var(--offline) 14%, var(--surface));
  border-color: var(--offline);
  color: var(--text-muted);
  cursor: not-allowed;
}
.gate-btn.state-offline .badge { background: var(--offline); color: #fff; }

.gate-btn.state-success { border-color: var(--success); background: color-mix(in srgb, var(--success) 14%, var(--surface)); }
.gate-btn.state-success .badge { background: var(--success); color: #fff; }

.gate-btn.state-error { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, var(--surface)); }
.gate-btn.state-error .badge { background: var(--danger); color: #fff; }

.error-msg { color: var(--danger); font-size: 0.85rem; margin-top: 8px; }

.activity-list, .device-list { list-style: none; padding: 0; margin: 0; }
.activity-list li, .device-list li {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 8px; font-size: 0.9rem;
}
.activity-list .meta, .device-list .meta { color: var(--text-muted); font-size: 0.8rem; }
.outcome-succeeded { color: var(--success); font-weight: 600; }
.outcome-failed { color: var(--danger); font-weight: 600; }
.outcome-timeout { color: var(--warning); font-weight: 600; }

.chart-legend { display: flex; gap: 16px; font-size: 0.82rem; color: var(--text-muted); margin-bottom: 12px; }
.chart-legend .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.stat-bar-row { margin-bottom: 16px; }
.stat-row-head { display: flex; justify-content: space-between; font-size: 0.9rem; margin-bottom: 4px; }
.stat-row-head .count { color: var(--text-muted); font-size: 0.82rem; }

/* Stacked bar: 2px surface gap between segments (the spacer, not a border),
   4px rounded data-ends on the outer edges only, square where segments meet. */
.stat-bar-track { display: flex; height: 14px; gap: 2px; }
.stat-bar-track .seg { height: 100%; }
.stat-bar-track .seg:first-child { border-radius: 4px 0 0 4px; }
.stat-bar-track .seg:last-child { border-radius: 0 4px 4px 0; }
.stat-bar-track .seg:only-child { border-radius: 4px; }
.stat-bar-track .seg-succeeded { background: var(--success); }
.stat-bar-track .seg-failed { background: var(--danger); }
.stat-bar-track .seg-timeout { background: var(--warning); }
.stat-bar-track .seg-empty { background: var(--border); border-radius: 4px; width: 100%; }

.btn {
  display: inline-block; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 0.85rem; cursor: pointer;
}
.btn.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }

form.login-form { max-width: 320px; margin: 60px auto; }
form.login-form p { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
form.login-form input { padding: 10px; border-radius: 8px; border: 1px solid var(--border); font-size: 1rem; }
