:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #0d9488;
  --primary-hover: #0f766e;
  --primary-soft: #ccfbf1;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --amber: #f59e0b;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 100%;
  overflow-x: clip;
}

/* ---------- Topbar ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 40;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  max-width: 100%;
}

.topbar-center {
  flex: 1 1 240px;
  max-width: 440px;
  min-width: 0;
  width: 100%;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #0d9488, #0284c7);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-sm);
}

.brand-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.15;
}

.brand-sub {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.camper-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
  flex-wrap: wrap;
  max-width: 100%;
}

.camper-picker select {
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  font-weight: 600;
  color: var(--text);
  min-width: 130px;
  max-width: 100%;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 11px;
  font-size: 0.85rem;
  pointer-events: none;
  opacity: 0.7;
}

.search-box input {
  width: 100%;
  padding: 8px 72px 8px 34px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface-alt);
  font-size: 0.88rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.search-box input:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
}

.search-count {
  position: absolute;
  right: 10px;
  font-size: 0.74rem;
  font-weight: 700;
  background: var(--amber);
  color: #fff;
  padding: 2px 8px;
  border-radius: 999px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.86rem;
  padding: 8px 14px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.82rem;
}

.btn-icon {
  padding: 6px 8px;
  font-size: 0.92rem;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-outline {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-outline:hover {
  background: var(--surface-alt);
  border-color: var(--text-muted);
}

.btn-outline.active {
  background: #0f172a;
  color: #fff;
  border-color: #0f172a;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
}

.btn-danger-ghost:hover {
  background: var(--danger-soft);
}

/* ---------- Workspace Layout ---------- */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 18px;
  padding: 18px 20px 24px;
  max-width: 1760px;
  width: 100%;
  margin: 0 auto;
  align-items: start;
}

/* ---------- Blueprint Panel ---------- */
.blueprint-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.blueprint-toolbar {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.level-tabs {
  display: inline-flex;
  background: var(--bg);
  padding: 4px;
  border-radius: 10px;
  gap: 4px;
}

.level-tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.83rem;
  padding: 6px 12px;
  border-radius: 7px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.level-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.tab-badge {
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--border);
  color: var(--text);
  padding: 1px 6px;
  border-radius: 999px;
}

.level-tab.active .tab-badge {
  background: var(--primary-soft);
  color: var(--primary-hover);
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.snap-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
}

.snap-toggle:hover {
  background: var(--surface-alt);
}

.zoom-controls {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
}

.zoom-btn,
.zoom-label {
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s;
}

.zoom-btn {
  width: 28px;
  font-size: 1rem;
}

.zoom-label {
  min-width: 48px;
  padding: 0 6px;
  font-size: 0.78rem;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  color: var(--text-muted);
}

.zoom-btn:hover:not(:disabled),
.zoom-label:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.zoom-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.blueprint-hint {
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  padding: 7px 16px;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
}

.blueprint-hint.draw-active {
  background: #fef3c7;
  color: #92400e;
  font-weight: 600;
}

.stages-wrapper {
  --zoom: 1;
  padding: 18px 16px 24px;
  display: flex;
  justify-content: safe center;
  align-items: flex-start;
  gap: 24px;
  flex-wrap: nowrap;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background:
    radial-gradient(circle at 1px 1px, #cbd5e1 1px, transparent 0);
  background-size: 22px 22px;
  min-height: 520px;
}

.stage-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  width: min(calc(360px * var(--zoom, 1)), calc(100% * var(--zoom, 1)));
}

.stages-wrapper.dual-mode {
  display: grid;
  grid-template-columns: repeat(2, calc(320px * var(--zoom, 1)));
  justify-content: safe center;
  gap: 16px;
}

.stages-wrapper.dual-mode .stage-column {
  width: 100%;
  max-width: none;
}

.stages-wrapper.landscape {
  flex-direction: column;
  align-items: safe center;
  justify-content: flex-start;
  min-height: 460px;
}

.stages-wrapper.landscape .stage-column {
  width: min(calc(760px * var(--zoom, 1)), calc(100% * var(--zoom, 1)));
}

.stages-wrapper.dual-mode.landscape {
  display: flex;
  flex-direction: column;
  align-items: safe center;
  justify-content: flex-start;
  gap: 18px;
}

.stages-wrapper.dual-mode.landscape .stage-column {
  width: min(calc(680px * var(--zoom, 1)), calc(100% * var(--zoom, 1)));
}

