/* ============================================================
   MEDIAKALTIM BLUR GRID — Liquid Glass SaaS Design System
   Mengikuti standar desain Media Kaltim (Fustat + Inter)
   Background: #F8FAFC | Primary: #0084FF | Glass Cards
   ============================================================ */

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

/* ── CSS Custom Properties ──────────────────────────────────── */
:root {
  /* Core Palette */
  --primary:        #0084FF;
  --primary-hover:  #006FD6;
  --primary-dim:    rgba(0, 132, 255, 0.10);
  --primary-glow:   rgba(0, 132, 255, 0.25);
  --primary-soft:   rgba(0, 132, 255, 0.06);

  --success:        #28C76F;
  --success-dim:    rgba(40, 199, 111, 0.12);
  --warning:        #FF9F43;
  --warning-dim:    rgba(255, 159, 67, 0.12);
  --danger:         #EA5455;
  --danger-dim:     rgba(234, 84, 85, 0.12);
  --info:           #00CFE8;
  --info-dim:       rgba(0, 207, 232, 0.12);

  /* Text */
  --text-dark:      #0F172A;
  --text-body:      #334155;
  --text-muted:     #64748B;
  --text-light:     #94A3B8;

  /* Background */
  --bg-page:        #F8FAFC;
  --bg-white:       #FFFFFF;
  --bg-subtle:      #F1F5F9;
  --bg-subtle2:     #E2E8F0;

  /* Glass Cards */
  --glass-bg:       rgba(255, 255, 255, 0.80);
  --glass-bg-heavy: rgba(255, 255, 255, 0.92);
  --glass-border:   rgba(0, 0, 0, 0.06);
  --glass-border2:  rgba(255, 255, 255, 0.85);
  --glass-shadow:   0 4px 24px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
  --glass-shadow-hover: 0 8px 32px rgba(0, 132, 255, 0.12), 0 2px 8px rgba(0,0,0,0.06);

  /* Borders */
  --border:         rgba(0, 0, 0, 0.07);
  --border-light:   rgba(0, 0, 0, 0.04);

  /* Spacing */
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px;
  --space-4: 16px; --space-5: 20px; --space-6: 24px;
  --space-8: 32px; --space-10: 40px; --space-12: 48px;

  /* Radius */
  --r-sm:   6px;  --r-md:   10px; --r-lg:   16px;
  --r-xl:   20px; --r-2xl:  24px; --r-full: 9999px;

  /* Shadows */
  --shadow-card: var(--glass-shadow);
  --shadow-btn:  0 2px 10px rgba(0, 132, 255, 0.30);
  --shadow-btn-hover: 0 4px 18px rgba(0, 132, 255, 0.45);

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --fast: 150ms var(--ease);
  --med:  250ms var(--ease);
  --slow: 380ms var(--ease);

  /* Z-index */
  --z-header:  100;
  --z-modal:   1000;
  --z-toast:   1100;
}

/* ── Reset & Base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-font-smoothing: antialiased; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-body);
  background: var(--bg-page);
  /* Ambient radial gradient — khas halaman publik Media Kaltim */
  background-image:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(0, 132, 255, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 110%, rgba(0, 207, 232, 0.05) 0%, transparent 60%);
  background-attachment: fixed;
  min-height: 100vh;
  overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 {
  font-family: 'Fustat', 'Inter', sans-serif;
  font-weight: 800;
  color: var(--text-dark);
  line-height: 1.3;
}

img, canvas { display: block; max-width: 100%; }

/* ── Scrollbar ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg-subtle); }
::-webkit-scrollbar-thumb { background: var(--bg-subtle2); border-radius: var(--r-full); }
::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

/* ── App Wrapper ─────────────────────────────────────────────── */
.app-wrapper { display: flex; flex-direction: column; min-height: 100vh; }

/* ── HEADER ──────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 10px var(--space-6);
  background: var(--glass-bg-heavy);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
  box-shadow: 0 1px 8px rgba(0,0,0,0.06);
  position: sticky;
  top: 0;
  z-index: var(--z-header);
}

/* Logo */
.logo {
  display: flex; align-items: center; gap: var(--space-3);
  text-decoration: none; flex-shrink: 0;
}
.logo img { height: 38px; width: auto; max-width: 150px; object-fit: contain; }
.logo-text { line-height: 1.2; }
.logo-text strong {
  display: block; font-family: 'Fustat', sans-serif;
  font-weight: 800; font-size: 0.95rem; color: var(--text-dark);
}
.logo-text span { font-size: 0.7rem; color: var(--text-muted); font-weight: 500; }

/* Step Navigation */
.step-nav { display: flex; align-items: center; flex: 1; justify-content: center; }

.step-nav-item {
  display: flex; align-items: center; gap: var(--space-2);
  padding: 6px 14px; border-radius: var(--r-full); cursor: pointer;
  transition: all var(--med); user-select: none;
}
.step-nav-item:hover {
  background: var(--primary-soft);
}

.step-num {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--bg-subtle); border: 2px solid var(--bg-subtle2);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.72rem; font-weight: 700; color: var(--text-muted);
  transition: all var(--med); flex-shrink: 0;
}

.step-nav-item span {
  font-size: 0.8rem; font-weight: 600; color: var(--text-muted);
  white-space: nowrap; transition: color var(--fast);
}

.step-nav-item.active .step-num {
  background: var(--primary); border-color: var(--primary);
  color: white; box-shadow: 0 0 0 4px var(--primary-dim);
}
.step-nav-item.active span { color: var(--primary); }

