/* frontend/css/studio.css — v3 Premium Visual Design */

/* ============================================================
   PREMIUM DESIGN SYSTEM
   ============================================================ */
:root {
  /* Accent — champagne gold (cinematic editorial) */
  --s-accent: #a37c3a;
  --s-accent-hover: #7d5f2c;
  --s-accent-text: #7d5f2c; /* Darker gold for text on light backgrounds - meets WCAG AA 4.5:1 */
  --s-accent-light: rgba(193, 152, 86, 0.14);
  --s-accent-glow: rgba(193, 152, 86, 0.14);
  --s-accent-glow-strong: rgba(193, 152, 86, 0.25);
  --s-accent-gradient: #c19856;
  --s-accent-gradient-hover: #a37c3a;

  /* Surfaces — warm paper */
  --s-bg: #f5f2eb;
  --s-bg-subtle: #ece4d3;
  --s-card: #fffdf8;
  --s-card-hover: #f7f1e3;
  --s-surface: #f5f2eb;
  --s-surface-elevated: #fffdf8;

  /* Borders */
  --s-border: rgba(15, 12, 9, 0.12);
  --s-border-strong: rgba(15, 12, 9, 0.22);
  --s-border-accent: rgba(193, 152, 86, 0.45);

  /* Text — ink on paper */
  --s-text: #0f0c09;
  --s-text-secondary: #3f3830;
  --s-text-muted: #6d6358;
  --s-text-inverse: #f5f2eb;

  /* Radius — sharp editorial */
  --s-radius-xs: 2px;
  --s-radius: 3px;
  --s-radius-md: 4px;
  --s-radius-lg: 6px;
  --s-radius-xl: 8px;
  --s-radius-full: 9999px;

  /* Shadows — layered for depth */
  --s-shadow-xs: 0 1px 2px rgba(23,20,15,0.05);
  --s-shadow-sm: 0 1px 3px rgba(23,20,15,0.07), 0 1px 2px rgba(23,20,15,0.05);
  --s-shadow: 0 4px 6px -1px rgba(23,20,15,0.08), 0 2px 4px -1px rgba(23,20,15,0.05);
  --s-shadow-md: 0 10px 15px -3px rgba(23,20,15,0.09), 0 4px 6px -2px rgba(23,20,15,0.05);
  --s-shadow-lg: 0 20px 25px -5px rgba(23,20,15,0.09), 0 10px 10px -5px rgba(23,20,15,0.04);
  --s-shadow-xl: 0 25px 50px -12px rgba(23,20,15,0.16);
  --s-shadow-glow: 0 4px 16px rgba(193, 152, 86, 0.22), 0 12px 28px rgba(23, 20, 15, 0.08);
  --s-shadow-card: 0 1px 3px rgba(23,20,15,0.05), 0 4px 12px rgba(23,20,15,0.04);
  --s-shadow-card-hover: 0 4px 12px rgba(23,20,15,0.09), 0 12px 28px rgba(23,20,15,0.07);

  /* Glass */
  --s-glass-bg: rgba(255, 255, 255, 0.72);
  --s-glass-border: rgba(255, 255, 255, 0.4);
  --s-glass-blur: 16px;

  /* Transitions */
  --s-transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --s-transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --s-transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  --s-transition-spring: 0.5s cubic-bezier(0.16, 1, 0.3, 1);

  /* Layout */
  --s-left-width: 380px;
  --s-right-width: 300px;
  --s-toolbar-height: 52px;
  --s-nav-height: 72px;

  /* Spacing scale */
  --s-space-1: 4px;
  --s-space-2: 8px;
  --s-space-3: 12px;
  --s-space-4: 16px;
  --s-space-5: 20px;
  --s-space-6: 24px;
  --s-space-8: 32px;
  --s-space-10: 40px;
}

/* Dark mode — warm charcoal */
[data-theme="dark"] {
  --s-bg: #17140f;
  --s-bg-subtle: #1f1b15;
  --s-card: #211d16;
  --s-card-hover: #2a241b;
  --s-surface: #1c1812;
  --s-surface-elevated: #262119;
  --s-accent: #d5b178;
  --s-accent-hover: #c19856;
  --s-accent-text: #d5b178; /* In dark mode, accent-text is the bright gold */
  --s-accent-light: rgba(213, 177, 120, 0.14);
  --s-accent-glow: rgba(213, 177, 120, 0.18);
  --s-accent-glow-strong: rgba(213, 177, 120, 0.3);
  --s-accent-gradient: #d5b178;
  --s-accent-gradient-hover: #c19856;
  --s-border: rgba(245, 242, 235, 0.12);
  --s-border-strong: rgba(245, 242, 235, 0.2);
  --s-border-accent: rgba(213, 177, 120, 0.45);
  --s-text: #f5f2ed;
  --s-text-secondary: #b5ab9c;
  --s-text-muted: #8a8272;
  --s-shadow-xs: 0 1px 2px rgba(0,0,0,0.2);
  --s-shadow-sm: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --s-shadow: 0 4px 6px -1px rgba(0,0,0,0.3), 0 2px 4px -1px rgba(0,0,0,0.2);
  --s-shadow-md: 0 10px 15px -3px rgba(0,0,0,0.4), 0 4px 6px -2px rgba(0,0,0,0.2);
  --s-shadow-lg: 0 20px 25px -5px rgba(0,0,0,0.5), 0 10px 10px -5px rgba(0,0,0,0.2);
  --s-shadow-xl: 0 25px 50px -12px rgba(0,0,0,0.6);
  --s-shadow-card: 0 1px 3px rgba(0,0,0,0.3), 0 4px 12px rgba(0,0,0,0.2);
  --s-shadow-card-hover: 0 4px 12px rgba(0,0,0,0.4), 0 12px 28px rgba(0,0,0,0.3);
  --s-glass-bg: rgba(33, 29, 22, 0.75);
  --s-glass-border: rgba(255, 255, 255, 0.08);
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInScale {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-16px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

@keyframes glow {
  0%, 100% { box-shadow: 0 4px 16px rgba(193, 152, 86, 0.18); }
  50% { box-shadow: 0 6px 24px rgba(193, 152, 86, 0.3); }
}

@keyframes ripple {
  to { transform: scale(4); opacity: 0; }
}

@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes borderGlow {
  0%, 100% { border-color: rgba(193, 152, 86, 0.3); }
  50% { border-color: rgba(193, 152, 86, 0.6); }
}

@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

/* ============================================================
   BASE RESET
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

.studio-main {
  min-height: 100vh;
  background: var(--s-bg);
  padding-top: var(--s-nav-height);
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.4s ease;
}

/* ============================================================
   NAVBAR — Premium glass effect
   ============================================================ */
.studio-main .navbar,
.navbar {
  background: var(--s-glass-bg) !important;
  backdrop-filter: blur(var(--s-glass-blur)) saturate(1.2);
  -webkit-backdrop-filter: blur(var(--s-glass-blur)) saturate(1.2);
  border-bottom: 1px solid var(--s-glass-border) !important;
  box-shadow: var(--s-shadow-xs) !important;
}

.studio-main .navbar .container,
.navbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 var(--s-space-6);
  height: var(--s-nav-height);
}

.navbar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--s-text);
  letter-spacing: -0.02em;
}

.logo-icon { width: 32px; height: 32px; }
.logo-highlight { color: var(--s-accent-text); }

.navbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Theme toggle */
.theme-toggle {
  width: 34px;
  height: 34px;
  border-radius: var(--s-radius);
  border: 1px solid var(--s-border);
  background: var(--s-surface);
  color: var(--s-text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--s-transition);
  position: relative;
  overflow: hidden;
}

.theme-toggle:hover {
  border-color: var(--s-accent-text);
  color: var(--s-accent-text);
  background: var(--s-accent-glow);
  transform: scale(1.05);
}

.theme-toggle:active { transform: scale(0.95); }

.theme-toggle .sun-icon,
.theme-toggle .moon-icon { width: 17px; height: 17px; transition: var(--s-transition); }
[data-theme="light"] .theme-toggle .moon-icon { display: none; }
[data-theme="dark"] .theme-toggle .sun-icon { display: none; }

/* Language toggle */
.lang-toggle {
  display: flex;
  background: var(--s-surface);
  border-radius: var(--s-radius);
  padding: 3px;
  border: 1px solid var(--s-border);
}

.lang-toggle span {
  padding: 5px 12px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--s-text-muted);
  cursor: pointer;
  border-radius: var(--s-radius-xs);
  transition: all var(--s-transition-fast);
  letter-spacing: 0.02em;
}

.lang-toggle span:hover { color: var(--s-text-secondary); }

.lang-toggle span.active {
  background: var(--s-card);
  color: var(--s-text);
  box-shadow: var(--s-shadow-sm);
}

/* ============================================================
   TOOLBAR — Premium tabs
   ============================================================ */
.studio-toolbar {
  background: var(--s-glass-bg);
  backdrop-filter: blur(var(--s-glass-blur)) saturate(1.1);
  -webkit-backdrop-filter: blur(var(--s-glass-blur)) saturate(1.1);
  border-bottom: 1px solid var(--s-border);
  position: sticky;
  top: var(--s-nav-height);
  z-index: 100;
}

.studio-toolbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  padding: 4px var(--s-space-5) 0;
  gap: 2px;
  min-height: 48px;
  align-items: stretch;
}

.toolbar-tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 13px 18px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--s-text-muted);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all var(--s-transition);
  white-space: nowrap;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
}

.toolbar-tab:hover {
  color: var(--s-text);
  background: var(--s-accent-glow);
}

.toolbar-tab.active {
  color: var(--s-accent-text);
  border-bottom-color: var(--s-accent-text);
}

.toolbar-tab svg {
  flex-shrink: 0;
  transition: var(--s-transition-fast);
}

.toolbar-tab:hover svg {
  transform: translateY(-1px);
}

/* ============================================================
   3-COLUMN LAYOUT
   ============================================================ */
.studio-layout {
  display: grid;
  grid-template-columns: var(--s-left-width) 1fr var(--s-right-width);
  gap: 0;
  flex: 1;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
  animation: fadeIn 0.5s ease 0.1s both;
}

/* ============================================================
   LEFT PANEL — AI Controls
   ============================================================ */
.studio-left {
  background: var(--s-card);
  border-right: 1px solid var(--s-border);
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--s-nav-height) - var(--s-toolbar-height));
  position: sticky;
  top: calc(var(--s-nav-height) + var(--s-toolbar-height));
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--s-border-strong) transparent;
}

.studio-left::-webkit-scrollbar { width: 4px; }
.studio-left::-webkit-scrollbar-track { background: transparent; }
.studio-left::-webkit-scrollbar-thumb { background: var(--s-border-strong); border-radius: 4px; }

/* Tab Panels */
.tab-panel {
  display: none;
  flex-direction: column;
  flex: 1;
  animation: fadeIn 0.3s ease;
}

.tab-panel.active { display: flex; }

.panel-section-header {
  padding: var(--s-space-4) var(--s-space-5) 0;
}

.panel-section-header h3 {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--s-text-muted);
  margin: 0;
}

.panel-section-body {
  padding: var(--s-space-4) var(--s-space-5) var(--s-space-5);
  display: flex;
  flex-direction: column;
  gap: var(--s-space-3);
}

.panel-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--s-text-secondary);
  margin-top: 2px;
}

/* ============================================================
   PROMPT INPUT — Premium textarea
   ============================================================ */
.prompt-area {
  position: relative;
}

.prompt-input {
  width: 100%;
  min-height: 110px;
  padding: var(--s-space-3) var(--s-space-4);
  padding-bottom: 48px;
  font-family: 'Be Vietnam Pro', system-ui, sans-serif;
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--s-text);
  background: var(--s-surface);
  border: 1.5px solid var(--s-border);
  border-radius: var(--s-radius-md);
  resize: vertical;
  transition: all var(--s-transition);
  box-sizing: border-box;
  overflow-wrap: anywhere;
  unicode-bidi: plaintext;
}

.prompt-input:hover {
  border-color: var(--s-border-strong);
  background: var(--s-card);
}

.prompt-input:focus {
  outline: none;
  border-color: var(--s-accent-text);
  box-shadow: 0 0 0 3px var(--s-accent-glow), var(--s-shadow-sm);
  background: var(--s-card);
}

.prompt-input::placeholder {
  color: var(--s-text-muted);
  font-style: italic;
}

/* Enhance Button */
.prompt-enhance-btn {
  position: absolute;
  bottom: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--s-accent-text);
  background: var(--s-accent-glow);
  border: 1px solid var(--s-accent-glow-strong);
  border-radius: var(--s-radius-full);
  cursor: pointer;
  transition: all var(--s-transition);
  letter-spacing: 0.02em;
}

.prompt-enhance-btn:hover {
  background: var(--s-accent-glow-strong);
  transform: translateY(-1px);
  box-shadow: var(--s-shadow-sm);
}

.prompt-enhance-btn:active {
  transform: translateY(0) scale(0.97);
}

.prompt-enhance-btn.enhancing {
  opacity: 0.7;
  pointer-events: none;
}

.prompt-enhance-btn.enhancing::after {
  content: '';
  width: 12px;
  height: 12px;
  border: 2px solid var(--s-accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ============================================================
   TEXT INPUT
   ============================================================ */
.text-input {
  width: 100%;
  padding: var(--s-space-2) var(--s-space-3);
  font-family: 'Be Vietnam Pro', system-ui, sans-serif;
  font-size: 0.85rem;
  color: var(--s-text);
  background: var(--s-surface);
  border: 1.5px solid var(--s-border);
  border-radius: var(--s-radius);
  transition: all var(--s-transition);
  box-sizing: border-box;
  overflow-wrap: anywhere;
  unicode-bidi: plaintext;
}

.text-input:hover {
  border-color: var(--s-border-strong);
  background: var(--s-card);
}

.text-input:focus {
  outline: none;
  border-color: var(--s-accent-text);
  box-shadow: 0 0 0 3px var(--s-accent-glow);
  background: var(--s-card);
}

/* ============================================================
   STYLE GRID — Premium chips
   ============================================================ */
.style-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.style-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 12px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--s-text-secondary);
  background: var(--s-surface);
  border: 1.5px solid var(--s-border);
  border-radius: var(--s-radius);
  cursor: pointer;
  transition: all var(--s-transition);
  text-align: left;
  position: relative;
  overflow: hidden;
}

.style-chip::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--s-accent-gradient);
  opacity: 0;
  transition: opacity var(--s-transition);
}

.style-chip:hover {
  border-color: var(--s-accent-text);
  color: var(--s-text);
  transform: translateY(-1px);
  box-shadow: var(--s-shadow-sm);
}

.style-chip.active {
  border-color: var(--s-accent-text);
  background: var(--s-accent-glow);
  color: var(--s-accent-text);
  font-weight: 600;
}

.style-chip:active {
  transform: translateY(0) scale(0.97);
}

.style-chip-icon {
  width: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--s-accent-text);
}

/* ============================================================
   PROMPT SUGGESTIONS
   ============================================================ */
.prompt-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: var(--s-space-2);
}

.prompt-suggestion-chip {
  padding: 6px 11px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--s-text-muted);
  background: var(--s-surface);
  border: 1px solid var(--s-border);
  border-radius: 20px;
  cursor: pointer;
  transition: all var(--s-transition);
  white-space: nowrap;
  font-family: 'Be Vietnam Pro', system-ui, sans-serif;
}

.prompt-suggestion-chip:hover {
  color: var(--s-accent-text);
  border-color: var(--s-accent-text);
  background: var(--s-accent-glow);
  transform: translateY(-1px);
}

.prompt-suggestion-chip:active {
  transform: translateY(0) scale(0.96);
}

/* ============================================================
   GENERATE BUTTON — Premium CTA
   ============================================================ */
/* Credit remaining badge — shows how many AI generations the user has left */
.credit-remaining-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding: 8px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--s-text-muted, #b8b2a7);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--s-radius-md, 10px);
}
.credit-remaining-badge[data-tone="low"] {
  color: #d97706;
  border-color: rgba(217, 119, 6, 0.35);
}
.credit-remaining-badge[data-tone="empty"] {
  color: #dc2626;
  border-color: rgba(220, 38, 38, 0.35);
}
.credit-remaining-icon { font-size: 0.9rem; }
.credit-remaining-buy {
  margin-left: auto;
  font-weight: 700;
  color: #d4a24e;
  text-decoration: none;
  border-bottom: 1px dashed rgba(212, 162, 78, 0.5);
}
.credit-remaining-buy:hover { color: #e8bc6f; }

.generate-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 24px;
  font-family: 'Be Vietnam Pro', system-ui, sans-serif;
  font-size: 0.92rem;
  font-weight: 700;
  color: #f5f2eb;
  background: #0f0c09;
  border: 1px solid #0f0c09;
  border-radius: var(--s-radius-md);
  cursor: pointer;
  transition: transform var(--s-transition), background var(--s-transition), color var(--s-transition), box-shadow var(--s-transition);
  position: relative;
  overflow: hidden;
  margin-top: var(--s-space-2);
  letter-spacing: 0.01em;
  box-shadow: 0 4px 14px rgba(15, 12, 9, 0.25);
}

