/* Relies on /css/tokens.css being loaded first for --dl-* variables and the
   base body/box-sizing reset. */

a { color: inherit; }

/* ── Topbar ──────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  background: rgba(255, 255, 255, .85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--dl-border);
}
.brand { font-weight: 800; text-decoration: none; color: var(--dl-text); font-size: 15px; }
.area-label {
  color: var(--dl-text-muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 3px 8px;
  background: var(--dl-surface-alt);
  border-radius: 999px;
}
.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
}
.badge-muted { color: var(--dl-text-muted); background: var(--dl-surface-alt); }
.spacer { flex: 1; }
#user-chip { font-size: 13px; color: var(--dl-text-muted); }
@media (max-width: 560px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 12px 16px; }
  #user-chip { display: none; }
}

/* ── Buttons ─────────────────────────────────────────────────────────── */
button {
  font: inherit;
  padding: 9px 18px;
  border-radius: var(--dl-radius-sm);
  border: 1px solid var(--dl-border);
  background: var(--dl-surface);
  color: var(--dl-text);
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
button:hover { background: var(--dl-surface-alt); }
button:active { transform: scale(.98); }
button.btn-secondary { background: var(--dl-surface); }

#btn-signin, #btn-signin-main, #btn-confirm-assign, #btn-request-access,
#btn-enroll-device, #btn-open-console, #btn-import-places, #btn-confirm-expiry {
  background: var(--dl-brand);
  color: #fff;
  border-color: var(--dl-brand);
}
#btn-signin:hover, #btn-signin-main:hover, #btn-confirm-assign:hover, #btn-request-access:hover,
#btn-enroll-device:hover, #btn-open-console:hover, #btn-import-places:hover, #btn-confirm-expiry:hover {
  background: var(--dl-brand-hover);
}

/* ── Centered (sign-in / status) screens ─────────────────────────────── */
.centered {
  max-width: 480px;
  margin: 72px auto;
  padding: 0 24px;
  text-align: center;
}
.centered h1 { font-size: 22px; font-weight: 800; margin-bottom: 12px; letter-spacing: -0.01em; }
.centered p { color: var(--dl-text-muted); margin-bottom: 20px; line-height: 1.6; }
.centered label { display: block; text-align: left; font-size: 13px; margin-bottom: 6px; color: var(--dl-text-muted); font-weight: 500; }
.centered input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--dl-border);
  border-radius: var(--dl-radius-sm);
  margin-bottom: 16px;
  font: inherit;
}
.centered input:focus, input:focus, select:focus { outline: 2px solid var(--dl-accent); outline-offset: 1px; }

.muted { color: var(--dl-text-faint); font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; }

/* ── Inline callout (info/warning box within a panel) ─────────────────── */
.callout-box {
  border: 1px solid var(--dl-border);
  background: var(--dl-surface-alt);
  border-radius: var(--dl-radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  color: var(--dl-text);
  margin-bottom: 16px;
}
.callout-box[hidden] { display: none; }

/* ── Panels ──────────────────────────────────────────────────────────── */
.panel {
  max-width: 960px;
  margin: 28px auto;
  padding: 24px;
  background: var(--dl-surface);
  border: 1px solid var(--dl-border);
  border-radius: var(--dl-radius-lg);
  box-shadow: var(--dl-shadow-sm);
  overflow-x: auto;
}
@media (max-width: 640px) {
  .panel { margin: 16px; padding: 16px; border-radius: var(--dl-radius); }
}
.panel h1 { font-size: 18px; font-weight: 800; margin-bottom: 16px; letter-spacing: -0.01em; }

.panel-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.panel-header-row h1 { margin-bottom: 0; }
.panel-header-actions { display: flex; gap: 8px; }

/* ── Bulk-select bar ─────────────────────────────────────────────────── */
.bulk-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 24px;
  margin-bottom: 8px;
}
#devices-table th:first-child, #devices-table td:first-child { width: 32px; }

/* ── Audit log filters (Console) ─────────────────────────────────────── */
.auditlog-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.auditlog-filters select, .auditlog-filters input {
  padding: 8px 10px;
  border: 1px solid var(--dl-border);
  border-radius: var(--dl-radius-sm);
  font-size: 13px;
  background: var(--dl-surface);
  color: var(--dl-text);
}
.auditlog-filters input { min-width: 180px; }

