/* Material Library — styles */
:root {
  --bg: #0f1115;
  --bg-2: #171a21;
  --panel: #1d2129;
  --panel-2: #252b36;
  --border: #303845;
  --text: #e6e8ee;
  --muted: #8892a3;
  --accent: #4c9aff;
  --accent-2: #2f7fe8;
  --warn: #f7a643;
  --danger: #e5484d;
  --ok: #46a758;
  --shelf: #3a4356;
  --shelf-hi: #506180;
  --shelf-empty: #262c37;
  --map-bg: #1a1d24;
  --floor-tint: 1;      /* multiplier on floorplan brightness — dimmed in dark mode */
  --zone-label-fill: #cfd4dd;
  --zone-sub-fill: #8892a3;
  --shelf-num-fill: #1e2430;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --pad: 12px;
}
:root[data-theme="light"] {
  --bg: #f7f7f9;
  --bg-2: #ffffff;
  --panel: #ffffff;
  --panel-2: #eef0f4;
  --border: #d8dbe1;
  --text: #1e2430;
  --muted: #626b7a;
  --accent: #2f7fe8;
  --accent-2: #1e5fbf;
  --warn: #d97706;
  --danger: #c5292e;
  --ok: #2f7d3d;
  --shelf: #cad4e3;
  --shelf-hi: #a8b7d0;
  --shelf-empty: #eef1f6;
  --map-bg: #f4f2ee;
  --floor-tint: 1;
  --zone-label-fill: #1e2430;
  --zone-sub-fill: #384051;
  --shelf-num-fill: #1e2430;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 14px;
  overflow: hidden;
}
button {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 12px; cursor: pointer;
}
button:hover { background: var(--border); }
button.primary { background: var(--accent); border-color: var(--accent); }
button.primary:hover { background: var(--accent-2); }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button.danger:hover { background: rgba(229,72,77,0.12); }
button.ghost { background: transparent; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg-2);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* -------- layout -------- */
#app {
  display: grid;
  /* Rows: header, division bar, subdivision bar (auto = collapses to 0 when
     hidden via display:none), then the main content takes the rest.
     Children below pin themselves to explicit rows so display:none on the
     subdivision bar doesn't shift `main` up into the auto track (which would
     make main 0px tall and blank the map). */
  grid-template-rows: 56px 40px auto 1fr;
  grid-template-columns: 1fr;
  height: 100vh;
  /* Use JS-measured visible height when available (set by the inline script
     in index.html). Fixes bottom-content cutoff on iPad and iPhone Safari
     where CSS viewport units can lie about the true visible area. */
  height: var(--app-height, 100vh);
}
#app > header.topbar { grid-row: 1; }
#app > #filter-bar   { grid-row: 2; }
#app > #filter-bar-sub { grid-row: 3; }
#app > main          { grid-row: 4; }
header.topbar {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-2); border-bottom: 1px solid var(--border);
  padding: 0 12px;
}
.brand { font-weight: 600; font-size: 15px; letter-spacing: 0.2px; }
.brand .accent { color: var(--accent); }
.topbar nav { display: flex; gap: 2px; }
.topbar nav button { background: transparent; border: 1px solid transparent; padding: 4px 8px; font-size: 13px; white-space: nowrap; }
.topbar nav button.active { background: var(--panel); border-color: var(--border); }
.topbar .spacer { flex: 1; }
.topbar .searchbox { position: relative; width: 240px; min-width: 160px; }
.topbar .searchbox input { width: 100%; padding-left: 30px; }
.topbar .searchbox::before {
  content: "🔍"; position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  opacity: 0.5; font-size: 12px;
}
.user-chip {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px; border: 1px solid var(--border); border-radius: 20px;
  color: var(--muted); font-size: 13px; cursor: pointer;
}
.user-chip:hover { color: var(--text); }

/* -------- main -------- */
main {
  position: relative; overflow: hidden;
  background:
    radial-gradient(1200px 800px at 30% 20%, rgba(76,154,255,0.05), transparent 60%),
    radial-gradient(1200px 800px at 80% 90%, rgba(70,167,88,0.03), transparent 60%);
}
main .stage-wrap { position: absolute; inset: 0; overflow: hidden; }
main svg#stage {
  width: 100%; height: 100%; display: block; user-select: none;
  touch-action: none; /* Let our JS handle single-finger pan and pinch-zoom */
}
main svg#stage.grabbing { cursor: grabbing; }
main svg#stage { cursor: grab; }
/* Light mode: OS grab cursor is a light gray hand and disappears against
   the white floor plan. Swap in a standard mouse-arrow cursor with a slim
   1px black outline so it stays visible on white. Same shape as the OS
   pointer, just outlined. Falls back to grab if the data URI fails.
   Hotspot 3,3 = the tip of the arrow. */
:root[data-theme="light"] main svg#stage {
  cursor:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='22' height='26' viewBox='0 0 22 26'><path d='M3,3 L3,20 L7.5,16 L10.5,22 L13.5,21 L10.5,15 L16.5,15 Z' fill='white' stroke='black' stroke-width='1' stroke-linejoin='miter'/></svg>") 3 3,
    grab;
}
:root[data-theme="light"] main svg#stage.grabbing {
  cursor:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='22' height='26' viewBox='0 0 22 26'><path d='M3,3 L3,20 L7.5,16 L10.5,22 L13.5,21 L10.5,15 L16.5,15 Z' fill='%23dcdcdc' stroke='black' stroke-width='1' stroke-linejoin='miter'/></svg>") 3 3,
    grabbing;
}

/* zoom controls */
.zoom-controls {
  position: absolute; right: 16px; bottom: 16px;
  display: flex; flex-direction: column; gap: 6px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px; box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
.zoom-controls button { width: 34px; height: 34px; padding: 0; font-size: 16px; }
.zoom-controls .zoom-level {
  text-align: center; font-size: 11px; color: var(--muted); padding: 2px 0;
}

/* -------- shelf detail panel -------- */
.side-panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: 480px; max-width: 92vw;
  background: var(--panel); border-left: 1px solid var(--border);
  box-shadow: -12px 0 40px rgba(0,0,0,0.4);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform 0.22s ease;
  z-index: 20;
}
.side-panel.open { transform: translateX(0); }
.side-panel header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.side-panel header .shelf-badge {
  background: var(--accent); color: white; font-weight: 700;
  padding: 4px 10px; border-radius: 6px; font-size: 13px;
}
.side-panel header .title { flex: 1; }
.side-panel header .title h2 { margin: 0; font-size: 16px; }
.side-panel header .title .subtitle { color: var(--muted); font-size: 12px; }
.side-panel .toolbar {
  display: flex; gap: 8px; padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.side-panel .list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  /* Classic flexbox-scroll fix: without min-height: 0 the flex child can't
     shrink below its content, so overflow-scroll never actually caps the
     list at the panel's height and the bottom material sits below the
     visible edge. Applies to iPad, iPhone, and any narrow viewport. */
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}
/* Real box (pseudo-element) that IS included in the scroll extent — gives
   the last material card breathing room and works around iOS Safari's
   padding-bottom-not-counted quirk. env() adds home-indicator clearance
   where the OS reports one. */
