/* Control dashboard. Dark UI on purpose — it's used next to a live stream. */

:root {
  color-scheme: dark;
  --surface-0: #0e1013;
  --surface-1: #16191e;
  --surface-2: #1d2128;
  --line: #2a2f38;
  --text-primary: #f3f5f7;
  --text-secondary: #a8b0bb;
  --text-muted: #7c8593;
  --accent: #53fc18;
  --accent-ink: #08170a;
  --good: #199e70;
  --bad: #e66767;
  --warn: #c98500;
  --radius: 12px;
}

*, *::before, *::after { box-sizing: border-box; }

/* Must beat the `display` rules below, or a [hidden] panel still renders. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}

h1, h2 { margin: 0; font-size: 15px; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
a { color: var(--accent); }

.muted { color: var(--text-secondary); }
.small { font-size: 12.5px; }
.error { color: var(--bad); }

/* ── Login ─────────────────────────────────────────────────────────── */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card p { margin: 0; }

/* ── Shell ─────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--surface-0) 88%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--bad);
  flex: none;
  transition: background 200ms ease;
}
.dot[data-on="true"] { background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }

.pill {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 3px 9px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--bad) 20%, transparent);
  color: var(--bad);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
  align-items: start;
}
@media (min-width: 1024px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-2 { grid-column: span 2; }
}
@media (min-width: 1400px) {
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .span-2 { grid-column: span 2; }
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.card > p:first-of-type { margin-top: 0; }

/* ── Buttons & inputs ──────────────────────────────────────────────── */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: background 140ms ease, border-color 140ms ease, opacity 140ms ease;
}
.btn:hover { background: #262b33; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

input, select {
  background: var(--surface-0);
  border: 1px solid var(--line);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  width: 100%;
  min-width: 0;
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 70%, transparent); outline-offset: -1px; border-color: var(--accent); }
input[type="color"] { padding: 2px; height: 36px; cursor: pointer; }
input[type="range"] { padding: 0; accent-color: var(--accent); }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }
input[readonly] { color: var(--text-secondary); }

.row-actions { display: flex; gap: 8px; align-items: center; flex: none; }
.row-actions.wrap { flex-wrap: wrap; }

.fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}
.fields label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 0;
}
.fields label.check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.val { color: var(--text-muted); font-weight: 500; }

.inline-form { display: flex; gap: 8px; margin-top: 8px; }

/* ── Stat tiles ────────────────────────────────────────────────────── */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 12px;
}
.tile {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}
.tile-value { font-size: 26px; font-weight: 700; line-height: 1.1; letter-spacing: -0.02em; }
.tile-label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.chip { width: 8px; height: 8px; border-radius: 2px; flex: none; background: var(--chip, var(--accent)); }

/* ── Goal editor ───────────────────────────────────────────────────── */
.goal-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }

.goal-item {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  display: grid;
  gap: 10px;
}
.goal-item[data-hidden="true"] { opacity: 0.55; }

.goal-item-top {
  display: grid;
  grid-template-columns: 40px minmax(120px, 1.6fr) minmax(130px, 1.2fr) 90px auto;
  gap: 8px;
  align-items: center;
}
@media (max-width: 720px) {
  .goal-item-top { grid-template-columns: 40px 1fr; }
}

.goal-progress { display: flex; align-items: center; gap: 10px; }

.mini-track {
  position: relative;
  flex: 1;
  height: 10px;
  border-radius: 5px;
  background: #0a0c0f;
  border: 1px solid var(--line);
  overflow: hidden;
}
.mini-fill {
  position: absolute;
  inset: 1px auto 1px 1px;
  border-radius: 4px;
  background: var(--bar, var(--accent));
  transition: width 420ms cubic-bezier(0.22, 1, 0.36, 1);
}
.goal-now { font-weight: 700; font-size: 13px; flex: none; min-width: 92px; }
.goal-now .of { color: var(--text-muted); font-weight: 600; }

.stepper { display: flex; gap: 4px; flex: none; }
.stepper .btn { padding: 4px 9px; font-size: 13px; }

/* ── Connections ───────────────────────────────────────────────────── */
.conn-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.conn-title { font-weight: 600; display: flex; align-items: center; gap: 8px; }

.status {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
}
.status[data-state="ok"] { background: color-mix(in srgb, var(--good) 22%, transparent); color: #6ee7b7; }
.status[data-state="bad"] { background: color-mix(in srgb, var(--bad) 20%, transparent); color: var(--bad); }
.status[data-state="warn"] { background: color-mix(in srgb, var(--warn) 22%, transparent); color: #f0c04d; }

.setup { margin-top: 12px; }
.setup summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-secondary);
  padding: 6px 0;
}
.setup summary:hover { color: var(--text-primary); }

.copy-field {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  gap: 8px;
  align-items: center;
  margin: 8px 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}
@media (max-width: 620px) {
  .copy-field { grid-template-columns: 1fr auto; }
  .copy-field > span { grid-column: 1 / -1; }
}
.copy-field input { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

.opts { margin: 6px 0 0; padding-left: 18px; }
.opts code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11.5px;
}

/* ── Activity ──────────────────────────────────────────────────────── */
.activity {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 860px) { .activity { grid-template-columns: 1fr; } }

.event-list, .log-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
  font-size: 13px;
}
.event-list li, .log-list li {
  display: flex;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.event-list .who { font-weight: 600; }
.event-list .when, .log-list .when { color: var(--text-muted); font-size: 11.5px; flex: none; min-width: 58px; }
.event-list .test { color: var(--warn); font-size: 11px; font-weight: 700; }
.log-list { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--text-secondary); }
.log-list li[data-level="error"] { color: var(--bad); }
.log-list li[data-level="warn"] { color: #f0c04d; }

/* ── Toast ─────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 20;
  max-width: min(520px, 92vw);
}
.toast[data-kind="error"] { border-left-color: var(--bad); }
