:root {
  --brand: #00a0e9;
  --brand-dark: #0284c7;
  --brand-soft: #e0f2fe;
  --zalo: #0068ff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --panel: #ffffff;
  --page: #f1f5f9;
  --danger: #dc2626;
  --success: #059669;
  --stage-w: 500;
  --stage-h: 500;
  font-family: Inter, "Be Vietnam Pro", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--page);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-width: 320px;
  min-height: 100%;
  background: var(--page);
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
img { max-width: 100%; display: block; }
.hidden { display: none !important; }

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 68px;
  padding: max(8px, env(safe-area-inset-top)) 14px 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 80;
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(15,23,42,.05);
}

.brand {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  text-decoration: none;
  font-size: 15px;
  font-weight: 800;
  text-transform: uppercase;
}

.brand img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 10px;
}

.brand-text {
  display: block;
  line-height: 1.24;
  padding-top: 2px;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}

.brand strong { color: var(--brand); }

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn,
.soft-danger-btn,
.zalo-link,
.workspace-actions button {
  min-height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
}

.icon-btn {
  width: 42px;
  padding: 0;
  font-size: 22px;
}

.icon-btn:disabled { opacity: .35; cursor: not-allowed; }

.soft-danger-btn { padding: 0 13px; color: #b91c1c; background: #fff1f2; border-color: #fecdd3; }
.zalo-link { padding: 10px 16px; color: #fff; background: var(--zalo); border-color: var(--zalo); }

.main-layout {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(250px, 310px) minmax(440px, 1fr) minmax(260px, 320px);
  gap: 14px;
  align-items: start;
  flex: 1;
}

.config-panel,
.inspector-panel {
  display: grid;
  gap: 12px;
  align-content: start;
}

.panel-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 10px 30px rgba(15,23,42,.06);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
}

.compact-heading { margin-bottom: 12px; }

.step-badge {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #fff;
  background: var(--brand);
  font-weight: 900;
}

.panel-heading h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
}

.panel-heading p,
.panel-note,
.inspector-empty p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.segmented,
.view-switch {
  display: grid;
  gap: 7px;
  background: #f8fafc;
  border: 1px solid var(--line);
  padding: 5px;
  border-radius: 14px;
}

.segmented { grid-template-columns: 1fr 1fr; }
.view-switch { grid-template-columns: 1fr 1fr; margin-top: 9px; }

.segment,
.view-btn {
  min-height: 42px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #475569;
  font-weight: 800;
  font-size: 13px;
}

.segment.active,
.view-btn.active {
  color: #fff;
  background: var(--brand);
  box-shadow: 0 6px 16px rgba(0,160,233,.22);
}

.scheme-grid,
.quick-position-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.scheme-grid button,
.quick-position-grid button {
  min-height: 40px;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  color: #334155;
  font-size: 12px;
  font-weight: 800;
}

.scheme-grid button:hover,
.quick-position-grid button:hover {
  border-color: var(--brand);
  color: var(--brand-dark);
  background: var(--brand-soft);
}

.color-controls {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.color-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fafc;
}

.color-row label {
  font-size: 13px;
  font-weight: 800;
  color: #334155;
}

.color-row small {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  margin-top: 2px;
}

.color-row input[type="color"] {
  width: 44px;
  height: 34px;
  border: 0;
  background: transparent;
  padding: 0;
}

.switch-row,
.remember-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #334155;
  font-size: 13px;
  font-weight: 700;
}

.switch-row { margin-bottom: 10px; }
.switch-row input,
.remember-row input { accent-color: var(--brand); }

.workspace-panel {
  min-width: 0;
  display: grid;
  gap: 10px;
}

.workspace-head {
  min-height: 58px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
}

