/* =============================================================
   SureDash Post Image Grid — image-grid.css
   Version: 7.7.0
   ============================================================= */


/* =============================================================
   1. Feed card grid — shared item styles
   ============================================================= */

.spig-grid {
    width: 100%;
    border-radius: 8px;
    overflow: hidden;
    margin: 8px 0;
    line-height: 0;
}

.spig-item {
    overflow: hidden;
    cursor: pointer;
    position: relative;
    background: #1a1a1a;
    line-height: 0;
}

.spig-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.2s ease;
}

.spig-item:hover img {
    transform: scale(1.03);
}


/* =============================================================
   2. Grid layouts — count 1 through 6
   CSS only defines layouts up to 6. The JS DISPLAY_CAP constant
   must match: posts with 7–10 images show 6 tiles + "+N" overlay.

   Counts 2–6 use aspect-ratio: 1/1 on tiles so all grids are
   square-cropped regardless of original image orientation.
   Count 1 is never cropped — always shown at natural size.
   Count 3: right two tiles are square; left tile spans both rows
            and becomes a natural tall portrait strip.
   Count 5: first tile is a wide landscape hero (2:1 ratio auto-
            computed from 3-column layout); tiles 2–5 are square.
   ============================================================= */

/* ── Count 1: centered, natural height, no crop ─────────────── */
.spig-grid.spig-count-1 {
    max-width: 65%; /* fallback before orientation is detected */
    border-radius: 8px;
    margin-left: auto;
    margin-right: auto;
}

.spig-grid.spig-count-1.spig-portrait  { max-width: 100%; }
.spig-grid.spig-count-1.spig-landscape { max-width: 75%; }


.spig-grid.spig-count-1 .spig-item {
    border-radius: 8px;
    height: auto;
    max-height: none;
    overflow: visible;
}

.spig-grid.spig-count-1 .spig-item img {
    height: auto;
    width: 100%;
    object-fit: contain;
    background: transparent;
}


/* ── Count 1 portrait — "vertical video" treatment ──────────────
   A lone portrait image would otherwise sit as a tall, slim column
   in the middle of the card. Instead the box is capped at a fixed
   height and the sides fill with a blurred, desaturated copy of the
   same image — same idea as vertical-video letterboxing. Landscape
   singles are untouched (natural size, no crop, no fixed height —
   rules above).

   .spig-item-bg is injected by JS (image-grid.js,
   injectPortraitBgLayer()) only once orientation resolves to
   portrait — it never exists for any other grid layout.
   ============================================================= */
.spig-grid.spig-count-1.spig-portrait .spig-item {
    position: relative;
    width: 100%;
    height: 500px;
    max-height: 500px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent !important;
}

.spig-grid.spig-count-1.spig-portrait .spig-item-bg {
    position: absolute !important;
    inset: 0;
    z-index: 0;
    background-repeat: no-repeat;
    background-size: 160% auto; /* the actual zoom control — raise for a tighter crop, lower to show more width */
    background-position: center 30%; /* upper-middle band — face/upper body, not top-aligned */
    filter: blur(10px) saturate(0.6);
    opacity: 0.45;
    pointer-events: none;
}

.spig-grid.spig-count-1.spig-portrait .spig-item img {
    position: relative;
    z-index: 1;
    height: 100%;
    width: auto;
    max-width: 100%;
    object-fit: contain;
    background: transparent;
}

/* ── Count 2: two equal square columns ──────────────────────── */
.spig-grid.spig-count-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px;
}

.spig-grid.spig-count-2 .spig-item {
    aspect-ratio: 1 / 1;
}

/* ── Count 3: left tall portrait strip, right 2 squares ─────── */
.spig-grid.spig-count-3 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 3px;
/*    max-width: 75%;*/
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
}

.spig-grid.spig-count-3 .spig-item:first-child {
    grid-row: 1 / 3;
    /* Height is determined by the two square siblings:
       fills both rows naturally for a portrait strip. */
}

.spig-grid.spig-count-3 .spig-item:not(:first-child) {
    aspect-ratio: 1 / 1;
}

/* ── Count 4: 2×2 square grid ───────────────────────────────── */
.spig-grid.spig-count-4 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 3px;
}

.spig-grid.spig-count-4 .spig-item {
    aspect-ratio: 1 / 1;
}

