/* Enhanced Image Gallery Extension Styles with 3D Card Flip */
/* Complete window flip - like a real card */
/* Z-INDEX HIERARCHY: Background(0) -> Gallery(1) -> Chat(10+) -> Menus(9997+) -> Modals(10000+) */

/* Gallery Picker Modal - High z-index for modals */
.gallery-picker-overlay {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 10000 !important; /* Above atmosphere corner when modal is open */
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.gallery-picker-overlay.active {
    display: flex;
}

.gallery-picker {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 24px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.9);
}

.gallery-picker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.gallery-picker-header h2 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
}

.gallery-picker-close {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 24px;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-picker-close:hover {
    background: var(--danger);
    border-color: var(--danger);
}

.gallery-upload-section {
    margin-bottom: 20px;
    padding: 20px;
    background: var(--bg-tertiary);
    border: 2px dashed var(--border);
    border-radius: 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.gallery-upload-section:hover {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.gallery-upload-section input {
    display: none;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    margin-top: 20px;
}

.gallery-item {
    position: relative;
    width: 100%;
    padding-top: 100%;
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg-tertiary);
}

.gallery-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.gallery-item img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-item-delete {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(239, 68, 68, 0.9);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.2s;
    font-size: 16px;
    z-index: 1;
}

.gallery-item:hover .gallery-item-delete {
    opacity: 1;
}

/* Drag & Drop States */
.gallery-item.holding {
    transform: scale(1.05);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
    z-index: 10;
    animation: holdPulse 0.8s ease-in-out infinite;
}

@keyframes holdPulse {
    0%, 100% { box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5); }
    50% { box-shadow: 0 12px 32px rgba(var(--accent-rgb, 124, 58, 237), 0.4), 0 0 0 3px rgba(var(--accent-rgb, 124, 58, 237), 0.3); }
}

.gallery-item.dragging {
    transform: scale(1.05);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5), 0 0 0 2px var(--accent);
    z-index: 10;
}

.gallery-grid.dragging-active .gallery-item {
    transition: transform 0.2s ease;
}

.gallery-item-delete:hover {
    background: rgba(220, 38, 38, 1);
    transform: scale(1.1);
}

/* Taskbar for Minimized Windows - Subtle, transparent, behind menus */
.gallery-taskbar {
    position: fixed !important;
    bottom: 80px;
    left: 0;
    right: 0;
    height: 60px;
    background: color-mix(in srgb, var(--bg-secondary) 15%, transparent);
    border-top: 1px solid color-mix(in srgb, var(--border) 20%, transparent);
    border-bottom: 1px solid color-mix(in srgb, var(--border) 20%, transparent);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    z-index: 999 !important; /* Behind sidebar, atmosphere corner, and all menus */
    overflow-x: auto;
    overflow-y: hidden;
    backdrop-filter: blur(8px);
    opacity: 0.25;
    transition: opacity 0.3s ease;
    pointer-events: none !important; /* No interaction when transparent */
}

.gallery-taskbar:hover {
    opacity: 0.85;
    pointer-events: all !important; /* Can interact when hovering */
}

.gallery-taskbar:empty {
    display: none;
}

.gallery-taskbar-tab {
    min-width: 180px;
    max-width: 220px;
    height: 44px;
    background: color-mix(in srgb, var(--bg-tertiary) 40%, transparent);
    border: 1px solid color-mix(in srgb, var(--border) 30%, transparent);
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    backdrop-filter: blur(4px);
    pointer-events: all !important; /* Tabs are always clickable */
}

.gallery-taskbar-tab:hover {
    background: color-mix(in srgb, var(--accent) 50%, transparent);
    border-color: color-mix(in srgb, var(--accent) 40%, transparent);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 20%, transparent);
}

.taskbar-tab-thumb {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background-size: cover;
    background-position: center;
    background-color: var(--bg-primary);
    flex-shrink: 0;
    border: 1px solid color-mix(in srgb, var(--border) 30%, transparent);
    opacity: 0.8;
}

.taskbar-tab-title {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    opacity: 0.9;
}

/* Scrollbar for taskbar */
.gallery-taskbar::-webkit-scrollbar {
    height: 6px;
}

.gallery-taskbar::-webkit-scrollbar-track {
    background: transparent;
}

.gallery-taskbar::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--border) 30%, transparent);
    border-radius: 3px;
}

.gallery-taskbar::-webkit-scrollbar-thumb:hover {
    background: color-mix(in srgb, var(--accent) 40%, transparent);
}

