* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface-2: #1c1c1c;
  --border: #262626;
  --text: #ffffff;
  --text-dim: #999;
  --text-muted: #666;
  --accent: #ffffff;
  --green: #4caf50;
  --yellow: #ffc107;
  --red: #f44336;
  --blue: #4a9eff;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}
code,
pre {
  font-family: "JetBrains Mono", Menlo, Consolas, monospace;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  font-size: 16px;
}
.brand .logo {
  width: 32px;
  height: 32px;
  background: #000 url("https://archi3.dev/assets/img/icon9.png?2")
    center/contain no-repeat;
  border-radius: 8px;
  font-size: 0; /* hide the "A" fallback text */
  color: transparent;
}
.brand .logo-img {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: cover;
  background: #000;
}
.brand small {
  color: var(--text-dim);
  font-weight: 400;
  font-size: 12px;
  margin-left: 4px;
}
.topbar nav {
  display: flex;
  gap: 4px;
  align-items: center;
}
.topbar nav a {
  color: var(--text-dim);
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  transition: all 0.15s;
}
.topbar nav a:hover,
.topbar nav a.active {
  background: var(--surface-2);
  color: var(--text);
}

/* Logout icon button — circular, icon-only */
.topbar nav a.logout {
  color: var(--text-muted);
  margin-left: 12px;
  padding: 8px;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
}
.topbar nav a.logout:hover {
  color: #f44336;
  border-color: rgba(244, 67, 54, 0.3);
  background: rgba(244, 67, 54, 0.08);
}
.topbar nav a.logout svg {
  width: 18px;
  height: 18px;
  display: block;
}

main {
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}
.stat-num {
  font-size: 28px;
  font-weight: bold;
}
.stat-label {
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 24px;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  gap: 12px;
  flex-wrap: wrap;
}
.card h2 {
  font-size: 16px;
  font-weight: 600;
}
.card h2 small {
  font-weight: 400;
}

.table-wrap {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table thead th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-dim);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  vertical-align: middle;
}
table tbody td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table tbody tr:hover {
  background: var(--surface-2);
}
table .center {
  text-align: center;
  padding: 32px;
}
table .muted {
  color: var(--text-muted);
}
table .small {
  font-size: 11px;
}
.actions {
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
}
.device-id {
  color: var(--text-dim);
  font-size: 11px;
  white-space: nowrap;
  font-family: monospace;
}

/* Inline tag for "[Group Name]" rendered next to device / history row name.
   Faded yellow so it doesn't compete with the device name but is still
   distinct enough to scan-read. */
.group-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(255, 213, 79, 0.10);
  color: #ffd54f;
  border: 1px solid rgba(255, 213, 79, 0.22);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  line-height: 1.4;
  transition: all 0.15s;
}
.btn:hover {
  background: var(--border);
}
.btn.primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}
.btn.primary:hover {
  opacity: 0.9;
}
.btn.ghost {
  background: transparent;
  color: var(--text-dim);
}
.btn.ghost:hover {
  color: var(--text);
}
.btn.danger {
  color: var(--red);
  border-color: rgba(244, 67, 54, 0.3);
}
.btn.danger:hover {
  background: rgba(244, 67, 54, 0.1);
}
.btn.small {
  padding: 5px 10px;
  font-size: 12px;
}

