/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-primary: #f8fafc; /* Slate 50 */
  --bg-secondary: #ffffff; /* White */
  --bg-tertiary: #f1f5f9; /* Slate 100 */
  --glass-bg: rgba(255, 255, 255, 0.85);
  --glass-border: #e2e8f0; /* Slate 200 */
  --text-primary: #0f172a; /* Slate 900 */
  --text-secondary: #475569; /* Slate 600 */
  --text-muted: #94a3b8; /* Slate 400 */
  --accent-1: #3b82f6; /* Blue 500 */
  --accent-2: #8b5cf6; /* Violet 500 */
  --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
  --success: #10b981; /* Emerald 500 */
  --error: #ef4444; /* Red 500 */
  --warning: #f59e0b; /* Amber 500 */
  --snap-color: #ec4899; /* Pink 500 */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.05), 0 1px 2px rgba(0,0,0,0.03);
  --shadow-md: 0 4px 10px rgba(0, 0, 0, 0.05), 0 2px 4px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.08);
  --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.15);
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --sidebar-width: 290px;
}

html { font-size: 14px; }
body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(59, 130, 246, 0.05) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(139, 92, 246, 0.05) 0%, transparent 60%);
}

/* Global drag cursor */
.is-dragging, .is-dragging * { cursor: grabbing !important; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, 0.25); }

/* ===== HEADER ===== */
.app-header {
  padding: 14px 24px;
  border-bottom: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  position: sticky; top: 0; z-index: 100;
}
.header-content { max-width: 1800px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; }
.logo { display: flex; align-items: center; gap: 12px; }
.logo-icon {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-gradient); border-radius: var(--radius-sm); padding: 4px;
}
.logo-icon svg { width: 100%; height: 100%; }
.logo-icon svg rect { stroke: white; fill: rgba(255, 255, 255, 0.8); }
.logo h1 {
  font-size: 1.25rem; font-weight: 700;
  background: var(--accent-gradient);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.subtitle { font-size: 0.78rem; color: var(--text-secondary); margin-top: 2px; }

/* Restart button */
.btn-restart {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--glass-border); background: var(--bg-secondary);
  color: var(--text-secondary); cursor: pointer;
  font-family: var(--font); font-size: 0.8rem; font-weight: 500;
  transition: var(--transition);
}
.btn-restart:hover {
  border-color: var(--error); color: var(--error);
  background: #fef2f2;
}
.btn-restart svg { flex-shrink: 0; }

/* ===== SETUP SCREEN ===== */
.setup-overlay {
  position: fixed; inset: 0; z-index: 9000;
  background: linear-gradient(135deg, #eef2ff 0%, #f5f3ff 40%, #fdf2f8 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  overflow-y: auto;
}
.setup-card {
  background: white;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  width: 100%; max-width: 560px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.08), 0 4px 16px rgba(0, 0, 0, 0.04);
  animation: setupFadeIn 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes setupFadeIn {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}
.setup-header {
  padding: 28px 32px 20px;
  border-bottom: 1px solid var(--glass-border);
}
.setup-logo {
  display: flex; align-items: center; gap: 14px;
}
.setup-title {
  font-size: 1.5rem; font-weight: 800;
  background: var(--accent-gradient);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.setup-subtitle {
  font-size: 0.85rem; color: var(--text-secondary); margin-top: 3px;
}
.setup-body {
  padding: 24px 32px;
  display: flex; flex-direction: column; gap: 20px;
}
.setup-section {
  display: flex; gap: 14px; align-items: flex-start;
}
.setup-section-num {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent-gradient); color: white;
  font-weight: 700; font-size: 0.85rem;
  display: flex; align-items: center; justify-content: center;
  margin-top: 2px;
}
.setup-section-content { flex: 1; }
.setup-section-title {
  font-size: 0.95rem; font-weight: 600; color: var(--text-primary);
  margin-bottom: 12px;
}
.setup-presets {
  grid-template-columns: 1fr 1fr 1fr 1fr;
}
.setup-preview-row {
  background: var(--bg-tertiary);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  display: flex; align-items: center; justify-content: center;
}
.setup-preview-info {
  display: flex; gap: 10px; flex-wrap: wrap; justify-content: center;
}
.preview-chip {
  font-size: 0.82rem; font-weight: 600;
  padding: 5px 14px; border-radius: 20px;
  background: white; border: 1px solid var(--glass-border);
  color: var(--text-primary);
}
.setup-footer {
  padding: 20px 32px 28px;
  border-top: 1px solid var(--glass-border);
  display: flex; justify-content: center;
}
.btn-setup-start {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 40px;
  background: var(--accent-gradient); color: white;
  border: none; border-radius: var(--radius-md);
  font-family: var(--font); font-size: 1rem; font-weight: 700;
  cursor: pointer; transition: var(--transition);
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.3);
}
.btn-setup-start:hover {
  opacity: 0.9;
  box-shadow: 0 6px 24px rgba(59, 130, 246, 0.4);
  transform: translateY(-1px);
}
.btn-setup-start svg { flex-shrink: 0; }

