/* =========================================================================
 * Picsin v2 — Atelier Create Photo Collage (Phase L.1 + L.2)
 * Layered on top of atelier-print-create.css (loaded globally via the
 * atelier layout). Re-uses .atl-* base components; adds .acl-* extensions
 * for collage-specific surfaces — orientation pills, multi-slot artframe,
 * photo tray, template gallery, swatch segments.
 *
 * L.2 (2026-04-29) introduces --acl-slot-gap — the uniform space between
 * adjacent slots. Tune in one place, applies everywhere.
 * ========================================================================= */

/* ---------- Tunables ---------- */
.acl-main {
    /* The single knob that controls (a) the visible gap between adjacent
       slots AND (b) the outer breathing space between the outermost slots
       and the artframe edge. Both are equal — by design. Half of this
       value is applied as inset on each side of every slot, so adjacent
       slots show a combined gap equal to this number; the .acl-slots host
       is also inset by half this value, which combined with the slot's
       own half-inset gives the outer edge the same total breathing space. */
    --acl-slot-gap: 8px;
}

/* ---------- Page wrapper ---------- */
.acl-main { /* same as .atl-main, namespaced for clarity */ }
.acl-grid { /* same 2-col grid; reuses .atl-grid */ }

/* ---------- Stage / artframe — collage chrome by data-finish ---------- */

/* Photo Print — bare image, no chrome */
.acl-artframe[data-finish="photo-print"] {
    padding: 0;
    background: transparent;
    box-shadow: 0 18px 40px -16px rgba(40,32,22,.25);
}
.acl-artframe[data-finish="photo-print"] .acl-artinner {
    background: #efeae0;
    padding: 0;
}

/* Canvas — flush image with deep shadow */
.acl-artframe[data-finish="canvas"] {
    padding: 0;
    background: transparent;
    box-shadow: 0 18px 40px -14px rgba(40,32,22,.3),
                inset 0 0 0 1px rgba(0,0,0,.04);
}
.acl-artframe[data-finish="canvas"] .acl-artinner {
    background: #efeae0;
    padding: 0;
}

/* Framed — outer frame chrome (background = swatch hex applied via JS),
   inner white margin around the slots */
.acl-artframe[data-finish="framed"] {
    padding: 28px;
    box-shadow: 0 30px 60px -20px rgba(40,32,22,.35),
                0 10px 20px -8px rgba(40,32,22,.25);
}
.acl-artframe[data-finish="framed"] .acl-artinner {
    background: #fbfaf6;
    padding: 12px;
}

/* ---------- Empty-template state (default until user picks layout) ---------- */
.acl-no-template {
    width: 100%; height: 100%;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 10px;
    background: repeating-linear-gradient(45deg, transparent 0 10px, rgba(0,0,0,.02) 10px 11px);
    border: 1.5px dashed var(--line-2);
    border-radius: 4px;
    padding: 32px;
    color: var(--ink-3);
    text-align: center;
}
.acl-no-template-icon { color: var(--ink-3); }
.acl-no-template-title {
    font-family: var(--serif);
    font-size: 24px;
    color: var(--ink);
    font-weight: 400;
    letter-spacing: -0.01em;
}
.acl-no-template-sub {
    font-size: 12px;
    color: var(--ink-3);
    line-height: 1.4;
    max-width: 260px;
}

/* ---------- Slot host (multi-slot positioning surface) ----------
   Absolutely positioned + inset by half-gap on every side. This gives the
   OUTER edges of the collage the same breathing space as between slots:
   each individual slot's image is inset by another half-gap inside its slot,
   so outer-edge total = full --acl-slot-gap, matching inter-slot gap. layout_json
   percentages keep working unchanged — they are now percentages of this
   inset rectangle, not the full artinner. */
.acl-slots {
    position: absolute;
    top:    calc(var(--acl-slot-gap) / 2);
    right:  calc(var(--acl-slot-gap) / 2);
    bottom: calc(var(--acl-slot-gap) / 2);
    left:   calc(var(--acl-slot-gap) / 2);
}

/* Each slot — absolutely positioned by x/y/w/h percentages from layout_json.
   The slot itself is just a positioning rectangle. The visible frame
   (background + hairline border) is drawn via ::before, inset by half the
   --acl-slot-gap on each side. Children (img / drop / overlay) are also
   inset by the same amount (rules below) so they sit inside the visible
   frame. Two adjacent slots therefore show a combined gap = --acl-slot-gap.
   layout_json math stays clean (full 0–100 percentages). */