/* ── Count 5: wide landscape hero + 4 squares ───────────────── */
/* 3-column layout. Item 1 spans cols 1–2 (hero, fixed 2:1 ratio).
   Item 2 sits in col 3, row 1, stretches to match hero height
   (no aspect-ratio — grid fills it to same row height as item 1).
   Items 3–5 fill row 2 across all 3 columns, all square.          */
.spig-grid.spig-count-5 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 3px;
/*    max-width: 75%;*/
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
}

.spig-grid.spig-count-5 .spig-item:nth-child(1) {
    grid-column: 1 / 3;
    aspect-ratio: 2 / 1; /* Sets row 1 height; item 2 stretches to match. */
}

.spig-grid.spig-count-5 .spig-item:nth-child(2) {
    grid-column: 3 / 4;
    aspect-ratio: 1 / 1; /* Matches row height set by hero's 2/1 ratio — no gap. */
}

.spig-grid.spig-count-5 .spig-item:nth-child(n+3) {
    aspect-ratio: 1 / 1;
}

/* ── Count 6: 3×2 square grid ───────────────────────────────── */
.spig-grid.spig-count-6 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 3px;
}

.spig-grid.spig-count-6 .spig-item {
    aspect-ratio: 1 / 1;
}


/* =============================================================
   3. "+N more" overflow overlay
   ============================================================= */

.spig-item.spig-has-more img {
    filter: brightness(0.45);
}

.spig-more-label {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 28px;
    font-weight: 700;
    pointer-events: none;
    z-index: 2;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}


/* =============================================================
   4. Mobile — two columns for all multi-image layouts
   ============================================================= */

@media (max-width: 580px) {
    .spig-grid:not(.spig-count-1) {
        grid-template-columns: 1fr 1fr !important;
        grid-template-rows: auto !important;
        height: auto !important;
    }
    .spig-grid:not(.spig-count-1) .spig-item {
        aspect-ratio: auto !important;
        height: 140px;
        grid-column: auto !important;
        grid-row: auto !important;
    }
    .spig-grid.spig-count-1 { max-width: 100%; }
    /* Restore full width on small screens for centered grids */
    .spig-grid.spig-count-3,
    .spig-grid.spig-count-5 {
        max-width: 100% !important;
    }
}


/* =============================================================
   5. Lightbox
   Only rendered when enableLightbox: true in SPIGConfig (default).
   ============================================================= */

#spig-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 999999;
    align-items: center;
    justify-content: center;
}

#spig-lightbox.spig-open {
    display: flex;
}

.spig-lb-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
}

.spig-lb-content {
    position: relative;
    z-index: 2;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.spig-lb-img {
    max-width: 90vw;
    max-height: 88vh;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
    display: block;
}

.spig-lb-close {
    position: absolute;
    top: 16px;
    right: 20px;
    z-index: 3;
    background: rgba(0, 0, 0, 0.5);
    border: none;
    color: #fff;
    font-size: 32px;
    line-height: 1;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.spig-lb-close:hover { background: rgba(255, 255, 255, 0.2); }

.spig-lb-prev,
.spig-lb-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 3;
    background: rgba(0, 0, 0, 0.45);
    border: none;
    color: #fff;
    font-size: 40px;
    line-height: 1;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    padding: 0;
}

.spig-lb-prev { left: 16px; }
.spig-lb-next { right: 16px; }

.spig-lb-prev:hover,
.spig-lb-next:hover { background: rgba(255, 255, 255, 0.2); }

.spig-lb-counter {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3;
    color: rgba(255, 255, 255, 0.7);
    font-size: 13px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: rgba(0, 0, 0, 0.4);
    padding: 4px 12px;
    border-radius: 100px;
}

body.spig-lb-open { overflow: hidden; }


/* =============================================================
   6. Create / Edit modal — image zone strip
   Fixed-height horizontal thumbnail strip injected between the
   Jodit editor and the hashtag picker / modal footer.
   ============================================================= */

.spig-modal-zone {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
    padding: 0 16px;
    overflow-x: auto;
    overflow-y: hidden;
    min-height: 0;
    max-height: 0;
    border-top: 0px solid #e8e8e8;
    border-bottom: 0px solid #e8e8e8;
    background: #fafafa;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #ccc transparent;
    /* Smooth height expansion — prevents layout jump */
    transition: min-height 0.2s ease, max-height 0.2s ease,
                padding 0.2s ease, border-width 0.2s ease;
}

.spig-modal-zone.spig-zone-active {
    min-height: 84px;
    max-height: 84px;
    padding: 8px 16px;
    border-top-width: 1px;
    border-bottom-width: 1px;
}

.spig-modal-zone::-webkit-scrollbar       { height: 4px; }
.spig-modal-zone::-webkit-scrollbar-track { background: transparent; }
.spig-modal-zone::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }

