/* ============================================================
   TogoPrint DTF Gang Sheet Builder — V4.1
   Original brand colors preserved. UI/UX enhancements added.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');

:root {
  /* Base colors — do not change these here.
     Primary (--blue) and accent (--brand) are injected from config.php.
     Override them there for white-label deployments. */
  --bg:    #f5f7fb;
  --panel: #fff;
  --ink:   #172033;
  --muted: #5d6678;
  --blue:  #2e4fa3;   /* overridden by config primary_color */
  --blue2: #27458e;
  --brand: #ff6f00;   /* overridden by config accent_color */
  --brand2:#e66000;
  --line:  #dfe8f4;
  --good:  #138a36;
  --bad:   #b42318;
  --warn:  #9a5b00;
}

* { box-sizing: border-box; }
html, body { min-width: 0; margin: 0; }
body {
  font-family: Inter, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}
button, input, select { font: inherit; }

/* ── Top Bar ─────────────────────────────────────────────── */
.topbar {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  height: 54px;
  background: var(--blue);
  box-shadow: 0 2px 12px rgba(46,79,163,.22);
  position: sticky;
  top: 0;
  z-index: 200;
}

.brand-wrap {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 12px;
  overflow: hidden;
  flex: 1 1 auto;
  min-width: 0;
}

.brand-logo-link { display: flex; align-items: center; flex: 0 0 auto; }
.brand-logo { height: 40px; width: auto; display: block; }

.brand-divider {
  width: 1px;
  height: 26px;
  background: rgba(255,255,255,.3);
  flex: 0 0 auto;
}

.brand-copy { min-width: 0; }
.eyebrow { display: none; }
.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -.01em;
}
.topbar p { display: none; }
/* .price-card removed — price shown in stats panel */

/* ── App Layout ──────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: 410px 1fr;
  gap: 22px;
  padding: 22px;
  max-width: 1680px;
  margin: 0 auto;
}

/* ── Panels ──────────────────────────────────────────────── */
.panel {
  background: var(--panel);
  border: 2px solid rgba(255,111,0,.55);
  border-radius: 22px;
  padding: 20px;
  box-shadow: 0 8px 25px rgba(255,111,0,.08), 0 2px 8px rgba(0,0,0,.04);
}

h2 {
  margin: 0 0 10px;
  padding-bottom: 12px;
  border-bottom: 2px solid rgba(255,111,0,.18);
}

