/* ============================================================
   gallery-popup2.css
   Scoped cho ImageGalleryPopup2 — dock right dưới topbar
   Prefix: igp2-  →  không đụng CSS cũ của ImageGalleryPopup
   Import trong App.razor / index.html sau canvas-ai.css
   ============================================================ */

/* ── Trigger button trên topbar ───────────────────────────────── */
.btn-gallery {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 7px;
    border: 1.5px solid var(--border, #e5e7eb);
    background: var(--bg-primary, #fff);
    color: var(--text-primary, #111827);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    position: relative;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
    white-space: nowrap;
}

    .btn-gallery:hover {
        border-color: #6366f1;
        background: #f5f3ff;
        box-shadow: 0 2px 8px rgba(99,102,241,.12);
    }

    .btn-gallery.has-new {
        border-color: #6366f1;
        background: #eef2ff;
    }

.btn-gallery-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    background: #6366f1;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    border-radius: 99px;
    line-height: 1;
}

    .btn-gallery-badge.dot {
        width: 7px;
        height: 7px;
        min-width: unset;
        padding: 0;
        border-radius: 50%;
        position: absolute;
        top: 4px;
        right: 4px;
        border: 1.5px solid var(--bg-primary, #fff);
    }

/* ── Overlay ──────────────────────────────────────────────────── */
.igp2-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    z-index: 600;
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    padding-top: 52px; /* chiều cao topbar */
    padding-right: 12px;
}

/* ── Panel ────────────────────────────────────────────────────── */
.igp2-panel {
    background: var(--bg-primary, #ffffff);
    border: 1px solid var(--border, #e5e7eb);
    /*border-radius: 12px;*/
    width: 520px;
    max-width: calc(100vw - 24px);
    max-height: calc(100vh - 64px);
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,.16), 0 2px 8px rgba(0,0,0,.08);
    overflow: hidden;
    animation: igp2DropIn 0.18s cubic-bezier(.4,0,.2,1);
}

@keyframes igp2DropIn {
    from {
        opacity: 0;
        transform: translateY(-8px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Fullscreen */
.igp2-panel.igp2-fullscreen {
    width: calc(100vw - 32px);
    max-width: calc(100vw - 32px);
    height: calc(100vh - 32px);
    max-height: calc(100vh - 32px);
    border-radius: 14px;
}

.igp2-overlay.igp2-fullscreen-mode {
    align-items: center;
    justify-content: center;
    padding: 16px;
}

/* ── Header ───────────────────────────────────────────────────── */
.igp2-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 12px;
    border-bottom: 1px solid var(--border, #e5e7eb);
    flex-shrink: 0;
}

.igp2-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #111827);
}

.igp2-count {
    font-size: 11px;
    background: var(--bg-secondary, #f3f4f6);
    color: var(--text-secondary, #6b7280);
    padding: 1px 7px;
    border-radius: 999px;
}

.igp2-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Layout switcher */
.igp2-layout-btns {
    display: flex;
    gap: 2px;
    background: var(--bg-secondary, #f3f4f6);
    padding: 3px;
    border-radius: 7px;
    margin-right: 4px;
}

.igp2-layout-btn {
    width: 26px;
    height: 26px;
    border: none;
    background: transparent;
    border-radius: 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary, #6b7280);
    transition: background 0.12s, color 0.12s;
}

    .igp2-layout-btn:hover {
        background: var(--bg-primary, #fff);
        color: var(--text-primary, #111);
    }

    .igp2-layout-btn.active {
        background: var(--bg-primary, #fff);
        color: #6366f1;
        box-shadow: 0 1px 3px rgba(0,0,0,.08);
    }

/* Icon buttons */
.igp2-icon-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary, #6b7280);
    transition: background 0.12s, color 0.12s;
}

    .igp2-icon-btn:hover {
        background: var(--bg-hover, #f3f4f6);
        color: var(--text-primary, #111);
    }

.igp2-close-btn {
    font-size: 18px;
    line-height: 1;
    padding-bottom: 1px;
}

    .igp2-close-btn:hover {
        background: #fee2e2;
        color: #dc2626;
    }

/* ── Filter bar ───────────────────────────────────────────────── */
.igp2-filter-bar {
    display: flex;
    gap: 6px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border, #e5e7eb);
    flex-shrink: 0;
}

.igp2-filter-select {
    padding: 6px 8px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 6px;
    font-size: 12px;
    background: var(--bg-primary, #fff);
    color: var(--text-primary, #111827);
    cursor: pointer;
}

.igp2-search {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 6px;
    font-size: 12px;
    background: var(--bg-primary, #fff);
    color: var(--text-primary, #111827);
}

    .igp2-search:focus {
        outline: none;
        border-color: #6366f1;
    }

.igp2-filter-select:focus {
    outline: none;
    border-color: #6366f1;
}

/* ── Admin cost bar ───────────────────────────────────────────── */
.igp2-cost-bar {
    display: flex;
    border-bottom: 1px solid var(--border, #e5e7eb);
    flex-shrink: 0;
}

.igp2-cost-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 4px;
    border-right: 1px solid var(--border, #e5e7eb);
    font-size: 11px;
    gap: 2px;
}

    .igp2-cost-item:last-child {
        border-right: none;
    }

    .igp2-cost-item span:first-child {
        color: var(--text-secondary, #6b7280);
        font-size: 10px;
        text-transform: uppercase;
        letter-spacing: .04em;
    }

    .igp2-cost-item span:last-child {
        font-weight: 700;
        color: #6366f1;
    }

/* ── Content / grid ───────────────────────────────────────────── */
.igp2-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: grid;
    gap: 8px;
    min-height: 180px;
    align-content: start;
}

    /* Layout variants */
    .igp2-content.igp2-layout-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .igp2-content.igp2-layout-grid3 {
        grid-template-columns: repeat(3, 1fr);
    }

    .igp2-content.igp2-layout-list {
        grid-template-columns: 1fr;
    }

    .igp2-content.igp2-layout-large {
        grid-template-columns: repeat(2, 1fr);
    }

/* ── Card ─────────────────────────────────────────────────────── */
.igp2-card {
    border: 1.5px solid var(--border, #e5e7eb);
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    position: relative;
    display: flex;
    flex-direction: column;
}

    .igp2-card:hover {
        border-color: #a5b4fc;
        box-shadow: 0 2px 8px rgba(99,102,241,.15);
    }

    /* Status border tint */
    .igp2-card.status-completed {
    }

    .igp2-card.status-pending {
        border-color: #fde68a;
    }

    .igp2-card.status-processing {
        border-color: #bfdbfe;
    }

    .igp2-card.status-rejected,
    .igp2-card.status-failed {
        border-color: #fca5a5;
    }

    /* Skeleton */
    .igp2-card.skeleton {
        background: var(--bg-secondary, #f3f4f6);
        min-height: 100px;
        animation: igp2Pulse 1.2s infinite;
    }

@keyframes igp2Pulse {
    0%,100% {
        opacity: 1;
    }

    50% {
        opacity: .5;
    }
}

/* Status badge */
.igp2-card-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 5px;
    border-radius: 4px;
    z-index: 1;
    line-height: 1.4;
}

    .igp2-card-badge.completed {
        background: #dcfce7;
        color: #15803d;
    }

    .igp2-card-badge.processing {
        background: #e0e7ff;
        color: #3730a3;
    }

    .igp2-card-badge.pending {
        background: #fef9c3;
        color: #854d0e;
    }

    .igp2-card-badge.rejected,
    .igp2-card-badge.failed {
        background: #fee2e2;
        color: #dc2626;
    }

/* Image */
.igp2-card-img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
    background: var(--bg-secondary, #f9fafb);
}

    .igp2-card-img.placeholder {
        display: flex;
        align-items: center;
        justify-content: center;
        background: var(--bg-secondary, #f3f4f6);
    }

/* Pending canvas overlay */
.igp2-pending-canvas {
    object-fit: cover;
}

.igp2-pending-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.35);
    display: flex;
    align-items: center;
    justify-content: center;
}

.igp2-pending-label {
    font-size: 10px;
    font-weight: 600;
    color: #fff;
    background: rgba(0,0,0,.45);
    padding: 3px 7px;
    border-radius: 5px;
}

/* List layout: image + text side by side */
.igp2-layout-list .igp2-card {
    flex-direction: row;
    align-items: center;
}

.igp2-layout-list .igp2-card-img {
    width: 56px;
    aspect-ratio: 1;
    flex-shrink: 0;
}

/* Card body */
.igp2-card-body {
    padding: 6px 8px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    flex: 1;
}

.igp2-card-prompt {
    font-size: 11px;
    color: var(--text-primary, #111827);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.3;
}

.igp2-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 10px;
    color: var(--text-secondary, #6b7280);
}

/* ── Empty state ──────────────────────────────────────────────── */
.igp2-empty {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 40px 16px;
    color: var(--text-secondary, #6b7280);
    font-size: 13px;
    font-weight: 500;
}

.igp2-empty-sub {
    font-size: 11px;
    font-weight: 400;
}

/* ── Badge helpers (admin cost) ───────────────────────────────── */
.igp2-badge {
    font-size: 11px;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 99px;
}

    .igp2-badge.amber {
        background: #fef3c7;
        color: #92400e;
    }

    .igp2-badge.green {
        background: #dcfce7;
        color: #15803d;
    }

/* ── Mobile ≤ 768px ───────────────────────────────────────────── */
@media (max-width: 768px) {
    .igp2-overlay {
        align-items: flex-end;
        justify-content: stretch;
        padding-top: 0;
        padding-right: 0;
    }

    .igp2-panel {
        width: 100%;
        max-width: 100%;
        max-height: 88vh;
        /*border-radius: 16px 16px 0 0;*/
        animation: igp2SlideUp 0.22s cubic-bezier(.4,0,.2,1);
    }

    @keyframes igp2SlideUp {
        from {
            opacity: 0;
            transform: translateY(20px);
        }

        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    /* Ẩn label "Gallery", chỉ giữ icon */
    .btn-gallery .btn-gallery-label {
        display: none;
    }

    .btn-gallery {
        padding: 6px 9px;
    }

    /* Grid nhỏ hơn trên mobile */
    .igp2-content.igp2-layout-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .igp2-content.igp2-layout-grid3 {
        grid-template-columns: repeat(2, 1fr);
    }

    .igp2-content.igp2-layout-large {
        grid-template-columns: 1fr;
    }
}

/* ── Dark theme ───────────────────────────────────────────────── */
[data-theme="dark"] .igp2-panel,
.dark-theme .igp2-panel {
    background: var(--bg-primary, #1e293b);
    border-color: var(--border, #334155);
}

[data-theme="dark"] .igp2-layout-btn.active,
.dark-theme .igp2-layout-btn.active {
    background: var(--bg-secondary, #334155);
}

[data-theme="dark"] .igp2-card,
.dark-theme .igp2-card {
    border-color: var(--border, #334155);
}

    [data-theme="dark"] .igp2-card.skeleton,
    .dark-theme .igp2-card.skeleton {
        background: var(--bg-secondary, #334155);
    }
