:root {
  --bg: #0f1115;
  --panel: #1a1d24;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --muted: #8b92a0;
  --accent: #3b82f6;
  --live: #22c55e;
}

* { box-sizing: border-box; }
.hidden { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px -apple-system, Segoe UI, system-ui, sans-serif;
}

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}
header h1 { font-size: 16px; margin: 0; font-weight: 600; }
.status { color: var(--muted); }
.count { margin-left: auto; color: var(--muted); }
.btn-offline {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 12px; font: inherit; cursor: pointer;
}
.btn-offline:hover { border-color: var(--accent); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
  padding: 20px;
}
.empty { color: var(--muted); grid-column: 1 / -1; }

.tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s;
}
.tile:hover { border-color: var(--accent); }

.tile video {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  display: block;
  object-fit: contain;
}

.tile-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
}
.tile-footer .name { font-weight: 600; }
.tile-footer .activity-btn {
  margin-left: auto;
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 3px 8px; font-size: 12px; cursor: pointer;
}
.tile-footer .activity-btn:hover { color: var(--text); border-color: var(--accent); }
.tile-footer .live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--live); margin-left: 8px;
}

/* Expanded modal */
.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex; flex-direction: column;
  z-index: 50;
}
.modal.hidden { display: none; }
.modal-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; color: var(--text);
}
.modal-bar button {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 12px; cursor: pointer;
}
.modal video {
  flex: 1; width: 100%; min-height: 0;
  background: #000; object-fit: contain;
}

/* Phase 4: tile connection state */
.tile[data-state="connecting"] { opacity: 0.6; }
.tile[data-state="offline"] { opacity: 0.35; filter: grayscale(1); }

/* Phase 6: login */
.login { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login.hidden { display: none; }
.login form { display: flex; flex-direction: column; gap: 10px; width: 300px; padding: 24px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; }
.login h2 { margin: 0 0 6px; }
.login input { padding: 9px 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.login button { padding: 9px; border: 0; border-radius: 6px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
.login-error { margin: 0; min-height: 1em; color: #f87171; font-size: 13px; }

/* Activity report */
.activity-box {
  margin: 40px auto; width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 80px); overflow: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
}
.activity-controls { display: flex; align-items: center; gap: 10px; }
.activity-controls input[type="date"] {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 8px; font: inherit;
}
.activity-hint { margin: 0 20px 14px; color: var(--muted); font-size: 12px; }
#activity-body { padding: 0 20px 20px; }
.muted { color: var(--muted); }

.activity-categories { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.cat-row { display: grid; grid-template-columns: 130px 1fr 70px; align-items: center; gap: 10px; font-size: 13px; }
.cat-row .cat-label { font-weight: 600; }
.cat-bar-track { background: var(--bg); border: 1px solid var(--border); border-radius: 4px; height: 10px; overflow: hidden; }
.cat-bar-fill { height: 100%; background: var(--accent); }
.cat-row .cat-time { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

#activity-table { width: 100%; border-collapse: collapse; font-size: 13px; }
#activity-table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; padding: 8px 6px; border-bottom: 1px solid var(--border); }
#activity-table td { padding: 7px 6px; border-bottom: 1px solid var(--border); }
#activity-table tbody tr:last-child td { border-bottom: none; }
#activity-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

#offline-body { padding: 0 20px 20px; }
#offline-table { width: 100%; border-collapse: collapse; font-size: 13px; }
#offline-table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; padding: 8px 6px; border-bottom: 1px solid var(--border); }
#offline-table td { padding: 7px 6px; border-bottom: 1px solid var(--border); }
#offline-table tbody tr:last-child td { border-bottom: none; }
.pill-disabled-tag { background: #7f1d1d33; color: #fca5a5; border-radius: 999px; padding: 2px 8px; font-size: 11px; font-weight: 600; }
