/* ================================================================
   LINH LAN template shell — page chrome around each template canvas
   The canvas itself is either 1080×1080 (Feed) or 1080×1920 (Reels)
   rendered at half-scale (540 / 960) on screen but exported at real size.
   ================================================================ */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: #F3E9E9;
  font-family: var(--font-body);
  color: var(--espresso);
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

.workbench {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr;
  padding: 40px 40px 60px;
  gap: 32px;
}

.workbench-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(22,13,12,0.14);
}
.workbench-head .crumb {
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--walnut);
}
.workbench-head .crumb a {
  color: inherit; text-decoration: none;
  border-bottom: 1px solid transparent;
}
.workbench-head .crumb a:hover { border-bottom-color: currentColor; }
.workbench-head h1 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 30px;
  line-height: 1.1;
  margin: 8px 0 0;
  color: var(--espresso);
}
.workbench-head h1 em {
  font-style: italic; color: var(--earth); font-weight: 400;
}
.workbench-head .format {
  font-family: var(--font-ui);
  font-size: 10.5px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--walnut);
  padding: 8px 14px;
  border: 1px solid rgba(103,83,83,0.35);
  border-radius: 999px;
  white-space: nowrap;
}

.workbench-body {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 40px;
  align-items: start;
}

.canvas-mount {
  display: flex; justify-content: center;
  padding: 20px 0;
}

/* Card frame around the export canvas */
.export-frame {
  position: relative;
  box-shadow: 0 30px 60px -20px rgba(103,83,83,0.35), 0 10px 20px -10px rgba(22,13,12,0.15);
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface, #EBD5D5);
}

/* The two canvas sizes — exported at 2x the on-screen size.
   Both min- and max- are pinned so that inner grid/flex layouts (whose
   auto-sizing can otherwise shrink an "explicit" parent height) cannot
   collapse the canvas below its export dimensions. */
.canvas-1x1 {
  width: 540px !important;
  height: 540px !important;
  min-height: 540px !important;
  max-height: 540px !important;
  min-width: 540px !important;
  max-width: 540px !important;
  position: relative; overflow: hidden;
  background: var(--surface);
  color: var(--ink);
  flex-shrink: 0;
}
.canvas-9x16 {
  width: 360px !important;
  height: 640px !important;
  min-height: 640px !important;
  max-height: 640px !important;
  min-width: 360px !important;
  max-width: 360px !important;
  position: relative; overflow: hidden;
  background: var(--surface);
  color: var(--ink);
  flex-shrink: 0;
}
/* Storyboard grids override — templates 04/05 need percent-width frames */
.storyboard .canvas-9x16 {
  width: 100% !important;
  min-width: 0 !important;
  max-width: none !important;
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  aspect-ratio: 9/16;
}
.carousel-row .canvas-1x1 {
  width: 380px !important;
  height: 380px !important;
  min-height: 380px !important;
  max-height: 380px !important;
  min-width: 380px !important;
  max-width: 380px !important;
}
/* Every child inside a canvas honours border-box */
.canvas-1x1 *, .canvas-1x1 *::before, .canvas-1x1 *::after,
.canvas-9x16 *, .canvas-9x16 *::before, .canvas-9x16 *::after { box-sizing: border-box; }

/* Canvas layouts must fill the full 540×540 (or 360×640) so exports come
   out as square/9:16. Each template's main layout class opts in with
   `height: 100%` at its own selector. The rule below is a safety net
   for canvases whose only-child is a full-bleed layout. */

/* Small caption under a canvas */
.canvas-caption {
  margin-top: 12px;
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: 0.20em;
  text-transform: uppercase;
  color: var(--walnut);
  display: flex; gap: 14px; justify-content: center; align-items: center;
}
.canvas-caption .dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--soft-lilac);
}

/* ---------- Editor panel ---------- */
.editor {
  position: sticky; top: 40px;
  background: #fff;
  border: 1px solid rgba(22,13,12,0.10);
  border-radius: 10px;
  padding: 22px 22px 24px;
  font-family: var(--font-ui);
  box-shadow: 0 12px 40px -20px rgba(103,83,83,0.35);
}
.editor h3 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 18px;
  color: var(--espresso);
}
.editor .sub {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 12px;
  color: var(--walnut);
  margin: 0 0 18px;
  line-height: 1.5;
}
.editor .group {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(22,13,12,0.08);
}
.editor .group:last-child { border-bottom: none; padding-bottom: 0; }
.editor .group h4 {
  margin: 0 0 8px;
  font-size: 9.5px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--walnut);
  font-weight: 600;
}