.side-panel .list::after {
  content: "";
  display: block;
  height: calc(env(safe-area-inset-bottom, 0px) + 40px);
}
.material-card {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px; margin-bottom: 8px;
}
.material-card .row1 { display: flex; align-items: baseline; gap: 8px; }
.material-card .desc { font-weight: 600; flex: 1; }
.material-card .division {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 6px; font-size: 11px; color: var(--muted);
}
.material-card .subdivision {
  background: transparent; border: 1px dashed var(--border);
  border-radius: 4px; padding: 2px 6px; font-size: 11px; color: var(--muted);
  font-style: italic;
}
.material-card .manu { color: var(--muted); font-size: 13px; margin-top: 2px; }
.material-card .meta { color: var(--muted); font-size: 12px; margin-top: 6px; }
.material-card .notes { color: var(--muted); font-size: 12px; margin-top: 6px; font-style: italic; }
.material-card .actions { display: flex; gap: 6px; margin-top: 10px; }
.material-card.checked-out { border-color: var(--warn); }
/* Green pulse applied by openLocateView when the user was looking for one
   specific material — pulls the eye to the right card among siblings. */
.material-card.flash-target {
  animation: material-flash 2.2s ease-out 1;
}
@keyframes material-flash {
  0%   { border-color: var(--ok); box-shadow: 0 0 0 3px rgba(70,167,88,0.55); background: rgba(70,167,88,0.18); }
  60%  { border-color: var(--ok); box-shadow: 0 0 0 2px rgba(70,167,88,0.28); background: rgba(70,167,88,0.08); }
  100% { border-color: var(--border); box-shadow: none; background: var(--bg-2); }
}
.material-card .status-badge {
  padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600;
}
.material-card .status-badge.out { background: rgba(247,166,67,0.15); color: var(--warn); }
.material-card .status-badge.in  { background: rgba(70,167,88,0.15); color: var(--ok); }
.material-card .mat-link {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600;
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--muted); text-decoration: none; white-space: nowrap;
}
.material-card .mat-link:hover { color: var(--accent, #4a9eff); border-color: var(--accent, #4a9eff); }

.empty { color: var(--muted); text-align: center; padding: 32px 20px; }

/* Grouped unassigned list */
.unassigned-group { margin-bottom: 14px; }
.unassigned-group-header {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border-bottom: 1px solid var(--border);
  padding: 8px 6px 6px; margin: 4px 0 8px;
  font-size: 12px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--muted); font-weight: 700;
}
.unassigned-group-header .cat-name { flex: 1; color: var(--text); }
.unassigned-group-header .cat-count {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 2px 8px; font-size: 11px;
  color: var(--muted); font-weight: 600; letter-spacing: 0;
}

/* -------- dialog -------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.dialog {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  min-width: 420px; max-width: 92vw; max-height: 90vh; overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.dialog header {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.dialog header h3 { margin: 0; font-size: 15px; flex: 1; }
.dialog .body { padding: 16px 18px; overflow-y: auto; }
.dialog footer {
  padding: 12px 18px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end;
}
.form-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.form-row label { font-size: 12px; color: var(--muted); }
.form-row.two { flex-direction: row; gap: 10px; }
.form-row.two > div { flex: 1; display: flex; flex-direction: column; gap: 4px; }

/* -------- stats view -------- */
.stats-view {
  position: absolute; inset: 0; overflow-y: auto; padding: 24px 32px;
}
.stats-view h2 { margin-top: 0; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 12px; }
.stat-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px;
}
.stat-card h3 { margin: 0 0 12px 0; font-size: 14px; }
.leader-row {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 0; border-bottom: 1px solid var(--border);
}
.leader-row:last-child { border-bottom: none; }
.leader-row .rank { width: 24px; color: var(--muted); font-size: 12px; }
.leader-row .name { flex: 1; }
.leader-row .count {
  background: var(--panel-2); padding: 2px 8px; border-radius: 4px; font-size: 12px;
}
.big-stat { display: flex; gap: 20px; margin-bottom: 12px; }
.big-stat .num { font-size: 28px; font-weight: 700; color: var(--accent); }
.big-stat .lbl { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* -------- toast -------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border);
  padding: 10px 16px; border-radius: 8px; font-size: 13px; z-index: 300;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-2); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--panel-2); }

/* Back button + floor caption (front-view mode) */
.back-btn {
  position: absolute; top: 16px; left: 16px; z-index: 5;
  background: var(--panel); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 8px; color: var(--text);
  cursor: pointer; font-size: 13px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
.back-btn:hover { background: var(--panel-2); }
.floor-caption {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--border);
  padding: 6px 16px; border-radius: 20px; font-size: 13px; color: var(--muted);
  z-index: 4; pointer-events: none;
}
.floor-caption b { color: var(--text); }

/* SVG shelf styles */
.shelf-rect {
  fill: var(--shelf);
  stroke: var(--border);
  stroke-width: 1;
  transition: fill 0.15s ease;
  cursor: pointer;
}
.shelf-rect:hover { fill: var(--shelf-hi); }
.shelf-rect.empty { fill: var(--shelf-empty); }
.shelf-rect.selected { fill: var(--accent); stroke: white; stroke-width: 2; }

