:root {
  --bg: #0b1220;
  --panel: #121b2e;
  --panel-2: #182338;
  --border: #223047;
  --text: #e6edf7;
  --muted: #8ea0bd;
  --accent: #f5a524;
  --accent-2: #38bdf8;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --radius: 14px;
}

* { box-sizing: border-box; }

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

.hidden { display: none !important; }
.muted { color: var(--muted); }

.offline-banner {
  background: var(--amber);
  color: #241a00;
  font-weight: 600;
  text-align: center;
  padding: 8px 12px;
  font-size: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-wrap: wrap;
  gap: 10px;
}

.topbar-title { display: flex; align-items: center; gap: 12px; }
.brand-mark { font-size: 30px; }
.topbar-title h1 { margin: 0; font-size: 18px; }
.topbar-title p { margin: 0; font-size: 12px; }

.topbar-nav { display: flex; gap: 8px; }
.nav-link {
  color: var(--muted);
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
}
.nav-link.active { background: var(--accent); color: #241a00; }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 900px) {
  .container { grid-template-columns: 1fr; }
}

.camera-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: scaleX(-1);
}

.camera-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: #0d1526;
  color: var(--muted);
}

.face-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 13px;
  background: var(--green);
  color: #06210f;
}
.face-badge.unknown { background: var(--red); color: #2b0808; }

.demo-controls {
  padding: 14px 16px;
  border-top: 1px dashed var(--border);
  background: var(--panel-2);
}
.demo-title { margin: 0 0 10px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.demo-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.demo-row:last-child { margin-bottom: 0; }
.demo-row label { font-size: 13px; color: var(--muted); }

.toggles { gap: 14px; }
.toggle-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 13px;
}

select, input[type="number"], input[type="date"] {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent-2); color: #001621; }
.btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-cta { background: var(--green); color: #06210f; font-size: 16px; padding: 14px; }
.btn-cta:disabled { background: #2a3a4d; color: var(--muted); }
.btn-block { width: 100%; }

.side-panel { display: flex; flex-direction: column; gap: 14px; }

.panel-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.panel-card h2 { margin: 0 0 10px; font-size: 15px; }

.status-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 10px;
}
.status-pending { background: var(--panel-2); color: var(--muted); }
.status-ok { background: rgba(34,197,94,0.15); color: var(--green); }
.status-fail { background: rgba(239,68,68,0.15); color: var(--red); }

.checklist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.checklist li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--panel-2);
  font-size: 14px;
}
.checklist .item-name { display: flex; align-items: center; gap: 8px; }
.checklist .badge { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.badge-ok { background: rgba(34,197,94,0.18); color: var(--green); }
.badge-fail { background: rgba(239,68,68,0.18); color: var(--red); }
.badge-optional { background: rgba(148,163,184,0.18); color: var(--muted); }
.req-tag { font-size: 10px; color: var(--muted); margin-left: 6px; }

.geo-settings { margin-top: 10px; font-size: 13px; color: var(--muted); }
.geo-settings summary { cursor: pointer; }
.geo-form { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.geo-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.geo-form-actions { display: flex; gap: 8px; }

.warning-banner {
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.4);
  color: #fca5a5;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
}
.warning-banner ul { margin: 6px 0 0; padding-left: 18px; font-weight: 500; }

.today-log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 220px; overflow-y: auto; }
.today-log li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: var(--panel-2);
  border-radius: 8px;
  font-size: 13px;
}
.today-log img { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--green);
  color: #06210f;
  padding: 12px 20px;
  border-radius: 10px;
  font-weight: 700;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  z-index: 50;
}
.toast.error { background: var(--red); color: #2b0808; }

/* Kelola Item APD */
.manage { grid-template-columns: 1fr; max-width: 900px; }

.add-item-form { display: flex; flex-wrap: wrap; gap: 14px; align-items: end; }
.add-item-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.checkbox-label { flex-direction: row !important; align-items: center; gap: 6px !important; }

.item-list { display: flex; flex-direction: column; gap: 14px; }
.item-card-head { display: flex; justify-content: space-between; align-items: start; gap: 10px; margin-bottom: 12px; }
.item-card-head h3 { margin: 0 0 4px; font-size: 15px; }
.req-tag.ai { background: var(--accent-2); color: #001621; border-radius: 4px; padding: 1px 5px; }

.item-card-controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 14px;
  padding: 10px;
  background: var(--panel-2);
  border-radius: 10px;
}
.item-card-controls label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
@media (max-width: 640px) { .item-card-controls { grid-template-columns: 1fr; } }

.photo-gallery { display: flex; flex-wrap: wrap; gap: 10px; }
.photo-thumb { position: relative; width: 72px; height: 72px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb-del {
  position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: rgba(11,18,32,0.8); color: #fff; border: none; font-size: 10px; cursor: pointer; line-height: 1;
}
.photo-upload-btn {
  width: 72px; height: 72px; border-radius: 10px; border: 1px dashed var(--border);
  display: flex; align-items: center; justify-content: center; font-size: 18px; color: var(--muted);
  cursor: pointer; background: var(--panel-2);
}

.toggle-item.ai-tag { background: rgba(56,189,248,0.12); border-color: var(--accent-2); color: var(--accent-2); }

.test-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 10px; }
@media (max-width: 700px) { .test-panel { grid-template-columns: 1fr; } }
.test-video { aspect-ratio: 4/3; border-radius: var(--radius); overflow: hidden; }
.test-readout { display: flex; flex-direction: column; gap: 14px; }
.test-score { background: var(--panel-2); border-radius: 10px; padding: 14px; }
.test-readout input[type="range"] { width: 100%; }
.test-readout label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }

