/* Collage Maker Tool - Custom Styles với Smart Features */

/* Remove input validation borders */
.toolInput:invalid,
.toolInput:valid {
    border-color: #ced4da !important;
    box-shadow: none !important;
}

.toolInput:focus {
    border-color: #80bdff !important;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25) !important;
}

/* Image Preview Grid */
.image-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 1rem;
    padding: 0.5rem;
    min-height: 100px;
}

.image-preview-item {
    position: relative;
    border: 2px solid #dee2e6;
    border-radius: 0.5rem;
    overflow: hidden;
    cursor: move;
    transition: all 0.2s ease;
    aspect-ratio: 1;
    background: #f8f9fa;
    user-select: none;
}

.image-preview-item:hover {
    border-color: #052c65;
    box-shadow: 0 0.25rem 0.75rem rgba(5, 44, 101, 0.15);
    transform: translateY(-2px);
}

.image-preview-item.dragging {
    opacity: 0.4;
    transform: scale(0.98) rotate(2deg);
    border-color: #052c65;
    box-shadow: 0 0.5rem 1.5rem rgba(5, 44, 101, 0.3);
    cursor: grabbing;
    z-index: 1000;
}

/* NEW: Drag Handle - giống reorder-pdf-pages */
.image-preview-item .drag-handle {
    position: absolute;
    top: 0.25rem;
    left: 0.25rem;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background-color: rgba(5, 44, 101, 0.9);
    border: none;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    font-size: 0.875rem;
    line-height: 1;
    z-index: 3;
    transition: all 0.2s ease;
    opacity: 0.7;
}

.image-preview-item:hover .drag-handle {
    opacity: 1;
    background-color: rgba(5, 44, 101, 1);
    transform: scale(1.1);
}

.image-preview-item.dragging .drag-handle {
    cursor: grabbing;
}

.preview-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none; /* Prevent img drag interference */
    user-select: none;
}

.preview-remove-btn {
    position: absolute;
    top: 0.25rem;
    right: 0.25rem;
    background: rgba(220, 53, 69, 0.95);
    color: white;
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.25rem;
    line-height: 1;
    padding: 0;
    transition: all 0.2s ease;
    opacity: 0;
    z-index: 2;
}

.image-preview-item:hover .preview-remove-btn {
    opacity: 1;
}

.preview-remove-btn:hover {
    background: rgba(220, 53, 69, 1);
    transform: scale(1.1);
}

.preview-number {
    position: absolute;
    top: 0.25rem;
    right: 0.25rem;
    background: rgba(5, 44, 101, 0.9);
    color: white;
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    z-index: 2;
}

/* NEW: Orientation Badge - moved position */
.preview-orientation {
    position: absolute;
    bottom: 0.25rem;
    left: 0.25rem;
    background: rgba(13, 110, 253, 0.9);
    color: white;
    padding: 0.125rem 0.4rem;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1;
    z-index: 1;
    cursor: help;
}

/* Layout Selector */
.layout-selector {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.layout-option {
    position: relative;
}

.layout-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.layout-label {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 1rem;
    background: #ffffff;
    border: 2px solid #e5e7eb;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    margin: 0;
    height: 100%;
}

.layout-icon {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f3f4f6;
    border-radius: 0.5rem;
    transition: all 0.3s ease;
}

.layout-icon .fsvg {
    width: 24px;
    height: 24px;
    opacity: 0.7;
    transition: all 0.3s ease;
}

.layout-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.layout-title {
    font-size: 1rem;
    font-weight: 600;
    color: #1f2937;
    line-height: 1.3;
}

.layout-desc {
    font-size: 0.875rem;
    color: #6b7280;
    line-height: 1.4;
}

/* Hover State */
.layout-label:hover {
    border-color: #cbd5e1;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transform: translateY(-2px);
}

.layout-label:hover .layout-icon {
    background: #e8edf3;
}

.layout-label:hover .layout-icon .fsvg {
    opacity: 0.9;
}

/* Checked State */
.layout-input:checked + .layout-label {
    border-color: #052c65;
    background: #f8fafc;
    box-shadow: 0 4px 12px rgba(5, 44, 101, 0.12), inset 0 0 0 1px rgba(5, 44, 101, 0.1);
    transform: translateY(0);
}

.layout-input:checked + .layout-label .layout-icon {
    background: #052c65;
}

.layout-input:checked + .layout-label .layout-icon .fsvg {
    filter: brightness(0) invert(1);
    opacity: 1;
}

.layout-input:checked + .layout-label .layout-title {
    color: #052c65;
}

.layout-input:checked + .layout-label .layout-desc {
    color: #475569;
}

/* Color Picker Styling */
.input-group {
    display: flex;
    flex-wrap: nowrap;
}

.form-control-color {
    width: 60px;
    min-width: 60px;
    height: 38px;
    padding: 0.25rem;
    border: 1px solid #ced4da;
    border-right: none;
    border-radius: 0.375rem 0 0 0.375rem;
    cursor: pointer;
    transition: border-color 0.15s ease-in-out;
}

.form-control-color:hover {
    border-color: #86b7fe;
}

.form-control-color:focus {
    border-color: #86b7fe;
    box-shadow: none;
    outline: none;
}

.form-control-color::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.form-control-color::-webkit-color-swatch {
    border: none;
    border-radius: 3px;
}

.form-control-color::-moz-color-swatch {
    border: none;
    border-radius: 3px;
}

.input-group .form-control {
    border-radius: 0 0.375rem 0.375rem 0;
    font-family: 'Courier New', monospace;
    font-weight: 500;
    font-size: 0.875rem;
    text-transform: uppercase;
    flex: 1;
}

.input-group:focus-within .form-control-color {
    border-color: #86b7fe;
}

.input-group:focus-within .form-control {
    border-color: #86b7fe;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

/* Range Slider Styling */
.form-range {
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: #e5e7eb;
    border-radius: 3px;
    outline: none;
    transition: all 0.2s ease;
}

.form-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: #052c65;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(5, 44, 101, 0.3);
}

.form-range::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 8px rgba(5, 44, 101, 0.4);
}