/* ── Tables (horizontally scrollable on narrow screens via .panel's own
   overflow-x, not restructured into cards -- keeps existing JS hooks
   untouched) ──────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; background: var(--dl-surface); min-width: 480px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--dl-border); font-size: 13px; white-space: nowrap; }
th { background: var(--dl-surface-alt); font-weight: 600; color: var(--dl-text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--dl-surface-alt); }

/* ── Inline collapsible "Manage" row (Console customers table) ───────── */
.manage-row[hidden] { display: none; }
.manage-row td {
  background: var(--dl-surface-alt);
  padding: 0;
  white-space: normal;
}
.manage-row:hover td { background: var(--dl-surface-alt); }
.manage-panel { padding: 18px 20px; }
.manage-panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px 24px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--dl-border);
}
.manage-panel-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.manage-trigger.active { background: var(--dl-accent-soft); color: var(--dl-accent); border-color: transparent; }

/* ── Collapsible hierarchy trees (main places tree + import dialog) ──── */
#places-tree details, #import-tree details {
  border: 1px solid var(--dl-border);
  border-radius: var(--dl-radius-sm);
  margin-bottom: 8px;
  background: var(--dl-surface);
  overflow: hidden;
}
#places-tree > details, #import-tree > .tree-node { margin-top: 12px; }
#places-tree summary, #import-tree summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 14px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  background: var(--dl-surface-alt);
  list-style: none;
}
#places-tree summary::-webkit-details-marker, #import-tree summary::-webkit-details-marker { display: none; }
#places-tree summary::before, #import-tree summary::before { content: '▸ '; color: var(--dl-text-muted); }
#places-tree details[open] > summary::before, #import-tree details[open] > summary::before { content: '▾ '; }
#places-tree details details summary, #import-tree .tree-node-floor summary { background: var(--dl-bg); font-weight: 500; }
#import-tree .tree-node-section summary { background: var(--dl-bg); font-weight: 400; font-size: 12px; color: var(--dl-text-muted); }

.desk-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px 10px 28px;
  border-top: 1px solid var(--dl-border);
  font-size: 13px;
  flex-wrap: wrap;
}
.desk-row .desk-name { flex: 1; min-width: 120px; font-weight: 500; }
.desk-row .desk-device { color: var(--dl-text-muted); }
.desk-row[hidden] { display: none; }

.tree-node[hidden] { display: none; }
/* The group checkbox lives inside <summary> now (see makeGroupNode() in
   admin/js/app.js) -- stopPropagation() on its own click is what stops it
   also toggling the native disclosure, not DOM position, so .tree-node
   itself is just a plain block wrapper around one <details>. */
.tree-checkbox { flex-shrink: 0; }
.tree-node-label { flex: 1; }
.tree-node-floor, .tree-node-section { margin: 8px 0 8px 14px; }

/* ── Dialogs ─────────────────────────────────────────────────────────── */
.backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .55);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
/* An author-stylesheet rule always wins over the UA stylesheet's
   [hidden]{display:none}, even at equal specificity -- without this, the
   backdrop above renders visible (and covers the whole screen, blocking
   everything including sign-in) regardless of the hidden attribute. */
.backdrop[hidden] { display: none; }
.dialog {
  background: var(--dl-surface);
  border-radius: var(--dl-radius-lg);
  box-shadow: var(--dl-shadow-lg);
  padding: 24px;
  width: 380px;
  max-width: 100%;
}
.dialog h2 { font-size: 16px; font-weight: 800; margin-bottom: 16px; }
.dialog label { display: block; font-size: 13px; margin-bottom: 6px; color: var(--dl-text-muted); font-weight: 500; }
/* :not([type="checkbox"]):not([type="radio"]) -- THE actual bug behind
   the import dialog looking blank: this rule used to match every <input>
   in any .dialog with no exclusion, including the tree/desk checkboxes
   built by makeGroupNode(), which live inside the Import dialog (a
   .dialog). width:100% + margin-bottom:20px forced every checkbox to
   demand the full row width with a huge gap after it, squeezing its
   label text off to the side and overflowing the dialog horizontally --
   exactly the wide-scrollbar, big-gaps, no-visible-text symptom reported.
   The main Desks & rooms tree never showed this because it isn't inside
   a .dialog at all, so this rule never touched its checkboxes. Two
   earlier fixes (a flex min-width tweak, then moving the checkbox inside
   <summary>) both missed this because neither addressed the checkbox
   actually being stretched -- confirmed by testing the real DOM output
   against live data before landing on this. */
