/* ==========================================================================
   川邊澄｜磁磚庫存管理系統 — Warm Architectural Ceramic Theme (v2)
   Mobile-First, High-Contrast Daylight Ready, Touch-Optimized
   ========================================================================== */

:root {
  /* Architectural Warm Ceramic Palette */
  --bg-page: #F6F4EF;
  --bg-surface: #FFFFFF;
  --bg-subtle: #EFECE5;
  --bg-muted: #E5E0D6;
  --bg-map: #FAF8F4;

  --text-main: #1C1B18;
  --text-sub: #5E5B53;
  --text-muted: #8C887E;

  /* Glaze Teal (Primary) & Terracotta (Target/Action) */
  --primary: #1F4E4A;
  --primary-hover: #173C39;
  --primary-soft: #E5EFEE;
  --primary-border: #B5D2CE;

  --accent: #C85A32;
  --accent-hover: #AD4924;
  --accent-soft: #FCEEE8;
  --accent-border: #F2C4B2;

  /* Semantic Status Colors */
  --ok: #256D4B;
  --ok-soft: #E6F4ED;
  --warn: #B86B14;
  --warn-soft: #FDF3E3;
  --danger: #B9382C;
  --danger-soft: #FDECEB;

  --border: #E2DDD2;
  --border-strong: #CBC4B5;

  --shadow-sm: 0 1px 3px rgba(28, 27, 24, 0.05), 0 1px 2px rgba(28, 27, 24, 0.03);
  --shadow-md: 0 6px 20px rgba(28, 27, 24, 0.08);
  --shadow-lg: 0 16px 40px rgba(28, 27, 24, 0.16);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;

  --header-h: 64px;
  --toolbar-h: 58px;
  --bottom-nav-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100vw;
  height: 100%;
  background: var(--bg-page);
  color: var(--text-main);
  font-family: 'Inter', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   Header
   ========================================================================== */
.app-header {
  height: var(--header-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--primary);
  padding: 6px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  flex-shrink: 0;
}

.brand-mark span {
  background: rgba(255, 255, 255, 0.88);
  border-radius: 2px;
}

.brand-mark span:last-child {
  background: #F4A27E;
}

.brand-text h1 {
  margin: 0;
  font-size: 16.5px;
  font-weight: 800;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand-text p {
  margin: 1px 0 0;
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 500;
}

/* KPI Strip */
.kpis {
  display: flex;
  align-items: center;
  gap: 8px;
}

.kpi {
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 12px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.kpi-label {
  font-size: 12px;
  color: var(--text-sub);
}

.kpi strong {
  font-size: 14.5px;
  font-weight: 800;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px var(--ok-soft);
}

/* Buttons */
.btn {
  height: 38px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13.5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-accent {
  background: var(--accent);
  color: #fff;
}

.btn-accent:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  background: var(--bg-subtle);
  color: var(--text-main);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--bg-muted);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger-ghost {
  color: var(--danger);
  background: var(--danger-soft);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-sub);
  background: var(--bg-page);
  border: 1px solid var(--border);
  position: relative;
}

.icon-btn:hover {
  color: var(--text-main);
  background: var(--bg-subtle);
}

/* Dropdown Menu */
.menu-wrap {
  position: relative;
}

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: 240px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  display: none;
  z-index: 100;
}

.menu.open {
  display: block;
}

.menu-item {
  display: flex;
  flex-direction: column;
  width: 100%;
  text-align: left;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-main);
}

.menu-item:hover {
  background: var(--bg-page);
}

.menu-item strong {
  font-size: 13.5px;
  font-weight: 700;
}

