/* ==========================================================================
   Portal for Access Management — visual identity
   Palette: graphite/indigo surface + brass accent (physical key/lock motif)
   Display: Space Grotesk · Body: Inter · Data/IDs: JetBrains Mono
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg:        #14161c;
  --surface:   #1b1e27;
  --surface-2: #232733;
  --border:    #2e3340;
  --text:      #edeff4;
  --text-dim:  #9aa1b3;
  --text-faint:#666c7c;

  --brass:     #c9a15a;
  --brass-hi:  #e0bc7c;
  --brass-dim: #7d6534;

  --success:   #6fbf8b;
  --danger:    #e2665a;
  --danger-dim:#4a2b2a;

  --radius: 10px;
  --radius-lg: 16px;

  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  background-image:
    radial-gradient(circle at 15% 0%, rgba(201,161,90,0.06), transparent 45%),
    radial-gradient(circle at 100% 20%, rgba(201,161,90,0.04), transparent 40%);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

h1, h2, h3, .display {
  font-family: var(--font-display);
  letter-spacing: -0.01em;
}

::selection { background: var(--brass-dim); color: #fff; }

:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------- auth --- */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  text-align: center;
}
.auth-mark {
  color: var(--brass);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px; height: 64px;
  border: 1px solid var(--border);
  border-radius: 50%;
  margin-bottom: 20px;
}
.auth-card h1 { font-size: 22px; margin: 0 0 6px; }
.auth-sub { color: var(--text-dim); font-size: 14px; margin: 0 0 24px; }
.auth-form { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.auth-form label { font-size: 12px; color: var(--text-dim); margin-top: 12px; }

input, select, textarea {
  font-family: var(--font-body);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 14px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--brass); }

/* native date/time picker in dark mode, to match the rest of the UI */
input[type="datetime-local"],
input[type="date"],
input[type="time"] {
  color-scheme: dark;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 16px;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, transform .05s ease;
}
.btn:hover { border-color: var(--brass-dim); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brass); border-color: var(--brass); color: #1a1206; }
.btn-primary:hover { background: var(--brass-hi); border-color: var(--brass-hi); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.btn-block { width: 100%; margin-top: 22px; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn-ghost { background: transparent; }

.alert { border-radius: var(--radius); padding: 10px 14px; font-size: 13px; margin-bottom: 16px; }
.alert-error { background: var(--danger-dim); color: #ffb4ac; border: 1px solid #6b3a37; }
.alert-success { background: #1d3327; color: #9be0b6; border: 1px solid #2c5a3f; }

/* ------------------------------------------------------------- shell --- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 22px;
  color: var(--brass);
}
.brand svg { flex-shrink: 0; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 15px; color: var(--text); }
.brand-name small { display: block; font-family: var(--font-mono); font-weight: 400; font-size: 10.5px; color: var(--text-faint); letter-spacing: .04em; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-dim);
  cursor: pointer;
  border: 1px solid transparent;
}
.nav-item:hover { color: var(--text); background: var(--surface-2); }
.nav-item.active { color: var(--brass-hi); background: var(--surface-2); border-color: var(--border); }
.nav-item .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-faint); }
.nav-item.active .dot { background: var(--brass); }

.sidebar-foot {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--text-faint);
}

.main { flex: 1; padding: 28px 34px 60px; max-width: 1180px; }

.page-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 22px; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 21px; margin: 0; }
.page-head p { color: var(--text-dim); font-size: 13.5px; margin: 4px 0 0; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* device selector chip row */
.device-picker { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 22px; }
.device-chip {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
}
.device-chip.active { border-color: var(--brass); color: var(--brass-hi); background: rgba(201,161,90,0.08); }

/* ------------------------------------------------------------- cards --- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
}

.device-card { display: flex; gap: 14px; align-items: flex-start; }

/* signature element: keyhole status ring, fills brass when unlocked */
.status-ring {
  --p: 0;
  width: 52px; height: 52px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(circle, var(--surface) 60%, transparent 61%),
    conic-gradient(var(--brass) calc(var(--p) * 1%), var(--border) 0);
  transition: background 1.2s ease;
}
.status-ring svg { color: var(--brass); }
.status-ring.locked { --p: 100; }
.status-ring.unlocked { --p: 0; animation: ring-pulse 1.6s ease infinite; }
@keyframes ring-pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.35); }
}
@media (prefers-reduced-motion: reduce) {
  .status-ring.unlocked { animation: none; }
}

.device-name { font-family: var(--font-display); font-weight: 600; font-size: 15px; margin: 0 0 2px; }
.device-id { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); }
.device-status { font-size: 12.5px; margin-top: 6px; display: inline-flex; align-items: center; gap: 6px; }
.device-status.online { color: var(--success); }
.device-status.offline { color: var(--text-faint); }
.device-status .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.device-actions { margin-top: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.device-actions .btn:nth-child(3) { grid-column: 1 / -1; }

/* ------------------------------------------------------------- table --- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border); color: var(--text); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.mono { font-family: var(--font-mono); font-size: 12.5px; color: var(--text-dim); }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.badge-admin { color: var(--brass-hi); border-color: var(--brass-dim); background: rgba(201,161,90,.08); }
.badge-common { color: var(--text-dim); }
.badge-permanent { color: var(--success); border-color: #2c5a3f; }
.badge-scheduled { color: #8fb3e0; border-color: #2c4a6a; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-faint);
}
.empty-state svg { color: var(--text-faint); margin-bottom: 12px; }
.empty-state h3 { color: var(--text-dim); font-size: 15px; margin: 0 0 6px; }
.empty-state p { font-size: 13px; margin: 0; }

/* ------------------------------------------------------------- modal --- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10,11,15,0.65);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  padding: 20px;
}
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  width: 100%; max-width: 420px; padding: 24px;
  overflow-x: hidden;
  box-sizing: border-box;
}
.modal h2 { font-size: 17px; margin: 0 0 16px; }
.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-row label { font-size: 12px; color: var(--text-dim); }
.form-row-inline { display: flex; gap: 10px; min-width: 0; }
.form-row-inline > * { flex: 1; min-width: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* door checklist (used in add/edit user + temp password modals) */
.door-check-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
}
.door-check-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s ease;
}
.door-check-item:hover { background: var(--surface-2); }
.door-check-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--brass);
  cursor: pointer;
}
.door-check-item span {
  font-size: 13.5px;
  color: var(--text);
  line-height: 1.3;
}
.door-check-empty {
  color: var(--text-faint);
  font-size: 13px;
  padding: 8px 4px;
}

.hidden { display: none !important; }

.toast-wrap { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 16px; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.35);
  animation: toast-in .2s ease;
}
.toast.success { border-color: #2c5a3f; color: #9be0b6; }
.toast.error { border-color: #6b3a37; color: #ffb4ac; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 780px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .sidebar-foot { display: none; }
  .brand { display: none; }
  .main { padding: 20px; }
}