.dialog select, .dialog input:not([type="checkbox"]):not([type="radio"]) {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--dl-border);
  border-radius: var(--dl-radius-sm);
  margin-bottom: 20px;
  font: inherit;
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dialog-wide { width: 560px; }

button.btn-danger { color: var(--dl-danger); border-color: #FCA5A5; }
button.btn-danger:hover { background: #FEF2F2; }

/* ── Settings form ───────────────────────────────────────────────────── */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
@media (max-width: 640px) { .settings-grid { grid-template-columns: 1fr; } }
.settings-grid-full { grid-column: 1 / -1; }
.settings-grid label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.field-hint { color: var(--dl-text-muted); font-size: 12px; margin-bottom: 8px; }
.settings-grid input[type="text"], .settings-grid input[type="email"], .settings-grid select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--dl-border);
  border-radius: var(--dl-radius-sm);
  font: inherit;
}
.checkbox-row { display: flex !important; align-items: center; gap: 8px; font-weight: 400 !important; font-size: 13px; }
.checkbox-row input { width: auto !important; }
.settings-actions { display: flex; align-items: center; gap: 12px; margin-top: 24px; }

/* ── Places import selection dialog ─────────────────────────────────── */
.import-toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.import-toolbar .muted { margin-left: auto; }
.import-list {
  max-height: 360px;
  overflow-y: auto;
  border: 1px solid var(--dl-border);
  border-radius: var(--dl-radius-sm);
  margin-bottom: 20px;
}
.import-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--dl-border);
  font-size: 13px;
}
.import-row:last-child { border-bottom: none; }
.import-row input[type="checkbox"] { width: auto; flex-shrink: 0; }
.import-row .import-path { color: var(--dl-text-muted); font-size: 12px; }

/* ── Loading screen ──────────────────────────────────────────────────── */
.loading-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--dl-text-muted);
  font-size: 13px;
}
/* Same gotcha as .backdrop below: an author display:flex rule always beats
   the UA stylesheet's [hidden]{display:none}, even at equal specificity --
   without this override the screen never actually goes away once boot()
   sets hidden=true, regardless of which real screen should show instead. */
.loading-screen[hidden] { display: none; }
.loading-screen .spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--dl-border);
  border-top-color: var(--dl-brand);
  border-radius: 50%;
  animation: dl-spin .8s linear infinite;
}
@keyframes dl-spin { to { transform: rotate(360deg); } }

/* ── Sidebar app shell (Admin) ────────────────────────────────────────── */
.app-shell { display: flex; align-items: flex-start; }
.app-sidebar {
  width: 200px;
  flex-shrink: 0;
  border-right: 1px solid var(--dl-border);
  padding: 16px 8px;
  transition: width .15s ease;
  overflow: hidden;
  align-self: stretch;
}
.app-sidebar.collapsed { width: 52px; }
.sidebar-toggle {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 8px;
  cursor: pointer;
  font-size: 16px;
  color: var(--dl-text-muted);
  margin-bottom: 12px;
}
.sidebar-toggle:hover { color: var(--dl-text); }
.sidebar-nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: none;
  background: transparent;
  border-radius: var(--dl-radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--dl-text-muted);
  cursor: pointer;
  white-space: nowrap;
}
.sidebar-nav-item:hover { background: var(--dl-surface-alt); color: var(--dl-text); }
.sidebar-nav-item.active { background: var(--dl-accent-soft); color: var(--dl-accent); font-weight: 700; }
.sidebar-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}
.sidebar-icon svg { width: 100%; height: 100%; }
.app-sidebar.collapsed .sidebar-label { display: none; }
.app-sidebar.collapsed .sidebar-nav-item { justify-content: center; padding: 10px; }
.app-main { flex: 1; min-width: 0; padding: 24px; }
.app-view[hidden] { display: none; }
@media (max-width: 760px) {
  .app-shell { flex-direction: column; }
  .app-sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--dl-border); }
  .app-sidebar.collapsed { width: 100%; }
  .sidebar-nav { flex-direction: row; flex-wrap: wrap; }
}