.menu-item span {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ==========================================================================
   Toolbar (Mode Switcher + Search + Filters)
   ========================================================================== */
.toolbar {
  height: var(--toolbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 25;
}

.seg {
  display: inline-flex;
  background: var(--bg-subtle);
  padding: 3px;
  border-radius: 10px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.seg-btn {
  height: 34px;
  padding: 0 13px;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-sub);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.seg-btn em {
  font-style: normal;
  font-size: 11.5px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 99px;
  background: rgba(28, 27, 24, 0.08);
  color: var(--text-sub);
}

.seg-btn.active {
  background: var(--bg-surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.seg-btn.active em {
  background: var(--primary-soft);
  color: var(--primary);
}

.search {
  position: relative;
  flex: 1;
  max-width: 460px;
  min-width: 140px;
}

.search-ico {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 17px;
  height: 17px;
  color: var(--text-muted);
  pointer-events: none;
}

.search input {
  width: 100%;
  height: 40px;
  padding: 0 34px 0 36px;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14.5px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

.search input:focus {
  background: var(--bg-surface);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: var(--text-muted);
  font-size: 13px;
}

.filter-toggle {
  display: none;
}

.filter-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 99px;
  background: var(--accent);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.filters {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.filters-head, .show-mobile {
  display: none;
}

.field-inline {
  display: inline-flex;
  align-items: center;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  height: 38px;
  padding: 0 8px 0 10px;
  gap: 6px;
}

.field-inline > span {
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.field-inline select {
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  outline: none;
  padding-right: 4px;
  cursor: pointer;
}

/* ==========================================================================
   Main Split Workspace
   ========================================================================== */
.workspace {
  height: calc(100vh - var(--header-h) - var(--toolbar-h));
  display: grid;
  grid-template-columns: minmax(420px, 47%) 1fr;
  overflow: hidden;
}

/* Left List Pane */
.list-pane {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  border-right: 1px solid var(--border);
  background: var(--bg-page);
}

.list-summary {
  padding: 10px 18px;
  font-size: 12.5px;
  color: var(--text-sub);
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.list-summary strong {
  color: var(--text-main);
  font-weight: 700;
}

.cards {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  overscroll-behavior: contain;
}

/* Skeleton Loader */
.skeleton {
  height: 116px;
  border-radius: var(--radius-md);
  background: linear-gradient(90deg, var(--bg-subtle) 25%, var(--bg-surface) 50%, var(--bg-subtle) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ==========================================================================
   Inventory Cards (Clean, Tactile, Uncluttered)
   ========================================================================== */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px 14px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
  cursor: pointer;
}

.card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

.card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-border), var(--shadow-md);
}

.card.returned {
  opacity: 0.65;
}

.card-main {
  display: flex;
  gap: 13px;
  align-items: flex-start;
}

.thumb {
  width: 68px;
  height: 68px;
  border-radius: 10px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-empty {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  padding: 4px;
  line-height: 1.25;
}

.card-body {
  flex: 1;
  min-width: 0;
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.badges {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--bg-subtle);
  color: var(--text-sub);
}

.badge-vendor {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
}

.badge-ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge-ret {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-checked {
  background: var(--ok-soft);
  color: var(--ok);
}

.card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.3;
  word-break: break-word;
}

.card-stats {
  margin-top: 7px;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px 14px;
  font-size: 13px;
  color: var(--text-sub);
}

.stat-qty {
  font-size: 16px;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.stat-cut {
  font-size: 12px;
  color: var(--warn);
  font-weight: 600;
}

/* Pallet Pill Strip inside Group Card */
.pallet-row {
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px dashed var(--border);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.p-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 7px;
  font-size: 12.5px;
  font-weight: 700;
  background: var(--bg-page);
  border: 1px solid var(--border);
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

.p-pill.located {
  background: var(--primary-soft);
  border-color: var(--primary-border);
  color: var(--primary);
}

.p-pill.special {
  background: var(--warn-soft);
  border-color: #EED1A7;
  color: var(--warn);
}

.p-pill small {
  font-weight: 500;
  font-size: 11.5px;
  opacity: 0.82;
}

.p-pill-pin {
  margin-left: auto;
  padding: 4px 10px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* Pallet-Mode Card Header */
.pallet-no-tag {
  font-size: 17px;
  font-weight: 900;
  color: var(--primary);
  background: var(--primary-soft);
  border: 1px solid var(--primary-border);
  padding: 3px 10px;
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
}

.pallet-items-mini {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pallet-item-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 9px;
  border-radius: 8px;
  background: var(--bg-page);
  font-size: 13.5px;
}

.pallet-item-line strong {
  font-weight: 700;
}

/* ==========================================================================
   Right Pane: Interactive Floor Plan Map (No Arbitrary Zones)
   ========================================================================== */
.map-pane {
  position: relative;
  height: 100%;
  background: var(--bg-map);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.map-topbar {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.map-focus {
  pointer-events: auto;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  border: 1.5px solid var(--accent);
  border-radius: 12px;
  padding: 7px 10px 7px 13px;
  box-shadow: var(--shadow-md);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
}

.map-focus-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.map-focus-text strong {
  color: var(--accent);
  font-weight: 800;
}

.chip-btn {
  padding: 4px 10px;
  border-radius: 7px;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.chip-btn.ghost {
  background: var(--bg-subtle);
  color: var(--text-sub);
  padding: 4px 8px;
}

.map-hint {
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 6px 13px;
  font-size: 12.5px;
  color: var(--text-sub);
  box-shadow: var(--shadow-sm);
}

.map-canvas {
  flex: 1;
  width: 100%;
  height: 100%;
  position: relative;
  touch-action: none;
  user-select: none;
  cursor: grab;
}

.map-canvas.dragging {
  cursor: grabbing;
}

.map-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.map-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--text-muted);
  background: var(--bg-map);
}

/* CAD Architectural Lines */
.cad-wall { stroke: #6E6A61; stroke-width: 9; stroke-linecap: round; }
.cad-col { stroke: #45423B; stroke-width: 11; fill: rgba(69, 66, 59, 0.12); }
.cad-stair { stroke: #9E998E; stroke-width: 5; }
.cad-elevator { stroke: #3B7A72; stroke-width: 7; }
.cad-opening { stroke: #B5AFA2; stroke-width: 5; }
.cad-floor { stroke: #C9C3B6; stroke-width: 4; }

.landmark-pill {
  fill: rgba(255, 255, 255, 0.92);
  stroke: #B5D2CE;
  stroke-width: 5;
}

.landmark-text {
  fill: #1F4E4A;
  font-size: 38px;
  font-weight: 800;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

/* Pallet Slots on Map */
.slot {
  cursor: pointer;
}

.slot-rect {
  stroke-width: 4.5;
  transition: opacity 0.15s, fill 0.15s, stroke 0.15s;
}

.slot-text {
  font-family: 'Inter', 'Noto Sans TC', sans-serif;
  font-weight: 800;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

/* Slot types */
.slot-numbered .slot-rect {
  fill: #FFFFFF;
  stroke: #2A645E;
}
.slot-numbered .slot-text {
  fill: #183E3A;
}

.slot-special .slot-rect {
  fill: #FDF3E3;
  stroke: #C97A1D;
}
.slot-special .slot-text {
  fill: #9A580B;
}

.slot-unknown .slot-rect {
  fill: #F3EFE6;
  stroke: #9C9588;
  stroke-dasharray: 10 6;
}
.slot-unknown .slot-text {
  fill: #787266;
}

.slot-empty .slot-rect {
  fill: rgba(226, 221, 210, 0.38);
  stroke: #CBC4B5;
  stroke-dasharray: 8 8;
}

/* Highlight States */
.map-svg.has-highlight .slot.dimmed {
  opacity: 0.22;
}

.slot.hl-primary .slot-rect {
  fill: #C85A32 !important;
  stroke: #7A2B10 !important;
  stroke-width: 9 !important;
  stroke-dasharray: none !important;
}
.slot.hl-primary .slot-text {
  fill: #FFFFFF !important;
}

.slot.hl-secondary .slot-rect {
  fill: #1F7A70 !important;
  stroke: #0F4741 !important;
  stroke-width: 7 !important;
  stroke-dasharray: none !important;
}
.slot.hl-secondary .slot-text {
  fill: #FFFFFF !important;
}

@keyframes pulseRing {
  0% { stroke-opacity: 0.95; stroke-width: 10; }
  100% { stroke-opacity: 0; stroke-width: 34; }
}

.pin-pulse {
  fill: none;
  stroke: #C85A32;
  pointer-events: none;
  animation: pulseRing 1.6s ease-out infinite;
}

/* Floating Map Controls & Legend */
.map-controls {
  position: absolute;
  right: 14px;
  bottom: 52px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 10;
}

.map-ctl {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-md);
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
}

.map-ctl:active {
  background: var(--bg-subtle);
}

.map-legend {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 10px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 11.5px;
  color: var(--text-sub);
  pointer-events: none;
}

.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.lg {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}
.lg-target { background: #C85A32; }
.lg-related { background: #1F7A70; }
.lg-num { background: #FFFFFF; border: 2px solid #2A645E; }
.lg-special { background: #FDF3E3; border: 2px solid #C97A1D; }
.lg-unknown { background: #F3EFE6; border: 1.5px dashed #9C9588; }
.lg-empty { background: rgba(226, 221, 210, 0.5); border: 1.5px dashed #CBC4B5; }

/* ==========================================================================
   Bottom / Side Detail Sheet (Instant On-Site Editing & Check)
   ========================================================================== */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28, 27, 24, 0.36);
  z-index: 60;
}

.sheet {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 460px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 96px);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  z-index: 70;
  display: flex;
  flex-direction: column;
  transform: translateY(115%);
  transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
  overflow: hidden;
}

.sheet.open {
  transform: translateY(0);
}

.sheet-grip {
  padding: 8px 0 2px;
  display: flex;
  justify-content: center;
}

.sheet-grip span {
  width: 38px;
  height: 4px;
  border-radius: 99px;
  background: var(--border-strong);
}

.sheet-head {
  padding: 6px 16px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.sheet-title {
  min-width: 0;
}

.sheet-title h3 {
  margin: 2px 0 0;
  font-size: 17px;
  font-weight: 800;
  line-height: 1.3;
}

.sheet-body {
  padding: 14px 16px calc(18px + var(--safe-bottom));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Detail Item Block inside Sheet (with +/- Quantity Stepper!) */
.s-hero {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--bg-page);
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.s-hero .thumb {
  width: 60px;
  height: 60px;
}

.s-hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 13px;
  color: var(--text-sub);
}

.s-hero-meta strong {
  color: var(--text-main);
  font-weight: 800;
}

.s-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.s-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.s-item-title {
  font-weight: 800;
  font-size: 15px;
}

.s-item-sub {
  font-size: 12.5px;
  color: var(--text-sub);
}

/* Original vs Final Qty Comparison & Transaction Log Ledger */
.qty-summary-box {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: var(--bg-page);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.qty-summary-box.single {
  grid-template-columns: 1fr;
}

.qty-col {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.qty-col span {
  font-size: 11.5px;
  color: var(--text-sub);
  font-weight: 600;
}

.qty-col strong {
  font-size: 17px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text-main);
}

.qty-col.final strong {
  color: var(--accent);
}

.qty-col.delta-neg strong {
  color: var(--danger);
}

.qty-col.delta-pos strong {
  color: var(--ok);
}

/* Add Log Form inside Item Card */
.log-form {
  display: flex;
  flex-direction: column;
  gap: 7px;
  background: var(--bg-subtle);
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.log-form-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.log-type-seg {
  display: inline-flex;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 2px;
  flex-shrink: 0;
}

.log-type-btn {
  height: 32px;
  padding: 0 10px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-sub);
}

.log-type-btn.active[data-sign="-1"] {
  background: var(--danger);
  color: #fff;
}

.log-type-btn.active[data-sign="1"] {
  background: var(--ok);
  color: #fff;
}

.log-qty-input {
  width: 84px;
  height: 36px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  font-size: 15px;
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.log-note-input {
  flex: 1;
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  font-size: 13.5px;
}

.log-submit-btn {
  height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

/* Log History List */
.log-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.log-list-title {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-sub);
}

.log-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 9px;
  border-radius: 7px;
  background: var(--bg-page);
  border: 1px solid var(--border);
  font-size: 12.5px;
}

.log-delta {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.log-delta.neg { color: var(--danger); }
.log-delta.pos { color: var(--ok); }

.log-note {
  flex: 1;
  min-width: 0;
  color: var(--text-main);
  word-break: break-word;
}

.log-time {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.log-del {
  color: var(--text-muted);
  font-size: 12px;
  padding: 2px 5px;
  border-radius: 4px;
}

.log-del:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

/* ==========================================================================
   Modals, Keypad, Lightbox & Toast
   ========================================================================== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(28, 27, 24, 0.48);
  backdrop-filter: blur(3px);
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: var(--bg-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 18px 20px;
}

.modal-card.narrow {
  max-width: 380px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-head h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 11px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field.full {
  grid-column: 1 / -1;
}

.field > span {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-sub);
}

.field input, .field select {
  height: 42px;
  padding: 0 12px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: var(--bg-page);
  font-size: 15px;
  outline: none;
}

.field input:focus, .field select:focus {
  background: var(--bg-surface);
  border-color: var(--primary);
}

.modal-foot {
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.spacer {
  flex: 1;
}

/* Number Pad for Fast Pallet Lookup */
.pad-card {
  max-width: 320px;
}

.pad-display {
  height: 54px;
  background: var(--bg-page);
  border: 1.5px solid var(--border-strong);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 28px;
  margin-bottom: 12px;
  font-variant-numeric: tabular-nums;
}

.pad-display span {
  color: var(--text-muted);
  font-weight: 700;
}

.pad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.pad-grid button {
  height: 54px;
  border-radius: 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  font-size: 20px;
  font-weight: 800;
}

.pad-grid button:active {
  background: var(--primary-soft);
}

.pad-grid .pad-go {
  background: var(--primary);
  color: #fff;
  font-size: 16px;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(18, 17, 15, 0.88);
  z-index: 110;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.lightbox img {
  max-width: 92vw;
  max-height: 78vh;
  border-radius: 12px;
  background: #fff;
}

.lightbox-cap {
  margin-top: 12px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottom-nav-h) + 20px);
  transform: translateX(-50%);
  background: #1C1B18;
  color: #fff;
  padding: 10px 18px;
  border-radius: 99px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 120;
  white-space: nowrap;
}

.toast.err {
  background: var(--danger);
}

/* Mobile Bottom Nav (Hidden on Desktop) */
.bottom-nav {
  display: none;
}

/* ==========================================================================
   Mobile & Tablet Optimization (<= 920px)
   ========================================================================== */
@media (max-width: 1100px) {
  .kpis .kpi:nth-child(4) {
    display: none;
  }
}

@media (max-width: 920px) {
  :root {
    --header-h: 54px;
    --toolbar-h: 54px;
  }

  .hide-mobile, .kpis, #modeSeg {
    display: none !important;
  }

  .app-header {
    padding: 0 12px;
  }

  .toolbar {
    padding: 0 12px;
    gap: 8px;
  }

  .search {
    max-width: none;
  }

  .search input {
    font-size: 16px; /* Prevents iOS zoom on focus */
  }

  .filter-toggle {
    display: inline-flex;
  }

  /* Filters become a bottom sheet on mobile */
  .filters {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-strong);
    border-radius: 20px 20px 0 0;
    box-shadow: var(--shadow-lg);
    padding: 16px 16px calc(20px + var(--safe-bottom));
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    z-index: 85;
  }

  .filters.open {
    display: flex;
  }

  .filters-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
  }

  .field-inline {
    height: 44px;
    justify-content: space-between;
  }

  .field-inline select {
    font-size: 15px;
  }

  .show-mobile {
    display: inline-flex;
  }

  /* Single active pane on mobile controlled by workspace[data-view] */
  .workspace {
    width: 100%;
    height: calc(100dvh - var(--header-h) - var(--toolbar-h) - var(--bottom-nav-h) - var(--safe-bottom));
    grid-template-columns: minmax(0, 1fr);
  }

  .list-pane {
    min-width: 0;
    width: 100%;
    border-right: none;
  }

  .workspace[data-view="map"] .list-pane {
    display: none;
  }

  .workspace:not([data-view="map"]) .map-pane {
    display: none;
  }

  .cards {
    padding: 10px 12px 24px;
  }

  /* Bottom Sheet full-width on mobile */
  .sheet {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    max-height: 86dvh;
    border-radius: 20px 20px 0 0;
    border-bottom: none;
  }

  /* Mobile Bottom Navigation Bar */
  .bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(var(--bottom-nav-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: center;
    z-index: 50;
  }

  .nav-btn {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 700;
  }

  .nav-btn svg {
    width: 22px;
    height: 22px;
  }

  .nav-btn.active {
    color: var(--primary);
  }

  .nav-add {
    width: 46px;
    height: 46px;
    margin: 0 auto;
    border-radius: 14px;
    background: var(--accent);
    color: #fff !important;
    box-shadow: 0 4px 12px rgba(200, 90, 50, 0.35);
  }
}
