:root {
  --bg: #0D1220;
  --surface: #151B2C;
  --surface-2: #1C2338;
  --surface-3: #262E48;
  --border: #2A3350;
  --text: #E9ECF5;
  --text-muted: #8D97B5;
  --text-faint: #5D6688;

  --accent: #F5A623;
  --accent-dim: #B8791A;
  --accent-soft: rgba(245, 166, 35, 0.14);

  --good: #35D399;
  --good-soft: rgba(53, 211, 153, 0.14);
  --bad: #F26D6D;
  --bad-soft: rgba(242, 109, 109, 0.14);
  --info: #6FA8FF;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --font-display: "Space Grotesk", "Inter", sans-serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;

  --shadow-elevated: 0 20px 50px -20px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 8px;
  color: var(--text);
}

h1 { font-size: 30px; letter-spacing: -0.02em; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }

p { margin: 0 0 12px; color: var(--text-muted); }

a { color: var(--accent); text-decoration: none; }

button { font-family: var(--font-body); cursor: pointer; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:active { transform: scale(0.98); }

.btn-primary { background: var(--accent); color: #16110A; }
.btn-primary:hover { background: #FFB74D; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--text-faint); }

.btn-danger { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn-danger:hover { background: var(--bad-soft); }

.btn-sm { padding: 7px 13px; font-size: 13px; }
.btn-block { width: 100%; }

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

input, select, textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 11px 13px;
  transition: border-color 0.15s ease;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; }
input::placeholder { color: var(--text-faint); }

.field { margin-bottom: 16px; }
.field-row { display: flex; gap: 14px; }
.field-row .field { flex: 1; }

.checkbox-row { display: flex; align-items: flex-start; gap: 10px; }
.checkbox-row input[type="checkbox"] {
  width: 18px; height: 18px; margin-top: 2px; flex-shrink: 0; accent-color: var(--accent);
}
.checkbox-row label { margin: 0; font-weight: 400; color: var(--text); }

.shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 28px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px; background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  color: #16110A; font-family: var(--font-display); font-weight: 700; font-size: 15px;
}
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 15px; }
.brand-name span { display: block; font-size: 11px; color: var(--text-faint); font-weight: 400; }

.nav-group { margin-bottom: 4px; }
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 14px; font-weight: 500; margin-bottom: 2px;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); }
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--surface-3);
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: var(--text);
}
.user-meta { flex: 1; min-width: 0; }
.user-meta .name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta .role { font-size: 11px; color: var(--text-faint); text-transform: capitalize; }

.main { padding: 32px 40px; max-width: 1280px; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 28px; gap: 20px; }
.page-head p { margin: 0; }

.tile-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 28px; }
.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--accent); border-radius: var(--radius-md); padding: 18px 20px;
}
.tile.tile-good { border-left-color: var(--good); }
.tile.tile-bad { border-left-color: var(--bad); }
.tile.tile-info { border-left-color: var(--info); }
.tile .tile-label { font-size: 12px; color: var(--text-faint); margin-bottom: 8px; font-weight: 600; }
.tile .tile-value { font-family: var(--font-display); font-size: 30px; font-weight: 600; }
.tile .tile-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; margin-bottom: 20px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }

table { width: 100%; border-collapse: collapse; }
thead th { text-align: left; font-size: 12px; color: var(--text-faint); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--border); }
tbody td { padding: 13px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

.avatar-name { display: flex; align-items: center; gap: 10px; }
.avatar-circle {
  width: 30px; height: 30px; border-radius: 50%; background: var(--surface-3);
  display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex-shrink: 0;
}

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 100px; font-size: 12px; font-weight: 600; }
.badge-good { background: var(--good-soft); color: var(--good); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-neutral { background: var(--surface-3); color: var(--text-muted); }
.badge-warn { background: var(--accent-soft); color: var(--accent); }

.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }
.toolbar .search { flex: 1; min-width: 220px; }