/* ── Search bars + filters (Devices / Desks & rooms) ──────────────────── */
.search-row { margin: 12px 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.search-input {
  flex: 1 1 260px;
  max-width: 360px;
  padding: 9px 12px;
  border: 1px solid var(--dl-border);
  border-radius: var(--dl-radius-sm);
  font-size: 13px;
  background: var(--dl-surface);
  color: var(--dl-text);
}
.search-input:focus { outline: none; border-color: var(--dl-accent); box-shadow: 0 0 0 3px var(--dl-accent-soft); }
.search-input::placeholder { color: var(--dl-text-muted); }
.filter-select {
  padding: 9px 12px;
  border: 1px solid var(--dl-border);
  border-radius: var(--dl-radius-sm);
  font-size: 13px;
  font: inherit;
  background: var(--dl-surface);
  color: var(--dl-text);
}
.filter-select:focus { outline: none; border-color: var(--dl-accent); box-shadow: 0 0 0 3px var(--dl-accent-soft); }

/* ── Pagination bar ───────────────────────────────────────────────────── */
.pagination-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}

/* ── Toast notifications ──────────────────────────────────────────────── */
#toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 40px));
}
.dl-toast {
  padding: 12px 16px;
  border-radius: var(--dl-radius-sm);
  font-size: 13px;
  line-height: 1.5;
  color: #fff;
  box-shadow: var(--dl-shadow);
  animation: dl-toast-in .18s ease-out;
}
.dl-toast-error { background: #DC2626; }
.dl-toast-info { background: #0F172A; }
.dl-toast-success { background: #16A34A; }
@keyframes dl-toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Processing overlay (bulk/multi-step operations) ─────────────────── */
.processing-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(15, 23, 42, .55);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: #fff;
  font-size: 14px;
}
/* Same [hidden]-vs-author-display gotcha as .loading-screen/.backdrop --
   see the comment above .loading-screen[hidden] for why this is needed. */
.processing-overlay[hidden] { display: none; }
.processing-overlay .spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: dl-spin .8s linear infinite;
}

/* ── Help drawer ──────────────────────────────────────────────────────── */
.help-backdrop {
  position: fixed;
  inset: 0;
  z-index: 190;
  background: rgba(15, 23, 42, .35);
}
.help-backdrop[hidden] { display: none; }

.help-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 191;
  width: min(420px, 100vw);
  background: var(--dl-surface);
  border-left: 1px solid var(--dl-border);
  box-shadow: var(--dl-shadow);
  padding: 20px 24px;
  overflow-y: auto;
  animation: dl-slide-in .18s ease-out;
}
.help-drawer[hidden] { display: none; }
@keyframes dl-slide-in { from { transform: translateX(24px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.help-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.help-drawer-header h2 { font-size: 17px; font-weight: 800; }
.help-drawer .btn-close-icon {
  background: transparent;
  border: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--dl-text-muted);
  padding: 4px 8px;
}
.help-drawer .btn-close-icon:hover { color: var(--dl-text); }
.help-drawer section { margin-bottom: 20px; }
.help-drawer h3 { font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.help-drawer p { color: var(--dl-text-muted); font-size: 13px; line-height: 1.6; }

/* ── User chip + popover ─────────────────────────────────────────────── */
.user-menu { position: relative; }
.user-chip-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: transparent;
  border: none;
  padding: 6px 8px;
  font-size: 13px;
  color: var(--dl-text-muted);
}
.user-chip-btn:hover { background: var(--dl-surface-alt); }
.user-chip-btn::after { content: '▾'; font-size: 10px; }
.user-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 280px;
  background: var(--dl-surface);
  border: 1px solid var(--dl-border);
  border-radius: var(--dl-radius);
  box-shadow: var(--dl-shadow-lg);
  padding: 16px;
  z-index: 20;
}
.popover-field { margin-bottom: 12px; }
.popover-field:last-child { margin-bottom: 0; }
.popover-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--dl-text-faint);
  margin-bottom: 2px;
}
.popover-field > span:not(.popover-label) { font-size: 13px; word-break: break-word; }

/* ── Maintenance banner ──────────────────────────────────────────────── */
.maintenance-banner {
  background: #FEF3C7;
  color: #92400E;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  padding: 10px 16px;
}