.step-nav-item.done .step-num {
  background: var(--success); border-color: var(--success); color: white;
}
.step-nav-item.done span { color: var(--success); }

.step-connector {
  width: 36px; height: 2px;
  background: var(--bg-subtle2); flex-shrink: 0; margin: 0 2px;
  transition: background var(--med);
}
.step-nav-item.done + .step-connector { background: var(--success); }

/* Header Actions */
.header-actions {
  display: flex; gap: var(--space-2); flex-shrink: 0; align-items: center;
}

/* Detector Status */
.detector-status {
  font-size: 0.7rem; font-weight: 600; color: var(--text-muted);
  background: var(--bg-subtle); border: 1px solid var(--border);
  border-radius: var(--r-full); padding: 4px 12px; white-space: nowrap;
}
.detector-status.ready {
  color: var(--success); background: var(--success-dim);
  border-color: rgba(40,199,111,0.2);
}
.detector-status.error {
  color: var(--warning); background: var(--warning-dim);
  border-color: rgba(255,159,67,0.2);
}

/* ── BUTTONS ─────────────────────────────────────────────────── */
button { cursor: pointer; font-family: 'Inter', sans-serif; }

.btn-primary {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: 9px 20px;
  background: var(--primary); color: white;
  font-weight: 600; font-size: 0.85rem;
  border: none; border-radius: var(--r-md);
  box-shadow: var(--shadow-btn);
  transition: all var(--fast); white-space: nowrap;
}
.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-btn-hover);
}
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled {
  background: var(--bg-subtle2); color: var(--text-light);
  cursor: not-allowed; box-shadow: none; transform: none;
}

.btn-secondary {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: 8px 16px;
  background: var(--bg-white); color: var(--text-body);
  font-weight: 500; font-size: 0.85rem;
  border: 1px solid var(--border); border-radius: var(--r-md);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  transition: all var(--fast); white-space: nowrap;
}
.btn-secondary:hover {
  border-color: var(--primary); color: var(--primary);
  box-shadow: 0 2px 8px rgba(0,132,255,0.1);
  transform: translateY(-1px);
}

.btn-ghost {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: 8px 14px;
  background: transparent; color: var(--text-muted);
  font-weight: 500; font-size: 0.85rem;
  border: 1px solid transparent; border-radius: var(--r-md);
  transition: all var(--fast);
}
.btn-ghost:hover {
  background: var(--bg-subtle); color: var(--text-body);
  border-color: var(--border);
}

.btn-danger {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: 8px 16px;
  background: var(--danger); color: white;
  font-weight: 600; font-size: 0.85rem;
  border: none; border-radius: var(--r-md);
  transition: all var(--fast);
}
.btn-danger:hover { background: #d43c3d; transform: translateY(-1px); }

.btn-icon {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: var(--glass-bg); color: var(--text-muted);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  transition: all var(--fast); flex-shrink: 0;
}
.btn-icon:hover { background: var(--primary-dim); color: var(--primary); border-color: rgba(0,132,255,0.2); }
.btn-icon svg { pointer-events: none; }

/* ── STEP SECTIONS ───────────────────────────────────────────── */
.step-section { display: none !important; flex: 1; animation: fadeUp 0.3s var(--ease); }
.step-section.active { display: flex !important; flex-direction: column; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── STEP 1: UPLOAD ──────────────────────────────────────────── */
.upload-section {
  flex: 1;
  align-items: center; justify-content: center;
  padding: var(--space-8) var(--space-6);
  min-height: calc(100vh - 62px);
}

.upload-zone {
  width: 100%; max-width: 600px;
  border: 2px dashed var(--bg-subtle2);
  border-radius: var(--r-2xl);
  padding: var(--space-12) var(--space-8);
  text-align: center; cursor: pointer;
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--glass-shadow);
  transition: all var(--med);
  position: relative; overflow: hidden;
}
.upload-zone::before {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(ellipse 70% 70% at 50% 50%, rgba(0,132,255,0.04) 0%, transparent 70%);
  opacity: 0; transition: opacity var(--med);
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--primary); border-style: solid;
  box-shadow: var(--glass-shadow-hover);
  transform: translateY(-2px);
}
.upload-zone:hover::before, .upload-zone.drag-over::before { opacity: 1; }

.upload-icon-wrap {
  width: 72px; height: 72px; margin: 0 auto var(--space-5);
  background: var(--primary-dim); border-radius: var(--r-xl);
  display: flex; align-items: center; justify-content: center;
  position: relative; z-index: 1; transition: all var(--med);
}
.upload-icon-wrap svg { color: var(--primary); }
.upload-zone:hover .upload-icon-wrap {
  background: rgba(0,132,255,0.15);
  transform: scale(1.08);
  box-shadow: 0 0 20px var(--primary-glow);
}

.upload-title {
  font-family: 'Fustat', sans-serif; font-size: 1.3rem; font-weight: 800;
  color: var(--text-dark); margin-bottom: var(--space-2);
  position: relative; z-index: 1;
}
.upload-subtitle {
  font-size: 0.875rem; color: var(--text-muted);
  position: relative; z-index: 1;
}
.upload-meta {
  display: flex; gap: var(--space-3); justify-content: center;
  flex-wrap: wrap; margin-top: var(--space-6);
  position: relative; z-index: 1;
}
.upload-meta-item {
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.75rem; color: var(--text-muted); font-weight: 500;
  background: var(--bg-subtle); padding: 6px 14px;
  border-radius: var(--r-full); border: 1px solid var(--border);
  letter-spacing: 0.01em;
}

