:root {
  color-scheme: light;
  --bg: #e8eef2;
  --surface: #ffffff;
  --surface-2: #f5f7fa;
  --border: #dce3ea;
  --text: #212121;
  --muted: #6b7280;
  --primary: #03a9f4;
  --primary-dark: #0288d1;
  --success: #4caf50;
  --warn: #ff9800;
  --danger: #f44336;
  --demo: #7e57c2;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --radius: 12px;
  font-family: Roboto, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Top bar ── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  gap: 1rem;
}

.topbar-brand {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
}

.topbar-nav {
  display: flex;
  gap: 0.25rem;
}

.topbar-nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  transition: background 0.15s, color 0.15s;
}

.topbar-nav a:hover {
  background: var(--surface-2);
  color: var(--text);
}

.topbar-nav a.active {
  background: rgba(3, 169, 244, 0.12);
  color: var(--primary-dark);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* ── Layout ── */
.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.25rem;
}

.page-header {
  margin-bottom: 1rem;
}

.page-header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 500;
}

.page-header .subtitle {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

/* ── Buttons ── */
button {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}

button:hover { background: var(--primary-dark); }

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--border); }

.hint {
  font-size: 0.75rem;
  color: var(--muted);
}

.block-hint { display: block; margin-bottom: 1rem; }

/* ── Status bar ── */
.status-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  padding: 0.65rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
}

.badge {
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.badge.live, .badge.online {
  background: #e8f5e9;
  color: #2e7d32;
  border-color: #c8e6c9;
}

.badge.offline, .badge.error {
  background: #ffebee;
  color: #c62828;
  border-color: #ffcdd2;
}

.badge.demo, .badge.dry-run, .badge.demo-unconfigured {
  background: #ede7f6;
  color: #5e35b1;
  border-color: #d1c4e9;
}

.badge.cache, .badge.stale-cache {
  background: #fff3e0;
  color: #e65100;
  border-color: #ffe0b2;
}

/* ── Cards & panels ── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.card, .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.card h2, .panel h2 {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.card-highlight {
  border-color: #b3e5fc;
  background: linear-gradient(180deg, #f0f9ff 0%, var(--surface) 100%);
}

.metric {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 500;
  color: var(--text);
}

.metric-sm {
  font-size: 0.95rem !important;
  line-height: 1.5;
  font-weight: 500;
}

.sub-metric {
  margin: 0.35rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}

.panel { margin-bottom: 1rem; }

/* ── Warnings ── */
.warn-banner {
  padding: 0.65rem 1rem;
  margin-bottom: 1rem;
  border-radius: var(--radius);
  background: #fff8e1;
  border: 1px solid #ffe082;
  color: #f57f17;
  font-size: 0.85rem;
}

.warn-banner.hidden { display: none; }

/* ── System panel ── */
.system-panel .system-desc {
  margin: 0 0 0.75rem;
  font-size: 0.875rem;
  color: var(--muted);
}

.bullet-list {
  margin: 0;
  padding-left: 1.2rem;
  font-size: 0.85rem;
}

.bullet-list li { margin-bottom: 0.3rem; }

.bullet-list a { color: var(--primary-dark); }

/* ── Devices ── */
.device-list { display: flex; flex-direction: column; gap: 0.4rem; }

.device-item {
  display: flex;
  justify-content: space-between;
  padding: 0.55rem 0.75rem;
  background: var(--surface-2);
  border-radius: 8px;
  font-size: 0.875rem;
}

/* ── Meta ── */
.meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.3rem 1rem;
  margin: 0;
  font-size: 0.85rem;
}

.meta dt { color: var(--muted); }
.meta dd { margin: 0; }

/* ── Raw JSON ── */
.raw-panel summary {
  cursor: pointer;
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--muted);
}

pre {
  margin: 0.75rem 0 0;
  padding: 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: auto;
  font-size: 0.75rem;
  max-height: 320px;
}

/* ── Config form ── */
.config-form .field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.config-form .field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
}

.config-form .field span { color: var(--muted); font-weight: 500; }

.config-form input[type="text"],
.config-form input[type="number"],
.config-form input[type="password"] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  color: var(--text);
  font-family: inherit;
  font-size: 0.875rem;
}

.config-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(3, 169, 244, 0.2);
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

/* ── Table ── */
.table-wrap { overflow-x: auto; }

.vars-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.vars-table th,
.vars-table td {
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.vars-table th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.vars-table .val { font-weight: 500; }
.vars-table .unit { color: var(--muted); }
.vars-table .topic { font-size: 0.75rem; color: var(--muted); font-family: monospace; }

code {
  background: var(--surface-2);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85em;
}
