/* ── Reset & Tokens ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
/* Respect device safe areas (notch, home indicator) */
@supports (padding: max(0px)) {
  .mobile-sidebar-toggle { bottom: max(20px, env(safe-area-inset-bottom, 20px) + 8px); right: max(20px, env(safe-area-inset-right, 20px)); }
  .sidebar { padding-bottom: env(safe-area-inset-bottom, 0px); }
}

:root {
  --sidebar-w:  340px;
  --bg:         #f4f4f6;
  --surface:    #ffffff;
  --surface-2:  #f7f7f9;
  --border:     #e4e4e8;
  --text:       #111114;
  /* light-only defaults continued below */
  --text-2:     #5f5f6b;
  --text-3:     #9999a8;
  --accent:     #0891b2;
  --accent-h:   #06798f;
  --card-min-w: 200px;
  --danger:     #dc2626;
  --r:          7px;
  --r-lg:       12px;
  --shadow:     0 1px 4px rgba(0,0,0,0.08), 0 2px 10px rgba(0,0,0,0.05);
  --shadow-lg:  0 8px 32px rgba(0,0,0,0.14);
}

/* ── Dark theme ──────────────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:         #111113;
  --surface:    #1c1c21;
  --surface-2:  #26262d;
  --border:     #32323b;
  --text:       #f0f0f3;
  --text-2:     #9898a8;
  --text-3:     #55555f;
  --shadow:     0 1px 4px rgba(0,0,0,0.35), 0 2px 10px rgba(0,0,0,0.2);
  --shadow-lg:  0 8px 32px rgba(0,0,0,0.5);
}
@media (prefers-color-scheme: dark) {
  [data-theme="system"] {
    --bg:         #111113;
    --surface:    #1c1c21;
    --surface-2:  #26262d;
    --border:     #32323b;
    --text:       #f0f0f3;
    --text-2:     #9898a8;
    --text-3:     #55555f;
    --shadow:     0 1px 4px rgba(0,0,0,0.35), 0 2px 10px rgba(0,0,0,0.2);
    --shadow-lg:  0 8px 32px rgba(0,0,0,0.5);
  }
}

/* ── Soft White theme (warm, slightly darker than pure white) ────────────────── */
[data-theme="soft-white"] {
  --bg:        #e8e5df;
  --surface:   #f2f0ea;
  --surface-2: #e2dfd9;
  --border:    #ccc9c2;
  --text:      #2c2a25;
  --text-2:    #6b6760;
  --text-3:    #a09c94;
  --shadow:    0 1px 4px rgba(0,0,0,0.08), 0 2px 10px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.13);
}

/* ── Blue-Grey Dark theme ─────────────────────────────────────────────────────── */
[data-theme="blue-grey-dark"] {
  --bg:        #1a2332;
  --surface:   #1e2a3b;
  --surface-2: #243044;
  --border:    #2d3d55;
  --text:      #d0d8e8;
  --text-2:    #8899b0;
  --text-3:    #4a5a70;
  --shadow:    0 1px 4px rgba(0,0,0,0.4), 0 2px 10px rgba(0,0,0,0.25);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.55);
}

/* ── Sidebar-right layout ────────────────────────────────────────────────────── */
[data-layout="right"] .app-shell { flex-direction: row-reverse; }
[data-layout="right"] .sidebar { border-right: none; border-left: 1px solid var(--border); }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

/* ── App shell ───────────────────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
  position: relative;
}

/* Resize handle — grab the right edge to resize */
.sidebar-resize-handle {
  position: absolute;
  top: 0;
  right: -4px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 100;
}
.sidebar-resize-handle:hover,
.sidebar-resize-handle:active {
  background: rgba(37,99,235,0.18);
}
[data-layout="right"] .sidebar-resize-handle {
  right: auto;
  left: -4px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 14px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 8px;
}

.sidebar-brand { min-width: 0; flex: 1; }
.sidebar-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.logo {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  font-size: 15px;
  letter-spacing: -0.3px;
  color: var(--text);
}
.logo-main { font-weight: 700; }
.logo-by {
  font-weight: 400;
  font-style: italic;
  color: var(--text-3);
}
.logo-sub {
  display: block;
  font-size: 10px;
  font-weight: 400;
  color: var(--text-3);
  margin-top: 1px;
}

/* Icon button (gear / customize) */
.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  flex-shrink: 0;
}
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn:hover { background: var(--border); color: var(--text); }
.icon-btn.active { background: var(--accent); border-color: var(--accent); color: white; }
.lang-toggle-btn {
  width: auto;
  min-width: 54px;
  padding: 0 9px;
  font-size: 11px;
  font-weight: 600;
}

/* ── Section icon ────────────────────────────────────────────────────────────── */
.section-heading {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 14px 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}
.section-icon { width: 13px; height: 13px; flex-shrink: 0; opacity: 0.7; }

