:root {
  --bg: #0a1424;
  --bg-2: #0e1a2e;
  --surface: #152438;
  --surface-2: #1a2d45;
  --text: #e8eef8;
  --ink: #07140f;
  --ink-2: #0c1f17;
  --forest: #1a4a35;
  --leaf: #3d9a68;
  --brass: #c9a227;
  --brass-2: #e0bc4a;
  --stone: #1e334d;
  --paper: #0a1424;
  --muted: #8ba0b8;
  --line: rgba(140, 180, 220, 0.14);
  --danger: #e05a48;
  --ok: #3d9a68;
  --warn: #d4a017;
  --side: 260px;
  --font-display: "Newsreader", Georgia, serif;
  --font-ui: "Sora", system-ui, sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0; font-family: var(--font-ui); color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, .display { font-family: var(--font-display); font-weight: 560; letter-spacing: -0.02em; color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: inherit; text-decoration: none; }

/* Auth gate */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(90% 70% at 20% 0%, rgba(47,107,79,.35), transparent 55%),
    radial-gradient(70% 50% at 90% 80%, rgba(40,90,160,.2), transparent 45%),
    linear-gradient(160deg, #060d18, #0a1628 55%, #071018);
  color: var(--text);
}
.auth-card {
  width: min(420px, 100%); background: rgba(21,36,56,.55);
  border: 1px solid rgba(201,162,39,.22); border-radius: 18px; padding: 28px;
  backdrop-filter: blur(10px);
}
.auth-card h1 { margin: 8px 0 6px; font-size: 1.9rem; }
.auth-card p { margin: 0 0 22px; color: rgba(232,238,248,.65); font-size: .92rem; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: .78rem; letter-spacing: .06em; text-transform: uppercase; color: rgba(232,238,248,.55); }
.field input, .field select, .field textarea,
.input, select, textarea {
  width: 100%; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: rgba(6,13,24,.55); color: var(--text);
}
.admin-shell .field input, .admin-shell .field select, .admin-shell .field textarea,
.admin-shell .input, .admin-shell select, .admin-shell textarea {
  background: var(--surface); color: var(--text); border: 1px solid var(--line);
}
.field input:focus, .input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brass); outline-offset: 0; border-color: transparent;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 16px; border-radius: 10px; font-weight: 600; font-size: .9rem;
  transition: .15s ease;
}
.btn-brass { background: var(--brass); color: var(--ink); width: 100%; }
.btn-brass:hover { background: var(--brass-2); }
.btn-solid { background: var(--leaf); color: #fff; }
.btn-outline { border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.btn-ghost { color: var(--muted); }
.btn-danger { background: rgba(224,90,72,.15); color: var(--danger); }
.btn-sm { padding: 7px 11px; font-size: .8rem; border-radius: 8px; }
.auth-error { color: #ffb4a8; font-size: .85rem; min-height: 1.2em; margin-bottom: 8px; }
.input-locked {
  opacity: .85 !important;
  cursor: default !important;
  color: var(--brass-2) !important;
  font-weight: 600;
}
.verify-number {
  font-family: var(--font-display);
  font-size: clamp(3.2rem, 12vw, 4.4rem);
  font-weight: 700;
  text-align: center;
  letter-spacing: .04em;
  color: var(--brass-2);
  padding: 12px 0 18px;
  line-height: 1;
}
.number-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.num-btn {
  padding: 18px 10px;
  border-radius: 14px;
  font-size: 1.35rem;
  font-weight: 700;
  color: #fff;
  background: rgba(232,238,248,.06);
  border: 1px solid rgba(232,238,248,.16);
  transition: .15s ease;
}
.num-btn:hover, .num-btn:active {
  background: rgba(201,162,39,.22);
  border-color: var(--brass);
  color: var(--brass-2);
}
.confirm-row {
  display: flex; gap: 8px; align-items: center; margin-top: 8px;
}
.confirm-row input { flex: 1; }
.qr-box {
  display: grid; place-items: center; gap: 10px; padding: 16px; margin: 12px 0;
  background: #fff; border-radius: 12px; color: #07140f;
}
.admin-shell .qr-box {
  border: 1px solid var(--line);
}
.step-note { font-size: .82rem; color: rgba(232,238,248,.6); margin-top: 10px; line-height: 1.5; }
.badge {
  display: inline-flex; gap: 6px; align-items: center; font-size: .7rem;
  letter-spacing: .1em; text-transform: uppercase; color: var(--brass-2);
  border: 1px solid rgba(201,162,39,.3); border-radius: 999px; padding: 4px 10px;
}

/* Shell */
.admin-shell { min-height: 100vh; display: flex; background: var(--bg); }
.sidebar {
  width: var(--side); flex-shrink: 0;
  background: linear-gradient(180deg, #060d18, #0a1620 40%, #0c1f17);
  color: rgba(232,238,248,.78); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
  border-right: 1px solid rgba(61,154,104,.15);
}
.side-brand { display: flex; gap: 10px; align-items: center; padding: 20px 18px; border-bottom: 1px solid rgba(201,162,39,.15); }
.side-brand .mark {
  width: 34px; height: 34px; border-radius: 9px; background: var(--brass); color: var(--ink);
  display: grid; place-items: center; font-family: var(--font-display); font-weight: 700;
}
.side-brand strong { display: block; color: #fff; font-size: .92rem; }
.side-brand span { font-size: .72rem; opacity: .55; }
.side-nav { flex: 1; overflow: auto; padding: 10px 0 16px; }
.side-label {
  font-size: .68rem; letter-spacing: .12em; text-transform: uppercase;
  color: rgba(232,238,248,.35); padding: 16px 18px 6px;
}
.side-link {
  display: flex; align-items: center; gap: 10px; padding: 10px 18px; font-size: .88rem; font-weight: 500;
  color: rgba(232,238,248,.65); border-left: 3px solid transparent;
}
.side-link:hover, .side-link.active { color: #fff; background: rgba(61,154,104,.12); }
.side-link.active { border-left-color: var(--brass); }
.side-foot { padding: 14px 16px; border-top: 1px solid rgba(201,162,39,.15); display: grid; gap: 8px; }
.main { flex: 1; min-width: 0; background: var(--bg); }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; justify-content: space-between; align-items: center;
  gap: 16px; padding: 14px 24px; background: rgba(10, 20, 36, 0.92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line); color: var(--text);
}
.topbar h1 { margin: 0; font-size: 1.35rem; }
.topbar .muted { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.content { padding: 22px 24px 64px; }
.grid-kpi { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: linear-gradient(165deg, var(--surface), var(--surface-2)); border: 1px solid var(--line);
  border-radius: 14px; padding: 16px 18px; position: relative; overflow: hidden;
}
.kpi::after {
  content: ""; position: absolute; right: -16px; top: -16px; width: 70px; height: 70px; border-radius: 50%;
  background: radial-gradient(circle, rgba(61,154,104,.25), transparent 70%);
}
.kpi .label { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.kpi .value { font-size: 1.55rem; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; color: var(--brass-2); }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-bottom: 16px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { margin: 0; font-size: 1.15rem; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; color: var(--text); }
th {
  text-align: left; font-size: .7rem; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); padding: 10px 12px; background: var(--bg-2); border-bottom: 1px solid var(--line);
}
td { padding: 10px 12px; border-bottom: 1px solid rgba(140,180,220,.08); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.thumb {
  width: 42px; height: 42px; border-radius: 8px; object-fit: cover; background: var(--stone);
}
.pill { display: inline-flex; padding: 2px 9px; border-radius: 999px; font-size: .72rem; font-weight: 600; }
.pill-ok { background: rgba(61,154,104,.18); color: var(--ok); }
.pill-warn { background: rgba(212,160,23,.16); color: var(--warn); }
.pill-muted { background: rgba(139,160,184,.15); color: var(--muted); }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.dropzone {
  border: 1.5px dashed var(--line); border-radius: 12px; padding: 22px; text-align: center;
  background: var(--bg-2); color: var(--muted); cursor: pointer;
}
.dropzone.drag { border-color: var(--brass); background: rgba(201,162,39,.08); }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.media-tile {
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface-2); position: relative;
}
.media-tile img { width: 100%; aspect-ratio: 1; object-fit: cover; }
.media-tile .cap { padding: 8px 10px; font-size: .75rem; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 90;
  background: var(--surface-2); color: var(--text); padding: 11px 18px; border-radius: 999px; font-size: .86rem; font-weight: 600;
  border: 1px solid var(--line);
}
.modal-scrim {
  position: fixed; inset: 0; background: rgba(4, 10, 22, .72); z-index: 70;
  display: grid; place-items: center; padding: 16px;
}
.modal {
  width: min(560px, 100%); background: var(--bg-2); border-radius: 16px; padding: 22px; max-height: 90vh; overflow: auto;
  border: 1px solid var(--line); color: var(--text);
}
.modal h3 { margin: 0 0 14px; }
.help {
  font-size: .85rem; color: var(--muted); line-height: 1.55; background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 14px;
}
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .84em; background: rgba(140,180,220,.12); padding: 1px 5px; border-radius: 4px; color: var(--brass-2); }
.burger { display: none; }

.btn, .side-link, .num-btn, .burger, .row-actions .btn {
  min-height: 44px;
  touch-action: manipulation;
}
.admin-shell {
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
}
.topbar {
  padding-top: max(14px, env(safe-area-inset-top, 0px));
}
.content {
  padding-bottom: max(64px, calc(48px + env(safe-area-inset-bottom, 0px)));
}
@media (max-width: 980px) {
  .grid-kpi { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 50;
    transform: translateX(-100%); transition: transform .25s cubic-bezier(.22,1,.36,1);
    width: min(var(--side), 86vw);
    padding-top: env(safe-area-inset-top, 0);
  }
  .sidebar.open { transform: none; }
  .burger { display: inline-flex; min-width: 44px; min-height: 44px; }
}
@media (max-width: 560px) {
  .grid-kpi { grid-template-columns: 1fr; }
  .content { padding: 16px 14px max(48px, env(safe-area-inset-bottom, 0px)); }
  .emp-grid { grid-template-columns: 1fr; }
  .topbar h1 { font-size: clamp(1.1rem, 4.5vw, 1.3rem); }
}

/* CCTV */
.cctv-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px;
}
.cctv-tile {
  position: relative; aspect-ratio: 16/10; border-radius: 14px; overflow: hidden;
  background: repeating-linear-gradient(135deg, #0c1f17, #0c1f17 12px, #12281e 12px, #12281e 24px);
  border: 1px solid var(--line);
}
.cctv-tile iframe, .cctv-tile img { width: 100%; height: 100%; border: 0; object-fit: cover; }
.cctv-placeholder {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  color: rgba(232,238,248,.75); font-size: .9rem; padding: 16px;
}
.live-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: #e14b3f; box-shadow: 0 0 0 3px rgba(225,75,63,.28); margin-right: 6px;
  animation: pulse 1.4s ease infinite;
}
@keyframes pulse { 50% { opacity: .45; } }
.cctv-cap {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 8px 10px;
  background: linear-gradient(transparent, rgba(6,13,24,.9)); color: #e8eef8;
  display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: .8rem;
}

/* Chat */
.chat-pane {
  max-height: 360px; overflow: auto; display: flex; flex-direction: column; gap: 10px;
  padding: 12px; background: var(--bg); border-radius: 12px; border: 1px solid var(--line);
}
.chat-bubble {
  max-width: 85%; padding: 10px 12px; border-radius: 12px; font-size: .88rem; line-height: 1.4;
}
.chat-bubble .meta { font-size: .7rem; color: var(--muted); margin-bottom: 4px; }
.chat-bubble.customer { background: var(--surface-2); border: 1px solid var(--line); align-self: flex-start; }
.chat-bubble.admin { background: var(--forest); color: #e8eef8; align-self: flex-end; }
.chat-bubble.admin .meta { color: rgba(232,238,248,.55); }

/* Chart.js dark readability */
#revChart { max-height: 260px; }

/* Styled panels / employees / scanner */
.styled-panel {
  background:
    linear-gradient(145deg, rgba(61,154,104,.08), transparent 40%),
    var(--surface);
  border: 1px solid rgba(61,154,104,.18);
  box-shadow: 0 12px 40px -24px rgba(0,0,0,.55);
}
.scanner-wrap {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
}
.scanner-view {
  min-height: 220px;
  border-radius: 10px;
  overflow: hidden;
  background: #060d18;
}
.scanner-view video { width: 100% !important; border-radius: 10px; }
.emp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.emp-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.emp-card-top { display: flex; gap: 12px; align-items: center; }
.emp-avatar {
  width: 56px; height: 56px; border-radius: 50%; overflow: hidden;
  background: linear-gradient(145deg, var(--forest), var(--leaf));
  display: grid; place-items: center; flex-shrink: 0;
  font-family: var(--font-display); font-size: 1.4rem; font-weight: 600; color: #fff;
}
.emp-avatar img { width: 100%; height: 100%; object-fit: cover; }
.emp-card h3 { margin: 0; font-size: 1.15rem; }
.emp-role { color: var(--muted); font-size: .82rem; margin-top: 2px; }
.emp-meta {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; font-size: .84rem;
}
.emp-meta .full { grid-column: 1 / -1; }
.emp-meta span {
  display: block; font-size: .68rem; letter-spacing: .05em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 2px;
}
.photo-prev { margin-top: 8px; }
.photo-prev img {
  max-width: 140px; max-height: 140px; border-radius: 12px; object-fit: cover;
  border: 1px solid var(--line);
}
.admin-shell .sidebar .nav-group {
  margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line);
}
.kpi {
  background:
    linear-gradient(160deg, rgba(201,162,39,.1), transparent 55%),
    var(--surface);
}