/* Image Viewer - Complete Card Flip - Behind all menus and sidebars */
.image-viewer-wrapper {
    position: fixed !important;
    z-index: 999 !important; /* Behind everything except background - sidebar is typically 10+, atmosphere is 9997+ */
    perspective: 2000px;
    min-width: 150px;
    min-height: 120px;
}

.image-viewer-card {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
}

.image-viewer-card.flipped {
    transform: rotateY(180deg);
}

.image-viewer-front,
.image-viewer-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    background: rgba(0, 0, 0, 0.95);
    border: 2px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.image-viewer-front {
    z-index: 2;
    transform: rotateY(0deg);
}

.image-viewer-back {
    transform: rotateY(180deg);
    background: var(--bg-secondary);
}

/* Header - Simplified for Front */
.image-viewer-header {
    padding: 12px 16px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    cursor: move;
    user-select: none;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
}

.image-viewer-front .image-viewer-header {
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.7) 70%, rgba(0, 0, 0, 0) 100%);
}

.image-viewer-front:hover .image-viewer-header,
.image-viewer-header:hover {
    opacity: 1;
    pointer-events: all;
}

.image-viewer-back .image-viewer-header {
    background: linear-gradient(180deg, var(--bg-tertiary) 0%, var(--bg-secondary) 100%);
    position: relative;
    opacity: 1;
    pointer-events: all;
    justify-content: space-between;
}

.image-viewer-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-viewer-controls {
    display: flex;
    gap: 6px;
    align-items: center;
}

.iv-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 14px;
    min-width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
}

.iv-btn:hover {
    transform: scale(1.1);
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 30%, transparent);
}

.iv-btn-close {
    background: var(--danger);
    border-color: var(--danger);
}

.iv-btn-close:hover {
    background: color-mix(in srgb, var(--danger) 80%, black);
}

/* Front: Image Content */
.image-viewer-content {
    width: 100%;
    height: 100%;
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-viewer-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    user-select: none;
    cursor: grab;
    transition: transform 0.1s ease;
}

.image-viewer-img:active {
    cursor: grabbing;
}

.image-viewer-zoom {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    padding: 6px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    color: var(--accent);
    font-size: 12px;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.image-viewer-zoom.visible {
    opacity: 1;
}

/* Context Menu */
.image-context-menu {
    position: absolute;
    background: var(--bg-tertiary);
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 8px;
    min-width: 180px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.7);
    z-index: 1000;
}