/* ── Customize panel ─────────────────────────────────────────────────────────── */
.customize-panel {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 14px 14px 24px;
  display: flex;
  opacity: 0;
  transform: translateX(14px);
  transition: opacity 0.22s ease, transform 0.22s ease;
  pointer-events: none;
}
.customize-panel.panel-open {
  opacity: 1;
  transform: translateX(0);
  pointer-events: all;
  flex-direction: column;
  gap: 2px;
}
.customize-panel::-webkit-scrollbar { width: 4px; }
.customize-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.customize-section { padding: 6px 0; }
.customize-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 9px;
}
.customize-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.customize-row-label {
  font-size: 11.5px;
  color: var(--text-2);
  flex: 0 0 62px;
  white-space: nowrap;
}
.customize-sep { height: 1px; background: var(--border); margin: 8px 0; }
.customize-panel .oss-support { padding: 2px 0 0; }

/* Accent colour presets */
.accent-swatches { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; }

.accent-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2.5px solid transparent;
  padding: 0;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.accent-swatch:hover { transform: scale(1.15); }
.accent-swatch.active {
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent);
  transform: scale(1.08);
}

/* Custom colour picker swatch */
.accent-custom {
  background: conic-gradient(
    hsl(0,100%,60%), hsl(60,100%,55%), hsl(120,100%,50%),
    hsl(180,100%,50%), hsl(240,100%,65%), hsl(300,100%,65%), hsl(360,100%,60%)
  );
}
.accent-custom svg { width: 11px; height: 11px; position: relative; z-index: 1; pointer-events: none; }
.accent-custom input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: none;
  padding: 0;
  cursor: pointer;
}

.pill-group { display: flex; gap: 4px; flex-wrap: wrap; }
.pill-option { position: relative; }
.pill-option input[type="radio"] { position: absolute; opacity: 0; width: 0; height: 0; }
.pill-option span {
  display: inline-flex;
  align-items: center;
  padding: 4px 11px;
  border-radius: 100px;
  border: 1px solid var(--border);
  font-size: 11.5px;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text-2);
  transition: background 0.1s, border-color 0.1s, color 0.1s;
  user-select: none;
}
.pill-option input:checked + span { background: var(--accent); border-color: var(--accent); color: white; }
.pill-option span:hover { border-color: var(--accent); color: var(--accent); }
.pill-option input:checked + span:hover { background: var(--accent-h); color: white; }

/* ── iOS-style toggle ────────────────────────────────────────────────────────── */
.ios-toggle {
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  user-select: none;
  padding: 3px 0;
}
.ios-toggle input[type="checkbox"] { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }
.ios-toggle-track {
  position: relative;
  width: 34px;
  height: 20px;
  background: var(--border);
  border-radius: 10px;
  flex-shrink: 0;
  transition: background 0.2s;
}
.ios-toggle input:checked + .ios-toggle-track { background: var(--accent); }
.ios-toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s cubic-bezier(.34,1.56,.64,1);
  box-shadow: 0 1px 3px rgba(0,0,0,0.22);
}
.ios-toggle input:checked + .ios-toggle-track .ios-toggle-thumb { transform: translateX(14px); }
.ios-toggle-label {
  font-size: 12px;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 5px;
}

/* ── Tooltip ─────────────────────────────────────────────────────────────────── */
.tooltip-anchor {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  background: var(--border);
  color: var(--text-3);
  border-radius: 50%;
  font-size: 9.5px;
  cursor: help;
  flex-shrink: 0;
  font-style: normal;
}
.tooltip-anchor:hover .tooltip-box { opacity: 1; pointer-events: all; }
.tooltip-box {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 7px);
  transform: translateX(-50%);
  background: #18181b;
  color: #e4e4e7;
  font-size: 11px;
  line-height: 1.45;
  padding: 7px 10px;
  border-radius: 7px;
  width: 190px;
  text-align: left;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 200;
  box-shadow: 0 4px 14px rgba(0,0,0,0.2);
  white-space: normal;
}
.tooltip-box::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #18181b;
}

/* ── Sidebar body (wraps scroll + customize panel) ───────────────────────────── */
.sidebar-body {
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* Sidebar scroll area */
.sidebar-scroll {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding-bottom: 24px;
  opacity: 1;
  transform: translateX(0);
  transition: opacity 0.22s ease, transform 0.22s ease;
  pointer-events: all;
}
.sidebar-scroll.panel-open {
  opacity: 0;
  transform: translateX(-14px);
  pointer-events: none;
}
.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Section header right ────────────────────────────────────────────────────── */
.section-header-right { display: flex; align-items: center; gap: 8px; }

/* ── Settings sections ───────────────────────────────────────────────────────── */
.settings-section { padding: 10px 0 2px; }

.sidebar-sep {
  height: 1px;
  background: var(--border);
  margin: 8px 14px 0;
}

.oss-support {
  padding: 12px 14px 14px;
}
.oss-support-link {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  background: var(--surface-2);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface-2));
  border: 1px solid var(--border);
  border: 1px solid color-mix(in srgb, var(--accent) 26%, var(--border));
  border-radius: 10px;
  padding: 10px;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}
.oss-support-link > svg:first-child {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  opacity: 0.88;
}
.oss-support-link > svg:last-child {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  opacity: 0.6;
}
.oss-support-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.oss-support-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.oss-support-sub {
  font-size: 10.5px;
  color: var(--text-2);
  line-height: 1.35;
}
.oss-support-link:hover {
  transform: translateY(-1px);
  background: var(--surface);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface-2));
  border-color: var(--border);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}
.oss-support-link:focus-visible {
  outline: 2px solid var(--accent);
  outline: 2px solid color-mix(in srgb, var(--accent) 65%, white);
  outline-offset: 2px;
}