/* Overview shelf (letter card) */
.shelf-card {
  fill: url(#shelfGradient);
  stroke: var(--border);
  stroke-width: 1.5;
  transition: filter 0.15s ease, stroke 0.15s ease;
  cursor: pointer;
}
.shelf-card:hover { stroke: var(--accent); filter: brightness(1.15); }
.shelf-card.empty { fill: var(--shelf-empty); }
.shelf-letter {
  fill: var(--text); font-size: 48px; font-weight: 800;
  pointer-events: none; text-anchor: middle; dominant-baseline: middle;
  letter-spacing: 2px;
}
.shelf-total {
  fill: var(--muted); font-size: 13px;
  pointer-events: none; text-anchor: middle; dominant-baseline: middle;
}
.shelf-badge-count {
  fill: var(--accent); font-size: 12px; font-weight: 700;
  pointer-events: none; text-anchor: middle; dominant-baseline: middle;
}

/* Front-view slot */
.slot-rect {
  fill: var(--shelf);
  stroke: var(--border);
  stroke-width: 1.5;
  transition: fill 0.15s ease, stroke 0.15s ease;
  cursor: pointer;
  rx: 4; ry: 4;
}
.slot-rect:hover { fill: var(--shelf-hi); stroke: var(--accent); }
.slot-rect.empty { fill: var(--shelf-empty); }
.slot-rect.tall { fill: var(--shelf-hi); }
.slot-rect.tall.empty { fill: var(--shelf-empty); }
.slot-rect.selected { fill: var(--accent); stroke: white; stroke-width: 2; }
.slot-label {
  fill: var(--text); font-size: 16px; font-weight: 700;
  pointer-events: none; text-anchor: middle; dominant-baseline: middle;
}
.slot-count {
  fill: var(--muted); font-size: 11px;
  pointer-events: none; text-anchor: middle; dominant-baseline: middle;
}
.shelf-label {
  fill: var(--text); font-size: 14px; font-weight: 600;
  pointer-events: none; text-anchor: middle; dominant-baseline: middle;
}
.shelf-count {
  fill: var(--muted); font-size: 10px;
  pointer-events: none; text-anchor: middle; dominant-baseline: middle;
}
.section-label {
  fill: var(--muted); font-size: 13px; font-weight: 700;
  pointer-events: none; letter-spacing: 2px; text-anchor: start;
}
.side-label {
  fill: var(--muted); font-size: 12px; font-weight: 600;
  pointer-events: none; letter-spacing: 1px;
}
.floor-outline {
  fill: none;
  stroke: var(--border);
  stroke-width: 1;
  stroke-dasharray: 6 4;
}

/* ---------- Map v2 SVG styles ---------- */
.zone-label {
  fill: #1e2430; font-weight: 800; letter-spacing: 1.5px;
  pointer-events: none;
}
.zone-sub {
  fill: #384051; font-weight: 500;
  pointer-events: none;
}
.shelf-bar { cursor: pointer; transition: filter 0.15s ease; }
.shelf-bar-group:hover .shelf-bar { filter: brightness(1.08); }

/* -------- Overview "quick access" cards (Unassigned, Resource Checkout) -------- */
.unassigned-card-rect {
  fill: var(--accent);
  fill-opacity: 0.16;
  stroke: var(--accent);
}
.unassigned-card-text {
  fill: var(--accent);
}
:root[data-theme="light"] .unassigned-card-rect {
  fill-opacity: 0.14;
}
:root[data-theme="light"] .unassigned-card-text {
  fill: var(--accent-2);
}

.resource-card-rect {
  fill: #34c759;
  fill-opacity: 0.18;
  stroke: #34c759;
}
.resource-card-text {
  fill: #34c759;
}
:root[data-theme="light"] .resource-card-rect {
  fill-opacity: 0.14;
}
:root[data-theme="light"] .resource-card-text {
  fill: #1f8f3f;
}

/* Hover: whole card group gently brightens (SVG rects can't `transform` on hover
   cleanly without shifting the click target, so we lean on `filter` instead). */
.shelf-bar-group:hover .unassigned-card-rect,
.shelf-bar-group:hover .resource-card-rect {
  filter: brightness(1.15);
}
.shelf-num-label {
  fill: #1e2430; font-size: 22px; font-weight: 800;
  text-anchor: middle; dominant-baseline: middle;
  pointer-events: none;
}
.shelf-bar-title {
  fill: #fff; font-size: 16px; font-weight: 700;
  pointer-events: none;
}
.shelf-bar-sub {
  fill: rgba(255,255,255,0.85); font-size: 12px;
  pointer-events: none;
}
.front-zone-label {
  fill: #1e2430; font-size: 14px; font-weight: 800; letter-spacing: 2px;
  pointer-events: none;
}
.slot-map-rect { cursor: pointer; transition: fill 0.12s ease, stroke 0.12s ease; }
.slot-map-rect.empty { fill: #f3ede6; }
.slot-group:hover .slot-map-rect { fill: #fffbe6; }
.slot-map-num {
  fill: #fff; font-size: 14px; font-weight: 800;
  text-anchor: middle; dominant-baseline: middle;
  pointer-events: none;
}
.slot-map-cat {
  fill: #1e2430; font-size: 13px; font-weight: 700;
  text-anchor: middle; dominant-baseline: middle;
  pointer-events: none;
}
.slot-map-mfr {
  fill: #4b5568; font-size: 10px; font-style: italic;
  text-anchor: middle; dominant-baseline: middle;
  pointer-events: none;
}
.slot-map-more {
  fill: #6b7280; font-size: 10px; font-weight: 600;
  text-anchor: middle; dominant-baseline: middle;
  pointer-events: none;
}
.slot-map-count {
  fill: #6b7280; font-size: 11px; font-weight: 700;
  text-anchor: end; dominant-baseline: baseline;
  pointer-events: none;
}

/* --- Floor-plan overlays --- */
.shelf-hotspot {
  cursor: pointer;
  transition: fill 0.15s ease, stroke-width 0.15s ease;
}
.shelf-hotspot:hover {
  fill: rgba(255, 255, 255, 0.30) !important;
  stroke-width: 6 !important;
}
.hotspot-badge-text {
  fill: #fff; font-size: 14px; font-weight: 700;
  text-anchor: middle; dominant-baseline: middle;
  pointer-events: none;
  letter-spacing: 0.3px;
}
main {
  background: var(--map-bg);
}
/* Dark-mode floor-plan dimming is now done via an SVG <filter> element
   applied to the <image> in js/app.js (Safari doesn't reliably support
   CSS filter on SVG <image>). This rule intentionally left empty. */
:root[data-theme="dark"] .zone-label { fill: var(--zone-label-fill); }
:root[data-theme="dark"] .zone-sub { fill: var(--zone-sub-fill); }
:root[data-theme="dark"] .shelf-num-label,
:root[data-theme="dark"] .front-zone-label,
:root[data-theme="dark"] .slot-map-cat,
:root[data-theme="dark"] .desk-label,
:root[data-theme="dark"] .hotspot-letter { fill: var(--text); }
:root[data-theme="dark"] .slot-map-mfr,
:root[data-theme="dark"] .slot-map-more,
:root[data-theme="dark"] .slot-map-count,
:root[data-theme="dark"] .hotspot-count { fill: var(--muted); }

/* Theme toggle button in the top bar */
.theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 34px; height: 34px; padding: 0;
  font-size: 15px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text);
}
.theme-toggle:hover { background: var(--panel-2); }

/* Letter-labeled shelf hotspots */
.shelf-hotspot.letter-shelf {
  fill: rgba(76, 154, 255, 0.14);
  stroke: #2f6ec7;
  stroke-width: 3;
  cursor: pointer;
  transition: fill 0.15s ease, stroke-width 0.15s ease;
}
.shelf-hotspot.letter-shelf:hover {
  fill: rgba(76, 154, 255, 0.32) !important;
  stroke-width: 4 !important;
}
.hotspot-letter {
  fill: #1e2430;
  font-weight: 900;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  letter-spacing: 1px;
}
.hotspot-count {
  fill: #4b5568;
  font-size: 14px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: baseline;
  pointer-events: none;
}
.desk-label {
  fill: #4b5568;
  font-size: 20px;
  font-weight: 700;
  font-style: italic;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}

/* -------- Header stat chips + tab counts -------- */
.header-stats { display: flex; gap: 6px; margin-left: 8px; }
.header-stats .stat {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--border);
  color: var(--muted); font-size: 12px;
}
.header-stats .stat b { color: var(--text); font-weight: 700; }
.header-stats .stat.has-out { border-color: var(--danger); color: var(--danger); }
.header-stats .stat.has-out b { color: var(--danger); }
.header-stats .stat.filtered { border-color: var(--accent); color: var(--accent); }
.header-stats .stat.filtered b { color: var(--accent); }