.generate-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.15) 0%, transparent 50%, rgba(255,255,255,0.05) 100%);
  opacity: 0;
  transition: opacity var(--s-transition);
}

.generate-btn:hover {
  transform: translateY(-2px);
  background: #c19856;
  border-color: #c19856;
  color: #0f0c09;
  box-shadow: 0 6px 20px rgba(193, 152, 86, 0.5);
}

.generate-btn:hover::before { opacity: 1; }

.generate-btn:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 2px 8px rgba(15, 12, 9, 0.25);
}

.generate-btn.loading {
  pointer-events: none;
  opacity: 0.85;
  background: #0f0c09;
  border-color: #0f0c09;
  transform: scale(0.98);
  will-change: transform;
}
.generate-btn.is-success {
  background: #4a5a3f !important;
  border-color: #4a5a3f !important;
}
.generate-btn.shake {
  animation: btnShake 280ms cubic-bezier(.36,.07,.19,.97) both;
}
@keyframes btnShake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(1px); }
  30%, 50%, 70% { transform: translateX(-3px); }
  40%, 60% { transform: translateX(3px); }
}
@media (prefers-reduced-motion: reduce) {
  .generate-btn.loading { transform: none !important; }
  .generate-btn.shake { animation: none !important; }
}

.generate-btn-loading { display: none; }
.generate-btn.loading .generate-btn-text,
.generate-btn.loading .generate-btn-icon { display: none; }
.generate-btn.loading .generate-btn-loading { display: inline; }

.generate-btn-spinner {
  display: none;
}

.generate-btn.loading .generate-btn-spinner {
  display: block;
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ============================================================
   UPLOAD ZONE
   ============================================================ */
.upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--s-space-8) var(--s-space-5);
  border: 2px dashed var(--s-border);
  border-radius: var(--s-radius-lg);
  cursor: pointer;
  transition: all var(--s-transition);
  text-align: center;
  gap: var(--s-space-2);
  background: var(--s-surface);
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--s-accent-text);
  background: var(--s-accent-glow);
  transform: translateY(-2px);
  box-shadow: var(--s-shadow-md);
}

/* Sprint 1: state machine — dragging scale, error shake, preview reveal */
.upload-zone.is-dragging {
  transform: scale(1.015);
  border-color: var(--s-accent-text);
  background: var(--s-accent-glow);
  box-shadow: var(--s-shadow-md);
  will-change: transform;
}
.upload-zone.is-error {
  border-color: #a3341f;
  background: rgba(163, 52, 31, 0.08);
}
@keyframes shakeX {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(1px); }
  30%, 50%, 70% { transform: translateX(-3px); }
  40%, 60% { transform: translateX(3px); }
}
.upload-zone.shake {
  animation: shakeX 280ms cubic-bezier(.36,.07,.19,.97) both;
}
.upload-preview.entering {
  animation: previewIn 300ms cubic-bezier(0.16,1,0.3,1) both;
}
@keyframes previewIn {
  from { opacity: 0; transform: scale(0.88); }
  to { opacity: 1; transform: scale(1); }
}
.upload-preview.leaving {
  animation: previewOut 220ms ease both;
}
@keyframes previewOut {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0; transform: scale(0.94); }
}
@media (prefers-reduced-motion: reduce) {
  .upload-zone.is-dragging { transform: none !important; }
  .upload-zone.shake { animation: none !important; }
  .upload-preview.entering,
  .upload-preview.leaving { animation: none !important; }
}

.upload-zone svg { color: var(--s-text-muted); transition: var(--s-transition); }
.upload-zone:hover svg { color: var(--s-accent-text); transform: translateY(-2px); }

.upload-zone-text {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--s-text);
}

.upload-zone-or {
  font-size: 0.75rem;
  color: var(--s-text-muted);
}

.upload-zone-browse {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--s-accent-text);
  cursor: pointer;
}

.upload-zone-formats {
  font-size: 0.75rem;
  color: var(--s-text-muted);
  margin-top: var(--s-space-1);
}

.upload-preview {
  position: relative;
  border-radius: var(--s-radius-md);
  overflow: hidden;
  border: 1.5px solid var(--s-border);
  animation: fadeInScale 0.3s ease;
}

.upload-preview img {
  width: 100%;
  height: 180px;
  object-fit: cover;
  display: block;
}

.upload-preview-remove {
  position: absolute;
  top: var(--s-space-2);
  right: var(--s-space-2);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  color: #fff;
  border: none;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--s-transition);
}

.upload-preview-remove:hover {
  background: rgba(220, 38, 38, 0.9);
  transform: scale(1.1);
}

/* ============================================================
   HISTORY PANEL
   ============================================================ */
.panel-history {
  border-top: 1px solid var(--s-border);
  margin-top: auto;
}

.panel-history-header {
  display: flex;
  align-items: center;
  gap: var(--s-space-2);
  padding: var(--s-space-3) var(--s-space-5);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--s-text-secondary);
  cursor: pointer;
  transition: all var(--s-transition);
  user-select: none;
}

.panel-history-header:hover {
  background: var(--s-card-hover);
  color: var(--s-text);
}

.history-chevron {
  margin-left: auto;
  transition: transform var(--s-transition);
}

.panel-history.open .history-chevron { transform: rotate(180deg); }

.panel-history-list {
  display: none;
  max-height: 240px;
  overflow-y: auto;
  padding: 0 var(--s-space-3) var(--s-space-3);
}

.panel-history.open .panel-history-list { display: block; }

.history-item {
  display: flex;
  align-items: center;
  gap: var(--s-space-2);
  padding: var(--s-space-2);
  border-radius: var(--s-radius);
  cursor: pointer;
  transition: all var(--s-transition-fast);
}

.history-item:hover {
  background: var(--s-card-hover);
  transform: translateX(2px);
}

.history-item-thumb {
  width: 40px;
  height: 40px;
  border-radius: var(--s-radius-xs);
  object-fit: cover;
  background: var(--s-surface);
  border: 1px solid var(--s-border);
  flex-shrink: 0;
}

.history-item-info { flex: 1; min-width: 0; }

.history-item-prompt {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--s-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-time {
  font-size: 0.72rem;
  color: var(--s-text-muted);
}

.history-item-delete {
  width: 24px;
  height: 24px;
  border-radius: var(--s-radius-xs);
  border: none;
  background: transparent;
  color: var(--s-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all var(--s-transition-fast);
  flex-shrink: 0;
}

.history-item:hover .history-item-delete { opacity: 1; }

.history-item-delete:hover {
  background: rgba(163, 52, 31, 0.1);
  color: #a3341f;
}

/* ============================================================
   CENTER: CANVAS — The hero
   ============================================================ */
.studio-canvas {
  display: flex;
  flex-direction: column;
  background: var(--s-bg);
  position: relative;
  overflow: hidden;
}

.canvas-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 500px;
  background:
    radial-gradient(circle at 50% 50%, rgba(193, 152, 86, 0.05) 0%, transparent 60%),
    var(--s-bg);
}

.canvas-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-space-3);
  color: var(--s-text-secondary);
  text-align: center;
  animation: fadeInUp 0.6s ease;
}

.canvas-empty svg {
  color: var(--s-accent-text);
  background: var(--s-accent-glow);
  border: 1px solid var(--s-border-accent);
  border-radius: 50%;
  padding: 18px;
  opacity: 1;
  animation: float 3s ease-in-out infinite;
}

.canvas-empty p {
  color: var(--s-text);
}

.canvas-empty p {
  font-size: 0.9rem;
  font-weight: 500;
}

/* 3D Viewer */
.canvas-viewer {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: studioCanvasReveal 0.3s ease;
}
@keyframes studioCanvasReveal { from { opacity: 0; } to { opacity: 1; } }

.viewer-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.viewer-fallback-img,
.viewer-css-fallback,
.viewer-svg-fallback {
  display: none;
  max-width: 300px;
  max-height: 400px;
}

/* Honest unavailable-garment state: never render another garment's model.
   The WebGL canvas hides; the 2D preview + notice stay visible. */
.garment-unavailable-msg {
  display: none;
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  max-width: min(420px, 90%);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(20, 16, 12, 0.82);
  color: #f6f3ec;
  font-size: 0.78rem;
  text-align: center;
  pointer-events: none;
  z-index: 3;
}
.canvas-viewer.garment-unavailable .viewer-canvas {
  display: none;
}
.canvas-viewer.garment-unavailable .garment-unavailable-msg:not([hidden]) {
  display: block;
}

/* Product selector: mark garments without a real 3D asset yet. */
.product-type-btn {
  position: relative;
}
.product-3d-badge {
  position: absolute;
  top: -8px;
  right: -6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--s-surface, #2a2620);
  border: 1px solid var(--s-border);
  color: var(--s-text-muted, #a8a29e);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.viewer-design-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.viewer-design-overlay .mockup-print-design {
  position: absolute;
  left: 0;
  top: 0;
  width: 46%;
  max-width: 320px;
  mix-blend-mode: multiply;
  transform: translate(calc(-50% + var(--print-x, 0%)), calc(-50% + var(--print-y, 0%))) scale(var(--print-scale, 1));
  user-select: none;
  pointer-events: none;
  box-shadow: none;
}

/* Prompt side switch — front/back separate prompts */
.prompt-side-switch {
  display: flex;
  gap: 6px;
  margin-bottom: var(--s-space-2, 8px);
}
.prompt-side-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 10px;
  border: 1px solid var(--s-border);
  border-radius: 8px;
  background: var(--s-card);
  color: var(--s-text-secondary, #6b6156);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.prompt-side-btn:hover {
  border-color: var(--s-border-accent);
  color: var(--s-text-primary, #1a1611);
}
.prompt-side-btn.active {
  background: var(--s-accent-light);
  border-color: var(--s-border-accent);
  color: var(--s-accent-text);
}
.prompt-side-btn:focus-visible {
  outline: 2px solid var(--s-accent);
  outline-offset: 2px;
}

.viewer-design-overlay .mockup-print-text {
  position: absolute;
  left: 0;
  top: 0;
  font-family: 'Be Vietnam Pro', system-ui, sans-serif;
  font-weight: 800;
  font-size: clamp(18px, 3.6vw, 34px);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
  max-width: 86%;
  overflow: hidden;
  text-overflow: ellipsis;
  overflow-wrap: anywhere;
  color: #111827;
  /* Stroke/viền điều khiển qua inline style từ renderStyledTextOverlay()
     (đồng bộ composite). Không hard-code text-shadow ở đây — quyền
     hiển thị thuộc về style người dùng chọn. */
  transform: translate(calc(-50% + var(--text-x, 0%)), calc(-50% + var(--text-y, 0%))) scale(var(--text-scale, 1));
  user-select: none;
  pointer-events: none;
}

/* Canvas Controls Bar */
.canvas-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s-space-2) var(--s-space-5);
  background: var(--s-glass-bg);
  backdrop-filter: blur(var(--s-glass-blur));
  border-top: 1px solid var(--s-border);
}

.canvas-controls-left,
.canvas-controls-center,
.canvas-controls-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* View Toggle */
.view-toggle {
  display: flex;
  background: var(--s-surface);
  border-radius: var(--s-radius);
  padding: 3px;
  border: 1px solid var(--s-border);
}

.view-toggle-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--s-text-muted);
  background: transparent;
  border: none;
  border-radius: var(--s-radius-xs);
  cursor: pointer;
  transition: all var(--s-transition-fast);
}

.view-toggle-btn.active {
  background: var(--s-card);
  color: var(--s-text);
  box-shadow: var(--s-shadow-sm);
}

.view-toggle-btn:hover:not(.active) { color: var(--s-text); }

/* Canvas Control Buttons */
.canvas-ctrl-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--s-text-secondary);
  background: var(--s-surface);
  border: 1px solid var(--s-border);
  border-radius: var(--s-radius);
  cursor: pointer;
  transition: all var(--s-transition);
}

.canvas-ctrl-btn:hover {
  border-color: var(--s-accent-text);
  color: var(--s-accent-text);
  background: var(--s-accent-glow);
}

.canvas-ctrl-btn.active {
  border-color: var(--s-accent-text);
  background: var(--s-accent-glow);
  color: var(--s-accent-text);
}

/* ============================================================
   PLACEMENT PANEL
   ============================================================ */
.placement-panel {
  background: var(--s-card);
  border-top: 1px solid var(--s-border);
  padding: var(--s-space-3) var(--s-space-5) var(--s-space-4);
  animation: fadeInUp 0.3s ease;
}

.viewer-side-badge {
  position: absolute;
  top: 10px;
  left: 12px;
  z-index: 5;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--s-card);
  background: var(--s-text);
  border: 1px solid var(--s-text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  user-select: none;
  pointer-events: none;
}

.viewer-side-badge.is-back {
  color: var(--s-accent-text);
  background: var(--s-accent-glow);
  border-color: var(--s-border-accent);
}

.back-design-controls {
  margin-bottom: 10px;
  padding: 10px 12px;
  border: 1px dashed var(--s-border-accent);
  border-radius: var(--s-radius);
  background: var(--s-accent-glow);
}

.back-design-status {
  font-size: 0.78rem;
  color: var(--s-text-muted, #64748b);
  line-height: 1.45;
  margin-bottom: 8px;
}

.back-design-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.placement-side-tag {
  font-style: normal;
  font-weight: 800;
  color: var(--s-accent-text);
  text-transform: uppercase;
  font-size: 1em;
}

.placement-side-tag.is-back {
  color: var(--s-accent-text);
}

@media print {
  .viewer-side-badge,
  .back-design-controls {
    display: none !important;
  }
}

.placement-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--s-space-2);
}

.placement-panel-header span {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--s-text-secondary);
}

.placement-reset-btn {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--s-accent-text);
  background: none;
  border: none;
  cursor: pointer;
  padding: 3px 8px;
  border-radius: var(--s-radius-xs);
  transition: all var(--s-transition-fast);
}

.placement-reset-btn:hover {
  background: var(--s-accent-glow);
}

.placement-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: var(--s-space-2);
}

.placement-preset-btn {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--s-card);
  color: var(--s-text-secondary);
  border: 1px solid var(--s-border);
  cursor: pointer;
  transition: all var(--s-transition-fast);
}

.placement-preset-btn:hover {
  border-color: var(--s-accent-text);
  color: var(--s-text);
}

.placement-preset-btn.active {
  background: var(--s-accent-glow);
  border-color: var(--s-accent-text);
  color: var(--s-accent-text);
}

/* Multi-design layer list */
.layer-section {
  margin-top: var(--s-space-3);
}
.layer-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}
.layer-empty {
  font-size: 0.78rem;
  color: var(--s-text-muted);
  border: 1px dashed var(--s-border);
  border-radius: var(--s-radius);
  padding: 10px 12px;
}
.layer-hint {
  font-size: 0.75rem;
  color: var(--s-text-muted);
  margin-top: 8px;
  line-height: 1.5;
}
.layer-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--s-border);
  border-radius: var(--s-radius);
  background: var(--s-card);
  cursor: pointer;
}
.layer-row.selected {
  border-color: var(--s-accent-text);
  box-shadow: 0 0 0 1px var(--s-accent);
}
.layer-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 3px;
  border: 1px solid var(--s-border);
  flex-shrink: 0;
}
.layer-info {
  flex: 1;
  min-width: 0;
}
.layer-name {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--s-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  overflow-wrap: anywhere;
  min-width: 0;
}
.layer-meta {
  font-size: 0.72rem;
  color: var(--s-text-muted);
  overflow-wrap: anywhere;
  min-width: 0;
}
.layer-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.layer-btn {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  border-radius: 2px;
  border: 1px solid var(--s-border);
  background: transparent;
  color: var(--s-text-secondary);
  cursor: pointer;
}
.layer-btn:hover:not(:disabled) {
  border-color: var(--s-accent-text);
  color: var(--s-accent-text);
}
.layer-btn:disabled {
  opacity: 0.35;
  cursor: default;
}
.layer-btn.layer-del:hover {
  border-color: #a3341f;
  color: #a3341f;
}

.placement-sliders {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s-space-3);
}

.placement-slider-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* (input/track/thumb styling đã chuyển xuống block ATELIER CONTROL cuối file) */

/* ============================================================
   RIGHT PANEL — Product & Actions
   ============================================================ */
.studio-right {
  background: var(--s-card);
  border-left: 1px solid var(--s-border);
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--s-nav-height) - var(--s-toolbar-height));
  position: sticky;
  top: calc(var(--s-nav-height) + var(--s-toolbar-height));
  overflow-y: auto;
  scrollbar-width: thin;
  padding-bottom: var(--s-space-5);
}

.studio-right::-webkit-scrollbar { width: 4px; }
.studio-right::-webkit-scrollbar-thumb { background: var(--s-border-strong); border-radius: 4px; }