.setting-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 14px;
  min-height: 28px;
}

.setting-label {
  font-size: 11.5px;
  color: var(--text-2);
  flex: 0 0 auto;
  min-width: 72px;
  white-space: nowrap;
}

.setting-control { flex: 1; min-width: 0; }

/* Range sliders */
.range-wrap { display: flex; align-items: center; gap: 6px; }

input[type="range"] {
  flex: 1;
  height: 3px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(37,99,235,0.35);
}
input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}

.range-val {
  font-size: 11px;
  color: var(--text-3);
  min-width: 40px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.range-val.range-val-editable {
  cursor: text;
  padding: 1px 4px;
  border-radius: 4px;
}
.range-val.range-val-editable:focus {
  outline: none;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 50%, transparent);
}

/* Color swatches */
.color-row { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }

.color-option { position: relative; cursor: pointer; display: inline-block; }
.color-option input[type="radio"] { position: absolute; opacity: 0; width: 0; height: 0; }

.color-swatch {
  display: block;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  box-shadow: 0 0 0 1.5px var(--border);
  transition: box-shadow 0.12s, border-color 0.12s;
}
.color-option input:checked + .color-swatch { box-shadow: 0 0 0 2px var(--accent); border-color: white; }
.color-option:hover .color-swatch { box-shadow: 0 0 0 2px var(--accent); }

.color-swatch.white     { background: #ffffff; }
.color-swatch.lightgray { background: #F0F0F0; }
.color-swatch.gray      { background: #9E9E9E; }
.color-swatch.black     { background: #1a1a1a; }

/* Custom color — single rainbow button */
.color-option-custom {
  position: relative;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  box-shadow: 0 0 0 1.5px var(--border);
  background: transparent;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  flex-shrink: 0;
  transition: box-shadow 0.12s, border-color 0.12s;
}
.color-option-custom:hover { box-shadow: 0 0 0 2px var(--accent); }
.color-option-custom.active { box-shadow: 0 0 0 2px var(--accent); border-color: white; }

.rainbow-icon {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: conic-gradient(
    hsl(0,100%,60%),
    hsl(30,100%,60%),
    hsl(60,100%,55%),
    hsl(120,100%,50%),
    hsl(180,100%,50%),
    hsl(240,100%,65%),
    hsl(300,100%,65%),
    hsl(360,100%,60%)
  );
}

/* Color picker sits inside the button, fills it, invisible — click bubbles up natively */
.color-option-custom input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: none;
  padding: 0;
  cursor: pointer;
}

/* Font select */
select.font-select {
  width: 100%;
  padding: 4px 24px 4px 7px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23999'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  font-size: 12px;
  color: var(--text);
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  font-family: inherit;
}
select.font-select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(37,99,235,0.12); }
select.font-select optgroup { font-weight: 600; font-size: 10px; color: var(--text-3); }
select.font-select option { font-size: 12px; font-weight: 400; color: var(--text); }

/* Style toggle buttons (Bold / Italic) */
.style-toggles { display: flex; gap: 4px; flex-wrap: wrap; }

.style-toggle-btn { position: relative; }
.style-toggle-btn input[type="checkbox"] { position: absolute; opacity: 0; width: 0; height: 0; }

.style-toggle-btn label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  padding: 3px 8px;
  border-radius: 5px;
  border: 1px solid var(--border);
  font-size: 12px;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text-2);
  user-select: none;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
  white-space: nowrap;
  line-height: 1.3;
}
.style-toggle-btn input:checked + label { background: var(--accent); border-color: var(--accent); color: white; }
.style-toggle-btn label:hover { border-color: var(--accent); color: var(--accent); }
.style-toggle-btn input:checked + label:hover { background: var(--accent-h); color: white; }

/* Aspect ratio pills */
.ratio-pills { display: flex; gap: 4px; flex-wrap: wrap; }

.ratio-pill { position: relative; }
.ratio-pill input[type="radio"] { position: absolute; opacity: 0; width: 0; height: 0; }

.ratio-pill label {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 5px;
  border: 1px solid var(--border);
  font-size: 11px;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text-2);
  user-select: none;
  transition: background 0.1s, border-color 0.1s;
}
.ratio-pill input:checked + label { background: var(--accent); border-color: var(--accent); color: white; }
.ratio-pill label:hover { border-color: var(--accent); color: var(--accent); }
.ratio-pill input:checked + label:hover { background: var(--accent-h); color: white; }
.location-pos-row .ratio-pills { flex-wrap: nowrap; gap: 3px; }
.location-pos-row .ratio-pill { flex: 1 1 0; min-width: 0; }
.location-pos-row .ratio-pill label {
  width: 100%;
  justify-content: center;
  padding: 3px 6px;
  font-size: 10px;
}

/* Visibility toggles (iOS) */
.vis-toggles { display: flex; flex-direction: column; gap: 2px; }

/* ── Main content area ───────────────────────────────────────────────────────── */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Preview area (also acts as drop zone) ───────────────────────────────────── */
.preview-area {
  flex: 0 0 auto;
  background: #18181b;
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--preview-h, 52vh);
  min-height: 200px;
  padding: 20px;
  position: relative;
  overflow: hidden;
}