/* Individual thumbnail */
.spig-zone-thumb {
    flex: 0 0 auto;
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 6px;
    overflow: hidden;
    background: #1a1a1a;
    cursor: default;
}

.spig-zone-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
}

/* Remove (×) button on each thumbnail */
.spig-zone-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    z-index: 2;
    transition: background 0.15s;
}

.spig-zone-remove:hover { background: rgba(0, 0, 0, 0.9); }

/* Cap warning banner above the hashtag picker */
.spig-cap-warning {
    font-size: 12px;
    color: #b45309;
    background: #fef3c7;
    border: 1px solid #fcd34d;
    border-radius: 0;
    padding: 5px 16px;
    text-align: center;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}


/* =============================================================
   7. Jodit editor — image visibility and text jump prevention
   ============================================================= */

/* Hide all uploaded images inside the Jodit WYSIWYG editor.
   Images are invisible to the user during creation/editing but
   remain in the DOM so Jodit syncs them to the hidden textarea
   and SureDash saves them with the post content.
   The zone strip (section 6 above) provides the image management UI. *
#portal-post-creation-modal .jodit-wysiwyg img,
#portal-thread-edit-modal .jodit-wysiwyg img {
    display: none !important;
}/

/* When the zone strip is active, add bottom padding to the Jodit
   editor so that text content does not jump when the strip appears.
   .spig-has-zone is added to .portal-modal-body by JS. */
.spig-has-zone .jodit .jodit-workplace .jodit-wysiwyg,
.spig-has-zone .jodit .jodit-workplace .jodit-wysiwyg_iframe,
.spig-has-zone .jodit-container .jodit-workplace .jodit-wysiwyg,
.spig-has-zone .jodit-container .jodit-workplace .jodit-wysiwyg_iframe {
    padding-bottom: 90px !important;
}


/* =============================================================
   8. v7.0.0 — Isolated Image Manager (edit-mode POC)
   ============================================================= */

.spig-manage-images-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 8px 16px 0;
    padding: 6px 14px;
    font-size: 13px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    background: #fafafa;
    cursor: pointer;
    transition: background 0.15s;
}
.spig-manage-images-btn:hover { background: #f0f0f0; }

/* Read-only footer strip in the edit modal — same shape as the old
   spig-modal-zone, but thumbnails carry no remove button. */
.spig-zone-thumb-readonly { cursor: default; }
.spig-zone-thumb-readonly .spig-zone-remove { display: none; }

/* ── Popup overlay ───────────────────────────────────────────── */
.spig-image-manager {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000000; /* above SD's modal (portal-modal) and our own lightbox */
    align-items: center;
    justify-content: center;
}
.spig-image-manager.spig-im-open { display: flex; }

.spig-im-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
}

.spig-im-panel {
    position: relative;
    z-index: 1;
    width: min(720px, 92vw);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.spig-im-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid #eee;
}
.spig-im-header h3 { margin: 0; font-size: 16px; }
.spig-im-close {
    border: none; background: none; font-size: 24px; line-height: 1;
    cursor: pointer; color: #666; padding: 0 4px;
}
.spig-im-close:hover { color: #000; }

.spig-im-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.spig-im-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}
@media (max-width: 560px) {
    .spig-im-grid { grid-template-columns: repeat(3, 1fr); }
}

.spig-im-item {
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: 6px;
    overflow: hidden;
    background: #1a1a1a;
}
.spig-im-item img {
    width: 100%; height: 100%; object-fit: cover; display: block;
}

/* v7.2.17 — in-flight upload placeholder: dimmed local preview + spinner,
   one per file currently uploading. Same treatment Vault Viewer already
   proved, ported into SPIG's own existing grid/colors. */
.spig-im-item--uploading img {
    opacity: 0.55;
}

.spig-im-uploading-spinner {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 6px;
}

.spig-im-spinner {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.55);
    border-top-color: #fff;
    animation: spig-im-spin 0.8s linear infinite;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

@keyframes spig-im-spin {
    to { transform: rotate(360deg); }
}