.topbar nav button .tab-count {
  display: inline-block; margin-left: 4px;
  padding: 0 6px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--muted); font-size: 10px; font-weight: 600;
}
.topbar nav button.active .tab-count { color: var(--text); }

/* -------- Anonymous chip (red-tinted when no name set) -------- */
.user-chip.anonymous {
  border-color: var(--danger);
  color: var(--danger);
  background: rgba(229,72,77,0.08);
}
.user-chip.anonymous:hover { color: var(--danger); }
.user-chip.anonymous #user-name { color: var(--danger); }

/* -------- Chip-style toolbar buttons (My checkouts, All checkouts) -------- */
.chip-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--border);
  color: var(--muted); font-size: 12px; cursor: pointer;
  white-space: nowrap;
}
.chip-btn:hover { color: var(--text); }
.chip-btn > span {
  padding: 0 6px; border-radius: 999px;
  background: var(--panel-2); font-size: 11px; font-weight: 700;
}
.chip-btn.active {
  background: var(--accent); border-color: var(--accent); color: white;
}
.chip-btn.active > span { background: rgba(255,255,255,0.25); color: white; }
.chip-btn.zero { opacity: 0.6; }

/* -------- Shelf tooltip -------- */
.shelf-tooltip {
  position: absolute; z-index: 6; pointer-events: none;
  background: var(--panel); border: 1px solid var(--border);
  padding: 6px 10px; border-radius: 6px;
  font-size: 12px; color: var(--text);
  box-shadow: 0 6px 16px rgba(0,0,0,0.35);
  opacity: 0; transition: opacity 0.12s ease;
  white-space: nowrap;
}
.shelf-tooltip.visible { opacity: 1; }
.shelf-tooltip b { color: var(--accent); }
.shelf-tooltip .muted { color: var(--muted); }

/* -------- Highlight currently open shelf + fullness colors -------- */
.shelf-hotspot.letter-shelf.open {
  fill: rgba(76, 154, 255, 0.55) !important;
  stroke: var(--accent) !important;
  stroke-width: 5 !important;
  filter: drop-shadow(0 0 8px rgba(76,154,255,0.5));
}
.shelf-hotspot.letter-shelf.dim {
  fill: rgba(120,120,120,0.05) !important;
  stroke: rgba(120,120,120,0.4) !important;
  opacity: 0.55;
}
/* -------- Locate-mode target shelf (top-down): pulses to draw the eye -------- */
.shelf-hotspot.letter-shelf.pulse-target {
  fill: rgba(76, 154, 255, 0.65) !important;
  stroke: var(--accent) !important;
  stroke-width: 6 !important;
  filter: drop-shadow(0 0 12px rgba(76, 154, 255, 0.75));
  animation: pulse-target 1.6s ease-in-out infinite;
}
@keyframes pulse-target {
  0%, 100% {
    fill: rgba(76, 154, 255, 0.55);
    filter: drop-shadow(0 0 10px rgba(76, 154, 255, 0.6));
  }
  50% {
    fill: rgba(76, 154, 255, 0.95);
    filter: drop-shadow(0 0 24px rgba(76, 154, 255, 1));
  }
}
/* Heading text above the right-hand front view in locate mode. */
.locate-front-heading {
  fill: var(--text);
  font-size: 42px;
  font-weight: 800;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  letter-spacing: 0.5px;
  pointer-events: none;
}
/* -------- Checked-out ribbon overlay on material cards -------- */
.material-card.checked-out {
  background: linear-gradient(90deg, rgba(247,166,67,0.10), var(--bg-2) 40%);
  position: relative;
}
.material-card.checked-out::before {
  content: "OUT";
  position: absolute; top: 8px; right: -22px;
  transform: rotate(35deg);
  background: var(--warn); color: white;
  font-size: 9px; font-weight: 800; letter-spacing: 1px;
  padding: 2px 24px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  pointer-events: none;
}
.material-card.checked-out { overflow: hidden; }

/* -------- Division filter bar -------- */
.filter-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-2); border-bottom: 1px solid var(--border);
  padding: 4px 16px;
  overflow-x: auto; overflow-y: hidden;
  white-space: nowrap;
}
.filter-bar .filter-label {
  font-size: 10px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 1px; font-weight: 700;
  flex-shrink: 0;
}
.filter-bar .filter-chips { display: inline-flex; gap: 6px; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 12px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--border);
  color: var(--muted); font-size: 12px; cursor: pointer;
  white-space: nowrap; user-select: none;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.filter-chip:hover { color: var(--text); }
.filter-chip.active {
  background: var(--accent); border-color: var(--accent); color: white;
}
.filter-chip .chip-count {
  padding: 0 7px; border-radius: 999px;
  background: var(--panel-2); font-size: 10px; font-weight: 700; color: var(--muted);
}
.filter-chip.active .chip-count { background: rgba(255,255,255,0.25); color: white; }
.filter-chip.zero { opacity: 0.4; }

/* Second-tier filter bar (subdivisions). Kept very compact so it doesn't
   push the floor plan down noticeably — reads as a sub-line of the main
   division bar above it, not another full-height bar. */
.filter-bar-sub {
  padding: 1px 16px 1px 32px;
  gap: 6px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  min-height: 0;
}
.filter-bar-sub .filter-label {
  font-size: 10px; opacity: 0.55; letter-spacing: 0.5px;
}
.filter-bar-sub .filter-chip {
  font-size: 10px; padding: 1px 8px; gap: 4px;
}
.filter-bar-sub .filter-chip .chip-count {
  font-size: 9px; padding: 0 5px;
}

/* -------- Empty-slot dashed style in front view -------- */
.slot-rect.empty {
  stroke-dasharray: 8 5;
  stroke: var(--muted);
  stroke-width: 1.5;
  fill: transparent;
  opacity: 0.7;
}
:root[data-theme="dark"] .slot-rect.empty { fill: rgba(255,255,255,0.02); }
.slot-group:hover .slot-rect.empty {
  stroke: var(--accent); opacity: 1;
}
.slot-rect.empty + .slot-label { opacity: 0.55; }

