:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --text: #e6e8eb;
  --muted: #8b93a1;
  --accent: #4f8cff;
  --ok: #35c26b;
  --off: #5a6270;
  --warn: #e0a233;
  --alert: #e0524b;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #f0f1f4;
    --border: #dde0e6;
    --text: #1a1d23;
    --muted: #5c6470;
  }
}

* { box-sizing: border-box; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); }

.alert {
  background: color-mix(in srgb, var(--alert) 15%, transparent);
  border: 1px solid var(--alert);
  color: var(--alert);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1.5rem;
}

/* Auth page */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  width: 100%;
  max-width: 360px;
}

.auth-card h1 { margin: 0 0 0.25rem; font-size: 1.4rem; }
.subtitle { margin: 0 0 1.5rem; color: var(--muted); font-size: 0.9rem; }

form { display: flex; flex-direction: column; gap: 0.25rem; }

label { font-size: 0.8rem; color: var(--muted); margin-top: 0.75rem; }

input, select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.6rem 0.7rem;
  border-radius: 8px;
  font-size: 0.95rem;
}

button {
  margin-top: 1.5rem;
  background: var(--accent);
  color: white;
  border: none;
  padding: 0.7rem;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
}

button:hover { opacity: 0.9; }

/* App shell */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-title { font-weight: 600; }
.topbar-user { color: var(--muted); font-size: 0.9rem; }

.content {
  max-width: 1000px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Panel grid */
.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.panel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  color: var(--text);
  display: block;
}

.panel-card:hover { border-color: var(--accent); text-decoration: none; }

.panel-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.panel-name { font-weight: 600; }

.badge {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}

.badge-on { background: color-mix(in srgb, var(--ok) 20%, transparent); color: var(--ok); }
.badge-off { background: color-mix(in srgb, var(--off) 25%, transparent); color: var(--off); }

.panel-card-body { font-size: 0.85rem; display: flex; flex-direction: column; gap: 0.2rem; }

/* Panel detail */
.status-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

.status-section h2 {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin: 1rem 0 0.5rem;
}

.status-section h2:first-child { margin-top: 0; }

.chip-row { display: flex; flex-direction: column; gap: 0.5rem; }

.chip-group { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }

.chip-label {
  font-size: 0.8rem;
  color: var(--muted);
  min-width: 110px;
}

.chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.1rem 0.5rem;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.chip-on { background: color-mix(in srgb, var(--ok) 20%, transparent); border-color: var(--ok); color: var(--ok); }
.chip-warn { background: color-mix(in srgb, var(--warn) 20%, transparent); border-color: var(--warn); color: var(--warn); }
.chip-alert { background: color-mix(in srgb, var(--alert) 20%, transparent); border-color: var(--alert); color: var(--alert); }

/* Events table */
.events-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.events-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
}

.events-table td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
}

.events-table tr:last-child td { border-bottom: none; }

.small { font-size: 0.8rem; margin-top: 0.5rem; }