.form-range::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: #052c65;
    border-radius: 50%;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(5, 44, 101, 0.3);
}

.form-range::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 8px rgba(5, 44, 101, 0.4);
}

/* Download Button */
#downloadLink {
    color: white !important;
    text-decoration: none !important;
}

#downloadLink:hover,
#downloadLink:focus,
#downloadLink:active {
    color: white !important;
    text-decoration: none !important;
}

/* Preview Container */
#collagePreview {
    max-width: 100%;
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.1);
}

/* Dark Mode Support */
[data-bs-theme="dark"] .image-preview-item {
    background: #2d3748;
    border-color: #4a5568;
}

[data-bs-theme="dark"] .image-preview-item:hover {
    border-color: #3b82f6;
}

[data-bs-theme="dark"] .image-preview-item.dragging {
    border-color: #3b82f6;
    box-shadow: 0 0.5rem 1.5rem rgba(59, 130, 246, 0.3);
}

[data-bs-theme="dark"] .image-preview-item .drag-handle {
    background-color: rgba(59, 130, 246, 0.9);
}

[data-bs-theme="dark"] .image-preview-item:hover .drag-handle {
    background-color: rgba(59, 130, 246, 1);
}

[data-bs-theme="dark"] .preview-number {
    background: rgba(59, 130, 246, 0.9);
}

[data-bs-theme="dark"] .layout-label {
    background: #2d3748;
    border-color: #4a5568;
}

[data-bs-theme="dark"] .layout-label:hover {
    background: #374151;
}

[data-bs-theme="dark"] .layout-input:checked + .layout-label {
    background: #1a202c;
    border-color: #052c65;
}

[data-bs-theme="dark"] .layout-title {
    color: #e2e8f0;
}

[data-bs-theme="dark"] .layout-desc {
    color: #a0aec0;
}

[data-bs-theme="dark"] .layout-input:checked + .layout-label .layout-title {
    color: #93c5fd;
}

[data-bs-theme="dark"] .layout-input:checked + .layout-label .layout-desc {
    color: #cbd5e0;
}

[data-bs-theme="dark"] .form-control-color {
    background-color: #2d3748;
    border-color: #4a5568;
}

[data-bs-theme="dark"] .input-group .form-control {
    background-color: #2d3748;
    border-color: #4a5568;
    color: #e2e8f0;
}

[data-bs-theme="dark"] #collagePreview {
    border-color: #4a5568;
}

[data-bs-theme="dark"] .card {
    background-color: #212529;
    border-color: #495057;
}

[data-bs-theme="dark"] .card-header {
    background-color: #1a1d20;
    border-bottom-color: #495057;
    color: #e9ecef;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .image-preview-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 0.75rem;
    }
    
    .image-preview-item .drag-handle {
        width: 22px;
        height: 22px;
        font-size: 0.75rem;
    }
    
    .preview-number {
        font-size: 0.7rem;
        padding: 0.1rem 0.4rem;
    }
    
    .preview-remove-btn {
        width: 24px;
        height: 24px;
        font-size: 1.1rem;
    }
    
    .layout-selector {
        grid-template-columns: 1fr;
    }
    
    .layout-label {
        padding: 0.875rem;
    }
    
    .layout-icon {
        width: 40px;
        height: 40px;
    }
    
    .layout-icon .fsvg {
        width: 20px;
        height: 20px;
    }
    
    .layout-title {
        font-size: 0.9375rem;
    }
    
    .layout-desc {
        font-size: 0.8125rem;
    }
}

@media (max-width: 576px) {
    .image-preview-grid {
        grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
        gap: 0.5rem;
    }
    
    .image-preview-item .drag-handle {
        width: 20px;
        height: 20px;
        font-size: 0.7rem;
        top: 0.15rem;
        left: 0.15rem;
    }
    
    .preview-number {
        font-size: 0.65rem;
        padding: 0.08rem 0.3rem;
        top: 0.15rem;
        right: 0.15rem;
    }
    
    .preview-remove-btn {
        width: 22px;
        height: 22px;
        font-size: 1rem;
        top: 0.15rem;
        right: 0.15rem;
    }
}

/* Animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.3s ease-out;
}

/* Spinner Animation */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}