/**
 * Zippy Edit - Asset Library (Inventory) Styles
 * RPG-style inventory with video game aesthetics
 */

/* ========== Inventory Panel ========== */
#inventory-panel {
    position: fixed;
    top: 80px; /* Below header */
    bottom: 140px; /* Above chatbot (50px) + bubble height (70px) + margin (20px) */
    right: -360px;
    width: 360px;
    height: auto;
    min-height: 200px;
    background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
    border-left: 3px solid #4a5568;
    border-top: 3px solid #4a5568;
    border-bottom: 3px solid #4a5568;
    border-radius: 0 0 0 12px;
    box-shadow: -5px 0 30px rgba(0, 0, 0, 0.5);
    z-index: 9999;
    transition: right 0.3s ease;
    display: flex;
    flex-direction: column;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

#inventory-panel.open {
    right: 0;
}

/* ========== Header ========== */
.inventory-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 15px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 2px solid #4a5568;
    position: relative;
    overflow: visible;
    flex-shrink: 0;
}

.inventory-header h3 {
    color: white;
    font-size: 18px;
    font-weight: 700;
    margin: 0;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    flex: 1;
}

/* Settings Button */
.inventory-settings-btn {
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.5);
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.2s;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.inventory-settings-btn:hover {
    background: rgba(0, 0, 0, 0.5);
    border-color: white;
    transform: rotate(45deg);
}

.inventory-settings-btn.active {
    background: rgba(0, 0, 0, 0.5);
    border-color: white;
}

/* Settings Dropdown */
.inventory-settings-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 5px;
    background: #1a202c;
    border: 1px solid #4a5568;
    border-radius: 8px;
    padding: 12px;
    min-width: 200px;
    max-width: 280px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    z-index: 10001;
    display: none !important;
    visibility: hidden;
    box-sizing: border-box;
}

.inventory-settings-dropdown.open {
    display: block !important;
    visibility: visible;
}

.inventory-settings-dropdown .inventory-setting {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    color: #cbd5e0;
    font-size: 13px;
    border-bottom: 1px solid #2d3748;
}

.inventory-settings-dropdown .inventory-setting:last-child {
    border-bottom: none;
}

.inventory-settings-dropdown .inventory-setting input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #667eea;
}

/* ========== Body ========== */
.inventory-body {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

/* ========== Grid ========== */
#inventory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 15px;
}

/* ========== Slots ========== */
.inventory-slot {
    aspect-ratio: 1;
    position: relative;
    cursor: pointer;
    transition: all 0.2s;
}

.inventory-slot .slot-content {
    width: 100%;
    height: 100%;
    background: linear-gradient(145deg, #2d3748 0%, #1a202c 100%);
    border: 2px solid #4a5568;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transition: all 0.2s;
}

.inventory-slot.empty .slot-content {
    background: linear-gradient(145deg, #1a202c 0%, #0d1117 100%);
    border-style: dashed;
    opacity: 0.5;
}

.inventory-slot.filled:hover .slot-content {
    border-color: #667eea;
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.5),
                inset 0 0 20px rgba(102, 126, 234, 0.1);
    transform: scale(1.05);
}

.inventory-slot.filled:active .slot-content {
    transform: scale(0.95);
}

.inventory-slot.dragging {
    opacity: 0.5;
}

.inventory-slot.selected .slot-content {
    border-color: #fbbf24 !important;
    box-shadow: 0 0 15px rgba(251, 191, 36, 0.6),
                inset 0 0 20px rgba(251, 191, 36, 0.2);
}

.inventory-slot img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.inventory-slot .slot-icon {
    font-size: 32px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

.inventory-slot .slot-label {
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.8);
    color: #a0aec0;
    font-size: 9px;
    text-align: center;
    padding: 2px;
    border-radius: 0 0 6px 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Category-specific glow effects */
.inventory-slot[data-category="image"]:hover .slot-content {
    box-shadow: 0 0 15px rgba(34, 197, 94, 0.5);
}

.inventory-slot[data-category="video"]:hover .slot-content {
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.5);
}

.inventory-slot[data-category="audio"]:hover .slot-content {
    box-shadow: 0 0 15px rgba(168, 85, 247, 0.5);
}

.inventory-slot[data-category="model"]:hover .slot-content {
    box-shadow: 0 0 15px rgba(249, 115, 22, 0.5);
}

/* ========== Drop Zone ========== */
#inventory-dropzone {
    border: 2px dashed #4a5568;
    border-radius: 10px;
    padding: 20px;
    text-align: center;
    color: #a0aec0;
    cursor: pointer;
    transition: all 0.3s;
    margin-bottom: 15px;
    background: rgba(26, 32, 44, 0.5);
}