/* -------- Auth screens -------- */
/* #app stays in normal flow; #auth-screen sits on top with position:fixed */
#auth-screen {
  display: flex;
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: var(--bg);
  color: var(--text);
  align-items: center;
  justify-content: center;
  font-family: var(--font);
}
.auth-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 32px;
  max-width: 420px;
  width: 90%;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}
.auth-logo {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 28px;
  letter-spacing: 0.3px;
}
.auth-logo span { color: var(--accent); }
.auth-card h1 {
  font-size: 20px;
  margin: 0 0 10px;
  font-weight: 600;
}
.auth-sub {
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.55;
  margin: 0 0 22px;
}
.auth-signin {
  display: inline-flex;
  align-items: center;
  padding: 11px 22px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
}
.auth-signin:hover { filter: brightness(1.08); }
.auth-error {
  background: rgba(229, 72, 77, 0.12);
  color: var(--danger);
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 13px;
  text-align: left;
}
.auth-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: auth-spin 0.8s linear infinite;
  margin: 20px auto;
}
@keyframes auth-spin { to { transform: rotate(360deg); } }

/* -------- Role badge in the user chip -------- */
.role-badge {
  display: none;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  margin-right: 6px;
  color: white;
}
.role-badge.admin  { display: inline-block; background: var(--danger); }
.role-badge.viewer { display: inline-block; background: var(--accent); }
.role-badge.rep    { display: inline-block; background: var(--warn); }

/* -------- Role-gated nav tabs -------- */
.topbar nav button.admin-only,
.topbar nav button.rep-only { display: none; }
body.role-admin .topbar nav button.admin-only { display: inline-flex; align-items: center; }
body.role-rep   .topbar nav button.rep-only   { display: inline-flex; align-items: center; }

/* Red counter on Reviews tab when there's something pending */
.tab-count.has-pending {
  background: var(--danger) !important;
  color: white !important;
}

/* -------- Reviews view (admin) -------- */
.reviews-view, .submissions-view, .users-view,
.resources-view, .unassigned-view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 24px 32px 48px;
  background: var(--bg);
}