.context-menu-item {
    padding: 10px 14px;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.context-menu-item:hover {
    background: var(--accent);
    transform: translateX(4px);
}

/* Back: Free Card Editor */
.card-editor-container {
    flex: 1;
    padding: 20px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.card-editor {
    width: 100%;
    height: 100%;
    padding: 20px;
    background: var(--bg-primary);
    border: 2px solid var(--border);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 15px;
    font-family: 'Courier New', monospace;
    line-height: 1.6;
    resize: none;
    outline: none;
    transition: all 0.3s;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3);
}

.card-editor:focus {
    border-color: var(--accent);
    box-shadow: 
        inset 0 2px 8px rgba(0, 0, 0, 0.3),
        0 0 0 3px color-mix(in srgb, var(--accent) 10%, transparent);
}

.card-editor::placeholder {
    color: var(--text-secondary);
    font-style: italic;
}

/* Resize Handles */
.resize-handle {
    position: absolute;
    z-index: 10;
    background: transparent;
}

.resize-n, .resize-s {
    height: 8px;
    left: 0;
    right: 0;
    cursor: ns-resize;
}

.resize-e, .resize-w {
    width: 8px;
    top: 0;
    bottom: 0;
    cursor: ew-resize;
}

.resize-n { top: -4px; }
.resize-s { bottom: -4px; }
.resize-e { right: -4px; }
.resize-w { left: -4px; }

.resize-ne, .resize-nw, .resize-se, .resize-sw {
    width: 16px;
    height: 16px;
}

.resize-ne { top: -4px; right: -4px; cursor: nesw-resize; }
.resize-nw { top: -4px; left: -4px; cursor: nwse-resize; }
.resize-se { bottom: -4px; right: -4px; cursor: nwse-resize; }
.resize-sw { bottom: -4px; left: -4px; cursor: nesw-resize; }

/* Animation for card appearance */
@keyframes cardSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.image-viewer-wrapper {
    animation: cardSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Save button special styling */
.iv-btn[data-action="save"] {
    position: relative;
}

.iv-btn[data-action="save"]:hover {
    background: var(--success);
    border-color: var(--success);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .image-viewer-wrapper {
        width: 90% !important;
        height: 70% !important;
        left: 5% !important;
        top: 15% !important;
    }
    
    .card-editor {
        font-size: 14px;
        padding: 15px;
    }
    
    .context-menu-item {
        font-size: 13px;
        padding: 8px 12px;
    }
    
    .gallery-taskbar {
        bottom: 70px;
        height: 56px;
        opacity: 0.2;
    }
    
    .gallery-taskbar:hover {
        opacity: 0.8;
    }
    
    .gallery-taskbar-tab {
        min-width: 140px;
        max-width: 160px;
        height: 40px;
    }
    
    .taskbar-tab-title {
        font-size: 12px;
    }
    
    .taskbar-tab-thumb {
        width: 28px;
        height: 28px;
    }
}

/* ==========================================================================
   RESPONSIVE BREAKPOINTS - IMAGE GALLERY VIEWER
   ========================================================================== */

/* Large screens (1600px and below) */
@media (max-width: 1600px) {
    .image-viewer-wrapper {
        max-width: 70vw !important;
        max-height: 75vh !important;
    }
    
    .gallery-picker {
        max-width: 700px;
    }
}

/* Medium-large screens (1400px and below) */
@media (max-width: 1400px) {
    .image-viewer-wrapper {
        max-width: 65vw !important;
        max-height: 70vh !important;
    }
    
    .gallery-picker {
        max-width: 600px;
    }
    
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 10px;
    }
    
    .iv-btn {
        min-width: 28px;
        height: 28px;
        font-size: 12px;
    }
}

/* Medium screens (1200px and below) */
@media (max-width: 1200px) {
    .image-viewer-wrapper {
        max-width: 60vw !important;
        max-height: 65vh !important;
    }
    
    .gallery-picker {
        max-width: 500px;
        padding: 20px;
    }
    
    .gallery-picker-header h2 {
        font-size: 18px;
    }
    
    .gallery-picker-close {
        width: 36px;
        height: 36px;
        font-size: 20px;
    }
    
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 8px;
    }
    
    .gallery-upload-section {
        padding: 16px;
        margin-bottom: 16px;
    }
    
    .image-viewer-title {
        font-size: 12px;
        max-width: 200px;
    }
    
    .iv-btn {
        min-width: 26px;
        height: 26px;
        font-size: 11px;
        border-radius: 6px;
    }
    
    .image-viewer-header {
        padding: 10px 12px;
    }
    
    .card-editor-container {
        padding: 14px;
    }
    
    .card-editor {
        font-size: 13px;
        padding: 14px;
    }
}

/* Small-medium screens (1024px and below) */
@media (max-width: 1024px) {
    .image-viewer-wrapper {
        max-width: 55vw !important;
        max-height: 60vh !important;
    }
    
    .gallery-picker {
        max-width: 450px;
        padding: 16px;
        max-height: 75vh;
    }
    
    .gallery-picker-header {
        margin-bottom: 16px;
    }
    
    .gallery-picker-header h2 {
        font-size: 16px;
    }
    
    .gallery-picker-close {
        width: 32px;
        height: 32px;
        font-size: 18px;
    }
    
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
        gap: 6px;
    }
    
    .gallery-item-delete {
        width: 24px;
        height: 24px;
        font-size: 14px;
        top: 4px;
        right: 4px;
    }
    
    .gallery-upload-section {
        padding: 12px;
        margin-bottom: 12px;
        font-size: 13px;
    }
    
    .image-viewer-title {
        font-size: 11px;
        max-width: 150px;
    }
    
    .iv-btn {
        min-width: 24px;
        height: 24px;
        font-size: 10px;
        border-radius: 5px;
        gap: 4px;
    }
    
    .image-viewer-controls {
        gap: 4px;
    }
    
    .image-viewer-header {
        padding: 8px 10px;
    }
    
    .image-viewer-zoom {
        font-size: 10px;
        padding: 4px 8px;
    }
    
    .card-editor-container {
        padding: 12px;
    }
    
    .card-editor {
        font-size: 12px;
        padding: 12px;
        border-radius: 8px;
    }
    
    /* Taskbar adjustments */
    .gallery-taskbar {
        height: 50px;
        bottom: 75px;
    }
    
    .gallery-taskbar-tab {
        min-width: 120px;
        max-width: 150px;
        height: 38px;
        padding: 4px 10px;
    }
    
    .taskbar-tab-thumb {
        width: 26px;
        height: 26px;
    }
    
    .taskbar-tab-title {
        font-size: 11px;
    }
    
    /* Context menu */
    .image-context-menu {
        min-width: 150px;
        padding: 6px;
        border-radius: 8px;
    }
    
    .context-menu-item {
        font-size: 12px;
        padding: 8px 10px;
        gap: 6px;
    }
}