/* ── Preview/pool vertical resize handle ─────────────────────────────────────── */
.main-resize-handle {
  height: 5px;
  flex-shrink: 0;
  cursor: row-resize;
  background: var(--border);
  transition: background 0.15s;
  z-index: 2;
  display: none;
}
.main-resize-handle:hover,
.main-resize-handle.resizing { background: var(--accent); }

/* Card size control bar */
.card-size-bar {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-3);
}
.card-size-bar input[type="range"] {
  width: 72px;
  accent-color: var(--accent);
}

/* File input covers the whole area when empty — click anywhere to open dialog */
.preview-area > input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
  z-index: 2;
}
/* When a preview is showing, disable file input overlay so canvas is clickable */
.preview-area.has-preview > input[type="file"] {
  pointer-events: none;
  z-index: -1;
}

/* Drag-over indicator as an overlay border */
.preview-area::after {
  content: '';
  position: absolute;
  inset: 6px;
  border: 2px dashed var(--accent);
  border-radius: 8px;
  background: rgba(37, 99, 235, 0.10);
  pointer-events: none;
  z-index: 5;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.preview-area.drag-over::after { opacity: 1; }

.preview-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
  user-select: none;
}
.preview-empty-icon { font-size: 44px; opacity: 0.55; line-height: 1; }
.preview-empty-text { font-size: 15px; color: #e4e4e7; text-align: center; font-weight: 500; letter-spacing: -0.01em; }
.preview-empty-sub  { font-size: 12px; color: #71717a; text-align: center; }

/* ── Preview zoom bar (vertical, right side) ─────────────────────────────────── */
.preview-zoom-bar {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 10px 6px;
  border-radius: 100px;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.preview-area.has-preview .preview-zoom-bar {
  opacity: 1;
  pointer-events: all;
}

.preview-history-wrap {
  position: absolute;
  right: 12px;
  top: 12px;
  display: flex;
  gap: 6px;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.preview-area.has-preview .preview-history-wrap {
  opacity: 1;
  pointer-events: all;
}
.preview-history-btn {
  border: none;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 11px;
  font-family: inherit;
  color: rgba(255,255,255,0.9);
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
  transition: background 0.12s;
}
.preview-history-btn:hover { background: rgba(0,0,0,0.72); }
.preview-history-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.zoom-btn {
  width: 22px;
  height: 22px;
  border: none;
  background: rgba(255,255,255,0.14);
  color: white;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s;
  line-height: 1;
  flex-shrink: 0;
  font-family: inherit;
}
.zoom-btn:hover { background: rgba(255,255,255,0.28); }

#zoomRange {
  /* Vertical slider */
  writing-mode: vertical-lr;
  direction: rtl;
  width: 3px;
  height: 80px;
  background: rgba(255,255,255,0.22);
  -webkit-appearance: slider-vertical;
  appearance: auto;
}
#zoomRange::-webkit-slider-thumb { background: white; box-shadow: 0 0 4px rgba(0,0,0,0.4); }
#zoomRange::-moz-range-thumb { background: white; border: none; }

.zoom-label {
  font-size: 10px;
  color: rgba(255,255,255,0.65);
  min-width: 28px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  user-select: none;
  writing-mode: horizontal-tb;
}

/* ── Preview Quality Button ───────────────────────────────────────────────────── */
.preview-quality-wrap {
  position: absolute;
  bottom: 12px;
  left: 12px;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.preview-area.has-preview .preview-quality-wrap {
  opacity: 1;
  pointer-events: all;
}

.preview-reset-view-btn {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  border: none;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 11px;
  font-family: inherit;
  color: rgba(255,255,255,0.9);
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
  transition: opacity 0.2s, background 0.12s;
}
.preview-reset-view-btn:hover { background: rgba(0,0,0,0.72); }
.preview-area.has-preview.view-modified .preview-reset-view-btn {
  opacity: 1;
  pointer-events: all;
}
.preview-quality-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: rgba(255,255,255,0.85);
  border: none;
  border-radius: 100px;
  padding: 5px 10px 5px 7px;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s;
}
.preview-quality-btn:hover { background: rgba(0,0,0,0.72); }
.preview-quality-popup {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  min-width: 170px;
  overflow: hidden;
  display: none;
}
.preview-quality-popup.open { display: block; }
.pq-option {
  padding: 7px 12px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.1s;
}
.pq-option:hover { background: var(--surface-2); }
.pq-option.active { color: var(--accent); font-weight: 500; }

/* ── Video Playback Bar (bottom center, shown only when video is in preview) ── */
.preview-video-bar {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 100px;
  padding: 6px 10px;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  min-width: 180px;
  max-width: calc(100% - 32px);
}
.preview-area.has-video .preview-video-bar {
  opacity: 1;
  pointer-events: all;
}

/* Hide quality selector for video (not applicable — video always renders at native res) */
.preview-area.has-video .preview-quality-wrap { display: none !important; }

/* Video canvas preview supports pan/zoom — inherit grab cursor from has-preview */

.video-ctrl-btn {
  border: none;
  background: rgba(255,255,255,0.14);
  color: white;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  font-family: inherit;
  transition: background 0.12s;
}
.video-ctrl-btn:hover { background: rgba(255,255,255,0.28); }

.video-time-label {
  font-size: 11px;
  color: rgba(255,255,255,0.75);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  min-width: 28px;
  text-align: center;
}

.video-seek-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  min-width: 60px;
}

.video-seek-range {
  width: 100%;
  height: 3px;
  cursor: pointer;
  accent-color: white;
}

/* ── Video volume control ────────────────────────────────────────────────────── */
.video-volume-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.video-mute-btn {
  width: 22px;
  height: 22px;
}

.video-volume-range {
  width: 64px;
  height: 3px;
  cursor: pointer;
  accent-color: white;
  flex-shrink: 0;
}

/* ── Video speed select ──────────────────────────────────────────────────────── */
.video-speed-select {
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 100px;
  color: rgba(255,255,255,0.85);
  font-size: 10.5px;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  padding: 2px 7px;
  cursor: pointer;
  flex-shrink: 0;
  outline: none;
  transition: background 0.12s;
  min-width: 38px;
  text-align: center;
}
.video-speed-select:hover { background: rgba(255,255,255,0.22); }
.video-speed-select option { background: #1a1a1a; color: white; }

/* ── EXIF panel (left edge of live preview, desktop only) ───────────────────── */
.preview-exif-wrap {
  position: absolute;
  left: 12px;
  top: 12px;
  transform: none;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.preview-area.has-preview .preview-exif-wrap {
  opacity: 1;
  pointer-events: all;
}

.preview-exif-toggle {
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: rgba(255,255,255,0.88);
  border: none;
  border-radius: 100px;
  padding: 6px 11px;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  transition: background 0.12s;
  flex-shrink: 0;
}
.preview-exif-toggle:hover { background: rgba(0,0,0,0.72); }
.preview-exif-toggle.active { background: rgba(8,145,178,0.72); }

.preview-exif-drawer {
  display: flex;
  flex-direction: column;
  background: rgba(0,0,0,0.68);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 10px;
  width: 210px;
  max-height: calc(100% - 80px);
  overflow: hidden;
}

.preview-exif-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 8px;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}
.preview-exif-drawer-header:hover { background: rgba(255,255,255,0.04); }

.preview-exif-content {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 0 12px 12px;
  max-height: 360px;
  opacity: 1;
  overflow-y: auto;
  overflow-x: hidden;
  transition: max-height 0.22s ease, opacity 0.16s ease, padding 0.22s ease, margin 0.22s ease;
}
.preview-exif-content::-webkit-scrollbar { width: 3px; }
.preview-exif-content::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }
.preview-exif-wrap:not(.exif-open) .preview-exif-content {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
  margin-top: 0;
  pointer-events: none;
}

.preview-exif-collapse-btn {
  background: none;
  border: none;
  padding: 2px;
  cursor: pointer;
  color: rgba(255,255,255,0.45);
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: color 0.12s;
}
.preview-exif-collapse-btn:hover { color: rgba(255,255,255,0.8); }
.preview-exif-collapse-btn svg {
  transition: transform 0.2s;
}
.preview-exif-wrap:not(.exif-open) .preview-exif-collapse-btn svg {
  transform: rotate(180deg);
}

.preview-exif-drawer-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.45);
}

