* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2a2d3a;
  --text: #e1e4ed;
  --text-dim: #8b8fa3;
  --accent: #4f8ff7;
  --on: #22c55e;
  --off: #64748b;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

header h1 { font-size: 1.3rem; font-weight: 600; }

.status-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.status-dot.online  { background: var(--on); box-shadow: 0 0 6px var(--on); }
.status-dot.offline { background: var(--off); }

/* ─── Device Filter Bar ───────────────────────────── */
#device-filter {
  display: flex;
  gap: 8px;
  padding: 12px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  overflow-x: auto;
  flex-wrap: wrap;
}

.filter-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-family: "SF Mono", "Cascadia Code", monospace;
  cursor: pointer;
  transition: 0.2s;
  white-space: nowrap;
}

.filter-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.filter-btn[data-mac="all"] {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

main { padding: 24px 32px; }

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-dim);
}
.empty-state .sub { font-size: 0.85rem; margin-top: 8px; }

/* ─── Device Card ─────────────────────────────────── */
.device-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 24px;
  overflow: hidden;
}

.device-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.device-mac {
  font-family: "SF Mono", "Cascadia Code", monospace;
  font-size: 0.95rem;
  color: var(--accent);
}

.last-seen {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.device-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  padding: 20px;
}

/* ─── Sections ────────────────────────────────────── */
.io-section h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.io-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}

/* ─── IO Item ─────────────────────────────────────── */
.io-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  transition: border-color 0.2s;
}

.io-item.active { border-color: var(--on); }

.io-label { color: var(--text-dim); }

.io-value {
  font-family: "SF Mono", "Cascadia Code", monospace;
  font-weight: 600;
}
.io-value.on  { color: var(--on); }
.io-value.off { color: var(--off); }

/* ─── Waiting data ───────────────────────────────── */
.waiting-data {
  padding: 12px 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  font-style: italic;
}

/* ─── Refresh button ──────────────────────────────── */
.btn-refresh {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: 0.2s;
}
.btn-refresh:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ─── History Section ─────────────────────────────── */
.history-section {
  border-top: 1px solid var(--border);
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
}

.history-header h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
}

.range-select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
}

.range-select:hover {
  border-color: var(--accent);
}

.history-body {
  max-height: 300px;
  overflow-y: auto;
  padding: 0 20px 14px;
}

.history-empty {
  text-align: center;
  padding: 24px;
  color: var(--text-dim);
  font-size: 0.85rem;
}

/* ─── History Table ───────────────────────────────── */
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.history-table th {
  position: sticky;
  top: 0;
  background: var(--surface);
  text-align: center;
  padding: 6px 8px;
  color: var(--text-dim);
  font-weight: 500;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.history-table th:first-child {
  text-align: left;
}

.history-table td {
  padding: 5px 8px;
  text-align: center;
  border-bottom: 1px solid rgba(42, 45, 58, 0.5);
}

.history-table tr:hover {
  background: rgba(79, 143, 247, 0.05);
}

.history-time {
  font-family: "SF Mono", "Cascadia Code", monospace;
  color: var(--text-dim);
  text-align: left !important;
  white-space: nowrap;
}

.history-val {
  font-family: "SF Mono", "Cascadia Code", monospace;
  font-weight: 600;
}

.history-val.on { color: var(--on); }
.history-val.off { color: var(--off); }

/* ─── Scrollbar ───────────────────────────────────── */
.history-body::-webkit-scrollbar {
  width: 6px;
}
.history-body::-webkit-scrollbar-track {
  background: var(--bg);
}
.history-body::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
.history-body::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

@media (max-width: 640px) {
  main { padding: 16px; }
  .device-body { grid-template-columns: 1fr; }
  .history-table { font-size: 0.7rem; }
  .history-table th,
  .history-table td { padding: 4px 4px; }
}