/* Dashboard */
.dashboard { grid-template-columns: 1fr; }
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
@media (max-width: 800px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.stat-label { margin: 0 0 6px; font-size: 12px; color: var(--muted); }
.stat-value { margin: 0; font-size: 26px; font-weight: 800; }

.compliance-header { display: flex; justify-content: space-between; align-items: center; }
.compliance-bars { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.compliance-bar-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.compliance-bar-row .label { width: 140px; flex-shrink: 0; color: var(--muted); }
.compliance-bar-track { flex: 1; background: var(--panel-2); border-radius: 999px; height: 10px; overflow: hidden; }
.compliance-bar-fill { height: 100%; background: var(--green); border-radius: 999px; }
.compliance-bar-row .pct { width: 44px; text-align: right; font-weight: 700; }

.table-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.table-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th { text-align: left; padding: 8px 10px; color: var(--muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody td { padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody img { width: 36px; height: 36px; border-radius: 8px; object-fit: cover; background: var(--panel-2); }
.pill { padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.pill-ok { background: rgba(34,197,94,0.18); color: var(--green); }
.pill-fail { background: rgba(239,68,68,0.18); color: var(--red); }
.pill-pending { background: rgba(245,165,36,0.18); color: var(--accent); }

/* Auth pages (login/signup) */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }
.auth-card h1 { margin: 0; font-size: 20px; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.auth-card input { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); padding: 10px 12px; border-radius: 8px; font-size: 14px; }

/* Staff header (manage/dashboard) */
.staff-header { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.staff-header #staffUserInfo { white-space: nowrap; }

/* Kiosk site-login gate (index.html) */
.kiosk-gate {
  position: fixed; inset: 0; z-index: 100; background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.kiosk-gate.hidden { display: none; }
.kiosk-gate-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.kiosk-gate-card input {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 14px; border-radius: 8px; font-size: 22px; text-align: center; letter-spacing: 0.15em; text-transform: uppercase;
}
.site-badge { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.site-badge button { font-size: 11px; padding: 4px 8px; flex-shrink: 0; }
.site-badge select { min-width: 0; }
@media (max-width: 480px) {
  .site-badge { flex-direction: column; align-items: stretch; }
  .site-badge select { width: 100%; }
}

/* Sites / Users panels (manage.html) */
.entity-table-wrap { overflow-x: auto; min-width: 0; }
.entity-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 10px; }
.entity-table th { text-align: left; padding: 6px 8px; color: var(--muted); border-bottom: 1px solid var(--border); }
.entity-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); }
.site-code-tag { font-family: monospace; font-weight: 700; letter-spacing: 0.05em; background: var(--panel-2); padding: 2px 8px; border-radius: 6px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-top: 12px; }
.inline-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }

/* ---------- Mobile ---------- */
/* Grid/flex items don't shrink below their content's natural width by default
   (min-width:auto), so a wide table or bar chart inside a card was forcing
   the whole page to scroll sideways instead of just that card. Cards are the
   items that sit directly in a grid/flex layout across every page, so fixing
   min-width there (paired with each wide element's own overflow-x:auto
   container, e.g. .table-wrap/.entity-table-wrap) fixes it everywhere at once. */
.panel-card, .stat-card, .camera-card, .item-card, .side-panel { min-width: 0; }
.table-wrap, .compliance-bars, .compliance-bar-row { min-width: 0; }

@media (max-width: 480px) {
  .container, .manage { padding: 14px; gap: 14px; }
  .stat-grid { grid-template-columns: 1fr; }
  .topbar { padding: 12px 14px; }
  .topbar-title h1 { font-size: 16px; }
  .compliance-bar-row { flex-wrap: wrap; }
  .compliance-bar-row .label { width: 100%; }
  .table-actions, .inline-form, .add-item-form { flex-direction: column; align-items: stretch; }
  .table-actions input, .table-actions button, .inline-form input, .inline-form select, .inline-form button { width: 100%; }
  .item-card-controls { grid-template-columns: 1fr; }
  .test-panel { grid-template-columns: 1fr; }
}
