/* Collection Wall Composer (#631) — share-page owner tool.
   All selectors are cc-/collection-wall- prefixed so nothing collides
   with the showcase template's own styles. */

/* Header actions row: the wall button sits beside the view switcher and
   wraps cleanly on phones instead of overflowing. */
.collection-header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.collection-wall-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.42rem 0.95rem;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: rgba(255, 255, 255, 0.10);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    cursor: pointer;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
    white-space: nowrap;
}

.collection-wall-btn:hover,
.collection-wall-btn:focus-visible {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.38);
    transform: translateY(-1px);
    color: #fff;
}

/* custom.css gives every .fas a right margin; the flex gap already
   provides the spacing here. Scoped override, never delete the global. */
.collection-wall-btn .fas {
    margin-right: 0;
}

/* ---------- Overlay / dialog (mounted on document.body) ---------- */

.cc-overlay {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(8, 10, 18, 0.74);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
}

body.cc-lock-scroll {
    overflow: hidden;
}

.cc-dialog {
    display: flex;
    flex-direction: column;
    width: min(1180px, 100%);
    height: min(860px, 100%);
    background: linear-gradient(160deg, rgba(30, 34, 54, 0.97), rgba(12, 14, 24, 0.98));
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 22px;
    overflow: hidden;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
    color: #fff;
}

.cc-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1.1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-wrap: wrap;
}

.cc-title-block {
    margin-right: auto;
    min-width: 0;
}

.cc-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.2;
}

.cc-subtitle {
    display: block;
    font-size: 0.76rem;
    color: rgba(255, 255, 255, 0.65);
}

.cc-tools {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.cc-tool-btn,
.cc-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-width: 38px;
    height: 38px;
    padding: 0 0.7rem;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 0.82rem;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.cc-tool-btn .fas,
.cc-close .fas {
    margin-right: 0;
}

.cc-tool-btn:hover:not(:disabled),
.cc-close:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.34);
}

.cc-tool-btn.cc-tool-active {
    background: rgba(91, 222, 235, 0.22);
    border-color: rgba(142, 234, 255, 0.7);
    color: #c9f7ff;
}

.cc-save:disabled,
.cc-tool-btn:disabled,
.cc-close:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* ---------- Stage (free canvas) ---------- */

.cc-stage {
    position: relative;
    flex: 1;
    overflow: hidden;
    touch-action: none;
    cursor: grab;
    background-color: rgba(10, 12, 22, 0.6);
    background-image: radial-gradient(rgba(255, 255, 255, 0.07) 1px, transparent 1.4px);
    background-size: 26px 26px;
}

.cc-stage.cc-grabbing {
    cursor: grabbing;
}

.cc-world {
    position: absolute;
    left: 0;
    top: 0;
    transform-origin: 0 0;
    will-change: transform;
}