/* ── STEP 2: EDIT & ARRANGE ──────────────────────────────────── */
.edit-section {
  flex: 1;
  height: calc(100vh - 62px);
  overflow: hidden;
}

.edit-layout {
  display: grid;
  grid-template-columns: 280px 1fr 290px;
  height: 100%;
  overflow: hidden;
}

/* Controls Panel — Glass Card */
.controls-panel {
  background: var(--glass-bg-heavy);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-right: 1px solid var(--glass-border);
  padding: var(--space-5);
  overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--space-5);
}

.panel-title {
  font-family: 'Fustat', sans-serif;
  font-size: 0.7rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--text-muted);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border);
}

.control-group { display: flex; flex-direction: column; gap: var(--space-3); }

.control-label {
  font-size: 0.78rem; font-weight: 600; color: var(--text-muted);
  display: flex; justify-content: space-between; align-items: center;
}
.control-label span { color: var(--primary); font-weight: 700; }

/* Layout Presets */
.layout-presets {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(65px, 1fr));
  gap: var(--space-2);
  width: 100%;
}

.preset-btn {
  min-height: 56px;
  width: 100%;
  background: var(--bg-white);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--fast);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 3px;
  padding: 4px 2px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  overflow: hidden;
  box-sizing: border-box;
}
.preset-btn span {
  font-size: 0.62rem;
  line-height: 1.1;
  text-align: center;
  font-weight: 600;
  word-break: break-word;
  max-width: 100%;
}
.preset-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0,132,255,0.12);
}
.preset-btn.active {
  border-color: var(--primary);
  background: var(--primary-dim);
  color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.preset-icon {
  width: 24px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.preset-icon svg {
  width: 24px;
  height: 20px;
  fill: currentColor;
  opacity: 0.85;
}

/* Sliders */
input[type="range"] {
  -webkit-appearance: none; flex: 1; height: 4px;
  background: var(--bg-subtle2); border-radius: var(--r-full);
  outline: none; cursor: pointer; transition: background var(--fast);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px;
  background: var(--primary); border-radius: 50%;
  box-shadow: 0 0 0 3px var(--primary-dim), 0 2px 6px rgba(0,132,255,0.3);
  transition: transform var(--fast);
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; background: var(--primary);
  border: none; border-radius: 50%;
}

/* Select dropdown */
.custom-select {
  width: 100%; padding: 7px 10px;
  background: var(--bg-white); border: 1.5px solid var(--border);
  border-radius: var(--r-sm); color: var(--text-dark);
  font-family: 'Inter', sans-serif; font-size: 0.8rem; font-weight: 500;
  outline: none; cursor: pointer; transition: border-color var(--fast);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.custom-select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-dim); }

/* Number inputs */
.num-input-row { display: flex; align-items: center; gap: var(--space-2); }
input[type="number"] {
  width: 52px; padding: 6px;
  background: var(--bg-white); border: 1.5px solid var(--border);
  border-radius: var(--r-sm); color: var(--text-dark);
  font-family: 'Inter', sans-serif; font-size: 0.875rem;
  text-align: center; outline: none; transition: border-color var(--fast);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
input[type="number"]:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-dim); }
input[type="number"]::-webkit-inner-spin-button { opacity: 0.5; }

/* Color input */
.color-wrap { display: flex; align-items: center; gap: var(--space-3); }
input[type="color"] {
  width: 38px; height: 30px;
  border: 1.5px solid var(--border); border-radius: var(--r-sm);
  background: transparent; cursor: pointer; padding: 2px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

/* Photo Grid Area */
.photo-grid-area {
  background: var(--bg-page);
  padding: var(--space-5);
  overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--space-4);
}

.grid-area-header {
  display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
}
.grid-area-title {
  font-family: 'Fustat', sans-serif;
  font-size: 0.9rem; font-weight: 800; color: var(--text-dark);
}
.photo-count-badge {
  font-size: 0.72rem; font-weight: 600; color: var(--text-muted);
  background: var(--bg-white); border: 1px solid var(--border);
  border-radius: var(--r-full); padding: 3px 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--space-3); align-content: start;
}

/* Drag & drop highlight state for photo-grid-area */
.photo-grid-area.drag-over {
  border-color: var(--primary) !important;
  background: var(--primary-dim) !important;
  box-shadow: inset 0 0 20px var(--primary-glow);
}

/* Add Photo Card inside Grid */
.add-photo-card {
  background: var(--glass-bg);
  border: 2px dashed var(--bg-subtle2);
  border-radius: var(--r-lg);
  aspect-ratio: 4/3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  color: var(--primary);
  transition: all var(--med);
  backdrop-filter: blur(8px);
  padding: var(--space-3);
  text-align: center;
  user-select: none;
}
.add-photo-card:hover {
  border-color: var(--primary);
  border-style: solid;
  background: var(--primary-dim);
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(0, 132, 255, 0.18);
}
.add-photo-card svg {
  color: var(--primary);
  transition: transform var(--fast);
}
.add-photo-card:hover svg {
  transform: scale(1.18);
}
.add-photo-card span {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--primary);
}