#inventory-dropzone:hover,
#inventory-dropzone.dragover {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.1);
    color: #667eea;
}

#inventory-dropzone .drop-icon {
    font-size: 32px;
    margin-bottom: 8px;
}

#inventory-dropzone p {
    margin: 0;
    font-size: 13px;
}

/* ========== Actions ========== */
.inventory-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.inventory-btn {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.inventory-btn.primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.inventory-btn.secondary {
    background: #4a5568;
    color: white;
}

.inventory-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* ========== Storage Indicator ========== */
.inventory-storage {
    margin-bottom: 15px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    border: 1px solid #4a5568;
}

.inventory-storage-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.inventory-storage-label {
    font-size: 12px;
    color: #a0aec0;
    font-weight: 500;
}

.inventory-storage-text {
    font-size: 12px;
    color: #718096;
}

.inventory-storage-bar {
    height: 8px;
    background: #1a202c;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.inventory-storage-fill {
    height: 100%;
    background: linear-gradient(90deg, #22c55e 0%, #22c55e 100%);
    border-radius: 4px;
    transition: width 0.3s ease, background 0.3s ease;
}

.inventory-storage-fill.warning {
    background: linear-gradient(90deg, #f59e0b 0%, #d97706 100%);
}

.inventory-storage-fill.danger {
    background: linear-gradient(90deg, #ef4444 0%, #dc2626 100%);
}

.inventory-storage-details {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 10px;
    color: #6b7280;
}

.inventory-storage-count {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ========== Privacy Disclaimer ========== */
.inventory-disclaimer {
    background: rgba(102, 126, 234, 0.1);
    border: 1px solid rgba(102, 126, 234, 0.3);
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 15px;
    font-size: 11px;
    color: #a0aec0;
    line-height: 1.4;
}

.inventory-disclaimer strong {
    color: #667eea;
}

/* ========== Toggle Button ========== */
#inventory-toggle {
    position: fixed;
    /* Center on panel: panel top=80px, bottom=140px, so center = (100vh - 80px - 140px) / 2 + 80px */
    top: calc(50vh - 30px);
    right: 0;
    transform: translateY(-50%);
    width: 30px;
    height: 60px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 60px 0 0 60px;
    color: white;
    cursor: pointer;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.3);
    transition: right 0.3s ease, background 0.2s;
}

#inventory-toggle:hover {
    background: linear-gradient(135deg, #5568d3 0%, #653a8b 100%);
}

/* Toggle moves with panel when open */
#inventory-toggle.open {
    right: 360px;
}

/* ========== Context Menu ========== */
.inventory-context-menu {
    position: fixed;
    background: #1a202c;
    border: 1px solid #4a5568;
    border-radius: 8px;
    padding: 6px 0;
    min-width: 160px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    z-index: 10001;
}

.inventory-context-menu .context-item {
    padding: 10px 16px;
    color: #e2e8f0;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.15s;
}

.inventory-context-menu .context-item:hover {
    background: #4a5568;
}

.inventory-context-menu .context-item.danger {
    color: #fc8181;
}

.inventory-context-menu .context-item.danger:hover {
    background: rgba(252, 129, 129, 0.2);
}

.inventory-context-menu .context-divider {
    height: 1px;
    background: #4a5568;
    margin: 6px 0;
}

/* ========== Tool Selector ========== */
.inventory-tool-selector {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #1a202c;
    border: 2px solid #667eea;
    border-radius: 12px;
    padding: 20px;
    min-width: 250px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
    z-index: 10002;
}

.inventory-tool-selector h4 {
    color: #e2e8f0;
    margin: 0 0 15px 0;
    font-size: 16px;
}

.inventory-tool-selector .tool-option {
    padding: 12px 16px;
    color: #cbd5e0;
    cursor: pointer;
    border-radius: 8px;
    margin-bottom: 6px;
    transition: all 0.2s;
}

.inventory-tool-selector .tool-option:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

/* ========== Modal ========== */
.inventory-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10003;
}

.inventory-modal-content {
    background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
    border: 2px solid #667eea;
    border-radius: 16px;
    padding: 30px;
    max-width: 400px;
    text-align: center;
}

.inventory-modal-content h3 {
    color: white;
    margin: 0 0 15px 0;
    font-size: 20px;
}

.inventory-modal-content p {
    color: #a0aec0;
    margin: 0 0 25px 0;
    line-height: 1.6;
}

.inventory-modal-buttons {
    display: flex;
    gap: 12px;
}

.inventory-modal-buttons button {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.inventory-modal-buttons .btn-session {
    background: #4a5568;
    color: white;
}

.inventory-modal-buttons .btn-persist {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.inventory-modal-buttons button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

/* ========== Notification ========== */
#inventory-notification {
    position: fixed;
    bottom: 20px;
    right: 340px;
    background: #22c55e;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s;
    z-index: 10000;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

#inventory-notification.show {
    opacity: 1;
    transform: translateY(0);
}

/* ========== Hidden File Input ========== */
#inventory-file-input {
    display: none;
}

/* ========== Scrollbar ========== */
.inventory-body::-webkit-scrollbar {
    width: 8px;
}

.inventory-body::-webkit-scrollbar-track {
    background: #1a202c;
}

.inventory-body::-webkit-scrollbar-thumb {
    background: #4a5568;
    border-radius: 4px;
}

.inventory-body::-webkit-scrollbar-thumb:hover {
    background: #667eea;
}

/* ========== Insert from Inventory Arrow Button ========== */
.inventory-insert-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border: 2px solid #4a5568;
    border-radius: 8px;
    color: #a0aec0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.2s;
    z-index: 10;
}

