/* AM – Drinkware Designer :: editor (mobile-first, fully scoped to .amdw-overlay) */
html.amdw-lock, html.amdw-lock body { overflow: hidden !important; overscroll-behavior: none; }

.amdw-overlay {
  --amdw-bg: #eef0f4; --amdw-surface: #fff; --amdw-ink: #1d2230; --amdw-muted: #6b7385;
  --amdw-line: #dfe3ea; --amdw-accent: #1e6bff; --amdw-danger: #d6334a; --amdw-radius: 10px;
  position: fixed; inset: 0; z-index: 100050; display: flex; flex-direction: column;
  height: 100vh; height: 100dvh; background: var(--amdw-bg); color: var(--amdw-ink);
  font: 14px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%; overscroll-behavior: contain; touch-action: manipulation;
}
.amdw-overlay *, .amdw-overlay *::before, .amdw-overlay *::after { box-sizing: border-box; }
.amdw-overlay .amdw-hidden { display: none !important; }

/* buttons */
.amdw-overlay .amdw-btn {
  appearance: none; -webkit-appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; min-width: 40px; padding: 0 12px; margin: 0; border: 1px solid transparent; border-radius: 8px;
  background: transparent; color: inherit; font: inherit; font-weight: 600; cursor: pointer; line-height: 1; box-shadow: none; text-decoration: none;
}
@media (hover: hover) { .amdw-overlay .amdw-btn:hover { background: rgba(30, 40, 60, .06); } }
.amdw-overlay .amdw-btn:focus-visible { outline: 2px solid var(--amdw-accent); outline-offset: 1px; }
.amdw-overlay .amdw-btn:disabled { opacity: .35; cursor: default; background: transparent; }
.amdw-overlay .amdw-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.amdw-overlay .amdw-icon-only { padding: 0; width: 40px; }
.amdw-overlay .amdw-icon-only span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.amdw-overlay .amdw-primary { background: var(--amdw-accent); color: #fff; padding: 0 16px; }
@media (hover: hover) { .amdw-overlay .amdw-primary:hover { background: #1558d6; } }
.amdw-overlay .amdw-danger { color: var(--amdw-danger); }
.amdw-overlay .amdw-btn-3d { border-color: var(--amdw-line); background: var(--amdw-surface); }

/* top bar */
.amdw-top { flex: none; display: flex; align-items: center; gap: 4px; min-height: 54px; padding: 6px 8px; padding-top: max(6px, env(safe-area-inset-top));
  background: var(--amdw-surface); border-bottom: 1px solid var(--amdw-line); }
.amdw-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.amdw-title strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.amdw-title small { color: var(--amdw-muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.amdw-top-actions { display: flex; align-items: center; gap: 4px; }
.amdw-status { font-size: 12px; color: var(--amdw-muted); white-space: nowrap; max-width: 110px; overflow: hidden; text-overflow: ellipsis; }

/* body – mobile: main / panel / tools stacked */
.amdw-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.amdw-main { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.amdw-stage { position: absolute; inset: 0; }
.amdw-canvas { display: block; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; outline: none; }
.amdw-empty { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); pointer-events: none; color: var(--amdw-muted); font-size: 13px; text-align: center; padding: 0 16px; }
.amdw-warn { position: absolute; left: 8px; right: 8px; bottom: 8px; display: flex; flex-wrap: wrap; gap: 6px; pointer-events: none; justify-content: center; }
.amdw-chip { background: #fff4dc; color: #7a4b00; border: 1px solid #f1d49a; border-radius: 999px; padding: 3px 10px; font-size: 12px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.amdw-tools { flex: none; display: flex; justify-content: center; gap: 8px; padding: 6px 8px; padding-bottom: max(6px, env(safe-area-inset-bottom));
  background: var(--amdw-surface); border-top: 1px solid var(--amdw-line); order: 3; }
.amdw-tools .amdw-btn { flex-direction: column; gap: 3px; min-width: 72px; min-height: 52px; font-size: 12px; font-weight: 500; }
.amdw-panel { flex: none; order: 2; background: var(--amdw-surface); border-top: 1px solid var(--amdw-line); max-height: 44vh; overflow-y: auto; -webkit-overflow-scrolling: touch; display: none; }
.amdw-has-selection .amdw-panel { display: block; }
.amdw-main { order: 1; }

.amdw-row { padding: 8px 12px; }
.amdw-row + .amdw-row { padding-top: 0; }
.amdw-row-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.amdw-row-actions .amdw-btn { flex: 1 1 auto; font-size: 12px; font-weight: 500; border-color: var(--amdw-line); }
.amdw-row-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.amdw-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.amdw-field > span { font-size: 11px; color: var(--amdw-muted); text-transform: uppercase; letter-spacing: .03em; }
.amdw-field-font { grid-column: 1 / -1; }
.amdw-overlay .amdw-textarea, .amdw-overlay .amdw-select, .amdw-overlay .amdw-num {
  width: 100%; max-width: none; margin: 0; border: 1px solid var(--amdw-line); border-radius: 8px; background: #fff; color: var(--amdw-ink);
  font: 16px/1.3 inherit; font-family: inherit; padding: 8px 10px; min-height: 40px; box-shadow: none; /* 16px: no iOS zoom */
}
.amdw-overlay .amdw-textarea { resize: vertical; min-height: 64px; }
.amdw-overlay .amdw-color { width: 100%; height: 40px; padding: 2px; border: 1px solid var(--amdw-line); border-radius: 8px; background: #fff; }
.amdw-seg { display: flex; border: 1px solid var(--amdw-line); border-radius: 8px; overflow: hidden; }
.amdw-seg .amdw-btn { flex: 1; border-radius: 0; width: auto; }
.amdw-seg .amdw-btn.is-on { background: #e7efff; color: var(--amdw-accent); }
.amdw-dims { padding: 0 12px 10px; font-size: 12px; color: var(--amdw-muted); font-variant-numeric: tabular-nums; }

/* 3D */
.amdw-3d { position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 40%, #ffffff 0%, #e9ecf1 70%); touch-action: none; }
.amdw-3d[hidden] { display: none; }
.amdw-3d-canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.amdw-3d-msg { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); color: var(--amdw-muted); text-align: center; padding: 0 24px; max-width: 420px; }
.amdw-3d-hint { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); font-size: 12px; color: var(--amdw-muted); background: rgba(255,255,255,.8); padding: 4px 10px; border-radius: 999px; pointer-events: none; }
.amdw-mode-3d .amdw-stage, .amdw-mode-3d .amdw-empty, .amdw-mode-3d .amdw-warn, .amdw-mode-3d .amdw-tools, .amdw-mode-3d .amdw-panel { display: none !important; }
.amdw-overlay.amdw-mode-3d .amdw-btn-3d, .amdw-overlay.amdw-mode-3d .amdw-btn-3d:hover { background: var(--amdw-ink); color: #fff; border-color: var(--amdw-ink); }

/* busy + toast */
.amdw-busy { position: absolute; inset: 0; background: rgba(238,240,244,.6); display: none; align-items: center; justify-content: center; flex-direction: column; gap: 10px; z-index: 5; }
.amdw-busy.is-on { display: flex; }
.amdw-busy::after { content: attr(data-label); font-size: 13px; color: var(--amdw-muted); }
.amdw-spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #cfd6e3; border-top-color: var(--amdw-accent); animation: amdw-spin .8s linear infinite; }
@keyframes amdw-spin { to { transform: rotate(360deg); } }
.amdw-toast { position: absolute; left: 50%; top: 64px; transform: translateX(-50%); background: #2a1216; color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 13px; z-index: 6; max-width: calc(100% - 32px); }

/* touch / narrow: compact property sheet */
@media (max-width: 782px), (pointer: coarse) {
  .amdw-row { padding: 6px 10px; }
  .amdw-row-grid { grid-template-columns: 1fr 1fr 1.2fr; gap: 6px 8px; }
  .amdw-field > span { font-size: 10px; }
  .amdw-overlay .amdw-textarea { min-height: 48px; }
  .amdw-row-actions .amdw-btn { min-height: 38px; }
  .amdw-row-actions .amdw-btn span { display: none; }
  .amdw-dims { padding-bottom: 6px; }
  .amdw-chip { font-size: 11px; }
}

/* small phones: compact top bar */
@media (max-width: 420px) {
  .amdw-title small { display: none; }
  .amdw-status { display: none; }
  .amdw-overlay .amdw-btn-3d { padding: 0 10px; }
  .amdw-overlay .amdw-primary { padding: 0 12px; }
}

/* desktop: tools | main | panel */
@media (min-width: 783px) and (pointer: fine) {
  .amdw-body { flex-direction: row; }
  .amdw-tools { order: 0; flex-direction: column; justify-content: flex-start; padding: 12px 8px; border-top: 0; border-right: 1px solid var(--amdw-line); }
  .amdw-main { order: 1; }
  .amdw-panel { order: 2; width: 300px; max-height: none; border-top: 0; border-left: 1px solid var(--amdw-line); display: block; padding-top: 6px; }
  .amdw-panel:empty::before { content: ""; }
  .amdw-status { max-width: 220px; }
}

/* GĐ02-A: Shared Asset Picker (AM – Asset Library) must stack above the fullscreen editor */
html.amdw-lock .amal-overlay { z-index: 100100 !important; }

/* V1.1-A: Starter Template mode + Background tool */
.amdw-overlay .amdw-btn-save { border-color: var(--amdw-line); background: var(--amdw-surface); }
.amdw-overlay.amdw-is-template .amdw-title strong::before { content: "★ "; color: var(--amdw-accent); }
.amdw-overlay .amdw-bg-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.amdw-overlay .amdw-bg-btns { display: flex; gap: 6px; }
.amdw-overlay .amdw-bg-btns .amdw-btn { flex: 1 1 0; border-color: var(--amdw-line); font-size: 12px; font-weight: 500; min-width: 0; }
.amdw-overlay .amdw-bg-src { grid-template-columns: 1fr 2fr; }
.amdw-overlay .amdw-bg-fit { grid-template-columns: 1fr; }
.amdw-overlay .amdw-range { width: 100%; height: 32px; margin: 0; accent-color: var(--amdw-accent); touch-action: pan-x; }
@media (max-width: 782px), (pointer: coarse) {
  .amdw-overlay .amdw-btn-save span { display: none; }
  .amdw-overlay .amdw-btn-save { padding: 0; width: 40px; }
  .amdw-overlay .amdw-bg-src { grid-template-columns: 1fr 2fr; }
  .amdw-overlay .amdw-bg-btns .amdw-btn span { display: inline; }
}