.right-section {
  padding: var(--s-space-4) var(--s-space-5);
  border-bottom: 1px solid var(--s-border);
  animation: fadeIn 0.4s ease calc(var(--index, 0) * 0.05s) both;
}

.right-section:nth-child(1) { --index: 0; }
.right-section:nth-child(2) { --index: 1; }
.right-section:nth-child(3) { --index: 2; }
.right-section:nth-child(4) { --index: 3; }
.right-section:nth-child(5) { --index: 4; }
.right-section:nth-child(6) { --index: 5; }
.right-section:nth-child(7) { --index: 6; }

.right-section:last-child { border-bottom: none; }

.right-section-header {
  display: flex;
  align-items: center;
  gap: var(--s-space-2);
  margin-bottom: var(--s-space-3);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--s-text-secondary);
}

.right-section-header svg { color: var(--s-text-muted); }

/* Product Type */
.product-type-row {
  display: flex;
  gap: 6px;
}

.product-type-btn {
  flex: 1;
  padding: 10px 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--s-text-secondary);
  background: var(--s-surface);
  border: 1.5px solid var(--s-border);
  border-radius: var(--s-radius);
  cursor: pointer;
  transition: all var(--s-transition);
  text-align: center;
}

.product-type-btn:hover {
  border-color: var(--s-accent-text);
  color: var(--s-text);
  transform: translateY(-1px);
}

.product-type-btn.active {
  border-color: var(--s-accent-text);
  background: var(--s-accent-glow);
  color: var(--s-accent-text);
}

/* Color */
.color-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.color-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--s-border);
  cursor: pointer;
  transition: all var(--s-transition);
  position: relative;
}

.color-dot:hover {
  transform: scale(1.2);
  box-shadow: var(--s-shadow-md);
}

.color-dot.active {
  border-color: var(--s-accent-text);
  box-shadow: 0 0 0 3px var(--s-accent-glow);
  transform: scale(1.1);
}

.color-dot[data-color="#ffffff"] {
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
}

/* Size */
.size-row {
  display: flex;
  gap: 6px;
}

.size-btn {
  flex: 1;
  padding: 10px 4px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--s-text-secondary);
  background: var(--s-surface);
  border: 1.5px solid var(--s-border);
  border-radius: var(--s-radius);
  cursor: pointer;
  transition: all var(--s-transition);
  text-align: center;
}

.size-btn:hover {
  border-color: var(--s-accent-text);
  color: var(--s-text);
  transform: translateY(-1px);
}

.size-btn.active {
  border-color: var(--s-accent-text);
  background: var(--s-accent-glow);
  color: var(--s-accent-text);
}

/* Quantity */
.qty-row {
  display: flex;
  align-items: center;
  background: var(--s-surface);
  border: 1.5px solid var(--s-border);
  border-radius: var(--s-radius);
  overflow: hidden;
  width: fit-content;
}

.qty-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--s-text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all var(--s-transition-fast);
}

.qty-btn:hover {
  background: var(--s-accent-glow);
  color: var(--s-accent-text);
}

.qty-value {
  width: 48px;
  text-align: center;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--s-text);
  border-left: 1px solid var(--s-border);
  border-right: 1px solid var(--s-border);
  line-height: 40px;
}

/* Price */
.price-section {
  background: linear-gradient(135deg, var(--s-accent-glow) 0%, rgba(193, 152, 86, 0.05) 100%);
  border-radius: var(--s-radius);
  margin: 0 var(--s-space-5);
  padding: var(--s-space-3) var(--s-space-4) !important;
  border: 1px solid var(--s-accent-glow-strong) !important;
}

.price-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.price-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--s-text-secondary);
}

.price-value {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--s-accent-text);
}

/* ============================================================
   ACTION BUTTONS
   ============================================================ */
.actions-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: var(--s-space-3) !important;
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 16px;
  font-family: 'Be Vietnam Pro', system-ui, sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--s-text-secondary);
  background: var(--s-surface);
  border: 1.5px solid var(--s-border);
  border-radius: var(--s-radius);
  cursor: pointer;
  transition: all var(--s-transition);
  position: relative;
  overflow: hidden;
}

.action-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--s-accent-gradient);
  opacity: 0;
  transition: opacity var(--s-transition);
}

.action-btn:hover:not(:disabled) {
  border-color: var(--s-accent-text);
  color: var(--s-accent-text);
  background: var(--s-accent-glow);
  transform: translateY(-1px);
}

.action-btn:active:not(:disabled) {
  transform: translateY(0) scale(0.98);
}

.action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.actions-hint {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  line-height: 1.5;
  color: var(--s-text-muted);
  text-align: center;
  margin: 2px 0 0;
}

.action-btn-primary {
  background: #0f0c09;
  border-color: #0f0c09;
  color: #f5f2eb;
  box-shadow: 0 4px 14px rgba(15, 12, 9, 0.25);
}

.action-btn-primary:hover:not(:disabled) {
  background: #c19856;
  border-color: #c19856;
  color: #0f0c09;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(193, 152, 86, 0.5);
}

.action-btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

/* ============================================================
   COMMUNITY GALLERY
   ============================================================ */
.community-section {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--s-space-10) var(--s-space-6) 60px;
  width: 100%;
  animation: fadeInUp 0.6s ease 0.3s both;
}

.community-header {
  text-align: center;
  margin-bottom: var(--s-space-8);
}

.community-header h2 {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}

.community-header p {
  color: var(--s-text-muted);
  font-size: 0.88rem;
}

.community-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--s-space-4);
}

.community-card {
  border-radius: var(--s-radius-md);
  overflow: hidden;
  border: 1px solid var(--s-border);
  background: var(--s-card);
  cursor: pointer;
  transition: all var(--s-transition);
  box-shadow: var(--s-shadow-card);
}

.community-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--s-shadow-card-hover);
  border-color: var(--s-accent-glow-strong);
}

.community-card-img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  transition: var(--s-transition);
}

.community-card:hover .community-card-img {
  transform: scale(1.03);
}

.community-card-info {
  padding: var(--s-space-3) var(--s-space-3);
  min-width: 0;
}

.community-card-prompt {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--s-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  overflow-wrap: anywhere;
  min-width: 0;
  margin-bottom: 4px;
}

.community-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--s-text-muted);
  min-width: 0;
}

.community-card-author {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: color var(--s-transition-fast);
}
.community-card-author:hover {
  color: var(--s-accent-text);
}

.community-card-img-wrap {
  cursor: pointer;
}

.community-card-like {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--s-text-muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--s-radius-xs);
  transition: all var(--s-transition-fast);
  font-size: 0.75rem;
}
.community-card-like:hover {
  color: #a3341f;
  background: rgba(163, 52, 31, 0.08);
}
.community-card-like.liked {
  color: #a3341f;
}
.community-card-like.liked:hover {
  color: #a3341f;
  background: rgba(163, 52, 31, 0.12);
}

/* ============================================================
   MODAL — Premium overlay
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: var(--s-space-5);
  animation: fadeIn 0.2s ease;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--s-card);
  border-radius: var(--s-radius-md);
  max-width: 480px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--s-shadow-xl);
  animation: fadeInScale 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  border: 1px solid var(--s-border);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s-space-5) var(--s-space-6) 0;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: var(--s-radius);
  border: 1px solid var(--s-border);
  background: var(--s-surface);
  color: var(--s-text-muted);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--s-transition);
}

.modal-close:hover {
  background: var(--s-card-hover);
  color: var(--s-text);
  border-color: var(--s-border-strong);
}

.modal-body {
  padding: var(--s-space-5) var(--s-space-6) var(--s-space-6);
}

/* Order Summary */
.order-summary {
  background: var(--s-surface);
  border-radius: var(--s-radius-md);
  padding: var(--s-space-3) var(--s-space-4);
  margin-bottom: var(--s-space-4);
  border: 1px solid var(--s-border);
}

.order-summary-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 0.85rem;
}

.order-summary-row .label { color: var(--s-text-secondary); }
.order-summary-row .value { font-weight: 600; color: var(--s-text); }

.order-summary-row.total {
  border-top: 1px solid var(--s-border);
  margin-top: 6px;
  padding-top: 10px;
}

.order-summary-row.total .label { font-weight: 700; color: var(--s-text); }

.order-summary-row.total .value {
  font-weight: 800;
  color: var(--s-accent-text);
  font-size: 1.05rem;
}

/* Payment Method */
.payment-method-panel { margin-bottom: var(--s-space-4); }

.payment-method-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--s-text-secondary);
  margin-bottom: var(--s-space-2);
}

.payment-method-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.payment-method-option {
  display: flex;
  align-items: center;
  gap: var(--s-space-3);
  padding: var(--s-space-3) var(--s-space-3);
  background: var(--s-surface);
  border: 1.5px solid var(--s-border);
  border-radius: var(--s-radius);
  cursor: pointer;
  transition: all var(--s-transition);
  text-align: left;
}

.payment-method-option:hover {
  border-color: var(--s-accent-text);
  transform: translateY(-1px);
}

.payment-method-option.active {
  border-color: var(--s-accent-text);
  background: var(--s-accent-glow);
}

.payment-method-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--s-radius);
  background: var(--s-card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--s-accent-text);
  flex-shrink: 0;
}

.payment-method-option strong {
  display: block;
  font-size: 0.85rem;
  color: var(--s-text);
}

.payment-method-option small {
  font-size: 0.73rem;
  color: var(--s-text-muted);
}

/* Bank Transfer */
.bank-transfer-box {
  background: var(--s-surface);
  border-radius: var(--s-radius-md);
  padding: var(--s-space-4);
  margin-top: var(--s-space-4);
  text-align: center;
  border: 1px solid var(--s-border);
}

.bank-transfer-title {
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: var(--s-space-3);
}

.bank-transfer-qr img {
  max-width: 200px;
  border-radius: var(--s-radius);
  margin-bottom: var(--s-space-3);
  box-shadow: var(--s-shadow-sm);
}

.bank-transfer-status {
  font-size: 0.8rem;
  color: var(--s-text-muted);
  margin-bottom: var(--s-space-3);
}

/* Live payment confirmation tones — driven by the server, never by a timer.
   Attribute selectors outrank the base class, so ordering does not matter. */
.bank-transfer-status[data-tone="waiting"] { color: #d97706; }
.bank-transfer-status[data-tone="paid"] { color: #16a34a; font-weight: 600; }
.bank-transfer-status[data-tone="warn"] { color: #d97706; font-weight: 600; }

.bank-transfer-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 0.8rem;
  border-bottom: 1px solid var(--s-border);
}

.bank-transfer-row:last-child { border-bottom: none; }
.bank-transfer-row span { color: var(--s-text-muted); }

/* Order Success */
.order-success-content {
  text-align: center;
  padding: var(--s-space-5) 0;
  animation: fadeInScale 0.4s ease;
}

.order-success-icon {
  display: flex;
  justify-content: center;
  margin-bottom: var(--s-space-3);
  color: #4a5a3f;
}

.order-success-title {
  font-size: 1.2rem;
  font-weight: 800;
  margin-bottom: var(--s-space-2);
}

.order-success-id {
  font-size: 0.85rem;
  color: var(--s-text-secondary);
  margin-bottom: var(--s-space-4);
}

.order-success-note {
  font-size: 0.82rem;
  color: var(--s-text-muted);
  margin-bottom: var(--s-space-5);
}

/* ============================================================
   AUTH MODAL
   ============================================================ */
.auth-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s-space-5);
  animation: fadeIn 0.3s ease;
}

.auth-modal {
  background: var(--s-card);
  border-radius: var(--s-radius-md);
  max-width: 420px;
  width: 100%;
  overflow: hidden;
  box-shadow: var(--s-shadow-xl);
  animation: fadeInScale 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  text-align: center;
  padding: var(--s-space-10) var(--s-space-8) var(--s-space-8);
  border: 1px solid var(--s-border);
}

.auth-modal-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #0f0c09;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto var(--s-space-5);
  box-shadow: 0 8px 24px rgba(15, 12, 9, 0.3);
  animation: breathe 3s ease-in-out infinite;
}

.auth-modal h3 {
  font-size: 1.3rem;
  font-weight: 800;
  margin: 0 0 var(--s-space-2);
  letter-spacing: -0.02em;
}

.auth-modal p {
  font-size: 0.92rem;
  color: var(--s-text-secondary);
  margin: 0;
  line-height: 1.6;
}

.auth-modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: var(--s-space-6);
}

.auth-modal-btn-primary {
  display: block;
  padding: 14px 24px;
  border-radius: var(--s-radius-md);
  background: #0f0c09;
  border: 1px solid #0f0c09;
  color: #f5f2eb;
  font-weight: 700;
  font-size: 1rem;
  text-decoration: none;
  transition: all var(--s-transition);
  box-shadow: 0 4px 16px rgba(15, 12, 9, 0.25);
}

.auth-modal-btn-primary:hover {
  transform: translateY(-2px);
  background: #c19856;
  border-color: #c19856;
  color: #0f0c09;
  box-shadow: 0 4px 16px rgba(15, 12, 9, 0.25);
}

.auth-modal-btn-secondary {
  display: block;
  padding: 14px 24px;
  border-radius: var(--s-radius-md);
  border: 1.5px solid var(--s-border);
  background: var(--s-surface);
  color: var(--s-text);
  font-weight: 600;
  font-size: 0.92rem;
  text-decoration: none;
  transition: all var(--s-transition);
}

.auth-modal-btn-secondary:hover {
  border-color: var(--s-accent-text);
  color: var(--s-accent-text);
  transform: translateY(-1px);
}

.auth-modal-link {
  padding: var(--s-space-2);
  text-align: center;
  color: var(--s-text-muted);
  font-size: 0.82rem;
  text-decoration: none;
}

.auth-modal-link:hover { color: var(--s-text-secondary); }

/* ============================================================
   AI GENERATING OVERLAY
   ============================================================ */
.canvas-viewer.is-generating::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,107,0,0.05) 0%, rgba(255,140,56,0.05) 100%);
  pointer-events: none;
  animation: pulse 2s ease-in-out infinite;
  border-radius: var(--s-radius);
}

/* ============================================================
   FORM GROUP (order modal)
   ============================================================ */
.form-group {
  margin-bottom: var(--s-space-3);
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--s-text-secondary);
  margin-bottom: 5px;
}

.form-input {
  width: 100%;
  padding: 10px var(--s-space-3);
  font-family: 'Be Vietnam Pro', system-ui, sans-serif;
  font-size: 0.85rem;
  color: var(--s-text);
  background: var(--s-surface);
  border: 1.5px solid var(--s-border);
  border-radius: var(--s-radius);
  transition: all var(--s-transition);
  box-sizing: border-box;
}

.form-input:hover {
  border-color: var(--s-border-strong);
  background: var(--s-card);
}

.form-input:focus {
  outline: none;
  border-color: var(--s-accent-text);
  box-shadow: 0 0 0 3px var(--s-accent-glow);
  background: var(--s-card);
}

/* ============================================================
   BUTTONS (from style.css)
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  font-family: 'Be Vietnam Pro', system-ui, sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--s-radius);
  cursor: pointer;
  transition: all var(--s-transition);
  border: none;
  text-decoration: none;
}

.btn:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-primary {
  background: #0f0c09;
  border: 1px solid #0f0c09;
  color: #f5f2eb;
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  background: #c19856;
  border-color: #c19856;
  color: #0f0c09;
  box-shadow: 0 4px 14px rgba(15, 12, 9, 0.25);
}

.btn-secondary {
  background: var(--s-surface);
  color: var(--s-text-secondary);
  border: 1.5px solid var(--s-border);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--s-accent-text);
  color: var(--s-accent-text);
}

.btn-ghost {
  background: transparent;
  color: var(--s-text-secondary);
}

.btn-ghost:hover { color: var(--s-text); }

.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-lg { padding: 14px 28px; font-size: 0.95rem; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1100px) {
  .studio-layout { grid-template-columns: 1fr; }
  .studio-left, .studio-right {
    position: static;
    height: auto;
    border: none;
    overflow: visible;
  }
  .studio-canvas { order: -1; }
  .studio-left { border-bottom: 1px solid var(--s-border); }
  .studio-right { border-top: 1px solid var(--s-border); }
  .canvas-wrapper { min-height: 400px; }
}

@media (max-width: 768px) {
  :root {
    --s-nav-height: 60px;
    --s-toolbar-height: 46px;
  }

  .studio-layout {
    display: flex;
    flex-direction: column;
  }

  /* Canvas 3D pinned at the top — always visible while scrolling panels below */
  .studio-canvas {
    order: -1;
    position: sticky;
    top: calc(var(--s-nav-height) + var(--s-toolbar-height));
    z-index: 5;
    background: var(--s-card);
    flex-shrink: 0;
  }

  .canvas-wrapper {
    min-height: 0;
    height: min(48vh, 460px);
  }

  .studio-left,
  .studio-right {
    position: static;
    height: auto;
    overflow: visible;
    border: none;
    border-top: 1px solid var(--s-border);
  }

  .style-grid { grid-template-columns: repeat(2, 1fr); }
  .community-grid { grid-template-columns: repeat(2, 1fr); }

  .style-chip { min-height: 46px; }
  .panel-section-body { padding: var(--s-space-4) var(--s-space-4) var(--s-space-5); }

  /* Larger touch targets */
  .generate-btn { min-height: 52px; }
  .view-toggle-btn { min-height: 44px; flex: 1; justify-content: center; }
  .view-toggle { width: 100%; }
  .canvas-ctrl-btn { min-height: 44px; min-width: 44px; justify-content: center; }
  .canvas-controls-left { flex: 1; }
  .canvas-controls { padding: 8px var(--s-space-4); }

  /* 16px inputs prevent iOS zoom-on-focus */
  .prompt-input,
  .text-input,
  .placement-panel input[type="number"] {
    font-size: 16px;
  }

  .placement-sliders { grid-template-columns: 1fr; }
}

