/* Template Customizer popup - the reusable "Master Customizer" UI.
   Shared by the dashboard (index.html) and the standalone preview (preview.html).
   Needs styles.css first (fonts, colour variables, .icon-btn). */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(3, 5, 9, .72);
  backdrop-filter: blur(3px);
  animation: fade .15s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  width: min(1240px, 100%);
  height: min(800px, calc(100vh - 48px));
  overflow: hidden;
  border: 1px solid #1d2530;
  border-radius: 16px;
  background: #07090c;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6);
}

.modal-preview {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 18px 20px;
  background: #0b0e12;
  border-right: 1px solid #161c24;
}
.preview-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.preview-title { flex: 1; margin: 0; font-size: 16px; font-weight: 700; color: #d7dade; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ratio-chips { display: flex; gap: 6px; }
.ratio-chip {
  padding: 5px 10px;
  border: 1px solid #252e39;
  border-radius: 999px;
  background: #11161d;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 700;
}
.ratio-chip:hover { color: var(--text); }
.ratio-chip.is-active { border-color: var(--blue); background: #132640; color: #fff; }
.preview-box { flex: 1; min-height: 0; display: grid; place-items: center; overflow: hidden; }
.stage-frame {
  position: relative;
  overflow: hidden;
  border-radius: 6px;
  box-shadow: 0 0 0 1px #1d2633, 0 12px 40px rgba(0, 0, 0, .5);
}
.stage { position: absolute; top: 0; left: 0; transform-origin: 0 0; overflow: hidden; background: var(--brand-background); }
/* Inside .stage: animated background (bottom) + template layer (top). */
.stage-layer { position: absolute; inset: 0; }
.bg-layer { position: absolute; inset: 0; background: #030916; }
.stage[data-bg-mode='light'] .bg-layer { background: #f4f6fa; }
.bg-media { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.bg-media[hidden] { display: none; }
.preview-note { margin: 12px 0 0; font-size: 12.5px; color: var(--text-mute); text-align: center; }

.stage-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 24px;
  color: var(--brand-text);
  font-family: var(--brand-font);
  font-size: 40px;
  opacity: .8;
}
.stage-placeholder img { max-width: 70%; max-height: 60%; border-radius: 12px; }
.stage-placeholder p { margin: 0; }

.brand-sample {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: var(--brand-background);
  color: var(--brand-text);
  font-family: var(--brand-font);
}
.brand-sample-logo { align-self: flex-start; object-fit: contain; }
.brand-sample-title { font-weight: 800; line-height: 1.05; }
.brand-sample-sub { opacity: .7; }
.brand-sample-row { display: flex; flex-wrap: wrap; }
.brand-sample-chip { border-radius: 999px; font-weight: 700; }
.brand-sample-chip--primary { background: var(--brand-primary); color: var(--brand-text); }
.brand-sample-chip--accent { background: var(--brand-accent); color: var(--brand-background); }
.brand-sample-chip--text { border: 2px solid var(--brand-text); }

/* Customizer panel - styled after the "Template Customizer" reference panel */
.customizer { display: flex; flex-direction: column; min-height: 0; background: #000; }
.cz-head { display: flex; align-items: center; gap: 10px; padding: 16px 14px 10px 18px; }
.cz-head h2 { flex: 1; margin: 0; font-size: 16px; font-weight: 700; }
.cz-chip { padding: 3px 9px; border-radius: 999px; background: #1c1f24; color: #d5d8dc; font-size: 12px; font-weight: 700; white-space: nowrap; }
.modal-close { width: 34px; height: 34px; font-size: 18px; }
.cz-body { flex: 1; overflow-y: auto; padding: 4px 18px 18px; }
.cz-section { display: flex; flex-direction: column; gap: 14px; }
.cz-heading { margin: 0; font-size: 15px; font-weight: 700; }
.cz-rule { margin: 20px 0; border: 0; border-top: 1px solid #1c1f24; }
.cz-field { display: flex; flex-direction: column; gap: 7px; }
.cz-label { font-size: 13.5px; font-weight: 700; color: #e9ebee; }
.cz-label-row { display: flex; justify-content: space-between; align-items: center; }
.cz-count { font-size: 13.5px; font-weight: 700; color: #e9ebee; }
.cz-input {
  width: 100%;
  height: 40px;
  padding: 0 16px;
  border: 1px solid #2a2e34;
  border-radius: 14px;
  background: #050607;
  color: #f2f3f5;
  font-size: 14px;
  outline: 0;
}
.cz-input::placeholder { color: #8a9098; }
.cz-input:focus { border-color: #3b6fb3; }
.cz-input--sub { height: 34px; font-size: 13px; border-radius: 12px; margin-top: 6px; }
.cz-input.is-invalid { border-color: #c2413c; }
.cz-item { display: flex; flex-direction: column; }
.cz-select { appearance: none; background: #050607 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a3a8ad' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 14px center / 16px; }
.cz-select option { background: #0b0e12; }

.cz-range {
  --fill: 0%;
  appearance: none;
  width: 100%;
  height: 20px;
  margin: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #2a3442 var(--fill), #141619 var(--fill));
}
.cz-range::-webkit-slider-thumb { appearance: none; width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 1px 4px rgba(0, 0, 0, .6); }
.cz-range::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 0; }
.cz-ticks { display: flex; justify-content: space-between; padding: 0 4px; font-size: 11px; color: var(--text-mute); }

.cz-brand-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 15px;
  font-weight: 700;
  text-align: left;
}
.cz-brand-toggle span { flex: 1; }
.cz-brand-toggle .icon { font-size: 16px; }
.cz-chevron { transition: transform .15s; transform: rotate(180deg); }
.cz-brand-toggle[aria-expanded='false'] .cz-chevron { transform: none; }
.cz-brand-body { display: flex; flex-direction: column; gap: 14px; }
.cz-brand-body[hidden] { display: none; }

.cz-presets { display: flex; gap: 8px; }
.cz-preset {
  display: grid;
  place-items: center;
  width: 52px;
  height: 38px;
  padding: 0;
  border: 1px solid #2a2e34;
  border-radius: 8px;
  background: var(--sw-bg);
}
.cz-preset.is-active { border-color: #3b8cff; box-shadow: 0 0 0 1px #3b8cff; }
.cz-preset-pill { width: 22px; height: 9px; border-radius: 999px; background: var(--sw-fg); }

.cz-colors { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cz-color-field { display: flex; flex-direction: column; gap: 6px; }
.cz-color-row { display: flex; gap: 6px; }
.cz-color {
  flex: none;
  width: 40px;
  height: 36px;
  padding: 2px;
  border: 1px solid #2a2e34;
  border-radius: 10px;
  background: #050607;
}
.cz-color::-webkit-color-swatch-wrapper { padding: 0; }
.cz-color::-webkit-color-swatch { border: 0; border-radius: 7px; }
.cz-hex { height: 36px; padding: 0 10px; border-radius: 10px; font-size: 13px; font-family: ui-monospace, Consolas, monospace; text-transform: lowercase; }

.cz-logo-preview { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.cz-logo-preview img { max-height: 44px; max-width: 120px; object-fit: contain; border-radius: 6px; background: repeating-conic-gradient(#1a1d21 0 25%, #121417 0 50%) 0 0 / 12px 12px; padding: 4px; margin-right: auto; }
.cz-logo-preview .cz-muted { margin-right: auto; }
.cz-muted { color: var(--text-mute); font-size: 13px; }
.cz-note { margin: 0; min-height: 1em; font-size: 12.5px; color: #f1c35b; }
.cz-note:empty { display: none; }

.cz-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  padding: 0 14px;
  border: 1px solid #2a2e34;
  border-radius: 10px;
  background: #101317;
  color: #e9ebee;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.cz-btn:hover { border-color: #3b6fb3; }
.cz-btn--ghost { background: transparent; color: var(--text-dim); }
.cz-btn--primary { height: 40px; padding: 0 24px; border: 0; background: var(--blue); color: #fff; }
.cz-btn--primary:hover { background: #4a9dff; }
/* Safe-zone guides (designer aid; outside .stage, never exported) */
.sz-overlay { position: absolute; inset: 0; pointer-events: none; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .55); }
.sz-overlay[hidden] { display: none; }
.sz-safe {
  position: absolute;
  outline: 1px dashed rgba(94, 234, 212, .95);
  /* everything outside the safe rect = potential danger zone */
  box-shadow: 0 0 0 9999px rgba(255, 72, 72, .16);
}
.sz-tag {
  /* sits just above the safe box (in the margin) so it never covers content */
  position: absolute;
  bottom: calc(100% + 2px);
  left: 0;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(10, 40, 36, .85);
  color: #5eead4;
  font: 700 10px/1.5 var(--font);
  letter-spacing: .03em;
}
.sz-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid #252e39;
  border-radius: 999px;
  background: #11161d;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.sz-toggle:hover { color: var(--text); }
.sz-toggle-box { width: 10px; height: 10px; border: 1.5px dashed currentColor; border-radius: 2px; }
.sz-toggle[aria-pressed='true'] { border-color: #2a7f74; background: #0d2522; color: #5eead4; }
.sz-info { margin: 10px 0 0; font-size: 12px; color: #5eead4; text-align: center; }
.sz-info[hidden] { display: none; }

/* Segmented choice (Background Mode, template State) */
.cz-segmented { display: flex; padding: 3px; border: 1px solid #2a2e34; border-radius: 12px; background: #050607; }
.cz-seg { flex: 1; height: 32px; border: 0; border-radius: 9px; background: transparent; color: var(--text-dim); font-size: 13px; font-weight: 700; }
.cz-seg:hover { color: var(--text); }
.cz-seg.is-active { background: #1c2733; color: #fff; box-shadow: inset 0 0 0 1px #3b6fb3; }

/* Background color swatches (8 presets + Custom HEX) */
.cz-swatches { display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px; }
.cz-swatch {
  aspect-ratio: 1;
  padding: 0;
  border: 2px solid #2a2e34;
  border-radius: 50%;
  background: var(--sw, #1a1d21) center / cover no-repeat;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .35);
}
.cz-swatch:hover { border-color: #56606c; }
.cz-swatch.is-active { border-color: #fff; }
.cz-swatch--custom {
  display: grid;
  place-items: center;
  background: conic-gradient(#ef4444, #eab308, #22c55e, #14b8a6, #0475ff, #8b5cf6, #ec4899, #ef4444);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  text-shadow: 0 1px 2px #000;
}
.cz-btn--sm { height: 26px; padding: 0 9px; font-size: 12px; }

.cz-hint { margin-top: -3px; font-size: 12px; color: var(--text-mute); }
.cz-hint:empty { display: none; }

/* A-roll layer (between background and graphic) + media placed in template slots */
.media-layer { position: absolute; inset: 0; overflow: hidden; }
.media-layer[hidden] { display: none; }
.media-layer.is-blur .media-fill { filter: blur(22px) brightness(.85) saturate(1.1); transform: scale(1.08); }
.media-fill { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 45% 40%; display: block; border-radius: inherit; }
[data-slot].has-media > :not(.media-fill) { visibility: hidden; }
[data-slot].has-media > .media-fill { visibility: visible; }

/* Animation + media controls */
.cz-inline { display: flex; gap: 6px; }
.cz-progress { height: 3px; border-radius: 2px; background: #141619; overflow: hidden; }
.cz-progress-bar { display: block; height: 100%; background: var(--blue); transform-origin: 0 50%; transform: scaleX(0); }
.cz-media-row { display: flex; align-items: center; gap: 8px; }
.cz-media-row .cz-select { flex: 1; }
.cz-select--sm { height: 34px; border-radius: 10px; font-size: 13px; }
.cz-toggle {
  display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 14px; flex: none;
  border: 1px solid #2a2e34; border-radius: 999px; background: #050607; color: var(--text-dim);
  font-size: 13px; font-weight: 700;
}
.cz-toggle-dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid currentColor; }
.cz-toggle[aria-pressed='true'] { border-color: #3b6fb3; background: #132640; color: #fff; }
.cz-toggle[aria-pressed='true'] .cz-toggle-dot { background: #4cc3ff; border-color: #4cc3ff; }
.cz-images { display: flex; flex-direction: column; gap: 6px; }
.cz-image-row { display: flex; align-items: center; gap: 8px; }
.cz-image-row .cz-label { min-width: 64px; }
.cz-image-row .cz-muted { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.cz-foot { display: flex; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid #16191d; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .modal-backdrop { padding: 0; }
  .modal {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(240px, 42vh) minmax(0, 1fr);
    height: 100%;
    border-radius: 0;
  }
  .modal-preview { border-right: 0; border-bottom: 1px solid #161c24; padding: 12px; }
  .preview-note { display: none; }
}

@media (max-width: 520px) {
  .preview-bar { flex-wrap: wrap; }
}