.acl-slot {
    position: absolute;
    cursor: pointer;
    overflow: hidden;            /* CRITICAL — clips the slot image to slot bounds.
                                    Without this, an <img> child may render at intrinsic
                                    size and bleed across adjacent slots. */
    transition: opacity .12s;
}
.acl-slot::before {
    content: '';
    position: absolute;
    top:    calc(var(--acl-slot-gap) / 2);
    right:  calc(var(--acl-slot-gap) / 2);
    bottom: calc(var(--acl-slot-gap) / 2);
    left:   calc(var(--acl-slot-gap) / 2);
    background: rgba(20, 14, 6, 0.04);
    box-shadow: inset 0 0 0 1px rgba(20, 14, 6, 0.06);
    pointer-events: none;
    transition: background .15s, box-shadow .15s;
    z-index: 0;
}
.acl-slot:hover::before {
    background: rgba(122, 90, 52, 0.06);
    box-shadow: inset 0 0 0 1.5px var(--accent);
}
.acl-slot.is-filled {
    cursor: default;
}
.acl-slot.is-filled::before {
    background: transparent;
    box-shadow: inset 0 0 0 1px rgba(20, 14, 6, 0.04);
}
/* Drag-over target — empty slot only. Stronger umber border + tinted fill. */
.acl-slot.is-drop-target::before {
    background: rgba(122, 90, 52, 0.12);
    box-shadow: inset 0 0 0 2px var(--accent);
}

/* Slot empty state — drop tile centred. Inset by half-gap so it sits
   inside the visible frame (which is also inset via ::before). */
.acl-slot-drop {
    position: absolute;
    top:    calc(var(--acl-slot-gap) / 2);
    right:  calc(var(--acl-slot-gap) / 2);
    bottom: calc(var(--acl-slot-gap) / 2);
    left:   calc(var(--acl-slot-gap) / 2);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 6px;
    pointer-events: none;
    color: var(--ink-3);
    text-align: center;
    padding: 8px;
    z-index: 1;
}
.acl-slot-drop-icon svg { display: block; }
.acl-slot-drop-label {
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: var(--ink-2);
    text-transform: uppercase;
}
.acl-slot-drop-sub {
    font-size: 10px;
    color: var(--ink-3);
}

/* Slot filled image — inset by half-gap to sit inside the visible frame.
   Explicit width + height (calc) instead of relying on top/right/bottom/left
   alone — replaced elements (<img>) can fall back to intrinsic sizing in
   some browsers when only offsets are set. With explicit width/height the
   sizing is deterministic. */
.acl-slot-img {
    position: absolute;
    top:    calc(var(--acl-slot-gap) / 2);
    left:   calc(var(--acl-slot-gap) / 2);
    width:  calc(100% - var(--acl-slot-gap));
    height: calc(100% - var(--acl-slot-gap));
    object-fit: cover;
    display: block;
    pointer-events: none;
    z-index: 1;
}

/* Slot hover overlay (filled state — Adjust crop / Replace / Remove).
   Inset to match the image so the overlay covers exactly the visible photo. */
.acl-slot-overlay {
    position: absolute;
    top:    calc(var(--acl-slot-gap) / 2);
    left:   calc(var(--acl-slot-gap) / 2);
    width:  calc(100% - var(--acl-slot-gap));
    height: calc(100% - var(--acl-slot-gap));
    display: none;
    align-items: center; justify-content: center;
    gap: 6px;
    background: rgba(20, 14, 6, 0.55);
    backdrop-filter: blur(2px);
    z-index: 2;
}
.acl-slot.is-filled:hover .acl-slot-overlay { display: flex; }
.acl-slot-action {
    display: inline-flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 6px 8px;
    background: transparent;
    border-radius: var(--radius);
    font-size: 10px;
    font-weight: 500;
    color: #fff;
    min-width: 50px;
    cursor: pointer;
    line-height: 1;
}
.acl-slot-action svg { display: block; }

/* ---------- Photo tray (preserves uploads across orientation/template change) ---------- */
.acl-photo-tray {
    margin-top: 14px;
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px 14px;
}
.acl-photo-tray-head {
    display: flex; align-items: baseline; justify-content: space-between;
    margin-bottom: 10px;
}
.acl-photo-tray-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-2);
    font-weight: 600;
}
.acl-photo-tray-help {
    font-size: 11px;
    color: var(--ink-3);
}
.acl-photo-tray-list {
    display: flex; gap: 8px; flex-wrap: wrap;
}
.acl-photo-tray-item {
    width: 56px; height: 56px;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--line);
    background: var(--bg-sunk);
    cursor: grab;
    position: relative;
    transition: border-color .12s, transform .12s, opacity .12s;
}
.acl-photo-tray-item:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
}
.acl-photo-tray-item:active { cursor: grabbing; }
.acl-photo-tray-item img {
    width: 100%; height: 100%; object-fit: cover; display: block;
    pointer-events: none;
}
/* Currently being dragged — dim the source so user sees what they're moving */
.acl-photo-tray-item.is-dragging {
    opacity: 0.4;
    cursor: grabbing;
}
/* Drop target indicator — thin umber bar on the LEFT edge of the target tray
   item, signalling "insert here, before this item" semantics. */