.stages-wrapper.zoom-compact .comp-label {
  font-size: 0.62rem;
}

.stages-wrapper.zoom-compact .comp-count {
  font-size: 0.54rem;
  padding: 1px 4px;
}

.stage-caption {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 4px 12px;
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}

.level-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.level-dot.upper { background: #3b82f6; }
.level-dot.lower { background: #10b981; }

.camper-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 400 / 720;
  user-select: none;
  touch-action: pan-x pan-y pinch-zoom;
}

.camper-stage.landscape {
  aspect-ratio: 720 / 400;
}

.camper-stage.draw-mode {
  cursor: crosshair;
  touch-action: none;
}

.camper-svg {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

/* ---------- Interactive Compartment Box ---------- */
.compartment {
  position: absolute;
  border-radius: 8px;
  border: 2px solid var(--comp-color, #3b82f6);
  background: color-mix(in srgb, var(--comp-color, #3b82f6) 22%, white);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.1);
  cursor: grab;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 4px 6px;
  text-align: center;
  overflow: visible;
  transition: box-shadow 0.15s, transform 0.08s;
  touch-action: none;
}

.compartment:hover {
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.16);
}

.compartment.dragging,
.compartment.resizing {
  cursor: grabbing;
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.22);
  opacity: 0.96;
}

.compartment.selected {
  box-shadow: 0 0 0 3px rgba(15, 23, 42, 0.22), 0 8px 20px rgba(15, 23, 42, 0.18);
  z-index: 30 !important;
}

.compartment.search-match {
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.7), 0 8px 20px rgba(245, 158, 11, 0.3);
  animation: pulse-match 1.6s infinite;
}

.compartment.search-dim {
  opacity: 0.38;
}

@keyframes pulse-match {
  0%, 100% { box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.75); }
  50% { box-shadow: 0 0 0 7px rgba(245, 158, 11, 0.28); }
}

.comp-content,
.comp-content * {
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

.comp-content {
  width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.comp-label {
  font-size: 0.74rem;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.15;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

.comp-count {
  font-size: 0.62rem;
  font-weight: 700;
  color: #fff;
  background: var(--comp-color, #3b82f6);
  padding: 1px 5px;
  border-radius: 999px;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.comp-match-pill {
  font-size: 0.64rem;
  font-weight: 700;
  background: #f59e0b;
  color: #fff;
  padding: 1px 5px;
  border-radius: 4px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Live geometry HUD while moving/resizing */
.comp-hud {
  position: absolute;
  top: -26px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 5px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 60;
}

/* 8 Resize Handles */
.resize-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #ffffff;
  border: 2px solid #0f172a;
  border-radius: 50%;
  z-index: 40;
  display: none;
  touch-action: none;
}

.compartment.selected .resize-handle {
  display: block;
}

.resize-handle:hover {
  background: var(--primary);
  border-color: #fff;
  transform: scale(1.2);
}

.resize-handle.nw { top: -6px; left: -6px; cursor: nwse-resize; }
.resize-handle.ne { top: -6px; right: -6px; cursor: nesw-resize; }
.resize-handle.sw { bottom: -6px; left: -6px; cursor: nesw-resize; }
.resize-handle.se { bottom: -6px; right: -6px; cursor: nwse-resize; }
.resize-handle.n  { top: -6px; left: 50%; margin-left: -6px; cursor: ns-resize; border-radius: 3px; width: 16px; height: 9px; margin-left: -8px; }
.resize-handle.s  { bottom: -6px; left: 50%; margin-left: -8px; cursor: ns-resize; border-radius: 3px; width: 16px; height: 9px; }
.resize-handle.w  { left: -6px; top: 50%; margin-top: -8px; cursor: ew-resize; border-radius: 3px; width: 9px; height: 16px; }
.resize-handle.e  { right: -6px; top: 50%; margin-top: -8px; cursor: ew-resize; border-radius: 3px; width: 9px; height: 16px; }

@media (pointer: coarse) {
  .resize-handle {
    width: 16px;
    height: 16px;
  }
  .resize-handle.nw { top: -8px; left: -8px; }
  .resize-handle.ne { top: -8px; right: -8px; }
  .resize-handle.sw { bottom: -8px; left: -8px; }
  .resize-handle.se { bottom: -8px; right: -8px; }
  .resize-handle.n  { top: -7px; width: 22px; height: 12px; margin-left: -11px; }
  .resize-handle.s  { bottom: -7px; width: 22px; height: 12px; margin-left: -11px; }
  .resize-handle.w  { left: -7px; width: 12px; height: 22px; margin-top: -11px; }
  .resize-handle.e  { right: -7px; width: 12px; height: 22px; margin-top: -11px; }
}

/* Draw preview rectangle */
.draw-preview {
  position: absolute;
  border: 2px dashed var(--primary);
  background: rgba(13, 148, 136, 0.18);
  border-radius: 8px;
  pointer-events: none;
  z-index: 50;
}

/* ---------- Inspector Panel ---------- */
.inspector-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 96px);
  overflow: hidden;
}

.inspector-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
}

.inspector-tab {
  border: none;
  background: transparent;
  padding: 12px 10px;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.inspector-tab.active {
  color: var(--primary-hover);
  background: var(--surface);
  border-bottom-color: var(--primary);
}

.inspector-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.empty-state {
  text-align: center;
  padding: 40px 18px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 2.5rem;
  margin-bottom: 8px;
}

.empty-state h3 {
  margin: 0 0 8px;
  color: var(--text);
}

.empty-tip {
  font-size: 0.84rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
}

.card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card-title {
  margin: 0;
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.comp-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.comp-name-input {
  flex: 1;
  font-size: 1.05rem;
  font-weight: 700;
  border: 1px solid transparent;
  background: transparent;
  padding: 5px 8px;
  border-radius: 6px;
  color: var(--text);
}

.comp-name-input:hover,
.comp-name-input:focus {
  background: #fff;
  border-color: var(--border-strong);
  outline: none;
}

.comp-quick-actions {
  display: flex;
  gap: 2px;
}

.comp-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field > label,
.field > span {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-muted);
}

.field input,
.field select,
.inline-field input,
.inline-field select,
.add-item-form input,
.add-item-form select,
.all-items-filters select {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: #fff;
  font-size: 0.85rem;
  font-family: inherit;
  color: var(--text);
}

.field input:focus,
.field select:focus,
.add-item-form input:focus,
.add-item-form select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.14);
}

.mini-segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--border);
  padding: 3px;
  border-radius: 7px;
  gap: 3px;
}

