:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --border: #334155;
}

* { box-sizing: border-box; }

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

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

.brand { color: var(--text); font-weight: 600; text-decoration: none; font-size: 1.1rem; }
.topbar nav { display: flex; gap: 1rem; align-items: center; }
.topbar a { color: var(--accent); text-decoration: none; }

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

h1, h2, h3 { color: var(--text); }
.muted { color: var(--muted); }
.error { color: #f87171; }

.login-card {
  max-width: 320px;
  margin: 4rem auto;
  padding: 2rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.login-card form { display: flex; flex-direction: column; gap: 0.75rem; }
.login-card label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }

input, button {
  font: inherit;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #0b1220;
  color: var(--text);
}

button {
  background: var(--accent);
  color: #082032;
  border: none;
  font-weight: 600;
  cursor: pointer;
}
button:disabled { opacity: 0.6; cursor: default; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; margin-top: 0.5rem; }
th, td { text-align: left; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 0.85rem; text-transform: uppercase; }
table a { color: var(--accent); text-decoration: none; }

.status-badge { padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.8rem; background: #14532d; color: #86efac; }
.status-inactive { background: #450a0a; color: #fca5a5; }

.presence-dot { display: inline-block; width: 8px; height: 8px; border-radius: 999px; }
.presence-online { background: #4ade80; box-shadow: 0 0 0 3px rgba(74,222,128,0.2); }
.presence-recent { background: #fbbf24; }
.presence-offline { background: #64748b; }

.enroll-panel { margin-bottom: 1.5rem; }
.search-input { width: 100%; max-width: 320px; margin-bottom: 0.75rem; display: block; }
.enroll-result { margin-top: 0.75rem; padding: 1rem; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; }
.code-display { display: flex; align-items: baseline; gap: 0.75rem; }
.code-label { color: var(--muted); font-size: 0.85rem; }
.code-value { font-size: 1.75rem; letter-spacing: 0.15em; font-weight: 700; font-family: monospace; }

#map { border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }

.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin: 1rem 0 2rem; }
.meta-grid > div { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem 1rem; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; }
.card dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 0.75rem; font-size: 0.9rem; }
.card dt { color: var(--muted); }
.card dd { margin: 0; text-align: right; }

pre { background: #0b1220; padding: 0.75rem; border-radius: 6px; overflow-x: auto; font-size: 0.85rem; }
details summary { cursor: pointer; color: var(--accent); }

.changelog h1 { margin-top: 0; }
.changelog h2 { margin-top: 2rem; padding-top: 0.5rem; border-top: 1px solid var(--border); }
.changelog h3 { color: var(--muted); font-size: 0.9rem; text-transform: uppercase; margin-bottom: 0.25rem; }
.changelog ul { margin: 0 0 1rem; padding-left: 1.25rem; }
.changelog li { margin: 0.25rem 0; }

.log-actions { display: flex; gap: 0.75rem; margin: 1rem 0; }
.log-actions button { cursor: pointer; }
#clear-log-btn { background: #450a0a; color: #fca5a5; }
.log-view { max-height: 70vh; overflow-y: auto; white-space: pre-wrap; word-break: break-word; font-size: 0.8rem; }

/* ---- Device detail page: wide container, header, tabs ---- */
.container-wide { max-width: 1280px; }

.device-header { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.device-header h1 { margin: 0; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--muted); font-weight: 500; font-size: 0.85rem; padding: 0.35rem 0.7rem; margin-left: auto; }
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }
.btn-ghost.btn-danger { color: #fca5a5; border-color: #7f1d1d; margin-left: 0; }
.btn-ghost.btn-danger:hover { background: #450a0a; }

.tabs {
  display: flex;
  gap: 0.25rem;
  margin: 1.25rem 0 1.5rem;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--muted);
  font-weight: 600;
  padding: 0.6rem 0.9rem;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel[hidden] { display: none; }

/* ---- Stat tiles (quick-glance row) ---- */
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin: 1rem 0 1.75rem; }
.stat-tile { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 0.9rem 1rem; }
.stat-tile-label { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-tile-value { font-size: 1.6rem; font-weight: 700; margin-top: 0.2rem; font-variant-numeric: tabular-nums; }
.stat-tile-sub { color: var(--muted); font-size: 0.8rem; margin-top: 0.15rem; }
.stat-tile-value.good { color: #4ade80; }
.stat-tile-value.warning { color: #fbbf24; }
.stat-tile-value.critical { color: #f87171; }

/* ---- Meter bars (battery / RAM / storage) ---- */
.meter { height: 8px; border-radius: 999px; background: #0b1220; overflow: hidden; margin-top: 0.4rem; border: 1px solid var(--border); }
.meter-fill { height: 100%; border-radius: 999px; background: var(--accent); transition: width 0.3s ease; }
.meter-fill.good { background: #0ca30c; }
.meter-fill.warning { background: #fab219; }
.meter-fill.critical { background: #d03b3b; }
.meter-caption { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.78rem; margin-top: 0.3rem; }

/* ---- Section headers inside a tab panel ---- */
.section-title { margin: 1.75rem 0 0.75rem; }
.section-title:first-child { margin-top: 0; }

/* ---- Compass ---- */
.compass-wrap { display: flex; align-items: center; gap: 1.25rem; }
.compass-value { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---- Scan tables (wifi/bluetooth/cell neighbors) ---- */
.scan-table td, .scan-table th { font-size: 0.85rem; }
.scan-table .signal-bar-cell { display: flex; align-items: center; gap: 0.5rem; }
.signal-bar { width: 60px; height: 6px; border-radius: 999px; background: #0b1220; border: 1px solid var(--border); overflow: hidden; flex-shrink: 0; }
.signal-bar-fill { height: 100%; background: var(--accent); }
.scan-empty { color: var(--muted); font-size: 0.85rem; padding: 0.5rem 0; }

/* ---- Chart cards ---- */
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.chart-card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; }
.chart-card h3 { margin: 0 0 0.75rem; font-size: 0.95rem; }
.chart-card canvas { max-height: 220px; }
.chart-empty { color: var(--muted); font-size: 0.85rem; text-align: center; padding: 2.5rem 0; }

/* ---- Badges (reachable / plugged / etc.) ---- */
.pill { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.78rem; font-weight: 600; }
.pill-good { background: #14532d; color: #86efac; }
.pill-bad { background: #450a0a; color: #fca5a5; }
.pill-neutral { background: #1e293b; color: var(--muted); border: 1px solid var(--border); }