.login-shell { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-brand {
  background: radial-gradient(circle at 20% 20%, rgba(245,166,35,0.12), transparent 45%), var(--surface);
  border-right: 1px solid var(--border);
  padding: 60px; display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
}
.login-brand .scan-frame { position: relative; width: 220px; height: 220px; margin: 40px 0; border-radius: var(--radius-lg); }
.scan-frame .corner { position: absolute; width: 34px; height: 34px; border: 3px solid var(--accent); }
.scan-frame .tl { top: 0; left: 0; border-right: none; border-bottom: none; border-top-left-radius: 10px; }
.scan-frame .tr { top: 0; right: 0; border-left: none; border-bottom: none; border-top-right-radius: 10px; }
.scan-frame .bl { bottom: 0; left: 0; border-right: none; border-top: none; border-bottom-left-radius: 10px; }
.scan-frame .br { bottom: 0; right: 0; border-left: none; border-top: none; border-bottom-right-radius: 10px; }
.scan-frame .scan-line {
  position: absolute; left: 6px; right: 6px; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: scan-move 2.6s ease-in-out infinite;
  box-shadow: 0 0 12px 1px rgba(245,166,35,0.7);
}
@keyframes scan-move { 0%, 100% { top: 12px; opacity: 0.4; } 50% { top: 200px; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .scan-frame .scan-line { animation: none; top: 100px; } }

.login-brand h1 { font-size: 34px; max-width: 380px; }
.login-brand .tagline { font-size: 15px; color: var(--text-muted); max-width: 360px; }
.login-stats { display: flex; gap: 32px; margin-top: auto; }
.login-stats div .num { font-family: var(--font-display); font-size: 24px; font-weight: 700; color: var(--accent); }
.login-stats div .lbl { font-size: 12px; color: var(--text-faint); }

.login-form-wrap { display: flex; align-items: center; justify-content: center; padding: 40px; }
.login-form-card { width: 100%; max-width: 380px; }
.login-form-card h2 { font-size: 24px; margin-bottom: 6px; }
.login-form-card > p { margin-bottom: 28px; }
.error-msg { background: var(--bad-soft); color: var(--bad); border-radius: var(--radius-sm); padding: 10px 13px; font-size: 13px; margin-bottom: 16px; display: none; }
.error-msg.show { display: block; }
.hint-msg { font-size: 12px; color: var(--text-faint); margin-top: 18px; text-align: center; }

.scanner-layout { display: grid; grid-template-columns: 1fr 340px; gap: 20px; align-items: start; }
.viewfinder { position: relative; background: #05070D; border-radius: var(--radius-lg); overflow: hidden; aspect-ratio: 4 / 3; border: 1px solid var(--border); }
.viewfinder video, .viewfinder canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.viewfinder .frame-corner { position: absolute; width: 44px; height: 44px; border: 3px solid var(--accent); opacity: 0.85; }
.viewfinder .fc-tl { top: 18px; left: 18px; border-right: none; border-bottom: none; }
.viewfinder .fc-tr { top: 18px; right: 18px; border-left: none; border-bottom: none; }
.viewfinder .fc-bl { bottom: 18px; left: 18px; border-right: none; border-top: none; }
.viewfinder .fc-br { bottom: 18px; right: 18px; border-left: none; border-top: none; }

.viewfinder .status-pill {
  position: absolute; top: 18px; left: 50%; transform: translateX(-50%);
  background: rgba(13,18,32,0.85); border: 1px solid var(--border);
  padding: 7px 16px; border-radius: 100px; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); }
.status-dot.live { background: var(--good); box-shadow: 0 0 8px var(--good); }
.status-dot.busy { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.status-dot.err { background: var(--bad); box-shadow: 0 0 8px var(--bad); }

.result-banner {
  position: absolute; bottom: 18px; left: 18px; right: 18px;
  background: rgba(13,18,32,0.92); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 14px 18px; display: none;
}
.result-banner.show { display: flex; align-items: center; gap: 12px; }
.result-banner.ok { border-color: var(--good); }
.result-banner.no { border-color: var(--bad); }

.feed-item {
  display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); margin-bottom: 10px; background: var(--surface-2);
}
.feed-item .avatar-circle { width: 36px; height: 36px; font-size: 13px; }
.feed-item .meta { flex: 1; min-width: 0; }
.feed-item .meta .n { font-size: 13px; font-weight: 600; }
.feed-item .meta .t { font-size: 11px; color: var(--text-faint); }

.enroll-layout { display: grid; grid-template-columns: 380px 1fr; gap: 24px; }
.enroll-preview { position: relative; background: #05070D; border-radius: var(--radius-lg); overflow: hidden; aspect-ratio: 1; border: 1px solid var(--border); }
.enroll-preview video, .enroll-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(5,7,13,0.7); display: none; align-items: center; justify-content: center; z-index: 50; }
.modal-backdrop.show { display: flex; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 28px; width: 100%; max-width: 460px; box-shadow: var(--shadow-elevated); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

.empty-state { text-align: center; padding: 50px 20px; color: var(--text-faint); }

.toast-stack { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast {
  background: var(--surface-3); border: 1px solid var(--border); border-left: 3px solid var(--info);
  padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13px; min-width: 240px; box-shadow: var(--shadow-elevated);
}
.toast.ok { border-left-color: var(--good); }
.toast.err { border-left-color: var(--bad); }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .tile-row { grid-template-columns: repeat(2, 1fr); }
  .scanner-layout, .enroll-layout { grid-template-columns: 1fr; }
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { display: none; }
}