.acl-photo-tray-item.is-drop-before::before {
    content: '';
    position: absolute;
    left: -5px; top: 0; bottom: 0;
    width: 3px;
    background: var(--accent);
    border-radius: 2px;
}

/* × delete button on each tray thumbnail */
.acl-photo-tray-remove {
    position: absolute;
    top: 2px; right: 2px;
    width: 18px; height: 18px;
    border-radius: 50%;
    background: rgba(20, 14, 6, 0.7);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    border: none;
    padding: 0;
    opacity: 0;
    transition: opacity .12s, background .12s, transform .12s;
    z-index: 2;
}
.acl-photo-tray-item:hover .acl-photo-tray-remove,
.acl-photo-tray-remove:focus-visible { opacity: 1; }
.acl-photo-tray-remove:hover {
    background: var(--danger);
    transform: scale(1.08);
}
.acl-photo-tray-remove svg {
    width: 10px; height: 10px;
    stroke: currentColor;
}

.acl-photo-tray-empty {
    font-size: 12px;
    color: var(--ink-3);
    font-style: italic;
}

/* ---------- Template gallery (right column) ---------- */
.acl-template-gallery {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 4px;
}
.acl-template-card {
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px 8px 8px;
    cursor: pointer;
    transition: border-color .15s, transform .12s, box-shadow .15s;
    display: flex; flex-direction: column; gap: 6px; align-items: center;
}
.acl-template-card:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}
.acl-template-card.is-on {
    border-color: var(--ink);
    background: var(--bg-sunk);
    box-shadow: var(--shadow-sm);
}
.acl-template-preview {
    width: 100%;
    aspect-ratio: 1 / 1;
    background: #fff;
    border-radius: 3px;
    position: relative;
    overflow: hidden;
}
.acl-template-preview-slot {
    position: absolute;
    background: var(--ink-3);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.5);
}
.acl-template-card.is-on .acl-template-preview-slot {
    background: var(--ink);
}
.acl-template-name {
    font-size: 11px;
    color: var(--ink-2);
    font-weight: 500;
    text-align: center;
    line-height: 1.2;
}
.acl-template-slots-count {
    font-size: 10px;
    color: var(--ink-3);
    text-align: center;
}

/* ---------- Pending-change pills (orientation, template) ---------- */
.acl-pending-pill {
    margin: 8px 0 0;
    align-self: flex-start;
}

/* ---------- Orientation segbar (3-way) ---------- */
.acl-orientation-bar { /* inherits .atl-segbar */ }

/* ---------- Size dropdown (single select) ---------- */
.acl-size-row {
    display: inline-flex; align-items: center;
}
.acl-size-select {
    /* inherits .atl-size-select; just widen slightly */
    min-width: 140px;
}

/* ---------- Finish family bar (3-way) — same as product bar on /create-print ---------- */
.acl-finish-bar { /* inherits .atl-segbar */ }

/* ---------- Variant bars ---------- */
.acl-variant-bar { /* inherits .atl-segbar */ }

/* Swatch chip variant — frame colour */
.acl-variant-bar-swatches { padding: 4px; }
.acl-swatch-seg {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    padding: 8px 6px;
}
.acl-swatch-chip {
    display: inline-block;
    width: 24px; height: 24px;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.acl-swatch-seg .atl-seg-label {
    font-size: 11px;
    line-height: 1;
}
.acl-swatch-seg .atl-seg-note {
    font-size: 10px;
    line-height: 1;
}

/* ---------- Title (smaller than /create-print's display title) ---------- */
.acl-title {
    font-size: 36px;
}

/* ---------- Stage caption ---------- */
.acl-stage-foot { /* inherits .atl-stage-foot */ }

/* ---------- Mobile (≤ 820px) ---------- */
@media (max-width: 820px) {
    .acl-grid {
        grid-template-columns: 1fr;
        gap: 24px;
    }
    .acl-preview { position: static; }
    .acl-template-gallery {
        grid-template-columns: repeat(2, 1fr);
    }
    .acl-title {
        font-size: 28px;
    }
}