/* ===== MAIN LAYOUT ===== */
.app-main {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr var(--sidebar-width);
  min-height: 100vh;
  max-width: 1800px; margin: 0 auto;
}

/* ===== PANELS ===== */
.panel {
  padding: 16px; overflow-y: auto;
  border-right: 1px solid var(--glass-border);
  background: var(--glass-bg);
  max-height: 100vh;
}
.panel-right { border-right: none; border-left: 1px solid var(--glass-border); }
.panel-section {
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 16px; margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}
.section-title {
  font-size: 0.85rem; font-weight: 600; color: var(--text-primary);
  display: flex; align-items: center; gap: 8px; margin-bottom: 14px;
}
.section-icon { font-size: 1rem; }
.badge {
  font-size: 0.7rem; font-weight: 600;
  background: var(--accent-gradient); color: white;
  padding: 2px 8px; border-radius: 10px; margin-left: auto;
}
.hint-text { font-size: 0.72rem; color: var(--text-muted); font-style: italic; }

/* ===== SIZE PRESETS ===== */
.size-presets { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.preset-btn {
  background: var(--bg-tertiary); border: 1.5px solid var(--glass-border);
  border-radius: var(--radius-sm); padding: 10px 8px;
  color: var(--text-secondary); cursor: pointer;
  transition: var(--transition); text-align: center; font-family: var(--font);
}
.preset-btn:hover { border-color: var(--accent-1); color: var(--accent-1); }
.preset-btn.active {
  border-color: var(--accent-1); color: white;
  background: var(--accent-gradient);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}
.preset-label { display: block; font-weight: 600; font-size: 0.9rem; }
.preset-detail { display: block; font-size: 0.7rem; margin-top: 2px; opacity: 0.8; }
.custom-size { margin-top: 10px; }
.input-row { display: flex; align-items: flex-end; gap: 8px; }
.input-sep { color: var(--text-muted); font-weight: 600; padding-bottom: 8px; }
.input-group { flex: 1; }
.input-group label {
  display: block; font-size: 0.72rem; font-weight: 500;
  color: var(--text-secondary); margin-bottom: 5px;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.input-group input[type="number"],
.input-group input[type="text"] {
  width: 100%; padding: 8px 10px;
  background: var(--bg-secondary); border: 1.5px solid var(--glass-border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  font-family: var(--font); font-size: 0.85rem;
  transition: var(--transition); outline: none;
}
.input-group input:focus { border-color: var(--accent-1); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1); }

/* ===== ORIENTATION TOGGLE ===== */
.orientation-toggle { display: flex; gap: 6px; margin-bottom: 12px; }
.orient-btn {
  flex: 1; padding: 8px;
  background: var(--bg-tertiary); border: 1.5px solid var(--glass-border);
  border-radius: var(--radius-sm); color: var(--text-secondary);
  cursor: pointer; font-family: var(--font); font-size: 0.8rem;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: var(--transition);
}
.orient-btn:hover { border-color: var(--accent-1); color: var(--accent-1); }
.orient-btn.active {
  border-color: var(--accent-1); color: white;
  background: var(--accent-gradient);
}
.orient-icon { font-size: 1.1rem; }
.orient-landscape { display: inline-block; transform: rotate(90deg); }

/* ===== TOGGLE SWITCH ===== */
.toggle-label {
  display: flex; align-items: center; gap: 10px;
  cursor: pointer; font-size: 0.82rem; color: var(--text-secondary);
  margin-top: 10px; user-select: none;
}
.toggle-switch {
  width: 36px; height: 20px; border-radius: 10px;
  background: var(--bg-tertiary); border: 1.5px solid var(--glass-border);
  position: relative; transition: var(--transition); flex-shrink: 0;
}
.toggle-switch.on { background: var(--accent-1); border-color: var(--accent-1); }
.toggle-thumb {
  width: 14px; height: 14px; border-radius: 50%; background: white;
  position: absolute; top: 2px; left: 2px; transition: var(--transition);
}
.toggle-switch.on .toggle-thumb { left: 18px; }

/* ===== SAVED PRESETS ===== */
.btn-save-preset {
  width: 100%; padding: 10px;
  background: var(--bg-tertiary); border: 1.5px dashed var(--glass-border);
  border-radius: var(--radius-sm); color: var(--text-secondary);
  cursor: pointer; font-family: var(--font); font-size: 0.8rem;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: var(--transition);
}
.btn-save-preset:hover { border-color: var(--accent-1); color: var(--accent-1); background: white; }
.btn-save-preset svg { stroke: currentColor; fill: none; }
.saved-presets-list { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.saved-preset-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: var(--radius-sm);
  cursor: pointer; transition: var(--transition); border: 1px solid transparent;
  background: var(--bg-tertiary);
}
.saved-preset-item:hover { background: rgba(59, 130, 246, 0.05); border-color: rgba(59, 130, 246, 0.1); }
.sp-info { display: flex; flex-direction: column; }
.sp-name { font-size: 0.82rem; font-weight: 600; color: var(--text-primary); }
.sp-detail { font-size: 0.68rem; color: var(--text-secondary); margin-top: 1px; }
.sp-delete {
  width: 22px; height: 22px; border-radius: 6px; border: none; background: transparent;
  color: var(--text-muted); cursor: pointer; font-size: 1rem;
  display: flex; align-items: center; justify-content: center; transition: var(--transition);
}
.sp-delete:hover { background: rgba(239, 68, 68, 0.1); color: var(--error); }
.empty-hint { font-size: 0.75rem; color: var(--text-muted); text-align: center; padding: 10px 0; font-style: italic; }

/* ===== WORKSPACE TOP BAR (UPLOAD & PHOTO BANK) ===== */
.workspace-top-bar {
  display: flex;
  gap: 16px;
  padding: 16px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--glass-border);
  align-items: center;
  flex-shrink: 0;
  height: 120px;
}

/* Mini Upload Box */
.mini-upload-zone {
  width: 130px;
  height: 88px;
  border: 2px dashed #cbd5e1; /* Slate 300 */
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--bg-tertiary);
  user-select: none;
}
.mini-upload-zone:hover, .mini-upload-zone.drag-active {
  border-color: var(--accent-1);
  background: rgba(59, 130, 246, 0.03);
}
.mini-upload-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  color: var(--text-secondary);
  gap: 4px;
}
.mini-upload-content svg {
  color: var(--accent-1);
  margin-bottom: 2px;
}
.mini-upload-zone:hover .mini-upload-content {
  color: var(--text-primary);
}
.upload-btn-text {
  font-size: 0.8rem;
  font-weight: 600;
}
.upload-btn-sub {
  font-size: 0.65rem;
  color: var(--text-muted);
}