.preview-exif-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 8px;
  align-items: center;
}
.preview-exif-grid label {
  font-size: 10.5px;
  color: rgba(255,255,255,0.5);
  white-space: nowrap;
  user-select: none;
}
.preview-exif-grid input {
  background: rgba(255,255,255,0.09);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 5px;
  padding: 3px 7px;
  font-size: 11px;
  color: rgba(255,255,255,0.9);
  font-family: inherit;
  width: 100%;
  outline: none;
  transition: border-color 0.12s, background 0.12s;
}
.preview-exif-grid input:focus {
  border-color: rgba(8,145,178,0.65);
  background: rgba(255,255,255,0.14);
}
.preview-exif-grid input::placeholder { color: rgba(255,255,255,0.25); }

.preview-exif-location-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}
.preview-exif-location-row input { width: 100%; min-width: 0; }
.preview-exif-location-actions {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
}

.preview-exif-geo-btn {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 4px;
  padding: 3px 5px;
  cursor: pointer;
  color: rgba(255,255,255,0.65);
  display: flex;
  align-items: center;
  transition: background 0.12s;
  flex-shrink: 0;
}
.preview-exif-geo-btn:hover { background: rgba(255,255,255,0.2); color: white; }

.preview-exif-map-btn {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 4px;
  padding: 3px 5px;
  cursor: pointer;
  color: rgba(255,255,255,0.65);
  display: flex;
  align-items: center;
  transition: background 0.12s;
  flex-shrink: 0;
}
.preview-exif-map-btn:hover { background: rgba(8,145,178,0.35); color: white; }

.preview-exif-apply-btn {
  background: rgba(8,145,178,0.75);
  color: white;
  border: none;
  border-radius: 100px;
  padding: 5px 12px;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  width: 100%;
  transition: background 0.12s;
  margin-top: 2px;
}
.preview-exif-apply-btn:hover { background: rgba(6,121,143,0.88); }

/* ── Map picker modal ─────────────────────────────────────────────────────────── */
.map-modal {
  position: fixed;
  inset: 0;
  z-index: 2600;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
}
.map-modal.open { display: flex; }