/* ============================================================
   AI GENERATION PROGRESS OVERLAY
   ============================================================ */
.gen-progress-overlay {
  position: fixed;
  inset: 0;
  z-index: 9500;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(6px);
  animation: fadeIn 0.25s ease;
  padding: var(--s-space-5);
}

.gen-progress-overlay.active { display: flex; }

.gen-progress-card {
  background: var(--s-card);
  border-radius: var(--s-radius-md);
  padding: var(--s-space-8) var(--s-space-8) var(--s-space-6);
  max-width: 420px;
  width: 100%;
  box-shadow: var(--s-shadow-xl);
  border: 1px solid var(--s-border);
  text-align: center;
  animation: fadeInScale 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.gen-progress-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  margin: 0 auto var(--s-space-4);
  background: #0f0c09;
  color: #f5f2eb;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(15, 12, 9, 0.3);
  animation: pulse 1.6s ease-in-out infinite;
}

.gen-progress-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--s-text);
  margin-bottom: var(--s-space-4);
  letter-spacing: -0.01em;
}

.gen-progress-bar {
  height: 10px;
  border-radius: var(--s-radius-full);
  background: var(--s-surface);
  border: 1px solid var(--s-border);
  overflow: hidden;
  margin-bottom: var(--s-space-3);
}

.gen-progress-fill {
  height: 100%;
  width: 100%;
  border-radius: var(--s-radius-full);
  background: #0f0c09;
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.gen-progress-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-space-3);
}

.gen-progress-message {
  font-size: 0.8rem;
  color: var(--s-text-secondary);
  text-align: left;
  flex: 1;
  min-height: 1.2em;
  animation: fadeIn 0.3s ease;
}

.gen-progress-percent {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--s-accent-text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Error state */
.gen-progress-overlay.error .gen-progress-icon {
  background: #a3341f;
  box-shadow: 0 8px 24px rgba(15, 12, 9, 0.25);
  animation: none;
}
.gen-progress-overlay.error .gen-progress-fill {
  background: #a3341f;
  animation: none;
}
.gen-progress-overlay.error .gen-progress-title {
  color: #a3341f;
}

/* Success flash */
.gen-progress-overlay.success .gen-progress-icon {
  background: #4a5a3f;
  box-shadow: 0 8px 24px rgba(15, 12, 9, 0.25);
  animation: none;
}
.gen-progress-overlay.success .gen-progress-fill {
  background: #4a5a3f;
  animation: none;
}

@media (max-width: 480px) {
  .gen-progress-card {
    padding: var(--s-space-6) var(--s-space-5);
  }

  /* No horizontal page overflow on small phones: navbar shrinks, toolbar
     scrolls internally, canvas controls wrap instead of overflowing. */
  .navbar .container { gap: 8px; }
  .navbar-actions { gap: 6px; margin-left: auto; }
  .navbar-actions .btn span[data-i18n="nav.home"] { display: none; }
  .navbar-actions .theme-toggle { display: none; }
  .navbar-actions .btn { padding: 7px 10px; }
  .navbar-actions .lang-toggle span { padding: 5px 8px; }
  .studio-toolbar-inner {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .studio-toolbar-inner::-webkit-scrollbar { display: none; }
  .toolbar-tab { padding: 12px 12px; flex-shrink: 0; }
  .canvas-controls { flex-wrap: wrap; row-gap: 8px; }
  .canvas-controls-right { margin-left: auto; }
}

/* ============================================================
   ONBOARDING OVERLAY
   ============================================================ */
.onboarding-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
}

.onboarding-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
}

.onboarding-tooltip {
  position: absolute;
  background: var(--s-card);
  border-radius: var(--s-radius-md);
  padding: var(--s-space-5);
  max-width: 360px;
  width: calc(100% - 32px);
  box-shadow: var(--s-shadow-xl);
  border: 1px solid var(--s-border);
  z-index: 1;
  animation: fadeInUp 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.onboarding-tooltip-step {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--s-accent-text);
  margin-bottom: var(--s-space-1);
}

.onboarding-tooltip-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--s-text);
  margin-bottom: var(--s-space-2);
  line-height: 1.3;
}

.onboarding-tooltip-desc {
  font-size: 0.85rem;
  color: var(--s-text-secondary);
  line-height: 1.5;
}

.onboarding-tooltip-arrow {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--s-card);
  border: 1px solid var(--s-border);
  transform: rotate(45deg);
  z-index: -1;
}

/* Arrow positions */
.onboarding-arrow-bottom .onboarding-tooltip-arrow {
  top: -6px;
  left: 50%;
  margin-left: -6px;
  border-right: none;
  border-bottom: none;
}
.onboarding-arrow-top .onboarding-tooltip-arrow {
  bottom: -6px;
  left: 50%;
  margin-left: -6px;
  border-left: none;
  border-top: none;
}
.onboarding-arrow-left .onboarding-tooltip-arrow {
  right: -6px;
  top: 50%;
  margin-top: -6px;
  border-left: none;
  border-bottom: none;
}
.onboarding-arrow-right .onboarding-tooltip-arrow {
  left: -6px;
  top: 50%;
  margin-top: -6px;
  border-right: none;
  border-top: none;
}

/* Highlight ring around target */
.onboarding-highlight {
  position: absolute;
  border-radius: var(--s-radius);
  box-shadow: 0 0 0 3px var(--s-accent-text), 0 8px 24px rgba(15, 12, 9, 0.25);
  animation: pulse 2s ease-in-out infinite;
  pointer-events: none;
  z-index: 1;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.onboarding-dots {
  display: flex;
  gap: 6px;
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1;
}

.onboarding-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.3);
  transition: all var(--s-transition);
  cursor: default;
}
.onboarding-dot.active {
  background: var(--s-accent);
  width: 24px;
  border-radius: 4px;
}

.onboarding-actions {
  display: flex;
  gap: 8px;
  position: absolute;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1;
}

.onboarding-btn-skip,
.onboarding-btn-prev,
.onboarding-btn-next {
  padding: 8px 20px;
  font-family: 'Be Vietnam Pro', system-ui, sans-serif;
  font-size: 0.84rem;
  font-weight: 600;
  border-radius: var(--s-radius);
  cursor: pointer;
  transition: all var(--s-transition);
  border: none;
}

.onboarding-btn-skip {
  background: transparent;
  color: rgba(255,255,255,0.7);
}
.onboarding-btn-skip:hover {
  color: #fff;
  background: rgba(255,255,255,0.1);
}

.onboarding-btn-prev {
  background: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.8);
}
.onboarding-btn-prev:hover {
  background: rgba(255,255,255,0.25);
  color: #fff;
}

.onboarding-btn-next {
  background: #0f0c09;
  border: 1px solid #0f0c09;
  color: #f5f2eb;
  box-shadow: 0 4px 14px rgba(15, 12, 9, 0.25);
  min-width: 100px;
}
.onboarding-btn-next:hover {
  transform: translateY(-1px);
  background: #c19856;
  border-color: #c19856;
  color: #0f0c09;
  box-shadow: 0 4px 14px rgba(15, 12, 9, 0.25);
}

@media (max-width: 768px) {
  .onboarding-tooltip {
    max-width: calc(100% - 32px);
    bottom: auto;
  }
  .onboarding-actions {
    gap: 4px;
  }
  .onboarding-btn-skip,
  .onboarding-btn-prev,
  .onboarding-btn-next {
    padding: 6px 12px;
    font-size: 0.78rem;
    min-width: auto;
  }
}

/* ============================================================
   TRIAL BANNER
   ============================================================ */
.trial-banner {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px var(--s-space-5);
  background: linear-gradient(135deg, #f7e4da 0%, #f3d5c3 100%);
  border-bottom: 1px solid rgba(193, 152, 86, 0.2);
  font-size: 0.84rem;
  color: #8a2f0d;
  position: fixed;
  top: var(--s-nav-height);
  left: 0;
  right: 0;
  z-index: 99;
  flex-wrap: wrap;
}
[data-theme="dark"] .trial-banner {
  background: linear-gradient(135deg, #2d1b00 0%, #3d2600 100%);
  color: #ffb366;
  border-bottom-color: rgba(193, 152, 86, 0.15);
}

.trial-banner.active { display: flex; }

.trial-banner svg { flex-shrink: 0; color: #7d5f2c; }
[data-theme="dark"] .trial-banner svg { color: #d5b178; }

.trial-banner-cta {
  margin-left: auto;
  padding: 5px 14px;
  background: #0f0c09;
  border: 1px solid #0f0c09;
  color: #f5f2eb;
  border-radius: var(--s-radius-full);
  font-weight: 700;
  font-size: 0.78rem;
  text-decoration: none;
  white-space: nowrap;
  transition: transform var(--s-transition), background var(--s-transition), color var(--s-transition), box-shadow var(--s-transition);
  box-shadow: 0 2px 8px rgba(15, 12, 9, 0.25);
}
.trial-banner-cta:hover {
  transform: translateY(-1px);
  background: #c19856;
  border-color: #c19856;
  color: #0f0c09;
  box-shadow: 0 4px 12px rgba(15, 12, 9, 0.25);
}

/* ============================================================
   WATERMARK OVERLAY (trial mode)
   ============================================================ */
.watermark-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 10;
  opacity: 0.35;
}
.watermark-overlay svg {
  width: 200px;
  height: 200px;
  color: var(--s-text-muted);
  opacity: 0.25;
}

/* Shift studio-main down when trial banner is active */
html[data-trial="true"] .studio-main {
  padding-top: calc(var(--s-nav-height) + 48px);
}
html[data-trial="true"] .studio-toolbar {
  top: calc(var(--s-nav-height) + 48px);
}
html[data-trial="true"] .studio-left,
html[data-trial="true"] .studio-right {
  top: calc(var(--s-nav-height) + var(--s-toolbar-height) + 48px);
  height: calc(100vh - var(--s-nav-height) - var(--s-toolbar-height) - 48px);
}
@media (max-width: 768px) {
  html[data-trial="true"] .studio-canvas {
    top: calc(var(--s-nav-height) + var(--s-toolbar-height) + 48px);
  }
}

/* ============================================================
   PRINT PREVIEW (In / Lưu PDF)
   ============================================================ */
.print-preview-overlay {
  z-index: 2500;
  overflow-y: auto;
  background: rgba(10, 10, 16, 0.7);
  backdrop-filter: blur(6px);
}

.print-preview-overlay.active { display: flex; }

.print-preview-panel {
  margin: auto;
  width: min(920px, calc(100vw - 48px));
  padding: 18px;
  background: var(--s-bg);
  border: 1px solid var(--s-border);
  border-radius: var(--s-radius-lg);
  box-shadow: var(--s-shadow-xl);
}

.print-preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--s-text);
}

.print-preview-toolbar-actions {
  display: flex;
  gap: 8px;
}

.print-sheet {
  background: #ffffff;
  color: #17140f;
  border-radius: var(--s-radius);
  padding: 28px 32px;
  font-family: 'Be Vietnam Pro', system-ui, sans-serif;
}

.print-sheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 2px solid #17140f;
  padding-bottom: 14px;
  margin-bottom: 18px;
}

.print-sheet-brand { display: flex; flex-direction: column; gap: 4px; }

.print-sheet-logo {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 1px;
  color: #17140f;
}

.print-sheet-logo span { color: var(--s-accent-text); }

.print-sheet-doc {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 2px;
  color: #6b7280;
  line-height: 1.5;
  text-transform: uppercase;
}

.print-sheet-doc span { font-weight: 500; }

.print-sheet-date {
  font-size: 0.72rem;
  color: #6b7280;
  text-align: right;
}

.print-sheet-body {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 24px;
}

.print-sheet-col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

.print-mockup-box {
  border: 1px solid #e5e0d8;
  border-radius: 10px;
  padding: 8px;
  background: #faf9f7;
  position: relative;
  text-align: center;
}

.print-mockup-box img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
}

.print-mockup-caption {
  position: absolute;
  top: 12px;
  left: 12px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 1px;
  background: rgba(23, 20, 15, 0.8);
  color: #fff;
  padding: 3px 8px;
  border-radius: 4px;
}

.print-sheet-note {
  font-size: 0.75rem;
  line-height: 1.6;
  color: #6b7280;
}

.print-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.print-table td {
  padding: 9px 10px;
  border-bottom: 1px solid #e5e7d8;
  vertical-align: middle;
}

.print-table td:first-child {
  font-weight: 700;
  color: #6b7280;
  width: 42%;
  letter-spacing: 0.3px;
}

.print-table td:last-child {
  font-weight: 800;
  text-align: right;
  color: #17140f;
}

.print-total-row td {
  border-top: 2px solid #17140f;
  border-bottom: none;
  font-size: 0.9rem;
}

.print-total-row td:last-child { color: var(--s-accent-text); }

.print-sheet-thumb {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
}

.print-sheet-thumb img {
  width: 100%;
  height: auto;
  border: 1px solid #e5e7d8;
  border-radius: 10px;
  background: #faf9f7;
}

.print-sheet-thumb-caption {
  font-size: 0.72rem;
  font-weight: 700;
  color: #6b7280;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.print-sheet-footer {
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid #e5e7d8;
  text-align: center;
  font-size: 0.72rem;
  color: #6b7280;
}

@media (max-width: 640px) {
  .print-sheet-body { grid-template-columns: 1fr; }
  .print-preview-panel { width: min(92vw, 480px); }
}

@media print {
  body.print-preview-open .print-preview-overlay {
    position: static !important;
    display: block !important;
    background: none;
    backdrop-filter: none;
    padding: 0;
  }
  body.print-preview-open .print-preview-toolbar { display: none; }
  body.print-preview-open .print-preview-panel {
    width: 100%;
    padding: 0;
    border: none;
    box-shadow: none;
    background: none;
  }
  .print-sheet {
    border-radius: 0;
    padding: 12mm;
  }
}

/* ============================================================
   STUDIO CINEMATIC LAYER (v5) — Cinematic Fashion Design Workspace.
   Logic untouched: every control keeps its id/class/handler.
   ============================================================ */