/* Horizontal Photo Bank */
.horizontal-photo-bank-wrapper {
  flex: 1;
  height: 88px;
  background: var(--bg-tertiary);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  padding: 0 12px;
  overflow: hidden;
}
.empty-bank-hint {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 0.8rem;
  width: 100%;
}
.empty-bank-hint .hint-icon {
  font-size: 1.4rem;
  filter: grayscale(0.2);
}
.empty-bank-hint .hint-text {
  font-style: italic;
  line-height: 1.3;
}
.horizontal-photo-bank {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  width: 100%;
  height: 100%;
  align-items: center;
  padding: 4px 0;
}
/* Style scrollbar cho photo bank ngang */
.horizontal-photo-bank::-webkit-scrollbar {
  height: 4px;
}
.horizontal-photo-bank::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.12);
  border-radius: 2px;
}
.horizontal-photo-bank::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}

.bank-photo-thumb {
  position: relative;
  height: 72px;
  aspect-ratio: 3/4;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1.5px solid var(--glass-border);
  cursor: grab;
  flex-shrink: 0;
  transition: var(--transition);
  background: white;
  user-select: none;
}
.bank-photo-thumb:hover {
  border-color: var(--accent-1);
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}
.bank-photo-thumb:active {
  cursor: grabbing;
}
.bank-photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}
.bank-photo-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: flex-end;
  gap: 2px;
  padding: 2px;
  opacity: 0;
  transition: opacity 0.2s;
  background: linear-gradient(rgba(0,0,0,0.3) 0%, transparent 100%);
}
.bank-photo-thumb:hover .bank-photo-overlay {
  opacity: 1;
}
.bank-thumb-btn {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  color: white;
}
.bank-thumb-btn.thumb-fill {
  background: rgba(16, 185, 129, 0.85);
}
.bank-thumb-btn.thumb-fill:hover {
  background: rgba(16, 185, 129, 1);
  transform: scale(1.1);
}
.bank-thumb-btn.thumb-remove {
  background: rgba(239, 68, 68, 0.85);
}
.bank-thumb-btn.thumb-remove:hover {
  background: rgba(239, 68, 68, 1);
  transform: scale(1.1);
}
.bank-drag-hint {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  font-size: 0.6rem;
  text-align: center;
  background: linear-gradient(transparent 0%, rgba(0,0,0,0.7) 100%);
  color: white;
  padding: 8px 2px 2px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.bank-photo-thumb:hover .bank-drag-hint {
  opacity: 1;
}

/* ===== DRAG & DROP INSTRUCTION BANNER ===== */
.drag-instruction-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  background: #eff6ff; /* Blue 50 */
  border-bottom: 1px solid #dbeafe; /* Blue 100 */
  color: #1e40af; /* Blue 800 */
  font-size: 0.82rem;
  flex-shrink: 0;
  transition: var(--transition);
  user-select: none;
}
.drag-instruction-banner.highlight-pulse {
  background: #fdf2f8; /* Pink 50 */
  border-bottom: 1px solid #fce7f3; /* Pink 100 */
  color: #9d174d; /* Pink 800 */
  animation: pulseBg 2.5s infinite ease-in-out;
}
@keyframes pulseBg {
  0%, 100% { background-color: #eff6ff; border-bottom-color: #dbeafe; color: #1e40af; }
  50% { background-color: #fdf2f8; border-bottom-color: #fce7f3; color: #9d174d; }
}

.instruction-icon {
  font-size: 1rem;
}
.instruction-text {
  font-weight: 500;
}
.instruction-arrow-anim {
  font-weight: bold;
  font-size: 1rem;
  animation: bounceDown 1.2s infinite ease-in-out;
  display: inline-block;
}
@keyframes bounceDown {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(3px); }
}

/* ===== A4 SECTION ===== */
.a4-section { display: flex; flex-direction: column; background: var(--bg-primary); }
.a4-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; border-bottom: 1px solid var(--glass-border);
  background: var(--bg-secondary); flex-shrink: 0;
}
.a4-info-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  font-size: 0.72rem; font-weight: 500; padding: 4px 10px; border-radius: 20px;
  background: var(--bg-tertiary); border: 1px solid var(--glass-border); color: var(--text-secondary);
}
.chip-accent {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(139, 92, 246, 0.05));
  border-color: rgba(59, 130, 246, 0.2); color: var(--accent-1);
}
.btn-icon {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border); background: var(--bg-secondary);
  color: var(--text-secondary); cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: var(--transition);
}
.btn-icon:hover:not(:disabled) { border-color: var(--error); color: var(--error); background: #fef2f2; }
.btn-icon:disabled { opacity: 0.3; cursor: not-allowed; }

.a4-scroll-area {
  flex: 1; overflow: auto;
  display: flex; align-items: flex-start; justify-content: center; padding: 24px;
  background: #e2e8f0; /* Darker Slate for maximum contrast against white A4 */
}
.a4-paper-wrapper { width: 100%; max-width: 595px; }
.a4-paper {
  width: 100%; aspect-ratio: 210 / 297;
  background: white; border-radius: 4px;
  box-shadow: 
    0 10px 25px -5px rgba(0, 0, 0, 0.1), 
    0 8px 10px -6px rgba(0, 0, 0, 0.1),
    0 0 0 1px rgba(0, 0, 0, 0.04);
  position: relative; overflow: hidden;
}

/* ===== MARGIN GUIDE ===== */
.margin-guide {
  position: absolute;
  border: 1px dashed rgba(59, 130, 246, 0.25);
  border-radius: 2px;
  pointer-events: none;
  z-index: 1;
}

/* ===== PLACED ITEMS ===== */
.placed-item {
  position: absolute; overflow: hidden; border-radius: 2px;
  cursor: grab; user-select: none;
  transition: opacity 0.15s, outline-color 0.15s;
  outline: 1px solid transparent;
  z-index: 2;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.placed-item.show-cuts {
  outline: 1.2px dashed rgba(0,0,0,0.3);
  outline-offset: -0.5px;
}
.placed-item:hover { z-index: 10; box-shadow: 0 4px 10px rgba(0,0,0,0.25); }
.placed-item:active { cursor: grabbing; }
.placed-item.is-hidden { opacity: 0.15; pointer-events: none; }

.placed-photo {
  width: 100%; height: 100%; object-fit: cover; display: block;
  pointer-events: none;
}

/* ===== ITEM CONTROLS ===== */
.item-controls {
  position: absolute; top: 3px; right: 3px;
  display: flex; gap: 3px; opacity: 0; transition: opacity 0.15s;
}
.placed-item:hover .item-controls { opacity: 1; }
.ctrl-btn {
  width: 22px; height: 22px; border-radius: 5px; border: none;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 11px; box-shadow: 0 1px 4px rgba(0,0,0,0.25); transition: var(--transition);
}
.ctrl-rotate { background: rgba(59, 130, 246, 0.9); color: white; }
.ctrl-rotate:hover { background: rgba(59, 130, 246, 1); transform: scale(1.15); }
.ctrl-remove { background: rgba(239, 68, 68, 0.9); color: white; font-size: 13px; font-weight: 600; }
.ctrl-remove:hover { background: rgba(239, 68, 68, 1); transform: scale(1.15); }

/* ===== ORIENT BADGE ===== */
.orient-badge {
  position: absolute; bottom: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 4px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(4px);
  color: #334155; font-size: 9px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.15s; pointer-events: none;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.placed-item:hover .orient-badge { opacity: 1; }
.orient-badge.portrait { color: var(--accent-1); }
.orient-badge.landscape { color: var(--warning); }

/* ===== GHOST PREVIEW ===== */
.ghost-preview {
  position: absolute;
  border: 2px solid var(--accent-1);
  border-radius: 3px;
  overflow: hidden;
  pointer-events: none;
  z-index: 50;
  opacity: 0.75;
  box-shadow: 0 0 16px rgba(59, 130, 246, 0.35);
  transition: opacity 0.1s;
}
.ghost-preview.invalid {
  border-color: var(--error);
  opacity: 0.5;
  box-shadow: 0 0 16px rgba(239, 68, 68, 0.35);
}
.ghost-preview img {
  width: 100%; height: 100%;
  object-fit: cover; display: block;
}

/* ===== SNAP GUIDES ===== */
.snap-guide {
  position: absolute;
  background: var(--snap-color);
  pointer-events: none;
  z-index: 60;
}
.snap-x {
  width: 1.5px;
  top: 0; bottom: 0;
}
.snap-y {
  height: 1.5px;
  left: 0; right: 0;
}

/* ===== A4 EMPTY STATE ===== */
.a4-empty-state {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: rgba(0, 0, 0, 0.25); text-align: center; gap: 8px;
  pointer-events: none;
  user-select: none;
  padding: 24px;
}
.empty-icon { font-size: 2.8rem; margin-bottom: 4px; }
.a4-empty-state p { font-size: 0.95rem; font-weight: 500; }
.empty-sub { font-size: 0.78rem; opacity: 0.7; }

/* ===== DRAG FLOAT (cursor follower) ===== */
.drag-float {
  position: fixed; z-index: 9999;
  width: 52px; height: 70px;
  border-radius: 6px; overflow: hidden;
  box-shadow: 0 8px 30px rgba(0,0,0,0.18);
  border: 2px solid var(--accent-1);
  opacity: 0.85;
  pointer-events: none;
  transform: translate(-50%, -50%);
}
.drag-float img { width: 100%; height: 100%; object-fit: cover; }

/* ===== EXPORT PANEL ===== */
.export-buttons { display: flex; flex-direction: column; gap: 8px; }
.btn-export {
  display: flex; align-items: center; gap: 12px;
  padding: 14px; border-radius: var(--radius-md);
  border: 1.5px solid var(--glass-border); background: var(--bg-tertiary);
  color: var(--text-primary); cursor: pointer; font-family: var(--font);
  transition: var(--transition); text-align: left;
}
.btn-export:hover:not(:disabled) { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-export:disabled { opacity: 0.35; cursor: not-allowed; }
.export-icon { font-size: 1.4rem; flex-shrink: 0; }
.export-info { display: flex; flex-direction: column; }
.export-label { font-weight: 600; font-size: 0.88rem; }
.export-detail { font-size: 0.7rem; color: var(--text-secondary); margin-top: 2px; }

.export-png:hover:not(:disabled) { border-color: var(--success); background: #ecfdf5; color: #065f46; }
.export-png:hover:not(:disabled) .export-detail { color: #047857; }
.export-pdf:hover:not(:disabled) { border-color: var(--error); background: #fef2f2; color: #991b1b; }
.export-pdf:hover:not(:disabled) .export-detail { color: #b91c1c; }
.export-print:hover:not(:disabled) { border-color: var(--accent-1); background: #eff6ff; color: #1e40af; }
.export-print:hover:not(:disabled) .export-detail { color: #1d4ed8; }

/* ===== INFO ===== */
.info-list { display: flex; flex-direction: column; gap: 2px; }
.info-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--glass-border);
}
.info-row:last-child { border-bottom: none; }
.info-label { font-size: 0.78rem; color: var(--text-secondary); }
.info-value { font-size: 0.82rem; font-weight: 600; color: var(--text-primary); }
.info-value.highlight { color: var(--accent-1); }

/* ===== GUIDE STEPS ===== */
.guide-steps { display: flex; flex-direction: column; gap: 10px; }
.guide-step { display: flex; align-items: center; gap: 10px; font-size: 0.78rem; color: var(--text-secondary); line-height: 1.4; }
.step-num {
  width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent-gradient); color: white; font-weight: 700; font-size: 0.7rem;
  display: flex; align-items: center; justify-content: center;
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(8px); display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal-dialog {
  background: var(--bg-secondary); border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl); width: 100%; max-width: 700px; max-height: 90vh;
  display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
  animation: modalIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-sm { max-width: 400px; }
@keyframes modalIn { from { opacity: 0; transform: scale(0.97) translateY(8px); } to { opacity: 1; transform: none; } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--glass-border);
  background: var(--bg-tertiary);
  border-top-left-radius: var(--radius-xl);
  border-top-right-radius: var(--radius-xl);
}
.modal-header h2 { font-size: 1rem; font-weight: 600; color: var(--text-primary); }
.modal-close {
  width: 30px; height: 30px; border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border); background: var(--bg-secondary);
  color: var(--text-secondary); cursor: pointer; font-size: 1.2rem;
  display: flex; align-items: center; justify-content: center; transition: var(--transition);
}
.modal-close:hover { color: var(--error); border-color: var(--error); background: #fef2f2; }
.modal-body { padding: 20px 22px; overflow: auto; flex: 1; }
.crop-container { width: 100%; max-height: 450px; overflow: hidden; background: #000; border-radius: var(--radius-sm); }
.crop-container img { display: block; max-width: 100%; }
.modal-footer {
  padding: 14px 22px; border-top: 1px solid var(--glass-border);
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-tertiary);
  border-bottom-left-radius: var(--radius-xl);
  border-bottom-right-radius: var(--radius-xl);
}
.crop-hint { font-size: 0.75rem; color: var(--text-secondary); }
.modal-btns { display: flex; gap: 8px; }
.btn-modal {
  padding: 9px 20px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--glass-border); background: var(--bg-secondary);
  color: var(--text-secondary); cursor: pointer;
  font-family: var(--font); font-size: 0.85rem; font-weight: 500;
  display: flex; align-items: center; gap: 6px; transition: var(--transition);
}
.btn-modal:hover { border-color: var(--text-secondary); color: var(--text-primary); }
.btn-confirm { background: var(--accent-gradient); border-color: transparent; color: white; }
.btn-confirm:hover { opacity: 0.9; border-color: transparent; color: white; box-shadow: var(--shadow-glow); }

/* ===== TOASTS ===== */
.toast-stack {
  position: fixed; bottom: 24px; right: 24px; z-index: 2000;
  display: flex; flex-direction: column-reverse; gap: 8px;
}
.toast {
  padding: 12px 18px; border-radius: var(--radius-md);
  background: var(--bg-secondary); border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-md);
  font-size: 0.82rem; font-weight: 500;
  display: flex; align-items: center; gap: 8px; max-width: 360px;
}
.toast-icon { font-size: 1rem; }
.toast-success { border-color: var(--success); color: #065f46; background: #ecfdf5; }
.toast-error { border-color: var(--error); color: #991b1b; background: #fef2f2; }
.toast-info { border-color: var(--accent-1); color: #1e40af; background: #eff6ff; }
.toast-enter-active { animation: toastIn 0.35s cubic-bezier(0.16, 1, 0.3, 1); }
.toast-leave-active { animation: toastOut 0.25s ease-in forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(20px) scale(0.95); } to { opacity: 1; transform: none; } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateY(-10px) scale(0.95); } }
.modal-enter-active { animation: modalIn 0.3s cubic-bezier(0.16, 1, 0.3, 1); }
.modal-leave-active { animation: modalOut 0.2s ease-in forwards; }
@keyframes modalOut { from { opacity: 1; } to { opacity: 0; } }
.fade-enter-active, .fade-leave-active { transition: opacity 0.3s; }
.fade-enter-from, .fade-leave-to { opacity: 0; }

/* ===== LOADING ===== */
.loading-overlay {
  position: fixed; inset: 0; z-index: 3000;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; color: white; font-size: 0.9rem;
}
.loading-spinner {
  width: 40px; height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.25); border-top-color: var(--accent-1);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== MOBILE: SELECTED BANK PHOTO ===== */
.bank-photo-thumb.bank-selected {
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3), var(--shadow-glow);
  transform: translateY(-2px);
}
.bank-photo-thumb.bank-selected::after {
  content: '✓';
  position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent-1); color: white;
  font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  z-index: 5;
}

/* ===== MOBILE: SELECTED PHOTO INDICATOR BAR ===== */
.mobile-selected-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: #ecfdf5; /* Emerald 50 */
  border-bottom: 1px solid #a7f3d0; /* Emerald 200 */
  flex-shrink: 0;
  animation: slideDown 0.2s ease-out;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}
.selected-preview {
  width: 36px; height: 48px;
  border-radius: 4px; overflow: hidden;
  border: 1.5px solid var(--accent-1);
  flex-shrink: 0;
}
.selected-preview img {
  width: 100%; height: 100%; object-fit: cover;
}
.selected-text {
  font-size: 0.78rem; font-weight: 600;
  color: #065f46; /* Emerald 800 */
  flex: 1;
}
.btn-deselect {
  padding: 5px 12px; border-radius: var(--radius-sm);
  border: 1px solid #d1d5db; background: white;
  color: var(--text-secondary); cursor: pointer;
  font-family: var(--font); font-size: 0.72rem; font-weight: 500;
  transition: var(--transition); white-space: nowrap;
}
.btn-deselect:hover { border-color: var(--error); color: var(--error); }



/* ===== RESPONSIVE ===== */
@media (max-width: 1200px) {
  .app-main { grid-template-columns: 200px 1fr 200px; }
  .a4-scroll-area { padding-bottom: 80px; }
}

@media (max-width: 800px) {
  .app-main {
    display: flex;
    flex-direction: column;
  }
  .panel {
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--glass-border);
    border-left: none;
  }
  .a4-scroll-area { padding: 12px; padding-bottom: 40px; }

  /* Right panel flows naturally at bottom */
  .panel-right {
    border-top: none;
  }
  .panel-right .panel-section { min-width: auto; width: 100%; flex-shrink: 0; }

  /* Header adjustments */
  .header-content { flex-direction: row; gap: 8px; }
  .logo h1 { font-size: 1rem; }
  .subtitle { display: none; }
  .btn-restart span { display: none; }

  /* Instruction banner compact */
  .drag-instruction-banner { font-size: 0.75rem; padding: 6px 12px; }

  /* Item controls hidden on mobile, using tap dialog instead */
  .placed-item .item-controls { display: none !important; }
  .placed-item .orient-badge { opacity: 0.85; }

  /* Touch-action to prevent browser gestures on draggables */
  .bank-photo-thumb,
  .placed-item {
    touch-action: none;
  }

  /* Setup card responsive */
  .setup-card { margin: 12px; }
  .setup-body { padding: 16px 20px; }
  .setup-header { padding: 20px; }
  .setup-footer { padding: 16px 20px 24px; }
  .setup-presets { grid-template-columns: 1fr 1fr !important; }
  .btn-setup-start { padding: 12px 28px; font-size: 0.9rem; }
}

/* ===== PRINT ===== */
@media print {
  body { background: white !important; background-image: none !important; }
  .app-header, .panel, .a4-toolbar, .toast-stack, .loading-overlay,
  .item-controls, .orient-badge, .a4-empty-state, .modal-overlay,
  .drag-float, .ghost-preview, .snap-guide, .margin-guide,
  .workspace-top-bar, .drag-instruction-banner, .mobile-fab,
  .mobile-selected-bar { display: none !important; }
  .app-main { display: block !important; }
  .a4-section { display: block !important; }
  .a4-scroll-area { padding: 0 !important; overflow: visible !important; display: block !important; background: white !important; }
  .a4-paper-wrapper { max-width: none !important; width: 100% !important; }
  .a4-paper {
    width: 210mm !important; height: 297mm !important; aspect-ratio: auto !important;
    box-shadow: none !important; border-radius: 0 !important; margin: 0 !important;
  }
  .placed-item { outline: none !important; cursor: default !important; box-shadow: none !important; }
  .placed-item.show-cuts { outline: 0.5pt dashed rgba(0,0,0,0.3) !important; }
  .placed-item.is-hidden { opacity: 1 !important; pointer-events: auto !important; }
  @page { size: A4; margin: 0; }
}