/* v7.3.1 — inline rejection/failure messages, replacing alert(). Same
   amber warning language as .spig-cap-warning elsewhere in this file. */
.spig-im-errors {
    margin-top: 10px;
    padding: 8px 12px;
    background: #fef3c7;
    border: 1px solid #fcd34d;
    border-radius: 6px;
    font-size: 12px;
    color: #b45309;
}

.spig-im-errors div + div {
    margin-top: 4px;
}

.spig-im-badge {
    position: absolute;
    top: 6px; left: 6px;
    background: rgba(37, 99, 235, 0.9);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    letter-spacing: 0.02em;
}

.spig-im-delete {
    position: absolute;
    bottom: 6px; right: 6px;
    width: 28px; height: 28px;
    border-radius: 50%;
    border: none;
    background: rgba(220, 38, 38, 0.85);
    color: #fff;
    font-size: 13px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s;
}
.spig-im-delete:hover { background: rgba(220, 38, 38, 1); }

/* v7.6.0 — drag-to-reorder. Only committed/pending thumbnails are
   draggable (JS never sets draggable on an in-flight uploading tile or
   the add/dropzone tiles) — so a user can only start reordering once an
   image has actually finished uploading and landed in the grid. */
.spig-im-item[draggable="true"] { cursor: grab; }

.spig-im-item.spig-im-dragging {
    cursor: grabbing;
    opacity: 0.4;
}

/* Insertion-point indicator on the tile being hovered while dragging —
   same gold accent as the Save button, so it reads as "this is where it
   lands" rather than a warning state. */
.spig-im-item.spig-im-drop-before { box-shadow: inset 3px 0 0 0 #f4c542; }
.spig-im-item.spig-im-drop-after  { box-shadow: inset -3px 0 0 0 #f4c542; }

/* v7.5.3 — click-or-drag upload zone, replacing the old inline "+Add
   Images" button + plain empty-state text. Full-size tile when the
   working set is empty; a compact "add" tile (same icon, smaller) is
   appended after existing thumbnails once at least one image is
   present. Drag-and-drop listeners live on .spig-im-grid itself (see
   imagegrid.js bindManagerDropzone()), so dropping works anywhere over
   the grid — these rules only style the tile and the drag-active state. */
.spig-im-dropzone {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    text-align: center;
    padding: 40px 16px;
    border: 2px dashed #d0d0d0;
    border-radius: 8px;
    color: #888;
    font-size: 13px;
    line-height: 1.5;
    cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s;
}
.spig-im-dropzone:hover { border-color: #b8b8b8; background: #fafafa; }

.spig-im-dropzone-icon { color: #ffCC00; }
.spig-im-dropzone-icon svg { display: block; width: 40px; height: 40px; }

.spig-im-add-tile {
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed #d0d0d0;
    border-radius: 6px;
    cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s;
}
.spig-im-add-tile:hover { border-color: #b8b8b8; background: #fafafa; }
.spig-im-add-tile .spig-im-dropzone-icon svg { width: 24px; height: 24px; }

.spig-im-grid.spig-im-drag-active .spig-im-dropzone,
.spig-im-grid.spig-im-drag-active .spig-im-add-tile {
    border-color: #ffCC00;
    background: #fffbe6;
}

.spig-im-footer {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    border-top: 1px solid #eee;
    background: #fafafa;
}

.spig-im-count {
    font-size: 12px;
    color: #888;
}

/* v7.6.0 — persistent reorder hint, shown once 2+ images are present
   (JS toggles [hidden]). Same muted styling as the count it sits next
   to — a permanent, low-key answer to "can I drag these?" rather than
   a one-time tooltip someone can miss. */
.spig-im-reorder-hint {
    font-size: 12px;
    color: #888;
    margin-left: 6px;
}

.spig-im-actions {
    margin-left: auto;
    display: flex;
    gap: 8px;
}
.spig-im-actions button {
    padding: 8px 16px;
    font-size: 13px;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid transparent;
}
.spig-im-cancel {
    background: #fff;
    border-color: #d0d0d0;
    color: #333;
}
.spig-im-cancel:hover { background: #f5f5f5; }
.spig-im-save {
    background: #f4c542;
    color: #1a1a1a;
    font-weight: 600;
}
.spig-im-save:hover { background: #e6b830; }

body.spig-im-lock-scroll { overflow: hidden; }