.workspace-head > div:first-child {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.workspace-head strong {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.workspace-head span {
  color: var(--muted);
  font-size: 11px;
}

.workspace-actions {
  display: flex;
  gap: 7px;
}

.workspace-actions button {
  padding: 0 10px;
  min-height: 36px;
  font-size: 11px;
}

.stage-viewport {
  min-height: 560px;
  padding: 16px;
  display: grid;
  place-items: center;
  overflow: auto;
  overscroll-behavior: contain;
  background:
    linear-gradient(45deg, #e2e8f0 25%, transparent 25%),
    linear-gradient(-45deg, #e2e8f0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e2e8f0 75%),
    linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0;
  border: 1px solid var(--line);
  border-radius: 20px;
}

.design-stage {
  position: relative;
  width: min(500px, calc(100vw - 690px));
  min-width: 430px;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 20px 50px rgba(15,23,42,.2);
  touch-action: none;
  user-select: none;
  isolation: isolate;
}

.shirt-template,
.shirt-template svg,
.layers-root,
.print-zones {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.shirt-template svg { display: block; }

.print-zones {
  z-index: 4;
  pointer-events: none;
}

.print-zone {
  position: absolute;
  display: grid;
  place-items: center;
  border: 1.5px dashed rgba(0,160,233,.85);
  border-radius: 10px;
  color: #0369a1;
  background: rgba(224,242,254,.16);
  font-size: 10px;
  font-weight: 900;
  text-align: center;
  pointer-events: auto;
  cursor: pointer;
}

.print-zone:hover {
  background: rgba(0,160,233,.14);
  border-style: solid;
}

.layers-root { z-index: 10; pointer-events: none; }

.design-layer {
  position: absolute;
  transform-origin: center;
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.design-layer.dragging { cursor: grabbing; }

.design-layer .layer-content {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.design-layer img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.design-layer.text-layer .layer-content {
  white-space: pre-wrap;
  overflow: visible;
  line-height: 1.1;
  text-align: center;
  font-weight: 800;
  padding: 3px;
}

.design-layer.selected::after {
  content: "";
  position: absolute;
  inset: -5px;
  border: 2px dashed var(--brand);
  border-radius: 6px;
  pointer-events: none;
}

.layer-handle {
  position: absolute;
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #fff;
  font-size: 14px;
  font-weight: 900;
  border: 2px solid #fff;
  box-shadow: 0 4px 12px rgba(15,23,42,.28);
  pointer-events: auto;
  touch-action: none;
}

.resize-handle {
  right: -17px;
  bottom: -17px;
  background: var(--brand);
  cursor: nwse-resize;
}

.rotate-handle {
  right: -17px;
  top: -17px;
  background: #7c3aed;
  cursor: grab;
}

.delete-handle {
  left: -17px;
  top: -17px;
  background: var(--danger);
}

.locked-mark {
  position: absolute;
  left: 50%;
  top: -20px;
  transform: translateX(-50%);
  padding: 2px 6px;
  border-radius: 999px;
  color: #fff;
  background: #0f172a;
  font-size: 9px;
  font-weight: 900;
}

.stage-watermark {
  position: absolute;
  left: 50%;
  bottom: 11px;
  transform: translateX(-50%);
  z-index: 30;
  color: rgba(15,23,42,.25);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .12em;
  pointer-events: none;
}

.workspace-tip {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 14px;
  color: #475569;
  font-size: 11px;
  font-weight: 700;
}

.add-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.primary-btn,
.outline-btn,
.bottom-btn {
  min-height: 44px;
  border-radius: 12px;
  padding: 10px 13px;
  font-weight: 900;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.primary-btn {
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
}

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

.outline-btn {
  border: 1px solid var(--brand);
  background: #fff;
  color: var(--brand-dark);
}

.layer-list {
  display: grid;
  gap: 7px;
  margin-top: 12px;
}

.layer-list-empty {
  padding: 18px 10px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 12px;
  font-size: 12px;
}

.layer-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #f8fafc;
}

.layer-item.active {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.layer-select {
  min-width: 0;
  border: 0;
  background: transparent;
  text-align: left;
  color: #334155;
  font-size: 12px;
  font-weight: 800;
}

.layer-select span {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.layer-mini-actions {
  display: flex;
  gap: 4px;
}

.layer-mini-actions button {
  width: 29px;
  height: 29px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #475569;
  font-weight: 900;
}

.object-inspector {
  min-height: 160px;
}

.inspector-empty {
  padding: 12px 5px;
  text-align: center;
  color: var(--muted);
}

.inspector-form {
  display: grid;
  gap: 10px;
}

.inspector-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}

.inspector-title strong { font-size: 15px; }
.inspector-title span { color: var(--muted); font-size: 10px; }

.field {
  display: grid;
  gap: 5px;
}

.field label {
  color: #475569;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.field input[type="text"],
.field input[type="number"],
.field select,
.field textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

.field textarea { min-height: 64px; resize: vertical; }

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(0,160,233,.12);
}

.range-row {
  display: grid;
  grid-template-columns: 1fr 54px;
  gap: 8px;
  align-items: center;
}

.range-row output {
  text-align: right;
  color: #334155;
  font-size: 11px;
  font-weight: 800;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.check-card {
  min-height: 40px;
  padding: 8px 9px;
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: #334155;
  font-size: 11px;
  font-weight: 800;
}

.check-card input { accent-color: var(--brand); }

.inspector-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
}

.inspector-actions button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: #334155;
  font-size: 11px;
  font-weight: 800;
}

.inspector-actions .danger-action {
  color: #b91c1c;
  border-color: #fecaca;
  background: #fff1f2;
}

.bottom-bar {
  position: sticky;
  bottom: 0;
  z-index: 70;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 14px max(10px, env(safe-area-inset-bottom));
  background: rgba(255,255,255,.97);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 24px rgba(15,23,42,.08);
}

.bottom-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: #334155;
}

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

.bottom-btn.zalo {
  color: #fff;
  border-color: var(--zalo);
  background: var(--zalo);
}

.app-dialog {
  width: min(92vw, 470px);
  border: 0;
  border-radius: 22px;
  padding: 0;
  box-shadow: 0 28px 80px rgba(15,23,42,.32);
}

.app-dialog::backdrop { background: rgba(15,23,42,.58); }

.dialog-card {
  padding: 24px;
  display: grid;
  gap: 14px;
  text-align: center;
}

.dialog-card > img {
  margin: 0 auto;
  width: 56px;
  height: 56px;
  object-fit: contain;
}

.dialog-card h2 { margin: 0; font-size: 22px; }
.dialog-card p { margin: 0; color: var(--muted); line-height: 1.55; font-size: 13px; }

.guide-list {
  padding: 0;
  margin: 0;
  display: grid;
  gap: 9px;
  list-style: none;
  text-align: left;
}

.guide-list li {
  display: grid;
  grid-template-columns: 30px 1fr;
  align-items: center;
  gap: 9px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.guide-list b {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #fff;
  background: var(--brand);
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.busy-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: #fff;
  background: rgba(15,23,42,.76);
}

.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid rgba(255,255,255,.25);
  border-top-color: #fff;
  border-radius: 999px;
  animation: spin .8s linear infinite;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  z-index: 220;
  max-width: calc(100vw - 30px);
  transform: translate(-50%, 15px);
  opacity: 0;
  pointer-events: none;
  padding: 11px 16px;
  border-radius: 999px;
  color: #fff;
  background: #0f172a;
  box-shadow: 0 14px 40px rgba(15,23,42,.32);
  font-size: 12px;
  font-weight: 800;
  transition: .2s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1180px) {
  .main-layout {
    grid-template-columns: 270px minmax(420px, 1fr);
  }

  .inspector-panel {
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1fr;
  }

  .design-stage {
    width: min(500px, calc(100vw - 340px));
  }
}

@media (max-width: 820px) {
  .topbar { min-height: 62px; }
  .soft-danger-btn { display: none; }

  .main-layout {
    padding: 9px;
    grid-template-columns: 1fr;
  }

  .workspace-panel { order: -1; }
  .config-panel,
  .inspector-panel {
    grid-template-columns: 1fr;
  }

  .stage-viewport {
    min-height: 0;
    padding: 8px;
  }

  .design-stage {
    width: min(500px, calc(100vw - 34px));
    min-width: 0;
  }

  .workspace-actions button:last-child { display: none; }
  .bottom-bar { grid-template-columns: repeat(4, minmax(0, 1fr)); padding-inline: 8px; }
  .bottom-btn { min-height: 42px; padding: 8px 5px; font-size: 11px; }
}

@media (max-width: 520px) {
  .brand span { max-width: 150px; font-size: 12px; }
  .top-actions { gap: 5px; }
  .icon-btn { width: 38px; height: 38px; min-height: 38px; }
  .zalo-link { padding: 9px 11px; font-size: 12px; }

  .workspace-head { align-items: flex-start; }
  .workspace-actions { display: none; }

  .panel-card { padding: 14px; border-radius: 15px; }
  .scheme-grid,
  .quick-position-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .print-zone { font-size: 8px; }
  .workspace-tip { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}

@media print {
  .no-export,
  .topbar,
  .config-panel,
  .inspector-panel,
  .bottom-bar,
  .workspace-head,
  .workspace-tip {
    display: none !important;
  }

  body { background: #fff; }
  .main-layout { display: block; padding: 0; }
  .workspace-panel { display: block; }
  .stage-viewport { padding: 0; border: 0; background: #fff; overflow: visible; }
  .design-stage {
    width: 500px;
    height: 600px;
    margin: 0 auto;
    box-shadow: none;
  }
}


.model-catalog {
  display: grid;
  gap: 10px;
}

.model-accordion {
  border: 1px solid var(--line);
  border-radius: 15px;
  background: #fff;
  overflow: hidden;
  transition: border-color .18s, box-shadow .18s;
}

.model-accordion.selected-model {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(0,160,233,.08);
}

.model-accordion summary {
  min-height: 78px;
  padding: 9px 11px;
  display: grid;
  grid-template-columns: 68px 1fr auto;
  align-items: center;
  gap: 11px;
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.model-accordion summary::-webkit-details-marker {
  display: none;
}

.model-accordion summary > img {
  width: 68px;
  height: 58px;
  object-fit: cover;
  object-position: center;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #f8fafc;
}

.model-accordion summary strong {
  display: block;
  color: #0f172a;
  font-size: 14px;
}

.model-accordion summary small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.accordion-arrow {
  color: var(--brand);
  font-size: 22px;
  font-weight: 900;
  transition: transform .18s;
}

.model-accordion[open] .accordion-arrow {
  transform: rotate(180deg);
}

.color-album {
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  border-top: 1px solid var(--line);
  background: #f8fafc;
}

.album-color-card {
  min-width: 0;
  padding: 5px;
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: #334155;
}

.album-color-card:hover,
.album-color-card.active {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(0,160,233,.10);
}

.album-color-card.active {
  background: #effaff;
}

.album-color-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 7px;
  background: #fff;
}

.album-color-card span {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.album-color-card i {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(15,23,42,.18);
}

.view-select-block {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.view-select-title {
  margin-bottom: 8px;
}

.view-select-title strong {
  display: block;
  font-size: 13px;
  color: #0f172a;
}

.view-select-title span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.shirt-template img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.inspector-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (max-width: 520px) {
  .color-album {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .model-accordion summary {
    grid-template-columns: 60px 1fr auto;
  }

  .model-accordion summary > img {
    width: 60px;
    height: 52px;
  }
}


.album-color-card span {
  justify-content: center;
  min-height: 28px;
  text-align: center;
  white-space: normal;
  line-height: 1.25;
}

.album-color-card.image-missing {
  opacity: .55;
  border-color: #ef4444;
}

.album-color-card.image-missing::after {
  content: "Sai tên ảnh";
  color: #b91c1c;
  font-size: 9px;
  font-weight: 900;
}


.sheet-close,
.mobile-stage-toolbar,
.mobile-panel-backdrop {
  display: none;
}

.inline-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.crop-dialog::backdrop {
  background: rgba(15, 23, 42, .55);
}

.crop-card {
  width: min(92vw, 540px);
}

.crop-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.crop-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.crop-close-btn {
  width: 40px;
  min-height: 40px;
  flex: 0 0 40px;
}

.crop-viewport {
  position: relative;
  min-height: 340px;
  margin-top: 14px;
  border-radius: 18px;
  overflow: hidden;
  background: linear-gradient(45deg, #e2e8f0 25%, transparent 25%),
    linear-gradient(-45deg, #e2e8f0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e2e8f0 75%),
    linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
}

.crop-viewport img {
  position: absolute;
  left: 50%;
  top: 50%;
  max-width: none;
  max-height: none;
  cursor: grab;
  touch-action: none;
  transform-origin: center center;
}

.crop-viewport img:active {
  cursor: grabbing;
}

.crop-frame {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(100% - 34px);
  height: calc(100% - 34px);
  max-width: 320px;
  max-height: 320px;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(255,255,255,.96);
  box-shadow: 0 0 0 999px rgba(15,23,42,.44);
  border-radius: 18px;
  pointer-events: none;
}

.crop-controls {
  margin-top: 14px;
  display: grid;
  gap: 12px;
}

.crop-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mobile-tool-btn {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: #334155;
  font-size: 12px;
  font-weight: 900;
}

.mobile-tool-btn.mobile-primary {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

@media (max-width: 820px) {
  body.panel-open { overflow: hidden; }

  .topbar {
    align-items: center;
  }

  .brand-text {
    font-size: 13px;
    line-height: 1.25;
    padding-top: 1px;
  }

  .brand strong { display: inline; }

  .config-panel,
  .inspector-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 86px;
    z-index: 120;
    padding: 0 10px max(10px, env(safe-area-inset-bottom));
    transform: translateY(calc(100% + 20px));
    opacity: 0;
    pointer-events: none;
    transition: transform .22s ease, opacity .22s ease;
  }

  .config-panel.mobile-open,
  .inspector-panel.mobile-open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  .config-panel .panel-card,
  .inspector-panel .panel-card {
    max-height: min(66dvh, 560px);
    overflow: auto;
    border-radius: 20px;
    box-shadow: 0 -12px 30px rgba(15,23,42,.18);
  }

  .sheet-close {
    display: inline-flex;
    width: 34px;
    height: 34px;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: #334155;
    font-weight: 900;
  }

  .mobile-stage-toolbar {
    position: sticky;
    bottom: calc(70px + env(safe-area-inset-bottom));
    z-index: 65;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
    margin-top: 2px;
    padding: 0 2px;
  }

  .mobile-panel-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 110;
    background: rgba(15,23,42,.45);
  }

  .workspace-panel {
    gap: 8px;
  }
}

@media (max-width: 520px) {
  .brand-text {
    max-width: 165px;
    font-size: 12px;
  }

  .topbar {
    gap: 8px;
  }

  .crop-viewport {
    min-height: 280px;
  }

  .crop-frame {
    max-width: 250px;
    max-height: 250px;
  }
}


.background-loading {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: #fff;
  font-size: 13px;
  font-weight: 800;
}

.workspace-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

@media (max-width: 520px) {
  .mobile-tool-btn {
    padding: 7px 3px;
    font-size: 10px;
  }
}


/* =========================================================
   V9 — Cửa sổ cắt ảnh luôn vừa màn hình
   ========================================================= */

body.crop-open {
  overflow: hidden;
}

.crop-dialog {
  position: fixed;
  inset: 0;
  width: min(96vw, 560px);
  max-width: none;
  max-height: calc(100dvh - 16px);
  margin: auto;
  padding: 0;
  overflow: hidden;
  border-radius: 22px;
}

.crop-dialog[open] {
  display: block;
}

.crop-dialog .crop-card {
  width: 100%;
  height: min(760px, calc(100dvh - 16px));
  max-height: calc(100dvh - 16px);
  min-height: 0;
  padding: 16px;
  display: grid;
  grid-template-rows: auto minmax(160px, 1fr) auto;
  gap: 10px;
  overflow: hidden;
  text-align: left;
}

.crop-dialog .crop-header {
  min-height: 0;
  margin: 0;
}

.crop-dialog .crop-header h2 {
  font-size: 19px;
  line-height: 1.25;
}

.crop-dialog .crop-header p {
  margin-top: 3px;
  font-size: 11px;
  line-height: 1.35;
}

.crop-dialog .crop-viewport {
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  border-radius: 15px;
}

.crop-dialog .crop-controls {
  min-height: 0;
  margin: 0;
  gap: 8px;
  padding-top: 1px;
  background: #fff;
}

.crop-dialog .crop-controls .field {
  gap: 3px;
}

.crop-dialog .crop-controls .field label {
  font-size: 10px;
}

.crop-dialog .crop-controls .range-row {
  min-height: 34px;
}

.crop-dialog .crop-actions {
  display: grid;
  grid-template-columns: .85fr .7fr 1.35fr;
  gap: 7px;
}

.crop-dialog .crop-actions .primary-btn,
.crop-dialog .crop-actions .outline-btn {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: 8px 7px;
  font-size: 12px;
}

.crop-dialog .crop-frame {
  width: 280px;
  height: 280px;
  max-width: none;
  max-height: none;
}

@media (max-width: 820px) {
  .crop-dialog {
    inset: 0;
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
  }

  .crop-dialog .crop-card {
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    padding:
      max(9px, env(safe-area-inset-top))
      10px
      max(9px, env(safe-area-inset-bottom));
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 8px;
  }

  .crop-dialog .crop-header h2 {
    font-size: 17px;
  }

  .crop-dialog .crop-header p {
    font-size: 10px;
  }

  .crop-dialog .crop-close-btn {
    width: 36px;
    height: 36px;
    min-height: 36px;
    flex-basis: 36px;
  }

  .crop-dialog .crop-viewport {
    min-height: 0;
    border-radius: 13px;
  }

  .crop-dialog .crop-controls {
    gap: 6px;
  }

  .crop-dialog .crop-actions .primary-btn,
  .crop-dialog .crop-actions .outline-btn {
    min-height: 38px;
    font-size: 11px;
  }
}

@media (max-height: 650px) {
  .crop-dialog .crop-card {
    padding-top: max(6px, env(safe-area-inset-top));
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    gap: 5px;
  }

  .crop-dialog .crop-header p {
    display: none;
  }

  .crop-dialog .crop-header h2 {
    font-size: 16px;
  }

  .crop-dialog .crop-controls .field label {
    display: none;
  }

  .crop-dialog .crop-controls {
    gap: 4px;
  }

  .crop-dialog .crop-actions .primary-btn,
  .crop-dialog .crop-actions .outline-btn {
    min-height: 35px;
    padding-block: 6px;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  .crop-dialog .crop-card {
    grid-template-columns: minmax(0, 1fr) minmax(210px, 260px);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .crop-dialog .crop-header {
    grid-column: 1 / -1;
  }

  .crop-dialog .crop-viewport {
    grid-column: 1;
    grid-row: 2;
  }

  .crop-dialog .crop-controls {
    grid-column: 2;
    grid-row: 2;
    align-self: center;
  }

  .crop-dialog .crop-actions {
    grid-template-columns: 1fr;
  }
}


/* =========================================================
   V10 — Mobile tinh gọn, chỉnh sửa inline dưới ảnh
   ========================================================= */

.mobile-home-icon,
.mobile-export-wrap,
.mobile-inline-inspector-head {
  display: none;
}

.top-actions {
  position: relative;
}

.mobile-export-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 190;
  width: 170px;
  padding: 7px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 16px 38px rgba(15,23,42,.22);
}

.mobile-export-menu button {
  min-height: 39px;
  padding: 7px 5px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
  color: #334155;
  font-size: 11px;
  font-weight: 900;
}

.mobile-export-menu button:last-child {
  color: #fff;
  border-color: #0068ff;
  background: #0068ff;
}

@media (max-width: 820px) {
  /* Header: giữ avatar, thay chữ dài bằng icon về trang chủ. */
  .brand {
    flex: 1;
    gap: 7px;
  }

  .brand-text {
    display: none !important;
  }

  .mobile-home-icon {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 11px;
    color: var(--brand-dark);
    background: #f8fafc;
  }

  .mobile-export-wrap {
    display: block;
    position: relative;
  }

  .mobile-export-btn {
    color: #fff;
    border-color: var(--brand);
    background: var(--brand);
  }

  /* Ẩn tên mẫu/màu và trạng thái lưu để dành không gian cho khung áo. */
  .workspace-head {
    display: none !important;
  }

  .main-layout {
    padding-top: 7px;
  }

  .workspace-panel {
    gap: 6px;
  }

  .stage-viewport {
    padding: 5px;
    border-radius: 15px;
  }

  /* Thanh 5 nút nằm ngay dưới ảnh, không dính đáy màn hình. */
  .mobile-stage-toolbar {
    position: static !important;
    bottom: auto !important;
    z-index: auto;
    grid-template-columns: .72fr 1.2fr .72fr .65fr .72fr;
    gap: 5px;
    padding: 0;
    margin: 1px 0 3px;
  }

  .mobile-tool-btn {
    min-height: 40px;
    padding: 6px 3px;
    font-size: 9.5px;
    line-height: 1.15;
  }

  /* Hàng In/Tải ảnh/HD/Zalo được thu vào menu trên header. */
  .bottom-bar {
    display: none !important;
  }

  /* Chỉ bảng Mẫu là bottom sheet. */
  .config-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 120;
    padding: 0 10px max(10px, env(safe-area-inset-bottom));
    transform: translateY(calc(100% + 20px));
    opacity: 0;
    pointer-events: none;
    transition: transform .22s ease, opacity .22s ease;
  }

  .config-panel.mobile-open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  .config-panel .panel-card {
    max-height: min(72dvh, 620px);
    overflow: auto;
    border-radius: 20px;
    box-shadow: 0 -12px 30px rgba(15,23,42,.18);
  }

  /* Phần Chỉnh sửa không còn là cửa sổ nổi.
     Nó xuất hiện trực tiếp bên dưới khung ảnh. */
  .inspector-panel {
    display: none;
    position: static !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    z-index: auto !important;
    width: 100%;
    padding: 0 !important;
    transform: none !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    transition: none !important;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .inspector-panel.mobile-inline-open {
    display: grid;
  }

  .inspector-panel .panel-card {
    max-height: none !important;
    overflow: visible !important;
    border-radius: 16px;
    box-shadow: 0 8px 20px rgba(15,23,42,.07);
  }

  .mobile-inline-inspector-head {
    position: sticky;
    top: 64px;
    z-index: 75;
    min-height: 46px;
    padding: 7px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: rgba(255,255,255,.97);
    backdrop-filter: blur(10px);
    box-shadow: 0 7px 18px rgba(15,23,42,.08);
  }

  .mobile-inline-inspector-head strong {
    font-size: 12px;
  }

  .mobile-inline-inspector-head button {
    min-height: 32px;
    padding: 5px 9px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: #f8fafc;
    color: #475569;
    font-size: 10px;
    font-weight: 900;
  }

  /* Bỏ nút đóng sheet cũ trong card vì đã có thanh Thu gọn bên trên. */
  .inspector-panel .layer-panel .sheet-close {
    display: none !important;
  }

  .mobile-panel-backdrop {
    bottom: 0;
  }

  .toast {
    bottom: 22px;
  }
}

@media (max-width: 520px) {
  .topbar {
    min-height: 58px;
    padding-inline: 8px;
  }

  .brand img {
    width: 38px;
    height: 38px;
  }

  .mobile-home-icon {
    width: 36px;
    height: 36px;
  }

  .top-actions {
    gap: 4px;
  }

  .top-actions .icon-btn {
    width: 35px;
    height: 35px;
    min-height: 35px;
  }

  .zalo-link {
    min-height: 35px;
    padding: 8px 10px;
    font-size: 11px;
  }

  .mobile-export-menu {
    right: -43px;
  }

  .main-layout {
    padding: 6px;
  }

  .design-stage {
    width: calc(100vw - 22px);
  }

  .panel-card {
    padding: 12px;
  }

  .inspector-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