/* Thumbnail Card — Glass Card */
.thumb-card {
  background: var(--glass-bg-heavy);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-lg);
  overflow: hidden; cursor: grab;
  box-shadow: var(--glass-shadow);
  transition: all var(--med);
  animation: slideInCard 0.3s var(--ease);
  backdrop-filter: blur(8px);
  user-select: none;
}
@keyframes slideInCard {
  from { opacity: 0; transform: scale(0.93) translateY(6px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.thumb-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--glass-shadow-hover);
  border-color: rgba(0,132,255,0.12);
}
.thumb-card:active { cursor: grabbing; }

.thumb-img-wrap {
  position: relative; aspect-ratio: 4/3; overflow: hidden;
  background: var(--bg-subtle);
}
.thumb-canvas { width: 100%; height: 100%; object-fit: cover; }

.thumb-overlay {
  position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(15,23,42,0.55) 0%, transparent 55%);
  opacity: 0; transition: opacity var(--fast);
  display: flex; flex-direction: column;
  justify-content: space-between; padding: var(--space-2);
}
.thumb-card:hover .thumb-overlay { opacity: 1; }
.thumb-status { display: flex; align-items: flex-start; justify-content: flex-end; }
.thumb-actions { display: flex; gap: 5px; justify-content: flex-end; align-self: flex-end; }

/* Override btn-icon style inside thumb overlay for better contrast */
.thumb-overlay .btn-icon {
  background: rgba(255,255,255,0.9);
  color: var(--text-muted); border-color: rgba(0,0,0,0.08);
  width: 28px; height: 28px;
}
.thumb-overlay .btn-icon:hover { background: white; color: var(--primary); }

.thumb-info {
  padding: var(--space-2) var(--space-3);
  display: flex; flex-direction: column; gap: 2px;
  background: var(--glass-bg-heavy);
}
.thumb-name {
  font-size: 0.72rem; font-weight: 600; color: var(--text-body);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thumb-face-count { font-size: 0.65rem; font-weight: 700; }
.thumb-face-count.has-faces { color: var(--warning); }
.thumb-face-count.no-faces  { color: var(--text-light); }

/* Status Badges — pill-shaped */
.status-badge {
  width: 20px; height: 20px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.62rem; font-weight: 800;
}
.status-badge.badge-done  { background: var(--success); color: white; }
.status-badge.badge-error { background: var(--danger);  color: white; }
.status-badge.hidden      { display: none; }

/* Progress */
.progress-wrap { padding: 0 var(--space-3) var(--space-2); background: var(--glass-bg-heavy); }
.progress-bar {
  height: 3px; background: var(--bg-subtle);
  border-radius: var(--r-full); overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%; border-radius: var(--r-full);
  background: var(--primary); transition: width 0.4s var(--ease);
}
.progress-fill.done  { background: var(--success); }
.progress-fill.error { background: var(--danger); }

/* Sortable */
.sortable-ghost   { opacity: 0.35; border: 2px dashed var(--primary) !important; }
.sortable-chosen  { box-shadow: 0 8px 24px rgba(0,132,255,0.2) !important; }
.sortable-drag    { transform: rotate(1.5deg) scale(1.04); }

/* Spinner */
.status-spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--bg-subtle2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
.status-spinner.hidden { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Preview Panel */
.preview-panel {
  background: var(--glass-bg-heavy);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-left: 1px solid var(--glass-border);
  border-right: 1px solid var(--glass-border);
  padding: var(--space-5);
  display: flex; flex-direction: column; gap: var(--space-4);
  overflow: hidden;
}
.preview-panel-header {
  display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
}
.preview-panel-title {
  font-family: 'Fustat', sans-serif;
  font-size: 0.7rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-muted);
}

.preview-canvas-wrap {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  /* Checkerboard — neutral background for transparent canvases */
  background: repeating-conic-gradient(var(--bg-subtle) 0% 25%, var(--bg-white) 0% 50%)
              0 0 / 16px 16px;
  border-radius: var(--r-md); overflow: hidden;
  border: 1px solid var(--border);
  min-height: 180px;
  position: relative;
}
#preview-canvas, #expand-preview-canvas {
  max-width: 100%; max-height: 100%; border-radius: var(--r-sm);
  cursor: grab; touch-action: none; transition: box-shadow var(--fast);
}
#preview-canvas:active, #expand-preview-canvas:active {
  cursor: grabbing;
}

/* Preview Adjustment Bar */
.preview-adj-bar {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
  flex-shrink: 0;
  width: 100%;
  box-sizing: border-box;
}
.adj-header {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
}
.adj-title {
  font-size: 0.7rem; font-weight: 700; color: var(--text-dark);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1;
}
.btn-sm { padding: 3px 8px; font-size: 0.7rem; border-radius: var(--r-sm); }

.adj-controls { display: flex; flex-direction: column; gap: 6px; }
.adj-field { display: flex; flex-direction: column; gap: 2px; width: 100%; }
.adj-field label {
  font-size: 0.68rem; font-weight: 600; color: var(--text-muted);
  display: flex; justify-content: space-between; align-items: center;
}
.adj-field label span { color: var(--primary); font-weight: 700; }
.adj-field input[type="range"] { width: 100%; height: 4px; }

/* ── STEP 3: EXPORT ──────────────────────────────────────────── */
.export-section {
  flex: 1; padding: var(--space-8) var(--space-6);
  align-items: flex-start; justify-content: center;
  min-height: calc(100vh - 62px);
  gap: var(--space-6);
  width: 100%; max-width: 1100px; margin: 0 auto;
}
.export-section.active {
  display: flex !important;
  flex-direction: row !important;
  align-items: flex-start;
  justify-content: center;
}