.cc-piece {
    position: absolute;
    box-sizing: border-box;
    border: 3px solid rgba(255, 255, 255, 0.92);
    border-radius: 4px;
    background: linear-gradient(135deg, #2a2f4a, #141a2e);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45);
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.cc-piece:active {
    cursor: grabbing;
}

.cc-piece img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    border-radius: 2px;
    pointer-events: none;
}

.cc-piece-transparent,
.cc-tray-transparent {
    background-color: #f2f5fb;
    background-image:
        linear-gradient(45deg, rgba(31, 48, 80, 0.14) 25%, transparent 25%),
        linear-gradient(-45deg, rgba(31, 48, 80, 0.14) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, rgba(31, 48, 80, 0.14) 75%),
        linear-gradient(-45deg, transparent 75%, rgba(31, 48, 80, 0.14) 75%);
    background-size: 12px 12px;
    background-position: 0 0, 0 6px, 6px -6px, -6px 0;
}

.cc-transparency-badge {
    position: absolute;
    left: 4px;
    top: 4px;
    z-index: 2;
    max-width: calc(100% - 8px);
    box-sizing: border-box;
    padding: 2px 5px;
    border: 1px solid rgba(151, 233, 255, 0.58);
    border-radius: 999px;
    background: rgba(7, 22, 41, 0.82);
    color: #bff5ff;
    font-size: 9px;
    font-weight: 700;
    line-height: 1.1;
    overflow-wrap: anywhere;
    text-align: center;
    white-space: normal;
    pointer-events: none;
}

.cc-piece-size {
    position: absolute;
    left: 50%;
    bottom: 6px;
    z-index: 2;
    transform: translateX(-50%);
    max-width: calc(100% - 8px);
    box-sizing: border-box;
    padding: 1px 8px;
    border-radius: 999px;
    background: rgba(10, 12, 20, 0.84);
    color: rgba(255, 255, 255, 0.9);
    font-size: 10px;
    white-space: nowrap;
    pointer-events: none;
}

.cc-piece-remove {
    position: absolute;
    top: -12px;
    right: -12px;
    z-index: 3;
    width: 26px;
    height: 26px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    background: rgba(10, 14, 26, 0.92);
    color: #fff;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    /* Counter-scale against the world zoom (set from applyWorld) so the
       control keeps a constant on-screen size. */
    transform: scale(var(--cc-inv-zoom, 1));
    transform-origin: top right;
}

.cc-piece-remove:hover:not(:disabled) {
    background: #d9534f;
    border-color: #d9534f;
}

.cc-piece-remove:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.cc-spacing-layer {
    position: absolute;
    inset: 0;
    /* Keep measurements above every piece, including saved layouts whose
       z values are higher than the default piece order. */
    z-index: 1000;
    pointer-events: none;
}

.cc-spacing-measure {
    position: absolute;
    color: #8eeaff;
    pointer-events: none;
}

.cc-spacing-horizontal {
    height: 0;
}

.cc-spacing-vertical {
    width: 0;
}

.cc-spacing-line {
    position: absolute;
    display: block;
    border-color: currentColor;
    border-style: dashed;
    opacity: 0.95;
}

.cc-spacing-horizontal .cc-spacing-line {
    top: 0;
    left: 0;
    width: 100%;
    border-top-width: 1px;
}

.cc-spacing-vertical .cc-spacing-line {
    top: 0;
    left: 0;
    height: 100%;
    border-left-width: 1px;
}

.cc-spacing-label {
    position: absolute;
    z-index: 1;
    padding: 2px 5px;
    border: 1px solid rgba(142, 234, 255, 0.58);
    border-radius: 999px;
    background: rgba(5, 20, 38, 0.9);
    color: #c9f7ff;
    font-size: 10px;
    font-weight: 700;
    line-height: 1.1;
    white-space: nowrap;
}

.cc-spacing-horizontal .cc-spacing-label {
    left: 50%;
    top: 0;
    transform: translate(-50%, -50%) scale(var(--cc-inv-zoom, 1));
    transform-origin: center;
}

.cc-spacing-vertical .cc-spacing-label {
    left: 0;
    top: 50%;
    transform: translate(-50%, -50%) scale(var(--cc-inv-zoom, 1));
    transform-origin: center;
}

.cc-hint {
    position: absolute;
    left: 50%;
    bottom: 12px;
    transform: translateX(-50%);
    max-width: 92%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0.3rem 0.85rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 999px;
    background: rgba(10, 12, 20, 0.55);
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.72rem;
    pointer-events: none;
}

/* ---------- Tray: pictures off the wall ---------- */

.cc-tray {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 0 0 auto;
    padding: 0.5rem 1.1rem;
    overflow-x: auto;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(9, 13, 26, 0.85);
}

.cc-tray-label {
    flex: 0 0 auto;
    font-size: 0.76rem;
    color: rgba(255, 255, 255, 0.6);
}

.cc-tray-item {
    position: relative;
    flex: 0 0 auto;
    width: 54px;
    height: 54px;
    padding: 2px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 0.55rem;
    background: rgba(255, 255, 255, 0.06);
    cursor: pointer;
    /* The "+" badge overflows the corner and must stay visible. */
    overflow: visible;
}

.cc-tray-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 0.4rem;
    display: block;
    pointer-events: none;
}