/* Editorial panel voice */
.studio-left .panel-section-header,
.studio-right .panel-section-header,
.placement-panel-header {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--s-accent-text);
}
.studio-toolbar {
  background: rgba(245, 242, 235, 0.9);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(15, 12, 9, 0.12);
}
.toolbar-tab {
  font-family: var(--font-mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 0.72rem;
}
.toolbar-tab.active {
  color: var(--s-accent-text);
  border-color: var(--s-accent-text);
}

/* Generate: ink monument button */
.generate-btn {
  background: #0f0c09;
  border: 1px solid #0f0c09;
  border-radius: 2px;
  font-family: var(--font-mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.generate-btn:hover:not(:disabled) {
  background: #c19856;
  border-color: #c19856;
  color: #0f0c09;
  box-shadow: 0 6px 20px rgba(193, 152, 86, 0.4);
}

/* Style chips: hairline, gold active */
.style-chip {
  border: 1px solid rgba(15, 12, 9, 0.18);
  border-radius: 2px;
  transition: border-color 0.3s, transform 0.3s, background 0.3s;
}
.style-chip:hover { transform: translateY(-2px); border-color: #0f0c09; }
.style-chip.active {
  border-color: #c19856;
  background: rgba(193, 152, 86, 0.1);
  box-shadow: inset 0 0 0 1px #c19856;
}

/* Prompt input: underline instrument */
.text-input,
#promptInput {
  border: none;
  border-bottom: 1px solid rgba(15, 12, 9, 0.3);
  border-radius: 0;
  background: transparent;
}
.text-input:focus,
#promptInput:focus {
  border-color: #c19856;
  box-shadow: none;
}

/* Segmented controls: front/back, product type */
.product-type-btn,
.placement-preset-btn,
.view-toggle-btn {
  border: 1px solid rgba(15, 12, 9, 0.2);
  border-radius: 2px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transition: all 0.3s;
}
.product-type-btn.active,
.placement-preset-btn.active,
.view-toggle-btn.active {
  background: #0f0c09;
  color: #f5f2eb;
  border-color: #0f0c09;
}

/* Layer management: ledger rows */
.layer-row {
  border: 1px solid rgba(15, 12, 9, 0.14);
  border-radius: 2px;
  background: #fffdf8;
  transition: border-color 0.3s, transform 0.3s;
}
.layer-row:hover { transform: translateX(3px); }
.layer-row.selected {
  border-color: #c19856;
  box-shadow: inset 2px 0 0 #c19856;
}
.layer-name { font-weight: 600; }
.layer-meta { font-family: var(--font-mono); }
.layer-btn {
  border: 1px solid rgba(15, 12, 9, 0.18);
  border-radius: 2px;
}
.layer-btn:hover { border-color: #0f0c09; }
.layer-btn.layer-del:hover { border-color: #a3341f; color: #a3341f; }
.layer-empty {
  border: 1px dashed rgba(15, 12, 9, 0.3);
  border-radius: 2px;
}

/* Sliders: gold accent */
.placement-panel input[type="range"] { accent-color: #a37c3a; }

/* Action buttons */
.action-btn {
  border: 1px solid rgba(15, 12, 9, 0.25);
  border-radius: 2px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transition: all 0.3s;
}
.action-btn:hover:not(:disabled) { border-color: #0f0c09; transform: translateY(-1px); }
.action-btn-primary {
  background: #0f0c09;
  border-color: #0f0c09;
  color: #f5f2eb;
}
.action-btn-primary:hover:not(:disabled) {
  background: #c19856;
  border-color: #c19856;
  color: #0f0c09;
}

/* Viewer stage: framed atelier canvas */
.studio-canvas,
.viewer-canvas {
  background:
    radial-gradient(circle at 50% 0%, rgba(193, 152, 86, 0.1), transparent 55%),
    #ece4d3;
  border: 1px solid rgba(15, 12, 9, 0.14);
}
.viewer-side-badge {
  font-family: var(--font-mono);
  letter-spacing: 0.16em;
  background: #0f0c09;
  color: #f5f2eb;
  border-radius: 2px;
}

/* Community: curated collection cards */
.community-header h2,
.community-header h3 {
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.community-card {
  border: 1px solid rgba(15, 12, 9, 0.14);
  border-radius: 2px;
  overflow: hidden;
  background: #fffdf8;
  transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.6s;
}
.community-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 24px 60px rgba(15, 12, 9, 0.14);
}
.community-card-img { transition: transform 1.1s cubic-bezier(0.16, 1, 0.3, 1); }
.community-card:hover .community-card-img { transform: scale(1.06); }
.community-card-prompt {
  font-family: 'Playfair Display', Georgia, serif;
  font-style: italic;
}
.community-card-author { color: var(--s-accent-text); }

/* History */
.history-item {
  border: 1px solid rgba(15, 12, 9, 0.12);
  border-radius: 2px;
}
.history-item:hover { border-color: #c19856; }

/* Modals (order/share/preview): gold rule */
.modal-content {
  border-radius: 3px;
  border-top: 3px solid #c19856;
}
.modal-content h2,
.modal-content h3 {
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 500;
}

/* Toast stays readable over the workspace */
#toast-container { z-index: 2200; }

@media (prefers-reduced-motion: reduce) {
  .style-chip, .action-btn, .layer-row, .community-card,
  .community-card-img, .generate-btn { transition: none !important; }
}

/* ---------- Generation result choreography (one-shot, state-driven) ---------- */
.result-fresh #mockupDesign,
.result-fresh .viewer-design-overlay {
  animation: resultIn 0.7s cubic-bezier(0.16, 1, 0.3, 1);
  will-change: filter, opacity;
}
@keyframes resultIn {
  from { filter: blur(12px); opacity: 0.35; }
  to { filter: blur(0); opacity: 1; }
}
.actions-fresh .action-btn {
  animation: actionIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}
.actions-fresh .action-btn:nth-child(1) { animation-delay: 0ms; }
.actions-fresh .action-btn:nth-child(2) { animation-delay: 50ms; }
.actions-fresh .action-btn:nth-child(3) { animation-delay: 100ms; }
.actions-fresh .action-btn:nth-child(4) { animation-delay: 150ms; }
.actions-fresh .action-btn:nth-child(n+5) { animation-delay: 200ms; }
@keyframes actionIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .result-fresh #mockupDesign,
  .result-fresh .viewer-design-overlay,
  .actions-fresh .action-btn { animation: none !important; }
}

/* ---------- Harden: keyboard focus must stay visible on custom sliders ---------- */
.placement-slider-group input[type="range"]:focus-visible {
  outline: 2px solid #c19856;
  outline-offset: 4px;
}
.placement-slider-group input[type="range"]::-moz-range-thumb {
  border: 2px solid transparent;
}
.placement-slider-group input[type="range"]:focus-visible::-moz-range-thumb {
  border-color: #c19856;
}

/* ---------- P0 contrast fix (audit): white-on-gold fails AA.
   Ink carries the CTA (paper text, ~16:1); gold speaks on hover. ---------- */
.btn-primary,
.auth-modal-btn-primary,
.trial-banner-cta {
  background: #0f0c09;
  border-color: #0f0c09;
  color: #f5f2eb;
}
.btn-primary:hover:not(:disabled),
.auth-modal-btn-primary:hover,
.trial-banner-cta:hover {
  background: #c19856;
  border-color: #c19856;
  color: #0f0c09;
}
.gen-progress-icon {
  background: #0f0c09;
  color: #f5f2eb;
}

/* ============================================================
   HARDEN (production-ready): errors, i18n, edge cases
   Preserves the committed world: warm paper, ink CTAs, gold
   accents, mono-for-process, near-square corners, flat-by-default.
   ============================================================ */

/* Text overflow & wrapping — long VI/DE/CJK/emoji must not break layout */
.history-item-info,
.layer-info,
.community-card-info,
.order-summary-row,
.gen-progress-bottom,
.placement-panel-header,
.community-card-meta { min-width: 0; }

.prompt-input,
.text-input,
.form-input,
.community-card-prompt,
.history-item-prompt,
.layer-name,
.layer-meta,
.order-summary-row .value,
.print-table td,
.bank-transfer-row strong,
.back-design-status,
.upload-zone-text {
  overflow-wrap: break-word;
  word-break: break-word;
  hyphens: auto;
}

.community-card-prompt,
.history-item-prompt,
.layer-name,
.order-summary-row .value {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.order-summary-row .value,
.print-table td:last-child,
.bank-transfer-row strong {
  min-width: 0;
  max-width: 60%;
}

/* Slogan overlay: single elegant line with ellipsis, never overflows mockup */
.viewer-design-overlay .mockup-print-text {
  max-width: min(46vw, 320px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* i18n expansion: 30-40% budget, no fixed text widths, wrap gracefully */
.toolbar-tab,
.style-chip,
.product-type-btn,
.placement-preset-btn,
.prompt-suggestion-chip,
.action-btn,
.generate-btn {
  min-width: 0;
  max-width: 100%;
}

.prompt-suggestion-chip {
  white-space: normal;
  text-align: start;
  line-height: 1.4;
}

.toolbar-tab span,
.style-chip span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Logical properties baseline for future RTL (dir="rtl") */
.studio-layout,
.studio-left,
.studio-right,
.panel-section-body,
.placement-panel { text-align: start; }

[dir="rtl"] .toolbar-tab svg,
[dir="rtl"] .canvas-ctrl-btn svg,
[dir="rtl"] .view-toggle-btn svg { transform: scaleX(-1); }

[dir="rtl"] .history-item:hover,
[dir="rtl"] .layer-row:hover { transform: translateX(-3px); }

/* Field meta / counters / inline errors (mono-for-process) */
.field-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-top: -2px;
}

.field-hint {
  font-size: 0.75rem;
  color: var(--s-text-muted);
  line-height: 1.5;
}

.field-count {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  color: var(--s-text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.field-error {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.5;
  color: #a3341f;
  background: rgba(193, 152, 86, 0.14);
  border: 1px solid rgba(163, 52, 31, 0.35);
  border-radius: 2px;
  padding: 8px 12px;
  margin: 8px 0 0;
  overflow-wrap: break-word;
}

.field-error[hidden] { display: none; }

.form-input[aria-invalid="true"],
.prompt-input[aria-invalid="true"],
.text-input[aria-invalid="true"] {
  border-color: #a3341f;
  box-shadow: 0 0 0 3px rgba(163, 52, 31, 0.12);
}

/* Price / qty: tabular numerals prevent layout shift on large VND totals */
.price-value,
.qty-value,
.gen-progress-percent,
#orderTotal,
#psTotal {
  font-variant-numeric: tabular-nums;
}

.price-value {
  overflow-wrap: normal;
  word-break: normal;
}

/* Community states: loading skeleton, empty, error (flat-by-default) */
.community-state {
  margin-top: 16px;
  border: 1px dashed rgba(15, 12, 9, 0.3);
  border-radius: 2px;
  background: #fffdf8;
  padding: 20px;
  text-align: center;
}

.community-state[hidden] { display: none; }

.community-state .field-hint { display: block; margin-top: 12px; }

.skeleton-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.skeleton-row span {
  display: block;
  aspect-ratio: 1;
  border-radius: 2px;
  background: linear-gradient(100deg, #ece4d3 30%, #f5f2eb 50%, #ece4d3 70%);
  background-size: 200% 100%;
  animation: skeletonShimmer 1.4s ease infinite;
}

.community-retry-btn {
  margin-top: 12px;
  padding: 10px 20px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #f5f2eb;
  background: #0f0c09;
  border: 1px solid #0f0c09;
  border-radius: 2px;
  cursor: pointer;
}

.community-retry-btn:hover {
  background: #c19856;
  border-color: #c19856;
  color: #0f0c09;
}

/* Templates empty state inherits ledger-row voice */
.templates-grid .layer-empty { grid-column: 1 / -1; }

@keyframes skeletonShimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* High-contrast / forced-colors: never rely on color alone */
@media (forced-colors: active) {
  .style-chip.active,
  .product-type-btn.active,
  .size-btn.active,
  .color-dot.active,
  .placement-preset-btn.active,
  .view-toggle-btn.active {
    outline: 2px solid Highlight;
    outline-offset: 1px;
  }

  .field-error { border: 2px solid Mark; }
}

/* Reduced-motion: hardening animations obey the floor */
@media (prefers-reduced-motion: reduce) {
  .skeleton-row span { animation: none; }
}

/* Keyboard focus: 2px gold ring on every interactive (DESIGN.md) */
.toolbar-tab:focus-visible,
.style-chip:focus-visible,
.product-type-btn:focus-visible,
.placement-preset-btn:focus-visible,
.prompt-suggestion-chip:focus-visible,
.action-btn:focus-visible,
.generate-btn:focus-visible,
.view-toggle-btn:focus-visible,
.canvas-ctrl-btn:focus-visible,
.color-dot:focus-visible,
.size-btn:focus-visible,
.qty-btn:focus-visible,
.payment-method-option:focus-visible,
.community-retry-btn:focus-visible,
.community-card-img-wrap:focus-visible,
.history-item:focus-visible,
.layer-row:focus-visible,
.btn:focus-visible,
.modal-close:focus-visible,
.upload-zone:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 2px solid #c19856;
  outline-offset: 2px;
}

/* Deferred images: no broken boxes, no layout shift */
.viewer-fallback-img,
.print-mockup-box img,
.print-sheet-thumb img,
.bank-transfer-qr img,
.upload-preview img {
  background: #ece4d3;
}

.viewer-fallback-img:not([src]),
.print-mockup-box img:not([src]),
.print-sheet-thumb img:not([src]),
.bank-transfer-qr img:not([src]),
.upload-preview img:not([src]) {
  visibility: hidden;
}

.print-mockup-box img[src=""],
.print-sheet-thumb img[src=""],
.bank-transfer-qr img[src=""] {
  visibility: hidden;
}

/* ============================================================
   ADAPT (Desktop → Mobile rethink) — studio single-column,
   thumb-first, touch-native. Preserves committed world:
   warm paper, ink CTAs, gold accent, mono-for-process.
   ============================================================ */

/* Safe areas + no horizontal overflow (notch, home indicator) */
html, body { overflow-x: clip; }
body {
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
}
.studio-main { overflow-x: clip; }

/* Touch: kill 300ms delay, keep vertical scroll on canvas */
button, .toolbar-tab, .style-chip, .action-btn, .color-dot,
.size-btn, .qty-btn, .placement-preset-btn, .product-type-btn {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.canvas-wrapper { touch-action: pan-y; }

/* Input method, not just screen size: coarse pointers get room */
@media (pointer: coarse) {
  .style-chip, .product-type-btn, .size-btn,
  .placement-preset-btn, .view-toggle-btn {
    min-height: 44px;
  }
  .color-dot { width: 44px; height: 44px; }
  .qty-btn { width: 48px; height: 48px; }
  .qty-value { line-height: 48px; min-width: 52px; }
  .toolbar-tab { min-height: 48px; }
  .canvas-ctrl-btn { min-height: 44px; min-width: 44px; }
  .action-btn { min-height: 48px; }
}

/* No hover on touch: hover lifts become active feedback only */
@media (hover: none) {
  .style-chip:hover, .product-type-btn:hover, .size-btn:hover,
  .action-btn:hover:not(:disabled), .color-dot:hover,
  .community-card:hover, .layer-row:hover {
    transform: none;
    box-shadow: none;
  }
  .style-chip:active, .product-type-btn:active, .size-btn:active,
  .action-btn:active:not(:disabled) {
    transform: scale(0.98);
  }
  .community-card:hover .community-card-img { transform: none; }
}
/* Fine pointers keep the atelier lift */
@media (hover: hover) and (pointer: fine) {
  .style-chip:hover { transform: translateY(-2px); }
  .action-btn:hover:not(:disabled) { transform: translateY(-1px); }
}

/* (slider mobile styling đã gộp vào block ATELIER CONTROL cuối file) */

/* Progressive disclosure on mobile: suggestions become a
   horizontal swipe row instead of a tall wrapping wall */
@media (max-width: 768px) {
  .prompt-suggestions {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 6px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .prompt-suggestions::-webkit-scrollbar { display: none; }
  .prompt-suggestion-chip {
    flex: 0 0 auto;
    scroll-snap-align: start;
    min-height: 44px;
    max-width: 220px;
  }
  .product-type-row, .size-row {
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .product-type-row::-webkit-scrollbar,
  .size-row::-webkit-scrollbar { display: none; }
  .product-type-btn, .size-btn { flex: 0 0 auto; min-width: 64px; }

  /* Thumb-zone: order actions stick to bottom within thumb reach */
  .studio-right .actions-section {
    position: sticky;
    bottom: 0;
    z-index: 20;
    background: var(--s-card);
    border-top: 1px solid var(--s-border);
    padding-bottom: max(16px, env(safe-area-inset-bottom, 0));
    margin: 0 calc(var(--s-space-5) * -1);
    padding-left: var(--s-space-5);
    padding-right: var(--s-space-5);
  }
  #orderBtn { min-height: 52px; }

  /* Order dialog becomes a bottom sheet, not a centered modal */
  #orderModal .modal,
  #printPreviewModal .print-preview-panel {
    width: 100%;
    max-width: 100%;
    margin: auto 0 0;
    border-radius: 4px 4px 0 0;
    max-height: 92dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  #orderModal.modal-overlay.active,
  #printPreviewModal.print-preview-overlay.active {
    align-items: flex-end;
    padding: 0;
  }
  .payment-method-options { grid-template-columns: 1fr; }

  /* Toolbar: snap between Prompt / Image / Templates */
  .studio-toolbar-inner { scroll-snap-type: x proximity; }
  .toolbar-tab { scroll-snap-align: start; }
}

/* Small phones: canvas yields to controls, community stays 2-up */
@media (max-width: 480px) {
  .canvas-wrapper {
    height: min(42vh, 380px);
    min-height: 280px;
  }
  .community-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .studio-left, .studio-right { padding-bottom: max(12px, env(safe-area-inset-bottom, 0)); }
}

/* Landscape phones: sticky canvas must not swallow the viewport */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .studio-canvas { position: static; }
  .canvas-wrapper { height: 72vh; min-height: 260px; }
  .studio-right .actions-section { position: static; }
}

/* ============================================================
   VIEWER OVERLAY — 2 chế độ hiển thị:
   • Fallback 2D (không có .has-real-3d): overlay cần kích thước thật
     để layer preview hiển thị trên khung áo.
   • Real 3D (.has-real-3d): thiết kế hiển thị qua DECAL trên áo — overlay
     2D phải ẩn (opacity 0) để KHÔNG thành ảnh thứ 2 trôi cạnh áo.
   ============================================================ */
.canvas-viewer:not(.has-real-3d) .viewer-design-overlay {
  width: 46%;
  aspect-ratio: 1;
  max-width: 460px;
}
.canvas-viewer.has-real-3d .viewer-design-overlay .mockup-print-design,
.canvas-viewer.has-real-3d .viewer-design-overlay .mockup-print-text {
  /* P0 FIX (double text): opacity 0 phải thắng INLINE style của node chữ
     (renderTextMarkup gắn opacity:${textOp} trực tiếp) — nếu không, chữ DOM
     hiển thị đè lên decal 3D => user thấy 2 bản chữ (1 DOM + 1 trên áo).
     Ảnh không lỗi vì node ảnh không có inline opacity. */
  opacity: 0 !important;
  /* QUAN TRỌNG: bắt buộc pointer-events:none — chỉ ẩn bằng opacity là element
     vẫn NGHIẾT chuột, chặn pointerdown xuống canvas drag handler (kéo ảnh/chữ
     "chết" thoạt nhìn, thật ra event bị node vô hình nuốt mất). */
  pointer-events: none !important;
}
/* ĐANG KÉO LAYER: preview 2D hiện lại ngay (bám con trỏ 1:1) thay thế decal
   3D tạm thời — kéo tới đâu ảnh theo tới đó. Thả chuột: decal mới đã dựng
   xong (atomic swap) rồi preview mới tắt → không nháy. */
.canvas-viewer.is-layer-dragging.has-real-3d .viewer-design-overlay .mockup-print-design,
.canvas-viewer.is-layer-dragging.has-real-3d .viewer-design-overlay .mockup-print-text {
  opacity: 0.85;
  pointer-events: none;
}
.canvas-viewer.is-layer-dragging .viewer-design-overlay .mockup-print-design {
  outline: 2px dashed color-mix(in srgb, var(--s-accent, #ff6b00) 70%, transparent);
  outline-offset: 4px;
}

/* ============================================================
   STICKER PICKER — chi tiết tùy ý trên áo
   ============================================================ */
.sticker-picker {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  margin: 8px 0 4px;
}
.sticker-chip {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  font-size: 18px;
  line-height: 1;
  padding: 0;
  border: 1px solid var(--s-border);
  border-radius: 10px;
  background: var(--s-card);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.sticker-chip:hover {
  transform: translateY(-2px) scale(1.08);
  border-color: var(--s-accent);
  box-shadow: 0 3px 10px rgba(15, 12, 9, 0.12);
  z-index: 1;
}
.sticker-chip:active { transform: scale(0.92); }
.sticker-hint {
  font-size: 0.72rem;
  color: var(--s-text-muted);
  margin: 2px 0 0;
  line-height: 1.45;
}

/* ============================================================
   ATELIER CONTROL — thanh điều chỉnh bản in kiểu xưởng in đắt tiền.
   Mỗi control 1 thẻ riêng · label mono giãn rộng · chip giá trị vàng ·
   track gold phát sáng · thumb kim loại đánh bóng. (thay SLIDER POLISH cũ)
   ============================================================ */
.placement-sliders {
  gap: 10px;
}
.placement-slider-group {
  gap: 7px;
  background: var(--s-card);
  border: 1px solid var(--s-border);
  border-radius: 10px;
  padding: 9px 12px 11px;
  box-shadow: 0 1px 2px rgba(15, 12, 9, 0.04), 0 3px 10px -6px rgba(15, 12, 9, 0.12);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.placement-slider-group:hover {
  border-color: var(--s-border-accent);
  box-shadow: 0 1px 2px rgba(15, 12, 9, 0.05), 0 6px 16px -8px rgba(193, 152, 86, 0.35);
}
.placement-slider-group:focus-within {
  border-color: var(--s-border-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--s-accent) 14%, transparent);
}

.placement-slider-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.placement-slider-top label {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--s-text-muted);
}
.slider-value {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
  color: var(--s-accent-text);
  background: var(--s-accent-light);
  border: 1px solid color-mix(in srgb, var(--s-accent) 26%, transparent);
  border-radius: 999px;
  padding: 1px 8px;
  min-width: 40px;
  text-align: center;
  line-height: 1.5;
}

/* Track: vẽ bằng background của chính input (độ tin cậy cao nhất trên cả
   WebKit + Gecko) — gold metallic dẫn từ trái, tỏa từ tâm với .center-origin. */
.placement-slider-group input[type="range"] {
  width: 100%;
  height: 18px;
  -webkit-appearance: none;
  appearance: none;
  background:
    linear-gradient(to right,
      var(--s-accent) 0%,
      var(--s-accent) var(--fill, 0%),
      var(--s-border-strong) var(--fill, 0%),
      var(--s-border-strong) 100%) no-repeat 0 50% / 100% 4px;
  border-radius: 999px;
  outline: none;
  cursor: pointer;
  transition: none;
}
.placement-slider-group input[type="range"].center-origin {
  background:
    linear-gradient(var(--s-border-strong), var(--s-border-strong)) no-repeat 50% 50% / 2px 10px,
    linear-gradient(to right,
      transparent 0%,
      transparent calc(50% - var(--off, 0%)),
      var(--s-accent) calc(50% - var(--off, 0%)),
      var(--s-accent) calc(50% + var(--off, 0%)),
      transparent calc(50% + var(--off, 0%)),
      transparent 100%) no-repeat 0 50% / 100% 4px;
}
.placement-slider-group input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: var(--s-border-strong);
}
.placement-slider-group input[type="range"]::-moz-range-progress {
  height: 4px;
  border-radius: 999px;
  background: var(--s-accent);
}
.placement-slider-group input[type="range"].center-origin::-moz-range-progress { background: transparent; }
.placement-slider-group input[type="range"].center-origin::-moz-range-track {
  background:
    linear-gradient(var(--s-border-strong), var(--s-border-strong)) no-repeat 50% 50% / 2px 10px,
    linear-gradient(to right,
      transparent 0%,
      transparent calc(50% - var(--off, 0%)),
      var(--s-accent) calc(50% - var(--off, 0%)),
      var(--s-accent) calc(50% + var(--off, 0%)),
      transparent calc(50% + var(--off, 0%)),
      transparent 100%) no-repeat 0 50% / 100% 4px;
}

/* Thumb: đĩa kim loại gold đánh bóng, viền ink — sang và rõ */
.placement-slider-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: conic-gradient(from 210deg, #eed9a9, #b98f47 28%, #f4e3b8 52%, #a87f42 74%, #eed9a9);
  border: 2px solid rgba(15, 12, 9, 0.88);
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.65),
    0 1px 3px rgba(15, 12, 9, 0.4),
    0 0 0 0 color-mix(in srgb, var(--s-accent) 0%, transparent);
  transition: transform 0.14s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.14s ease;
  margin-top: 0; /* center giữa track 4px */
}
.placement-slider-group input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.12); }
.placement-slider-group input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.2);
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.65),
    0 1px 3px rgba(15, 12, 9, 0.4),
    0 0 0 5px color-mix(in srgb, var(--s-accent) 20%, transparent);
}
.placement-slider-group input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: conic-gradient(from 210deg, #eed9a9, #b98f47 28%, #f4e3b8 52%, #a87f42 74%, #eed9a9);
  border: 2px solid rgba(15, 12, 9, 0.88);
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.65), 0 1px 3px rgba(15, 12, 9, 0.4);
  cursor: pointer;
}

/* Reset: nút con dấu nhỏ — ink trên paper, luôn nhìn thấy */
.placement-reset-btn {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--s-text);
  background: transparent;
  border: 1px solid var(--s-border-strong);
  border-radius: 999px;
  padding: 4px 13px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.placement-reset-btn:hover {
  background: var(--s-text);
  border-color: var(--s-text);
  color: var(--s-text-inverse);
}
.placement-reset-btn:active { transform: scale(0.96); }

/* Coarse pointer: vùng bấm dày hơn — thumb/track to hơn, KHÔNG track thành viên thuốc */
@media (pointer: coarse) {
  .placement-slider-group input[type="range"] { height: 28px; }
  .placement-slider-group input[type="range"] {
    background-size: 100% 5px;
  }
  .placement-slider-group input[type="range"].center-origin {
    background-size: 2px 12px, 100% 5px;
  }
  .placement-slider-group input[type="range"]::-webkit-slider-thumb { width: 22px; height: 22px; }
  .placement-slider-group input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  .placement-slider-group,
  .placement-slider-group input[type="range"],
  .placement-slider-group input[type="range"]::-webkit-slider-thumb,
  .placement-reset-btn { transition: none; }
}

/* Layer list — hover + selected rõ hơn, mượt hơn */
.layer-row {
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.layer-row:hover {
  border-color: var(--s-accent);
  transform: translateX(2px);
}
.layer-row.selected {
  border-color: var(--s-accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--s-accent) 22%, transparent);
}
.layer-row .layer-btn {
  transition: background 0.12s ease, transform 0.12s ease;
}
.layer-row .layer-btn:hover { transform: scale(1.12); }

@media (prefers-reduced-motion: reduce) {
  .sticker-chip, .layer-row, .layer-row .layer-btn,
  .placement-slider-group input[type="range"],
  .placement-slider-group input[type="range"]::-webkit-slider-thumb { transition: none; }
}

/* ============================================================
   DRAG PREVIEW — ảnh clone bám con trỏ khi kéo layer (screen-space,
   fixed). Tạo bằng JS, gỡ sau atomic swap → kéo tới đâu THẤY tới đó.
   ============================================================ */
.studio-drag-preview {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.92;
  filter: drop-shadow(0 4px 14px rgba(15, 12, 9, 0.35));
  /* KHÔNG có translate(-50%,-50%) — left/top đã là góc trên-trái của ảnh thật
     (đo bằng getBoundingClientRect). Có translate làm tâm preview dồn về góc
     trái-trên → ảnh “nhảy” lên góc trên trái của con trỏ lúc bắt đầu kéo. */
  will-change: left, top;
}

/* ============================================================
   TEXT STYLE CONTROLS — "Atelier Type Case"
   Ngôn ngữ thiết kế khớp placement sliders: thẻ porcelain, label
   mono giãn rộng, chip giá trị gold. Mọi tương tác dùng transform
   (không layout-thrash) — mượt theo tiêu chí thương hiệu.
   ============================================================ */
.text-style-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  margin-top: 6px;
  background: var(--s-card);
  border: 1px solid var(--s-border);
  border-radius: 10px;
}
.text-style-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
}
.text-style-row-slider { gap: 10px; }
.text-style-label {
  flex: 0 0 auto;
  min-width: 44px;
  font-family: var(--s-font-mono, var(--font-mono));
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--s-text-muted);
}
.text-style-select-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}
.text-style-select {
  width: 100%;
  height: 32px;
  padding: 0 26px 0 10px;
  font-family: var(--s-font-mono, var(--font-mono));
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--s-text);
  background: var(--s-surface);
  border: 1px solid var(--s-border);
  border-radius: 8px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.16s var(--s-ease, ease), box-shadow 0.16s var(--s-ease, ease);
}
.text-style-select:hover { border-color: var(--s-accent); }
.text-style-select:focus-visible {
  outline: none;
  border-color: var(--s-accent);
  box-shadow: 0 0 0 3px var(--s-accent-glow, rgba(163, 124, 58, 0.18));
}
.text-style-select-wrap::after {
  content: '';
  position: absolute;
  right: 11px; top: 50%;
  width: 6px; height: 6px;
  border-right: 1.5px solid var(--s-text-muted);
  border-bottom: 1.5px solid var(--s-text-muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
/* Case buttons — AA / aa / Aa / A|a */
.text-case-group {
  display: flex;
  flex: 1 1 auto;
  background: var(--s-surface);
  border: 1px solid var(--s-border);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}
.text-case-btn {
  flex: 1 1 0;
  min-width: 0;
  height: 26px;
  font-family: Georgia, serif;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--s-text-muted);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s var(--s-ease, ease), color 0.15s var(--s-ease, ease), box-shadow 0.15s var(--s-ease, ease);
}
.text-case-btn:hover { color: var(--s-text); background: var(--s-accent-soft, rgba(163, 124, 58, 0.1)); }
.text-case-btn.active {
  color: var(--s-accent-text, #7d5f2c);
  background: var(--s-card);
  box-shadow: inset 0 0 0 1px var(--s-accent), 0 1px 3px rgba(15, 12, 9, 0.12);
}
[data-theme="dark"] .text-case-btn.active { color: var(--s-accent); }
/* B / U / S toggles */
.text-style-toggles { display: flex; gap: 4px; flex: 0 0 auto; }
.text-toggle-btn {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: Georgia, serif;
  font-size: 0.78rem;
  color: var(--s-text-muted);
  background: var(--s-surface);
  border: 1px solid var(--s-border);
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.15s var(--s-ease, ease);
}
.text-toggle-btn em { font-style: italic; }
.text-toggle-btn u { text-decoration: underline; text-underline-offset: 2px; }
.text-toggle-btn:hover { border-color: var(--s-accent); color: var(--s-text); }
.text-toggle-btn.active {
  color: var(--s-accent-text, #7d5f2c);
  border-color: var(--s-accent);
  background: var(--s-accent-soft, rgba(163, 124, 58, 0.12));
  box-shadow: 0 0 0 1px var(--s-accent) inset;
}
[data-theme="dark"] .text-toggle-btn.active { color: var(--s-accent); }
/* Color input + presets */
.text-color-input {
  width: 30px; height: 30px;
  padding: 0;
  flex: 0 0 auto;
  border: 1px solid var(--s-border);
  border-radius: 7px;
  background: var(--s-surface);
  cursor: pointer;
  transition: border-color 0.15s var(--s-ease, ease), transform 0.15s var(--s-ease, ease);
}
.text-color-input:hover { border-color: var(--s-accent); transform: scale(1.06); }
.text-color-input::-webkit-color-swatch-wrapper { padding: 3px; }
.text-color-input::-webkit-color-swatch { border: none; border-radius: 4px; }
.text-color-presets {
  display: flex;
  gap: 7px;
  padding-top: 9px;
  border-top: 1px dashed var(--s-border);
}
.text-color-dot {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1px solid var(--s-border);
  cursor: pointer;
  position: relative;
  transition: transform 0.15s var(--s-ease, ease), box-shadow 0.15s var(--s-ease, ease);
}
.text-color-dot:hover { transform: scale(1.15); }
.text-color-dot.active {
  box-shadow: 0 0 0 2px var(--s-card), 0 0 0 3.5px var(--s-accent);
}
/* Spacing slider khớp hệ slider Atelier (track mảnh, thumb gold) */
.text-style-row-slider input[type="range"] {
  flex: 1 1 auto;
  min-width: 0;
  height: 20px;
  -webkit-appearance: none;
  appearance: none;
  background: linear-gradient(
    to right,
    var(--s-accent) 0 var(--fill, 0%),
    var(--s-border) var(--fill, 0%) 100%
  );
  background-clip: content-box;
  padding: 8px 0;
  border-radius: 0;
  cursor: pointer;
}
.text-style-row-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: linear-gradient(145deg, #e8cf9e, var(--s-accent));
  border: 2px solid var(--s-ink, #0f0c09);
  box-shadow: 0 1px 4px rgba(15, 12, 9, 0.35);
  transition: transform 0.12s var(--s-ease, ease);
}
.text-style-row-slider input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
.text-style-row-slider input[type="range"]::-webkit-slider-thumb:active { transform: scale(0.95); }
.text-style-row-slider input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: linear-gradient(145deg, #e8cf9e, var(--s-accent));
  border: 2px solid var(--s-ink, #0f0c09);
}
.text-style-row-slider .slider-value {
  flex: 0 0 38px;
  text-align: right;
  font-family: var(--s-font-mono, var(--font-mono));
  font-size: 0.66rem;
  color: var(--s-accent-text, #7d5f2c);
}
[data-theme="dark"] .text-style-row-slider .slider-value { color: var(--s-accent); }

/* Mobile: cảm ứng thoải mái, không track "viên thuốc" */
@media (max-width: 768px) {
  .text-style-controls { padding: 8px; }
  .text-case-btn { height: 34px; }
  .text-toggle-btn { width: 34px; height: 34px; }
  .text-color-dot { width: 26px; height: 26px; }
  .text-color-input { width: 34px; height: 34px; }
}

/* ============================================================
   SNAP GUIDES + DRAG HUD — hệ dẫn hướng căn chỉnh chuẩn pro
   ============================================================ */
.snap-guide {
  position: absolute;
  pointer-events: none;
  z-index: 40;
  opacity: 0;
  transition: opacity 0.12s var(--s-ease, ease);
}
.snap-guide.active { opacity: 1; }
.snap-guide-v {
  top: 6%; bottom: 6%; left: 50%;
  width: 1.5px;
  transform: translateX(-50%);
  background: linear-gradient(to bottom, transparent, var(--s-accent) 18%, var(--s-accent) 82%, transparent);
  box-shadow: 0 0 8px rgba(212, 175, 110, 0.65);
}
.snap-guide-h {
  left: 8%; right: 8%; top: 50%;
  height: 1.5px;
  transform: translateY(-50%);
  background: linear-gradient(to right, transparent, var(--s-accent) 18%, var(--s-accent) 82%, transparent);
  box-shadow: 0 0 8px rgba(212, 175, 110, 0.65);
}
.drag-hud {
  position: absolute;
  z-index: 41;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%) translateY(6px);
  padding: 6px 14px;
  font-family: var(--s-font-mono, var(--font-mono));
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: var(--s-text);
  background: color-mix(in srgb, var(--s-card, #fffdf8) 88%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--s-border);
  border-radius: 999px;
  box-shadow: 0 6px 24px rgba(15, 12, 9, 0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s var(--s-ease, ease), transform 0.12s var(--s-ease, ease);
  white-space: nowrap;
}
.drag-hud.active { opacity: 1; transform: translateX(-50%) translateY(0); }
.drag-hud.snap-locked {
  color: var(--s-accent-text, #7d5f2c);
  border-color: var(--s-accent);
  box-shadow: 0 0 0 1px var(--s-accent) inset, 0 6px 24px rgba(15, 12, 9, 0.25);
}
.drag-hud.snap-locked::before { content: '⌖ '; }
[data-theme="dark"] .drag-hud.snap-locked { color: var(--s-accent); }
/* Nút căn giữa nhanh trong header panel */
.align-quick {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}
.align-btn {
  width: 26px; height: 24px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.78rem;
  line-height: 1;
  color: var(--s-text-muted);
  background: var(--s-surface);
  border: 1px solid var(--s-border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.14s var(--s-ease, ease);
}
.align-btn:hover {
  color: var(--s-accent-text, #7d5f2c);
  border-color: var(--s-accent);
  background: var(--s-accent-soft, rgba(163, 124, 58, 0.1));
  transform: translateY(-1px);
}
[data-theme="dark"] .align-btn:hover { color: var(--s-accent); }
/* Hint giữ Alt/lăn chuột — hiện góc dưới khung viewer */
.viewer-hint {
  position: absolute;
  z-index: 39;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  padding: 5px 12px;
  font-size: 0.68rem;
  color: var(--s-text-muted);
  background: color-mix(in srgb, var(--s-card, #fffdf8) 82%, transparent);
  border: 1px solid var(--s-border);
  border-radius: 999px;
  backdrop-filter: blur(6px);
  pointer-events: none;
}
.viewer-hint b { color: var(--s-accent-text, #7d5f2c); font-weight: 700; }
[data-theme="dark"] .viewer-hint b { color: var(--s-accent); }

/* ============================================================
   PRINT BOUNDARY — khung giới hạn di chuyển (ảnh luôn nguyên vẹn)
   Khung vàng nét đứt = nơi TÂM ảnh được phép tới; mép khung = mép
   ảnh sẽ chạm đúng mép vùng in → không bao giờ bị khuất.
   ============================================================ */
/* ============================================================
   PRINT BOUNDARY 3.0 — khung ĐỎ ôm VÙNG IN trên áo (theo mẫu thiết kế):
   SVG polygon chiếu 4 góc decal qua projection 3D → viền đỏ chạy theo biên
   in trên áo, KHÔNG phải khung chữ nhật viewport vô nghĩa. Ý nghĩa rõ:
   mép artwork không bao giờ vượt khung đỏ này (clamp theo mép object).
   ============================================================ */
.print-boundary {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 38;
  overflow: visible;
  opacity: 0;
  /* KHÔNG transition opacity: tab throttle → transition kẹt 0 → khung biến mất.
     Hiện/ẩn tức thì cũng đúng UX (boundary chỉ hiện trong lúc kéo). */
}
.print-boundary.active { opacity: 1; }
.print-boundary .pb-quad {
  fill: transparent;
  stroke: var(--s-accent, #b58a42);
  stroke-opacity: 0.55;
  stroke-width: 1.25;
  stroke-linejoin: round;
  stroke-dasharray: 10 7;
  animation: none;
  transition: fill 0.15s ease;
}
@keyframes pb-march { to { stroke-dashoffset: -34; } }
/* CHẠM GIỚI HẠN: khung đỏ rực đập nhịp — "tới đây là tối đa" */
.print-boundary.at-limit .pb-quad {
  fill: rgba(220, 38, 38, 0.025);
  stroke: #dc2626;
  stroke-opacity: 0.85;
  stroke-width: 1.75;
  animation: none;
}
@keyframes pb-pulse {
  0%, 100% { stroke-opacity: 1; }
  50% { stroke-opacity: 0.45; }
}
/* CHIP cảnh báo đỏ nổi sát mép object khi chạm giới hạn */
.pb-limit-chip {
  position: absolute;
  z-index: 60;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 10px));
  padding: 5px 11px;
  font-family: var(--s-font-mono, var(--font-mono));
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #fff;
  background: #dc2626;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(220, 38, 38, 0.45), 0 0 0 2px rgba(255, 255, 255, 0.85);
  opacity: 0;
  /* không transition — tránh kẹt 0 khi tab throttle (như .print-boundary) */
  white-space: nowrap;
}
.pb-limit-chip::after {
  content: '';
  position: absolute;
  top: 100%; left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #dc2626;
}
.pb-limit-chip.below { transform: translate(-50%, 10px); }
.pb-limit-chip.below::after {
  top: auto; bottom: 100%;
  border-top-color: transparent;
  border-bottom-color: #dc2626;
}
.pb-limit-chip.active { opacity: 1; }
/* HUD trạng thái chạm biên — viền cảnh báo amber đậm */
.drag-hud.at-limit {
  color: #8a5a10;
  border-color: #d97706;
  background: rgba(254, 243, 199, 0.92);
}
[data-theme="dark"] .drag-hud.at-limit { color: #fbbf24; background: rgba(69, 46, 8, 0.9); }
.drag-hud.at-limit::before { content: '⤢ '; }

/* (pb-corner cũ đã thay bằng SVG polygon — xem PRINT BOUNDARY 3.0 ở trên) */
/* Ghost ảnh ở biên: bản-sao mờ vàng — xem trước nơi ảnh sẽ dừng */
.boundary-ghost {
  position: absolute;
  z-index: 37;
  pointer-events: none;
  opacity: 0;
  filter: sepia(0.4) saturate(0.8) opacity(0.45);
  outline: 1.5px dashed var(--s-accent, #a37c3a);
  outline-offset: 2px;
  border-radius: 4px;
  transition: opacity 0.12s var(--s-ease, ease);
}
.boundary-ghost.active { opacity: 1; }
/* HUD overflow (vượt khung in chủ ý) — xanh dương nhẹ khác at-limit amber */
.drag-hud.overflow {
  color: #3d5a80;
  border-color: #4f6a8a;
  background: rgba(219, 234, 254, 0.92);
}
[data-theme="dark"] .drag-hud.overflow { color: #93c5fd; background: rgba(23, 37, 60, 0.9); }
.drag-hud.overflow::before { content: '◇ '; }

/* Align tools pro — hàng nút phân bố/xếp hàng trong layer section */
.align-tools {
  display: flex;
  gap: 5px;
  padding: 6px 0 2px;
  flex-wrap: wrap;
}
.align-tool-btn {
  flex: 1 1 auto;
  min-width: 0;
  height: 24px;
  padding: 0 8px;
  font-family: var(--s-font-mono, var(--font-mono));
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  color: var(--s-text-muted);
  background: var(--s-surface);
  border: 1px solid var(--s-border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.14s var(--s-ease, ease);
  white-space: nowrap;
}
.align-tool-btn:hover {
  color: var(--s-accent-text, #7d5f2c);
  border-color: var(--s-accent);
  background: var(--s-accent-soft, rgba(163, 124, 58, 0.1));
  transform: translateY(-1px);
}
[data-theme="dark"] .align-tool-btn:hover { color: var(--s-accent); }

/* ====== EDITOR PRO — undo/redo, opacity, crop, lock, duplicate, rename ====== */
/* Quick actions trên layer đang chọn */
.layer-quick-actions{display:flex;gap:6px;flex-wrap:wrap;margin:10px 0 6px;}
.layer-qa-btn{flex:1;min-width:70px;padding:7px 10px;border-radius:9px;border:1px solid var(--s-border,rgba(255,255,255,.14));background:rgba(255,255,255,.04);color:var(--s-text,#f2f2f2);font-size:.78rem;font-weight:600;cursor:pointer;transition:border-color .15s,background .15s,transform .12s;}
.layer-qa-btn:hover{border-color:var(--s-accent,#ff6b00);background:rgba(255,107,0,.08);}
.layer-qa-btn:active{transform:scale(.97);}
.layer-qa-danger:hover{border-color:#ef4444;background:rgba(239,68,68,.1);color:#fca5a5;}
/* Layer row: locked/hidden states + rename input */
.layer-row.locked{opacity:.75;}
.layer-row.locked .layer-thumb{filter:grayscale(.4);}
.layer-row.hidden{opacity:.5;}
.layer-name-input{width:100%;background:transparent;border:1px solid transparent;border-radius:6px;color:var(--s-text,#f2f2f2);font:inherit;font-size:.8rem;font-weight:600;padding:2px 4px;margin:-2px -4px;cursor:text;transition:border-color .15s,background .15s;}
.layer-name-input:hover{border-color:var(--s-border,rgba(255,255,255,.15));}
.layer-name-input:focus{outline:none;border-color:var(--s-accent,#ff6b00);background:rgba(0,0,0,.25);}
.layer-btn.active{border-color:var(--s-accent,#ff6b00);color:var(--s-accent,#ff6b00);background:rgba(255,107,0,.12);}
.layer-btn:disabled{opacity:.35;cursor:not-allowed;}
/* Opacity + crop sliders */
#cropControls .crop-reset-row{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-top:6px;}
.crop-reset-btn{padding:5px 10px;border-radius:8px;border:1px solid var(--s-border,rgba(255,255,255,.14));background:transparent;color:var(--s-text-muted,#9ca3af);font-size:.74rem;font-weight:600;cursor:pointer;transition:color .15s,border-color .15s;}
.crop-reset-btn:hover{color:var(--s-text,#f2f2f2);border-color:var(--s-accent,#ff6b00);}
.crop-hint{font-size:.68rem;color:var(--s-text-muted,#9ca3af);line-height:1.3;}
@media (max-width:640px){.crop-hint{display:none;}}
/* Undo/redo buttons disabled state */
.canvas-ctrl-btn:disabled{opacity:.3;cursor:not-allowed;}
.canvas-ctrl-btn:disabled:hover{background:transparent;}

/* ====== PHASE 1 — SELECTION FRAME + DIRECT HANDLES ====== */
/* Text rotation (per side) — biến riêng để không phá transform cũ */
.viewer-design-overlay .mockup-print-text {
  transform: translate(calc(-50% + var(--text-x, 0%)), calc(-50% + var(--text-y, 0%))) scale(var(--text-scale, 1)) rotate(var(--text-rot, 0deg));
}
/* Khung selection thật: bounding box + 4 corner handles + rotation handle */
.selection-frame {
  position: absolute;
  z-index: 400;
  pointer-events: none;
  transform: translate(-50%, -50%);
  border: 1.5px solid var(--s-accent, #ff6b00);
  box-shadow: 0 0 0 1px rgba(0,0,0,.25), 0 0 12px rgba(255,107,0,.18);
  opacity: 0;
  transition: opacity .12s ease;
  touch-action: none;
}
.selection-frame.active { opacity: 1; }
.selection-frame .sel-corner {
  position: absolute; width: 12px; height: 12px;
  background: #fff; border: 2px solid var(--s-accent, #ff6b00);
  border-radius: 3px; box-sizing: border-box;
  pointer-events: auto; touch-action: none; cursor: nwse-resize;
  z-index: 2;
}
.selection-frame .sel-corner[data-handle="nw"] { left: -7px; top: -7px; cursor: nwse-resize; }
.selection-frame .sel-corner[data-handle="ne"] { right: -7px; top: -7px; cursor: nesw-resize; }
.selection-frame .sel-corner[data-handle="sw"] { left: -7px; bottom: -7px; cursor: nesw-resize; }
.selection-frame .sel-corner[data-handle="se"] { right: -7px; bottom: -7px; cursor: nwse-resize; }
.selection-frame .sel-rot-line {
  position: absolute; left: 50%; top: 100%;
  width: 2px; height: 20px; margin-left: -1px;
  background: linear-gradient(to bottom, var(--s-accent, #ff6b00), transparent);
  pointer-events: none;
}
.selection-frame .sel-rot-handle {
  position: absolute; left: 50%; top: calc(100% + 20px);
  width: 18px; height: 18px; margin-left: -9px; margin-top: -9px;
  background: #fff; border: 2px solid var(--s-accent, #ff6b00);
  border-radius: 50%; box-sizing: border-box;
  pointer-events: auto; touch-action: none; cursor: grab;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: var(--s-accent, #ff6b00); font-weight: 700;
  z-index: 2;
}
.selection-frame .sel-rot-handle:active { cursor: grabbing; }
/* Hit-area lớn cho touch (390px) — padding vô hình quanh handle */
.selection-frame .sel-corner::after,
.selection-frame .sel-rot-handle::after {
  content: ''; position: absolute; inset: -7px; border-radius: inherit;
}
.selection-frame.locked-view { border-style: dashed; border-color: #9ca3af; box-shadow: none; }
.selection-frame.locked-view .sel-corner,
.selection-frame.locked-view .sel-rot-handle { display: none; }
.selection-frame.text-frame { border-style: dashed; }
/* Lock chip cho text */
.text-lock-btn{padding:4px 9px;border-radius:8px;border:1px solid var(--s-border,rgba(255,255,255,.14));background:transparent;color:var(--s-text,#f2f2f2);font-size:.74rem;font-weight:600;cursor:pointer;}
.text-lock-btn.active{border-color:var(--s-accent,#ff6b00);color:var(--s-accent,#ff6b00);background:rgba(255,107,0,.1);}
/* Unlock chip trên selection frame */
.selection-frame .sel-unlock {
  position: absolute; top: -34px; left: 50%; transform: translateX(-50%);
  padding: 4px 10px; border-radius: 8px; white-space: nowrap;
  background: rgba(17,20,24,.92); color: #fff; font-size: .72rem; font-weight: 700;
  pointer-events: auto; cursor: pointer; border: 1px solid rgba(255,255,255,.25);
  box-shadow: 0 4px 10px rgba(0,0,0,.3); z-index: 3;
}
.selection-frame .sel-unlock:hover { background: var(--s-accent, #ff6b00); }
/* Text lock + rotate controls row (Kiểu chữ panel) */
.text-rot-lock-row{display:flex;gap:6px;align-items:center;margin-top:8px;flex-wrap:wrap;}
.text-rot-lock-row .text-style-label{margin:0 2px 0 0;}
.text-rot-slider{flex:1;min-width:90px;}

/* PHASE 1: touch-target chuẩn a11y trên thiết bị cảm ứng thật (>=40px hit) */
@media (pointer: coarse) {
  .selection-frame .sel-corner::after,
  .selection-frame .sel-rot-handle::after { inset: -11px; }
}

/* ====== PHASE 2 — CROP MODE (professional non-destructive crop) ====== */
.crop-toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 12px; margin-bottom: 10px;
  background: linear-gradient(135deg, var(--s-accent-light, rgba(193,152,86,0.14)), transparent);
  border: 1px solid var(--s-accent, #a37c3a); border-radius: 10px;
}
.crop-toolbar[hidden] { display: none; }
.crop-mode-tag {
  font-size: 10.5px; font-weight: 800; letter-spacing: 0.12em;
  color: var(--s-accent-text, #7d5f2c);
  padding: 3px 8px; border-radius: 6px;
  background: var(--s-accent-light, rgba(193,152,86,0.14));
  border: 1px solid var(--s-accent, #a37c3a);
}
.crop-tb-btn {
  border: 1px solid var(--s-border, #ddd); background: var(--s-surface, #fff);
  color: var(--s-text, #222); border-radius: 8px; padding: 7px 14px;
  font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.crop-tb-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.10); }
.crop-tb-apply { background: var(--s-accent, #a37c3a); border-color: var(--s-accent, #a37c3a); color: #fff; }
.crop-tb-apply:hover { background: var(--s-accent-hover, #7d5f2c); }
.crop-tb-cancel { color: #b3392e; border-color: rgba(179,57,46,0.4); }
.crop-tb-cancel:hover { background: rgba(179,57,46,0.08); }
.crop-toolbar-hint { font-size: 11.5px; color: var(--s-text-muted, #777); margin-bottom: 8px; }
.crop-toolbar-hint[hidden] { display: none; }

/* Crop frame: holder phủ toàn bộ ảnh gốc, xoay theo layer */
.crop-frame {
  position: absolute; z-index: 40; display: none;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.crop-frame.active { display: block; }
body.crop-mode-active #mockupDesign .mockup-print-design { pointer-events: none !important; }
body.crop-mode-active #mockupDesign .mockup-print-text { pointer-events: none !important; }
.crop-frame .crop-img-holder { position: absolute; inset: 0; overflow: hidden; }
.crop-frame .crop-img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; -webkit-user-drag: none; pointer-events: none;
  filter: brightness(0.92);
}
.crop-frame .crop-dim {
  position: absolute; inset: 0; pointer-events: none;
  background: rgba(8, 10, 14, 0.42);
  clip-path: polygon(
    0 0, 100% 0, 100% 100%, 0 100%, 0 0,
    var(--cx, 0%) var(--cy, 0%), var(--cx, 0%) calc(var(--cy, 0%) + var(--ch, 0%)),
    calc(var(--cx, 0%) + var(--cw, 0%)) calc(var(--cy, 0%) + var(--ch, 0%)),
    calc(var(--cx, 0%) + var(--cw, 0%)) var(--cy, 0%), var(--cx, 0%) var(--cy, 0%));
}
.crop-frame .crop-window {
  position: absolute; border: 1.5px solid var(--s-accent, #a37c3a);
  box-shadow: 0 0 0 9999px rgba(8,10,14,0.0), inset 0 0 0 1px rgba(255,255,255,0.35);
  cursor: move; touch-action: none;
}
.crop-frame .crop-window::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,0.28) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.28) 1px, transparent 1px);
  background-size: 25% 33.4%, 33.4% 25%;
  background-position: -1px -1px;
  opacity: 0.5;
}
.crop-c, .crop-e { position: absolute; z-index: 3; }
.crop-c {
  width: 15px; height: 15px; background: var(--s-accent, #a37c3a);
  border: 2px solid #fff; border-radius: 3px; box-shadow: 0 1px 4px rgba(0,0,0,0.35);
}
.crop-c[data-crop="nw"] { left: -8px; top: -8px; cursor: nwse-resize; }
.crop-c[data-crop="ne"] { right: -8px; top: -8px; cursor: nesw-resize; }
.crop-c[data-crop="sw"] { left: -8px; bottom: -8px; cursor: nesw-resize; }
.crop-c[data-crop="se"] { right: -8px; bottom: -8px; cursor: nwse-resize; }
.crop-e { background: transparent; }
.crop-e[data-crop="n"] { left: 12px; right: 12px; top: -9px; height: 18px; cursor: ns-resize; }
.crop-e[data-crop="s"] { left: 12px; right: 12px; bottom: -9px; height: 18px; cursor: ns-resize; }
.crop-e[data-crop="w"] { top: 12px; bottom: 12px; left: -9px; width: 18px; cursor: ew-resize; }
.crop-e[data-crop="e"] { top: 12px; bottom: 12px; right: -9px; width: 18px; cursor: ew-resize; }
.crop-badge {
  position: absolute; top: -24px; left: 0; z-index: 4;
  font-size: 9.5px; font-weight: 800; letter-spacing: 0.14em;
  color: #fff; background: var(--s-accent, #a37c3a);
  padding: 2.5px 8px; border-radius: 4px;
}
/* Touch target chuẩn §22: handles ≥ 40px trên thiết bị cảm ứng */
@media (pointer: coarse) {
  .crop-c::after, .crop-e::after { content: ''; position: absolute; inset: -13px; }
  .crop-c { width: 19px; height: 19px; }
  .crop-frame .crop-window { cursor: move; }
}

/* ====== PHASE 4 — SAVED DESIGNS ====== */
.panel-saved { margin-top: 8px; }
.saved-designs-list { display: none; padding: 6px 10px 10px; max-height: 260px; overflow-y: auto; }
.panel-saved.open .saved-designs-list { display: block; }
.saved-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 10px; cursor: pointer;
  color: var(--s-text, #cbd5e1); transition: background 0.15s ease, transform 0.1s ease;
}
.saved-item:hover { background: rgba(148, 163, 184, 0.12); }
.saved-item.current { background: rgba(212, 175, 55, 0.14); box-shadow: inset 0 0 0 1px rgba(212, 175, 55, 0.35); }
.saved-item-info { flex: 1; min-width: 0; }
.saved-item-name { font-size: 0.82rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved-item-meta { font-size: 0.7rem; opacity: 0.65; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved-item-delete {
  flex: 0 0 auto; width: 26px; height: 26px; border-radius: 8px;
  display: grid; place-items: center; border: none; cursor: pointer;
  background: transparent; color: inherit; opacity: 0.55; font-size: 0.85rem;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.saved-item-delete:hover { opacity: 1; background: rgba(239, 68, 68, 0.18); color: #f87171; }
.saved-empty { padding: 10px 12px; font-size: 0.78rem; color: var(--s-text-muted, #94a3b8); }
.saved-badge {
  font-size: 0.66rem; font-weight: 700; letter-spacing: 0.02em;
  padding: 2px 8px; border-radius: 999px; max-width: 140px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: rgba(212, 175, 55, 0.16); color: #d4af37; border: 1px solid rgba(212, 175, 55, 0.4);
}
.action-btn-save { box-shadow: inset 0 0 0 1px rgba(212, 175, 55, 0.45); }
.action-btn.is-loading { opacity: 0.6; pointer-events: none; }
@media (max-width: 640px) {
  .saved-item { padding: 10px 8px; } /* touch target ≥ 40px */
  .saved-item-delete { width: 34px; height: 34px; }
}

/* ============================================================
   PRO EDIT SUITE — nâng tầm thao tác ảnh/chữ (2026 refresh)
   ============================================================ */

/* Kéo file từ desktop thẳng lên áo: overlay phủ khung 3D với hướng dẫn rõ.
   QUAN TRỌNG: [hidden] phải thắng display:flex của rule chính (author CSS
   luôn thắng UA [hidden]{display:none}) — nếu không overlay hiển thị VĨNH
   VIỄN che hết vùng chỉnh sửa (bug đã gặp). */
.canvas-drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: none; /* mặc định ẩn — chỉ hiện khi đang kéo file thật */
  align-items: center;
  justify-content: center;
  background: rgba(10, 12, 16, 0.55);
  backdrop-filter: blur(2px);
  border: 2.5px dashed rgba(255, 128, 54, 0.9);
  border-radius: 14px;
  pointer-events: none; /* không chặn drop event của host */
}

.canvas-drop-overlay.is-active {
  display: flex;
}

.canvas-drop-hint {
  padding: 14px 22px;
  border-radius: 12px;
  background: rgba(15, 18, 24, 0.82);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

/* Cursor feedback chuẩn editor: layer = grab, đang kéo = grabbing (nút canvas
   đã có cursor:grab trước đây, giờ đồng bộ cả overlay layer). */
.mockup-print-design { cursor: grab; }
.mockup-print-design:active { cursor: grabbing; }
.mockup-print-text { cursor: grab; }
.mockup-print-text:active { cursor: grabbing; }

/* The editing surface owns touch gestures; scrolling remains available
   outside the canvas. Object movement never inherits CSS easing. */
.canvas-viewer.interaction-position,
.viewer-design-overlay [data-layer-id],
.viewer-design-overlay [data-text-drag] { touch-action: none; }
.viewer-design-overlay [data-layer-id],
.viewer-design-overlay [data-text-drag] { transition: none; user-select: none; }
.canvas-viewer.is-print-manipulating,
.canvas-viewer.is-print-manipulating * { cursor: grabbing !important; }
.canvas-viewer.is-print-manipulating .selection-frame { transition: none; }
.selection-frame .sel-name { pointer-events: auto; cursor: grab; touch-action: none; border: 0; }
.selection-frame .sel-name:focus-visible { outline: 2px solid white; outline-offset: 2px; }
.selection-frame .sel-name::before { content: '⠿ '; opacity: .65; }
.viewer-design-overlay .mockup-print-text { max-width: none; overflow: visible; }

/* Layer action mới (flip) — active state xanh lá nhẹ khi đang bật */
.layer-btn.active[data-action='flip-h'],
.layer-btn.active[data-action='flip-v'] {
  border-color: rgba(74, 222, 128, 0.55);
  background: rgba(74, 222, 128, 0.12);
}

/* ============================================================
   ORDER REVIEW CTA — editorial print. Hairline frame, mono
   microcopy, gold stars. Không emoji, không gradient.
   ============================================================ */
.order-review-cta {
  margin-top: 20px;
  padding: 18px 20px 16px;
  border: 1px solid rgba(15, 12, 9, 0.16);
  border-left: 2px solid var(--s-accent);
  border-radius: 0;
  background: rgba(193, 152, 86, 0.06);
  animation: orderReviewIn 0.5s var(--s-ease, cubic-bezier(0.16, 1, 0.3, 1));
}
@keyframes orderReviewIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.order-review-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}
.order-review-stars {
  display: inline-flex;
  gap: 2px;
}
.order-review-star {
  width: 32px;
  height: 32px;
  font-size: 1.25rem;
  line-height: 1;
  color: rgba(15, 12, 9, 0.22);
  background: none;
  border: none;
  cursor: pointer;
  transition: color 0.15s ease, transform 0.2s var(--s-ease, ease);
}
.order-review-star:hover { transform: translateY(-2px); }
.order-review-star.on { color: var(--s-accent); }
.order-review-star.preview { color: var(--s-accent); }
.order-review-label {
  font-family: 'Playfair Display', Georgia, serif;
  font-style: italic;
  font-size: 1rem;
  color: var(--s-accent-text);
  transition: color 0.2s ease;
}
.order-review-label[data-level="1"],
.order-review-label[data-level="2"] { color: #8a4b2f; }
.order-review-label[data-level="3"] { color: #6d6358; }
.order-review-label[data-level="4"],
.order-review-label[data-level="5"] { color: var(--s-accent-text); }
.order-review-text {
  width: 100%;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.85rem;
  color: #0f0c09;
  background: #fffdf8;
  border: 1px solid rgba(15, 12, 9, 0.16);
  border-radius: 0;
  resize: vertical;
  min-height: 70px;
  box-sizing: border-box;
}
.order-review-text:focus {
  outline: none;
  border-color: var(--s-accent);
  box-shadow: 0 0 0 3px rgba(193, 152, 86, 0.16);
}
.order-review-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
}
.order-review-count {
  font-size: 0.7rem;
  color: #6d6358;
  font-variant-numeric: tabular-nums;
}
.order-review-foot .btn {
  border-radius: 0;
}
.order-review-done {
  margin: 8px 0 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: #3f6b46;
}
.order-review-foot .btn.success {
  color: #fffdf8;
  background: #3f6b46;
  border-color: transparent;
}

/* ============================================================
   STUDIO WORKSPACE — clearer three-panel workflow
   ============================================================ */
:root {
  --s-left-width: clamp(20rem, 26vw, 23.75rem);
  --s-right-width: clamp(17rem, 20.5vw, 18.75rem);
}

.studio-toolbar-inner {
  max-width: 1720px;
  scroll-padding-inline: var(--s-space-5);
}

.tab-label-compact { display: none; }

.toolbar-tab:focus-visible,
.canvas-empty-cta:focus-visible,
.templates-empty a:focus-visible {
  outline: 3px solid var(--s-accent-text);
  outline-offset: 3px;
}

.panel-section-header h3 {
  font-size: 0.86rem;
  letter-spacing: 0.01em;
  text-transform: none;
  color: var(--s-text);
}

.studio-left,
.studio-right {
  height: calc(100dvh - var(--s-nav-height) - var(--s-toolbar-height));
}

.studio-canvas { min-width: 0; }

.canvas-wrapper {
  min-width: 0;
  background:
    radial-gradient(ellipse at 50% 42%, rgba(193, 152, 86, 0.09) 0%, rgba(193, 152, 86, 0.025) 34%, transparent 68%),
    var(--s-bg);
}

.canvas-empty {
  width: min(100% - 40px, 520px);
  gap: var(--s-space-4);
  padding: var(--s-space-6) 0;
}

.canvas-empty-copy {
  display: grid;
  justify-items: center;
  gap: var(--s-space-2);
  max-width: 460px;
}

.canvas-empty-kicker {
  color: var(--s-accent-text);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.14em;
}

.canvas-empty-copy p {
  margin: 0;
  font-size: clamp(1.12rem, 1.5vw, 1.38rem);
  font-weight: 650;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

.canvas-empty-copy .field-hint {
  max-width: 42ch;
  font-size: 0.82rem;
  line-height: 1.65;
  text-wrap: pretty;
}

.canvas-empty-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--s-space-2);
  margin-top: var(--s-space-1);
}

.canvas-empty-cta {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 0 var(--s-space-5);
  border: 1px solid #0f0c09;
  border-radius: var(--s-radius-md);
  background: #0f0c09;
  color: #f5f2eb;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 650;
  cursor: pointer;
  transition: transform var(--s-transition-fast), background var(--s-transition-fast), border-color var(--s-transition-fast), color var(--s-transition-fast);
}

.canvas-empty-cta:hover {
  transform: translateY(-1px);
  border-color: var(--s-accent);
  background: var(--s-accent);
  color: #0f0c09;
}

.canvas-empty-cta:active { transform: scale(0.98); }

.canvas-empty-cta-secondary {
  border-color: var(--s-border-strong);
  background: var(--s-card);
  color: var(--s-text);
}

.canvas-empty-note {
  color: var(--s-text-muted);
  font-size: 0.72rem;
  line-height: 1.5;
}

.templates-empty {
  display: grid;
  justify-items: start;
  gap: var(--s-space-2);
  margin: var(--s-space-5);
  padding: var(--s-space-4);
  border-left: 2px solid var(--s-accent);
  background: var(--s-surface);
  color: var(--s-text-secondary);
  font-size: 0.82rem;
  line-height: 1.55;
}

.templates-empty p { margin: 0; }
.templates-empty a { color: var(--s-accent-text); font-weight: 650; }

.product-type-btn {
  display: flex;
  min-height: 48px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
}

.product-3d-badge {
  position: static;
  display: block;
  width: max-content;
  max-width: 100%;
  margin: 0 auto;
  padding: 1px 5px;
  border-radius: 2px;
  font-size: 0.58rem;
  line-height: 1.3;
}

@media (min-width: 1101px) {
  .studio-layout {
    grid-template-columns: minmax(20rem, var(--s-left-width)) minmax(26rem, 1fr) minmax(17rem, var(--s-right-width));
    max-width: 1720px;
  }
}

@media (max-width: 1100px) {
  .studio-left,
  .studio-right { height: auto; }
  .canvas-empty { width: min(100% - 32px, 520px); }
}

@media (max-width: 480px) {
  .studio-toolbar-inner {
    justify-content: flex-start;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }

  .studio-toolbar-inner::-webkit-scrollbar { display: none; }

  .toolbar-tab {
    width: max-content;
    max-width: none;
    min-width: max-content;
    flex: 0 0 auto;
    gap: 5px;
    padding: 10px 9px;
    font-size: 0.74rem;
    scroll-snap-align: start;
  }

  .toolbar-tab .tab-label-full { display: none; }
  .toolbar-tab .tab-label-compact { display: inline; }
  .toolbar-tab svg { width: 16px; height: 16px; }

  .canvas-empty { gap: var(--s-space-3); }
  .canvas-empty-actions { width: 100%; flex-direction: column; }
  .canvas-empty-cta { width: 100%; }
  .canvas-empty-note { max-width: 32ch; }
}

@media (prefers-reduced-motion: reduce) {
  .canvas-empty-cta { transition: none; }
}

/* Direct manipulation affordances: selected target, keyboard focus and limits. */
.selection-frame .sel-name {
  position: absolute;
  left: 50%;
  top: -30px;
  max-width: min(240px, 76vw);
  overflow: hidden;
  padding: 4px 9px;
  border: 1px solid color-mix(in srgb, var(--s-accent, #c19856) 45%, transparent);
  border-radius: 5px;
  background: var(--s-surface, #fffdf8);
  color: var(--s-text, #2f2a22);
  font: 700 11px/1.2 Arial, sans-serif;
  letter-spacing: .04em;
  text-overflow: ellipsis;
  white-space: nowrap;
  transform: translateX(-50%);
  pointer-events: auto;
}

.canvas-viewer:focus-visible {
  outline: 2px solid var(--s-accent, #c19856);
  outline-offset: 3px;
}

.placement-feedback {
  margin: 7px 0 2px;
  padding: 8px 10px;
  border-left: 3px solid var(--s-accent, #c19856);
  border-radius: 4px;
  background: color-mix(in srgb, var(--s-accent, #c19856) 10%, var(--s-surface, #fffdf8));
  color: var(--s-text, #2f2a22);
  font-size: .78rem;
  line-height: 1.45;
}

.placement-feedback[data-kind="limit"] {
  border-left-color: #b45309;
  background: #fff7ed;
  color: #7c2d12;
}

[data-theme="dark"] .placement-feedback[data-kind="limit"] {
  background: #3b2415;
  color: #fed7aa;
}

.layer-row[tabindex="0"]:focus-visible {
  outline: 2px solid var(--s-accent, #c19856);
  outline-offset: 2px;
}

.layer-row[aria-current="true"] .layer-name,
.layer-row[aria-current="true"] .layer-name-input {
  font-weight: 800;
}