/* Export Options — Glass Card */
.export-options-card {
  background: var(--glass-bg-heavy);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-2xl);
  padding: var(--space-6); width: 340px;
  display: flex; flex-direction: column; gap: var(--space-5);
  box-shadow: var(--glass-shadow); flex-shrink: 0;
}
.export-section-title {
  font-family: 'Fustat', sans-serif;
  font-size: 1.05rem; font-weight: 800; color: var(--text-dark);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border);
}
.export-opt-group { display: flex; flex-direction: column; gap: var(--space-2); }
.export-opt-label {
  font-size: 0.78rem; font-weight: 700;
  color: var(--text-muted); letter-spacing: 0.03em;
}

/* Format radio pills */
.format-options { display: flex; gap: var(--space-2); }
.format-radio { display: none; }
.format-label {
  flex: 1; padding: 9px; text-align: center;
  background: var(--bg-white); border: 1.5px solid var(--border);
  border-radius: var(--r-md); cursor: pointer;
  font-size: 0.85rem; font-weight: 700; color: var(--text-muted);
  transition: all var(--fast);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.format-radio:checked + .format-label {
  background: var(--primary-dim); border-color: var(--primary); color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.format-label:hover:not(:has(+ input:checked)) { border-color: var(--primary); color: var(--primary); }

/* Select */
select {
  width: 100%; padding: 9px 36px 9px 12px;
  background: var(--bg-white); color: var(--text-dark);
  border: 1.5px solid var(--border); border-radius: var(--r-md);
  font-family: 'Inter', sans-serif; font-size: 0.875rem;
  outline: none; cursor: pointer; transition: border-color var(--fast);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-dim); }

/* Size Estimate */
.size-estimate-row {
  background: var(--bg-subtle); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: var(--space-4);
  display: flex; flex-direction: column; gap: var(--space-2);
}
.size-row { display: flex; align-items: center; justify-content: space-between; }
.size-label { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; }
.size-value { font-size: 1.05rem; font-weight: 800; font-family: 'Fustat', sans-serif; color: var(--text-dark); }
.size-indicator { font-size: 0.72rem; font-weight: 700; }
.size-indicator.ok   { color: var(--success); }
.size-indicator.warn { color: var(--warning); }

.size-bar { height: 4px; background: var(--bg-subtle2); border-radius: var(--r-full); overflow: hidden; }
.size-bar-fill {
  height: 100%; border-radius: var(--r-full);
  background: var(--success); transition: width 0.4s var(--ease), background 0.3s;
}
.size-bar-fill.warn { background: var(--warning); }
.size-bar-fill.over { background: var(--danger); }

.export-btn-wrap { display: flex; flex-direction: column; gap: var(--space-2); }
#export-btn { width: 100%; justify-content: center; padding: 12px; font-size: 0.95rem; }
.export-note { font-size: 0.7rem; color: var(--text-light); text-align: center; line-height: 1.5; }

/* Export Preview Card */
.export-preview-card {
  flex: 1; min-width: 320px; max-width: 700px;
  background: var(--glass-bg-heavy);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-2xl); overflow: hidden;
  box-shadow: var(--glass-shadow);
  display: flex; flex-direction: column;
}
.export-preview-header {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  font-family: 'Fustat', sans-serif;
  font-size: 0.7rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--text-muted);
  display: flex; align-items: center; justify-content: space-between;
}
#export-preview {
  flex: 1; padding: var(--space-5);
  display: flex; align-items: center; justify-content: center;
  background: repeating-conic-gradient(var(--bg-subtle) 0% 25%, var(--bg-white) 0% 50%)
              0 0 / 16px 16px;
  min-height: 300px;
}
#export-canvas {
  max-width: 100%; max-height: 480px;
  border-radius: var(--r-md);
  box-shadow: 0 8px 32px rgba(0,0,0,0.10);
}

/* ── MANUAL BLUR MODAL ───────────────────────────────────────── */
.blur-modal {
  position: fixed; inset: 0; z-index: 1050;
  display: none; align-items: center; justify-content: center;
  padding: var(--space-4);
}
.blur-modal.visible { display: flex; }

.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: fadeUp 0.2s var(--ease);
}

.modal-container {
  position: relative; z-index: 1;
  background: var(--glass-bg-heavy);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border2);
  border-radius: var(--r-2xl);
  width: min(960px, 100%); max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.12), 0 4px 16px rgba(0,132,255,0.06);
  animation: modalIn 0.3s var(--ease);
  overflow: hidden;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(16px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0; flex-wrap: wrap;
  background: var(--glass-bg-heavy);
}
.modal-title {
  font-family: 'Fustat', sans-serif;
  font-size: 1rem; font-weight: 800; color: var(--text-dark);
}
.modal-photo-name { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; }

.brush-controls {
  display: flex; align-items: center; gap: var(--space-4);
  flex: 1; justify-content: center; flex-wrap: wrap;
}
.brush-control-item {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: 0.78rem; color: var(--text-muted); font-weight: 500;
}
.brush-control-item input[type="range"] { width: 100px; }
.brush-control-item strong {
  color: var(--primary); font-weight: 700;
  min-width: 24px; display: inline-block;
}

.modal-actions { display: flex; gap: var(--space-2); flex-shrink: 0; }
#modal-undo, #modal-redo {
  background: var(--bg-white); border: 1.5px solid var(--border);
  border-radius: var(--r-sm); color: var(--text-muted);
  font-size: 0.8rem; padding: 6px 12px; transition: all var(--fast);
  font-family: 'Inter', sans-serif;
}
#modal-undo:hover:not(:disabled), #modal-redo:hover:not(:disabled) {
  color: var(--primary); border-color: var(--primary);
  background: var(--primary-soft);
}
#modal-undo:disabled, #modal-redo:disabled { opacity: 0.35; cursor: not-allowed; }