/* Segmented control (theme + accent swatches) */
.seg {
  display: flex; gap: 6px;
  background: #f5efef;
  border-radius: 8px;
  padding: 4px;
}
.seg button {
  flex: 1;
  border: 0; background: transparent;
  padding: 8px 10px;
  border-radius: 6px;
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--walnut);
  cursor: pointer;
  transition: all 0.15s ease;
}
.seg button:hover { color: var(--espresso); }
.seg button.on {
  background: var(--espresso);
  color: var(--ivory);
}

.accent-swatches {
  display: flex; gap: 8px;
}
.accent-swatches button {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  outline-offset: 2px;
  transition: transform 0.15s ease;
}
.accent-swatches button:hover { transform: scale(1.1); }
.accent-swatches button.on {
  border-color: var(--espresso);
}

/* Save / export buttons */
.save-btn {
  width: 100%;
  padding: 12px 16px;
  background: var(--espresso);
  color: var(--ivory);
  border: 0;
  border-radius: 8px;
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 0.20em;
  text-transform: uppercase;
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.save-btn:hover { opacity: 0.85; }
.save-btn.secondary {
  background: transparent;
  color: var(--walnut);
  border: 1px solid rgba(103,83,83,0.4);
  margin-top: 8px;
}
.save-btn.secondary:hover { color: var(--espresso); border-color: var(--espresso); }

.editor-hint {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 11px;
  color: var(--warm-grey);
  line-height: 1.5;
  margin-top: 12px;
}

/* ============================================================
   Photo slot (click to replace, drag to pan, wheel/pinch to zoom)
   ============================================================ */
[data-photo-slot] { position: relative; }

/* Edit-mode overlay + hint — injected as real DOM children so we don't
   collide with any template's own ::before / ::after pseudo-elements. */
.photo-slot-overlay {
  position: absolute; inset: 0;
  background: rgba(22,13,12,0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 5;
  display: flex; align-items: center; justify-content: center;
}
.photo-slot-overlay .hint {
  padding: 8px 14px;
  background: rgba(251,248,248,0.95);
  color: var(--espresso);
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  border-radius: 999px;
  white-space: nowrap;
}
body.editing [data-photo-slot] { cursor: pointer; }
body.editing [data-photo-slot]:hover .photo-slot-overlay { opacity: 1; }
body.editing [data-photo-slot].panning { cursor: grabbing; }
body.editing [data-photo-slot].panning .photo-slot-overlay { opacity: 0; }

/* Photo pan-zoom controls — mini toolbar bottom-right of the slot */
.photo-toolbar {
  position: absolute;
  bottom: 8px; right: 8px;
  display: none;
  gap: 4px;
  background: rgba(251,248,248,0.94);
  border-radius: 999px;
  padding: 4px;
  z-index: 7;
  box-shadow: 0 4px 12px -4px rgba(22,13,12,0.35);
}
body.editing [data-photo-slot]:hover .photo-toolbar,
body.editing [data-photo-slot].panning .photo-toolbar,
body.editing .photo-toolbar.pinned { display: flex; }
.photo-toolbar button {
  border: 0; background: transparent;
  width: 24px; height: 24px; border-radius: 50%;
  font-family: var(--font-ui);
  font-size: 13px; color: var(--espresso);
  cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s ease;
}
.photo-toolbar button:hover { background: rgba(22,13,12,0.08); }
.photo-toolbar .zoom-label {
  font-family: var(--font-num);
  font-size: 10px;
  color: var(--walnut);
  padding: 0 6px;
  min-width: 32px;
  text-align: center;
  align-self: center;
}

/* Hidden file input (one per canvas) */
.photo-file-input { display: none; }

/* Inline edit highlight */
[contenteditable="true"] {
  outline: none;
  transition: box-shadow 0.15s ease, background 0.15s ease;
  border-radius: 3px;
}
body.editing [contenteditable="true"] {
  box-shadow: 0 0 0 1px rgba(188,147,178,0.4);
  background: rgba(188,147,178,0.06);
}
body.editing [contenteditable="true"]:hover {
  box-shadow: 0 0 0 1px rgba(188,147,178,0.7);
  background: rgba(188,147,178,0.12);
}
[contenteditable="true"]:focus {
  box-shadow: 0 0 0 2px var(--soft-lilac) !important;
  background: rgba(188,147,178,0.15) !important;
}

/* Print (rare but supported) — hide editor, show only canvas */
@media print {
  body { background: #fff; }
  .workbench-head, .editor, .canvas-caption { display: none !important; }
  .workbench, .workbench-body { display: block; padding: 0; margin: 0; }
  .export-frame { box-shadow: none; border-radius: 0; }
}

/* Responsive collapse */
@media (max-width: 900px) {
  .workbench-body { grid-template-columns: 1fr; }
  .editor { position: static; }
}
