/* ============================================
   ADMIN PRODUCT IMAGES CSS
   File: public/css/admin-product-images.css
   Version: 2.0 FINAL - Max 5 Images Per Product
   Used by: create.php & edit.php
   ============================================ */

/* Upload Section Container */
.image-upload-section {
    background: #f8f9fa;
    border: 2px dashed #dee2e6;
    border-radius: 8px;
    padding: 20px;
    margin-top: 10px;
    transition: border-color 0.3s ease;
}

.image-upload-section:hover {
    border-color: #667eea;
}

/* Upload Area */
.upload-area {
    text-align: center;
    padding: 20px;
    margin-bottom: 15px;
}

.btn-add-images {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.btn-add-images:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.btn-add-images:active {
    transform: translateY(0);
}

.btn-add-images:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-add-images i {
    margin-right: 8px;
}

.upload-hint {
    color: #6c757d;
    font-size: 13px;
    margin-top: 12px;
    margin-bottom: 0;
    line-height: 1.5;
}

.upload-hint i {
    color: #667eea;
    margin-right: 5px;
}

/* Sortable Grid - Container for images */
.sortable-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 15px;
    margin-top: 20px;
    padding: 15px;
    background: white;
    border-radius: 8px;
    min-height: 100px;
    transition: all 0.3s ease;
}

.no-images-text {
    grid-column: 1 / -1;
    text-align: center;
    color: #adb5bd;
    font-style: italic;
    padding: 40px 20px;
    font-size: 14px;
}

/* Image Preview Item */
.image-preview-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    background: #f8f9fa;
    border: 2px solid #dee2e6;
    cursor: move;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.image-preview-item:hover {
    border-color: #667eea;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
    transform: translateY(-2px);
}

.image-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
    display: block;
}

.image-preview-item:hover img {
    transform: scale(1.05);
}

/* Main Image Badge - Ảnh đầu tiên */
.image-preview-item.main-image::before {
    content: "ẢNH CHÍNH";
    position: absolute;
    top: 8px;
    left: 8px;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(245, 87, 108, 0.4);
    animation: pulseMain 2s ease-in-out infinite;
}

@keyframes pulseMain {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 2px 8px rgba(245, 87, 108, 0.4);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 4px 12px rgba(245, 87, 108, 0.6);
    }
}

/* Drag Handle */
.drag-handle {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.6);
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 5;
}

.image-preview-item:hover .drag-handle {
    opacity: 1;
}

.drag-handle i {
    font-size: 18px;
}

/* Remove Button */
.remove-image-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #dc3545;
    color: white;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(220, 53, 69, 0.3);
}

.remove-image-btn:hover {
    background: #c82333;
    transform: scale(1.1) rotate(90deg);
    box-shadow: 0 4px 12px rgba(220, 53, 69, 0.5);
}

.remove-image-btn:active {
    transform: scale(0.95);
}

.remove-image-btn i {
    font-size: 12px;
}

/* Image Number Badge */
.image-number {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    z-index: 5;
}

/* Image Counter */
.image-counter {
    text-align: center;
    margin-top: 15px;
    padding: 10px 15px;
    background: white;
    border-radius: 6px;
    font-size: 14px;
    color: #495057;
    border: 1px solid #dee2e6;
    transition: all 0.3s ease;
}

.image-counter strong {
    color: #667eea;
    font-size: 16px;
}

.image-counter i {
    margin-right: 5px;
}

.image-counter.full {
    background: #fff3cd;
    border-color: #ffc107;
    color: #856404;
}

.image-counter.full strong {
    color: #856404;
}

/* Sortable States (Drag & Drop) */
.sortable-ghost {
    opacity: 0.4;
    background: #667eea;
    border: 2px dashed #667eea;
}

.sortable-chosen {
    cursor: grabbing !important;
    transform: scale(1.05) rotate(2deg);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.5);
    z-index: 1000;
}

.sortable-drag {
    opacity: 0.8;
}

/* Loading State */
.image-preview-item.loading {
    pointer-events: none;
    opacity: 0.6;
}

.image-preview-item.loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30px;
    height: 30px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 20;
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Error State */
.image-preview-item.error {
    border-color: #dc3545;
    background: #f8d7da;
}

.image-preview-item.error::after {
    content: "✕";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 40px;
    color: #dc3545;
    font-weight: bold;
    z-index: 20;
}

/* Alerts */
.alert {
    padding: 12px 15px;
    margin-bottom: 15px;
    border-radius: 6px;
    font-size: 14px;
}

.alert-info {
    background: #d1ecf1;
    border: 1px solid #bee5eb;
    color: #0c5460;
}

.alert-warning {
    background: #fff3cd;
    border: 1px solid #ffeeba;
    color: #856404;
}

.alert-danger {
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
}

.alert i {
    margin-right: 8px;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .sortable-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 12px;
    }
}

@media (max-width: 768px) {
    .sortable-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 12px;
        padding: 12px;
    }
    
    .image-upload-section {
        padding: 15px;
    }
    
    .upload-area {
        padding: 15px;
    }
    
    .btn-add-images {
        padding: 10px 24px;
        font-size: 14px;
    }
    
    .image-preview-item.main-image::before {
        font-size: 9px;
        padding: 3px 8px;
    }
}

@media (max-width: 480px) {
    .sortable-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        padding: 10px;
    }
    
    .image-upload-section {
        padding: 12px;
        border-width: 1px;
    }
    
    .upload-area {
        padding: 12px;
    }
    
    .btn-add-images {
        padding: 10px 20px;
        font-size: 13px;
        width: 100%;
    }
    
    .upload-hint {
        font-size: 11px;
    }
    
    .image-preview-item.main-image::before {
        font-size: 8px;
        padding: 3px 6px;
        top: 4px;
        left: 4px;
    }
    
    .remove-image-btn {
        width: 24px;
        height: 24px;
        top: 4px;
        right: 4px;
    }
    
    .remove-image-btn i {
        font-size: 10px;
    }
    
    .image-number {
        width: 20px;
        height: 20px;
        font-size: 10px;
        bottom: 4px;
        right: 4px;
    }
    
    .drag-handle {
        width: 32px;
        height: 32px;
    }
    
    .drag-handle i {
        font-size: 14px;
    }
    
    .image-counter {
        font-size: 13px;
        padding: 8px 12px;
    }
}

/* Print Styles */
@media print {
    .btn-add-images,
    .remove-image-btn,
    .drag-handle,
    .upload-hint,
    .image-counter {
        display: none !important;
    }
    
    .image-preview-item {
        cursor: default;
        page-break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ddd;
    }
    
    .sortable-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Accessibility */
.image-preview-item:focus-visible {
    outline: 3px solid #667eea;
    outline-offset: 2px;
}

.btn-add-images:focus-visible {
    outline: 3px solid #667eea;
    outline-offset: 4px;
}

.remove-image-btn:focus-visible {
    outline: 3px solid #dc3545;
    outline-offset: 2px;
}

/* Screen reader only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Utilities */
.d-none {
    display: none !important;
}

.text-muted {
    color: #6c757d !important;
}

.text-danger {
    color: #dc3545 !important;
}

.text-success {
    color: #28a745 !important;
}

.mt-2 {
    margin-top: 0.5rem !important;
}

.mb-0 {
    margin-bottom: 0 !important;
}

/* Smooth Transitions */
* {
    -webkit-tap-highlight-color: transparent;
}

.image-preview-item,
.btn-add-images,
.remove-image-btn,
.sortable-grid {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* END OF STYLESHEET */