.modal-canvas-area {
  flex: 1; overflow: auto;
  display: flex; align-items: flex-start; justify-content: center;
  padding: var(--space-5);
  background: var(--bg-subtle);
  position: relative;
}
#brush-canvas {
  cursor: none; border-radius: var(--r-lg);
  box-shadow: 0 8px 32px rgba(0,0,0,0.10);
  display: block;
}
#brush-cursor {
  position: absolute;
  border: 2px solid var(--primary);
  border-radius: 50%;
  pointer-events: none;
  background: rgba(0,132,255,0.07);
  box-shadow: 0 0 0 1px rgba(0,132,255,0.15);
  transition: width 0.1s, height 0.1s;
}

/* ── MODE SWITCHER & SHAPE SELECTOR ──────────────────────────── */
.mode-pill {
  padding: 5px 12px;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: var(--r-md);
  background: var(--bg-white);
  border: 1.5px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--fast);
  white-space: nowrap;
}
.mode-pill:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.mode-pill.active {
  background: var(--primary-dim);
  border-color: var(--primary);
  color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.shape-pill {
  padding: 4px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: var(--r-full);
  background: var(--bg-white);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--fast);
}
.shape-pill:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.shape-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  box-shadow: 0 2px 6px rgba(0, 132, 255, 0.3);
}

.canvas-wrapper-relative {
  position: relative;
  display: inline-block;
  user-select: none;
}

.blur-shapes-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.shape-box-item {
  position: absolute;
  border: 2px dashed rgba(0, 132, 255, 0.7);
  background: rgba(0, 132, 255, 0.08);
  box-sizing: border-box;
  pointer-events: auto;
  cursor: move;
  transition: border-color var(--fast), background var(--fast);
}
.shape-box-item.shape-oval { border-radius: 50%; }
.shape-box-item.shape-circle { border-radius: 50%; }
.shape-box-item.shape-rect { border-radius: 4px; }

.shape-box-item.selected {
  border: 2px solid var(--primary);
  background: rgba(0, 132, 255, 0.14);
  box-shadow: 0 0 0 2px rgba(0, 132, 255, 0.25);
  z-index: 10;
}

.shape-box-delete {
  position: absolute;
  top: -12px;
  right: -12px;
  width: 24px;
  height: 24px;
  background: var(--danger);
  color: white;
  border-radius: 50%;
  font-size: 13px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(234, 84, 85, 0.5);
  opacity: 0;
  transition: opacity var(--fast);
  z-index: 15;
  touch-action: manipulation;
}
.shape-box-delete::after {
  content: '';
  position: absolute;
  inset: -10px;
}
.shape-box-item:hover .shape-box-delete,
.shape-box-item.selected .shape-box-delete {
  opacity: 1;
}

.shape-box-handle {
  position: absolute;
  width: 16px;
  height: 16px;
  background: white;
  border: 2.5px solid var(--primary);
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  z-index: 12;
  touch-action: none;
}
.shape-box-handle::after {
  content: '';
  position: absolute;
  inset: -12px;
}
.shape-box-handle.nw { top: -8px; left: -8px; cursor: nwse-resize; }
.shape-box-handle.ne { top: -8px; right: -8px; cursor: nesw-resize; }
.shape-box-handle.sw { bottom: -8px; left: -8px; cursor: nesw-resize; }
.shape-box-handle.se { bottom: -8px; right: -8px; cursor: nwse-resize; }

/* ── PREVIEW EXPAND MODAL ────────────────────────────────────── */
.preview-expand-modal {
  position: fixed; inset: 0; z-index: var(--z-modal);
  display: none; align-items: center; justify-content: center;
  padding: var(--space-4);
}
.preview-expand-modal.visible { display: flex; }

.expand-modal-container {
  position: relative; z-index: 1;
  background: var(--glass-bg-heavy);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--glass-border2);
  border-radius: var(--r-2xl);
  width: min(1100px, 96vw); height: min(850px, 92vh);
  display: flex; flex-direction: column;
  box-shadow: 0 24px 72px rgba(0,0,0,0.18), 0 4px 20px rgba(0,132,255,0.08);
  animation: modalIn 0.3s var(--ease);
  overflow: hidden;
}

.expand-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border);
  background: var(--glass-bg-heavy);
  flex-shrink: 0;
}
.expand-modal-title h2 {
  font-size: 1.1rem; font-weight: 800; font-family: 'Fustat', sans-serif;
  color: var(--text-dark);
}
.expand-modal-title span {
  font-size: 0.75rem; color: var(--text-muted);
}

.expand-modal-body {
  flex: 1; overflow: hidden;
  display: flex; flex-direction: column; gap: var(--space-4);
  padding: var(--space-5);
  background: var(--bg-page);
}

.expand-canvas-wrap {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  background: repeating-conic-gradient(var(--bg-subtle) 0% 25%, var(--bg-white) 0% 50%) 0 0 / 20px 20px;
  border-radius: var(--r-xl); overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.03);
  position: relative;
}
#expand-preview-canvas {
  max-width: 100%; max-height: 100%;
  border-radius: var(--r-md);
  box-shadow: 0 12px 40px rgba(0,0,0,0.12);
}

.expand-adj-controls {
  display: flex; flex-direction: row; gap: 16px; width: 100%;
}
@media (max-width: 768px) {
  .expand-adj-controls { flex-direction: column; gap: 8px; }
}