.mini-segmented button {
  border: none;
  background: transparent;
  padding: 5px 6px;
  border-radius: 5px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.mini-segmented button.active {
  background: #fff;
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.color-swatches {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding-top: 2px;
}

.color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.12s;
}

.color-swatch:hover {
  transform: scale(1.14);
}

.color-swatch.active {
  border-color: #0f172a;
  box-shadow: 0 0 0 2px #fff inset;
}

.geometry-details summary {
  font-size: 0.77rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.geometry-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.geometry-grid label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.geometry-grid input {
  width: 100%;
  padding: 5px 6px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: #fff;
  font-size: 0.8rem;
}

/* ---------- Add Item Form ---------- */
.add-item-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-row {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.form-row > * {
  min-width: 0;
}

.form-row-3 {
  grid-template-columns: 78px 80px 1fr;
}

.form-row-submit {
  grid-template-columns: 1fr auto;
}

.inline-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.inline-field span {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* ---------- Items List ---------- */
.items-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.items-section-header h3 {
  margin: 0;
  font-size: 0.9rem;
}

.muted {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.82rem;
}

.items-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-row {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  transition: border-color 0.15s;
}

.item-row:hover {
  border-color: var(--border-strong);
}

.item-row.out-of-stock {
  background: #fef2f2;
  border-color: #fecaca;
}

.item-main {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.item-name {
  font-weight: 700;
  font-size: 0.9rem;
  word-break: break-word;
}

.item-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
}

.pill {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-muted);
}

.pill-warn {
  background: #fee2e2;
  color: #b91c1c;
}

.pill-comp {
  background: var(--primary-soft);
  color: var(--primary-hover);
  cursor: pointer;
}

.item-notes {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.item-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.qty-stepper {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-alt);
}

.qty-btn {
  border: none;
  background: transparent;
  width: 28px;
  height: 30px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  display: grid;
  place-items: center;
}

.qty-btn:hover {
  background: var(--border);
}

.qty-input {
  width: 44px;
  height: 30px;
  border: none;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  text-align: center;
  font-weight: 700;
  font-size: 0.85rem;
  background: #fff;
  color: var(--text);
  -moz-appearance: textfield;
}

.qty-input::-webkit-inner-spin-button,
.qty-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.qty-unit {
  font-size: 0.74rem;
  color: var(--text-muted);
  min-width: 22px;
}

/* ---------- All Items Overview ---------- */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat-tile {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  text-align: center;
}

.stat-value {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text);
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
}

.all-items-filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.checkbox-pill {
  grid-column: 1 / -1;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: 100vw;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 100;
  backdrop-filter: blur(2px);
  overflow-x: hidden;
  overflow-y: auto;
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: min(440px, calc(100vw - 24px));
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.modal-card-wide {
  max-width: min(580px, calc(100vw - 24px));
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
}

#modal-item {
  z-index: 120;
}

.modal-comp-header-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1;
}

.modal-comp-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.comp-color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.modal-comp-body {
  padding: 16px 18px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  -webkit-overflow-scrolling: touch;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.05rem;
  word-break: break-word;
}

.modal-form {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  cursor: pointer;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 6px;
}

.modal-footer-left,
.modal-footer-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ---------- Demo Banner & Account Controls ---------- */
.auth-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 8px;
  border-left: 1px solid var(--border);
}