/* -------- Calendar view -------- */
.calendar-view {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}
.calendar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  flex-shrink: 0;
}
.calendar-nav { display: flex; align-items: center; gap: 6px; }
.calendar-title { font-size: 18px; font-weight: 600; margin-left: 10px; }
.calendar-arrow {
  width: 32px; height: 32px; padding: 0; font-size: 18px; line-height: 1;
}
.calendar-view-toggle { display: flex; align-items: center; gap: 4px; }
.calendar-view-toggle button.active {
  background: var(--panel);
  border-color: var(--accent);
  color: var(--text);
}
.calendar-body {
  flex: 1; overflow: hidden; position: relative;
  display: flex; flex-direction: column;
}
.cal-event {
  display: block; padding: 3px 6px; border-radius: 4px;
  color: white; font-size: 11px; line-height: 1.25;
  cursor: pointer; overflow: hidden;
  border: 1px solid rgba(0,0,0,0.15);
  white-space: nowrap; text-overflow: ellipsis;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
.cal-event:hover { filter: brightness(1.1); }
.cal-event-dim { opacity: 0.5; text-decoration: line-through; }

/* Month view */
.cal-month-weekhead {
  display: grid; grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  flex-shrink: 0;
}
.cal-month-weekhead > div {
  padding: 8px 12px; font-size: 11px; text-transform: uppercase;
  color: var(--muted); font-weight: 600; letter-spacing: 0.5px;
}
.cal-month-grid {
  flex: 1; display: flex; flex-direction: column;
  overflow-y: auto;
}
.cal-month-week {
  display: grid; grid-template-columns: repeat(7, 1fr);
  flex: 1; min-height: 100px;
  border-bottom: 1px solid var(--border);
}
.cal-month-day {
  border-right: 1px solid var(--border);
  padding: 4px; cursor: pointer;
  display: flex; flex-direction: column; gap: 2px;
  overflow: hidden;
}
.cal-month-day:hover { background: var(--panel); }
.cal-month-day.outside { background: var(--bg-2); opacity: 0.55; }
.cal-month-day.today .cal-day-num {
  color: white; background: var(--accent);
  border-radius: 50%; width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
}
.cal-day-num {
  font-size: 12px; color: var(--muted); font-weight: 600;
  align-self: flex-start; padding: 0 4px;
}
.cal-more {
  font-size: 11px; color: var(--muted); padding: 2px 4px;
  cursor: pointer; border-radius: 3px;
}
.cal-more:hover { background: var(--panel); color: var(--text); }

/* Week + Day time-grid view */
.cal-week-head {
  display: grid; border-bottom: 1px solid var(--border);
  background: var(--bg-2); flex-shrink: 0;
}
.cal-time-corner { border-right: 1px solid var(--border); }
.cal-day-head {
  padding: 8px 6px; font-size: 12px; color: var(--muted);
  text-align: center; border-right: 1px solid var(--border);
  font-weight: 500;
}
.cal-day-head.today { color: var(--accent); font-weight: 700; }
.cal-week-body {
  display: grid; flex: 1; overflow-y: auto; position: relative;
}
.cal-time-gutter {
  border-right: 1px solid var(--border);
  background: var(--bg-2);
  position: sticky; left: 0; z-index: 2;
}
.cal-hour-label {
  padding: 2px 8px; font-size: 10px; color: var(--muted);
  text-align: right; box-sizing: border-box;
  border-bottom: 1px solid var(--border);
}
.cal-day-col {
  position: relative;
  border-right: 1px solid var(--border);
}
.cal-day-col:hover { background: var(--panel); }
.cal-hour-line {
  position: absolute; left: 0; right: 0; height: 1px;
  background: var(--border);
}
.cal-week-event {
  position: absolute;
  padding: 4px 6px;
  font-size: 11px;
  line-height: 1.2;
  white-space: normal;
  display: flex; flex-direction: column; gap: 1px;
}
.cal-event-time { font-size: 10px; opacity: 0.85; font-weight: 600; }
.cal-event-label { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.cal-event-user { font-size: 10px; opacity: 0.8; overflow: hidden; text-overflow: ellipsis; }
.cal-allday-row {
  display: grid;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  flex-shrink: 0;
}
.cal-allday-label-cell {
  padding: 6px 8px; font-size: 10px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  border-right: 1px solid var(--border);
  grid-row: 1; grid-column: 1;
}
/* Scroll container for stacked spanning events so they don't push the hour
   grid off screen. Caps at ~120px; more than that scrolls inside this row. */
.cal-allday-scroll {
  position: relative;
  grid-row: 1;
  grid-column: 2 / -1;
  max-height: 120px;
  overflow-y: auto;
}
.cal-allday-event {
  position: absolute;
  height: 18px;
  padding: 2px 6px;
  font-size: 11px; line-height: 1.15;
  display: flex; align-items: center; gap: 6px;
  overflow: hidden; white-space: nowrap;
}
.cal-allday-label { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.cal-allday-user { opacity: 0.85; overflow: hidden; text-overflow: ellipsis; font-size: 10px; }
.cal-now-line {
  position: absolute; left: 0; right: 0; height: 2px;
  background: #ff3b30;
  z-index: 3; pointer-events: none;
  box-shadow: 0 0 6px rgba(255,59,48,0.4);
}
.cal-now-line::before {
  content: ""; position: absolute; left: -4px; top: -3px;
  width: 8px; height: 8px; border-radius: 50%; background: #ff3b30;
}

/* Reservation detail popup */
.reservation-detail header { display: flex; align-items: center; gap: 8px; }
.res-color {
  display: inline-block; width: 14px; height: 14px; border-radius: 3px;
  flex-shrink: 0;
}
.res-meta { display: flex; flex-direction: column; gap: 4px; }
.res-meta .muted { color: var(--muted); font-size: 13px; }
.res-notes {
  margin-top: 12px; padding: 8px 12px;
  background: var(--panel); border-radius: 6px;
  font-size: 13px; color: var(--text);
}
.res-status-scheduled { color: var(--accent); font-weight: 600; }
.res-status-picked_up { color: #46a758; font-weight: 600; }
.res-status-returned  { color: var(--muted); }
.res-status-cancelled { color: var(--muted); text-decoration: line-through; }

/* Reservation dialog: fixed width so status text can't reflow the dialog. */
.dialog.reservation-dialog {
  width: 480px; min-width: 480px; max-width: 92vw;
}
.dialog.reservation-dialog .form-row input,
.dialog.reservation-dialog .form-row textarea {
  width: 100%; box-sizing: border-box;
  padding: 8px 10px; border-radius: 6px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border);
  font-family: inherit; font-size: 13px;
  resize: vertical;
}
/* Live status line reserves a stable minimum height and wraps long text so
   the dialog itself never resizes as the user types. */
.reservation-status {
  font-size: 12px; padding: 4px 0;
  min-height: 22px;
  overflow-wrap: anywhere; word-break: break-word;
}
.reservation-status.error { color: #e5484d; font-weight: 600; }
.reservation-status.info  { color: var(--muted); }

/* Material picker */
.material-picker .body {
  display: flex; flex-direction: column; gap: 10px;
  max-height: 60vh;
}
.material-picker input#mp-search {
  padding: 10px 14px; font-size: 14px;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
}
.material-picker-list {
  flex: 1; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg);
}
.mp-item {
  padding: 8px 12px; cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 2px;
}
.mp-item:hover { background: var(--panel); }
.mp-item:last-child { border-bottom: none; }
.mp-desc { font-weight: 500; }
.mp-meta { font-size: 11px; color: var(--muted); }
.mp-out {
  display: inline-block; font-size: 10px;
  background: rgba(229,72,77,0.15); color: #e5484d;
  padding: 1px 6px; border-radius: 4px; margin-top: 2px; align-self: flex-start;
}
.mp-empty { padding: 20px; color: var(--muted); text-align: center; }

/* -------- Centered list layout (Resources, Unassigned) -------- */
.center-shell {
  max-width: 780px;
  margin: 0 auto;
}
.center-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}
.center-header .center-title { flex: 1; text-align: center; }
.center-title h1 { margin: 0; font-size: 22px; font-weight: 700; }
.center-subtitle { color: var(--muted); font-size: 13px; margin-top: 4px; }
.center-header-actions { min-width: 140px; display: flex; justify-content: flex-end; }
.back-inline {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}
.back-inline:hover { background: var(--panel-2); }
.center-list { display: flex; flex-direction: column; gap: 8px; }
/* Material cards render at natural width inside the centered container. */
.center-list .material-card { max-width: none; }

/* ---- Divisions browser ---- */
.divisions-view {
  padding: 24px;
  overflow-y: auto;
  height: 100%;
}
.divisions-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.division-tile {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  transition: border-color 120ms ease, background 120ms ease;
}
.division-tile:hover {
  border-color: var(--accent);
  background: var(--panel-2);
}
.division-tile-name {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 8px;
}
.division-tile-stats {
  display: flex;
  align-items: baseline;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}
.division-tile-count { font-size: 20px; font-weight: 700; color: var(--text); }
.division-tile-count-label { }
.division-tile-out {
  margin-left: auto;
  color: var(--warn);
  font-size: 12px;
  font-weight: 600;
}
/* Division detail rows: card on top, "location · Go to slot" underneath. */
.division-row { display: flex; flex-direction: column; gap: 4px; }
.division-row-loc {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  padding: 0 12px 8px;
}
.division-row-loc button {
  margin-left: auto;
}
.reviews-header, .submissions-header {
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.reviews-header h1, .submissions-header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}
.reviews-summary { color: var(--muted); font-size: 13px; }
.review-empty {
  text-align: center;
  padding: 80px 20px;
  color: var(--muted);
}
.review-empty .empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.7; }
.review-empty h2 { margin: 0 0 8px; font-size: 18px; color: var(--text); }

