:root{
  --navy: #2c313a;
  --navy-2: #23272e;
  --orange: #e8601c;
  --orange-dark: #c94f14;
  --panel: #d7d7d5;
  --panel-2: #c7c7c5;
  --ink: #23272e;
  --ink-soft: #5a5e64;
  --line: #b9b9b6;
  --ok: #2f8f4e;
  --err: #c93a3a;
  --white: #f3f2ef;
}
*{box-sizing:border-box;}
[hidden]{display:none !important;}
body{
  margin:0;
  font-family:'Inter',sans-serif;
  background:var(--navy);
  color:var(--ink);
}

.app{
  display:grid;
  grid-template-columns:240px 1fr;
}

/* ---------- Sidebar ---------- */
.sidebar{
  background:var(--orange);
  padding:24px 18px;
  display:flex;
  flex-direction:column;
  gap:10px;
  height:100vh;
  overflow-y:auto;
  position:sticky;
  top:0;
}
/* On short screens, stop reserving space to push Settings to the
   bottom — let it sit in normal flow so nothing gets clipped. */
@media (max-height:640px){
  .nav-spacer{flex:none;height:6px;}
}
.logo{
  display:flex;
  align-items:center;
  gap:8px;
  margin-bottom:26px;
}
.logo svg{width:26px;height:26px;flex-shrink:0;}
.logo span{
  font-family:'Oswald',sans-serif;
  font-weight:700;
  font-style:italic;
  font-size:24px;
  letter-spacing:.02em;
  color:var(--navy-2);
}
.nav-btn{
  background:var(--navy-2);
  color:var(--white);
  border:none;
  border-radius:3px;
  padding:13px 14px;
  text-align:left;
  font-family:'Inter',sans-serif;
  font-size:14px;
  font-weight:500;
  cursor:pointer;
  transition:background .15s;
  display:flex;
  align-items:center;
  gap:10px;
}
.nav-btn-label{flex:1;}
/* Same viewBox/stroke-width convention across every nav icon (line-art,
   currentColor) so they read as one consistent set despite covering very
   different subjects. Icon always comes first, label after -- same order
   for every button, including Search (it's a nav button, not a search
   input, so it doesn't get the trailing-icon treatment a real search
   field would). */