.user-badge {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--primary-hover);
  background: var(--primary-soft);
  padding: 4px 10px;
  border-radius: 999px;
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.demo-banner {
  background: #fef3c7;
  border-bottom: 1px solid #fcd34d;
  color: #78350f;
  padding: 8px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.84rem;
}

.demo-banner-text {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 260px;
  line-height: 1.35;
}

.demo-pill {
  background: #d97706;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.demo-banner-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
}

.auth-tab {
  border: none;
  background: transparent;
  padding: 11px 10px;
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.auth-tab.active {
  color: var(--primary-hover);
  background: var(--surface);
  border-bottom-color: var(--primary);
}

.auth-input-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.auth-input-wrap input {
  flex: 1;
}

.auth-error {
  background: var(--danger-soft);
  color: #b91c1c;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
}

.verify-intro {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.45;
  word-break: break-word;
}

.verify-code-input {
  text-align: center;
  font-size: 1.4rem !important;
  font-weight: 800;
  letter-spacing: 0.35em;
  padding: 10px 12px !important;
}

/* ---------- Toasts ---------- */
.toast-container {
  position: fixed;
  bottom: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}

.toast {
  background: #0f172a;
  color: #fff;
  padding: 10px 14px;
  border-radius: 9px;
  font-size: 0.84rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease;
}

.toast.error {
  background: var(--danger);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .inspector-panel {
    position: static;
    max-height: none;
  }
}

@media (max-width: 680px) {
  .stages-wrapper.dual-mode {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .topbar {
    padding: 10px 12px;
    gap: 10px;
  }
  .auth-actions {
    padding-left: 0;
    border-left: none;
  }
  .demo-banner {
    padding: 10px 12px;
    font-size: 0.8rem;
  }
  .user-badge {
    max-width: 140px;
  }
  .camper-picker {
    padding-left: 0;
    border-left: none;
    width: 100%;
  }
  .camper-picker select {
    flex: 1 1 120px;
  }
  .workspace {
    padding: 10px;
    gap: 12px;
  }
  .blueprint-toolbar {
    padding: 10px 12px;
  }
  .level-tabs {
    width: 100%;
    justify-content: space-between;
  }
  .level-tab {
    flex: 1;
    justify-content: center;
    padding: 6px 6px;
    font-size: 0.78rem;
  }
  .comp-meta-grid {
    grid-template-columns: 1fr;
  }
  .form-row-3 {
    grid-template-columns: 1fr 1fr;
  }
  .form-row-3 > :last-child {
    grid-column: 1 / -1;
  }
  .form-row-submit {
    grid-template-columns: 1fr;
  }
  .modal-backdrop {
    padding: 8px;
    align-items: flex-end;
  }
  .modal-card,
  .modal-card-wide {
    max-width: calc(100vw - 16px);
    max-height: 88dvh;
    border-radius: 14px;
  }
  .modal-header {
    padding: 12px 14px;
  }
  .modal-comp-body,
  .modal-form {
    padding: 12px 14px;
    gap: 10px;
  }
  .modal-backdrop input,
  .modal-backdrop select {
    font-size: 16px;
  }
  .item-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px;
  }
  .item-controls {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }
  .modal-footer {
    flex-wrap: wrap;
    gap: 8px;
  }
}