/* ── TOAST NOTIFICATIONS ─────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: var(--space-6); right: var(--space-6);
  z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: var(--space-2);
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 12px 16px;
  background: var(--glass-bg-heavy);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-md);
  box-shadow: 0 8px 24px rgba(0,0,0,0.08);
  font-size: 0.83rem; font-weight: 500; color: var(--text-body);
  pointer-events: auto;
  transform: translateX(110%); opacity: 0;
  transition: all var(--med);
  min-width: 260px; max-width: 420px;
}
.toast.toast-visible { transform: translateX(0); opacity: 1; }

.toast-icon {
  width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.72rem; font-weight: 800; flex-shrink: 0;
}
.toast-success .toast-icon { background: var(--success-dim); color: var(--success); }
.toast-error   .toast-icon { background: var(--danger-dim);  color: var(--danger); }
.toast-warning .toast-icon { background: var(--warning-dim); color: var(--warning); }
.toast-info    .toast-icon { background: var(--primary-dim); color: var(--primary); }
.toast-success { border-left: 3px solid var(--success); }
.toast-error   { border-left: 3px solid var(--danger); }
.toast-warning { border-left: 3px solid var(--warning); }
.toast-info    { border-left: 3px solid var(--primary); }

/* ── LOADING OVERLAY ─────────────────────────────────────────── */
#loading-overlay {
  position: fixed; inset: 0; z-index: 900;
  background: rgba(248, 250, 252, 0.75);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity var(--med);
}
#loading-overlay.visible { opacity: 1; pointer-events: all; }

.loading-card {
  background: var(--glass-bg-heavy);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-2xl); padding: var(--space-8);
  display: flex; flex-direction: column; align-items: center; gap: var(--space-4);
  box-shadow: 0 12px 40px rgba(0,0,0,0.08);
  animation: modalIn 0.3s var(--ease);
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--bg-subtle2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
.loading-card p { font-size: 0.9rem; color: var(--text-muted); text-align: center; font-weight: 500; }

/* ── CONFIRM DIALOG ──────────────────────────────────────────── */
.confirm-overlay {
  position: fixed; inset: 0; z-index: 1010;
  background: rgba(15,23,42,0.35);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity var(--med);
}
.confirm-overlay.visible { opacity: 1; }
.confirm-card {
  background: var(--glass-bg-heavy);
  border: 1px solid var(--glass-border2);
  border-radius: var(--r-xl); padding: var(--space-6);
  max-width: 360px; width: 90%;
  box-shadow: 0 16px 40px rgba(0,0,0,0.10);
  animation: modalIn 0.25s var(--ease);
}
.confirm-card p {
  font-size: 0.9rem; color: var(--text-body);
  margin-bottom: var(--space-5); line-height: 1.6;
}
.confirm-actions { display: flex; gap: var(--space-2); justify-content: flex-end; }

/* ── EMPTY STATE CARD ────────────────────────────────────────── */
.empty-state-card {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-10) var(--space-6);
  max-width: 400px;
  background: var(--glass-bg-heavy);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-2xl);
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(12px);
}
.empty-icon-wrap {
  width: 60px; height: 60px; border-radius: var(--r-xl);
  background: var(--primary-dim); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: var(--space-4);
}
.empty-state-card h3 {
  font-family: 'Fustat', sans-serif;
  font-size: 1.1rem; font-weight: 800; color: var(--text-dark);
  margin-bottom: var(--space-2);
}
.empty-state-card p {
  font-size: 0.82rem; color: var(--text-muted);
  margin-bottom: var(--space-5); line-height: 1.5;
}

/* ── UTILITIES ───────────────────────────────────────────────── */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ── TOUCH & CANVAS OPTIMIZATIONS ────────────────────────────── */
#preview-canvas, #brush-canvas {
  touch-action: none; /* Prevents native page scroll while dragging/drawing on mobile touchscreens */
}

/* Always display thumb-card action buttons (Edit Blur & Delete) on touch/mobile devices */
@media (hover: none), (max-width: 768px) {
  .thumb-overlay {
    opacity: 1 !important;
    background: linear-gradient(to top, rgba(15, 23, 42, 0.85) 0%, rgba(15,23,42,0.2) 60%, transparent 100%) !important;
  }
  .thumb-card:active {
    transform: scale(0.98);
  }
}

/* ── RESPONSIVE & SMARTPHONE DESIGN ──────────────────────────── */
@media (max-width: 1100px) {
  .edit-section {
    height: auto !important;
    min-height: calc(100vh - 54px) !important;
    overflow: visible !important;
  }
  .edit-layout {
    display: flex !important;
    flex-direction: column !important;
    height: auto !important;
    overflow: visible !important;
    gap: var(--space-4);
    padding: var(--space-3);
    width: 100% !important;
    box-sizing: border-box !important;
  }
  /* Smartphone Step 2 Order: 1. Live Preview & Adjustment, 2. Layout Controls, 3. Photos List */
  .preview-panel {
    order: 1;
    border-left: none !important;
    border: 1px solid var(--glass-border) !important;
    border-radius: var(--r-xl);
    width: 100% !important;
    box-sizing: border-box !important;
    min-height: 240px;
    max-height: none;
    padding: var(--space-3);
  }
  .controls-panel {
    order: 2;
    border-right: none !important;
    border: 1px solid var(--glass-border) !important;
    border-radius: var(--r-xl);
    width: 100% !important;
    box-sizing: border-box !important;
    max-height: none;
    overflow-y: visible;
    padding: var(--space-3);
  }
  .photo-grid-area {
    order: 3;
    width: 100% !important;
    box-sizing: border-box !important;
    border: 1px solid var(--glass-border) !important;
    border-radius: var(--r-xl);
    overflow-y: visible;
    padding: var(--space-3);
  }
}