.inventory-insert-btn:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: #667eea;
    color: white;
    transform: scale(1.1);
}

.inventory-insert-btn:active {
    transform: scale(0.95);
}

.inventory-insert-btn::before {
    content: '←';
    font-weight: bold;
}

.inventory-insert-btn[title]::after {
    content: attr(title);
    position: absolute;
    bottom: -30px;
    right: 0;
    background: #1a202c;
    color: #e2e8f0;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.inventory-insert-btn:hover[title]::after {
    opacity: 1;
}

/* Drop zone wrapper for relative positioning */
.drop-zone-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
}

/* ========== Animations ========== */

/* Item added "pop-in" animation */
@keyframes itemPopIn {
    0% {
        transform: scale(0) rotate(-20deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.3) rotate(5deg);
    }
    70% {
        transform: scale(0.9) rotate(-2deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

@keyframes itemGlow {
    0%, 100% {
        box-shadow: 0 0 5px rgba(102, 126, 234, 0.5);
    }
    50% {
        box-shadow: 0 0 20px rgba(102, 126, 234, 0.9), 0 0 30px rgba(118, 75, 162, 0.6);
    }
}

.inventory-slot.just-added {
    animation: itemPopIn 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards,
               itemGlow 0.8s ease-in-out 0.3s;
}

.inventory-slot.just-added .slot-content {
    animation: itemGlow 1s ease-in-out;
}

/* Panel slide-in highlight */
@keyframes panelHighlight {
    0% {
        box-shadow: inset 0 0 0 3px rgba(102, 126, 234, 0);
    }
    30% {
        box-shadow: inset 0 0 0 3px rgba(102, 126, 234, 0.8);
    }
    100% {
        box-shadow: inset 0 0 0 3px rgba(102, 126, 234, 0);
    }
}

#inventory-panel.item-added {
    animation: panelHighlight 1s ease-out;
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
    #inventory-panel {
        width: 280px;
        right: -280px;
        bottom: 120px; /* Slightly less clearance on mobile */
    }

    #inventory-panel.open {
        right: 0;
    }

    #inventory-toggle {
        top: calc(50vh - 20px);
    }

    #inventory-toggle.open {
        right: 280px;
    }

    #inventory-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    #inventory-notification {
        right: 20px;
        bottom: 80px;
    }

    #inventory-notification.show {
        right: 20px;
    }
}

/* ========== Search & Filter ========== */
.inventory-search {
    padding: 10px 15px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

#inventory-search-input {
    width: 100%;
    padding: 8px 12px;
    background: #1a202c;
    border: 1px solid #4a5568;
    border-radius: 6px;
    color: white;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

#inventory-search-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

#inventory-search-input::placeholder {
    color: #718096;
}

.inventory-filter-btns {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

.filter-btn {
    flex: 1;
    padding: 6px 8px;
    background: #2d3748;
    border: 1px solid #4a5568;
    border-radius: 4px;
    color: #a0aec0;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.filter-btn:hover {
    background: #3d4a5c;
    color: white;
}

.filter-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: transparent;
    color: white;
}

.inventory-slot.filtered-out {
    display: none !important;
}