.nav-icon{width:17px;height:17px;flex-shrink:0;}
.nav-btn:hover{background:#31363f;}
.nav-btn.active{
  background:var(--navy);
  box-shadow:inset 3px 0 0 var(--white);
}
.nav-spacer{flex:1;}

/* ---------- Main ---------- */
main{
  background:var(--navy);
  padding:24px 28px 40px;
  display:flex;
  flex-direction:column;
  /* main is a grid item (.app's "1fr" column) -- grid items default to a
     minimum size equal to their content's intrinsic width, not 0. A wide
     room (e.g. 37 grid-columns = 2220px of fixed-width .grid-2d-content
     buried inside it) was silently forcing that minimum past the actual
     available space, stretching the whole page wider than the viewport
     and producing the horizontal scrollbar -- overflow:hidden on the map
     containers alone can't fix this, since the oversizing happens one
     layout level up, before any of their own clipping ever applies. */
  min-width:0;
}
.page-header{margin-bottom:16px;}
.page-title{
  font-family:'Oswald',sans-serif;
  font-weight:600;
  font-size:26px;
  text-transform:uppercase;
  color:var(--white);
  margin:2px 0 0;
}

.content-panel{
  background:var(--panel);
  border-radius:4px;
  padding:26px;
  flex:1;
  min-height:600px;
  max-height:2000px;
  overflow:visible;
  transition:max-height .3s ease;
}
/* Starting state for pages that want to grow into place (e.g. Search,
   before there's anything typed) instead of being a big empty box.
   Animates max-height (content is clipped via overflow:hidden while
   compact) rather than min-height, because min-height doesn't visibly
   animate anything once actual content already exceeds it -- the box
   would just snap to fit instead of growing into view.
   Any panel using this pattern also needs its own min-height:0 override --
   the base rule's min-height:600px isn't part of the transition, so left
   in place it would instantly snap the box to 600px the moment .compact
   is removed, regardless of how far max-height had animated (min-height
   always wins over max-height when the two conflict).
   flex:none overrides the base rule's flex:1, which would otherwise grow
   this panel to fill all leftover vertical space in the sidebar layout
   regardless of how much content is actually in it -- e.g. a single
   result row stretching the box out to fill the whole window. Without
   flex-grow, height comes purely from content, capped by max-height. */
#search-panel{min-height:0;flex:none;}
.content-panel.compact{
  max-height:330px;
  overflow:hidden;
}

/* ---------- Buttons / inputs shared ---------- */
.btn{
  font-family:'Oswald',sans-serif;
  font-weight:600;
  letter-spacing:.03em;
  text-transform:uppercase;
  font-size:13px;
  border:none;
  border-radius:3px;
  padding:12px 18px;
  cursor:pointer;
  background:var(--orange);
  color:var(--white);
}
.btn:hover{background:var(--orange-dark);}
.btn.ghost{
  background:transparent;
  border:1px solid var(--ink-soft);
  color:var(--ink);
}
/* Same gray-background/white-text look as the sidebar nav buttons. */
.btn.dark{background:var(--navy-2);color:var(--white);border:none;}
.btn.dark:hover{background:#31363f;}
.field-label{
  font-family:'IBM Plex Mono',monospace;
  font-size:11px;
  text-transform:uppercase;
  letter-spacing:.05em;
  color:var(--ink-soft);
  display:block;
  margin-bottom:6px;
}
.field-input{
  width:100%;
  background:var(--white);
  border:1px solid var(--line);
  border-radius:3px;
  padding:12px 14px;
  font-family:'IBM Plex Mono',monospace;
  font-size:14px;
  color:var(--ink);
  outline:none;
}
.field-input:focus{border-color:var(--orange);}

table{width:100%;border-collapse:collapse;font-family:'IBM Plex Mono',monospace;font-size:13px;}
th{
  text-align:left;
  font-family:'Inter',sans-serif;
  font-weight:600;
  font-size:12px;
  color:var(--ink-soft);
  text-transform:uppercase;
  letter-spacing:.04em;
  padding:10px 12px;
  border-bottom:2px solid var(--line);
}
td{padding:11px 12px;border-bottom:1px solid var(--line);}
tr:hover td{background:var(--panel-2);}

.toolbar{
  display:flex;
  gap:10px;
  margin-bottom:18px;
  flex-wrap:wrap;
  align-items:center;
}

.list-table-wrap{max-height:560px;overflow-y:auto;}
.list-table-wrap thead th{position:sticky;top:0;background:var(--panel);z-index:1;}

.pager{display:flex;gap:6px;margin-top:16px;flex-wrap:wrap;}
.pager-btn{
  min-width:32px;
  padding:6px 10px;
  border:1px solid var(--line);
  background:var(--white);
  border-radius:3px;
  font-family:'IBM Plex Mono',monospace;
  font-size:12px;
  cursor:pointer;
}
.pager-btn:hover{border-color:var(--orange);}
.pager-btn.active{background:var(--orange);border-color:var(--orange);color:var(--white);}
.toolbar select, .toolbar input{
  background:var(--white);
  border:1px solid var(--line);
  border-radius:3px;
  padding:9px 12px;
  font-family:'Inter',sans-serif;
  font-size:13px;
  color:var(--ink);
}

/* ---------- Storage map ---------- */
.map-frame{
  background:var(--white);
  border:1px solid var(--line);
  border-radius:4px;
  padding:18px;
  /* No scrollbars here -- the canvas already pans/zooms internally, and a
     browser scrollbar on top of that (previously overflow:auto with a
     max-height the canvas was right up against) fought with it: once the
     canvas edged past the cap the vertical scrollbar appeared, which then
     ate into the available width and could trigger a horizontal one too.
     overflow:hidden is just a safety net -- .map-canvas below already
     clips its own pannable content, this should never actually engage. */
  overflow:hidden;
}
/* Three groups (room-switcher, room-actions, map-toolbar-actions) spread
   left/center/right by space-between -- +Room/Delete room sit in their own
   middle group specifically so they land between the room switcher and
   Print shelf labels, not tacked onto either end. */
.map-toolbar{display:flex;justify-content:space-between;align-items:center;gap:8px;margin-bottom:6px;flex-wrap:wrap;}
.map-toolbar-actions, .room-actions{display:flex;gap:8px;align-items:center;}
#iso-controls{display:inline-flex;gap:8px;}
.map-hint{font-family:'IBM Plex Mono',monospace;font-size:13px;color:var(--ink);margin-bottom:12px;}

/* Toolbar buttons on the Storage map page, roughly doubled in size vs the
   normal .btn.small used elsewhere (Settings, Search, etc) -- scoped here
   so it doesn't affect those other, smaller contexts. */
.map-toolbar .btn.small{padding:14px 20px;font-size:20px;}

/* ---------- Room switcher ---------- */
.room-switcher{display:flex;align-items:center;gap:8px;}
.room-nav-btn{
  width:52px;height:52px;
  border:1px solid var(--line);
  background:var(--white);
  border-radius:3px;
  font-size:28px;
  line-height:1;
  cursor:pointer;
  display:flex;align-items:center;justify-content:center;
}
.room-nav-btn:hover{border-color:var(--orange);}
.room-nav-btn:disabled{opacity:.35;cursor:default;}
.room-name{
  font-family:'Oswald',sans-serif;
  font-weight:600;
  font-size:20px;
  text-transform:uppercase;
  color:var(--ink);
  min-width:90px;
  text-align:center;
  cursor:pointer;
}
/* Edit page only -- the room name is a real input instead of a display +
   dialog, so renaming is just "click in, select, retype" rather than a
   double-click-to-prompt round trip. */
.room-name-input{
  font-family:'Oswald',sans-serif;
  font-weight:600;
  font-size:20px;
  text-transform:uppercase;
  color:var(--ink);
  min-width:140px;
  text-align:center;
  background:var(--white);
  border:1px solid var(--line);
  border-radius:3px;
  padding:10px 8px;
}
.room-name-input:focus{border-color:var(--orange);outline:none;}
.room-name-input:disabled{opacity:.5;}

.map-canvas{position:relative;}
.map-canvas.mode-2d{
  background:var(--white);
  border:1px dashed var(--line);
  overflow:hidden;
  cursor:grab;
}
.map-canvas.mode-2d:active{cursor:grabbing;}
.map-canvas.mode-2d.edit-mode{cursor:copy;}
.map-canvas.mode-iso{background:var(--white);border:1px solid var(--line);overflow:hidden;}

/* The pannable/zoomable content living inside the fixed-size 2D viewport --
   background grid pattern lives here (not on .map-canvas) so it pans and
   scales along with everything else instead of staying fixed in place. */
.grid-2d-content{
  position:relative;
  transform-origin:0 0;
  background:
    linear-gradient(var(--line) 2px, transparent 2px),
    linear-gradient(90deg, var(--line) 2px, transparent 2px);
  background-size:60px 60px;
}
/* Outer "walls" of the room, distinct from (and thicker/darker than) the
   per-tile grid lines above. A ::after overlay rather than a real border --
   rack boxes are positioned absolutely against this element's own origin,
   and a real border would shift that origin inward by its width, throwing
   every rack slightly out of alignment with the grid beneath it. */
.grid-2d-content::after{
  content:'';
  position:absolute;
  inset:0;
  border:3px solid #8a8a86;
  pointer-events:none;
}
.map-empty-state{
  padding:60px 20px;
  text-align:center;
  color:var(--ink-soft);
  font-family:'IBM Plex Mono',monospace;
  font-size:13px;
}

/* 2D rack blocks -- plain white regardless of fill/occupancy (that
   gradient stays a 3D-only visualization now); the box itself rotates
   per facing (see map-edit.js/map.js), around its own center by default. */
.rack-box2d{
  position:absolute;
  background:var(--white);
  border:1px solid var(--orange-dark);
  border-radius:4px;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:2px;
  color:var(--ink);
  font-family:'IBM Plex Mono',monospace;
  font-size:11px;
  font-weight:600;
  cursor:pointer;
  user-select:none;
  box-shadow:inset 0 0 0 1px rgba(255,255,255,.4);
}
.rack-box2d.floor{border-style:dashed;border-radius:50%;}
.map-canvas.mode-2d.edit-mode .rack-box2d{cursor:grab;}
.rack-box2d.selected{outline:2px solid var(--orange-dark);outline-offset:1px;}
.rack-code{pointer-events:none;}

/* Explicit, deliberate grid resize -- one row/column per click, in place
   of the old implicit auto-grow-while-dragging. */
.grid-edge-btn{
  position:absolute;
  width:22px;height:22px;
  border-radius:50%;
  border:1px solid var(--orange-dark);
  background:var(--white);
  color:var(--orange-dark);
  line-height:1;
  font-size:13px;
  cursor:pointer;
  padding:0;
  z-index:3;
}
.grid-edge-btn.minus{border-color:var(--ink-soft);color:var(--ink-soft);}

/* Placed next to a selected rack's empty neighbor cells, to quickly add
   a matching rack there (see renderNeighborAddButtons in map-edit.js). */
.cell-add-btn{
  position:absolute;
  width:22px;height:22px;
  border-radius:50%;
  border:1px dashed var(--orange-dark);
  background:rgba(232,96,28,.08);
  color:var(--orange-dark);
  line-height:1;
  font-size:13px;
  cursor:pointer;
  padding:0;
  z-index:2;
}

/* The box itself rotates now (see the inline transform in map-edit.js/
   map.js), so this just sits at its top edge and rotates along with it --
   no separate rotation wrapper/per-facing classes needed any more. */
.rack-front-arrow{
  position:absolute;
  top:-6px; left:50%;
  transform:translateX(-50%);
  width:0; height:0;
  border-left:5px solid transparent;
  border-right:5px solid transparent;
  border-bottom:7px solid var(--orange-dark);
}
/* ---------- 3D (isometric) SVG view ---------- */
.iso-svg{display:block;cursor:grab;}
.iso-svg:active{cursor:grabbing;}
.rack-stack-svg polygon{transition:filter .1s ease;}
.rack-stack-svg:hover polygon{filter:brightness(1.05);}

/* Edit-map only: wraps the action panel + popover so they stack (action
   panel above, popover below, matching its width) anchored to the same
   bottom-right corner the plain popover (view-only map.js) uses on its
   own. Rotate/delete live here now, not on the rack box itself -- that's
   what stopped the button clicks getting entangled with the box's own
   drag/click handling underneath them. */
.rack-side-panels{
  position:fixed;
  bottom:54px; right:54px;
  display:flex;
  flex-direction:column;
  gap:14px;
  width:380px;
}
.rack-side-panels .shelf-popover{
  position:static;
  width:auto;
}
.rack-action-panel{
  display:flex;
  gap:14px;
  justify-content:center;
  background:var(--white);
  border:1px solid var(--line);
  border-radius:4px;
  padding:14px;
  box-shadow:0 4px 18px rgba(0,0,0,.25);
}
.rack-action-btn{
  width:60px; height:60px;
  border-radius:8px;
  border:1px solid var(--orange-dark);
  background:var(--white);
  color:var(--orange-dark);
  font-size:26px;
  line-height:1;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
}
.rack-action-btn.danger{border-color:var(--err);color:var(--err);}
.rack-action-btn .trash-icon{width:26px;height:26px;}

/* Trash icon used wherever a delete button used to be a plain "x" --
   reads as delete rather than "cancel/close" at a glance. */
.trash-icon{width:15px;height:15px;display:block;}
.btn.icon-only{display:inline-flex;align-items:center;justify-content:center;}

.shelf-popover{
  position:fixed;
  bottom:54px; right:54px;
  background:var(--white);
  border:1px solid var(--line);
  border-radius:4px;
  padding:14px 16px;
  width:380px;
  max-height:400px;
  overflow-y:auto;
  box-shadow:0 4px 18px rgba(0,0,0,.25);
}
.popover-head{display:flex;justify-content:space-between;align-items:center;margin-bottom:10px;font-family:'IBM Plex Mono',monospace;gap:6px;}
.popover-close{background:none;border:none;font-size:16px;cursor:pointer;color:var(--ink-soft);}
.popover-head > .popover-close{margin-left:auto;}
.popover-dims{margin:-4px 0 10px;font-family:'IBM Plex Mono',monospace;}
.popover-story{border-top:1px solid var(--line);padding:8px 0;}
.popover-story:first-of-type{border-top:none;}
.popover-story-head{display:flex;justify-content:space-between;font-size:13px;margin-bottom:4px;}
.popover-story-open .popover-story-head{color:var(--ink-soft);font-style:italic;}
.popover-item{
  font-size:12px;
  color:var(--ink-soft);
  padding:2px 0 2px 8px;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

/* Add-rack modal */
.rack-kind-toggle{display:flex;gap:8px;}
.kind-btn{
  flex:1;
  padding:10px;
  border:1px solid var(--line);
  background:var(--white);
  border-radius:3px;
  cursor:pointer;
  font-family:'Inter',sans-serif;
  font-size:12px;
}
.kind-btn.active{border-color:var(--orange);background:rgba(232,96,28,.12);color:var(--orange-dark);font-weight:600;}
.dims-row{display:flex;gap:8px;}
.dims-row .field-input{width:0;flex:1;}

/* These two modals pack in a lot more (per-story rows) than the plain
   300px .modal-card default fits comfortably -- a bit of extra width
   gives the height field real breathing room instead of squeezing it
   against a fixed-width label and an "Open (walkthrough)" checkbox. */
#rack-modal .modal-card, #dims-modal .modal-card{width:380px;}

/* One row per story in the add-rack/edit-dimensions modals -- a height
   field plus a "leave this level open" checkbox, so a walk-under gap in
   a shelving row (or simply two stories of different height) can be set
   per story instead of one height applying to the whole rack. Stacked
   (label+height on their own line, the checkbox below) rather than all
   three side by side -- crammed into one row, the height input had
   barely enough width left to show a single digit, let alone its
   "Height (cm)" placeholder.*/
.story-config-row{margin-top:10px;padding-bottom:8px;border-bottom:1px solid var(--line);}
.story-config-row:last-child{border-bottom:none;padding-bottom:0;}
.story-config-top{display:flex;align-items:center;gap:8px;}
.story-config-label{width:56px;flex-shrink:0;font-family:'IBM Plex Mono',monospace;font-size:12px;color:var(--ink-soft);}
.story-height-input{width:0;flex:1;}
.story-open-toggle{display:flex;align-items:center;gap:6px;font-size:12px;white-space:nowrap;color:var(--ink);margin-top:6px;padding-left:64px;}

/* ---------- Place product ---------- */
/* Shrinks to fit the card instead of being a big box with the card
   floating in the middle of it, and centers itself in the content area. */
.place-panel{
  flex:none;
  min-height:0;
  align-self:center;
  margin-top:auto;
  margin-bottom:auto;
  width:560px;
  max-width:100%;
}
.place-card{
  max-width:560px;
  width:100%;
  display:flex;
  flex-direction:column;
  gap:16px;
}
.place-msg{
  font-family:'IBM Plex Mono',monospace;
  font-size:13px;
  padding:12px 14px;
  border-radius:3px;
  background:rgba(47,143,78,.12);
  border:1px solid rgba(47,143,78,.35);
  color:var(--ok);
}
.place-msg-err{
  background:rgba(201,58,58,.12);
  border-color:rgba(201,58,58,.35);
  color:var(--err);
}
.place-msg-warn{
  background:rgba(232,96,28,.12);
  border-color:rgba(232,96,28,.35);
  color:var(--orange-dark);
}
.place-msg a{color:inherit;font-weight:600;}

.suggestions-list{
  display:flex;
  flex-direction:column;
  gap:6px;
  margin-top:8px;
}
.suggestion-item{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  background:var(--white);
  border:1px solid var(--line);
  border-radius:3px;
  padding:9px 12px;
  font-family:'Inter',sans-serif;
  font-size:13px;
  text-align:left;
  cursor:pointer;
}
.suggestion-item:hover{border-color:var(--orange);}

.search-field-row{display:flex;align-items:center;gap:10px;margin-bottom:16px;}
.search-field-row .field-label{margin:0;white-space:nowrap;}
.search-field-row .field-input{flex:1;}

/* A scaled-down live snapshot of the storage map (see IsoRender in
   assets/iso-render.js, used by search.js) -- hidden until an actual
   search has been run, same reveal timing as the result rows. Hovering a
   result row pans this to center that shelf's rack (IsoRender.panTo) and
   blinks the matching shelf face green (.shelf-blink below); every shelf
   currently in the results gets a persistent green outline
   (.shelf-result-highlight). Tall enough that the auto-fit scene (see
   buildScene's fit-to-content math) reads clearly rather than as a thin
   sliver. */
.search-minimap-frame{position:relative;margin-bottom:16px;}
.search-minimap{
  height:448px;
  background:var(--white);
  border:1px solid var(--line);
  border-radius:4px;
  overflow:hidden;
}
.search-minimap-controls{position:absolute;top:8px;right:8px;display:flex;gap:6px;}
/* Transitions on .iso-viewport's transform are applied inline from JS
   now (IsoRender.panTo/resetPan set a .5s glide, the wheel-zoom handler
   explicitly sets 'none' per tick) rather than a blanket CSS rule --
   wheel-zooming needs to feel instant, not animate every scroll tick. */

/* Green outline around every shelf face currently in the search results
   -- overrides the polygon's own inline stroke/fill presentation
   attributes (any CSS rule, even a class selector, beats those). */
.search-minimap .shelf-result-highlight{
  stroke:var(--ok) !important;
  stroke-width:2.5px;
}
/* Slow green blink on the shelf whose result row is currently hovered --
   replaces the fill outright (not blended with the original occupancy
   color) so it reads unambiguously as "this one" against the rest of
   the map. */
.search-minimap .shelf-blink{
  animation:shelf-blink-anim 1.3s ease-in-out infinite;
}
@keyframes shelf-blink-anim{
  0%, 100% { fill:var(--ok); }
  50% { fill:#8fdba8; }
}
/* Dims every OTHER rack (or, for a glued row, everything outside that
   whole group) while a result row is hovered, so the blinking target
   stays visible even when another rack sits in front of it in the iso
   projection -- opacity transition is fine here (unlike the pan/zoom
   transform above) since it only ever fires on hover, not continuously. */
.search-minimap .rack-stack-svg{transition:opacity .3s ease;}
.search-minimap .rack-dimmed{opacity:.03;}
/* Same effect on the Storage map page's own interactive 3D view --
   hovering a rack there fades every other rack (outside its glued group)
   the same way. */
.mode-iso .rack-stack-svg{transition:opacity .3s ease;}
.mode-iso .rack-dimmed{opacity:.03;}

/* ---------- Search result rows ---------- */
.result-rows{display:flex;flex-direction:column;gap:8px;max-height:640px;overflow-y:auto;padding-right:4px;}
.result-row{
  background:var(--white);
  border:1px solid var(--line);
  border-radius:3px;
  padding:10px 14px;
  display:flex;
  align-items:center;
  gap:14px;
  transition:border-color .15s;
}
.result-row:hover{border-color:var(--orange);}
.rr-cell{
  flex:1;
  min-width:0;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  font-size:13px;
}
.rr-brand{font-weight:600;flex:0.8;}
.rr-ean{font-family:'IBM Plex Mono',monospace;color:var(--ink-soft);}
.rr-room{flex:0.8;color:var(--ink-soft);}
.rr-shelf{
  flex:none;
  font-family:'IBM Plex Mono',monospace;
  font-size:13px;
  background:var(--panel-2);
  padding:4px 9px;
  border-radius:3px;
}
.rr-remove{flex:none;}
.rr-thumb{
  flex:none;
  width:52px;
  height:52px;
  border-radius:4px;
  object-fit:cover;
  background:var(--panel-2);
  border:1px solid var(--line);
}
.rr-thumb-empty{width:52px;height:52px;border-radius:4px;background:var(--panel-2);border:1px solid var(--line);}

/* ---------- Movement log: mobile row list + detail modal ---------- */
/* Hidden outside the mobile media query at the bottom of this file,
   which switches this and .log-table (the desktop table) on and off. */
.log-mobile-list{display:none;flex-direction:column;gap:8px;}
.log-row-mobile{
  display:flex;
  align-items:center;
  gap:12px;
  background:var(--white);
  border:1px solid var(--line);
  border-radius:4px;
  padding:12px 14px;
  cursor:pointer;
}
.log-row-mobile:active{border-color:var(--orange);}
.log-row-icon{
  width:24px;height:24px;
  border-radius:50%;
  display:flex;
  align-items:center;
  justify-content:center;
  font-size:13.5px;
  font-weight:700;
  line-height:1;
  color:var(--white);
  flex-shrink:0;
}
.log-icon-plus{background:var(--ok);}
.log-icon-minus{background:var(--err);}
.log-row-main{min-width:0;flex:1;}
.log-row-title{font-size:14px;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
.log-row-sub{font-size:12px;color:var(--ink-soft);font-family:'IBM Plex Mono',monospace;margin-top:2px;}

.log-detail-row{display:flex;justify-content:space-between;gap:12px;padding:8px 0;border-bottom:1px solid var(--line);font-size:13px;}
.log-detail-row:last-child{border-bottom:none;}
.log-detail-label{color:var(--ink-soft);font-family:'IBM Plex Mono',monospace;font-size:11px;text-transform:uppercase;letter-spacing:.04em;flex-shrink:0;}

/* ---------- List view ---------- */
.print-bar{
  display:flex;
  flex-wrap:wrap;
  justify-content:space-between;
  align-items:center;
  margin-bottom:14px;
  /* Column-gap doubles as the "at least this much room, or wrap" buffer
     Stian asked for -- once the toolbar and button can't both fit with
     50px between them, the button flexes down onto its own row. */
  gap:12px 50px;
}
.print-bar .toolbar{flex:1 1 320px;}
.print-bar .btn{padding:10px 16px;font-size:12px;flex-shrink:0;}

/* ---------- Auth gate ---------- */
.auth-gate{
  min-height:100vh;
  display:flex;
  align-items:center;
  justify-content:center;
  background:var(--navy);
}
.auth-card{
  background:var(--panel);
  border-radius:6px;
  padding:32px 30px;
  width:340px;
  display:flex;
  flex-direction:column;
}
.auth-card .logo{margin-bottom:18px;}
.auth-title{
  font-family:'Oswald',sans-serif;
  font-weight:600;
  font-size:20px;
  text-transform:uppercase;
  margin:0 0 18px;
  color:var(--ink);
}
.auth-card .btn{margin-top:20px;}
.auth-error{
  font-family:'IBM Plex Mono',monospace;
  font-size:12px;
  color:var(--err);
  min-height:16px;
  margin-top:10px;
}

/* ---------- Employee bar ---------- */
.employee-bar{
  background:var(--navy-2);
  border-radius:3px;
  padding:11px 12px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  margin-bottom:6px;
}
.employee-bar .s-sub{color:#9aa0a8;font-size:10px;text-transform:uppercase;letter-spacing:.05em;}
.employee-name{
  color:var(--white);
  font-family:'IBM Plex Mono',monospace;
  font-size:13px;
  font-weight:600;
}
.btn.small{padding:7px 10px;font-size:11px;}
/* Scoped to the (dark) employee bar only -- .btn.ghost elsewhere keeps its
   normal dark-on-light look from the base rule above. */
.employee-bar .btn.ghost{color:var(--white);border-color:#4a4f57;}
.btn.danger{
  background:var(--err);
  border:1px solid var(--err);
  color:var(--white);
}
.btn.danger:hover{background:#a92f2f;border-color:#a92f2f;}

/* ---------- Modal ---------- */
.modal-backdrop{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.5);
  display:flex;
  align-items:center;
  justify-content:center;
  z-index:50;
}
.modal-card{
  background:var(--panel);
  border-radius:6px;
  padding:26px;
  width:300px;
  display:flex;
  flex-direction:column;
}
.modal-title{
  font-family:'Oswald',sans-serif;
  font-weight:600;
  font-size:18px;
  text-transform:uppercase;
  margin:0 0 16px;
  color:var(--ink);
}
.modal-actions{display:flex;gap:10px;margin-top:18px;justify-content:flex-end;}

/* ---------- Print ---------- */
.print-only{display:none;}
@media print{
  body *{visibility:hidden;}
  .print-only, .print-only *{visibility:visible;}
  .print-only{display:block;position:absolute;top:0;left:0;width:100%;}
  .print-labels-grid{display:flex;flex-wrap:wrap;gap:8px;}
  .print-label{border:1px dashed #999;padding:10px;break-inside:avoid;box-sizing:border-box;width:calc(33.333% - 6px);}
  .print-label-title{font-weight:600;font-size:32px;}
  /* "Print selected EANs" (list.js) shares .print-label markup with the
     shelf-ID labels (map-edit.js) but needs its own, much smaller title
     size -- these labels also carry a category/shelf subtitle line the
     shelf-ID ones don't, so 32px read as oversized here specifically. */
  .print-label-title.small{font-size:16px;}
  .print-label-sub{font-family:monospace;color:#555;margin-bottom:6px;}
  .print-label-barcode{display:block;margin-top:4px;}
}

/* ---------- Settings ---------- */
.settings-grid{display:flex;flex-direction:column;gap:22px;max-width:520px;}
.settings-row{
  display:flex;
  justify-content:space-between;
  align-items:center;
  background:var(--white);
  border:1px solid var(--line);
  border-radius:3px;
  padding:16px;
}
.settings-row .s-label{font-weight:600;font-size:14px;}
.settings-row .s-sub{font-size:12px;color:var(--ink-soft);margin-top:2px;}

/* ==================================================================
   Mobile (mainly Zebra Android scanners) -- everything above this
   point is the untouched desktop layout. Every rule below only takes
   effect at <=768px, the same breakpoint isMobileViewport() (script.js)
   checks in JS, so CSS and JS agree on what counts as "mobile."
   ================================================================== */
@media (max-width: 768px) {
  /* ---------- App shell: sidebar becomes a top button grid ---------- */
  .app{grid-template-columns:1fr;}
  .sidebar{
    position:static;
    height:auto;
    flex-direction:row;
    flex-wrap:wrap;
    padding:14px;
    gap:8px;
  }
  .sidebar .logo{width:auto;margin-bottom:6px;margin-right:auto;}
  .nav-btn{flex:1 1 calc(50% - 4px);justify-content:center;padding:15px 10px;font-size:14px;}
  .nav-spacer{display:none;}
  /* Sits next to the logo, top right, on the same row -- order:0 (the
     default) ties it with the logo (also order:0), and DOM order then
     puts it after the logo but still ahead of the order:1-6 nav-btns,
     which wrap onto their own row below. */
  .employee-bar{order:0;width:auto;margin-bottom:6px;}

  /* Place product and Search first -- per Stian, that's what a scanner
     is mostly used for. Same buttons as desktop, just reordered via
     `order` (no separate mobile markup to keep in sync). */
  .nav-btn[data-page="pages/place.html"]{order:1;}
  .nav-btn[data-page="pages/search.html"]{order:2;}
  .nav-btn[data-page="pages/log.html"]{order:3;}
  .nav-btn[data-page="pages/map.html"]{order:4;}
  .nav-btn[data-page="pages/list.html"]{order:5;}
  .nav-btn[data-page="pages/settings.html"]{order:6;}

  main{padding:14px;}
  .page-title{font-size:20px;}
  .content-panel{padding:16px;min-height:0;}

  /* Toolbars (Search/Overview/Movement log filter rows) stack full-width
     instead of several narrow controls squeezed onto one line. */
  .toolbar > *{flex:1 1 100%;}

  /* Storage map: 3D view dropped for now (see the commented-out line in
     map.js) -- hides the toggle button and its rotate/reset controls so
     there's no way to reach a view that isn't there for mobile yet. */
  #view-toggle-btn, #iso-controls{display:none !important;}

  /* Map toolbar: +Room / Delete room / Print shelf labels are sized way up
     on desktop (.map-toolbar .btn.small above, ~2x normal .btn.small) for
     the scanner-friendly big-target feel -- too big to fit three across on
     a phone, so shrink them back down toward the normal .btn.small size. */
  .map-toolbar .btn.small{padding:7px 10px;font-size:12px;}

  /* Edit map, rack selected: the shelf-contents popover doesn't fit a
     phone screen usefully -- drop it and just pin rotate/delete full-width
     at the bottom, big enough to tap reliably. */
  .rack-side-panels .shelf-popover{display:none;}
  .rack-side-panels{
    position:fixed;
    bottom:0; left:0; right:0;
    width:auto;
    gap:0;
  }
  .rack-action-panel{
    border-radius:0;
    border-width:1px 0 0;
    box-shadow:0 -4px 18px rgba(0,0,0,.25);
    padding:10px 14px calc(10px + env(safe-area-inset-bottom));
  }
  .rack-action-btn{width:auto;flex:1;height:52px;}

  /* Map: pan-y keeps one-finger vertical scroll working natively (so the
     page can still be scrolled away from the map -- touch-action:none
     previously blocked that entirely) while still leaving pinch-zoom to
     the JS handler in map.js, since pan-y doesn't grant the browser its
     own pinch-zoom gesture. Mobile-only -- leaving this off on desktop
     keeps two-finger trackpad gestures untouched. */
  .map-canvas{touch-action:pan-y;}

  /* Search: minimap dropped for now (see the commented-out loadMinimap()
     call in search.js). */
  .search-minimap-frame{display:none !important;}

  /* Search results: let the cells wrap onto multiple lines instead of
     six-plus columns fighting for a phone-width row. */
  .result-row{flex-wrap:wrap;}
  .rr-cell{flex:1 1 45%;white-space:normal;}
  .rr-thumb, .rr-thumb-empty{order:-1;}

  /* Modals: never wider than the viewport, even the wider two
     (rack-modal/dims-modal, 380px on desktop). */
  .modal-card, #rack-modal .modal-card, #dims-modal .modal-card{width:92vw;max-width:380px;}
  .auth-card{width:92vw;max-width:340px;}

  /* Movement log: compact tappable rows (see log.js) instead of the
     5-column table, which has no room on a phone screen. */
  .log-table{display:none;}
  .log-mobile-list{display:flex;}

  /* Overview table: Room/Category/EAN deprioritized off-screen -- still
     in the DOM (and still in the printed EAN labels, which read from
     list.js's row data, not this table) but not shown on a phone. */
  .list-table-wrap th:nth-child(3), .list-table-wrap td:nth-child(3),
  .list-table-wrap th:nth-child(5), .list-table-wrap td:nth-child(5),
  .list-table-wrap th:nth-child(6), .list-table-wrap td:nth-child(6){
    display:none;
  }
}

/* ---------- Portrait lock (mobile only) ----------
   Real orientation-lock (screen.orientation.lock()) only works inside an
   installed/fullscreen PWA, not a plain browser tab -- so instead, on a
   phone-sized *and* landscape viewport, #rotate-lock gets counter-rotated
   back to portrait and resized to fill the (now swapped) viewport
   dimensions. The layout itself never sees landscape at all.
   (pointer:coarse) keeps this off an ordinary widened desktop browser
   window, which can also match max-width/orientation:landscape but always
   has a mouse. */
@media (max-width:768px) and (orientation:landscape) and (pointer:coarse){
  html, body{width:100%;height:100%;overflow:hidden;margin:0;}
  #rotate-lock{
    position:fixed;
    top:0;
    left:0;
    width:100vh;
    height:100vw;
    transform-origin:top left;
    transform:rotate(90deg) translateY(-100%);
    overflow-y:auto;
  }
}