.review-day, .submissions-day { margin-bottom: 28px; }
.review-day-heading {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 0 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.review-rep-block {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 14px;
}
.review-rep-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.review-rep-name { font-weight: 700; font-size: 15px; }
.review-rep-email { color: var(--muted); font-size: 12px; }
.review-rep-actions { display: flex; gap: 8px; }

.review-btn {
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.review-btn:hover { background: var(--panel); border-color: var(--accent); }
.review-btn.approve, .review-btn.approve-all { color: var(--ok); border-color: var(--ok); }
.review-btn.approve:hover, .review-btn.approve-all:hover { background: var(--ok); color: white; }
.review-btn.danger, .review-btn.deny, .review-btn.deny-all { color: var(--danger); border-color: var(--danger); }
.review-btn.danger:hover, .review-btn.deny:hover, .review-btn.deny-all:hover { background: var(--danger); color: white; }

.review-items { display: flex; flex-direction: column; gap: 12px; }
.review-item {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}
.review-item-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.review-type-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: white;
}
.review-type-badge.type-add      { background: var(--ok); }
.review-type-badge.type-edit     { background: var(--accent); }
.review-type-badge.type-delete   { background: var(--danger); }
.review-type-badge.type-reassign { background: var(--warn); }
.review-material-name { font-weight: 600; font-size: 14px; }
.review-detail { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.review-conflict {
  background: rgba(247, 166, 67, 0.12);
  border: 1px solid rgba(247, 166, 67, 0.4);
  color: var(--warn);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12.5px;
  margin: 8px 0;
}
.review-diff {
  width: 100%;
  border-collapse: collapse;
  margin: 6px 0 10px;
  font-size: 12.5px;
}
.review-diff th, .review-diff td {
  padding: 4px 8px;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.review-diff th { background: var(--panel-2); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; }
.review-diff .field-name { color: var(--muted); font-weight: 600; width: 130px; }
.review-diff .field-before { color: var(--danger); }
.review-diff .field-after  { color: var(--ok); }
.review-item-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

/* -------- Submissions view (rep) -------- */
.submissions-summary { display: flex; gap: 8px; }
.pill {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  border: 1px solid var(--border);
}
.pill.pending  { background: rgba(247, 166, 67, 0.15); color: var(--warn); border-color: rgba(247, 166, 67, 0.4); }
.pill.approved { background: rgba(70, 167, 88, 0.15); color: var(--ok); border-color: rgba(70, 167, 88, 0.4); }
.pill.denied   { background: rgba(229, 72, 77, 0.15); color: var(--danger); border-color: rgba(229, 72, 77, 0.4); }

.submissions-items { display: flex; flex-direction: column; gap: 8px; }
.submission-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
}
.submission-item.pending  { border-left: 4px solid var(--warn); }
.submission-item.approved { border-left: 4px solid var(--ok); }
.submission-item.denied   { border-left: 4px solid var(--danger); }
.submission-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.submission-status { font-size: 12.5px; font-weight: 700; }
.submission-type {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 800;
  color: white;
  letter-spacing: 0.4px;
}
.submission-type.type-add      { background: var(--ok); }
.submission-type.type-edit     { background: var(--accent); }
.submission-type.type-delete   { background: var(--danger); }
.submission-type.type-reassign { background: var(--warn); }
.submission-material { flex: 1; font-weight: 500; }
.submission-location {
  background: var(--panel-2);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
.submission-withdraw {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  cursor: pointer;
}
.submission-withdraw:hover { color: var(--danger); border-color: var(--danger); }
.submission-note {
  margin-top: 8px;
  padding: 6px 10px;
  background: var(--bg-2);
  border-radius: 6px;
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}

/* -------- Users view (admin) -------- */
.users-header {
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.users-header h1 { margin: 0; font-size: 22px; font-weight: 700; }
.users-summary { color: var(--muted); font-size: 13px; }

.users-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 16px;
}
.users-section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.users-section-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}
.users-section-count {
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}

.user-list-header {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 130px;
  gap: 12px;
  padding: 6px 10px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.user-list { display: flex; flex-direction: column; }
.user-list-empty {
  padding: 20px 10px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}
.user-row, .invite-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 130px;
  gap: 12px;
  align-items: center;
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
}
.user-row:last-child, .invite-row:last-child { border-bottom: none; }
.user-row.inactive { opacity: 0.55; }

.user-info { min-width: 0; }
.user-name {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-email {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}
.you-chip {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  background: var(--accent);
  color: white;
  letter-spacing: 0.3px;
}
.user-role-select {
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 12.5px;
}
.user-role-locked {
  padding: 5px 8px;
  color: var(--muted);
  font-size: 12.5px;
  font-style: italic;
}
.user-status {
  font-size: 12px;
  font-weight: 700;
}
.user-status.active   { color: var(--ok); }
.user-status.inactive { color: var(--muted); }
.user-status.pending  { color: var(--warn); }
.user-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}
.user-btn {
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.user-btn:hover { background: var(--panel); }
.user-btn.danger { color: var(--danger); border-color: var(--danger); }
.user-btn.danger:hover { background: var(--danger); color: white; }

.invite-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.invite-form input {
  flex: 1;
  min-width: 200px;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text);
  font-size: 13px;
}
.invite-form input:focus { outline: none; border-color: var(--accent); }
.invite-form button {
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
}

/* -------- Pending change badges on material cards -------- */
.pending-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.pending-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.2px;
  line-height: 1.4;
}
.pending-badge-delete {
  background: rgba(229, 72, 77, 0.15);
  color: var(--danger);
  border: 1px solid rgba(229, 72, 77, 0.35);
}
.pending-badge-changes {
  background: rgba(247, 166, 67, 0.15);
  color: var(--warn);
  border: 1px solid rgba(247, 166, 67, 0.35);
}
.pending-badge-mine {
  background: rgba(76, 154, 255, 0.15);
  color: var(--accent);
  border: 1px solid rgba(76, 154, 255, 0.35);
}
.material-card.pending-delete {
  border: 1px dashed rgba(229, 72, 77, 0.5);
}
.material-card.pending-changes {
  border: 1px dashed rgba(247, 166, 67, 0.5);
}

/* -------- Sync banner (admin CTA when Firestore is empty) -------- */
#sync-banner {
  position: fixed;
  inset: 0;
  z-index: 9000;
  background: rgba(15, 17, 21, 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.sync-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 28px;
  max-width: 480px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}
.sync-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--warn);
}
.sync-msg {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  margin: 0 0 20px;
}
.sync-msg code {
  background: var(--panel-2);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12.5px;
}
.sync-btn {
  padding: 12px 24px;
  font-size: 14.5px;
  font-weight: 600;
}
.sync-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}
.sync-progress {
  margin-top: 16px;
  color: var(--muted);
  font-size: 13px;
  min-height: 18px;
}