form label {
  display: block;
  color: var(--text-dim);
  font-size: 12px;
  margin-bottom: 6px;
  margin-top: 14px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
form label small {
  text-transform: none;
  color: var(--text-muted);
  letter-spacing: 0;
}
form input[type="text"],
form input[type="password"],
form input[type="number"],
form select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
form input:focus,
form select:focus {
  outline: none;
  border-color: var(--accent);
}
form input:disabled {
  color: var(--text-muted);
  background: var(--surface-2);
  cursor: not-allowed;
}
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}
.filter-form {
  display: flex;
  gap: 8px;
  align-items: center;
}
.filter-form select {
  padding: 6px 10px;
  font-size: 12px;
  min-width: 200px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  padding: 24px;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-card.wide {
  max-width: 720px;
}

/* Buttons inside modal forms tend to sit flush against the last input,
   which reads as cramped (see Reset Password modal). Push them down so
   there's a consistent breathing gap between the last form control and
   the call-to-action below it. Works for all modals — Add/Edit Device,
   Add/Edit Group, Reset PW, etc. */
.modal-card form > .btn,
.modal-card form > button[type="submit"] {
  margin-top: 16px;
}

/* Feature visibility grid — used by BOTH the Add/Edit Device modal AND
   the Add/Edit Group modal so the two views render identically.
   Originally lived inline in admin/index.php's <style> block; moved here
   when the Accounts page also needed the same layout.

   Two-column compact grid: one checkbox + sentence-case label per cell.
   Defeats the global form-label uppercasing so the labels read
   "Face Recognition" instead of "FACE RECOGNITION". */
.feature-toggles {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 12px;
    margin-top: 6px;
    padding: 10px 12px;
    background: #0f0f0f;
    border: 1px solid #2a2a2a;
    border-radius: 8px;
}
.feature-toggle {
    display: flex !important;
    align-items: center;
    gap: 8px;
    text-transform: none !important;
    letter-spacing: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    color: var(--text, #eee) !important;
    font-size: 13px !important;
    cursor: pointer;
}
.feature-toggle input[type="checkbox"] {
    width: auto !important;
    margin: 0 !important;
    transform: scale(1.15);
    accent-color: #fff;
}
.feature-toggle span { user-select: none; }
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.modal-head h3 {
  font-size: 16px;
}
.modal-head .close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 24px;
  cursor: pointer;
  padding: 0 8px;
}
.modal-head .close:hover {
  color: var(--text);
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.badge.active {
  background: rgba(76, 175, 80, 0.15);
  color: var(--green);
}
.badge.blocked {
  background: rgba(244, 67, 54, 0.15);
  color: var(--red);
}
.score-pill {
  display: inline-block;
  background: rgba(74, 158, 255, 0.15);
  color: var(--blue);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  margin-left: 8px;
}

.query-thumb {
  width: 50px;
  height: 50px;
  border-radius: 8px;
  object-fit: cover;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: transform 0.15s, border-color 0.15s;
}
.query-thumb:hover {
  transform: scale(1.08);
  border-color: var(--blue);
}
.thumb-placeholder {
  width: 50px;
  height: 50px;
  background: var(--surface-2);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 18px;
}

.server-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  font-family: monospace;
  letter-spacing: 0.5px;
}
.server-badge.srv-1 {
  background: rgba(74, 158, 255, 0.18);
  color: #6db4ff;
  border: 1px solid rgba(74, 158, 255, 0.3);
}
.server-badge.srv-2 {
  background: rgba(156, 39, 176, 0.18);
  color: #ce93d8;
  border: 1px solid rgba(156, 39, 176, 0.3);
}
.server-badge.srv-imei {
  background: rgba(255, 167, 38, 0.18);
  color: #ffb74d;
  border: 1px solid rgba(255, 167, 38, 0.3);
}

.loc-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(76, 175, 80, 0.12);
  color: #81c784;
  text-decoration: none;
  font-size: 12px;
  border: 1px solid rgba(76, 175, 80, 0.25);
  transition: background 0.15s;
  white-space: nowrap;
}
.loc-link:hover {
  background: rgba(76, 175, 80, 0.22);
}
.loc-link .loc-acc {
  color: #aaa;
  font-size: 10px;
  margin-left: 4px;
  white-space: nowrap;
}

.usage {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 110px;
}
.usage-bar {
  flex: 1;
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
}
.usage-fill {
  height: 100%;
  transition: width 0.3s;
}
.usage-fill.low {
  background: var(--green);
}
.usage-fill.mid {
  background: var(--yellow);
}
.usage-fill.high {
  background: var(--red);
}
.usage span {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}

.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 13px;
}
.alert.success {
  background: rgba(76, 175, 80, 0.1);
  color: var(--green);
  border: 1px solid rgba(76, 175, 80, 0.2);
}
.alert.error {
  background: rgba(244, 67, 54, 0.1);
  color: var(--red);
  border: 1px solid rgba(244, 67, 54, 0.2);
}

.pagination {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.page {
  color: var(--text-dim);
  padding: 6px 12px;
  text-decoration: none;
  border-radius: 6px;
  font-size: 13px;
  border: 1px solid var(--border);
}
.page:hover {
  background: var(--surface-2);
  color: var(--text);
}
.page.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}