.map-modal-content {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  width: min(680px, 95vw);
  height: min(520px, 90vh);
  overflow: hidden;
}

.map-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.map-modal-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.map-modal-close {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-3);
  padding: 2px 6px;
  border-radius: 4px;
  transition: background 0.1s;
}
.map-modal-close:hover { background: var(--surface-2); color: var(--text); }

.map-picker-container {
  flex: 1;
  min-height: 0;
}

.map-modal-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.map-picker-coords {
  flex: 1;
  font-size: 11.5px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

/* ── Share modal ─────────────────────────────────────────────────────────────── */
.share-modal-content {
  width: min(560px, 94vw);
  height: auto;
}
.share-modal-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.share-modal-sub {
  margin: 0;
  font-size: 12px;
  color: var(--text-2);
}
.share-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.share-grid .btn {
  text-align: center;
  justify-content: center;
}
.share-copy-row {
  display: flex;
  gap: 8px;
}
.share-copy-row .setting-text-input {
  font-family: inherit;
}

/* ── Map overlay settings ────────────────────────────────────────────────────── */
.setting-text-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 4px 8px;
  font-size: 11.5px;
  color: var(--text);
  font-family: 'Menlo', 'Consolas', monospace;
  outline: none;
  transition: border-color 0.12s;
}
.setting-text-input:focus { border-color: var(--accent); }
.setting-text-input::placeholder { color: var(--text-3); }

/* ── Empty hint ───────────────────────────────────────────────────────────────── */
.empty-hint {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
  background: var(--bg);
}

.empty-hint-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-width: 360px;
  width: 100%;
}

.empty-hint-card {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 16px 12px;
  text-align: center;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.empty-hint-emoji { font-size: 22px; line-height: 1; }
.empty-hint-card-title { font-size: 12px; font-weight: 600; color: var(--text); }
.empty-hint-card-desc { font-size: 10.5px; color: var(--text-3); line-height: 1.55; }

#livePreviewCanvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 4px;
  box-shadow: 0 6px 30px rgba(0,0,0,0.55);
  cursor: grab;
  transition: box-shadow 0.2s;
  touch-action: none;  /* allow JS to handle all touch gestures (pan + pinch) */
}
#livePreviewCanvas.frame-dark {
  box-shadow: 0 6px 30px rgba(0,0,0,0.55), 0 0 0 1.5px rgba(255,255,255,0.2);
}
/* Whole preview area gets grab cursor when a preview is active */
.preview-area.has-preview { cursor: grab; }
.preview-area.has-preview.dragging,
.preview-area.has-preview.dragging #livePreviewCanvas { cursor: grabbing; }

/* ── Image section ───────────────────────────────────────────────────────────── */
.image-section {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg);
}
.image-section::-webkit-scrollbar { width: 5px; }
.image-section::-webkit-scrollbar-track { background: transparent; }
.image-section::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.section-counter { font-size: 11px; color: var(--text-3); }

/* ── Export progress bar ─────────────────────────────────────────────────────── */
.export-progress {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 10px 12px 9px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.export-progress-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.export-progress-label {
  font-size: 11.5px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.export-progress-pct {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  font-weight: 600;
  flex-shrink: 0;
}

.export-progress-track {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.export-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width 0.25s ease;
}

/* ── Batch bar ───────────────────────────────────────────────────────────────── */
.batch-bar { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Image grid ──────────────────────────────────────────────────────────────── */
#imageGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--card-min-w), 1fr));
  gap: 10px;
}

.image-card {
  background: var(--surface);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.15s, transform 0.15s;
}
.image-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.image-card.selected-preview { box-shadow: 0 0 0 2.5px var(--accent), var(--shadow-lg); transform: translateY(-1px); }
.image-card.selected-preview:hover { box-shadow: 0 0 0 2.5px var(--accent), var(--shadow-lg); }

.card-preview {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--surface-2);
  overflow: hidden;
  cursor: pointer;
  flex-shrink: 0;
}
.card-preview img,
.card-preview canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card-preview canvas { object-fit: contain; background: #f0f0f0; }

/* Video badge overlay */
.video-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  color: white;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 100px;
  pointer-events: none;
  z-index: 1;
}


.card-status {
  position: absolute;
  bottom: 6px;
  left: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  padding: 3px 7px;
  border-radius: 100px;
  font-size: 10px;
  color: white;
  pointer-events: none;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.pending    { background: #f59e0b; }
.status-dot.processing { background: #60a5fa; animation: blink 1s ease-in-out infinite; }
.status-dot.done       { background: #34d399; }
.status-dot.error      { background: #f87171; }

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.card-body {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.card-filename {
  font-size: 11px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-actions { display: flex; gap: 4px; flex-wrap: wrap; }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 11px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.1s, opacity 0.1s, border-color 0.1s;
  white-space: nowrap;
  line-height: 1.4;
  font-family: inherit;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }
.btn-primary  { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-h); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fee2e2; }
.btn-sm  { padding: 3px 8px; font-size: 11px; }
.btn-lg  { padding: 7px 14px; font-size: 13px; }
.btn-full { width: 100%; justify-content: center; }

/* ── EXIF panel ──────────────────────────────────────────────────────────────── */
.exif-panel {
  border-top: 1px solid var(--border);
  padding: 10px;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.exif-panel.hidden { display: none; }

.exif-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 8px;
  align-items: center;
}
.exif-grid label { font-size: 10px; color: var(--text-3); white-space: nowrap; }
.exif-location-row { display: flex; gap: 4px; align-items: center; }
.exif-geolocate-btn { padding: 3px 6px !important; flex-shrink: 0; }
.exif-grid input {
  width: 100%;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 11px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}
.exif-grid input:focus { outline: none; border-color: var(--accent); }

/* ── Notice ──────────────────────────────────────────────────────────────────── */
.notice {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-3);
  padding-top: 4px;
}


/* ── Toast ───────────────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  padding: 8px 18px;
  border-radius: 100px;
  font-size: 12px;
  background: #18181b;
  color: white;
  z-index: 2000;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.toast-success { background: #14532d; }
#toast.toast-warn    { background: #78350f; }
#toast.toast-error   { background: #7f1d1d; }

/* ── Global transitions ──────────────────────────────────────────────────────── */

/* Image card entrance */
@keyframes card-in {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)   scale(1);    }
}
.image-card { animation: card-in 0.22s ease forwards; }

/* Preview canvas fade-in */
#livePreviewCanvas {
  transition: opacity 0.25s ease;
}

/* Empty hint / Image section fades (JS sets opacity) */
.empty-hint, .image-section {
  transition: opacity 0.18s ease;
}

/* EXIF panel smooth expand/collapse */
.exif-panel {
  overflow: hidden;
  max-height: 400px;
  opacity: 1;
  transition: max-height 0.22s ease, opacity 0.18s ease, padding 0.22s ease;
}
.exif-panel.hidden {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
}

/* Photo quality row show/hide */
#photoQualityRow {
  overflow: hidden;
  max-height: 40px;
  opacity: 1;
  transition: max-height 0.2s ease, opacity 0.15s ease;
}
#photoQualityRow.row-hidden {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
}