/* -------- Mobile phone layout (does not affect iPad / desktop) -------- */
@media (max-width: 767px) {
  /* Compositor-layer hints: force iOS Safari to promote the map to its own
     GPU-composited layer, so pan/pinch transforms are cheap. Only inside
     this mobile media query — desktop rendering is unchanged. */
  .stage-wrap { transform: translateZ(0); }
  #stage-inner { will-change: transform; }

  /* Use a JS-fed CSS var for the height instead of 100vh/100dvh — mobile
     Safari's viewport-unit reporting can lie about the visible area, causing
     content near the bottom to hide behind the URL bar / gesture zone.
     window.innerHeight (set in the inline script in index.html) is the true
     visible height. Falls back to 100dvh / 100vh for browsers before the var
     is set. */
  #app {
    height: 100vh;
    height: 100dvh;
    height: var(--app-height, 100dvh);
    grid-template-rows: auto auto auto 1fr;
  }

  /* Top bar: allow wrap, hide non-essential items so nav + user chip fit. */
  header.topbar {
    flex-wrap: wrap;
    padding: 8px 10px;
    gap: 6px;
  }
  .topbar .brand,
  .topbar .header-stats,
  .topbar .spacer,
  .topbar #my-checkouts-btn {
    display: none;
  }
  .topbar nav {
    order: 1;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    padding-bottom: 2px;
  }
  .topbar nav button {
    flex-shrink: 0;
    font-size: 13px;
    padding: 6px 10px;
  }
  .topbar .searchbox {
    order: 2;
    width: auto;
    flex: 1;
    min-width: 140px;
  }
  .topbar .searchbox input {
    font-size: 16px; /* prevent iOS auto-zoom on focus */
  }
  .topbar #theme-toggle { order: 3; }
  .topbar .user-chip {
    order: 4;
    font-size: 12px;
    padding: 4px 8px;
  }
  .user-chip .role-badge {
    padding: 1px 5px;
    font-size: 8.5px;
  }

  /* Filter chips: keep horizontal scroll, tighter padding. */
  .filter-bar { padding: 3px 10px; }

  /* Zoom controls: bigger tap targets, thumb-friendly position. */
  .zoom-controls {
    right: 10px;
    bottom: 10px;
    gap: 4px;
  }
  .zoom-controls button {
    width: 44px;
    height: 44px;
    font-size: 20px;
  }
  .zoom-level {
    padding: 4px 6px;
    font-size: 11px;
  }

  /* Side panel becomes full-screen on mobile (close via ✕). */
  .side-panel {
    width: 100vw;
    max-width: 100vw;
  }
  /* Bump the scroll-extent spacer for phone-sized viewports specifically
     (base rule already applies 40px universally; phones get more headroom). */
  .side-panel .list::after {
    height: calc(env(safe-area-inset-bottom, 0px) + 100px);
  }

  /* Prevent iOS input auto-zoom in dialogs. */
  .overlay input,
  .overlay select,
  .overlay textarea {
    font-size: 16px;
  }

  /* Reviews / Submissions / Users pages: tighter horizontal padding, with a
     ::after spacer for the same iOS scroll-extent reason as the side panel. */
  .reviews-view, .submissions-view, .users-view {
    padding: 14px 12px 0;
  }
  .reviews-view::after, .submissions-view::after, .users-view::after {
    content: "";
    display: block;
    height: calc(env(safe-area-inset-bottom, 0px) + 60px);
  }
  .reviews-header h1, .submissions-header h1, .users-header h1 {
    font-size: 18px;
  }

  /* Users page: stack the row columns vertically so they fit narrow screens. */
  .user-list-header { display: none; }
  .user-row, .invite-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .user-actions { justify-content: flex-start; }
  .invite-form {
    flex-direction: column;
    align-items: stretch;
  }
  .invite-form input { min-width: 0; font-size: 16px; }

  /* Back-to-floor button: bigger on mobile. */
  .back-btn { font-size: 13px; padding: 8px 12px; }
}

/* ============ USER MENU (dropdown from the user chip) ============ */
.user-menu {
  z-index: 1200;
  min-width: 220px;
  background: var(--panel-bg, #1a1d24);
  color: var(--text, #eaeaea);
  border: 1px solid var(--border, #2b2f38);
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.35);
  padding: 6px;
  display: flex;
  flex-direction: column;
}
.user-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: transparent;
  border: none;
  color: inherit;
  text-align: left;
  font-size: 14px;
  cursor: pointer;
  border-radius: 6px;
}
.user-menu-item:hover { background: rgba(76,154,255,0.15); }
.user-menu-item.active { color: #4c9aff; background: rgba(76,154,255,0.10); }
.user-menu-icon { width: 18px; text-align: center; opacity: 0.75; }
.user-menu-sep { height: 1px; background: var(--border, #2b2f38); margin: 4px 2px; }

/* ============ EDITOR MODE ============ */
body.editor-mode .shelf-hotspot { cursor: default; }
.editor-banner {
  position: fixed;
  top: 68px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1100;
  background: linear-gradient(180deg, #1f4bc7, #1934a3);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  display: flex;
  gap: 14px;
  align-items: center;
  font-size: 13px;
  max-width: calc(100vw - 40px);
}
.editor-banner-title { font-weight: 700; letter-spacing: 0.02em; }
.editor-banner-hint { opacity: 0.85; }
.editor-banner-add,
.editor-banner-exit {
  background: rgba(255,255,255,0.18);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.35);
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.editor-banner-add:hover,
.editor-banner-exit:hover { background: rgba(255,255,255,0.28); }

/* SVG overlay elements — the transparent hit target and the resize handles. */
.editor-move-target { transition: fill 120ms ease; }
.editor-move-target:hover { fill: rgba(76,154,255,0.15); }
.editor-handle {
  transition: transform 100ms ease;
  transform-box: fill-box;
  transform-origin: center;
}
.editor-handle:hover { transform: scale(1.2); }

/* ============ EDITOR POPOVER (rename / duplicate / delete) ============ */
.editor-popover {
  position: fixed;
  z-index: 1300;
  width: 320px;
  background: var(--panel-bg, #1a1d24);
  color: var(--text, #eaeaea);
  border: 1px solid var(--border, #2b2f38);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.editor-popover-wide { width: 380px; }
.editor-popover-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border, #2b2f38);
  margin-bottom: 4px;
}
.editor-popover-title { font-weight: 700; font-size: 15px; }
.editor-popover-close {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 8px;
  border-radius: 6px;
}
.editor-popover-close:hover { background: rgba(255,255,255,0.08); }
.editor-popover-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.7;
  margin-top: 4px;
}
.editor-popover-input {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border, #2b2f38);
  background: rgba(0,0,0,0.25);
  color: inherit;
  font-size: 14px;
}
.editor-popover-input:focus { outline: 2px solid #4c9aff; outline-offset: -1px; }
.editor-popover-meta { font-size: 12px; opacity: 0.65; }
.editor-popover-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.editor-popover-btn {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border, #2b2f38);
  background: rgba(255,255,255,0.05);
  color: inherit;
  cursor: pointer;
  font-size: 13px;
  flex: 1;
  min-width: 80px;
}
.editor-popover-btn:hover:not(:disabled) { background: rgba(76,154,255,0.15); }
.editor-popover-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.editor-popover-btn.primary {
  background: #2f6ec7;
  border-color: #4c9aff;
  color: #fff;
}
.editor-popover-btn.primary:hover:not(:disabled) { background: #3d7fd0; }
.editor-popover-btn.danger { border-color: #a2413a; color: #ff8177; }
.editor-popover-btn.danger:hover:not(:disabled) { background: rgba(200,60,50,0.15); }

/* Light-theme adjustments for the editor UI. */
[data-theme="light"] .user-menu,
[data-theme="light"] .editor-popover {
  background: #ffffff;
  color: #222;
  border-color: #d5d8de;
}
[data-theme="light"] .user-menu-sep,
[data-theme="light"] .editor-popover-head { border-color: #e2e5eb; }
[data-theme="light"] .editor-popover-input {
  background: #f6f7fa;
  color: #222;
  border-color: #d5d8de;
}
[data-theme="light"] .editor-popover-btn { background: #f0f2f6; }