/* ── Drop Zone ───────────────────────────────────────────── */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 132px;
  border: 2px dashed rgba(255,111,0,.55);
  border-radius: 18px;
  background: #fffaf5;
  cursor: pointer;
  padding: 22px;
  transition: border-color .15s, background .15s;
}
.dropzone:hover { border-color: var(--brand); background: #fff4e8; }
.dropzone strong { font-size: 18px; }
.dropzone span { color: var(--muted); font-size: 13px; margin-top: 6px; }

/* ── Items ───────────────────────────────────────────────── */
.items { display: flex; flex-direction: column; gap: 12px; }

.item {
  border: 1px solid rgba(255,111,0,.22);
  border-radius: 16px;
  padding: 12px;
  background: #fff;
  transition: box-shadow .15s;
}
.item:hover { box-shadow: 0 4px 14px rgba(255,111,0,.1); }

.item-top { display: grid; grid-template-columns: 68px 1fr auto; gap: 10px; align-items: center; }

.thumb {
  width: 68px;
  height: 68px;
  border-radius: 12px;
  object-fit: contain;
  background:
    linear-gradient(45deg,#eee 25%,transparent 25%),
    linear-gradient(-45deg,#eee 25%,transparent 25%),
    linear-gradient(45deg,transparent 75%,#eee 75%),
    linear-gradient(-45deg,transparent 75%,#eee 75%);
  background-size: 16px 16px;
  background-position: 0 0,0 8px,8px -8px,-8px 0;
}

.file-name { font-weight: 800; font-size: 13px; word-break: break-word; }
.meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.empty { padding: 12px; color: var(--muted); }

.mini-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 7px; }
.mini-badges span {
  font-size: 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 7px;
  background: #fafafa;
  font-weight: 800;
}
.mini-badges .good { color: var(--good); }
.mini-badges .warn { color: var(--warn); }
.mini-badges .bad  { color: var(--bad); }

.item-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 12px; }
.field label { display: block; font-size: 11px; color: var(--muted); font-weight: 800; margin-bottom: 4px; }
.field input {
  width: 100%;
  border: 1px solid #ddd;
  border-radius: 10px;
  padding: 10px;
  transition: border-color .15s;
}
.field input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(255,111,0,.12); }

.item-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.item-actions button { padding: 8px 11px; font-size: 12px; }
.item-actions label { font-size: 12px; color: #333; font-weight: 800; }

/* ── Buttons ─────────────────────────────────────────────── */
button {
  border: 1px solid #d8cec2;
  background: #fff;
  border-radius: 999px;
  padding: 12px 18px;
  font-weight: 800;
  cursor: pointer;
  transition: background .12s, box-shadow .12s;
}
button:hover:not(:disabled) { background: #f5f5f5; }

button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--brand2); box-shadow: 0 4px 14px rgba(255,111,0,.35); }

button.checkout { background: var(--blue); color: #fff; border-color: var(--blue); }
button.checkout:hover:not(:disabled) { background: var(--blue2); box-shadow: 0 4px 14px rgba(46,79,163,.35); }

button:disabled { opacity: .45; cursor: not-allowed; }

.remove { color: var(--bad); border: none; background: #fff; }
.remove:hover:not(:disabled) { background: #ffebe9; }

/* ── Preview Panel ───────────────────────────────────────── */
.preview-head { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; }
.preview-head p { margin: 0; color: var(--muted); }

.stats { display: flex; gap: 10px; flex-wrap: wrap; }
.stats div { min-width: 76px; border: 1px solid rgba(255,111,0,.25); border-radius: 14px; padding: 10px 12px; background: #fff; }
.stats small { display: block; color: var(--muted); font-size: 11px; font-weight: 800; }
.stats strong { font-size: 20px; }

.stat-price { background: #ecfdf3 !important; border: 1px solid rgba(19,138,54,.35) !important; }
.stat-price small { color: #138a36 !important; }
.stat-price strong { color: #138a36 !important; font-weight: 900; }

/* ── Toolbar ─────────────────────────────────────────────── */
.toolbar, .preview-tools {
  display: flex;
  gap: 10px;
  margin: 16px 0;
}
.preview-tools { justify-content: flex-end; align-items: center; margin: 8px 0 12px; }
.preview-tools span { font-weight: 900; color: #333; min-width: 52px; text-align: center; }
.toolbar.bottom { justify-content: flex-end; margin-top: 18px; }

.gap-control { display: inline-flex; align-items: center; gap: 6px; font-weight: 800; margin-left: 8px; }
.gap-control select { border: 1px solid var(--line); border-radius: 999px; padding: 10px 12px; background: #fff; font-weight: 800; }

/* ── Canvas ──────────────────────────────────────────────── */
.canvas-wrap {
  position: relative;
  margin-top: 8px;
  border: 2px solid rgba(255,111,0,.35);
  border-radius: 18px;
  background: #f3f3f3;
  overflow: auto;
  max-height: 72vh;
  padding: 22px;
  text-align: left;
}

canvas {
  display: block;
  background: #fff;
  box-shadow: 0 8px 22px rgba(0,0,0,.18);
  margin: 0 auto;
  cursor: default;
}

canvas.dragging { cursor: grabbing !important; }
canvas.drag-hover { cursor: grab; }

/* ── Drag Tooltip ────────────────────────────────────────── */
#dragTooltip {
  position: fixed;
  z-index: 9000;
  background: rgba(23,32,51,.88);
  color: #fff;
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 700;
  pointer-events: none;
  display: none;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
#dragTooltip.visible { display: block; }

/* ── Warnings ────────────────────────────────────────────── */
.warnings { margin-top: 12px; }
.warning {
  border: 1px solid #fedf89;
  background: #fffaeb;
  color: #7a4b00;
  border-radius: 12px;
  padding: 10px 12px;
  margin-top: 8px;
  font-size: 13px;
}
.warning.warning-clickable { cursor: pointer; border-color: rgba(255,111,0,.45); background: #fff7ed; }
.warning.warning-clickable:hover { background: #fff1e5; }
.warning .warning-action { display: inline-block; margin-left: 6px; color: #ff6f00; font-weight: 900; text-decoration: underline; white-space: nowrap; }

/* ── Save Result ─────────────────────────────────────────── */
.save-result { font-size: 13px; color: var(--muted); word-break: break-word; margin-top: 8px; }
.save-result a { color: var(--brand); font-weight: 800; }

/* ── Advanced ────────────────────────────────────────────── */
.advanced-tools { margin-top: 12px; }
.advanced-toggle {
  width: 100%;
  text-align: left;
  background: #f8f9fc;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 800;
  color: var(--muted);
  font-size: 13px;
}
.advanced-toggle:hover:not(:disabled) { background: #eef3ff; color: var(--blue); }
.advanced-panel { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.advanced-panel button { flex: 1; border-radius: 12px; }

/* ── Busy Overlay ────────────────────────────────────────── */
.builder-busy-overlay {
  position: fixed;
  inset: 0;
  z-index: 20000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(23,32,51,.62);
  backdrop-filter: blur(3px);
}
.builder-busy-overlay[hidden] { display: none !important; }
.builder-busy-card {
  width: min(92vw, 460px);
  padding: 28px 26px;
  border-radius: 22px;
  background: #fff;
  border: 2px solid rgba(255,111,0,.65);
  box-shadow: 0 18px 50px rgba(0,0,0,.22);
  text-align: center;
}
.builder-busy-card strong { display: block; color: var(--ink); font-size: 18px; margin-top: 12px; }
.builder-busy-card span { display: block; color: var(--muted); font-size: 13px; line-height: 1.45; margin-top: 6px; }
.builder-spinner {
  width: 38px;
  height: 38px;
  margin: 0 auto;
  border-radius: 50%;
  border: 4px solid rgba(255,111,0,.18);
  border-top-color: var(--brand);
  animation: togoprint-spin .85s linear infinite;
}
body.builder-busy { overflow: hidden; }
body.builder-busy .dropzone, body.builder-busy button, body.builder-busy input, body.builder-busy select { pointer-events: none; }
body.builder-busy .toolbar.bottom { z-index: -1 !important; opacity: 0; }
body.builder-busy .preview-tools { z-index: -1 !important; opacity: 0; }
body.builder-busy .topbar { z-index: 0 !important; }
@keyframes togoprint-spin { to { transform: rotate(360deg); } }

/* ── Artwork Editor ──────────────────────────────────────── */
.artwork-editor-modal[hidden] { display: none !important; }
.artwork-editor-modal { position: fixed; inset: 0; z-index: 9999; display: flex; align-items: center; justify-content: center; padding: 18px; }
.artwork-editor-backdrop { position: absolute; inset: 0; background: rgba(23,32,51,.62); backdrop-filter: blur(2px); }
.artwork-editor-dialog {
  position: relative;
  width: min(720px, 100%);
  max-height: 92vh;
  overflow: auto;
  background: #fff;
  border: 2px solid rgba(255,111,0,.65);
  border-radius: 22px;
  box-shadow: 0 24px 80px rgba(0,0,0,.28);
  padding: 20px;
}
.artwork-editor-header { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; border-bottom: 2px solid rgba(255,111,0,.18); padding-bottom: 14px; margin-bottom: 16px; }
.artwork-editor-header h2 { margin: 0; color: var(--ink); border: 0; padding: 0; }
.artwork-editor-header p { margin: 6px 0 0; color: var(--muted); }
.artwork-editor-close { border: 0; background: #fff; color: var(--ink); font-size: 32px; line-height: 1; padding: 2px 8px; border-radius: 10px; }
.artwork-editor-close:hover { background: #fff4eb; color: var(--brand); }
.artwork-editor-body { display: grid; grid-template-columns: 280px 1fr; gap: 18px; align-items: center; }
.artwork-editor-preview-wrap {
  min-height: 240px;
  border: 1px solid rgba(255,111,0,.3);
  border-radius: 18px;
  background:
    linear-gradient(45deg,#f1f1f1 25%,transparent 25%),
    linear-gradient(-45deg,#f1f1f1 25%,transparent 25%),
    linear-gradient(45deg,transparent 75%,#f1f1f1 75%),
    linear-gradient(-45deg,transparent 75%,#f1f1f1 75%);
  background-size: 18px 18px;
  background-position: 0 0,0 9px,9px -9px,-9px 0;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.artwork-editor-preview-wrap img { max-width: 100%; max-height: 260px; object-fit: contain; display: block; }
.artwork-editor-info strong { display: block; font-size: 18px; margin-bottom: 8px; word-break: break-word; }
.artwork-editor-info span { display: block; color: var(--muted); font-size: 13px; line-height: 1.45; }
.artwork-editor-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.artwork-editor-actions button:disabled { opacity: .5; cursor: not-allowed; }
.artwork-editor-note { margin: 12px 0 0; color: var(--muted); font-size: 13px; }
.item-actions button[data-edit] { background: #fff4eb; border-color: rgba(255,111,0,.45); color: #a54500; }

/* ── Upload Progress ─────────────────────────────────────── */
#uploadProgressBox { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
.upload-progress-card {
  border: 1px solid rgba(255,111,0,.28) !important;
  border-radius: 16px !important;
  padding: 12px !important;
  background: #fffaf5 !important;
  box-shadow: 0 4px 14px rgba(255,111,0,.06);
}
.upload-progress-card .upload-row { display: grid; grid-template-columns: 68px 1fr auto; gap: 10px; align-items: center; }
.upload-progress-card .upload-icon { width: 68px; height: 68px; border-radius: 12px; background: #fff4eb; color: #ff6f00; display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 900; }
.upload-progress-card .upload-name { font-weight: 800; font-size: 13px; word-break: break-word; color: var(--ink); }
.upload-progress-card .status { color: var(--muted); font-size: 12px; margin-top: 2px; }
.upload-progress-track { height: 7px; background: #eee; border-radius: 99px; margin-top: 8px; overflow: hidden; }
.upload-progress-track .bar { height: 100%; width: 10%; background: #ff6f00; border-radius: 99px; transition: width .25s ease; }
.upload-progress-card.ready { background: #ecfdf3 !important; border-color: rgba(19,138,54,.35) !important; }
.upload-progress-card.ready .upload-icon { background: #d1fadf; color: #138a36; }
.upload-progress-card.ready .upload-progress-track .bar { background: #138a36; }

/* ── Order Summary Sidebar ───────────────────────────────── */
#orderSidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(400px, 100vw);
  background: #fff;
  box-shadow: -8px 0 40px rgba(0,0,0,.18);
  z-index: 5000;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .28s cubic-bezier(.4,0,.2,1);
  border-left: 2px solid rgba(255,111,0,.35);
}
#orderSidebar.open { transform: translateX(0); }
#orderSidebar .sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(23,32,51,.38);
  z-index: -1;
  opacity: 0;
  pointer-events: none;
  transition: opacity .28s;
}
#orderSidebar.open .sidebar-backdrop { opacity: 1; pointer-events: auto; }

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 2px solid rgba(255,111,0,.18);
  background: var(--blue);
  color: #fff;
  flex-shrink: 0;
}
.sidebar-header h3 { margin: 0; font-size: 18px; font-weight: 900; }
.sidebar-close {
  border: none;
  background: rgba(255,255,255,.18);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  padding: 4px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 900;
}
.sidebar-close:hover { background: rgba(255,255,255,.3); }

.sidebar-body { flex: 1; overflow-y: auto; padding: 18px 20px; }

.sidebar-section { margin-bottom: 20px; }
.sidebar-section-title {
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

/* Sheet summary box */
.sheet-summary-box {
  background: #f8faff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.sheet-summary-box .ss-item small { display: block; font-size: 11px; font-weight: 800; color: var(--muted); margin-bottom: 2px; }
.sheet-summary-box .ss-item strong { font-size: 17px; font-weight: 900; }
.sheet-summary-box .ss-price { grid-column: span 2; background: #ecfdf3; border: 1px solid rgba(19,138,54,.3); border-radius: 12px; padding: 10px 14px; display: flex; justify-content: space-between; align-items: center; }
.sheet-summary-box .ss-price small { font-size: 12px; font-weight: 800; color: var(--good); }
.sheet-summary-box .ss-price strong { font-size: 24px; font-weight: 900; color: var(--good); }

/* Utilization bar */
.util-bar-wrap { margin-top: 10px; }
.util-bar-label { display: flex; justify-content: space-between; font-size: 12px; font-weight: 800; color: var(--muted); margin-bottom: 5px; }
.util-bar { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.util-bar-fill { height: 100%; background: linear-gradient(90deg, #ff6f00, #ff9a3c); border-radius: 99px; transition: width .4s ease; }

/* Item rows in sidebar */
.sidebar-item-row {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.sidebar-item-row:last-child { border-bottom: none; }
.sidebar-item-row .si-thumb {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  object-fit: contain;
  background:
    linear-gradient(45deg,#eee 25%,transparent 25%),
    linear-gradient(-45deg,#eee 25%,transparent 25%),
    linear-gradient(45deg,transparent 75%,#eee 75%),
    linear-gradient(-45deg,transparent 75%,#eee 75%);
  background-size: 12px 12px;
  background-position: 0 0,0 6px,6px -6px,-6px 0;
}
.sidebar-item-row .si-name { font-weight: 800; font-size: 13px; word-break: break-word; }
.sidebar-item-row .si-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.sidebar-item-row .si-qty { font-size: 14px; font-weight: 900; color: var(--blue); background: #eef3ff; border-radius: 8px; padding: 5px 10px; }

/* Efficiency tip */
.efficiency-tip {
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  margin-top: 10px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.efficiency-tip.good { background: #f0fdf4; border: 1px solid rgba(19,138,54,.28); color: var(--good); }
.efficiency-tip.warn { background: #fffaeb; border: 1px solid rgba(154,91,0,.28); color: var(--warn); }
.efficiency-tip .tip-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 2px solid rgba(255,111,0,.18);
  flex-shrink: 0;
  background: #fffaf5;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sidebar-footer .price-breakdown { font-size: 13px; color: var(--muted); }
.sidebar-footer .price-breakdown strong { color: var(--ink); }

/* Review Order button in preview panel */
#reviewOrderBtn {
  background: #fffaf5;
  border: 2px solid rgba(255,111,0,.45);
  color: var(--brand);
  font-weight: 900;
  border-radius: 999px;
  padding: 12px 20px;
}
#reviewOrderBtn:hover { background: #fff4e8; }

/* ── Mobile Bottom Sheet ─────────────────────────────────── */
#mobileItemSheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4000;
  background: #fff;
  border-top: 3px solid rgba(255,111,0,.55);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -8px 32px rgba(0,0,0,.18);
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}
#mobileItemSheet.open { transform: translateY(0); }
#mobileItemSheet .sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(23,32,51,.38);
  z-index: -1;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
}
#mobileItemSheet.open .sheet-backdrop { opacity: 1; pointer-events: auto; }

.sheet-handle-wrap {
  text-align: center;
  padding: 10px 20px 0;
  flex-shrink: 0;
}
.sheet-handle {
  display: inline-block;
  width: 40px;
  height: 5px;
  background: #ddd;
  border-radius: 99px;
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px 14px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--line);
}
.sheet-header h3 { margin: 0; font-size: 16px; font-weight: 900; }
.sheet-header-right { display: flex; gap: 8px; align-items: center; }
.sheet-close {
  border: none;
  background: #f5f5f5;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  cursor: pointer;
}
.sheet-close:hover { background: #eee; }

.sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  -webkit-overflow-scrolling: touch;
}

/* Mobile items fab */
#mobileItemsFab {
  display: none;
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 13px 22px;
  font-size: 14px;
  font-weight: 900;
  box-shadow: 0 6px 22px rgba(46,79,163,.45);
  white-space: nowrap;
  cursor: pointer;
}
#mobileItemsFab:hover { background: var(--blue2); }
#mobileItemsFab .fab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--brand);
  color: #fff;
  border-radius: 999px;
  min-width: 20px;
  height: 20px;
  font-size: 11px;
  font-weight: 900;
  margin-left: 8px;
  padding: 0 5px;
}

/* ── Footer ──────────────────────────────────────────────── */
.footer {
  text-align: center;
  color: var(--muted);
  padding: 0 20px 30px;
  font-size: 13px;
}
.footer strong { color: var(--ink); }

/* ── Drag highlight on canvas placements ─────────────────── */
.canvas-wrap.drag-active { cursor: grabbing; user-select: none; }

/* ── Placement selected ring ─────────────────────────────── */
/* drawn in JS on canvas, no CSS needed */

/* ── Desktop sticky left panel ───────────────────────────── */
@media (min-width: 901px) {
  .left-panel {
    max-height: calc(100vh - 120px);
    overflow: hidden;
    position: sticky;
    top: 90px;
    display: flex;
    flex-direction: column;
  }
  .left-panel .items {
    max-height: calc(100vh - 480px);
    overflow-y: auto;
    padding-right: 6px;
    margin-right: -6px;
  }
  .preview-panel { align-self: start; }
  #mobileItemsFab { display: none !important; }
  #mobileItemSheet { display: none !important; }
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 900px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .app { grid-template-columns: 1fr; padding: 14px; gap: 14px; }
  .preview-head { flex-direction: column; }
  .stats { width: 100%; overflow: auto; }
  .topbar h1 { font-size: 24px; }
  .canvas-wrap { padding: 12px; }
}

@media (max-width: 760px) {
  body { background: var(--bg); }
  .topbar { padding: 10px 14px; flex-wrap: nowrap; }
  .brand-logo { height: 26px; }
  .brand-divider { height: 18px; }
  .topbar h1 { font-size: 12px; }
  .app { display: flex; flex-direction: column; padding: 10px; gap: 12px; }
  .panel { border-radius: 16px; padding: 14px; }
  h2 { font-size: 18px; }
  .dropzone { min-height: 100px; padding: 16px; }
  .toolbar, .preview-tools { flex-wrap: wrap; gap: 8px; }
  button { padding: 11px 14px; }
  .item-top { grid-template-columns: 54px 1fr auto; gap: 8px; }
  .thumb { width: 54px; height: 54px; border-radius: 10px; }
  .file-name { font-size: 12px; }
  .meta { font-size: 11px; }
  .mini-badges span { font-size: 10.5px; padding: 3px 6px; }
  .item-grid { grid-template-columns: 1fr 1fr; }
  .item-grid .field:nth-child(3) { grid-column: span 2; }
  .field input { min-height: 42px; font-size: 16px; }
  .item-actions { gap: 6px; flex-wrap: wrap; }
  .item-actions button { flex: 1 1 100%; width: 100%; min-height: 44px; }
  .item-actions label { width: 100%; margin-top: 4px; }
  .preview-head { gap: 12px; }
  .stats { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; width: 100%; }
  .stats div { min-width: 0; padding: 9px 10px; }
  .stats strong { font-size: 18px; }
  .preview-tools { justify-content: flex-start; position: sticky; top: 0; z-index: 5; background: var(--panel); padding: 6px 0 8px; }
  .preview-tools button { flex: 0 0 auto; min-width: 44px; }
  .preview-tools span { min-width: 46px; }
  .gap-control { margin-left: 0; width: 100%; justify-content: space-between; border: 1px solid var(--line); border-radius: 999px; padding: 4px 6px 4px 12px; background: #fff; }
  .gap-control select { min-height: 40px; }
  .canvas-wrap { padding: 10px; max-height: 58vh; border-radius: 14px; -webkit-overflow-scrolling: touch; }
  .toolbar.bottom {
    position: sticky; bottom: 0; z-index: 10;
    background: linear-gradient(to top, var(--panel) 80%, transparent);
    padding: 12px 0 74px;
    margin-bottom: -4px;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
  }
  .toolbar.bottom button { border-radius: 12px; padding: 11px 6px; font-size: 12px; text-align: center; width: 100%; }
  .save-result { font-size: 12px; }
  .footer { font-size: 12px; padding: 8px 16px 24px; }
  #mobileItemsFab { display: flex; align-items: center; }
  #orderSidebar { width: 100vw; }
}

@media (max-width: 420px) {
  .topbar h1 { font-size: 14px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .toolbar.bottom { gap: 5px; }
  .toolbar.bottom button { font-size: 11px; padding: 10px 4px; }
  .item-grid { grid-template-columns: 1fr; }
  .item-grid .field:nth-child(3) { grid-column: auto; }
}

/* Drag tooltip */
#dragTooltip {
  position: fixed;
  z-index: 9000;
  background: rgba(23,32,51,.88);
  color: #fff;
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 700;
  pointer-events: none;
  display: none;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
#dragTooltip.visible { display: block; }

/* Canvas rotate hint bar */
.canvas-rotate-hint {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
  font-weight: 600;
}
.canvas-rotate-hint kbd {
  display: inline-block;
  background: #f0f2f5;
  border: 1px solid #ccc;
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 11px;
  font-family: monospace;
  color: var(--ink);
}