/* ── Preview empty: mobile import hint (hidden on desktop) ──────────────────── */
.preview-empty-mobile-hint { display: none; }


.preview-area::after { transition: opacity 0.15s ease; }
.preview-area:not(.drag-over)::after { opacity: 0; pointer-events: none; }

/* Smooth sidebar separator */
.sidebar-sep { transition: background 0.2s; }

/* ── Toolbar slider: fixed width so labels don't get squished ────────────────── */
.range-wrap input[type="range"] {
  flex: none;
  width: 90px;
  min-width: 0;
}

/* ── Mobile tab bar ──────────────────────────────────────────────────────────── */
.mobile-tab-bar {
  display: none; /* shown via media query on mobile */
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 600;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  font-size: 10px;
  font-family: inherit;
  padding: 5px 0;
  transition: color 0.15s;
}
.tab-btn.active { color: var(--accent); }
.tab-btn svg { width: 20px; height: 20px; }
.tab-btn span { line-height: 1.2; }

/* ── Mobile sidebar toggle button ───────────────────────────────────────────── */
.mobile-sidebar-toggle {
  display: none; /* shown via media query */
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1010;  /* above overlay (950) and sidebar (1000) so always tappable */
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 16px rgba(0,0,0,0.28);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
}
.mobile-sidebar-toggle:hover  { background: var(--accent-h); }
.mobile-sidebar-toggle.active { background: var(--danger); transform: rotate(45deg); }
.mobile-sidebar-toggle svg    { width: 22px; height: 22px; }

/* Backdrop behind mobile sidebar */
.mobile-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 950;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;        /* transparent = non-interactive */
  transition: opacity 0.25s;
}
.mobile-sidebar-overlay.visible {
  opacity: 1;
  pointer-events: auto;        /* only blocks when actually shown */
}

/* ── Tablet: narrower sidebar ────────────────────────────────────────────────── */
@media (max-width: 1100px) and (min-width: 769px) {
  :root { --sidebar-w: 280px; }

  .preview-area { min-height: 280px; }
}