@media (max-width: 768px) {
  /* Prevent horizontal overflow on mobile viewports */
  html, body {
    width: 100vw !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
  }
  .app-wrapper {
    width: 100vw !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
  }

  /* Compact Header on Mobile */
  .app-header {
    width: 100vw !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
    padding: 8px 12px !important;
    gap: 6px !important;
    justify-content: space-between !important;
    overflow: hidden !important;
  }
  .logo { flex-shrink: 0; gap: 6px; }
  .logo img { height: 32px; width: auto; max-width: 130px; object-fit: contain; }
  .logo-text { display: none !important; }

  /* Hide step navigation indicator on mobile to eliminate header crowding */
  .step-nav { display: none !important; }

  .header-actions {
    flex-shrink: 0 !important;
    display: flex !important;
    align-items: center !important;
    gap: 4px !important;
  }

  /* Hide wide detector status text badge & reset button from small header */
  #detector-status { display: none !important; }
  #reset-btn { display: none !important; }

  /* Hide invisible elements so they consume 0 space */
  #back-btn[style*="visibility:hidden"],
  #back-btn[style*="visibility: hidden"],
  .header-actions button.hidden {
    display: none !important;
  }

  .header-actions .btn-primary,
  .header-actions .btn-secondary {
    padding: 6px 12px !important;
    font-size: 0.78rem !important;
    min-height: 36px !important;
    border-radius: var(--r-full) !important;
    white-space: nowrap !important;
  }

  /* Sliders: touch-friendly thumb sizing */
  input[type="range"]::-webkit-slider-thumb {
    width: 22px; height: 22px;
  }
  input[type="range"]::-moz-range-thumb {
    width: 22px; height: 22px;
  }

  /* Form inputs font-size 16px to prevent iOS auto-zoom */
  select, input[type="text"], input[type="number"] {
    font-size: 1rem !important;
    min-height: 42px;
  }

  /* Step 1 Upload Mobile */
  .upload-section {
    padding: 16px 12px !important;
    min-height: calc(100vh - 54px) !important;
    width: 100% !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
  }
  .upload-zone {
    width: 100% !important;
    max-width: 100% !important;
    padding: 24px 14px !important;
    box-sizing: border-box !important;
  }
  .upload-icon-wrap {
    width: 54px !important;
    height: 54px !important;
    margin-bottom: 10px !important;
  }
  .upload-title {
    font-size: 1.15rem !important;
  }
  .upload-subtitle {
    font-size: 0.8rem !important;
  }
  .upload-btn-wrap button {
    width: 100% !important;
    max-width: 260px !important;
    padding: 10px 14px !important;
    font-size: 0.85rem !important;
  }
  .upload-meta {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 6px !important;
    width: 100% !important;
    margin-top: 14px !important;
  }
  .upload-meta-item {
    font-size: 0.68rem !important;
    padding: 5px 4px !important;
    justify-content: center !important;
    text-align: center !important;
    white-space: nowrap !important;
  }

  /* Step 3 Export Section on Mobile */
  .export-section {
    padding: 12px !important;
    width: 100% !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
    min-height: calc(100vh - 54px) !important;
    height: auto !important;
  }
  .export-section.active {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
    width: 100% !important;
  }
  .export-options-card {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    padding: 14px !important;
  }
  .export-preview-card {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /* Toast notification on mobile: centered at bottom */
  .toast-container {
    bottom: 16px; left: 16px; right: 16px;
    transform: none; max-width: none;
  }
  .toast { width: 100%; justify-content: center; font-size: 0.85rem; padding: 10px 14px; }

  /* Manual Blur Modal on Mobile Smartphones */
  .blur-modal { padding: 8px; }
  .modal-container { width: 100%; max-height: 96vh; border-radius: var(--r-xl); }
  .modal-header { padding: 10px; gap: 8px; flex-direction: column; align-items: stretch; }
  .brush-controls { width: 100%; justify-content: space-between; gap: 6px; flex-wrap: wrap; }
  .brush-control-item input[type="range"] { flex: 1; min-width: 60px; }
  .modal-actions { width: 100%; justify-content: flex-end; gap: 6px; }
  .modal-actions button { min-height: 38px; padding: 6px 12px; font-size: 0.82rem; }
  .modal-footer { padding: 8px 10px; }
  .modal-hint { font-size: 0.62rem; }

  /* Mobile touch handles & delete button */
  .shape-box-delete {
    opacity: 1 !important;
    width: 28px !important;
    height: 28px !important;
    top: -14px !important;
    right: -14px !important;
    font-size: 15px !important;
  }
  .shape-box-handle {
    width: 20px !important;
    height: 20px !important;
    border-width: 3px !important;
  }
  .shape-box-handle.nw { top: -10px !important; left: -10px !important; }
  .shape-box-handle.ne { top: -10px !important; right: -10px !important; }
  .shape-box-handle.sw { bottom: -10px !important; left: -10px !important; }
  .shape-box-handle.se { bottom: -10px !important; right: -10px !important; }
}

@media (max-width: 480px) {
  .photo-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important; }
  .preset-btn { height: 46px !important; }
  .layout-presets { grid-template-columns: repeat(4, 1fr) !important; gap: 4px !important; }
}