.cc-tray-item .cc-tray-add {
    position: absolute;
    top: -7px;
    right: -7px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #7ee2a8;
    color: #06341c;
    font-size: 13px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    pointer-events: none;
}

.cc-tray-item:hover:not(:disabled) {
    border-color: rgba(255, 255, 255, 0.5);
}

.cc-tray-item:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ---------- Footer ---------- */

.cc-footer {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.8rem 1.1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    flex-wrap: wrap;
}

.cc-status {
    flex: 1 1 260px;
    min-width: 200px;
    display: none;
}

.cc-status.cc-visible {
    display: block;
}

.cc-status-text {
    margin-bottom: 0.3rem;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.85);
}

.cc-status.cc-error .cc-status-text {
    color: #ff9f9f;
}

.cc-progress-track {
    height: 6px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    overflow: hidden;
}

.cc-status.cc-error .cc-progress-track {
    display: none;
}

.cc-progress-bar {
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: linear-gradient(90deg, #7bd0ff, #80d0c7);
    transition: width 0.4s ease;
}

.cc-note {
    flex: 1;
    min-width: 180px;
    font-size: 0.74rem;
    color: rgba(255, 255, 255, 0.55);
}

.cc-save {
    border: none;
    border-radius: 999px;
    padding: 0.65rem 1.4rem;
    font-size: 0.9rem;
    font-weight: 700;
    color: #0b1020;
    background: linear-gradient(135deg, #9ee7ff, #80d0c7);
    box-shadow: 0 10px 26px rgba(128, 208, 199, 0.35);
    cursor: pointer;
}

.cc-history {
    position: absolute;
    z-index: 6;
    top: 4.5rem;
    right: 1rem;
    width: min(26rem, calc(100% - 2rem));
    max-height: min(65vh, 36rem);
    overflow: auto;
    padding: 0.85rem;
    border: 1px solid rgba(160, 230, 255, 0.26);
    border-radius: 1rem;
    background: rgba(11, 16, 32, 0.96);
    box-shadow: 0 18px 54px rgba(0, 0, 0, 0.4);
}

.cc-history h3 {
    margin: 0 0 0.6rem;
    font-size: 0.9rem;
    color: #d8f6ff;
}

.cc-history-item {
    display: grid;
    grid-template-columns: 42px 1fr auto auto auto;
    gap: 0.45rem;
    align-items: center;
    padding: 0.45rem 0;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.cc-history-item img {
    width: 42px;
    height: 42px;
    object-fit: cover;
    border-radius: 0.55rem;
}

.cc-history-details {
    min-width: 0;
    font-size: 0.74rem;
    color: rgba(255, 255, 255, 0.75);
}

.cc-history .cc-tool-btn {
    padding: 0.38rem 0.48rem;
    font-size: 0.72rem;
}

/* ---------- Phones ---------- */

@media (max-width: 640px) {
    .cc-overlay {
        padding: 0;
    }

    .cc-dialog {
        width: 100%;
        height: 100%;
        border-radius: 0;
        border: none;
    }

    .cc-tool-label {
        display: none;
    }

    .cc-note {
        flex-basis: 100%;
        order: 2;
        text-align: center;
    }

    .cc-save {
        flex: 1 1 100%;
        order: 1;
    }

    .cc-status {
        order: 0;
        flex-basis: 100%;
    }

    .cc-history {
        top: 4rem;
        right: 0.5rem;
        width: calc(100% - 1rem);
    }

    .cc-history-item {
        grid-template-columns: 38px 1fr auto auto;
    }

    .cc-history-item .cc-tool-label {
        display: inline;
    }
}

@media (prefers-reduced-motion: reduce) {
    .collection-wall-btn,
    .cc-tool-btn,
    .cc-close,
    .cc-progress-bar {
        transition: none;
    }
}