.json-view {
  background: var(--bg);
  padding: 16px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
  max-height: 60vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.result-view {
  max-height: 70vh;
  overflow-y: auto;
  padding-right: 4px;
}
.result-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 12px;
}
.result-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.score-badge {
  font-weight: 700;
  font-size: 14px;
  padding: 4px 12px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
}
.nik-code {
  font-family: monospace;
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 0.3px;
}
.result-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
}
.result-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.result-row {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 10px;
  font-size: 13px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.result-row:last-child {
  border-bottom: none;
}
.result-row .rl {
  color: var(--text-dim);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
  padding-top: 1px;
}
.result-row .rv {
  color: var(--text);
  word-break: break-word;
}

.auth-bg {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 24px;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.auth-logo {
  width: 64px;
  height: 64px;
  background: #000 url("https://archi3.dev/assets/img/icon9.png?2")
    center/contain no-repeat;
  border-radius: 16px;
  font-size: 0;
  color: transparent;
  margin: 0 auto 20px;
}
.auth-logo-img {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  object-fit: cover;
  background: #000;
  display: block;
  margin: 0 auto 20px;
}
.auth-card h1 {
  font-size: 20px;
  margin-bottom: 6px;
}
.auth-sub {
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 24px;
}
.auth-card form {
  text-align: left;
}
.auth-card .btn {
  width: 100%;
  margin-top: 24px;
  padding: 12px;
  font-size: 14px;
}

/* === Mobile responsive === */
@media (max-width: 900px) {
  main {
    padding: 16px;
  }
  .stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .stat-card {
    padding: 14px;
  }
  .stat-num {
    font-size: 22px;
  }
  .stat-label {
    font-size: 10px;
  }
  .card {
    padding: 14px;
  }
  .card-head {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .card-head h2 {
    font-size: 16px;
  }
  /* Mobile: filter dropdowns + search input on the History page were
     overflowing the card horizontally because each select was forced
     to a 200px min-width. Stretch every control to the full card width
     and use !important to beat the inline `min-width:220px` on the
     search input (history.php sets it inline for desktop layout). */
  .filter-form {
    flex-wrap: wrap !important;
    gap: 8px;
    width: 100%;
  }
  .filter-form > select,
  .filter-form > input,
  .filter-form > input[type="text"] {
    flex: 1 1 100% !important;
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
  }
  .filter-form > .btn,
  .filter-form > button {
    flex: 1 1 auto;
  }
}

@media (max-width: 720px) {
  .topbar {
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 8px;
    position: relative; /* anchor for absolute logout */
    padding-right: 60px; /* room for logout button */
  }
  .brand {
    font-size: 14px;
    gap: 8px;
  }
  .brand .logo-img {
    width: 28px;
    height: 28px;
  }
  .brand small {
    display: none;
  }
  .topbar nav {
    font-size: 12px;
    flex-wrap: wrap;
    gap: 2px;
    flex: 1 1 100%;
    justify-content: flex-start;
  }
  .topbar nav a {
    padding: 6px 10px;
    font-size: 12px;
  }

  /* Pin logout button to top-right corner, aligned with brand row */
  .topbar nav a.logout {
    position: absolute;
    top: 10px;
    right: 14px;
    margin-left: 0;
  }
  main {
    padding: 12px;
  }

  .filter-row {
    gap: 6px !important;
  }
  .filter-row input,
  .filter-row select {
    font-size: 13px !important;
    padding: 8px 10px !important;
    flex: 1 1 100%;
    min-width: 0;
  }
  .filter-row .btn {
    flex: 0 0 auto;
  }

  .actions {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px !important;
    align-items: stretch;
  }
  .actions .btn,
  .actions form {
    flex: 1 1 calc(50% - 4px);
  }
  .actions form {
    display: flex !important;
  }
  .actions form .btn {
    width: 100%;
  }

  /* Tables: keep horizontal scroll, but make cells more compact */
  table {
    font-size: 12px;
  }
  table thead th,
  table tbody td {
    padding: 10px 8px;
  }
  .device-id {
    font-size: 10px !important;
  }

  /* Modal: full width on mobile */
  .modal {
    padding: 0 !important;
    align-items: flex-end !important;
  }
  .modal-card,
  .modal-card.wide {
    max-width: 100% !important;
    width: 100% !important;
    max-height: 95vh !important;
    border-radius: 16px 16px 0 0 !important;
    padding: 16px !important;
  }

  /* Result modal cards more compact */
  .result-card {
    padding: 14px !important;
  }
  .result-row {
    grid-template-columns: 90px 1fr !important;
    gap: 10px !important;
    font-size: 12px !important;
  }
  .result-row .rl {
    font-size: 10px !important;
  }

  /* Stats stack 2 columns */
  .stats {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Hide drag-handle / brand small text */
  .brand small {
    display: none;
  }
}

@media (max-width: 480px) {
  .stats {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .stat-card {
    padding: 12px;
  }
  .stat-num {
    font-size: 20px;
  }
  .actions .btn,
  .actions form {
    flex: 1 1 100%;
  }
  table thead th,
  table tbody td {
    padding: 8px 6px;
    font-size: 11px;
  }
  .topbar nav a {
    padding: 5px 8px;
    font-size: 11px;
  }
}

/* === Custom Scrollbars (dark-theme matched) === */

/* Webkit (Chrome, Safari, Edge, Brave) */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #2a2a2a;
  border-radius: 5px;
  border: 2px solid #0a0a0a;
}
::-webkit-scrollbar-thumb:hover {
  background: #3a3a3a;
}
::-webkit-scrollbar-corner {
  background: transparent;
}

/* Specifically for the table-wrap horizontal scroller */
.table-wrap::-webkit-scrollbar {
  height: 8px;
}
.table-wrap::-webkit-scrollbar-track {
  background: #141414;
  border-radius: 0 0 12px 12px;
}
.table-wrap::-webkit-scrollbar-thumb {
  background: #333;
  border-radius: 4px;
  border: 2px solid #141414;
}
.table-wrap::-webkit-scrollbar-thumb:hover {
  background: #4a9eff;
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: #2a2a2a transparent;
}
.table-wrap {
  scrollbar-color: #333 #141414;
}