/* ── Mobile: tab-bar layout ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --tab-bar-h: 56px; }

  /* Safe-area padding for home indicator (notch devices) */
  @supports (padding: max(0px)) {
    .mobile-tab-bar { padding-bottom: max(0px, env(safe-area-inset-bottom)); height: calc(56px + env(safe-area-inset-bottom, 0px)); }
  }

  html, body { overflow: hidden; }

  /* Show tab bar */
  .mobile-tab-bar { display: flex; }

  /* Hide old FAB + overlay */
  .mobile-sidebar-toggle { display: none !important; }
  .mobile-sidebar-overlay { display: none !important; }

  /* App shell: column layout, leave room for tab bar */
  .app-shell {
    flex-direction: column;
    height: calc(100dvh - var(--tab-bar-h));
    height: calc(100vh - var(--tab-bar-h));
    overflow: hidden;
    position: relative;
  }

  /* Main: flex column, fills remaining space */
  .main {
    flex: 1;
    min-height: 0;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  /* Sidebar: fullscreen overlay (shown when settings tab is active) */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: var(--tab-bar-h, 56px);
    width: 100% !important;
    max-height: none;
    border: none;
    border-radius: 0;
    z-index: 500;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    /* opacity fades over 0.2s; visibility stays visible during that 0.2s then snaps to hidden */
    transition: opacity 0.2s, visibility 0s 0.2s;
    overflow: hidden;
    box-shadow: none;
  }

  /* Settings tab active: show sidebar */
  body[data-mobile-tab="settings"] .sidebar {
    opacity: 1;
    visibility: visible;
    pointer-events: all;
    transition-delay: 0s;
  }

  /* Resize handle hidden on mobile */
  .sidebar-resize-handle { display: none; }

  /* Preview area: fills the main area on preview tab */
  .preview-area {
    flex: 1;
    height: auto !important;
    min-height: 0;
    max-height: none;
    position: relative;
  }

  /* Image section: fills the main area on photos tab */
  .image-section {
    position: absolute;
    inset: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Empty hint: fills the main area on photos tab (no photos) */
  .empty-hint {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 20px 16px;
  }

  /* Mobile add button (shown in empty hint on Photos tab) */
  .mobile-add-btn { display: none; }
  body[data-mobile-tab="photos"] .mobile-add-btn { display: inline-flex; }

  /* Tab visibility — hide/show sections based on active tab */
  body[data-mobile-tab="preview"] .image-section,
  body[data-mobile-tab="preview"] .empty-hint {
    display: none !important;
  }

  body[data-mobile-tab="photos"] .preview-area { display: none !important; }

  body[data-mobile-tab="settings"] .preview-area,
  body[data-mobile-tab="settings"] .image-section,
  body[data-mobile-tab="settings"] .empty-hint {
    display: none !important;
  }

  /* Image grid: mobile card-size slider should still affect column sizing */
  #imageGrid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--card-min-w)), 1fr));
    gap: 8px;
  }

  /* Card actions compact */
  .card-actions { flex-wrap: wrap; gap: 4px; }
  .card-actions .btn { font-size: 11px; padding: 4px 8px; }

  /* Empty hint grid 2×2 */
  .empty-hint-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .empty-hint-card { padding: 12px 8px; }
  .empty-hint-emoji { font-size: 22px; }

  /* Batch bar stacks */
  .batch-bar { flex-wrap: wrap; gap: 6px; }
  .batch-bar .btn-lg { flex: 1; min-width: 120px; font-size: 13px; padding: 10px 12px; }

  /* Section header tighter */
  .section-header { padding: 10px 12px 6px; }

  /* Preview controls */
  .preview-quality-wrap { bottom: 8px; left: 8px; }
  .preview-history-wrap { right: 8px; top: 8px; }
  .preview-zoom-bar { right: 8px; }
  .preview-reset-view-btn { right: 8px; bottom: 8px; }
  /* Video bar: compact on mobile */
  .preview-video-bar {
    bottom: 8px;
    gap: 4px;
    padding: 5px 8px;
    max-width: calc(100% - 16px);
    min-width: 0;
    flex-wrap: nowrap;
  }
  .video-ctrl-btn { width: 22px; height: 22px; }
  .video-mute-btn { width: 20px; height: 20px; }
  .video-time-label { font-size: 10px; min-width: 24px; }
  .video-volume-range { width: 36px; }
  .video-seek-wrap { min-width: 36px; }
  .video-speed-select { font-size: 9.5px; padding: 2px 5px; min-width: 30px; }
  .preview-exif-wrap {
    display: block !important;
    left: 8px;
    top: 8px;
    right: 52px;
    max-width: calc(100% - 60px);
  }
  .preview-exif-drawer {
    width: min(236px, calc(100vw - 68px));
    max-height: calc(100% - 16px);
  }
  .preview-exif-content { max-height: 200px; }
  .preview-exif-grid {
    grid-template-columns: 1fr;
    gap: 5px;
  }
  .preview-exif-grid label { margin-top: 2px; }
  #zoomRange { height: 60px; }
  .zoom-btn  { width: 20px; height: 20px; font-size: 14px; }

  /* Toast: above tab bar */
  #toast { bottom: calc(var(--tab-bar-h) + 12px); }

  /* Preview empty-state mobile hint message */
  .preview-empty-mobile-hint {
    display: block;
    margin-top: 6px;
    font-size: 13px;
    color: var(--accent);
    text-align: center;
    font-weight: 500;
    letter-spacing: -0.01em;
  }

  /* Tap-to-import overlay for empty state (preview + photos tabs) */
  .mobile-empty-tap-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
}

/* ── Blur background controls ─────────────────────────────────────────────── */
.blur-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}
.blur-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.blur-sub-label {
  font-size: 11px;
  color: var(--text-3);
  min-width: 62px;
  flex-shrink: 0;
}

/* ── Location icon picker ─────────────────────────────────────────────────── */
.icon-picker {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.icon-pick-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--r);
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  color: var(--text-3);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.icon-pick-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.icon-pick-btn.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
}

/* ── Customize panel: token input ─────────────────────────────────────────── */
.customize-token-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 5px 8px;
  font-size: 11.5px;
  color: var(--text);
  font-family: monospace;
  box-sizing: border-box;
}
.customize-token-input:focus {
  outline: none;
  border-color: var(--accent);
}
.customize-row-hint {
  font-size: 10.5px;
  color: var(--text-3);
  line-height: 1.4;
}

/* ── Map picker container: ensure it has height within flex layout ─────────── */
.map-picker-container {
  flex: 1;
  min-height: 280px;
  background: #e5e7eb;
}
