/* ==========================================================================
   CarePDF - File Cards Styles (iLovePDF Style)
   Clean, Professional Grid Layout
   ========================================================================== */

/* ==========================================================================
   1. CSS Variables
   ========================================================================== */

:root {
    --card-size: 140px;
    --card-bg: #ffffff;
    --card-border: #e5e7eb;
    --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --card-shadow-hover: 0 8px 25px rgba(0, 0, 0, 0.15);
    --accent-color: #ef4444;
    --accent-light: #fef2f2;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --transition-fast: 0.2s ease;
    --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   2. File List - Clean Grid Container
   ========================================================================== */

.file-list {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    padding: 24px;
    justify-content: flex-start;
    align-items: flex-start;
    background: #f9fafb;
    border-radius: 12px;
    min-height: 180px;
}

.file-list.hidden {
    display: none;
}

.file-list.drag-active {
    background: var(--accent-light);
}

/* ==========================================================================
   3. File Card - iLovePDF Style
   ========================================================================== */

.file-card {
    position: relative;
    width: var(--card-size);
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: grab;
    transition: transform var(--transition-smooth);
}

.file-card:hover {
    transform: translateY(-4px);
}

.file-card:active {
    cursor: grabbing;
}

/* Entry animation */
.file-card.entering {
    animation: cardSlideIn 0.4s ease forwards;
}

@keyframes cardSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Remove animation */
.file-card.removing {
    animation: cardSlideOut 0.25s ease forwards;
}

@keyframes cardSlideOut {
    to {
        opacity: 0;
        transform: scale(0.8);
    }
}

/* ==========================================================================
   4. File Thumbnail - Document Preview
   ========================================================================== */

.file-thumbnail {
    position: relative;
    width: 100%;
    aspect-ratio: 3/4;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--card-shadow);
    transition: all var(--transition-smooth);
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-card:hover .file-thumbnail {
    box-shadow: var(--card-shadow-hover);
    border-color: #d1d5db;
}

.file-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--transition-smooth);
}

.file-card:hover .file-thumbnail img {
    transform: scale(1.02);
}

/* Document icon fallback */
.file-type-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    height: 100%;
    background: linear-gradient(180deg, #ffffff 0%, #f8f9fa 100%);
}

.file-type-icon svg {
    width: 40px;
    height: 40px;
    color: #9ca3af;
}

.file-ext {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    color: #ffffff;
    background: var(--accent-color);
    padding: 2px 8px;
    border-radius: 4px;
    letter-spacing: 0.5px;
}

/* Thumbnail loading state */
.thumbnail-loader {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.9);
    transition: opacity 0.3s ease;
}

.file-thumbnail.loaded .thumbnail-loader,
.file-thumbnail.failed .thumbnail-loader {
    opacity: 0;
    pointer-events: none;
}

.loader-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid #e5e7eb;
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==========================================================================
   5. File Number Badge
   ========================================================================== */

.file-number {
    position: absolute;
    top: -6px;
    left: -6px;
    width: 22px;
    height: 22px;
    background: var(--text-primary);
    color: #ffffff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease, background 0.2s ease;
}

.file-number.updating {
    animation: numberBounce 0.3s ease;
    background: var(--accent-color);
}

@keyframes numberBounce {
    50% { transform: scale(1.3); }
}

/* ==========================================================================
   6. File Actions - Delete Button
   ========================================================================== */

.file-actions {
    position: absolute;
    top: -8px;
    right: -8px;
    z-index: 15;
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.2s ease;
}

.file-card:hover .file-actions {
    opacity: 1;
    transform: scale(1);
}

.file-remove-btn {
    width: 26px;
    height: 26px;
    background: #ffffff;
    color: var(--accent-color);
    border: none;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.file-remove-btn svg {
    width: 12px;
    height: 12px;
}

.file-remove-btn:hover {
    background: var(--accent-color);
    color: #ffffff;
    transform: scale(1.1);
}

/* ==========================================================================
   7. Drag Handle
   ========================================================================== */

.file-drag-handle {
    display: none; /* Hidden by default, card itself is draggable */
}

/* ==========================================================================
   8. File Details - Name below card
   ========================================================================== */

.file-details {
    width: 100%;
    padding: 8px 4px 0;
    text-align: center;
}

.file-name {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.page-count {
    font-size: 10px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ==========================================================================
   9. Add More Card
   ========================================================================== */

.add-more-card {
    width: var(--card-size);
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: transform var(--transition-smooth);
}

.add-more-card:hover {
    transform: translateY(-4px);
}

.add-more-card .add-thumbnail,
.add-thumbnail {
    width: 100%;
    aspect-ratio: 3/4;
    border: 2px dashed #d1d5db;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: #ffffff;
    transition: all var(--transition-smooth);
}

.add-more-card:hover .add-thumbnail {
    border-color: var(--accent-color);
    background: var(--accent-light);
}

.add-icon {
    width: 40px;
    height: 40px;
    background: #f3f4f6;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    transition: all var(--transition-smooth);
}

.add-icon svg {
    width: 20px;
    height: 20px;
}

.add-more-card:hover .add-icon {
    background: var(--accent-color);
    color: #ffffff;
    transform: rotate(90deg);
}

.add-text {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    padding-top: 8px;
    transition: color var(--transition-fast);
}

.add-more-card:hover .add-text {
    color: var(--accent-color);
}

/* ==========================================================================
   10. Sortable Drag States
   ========================================================================== */

/* Ghost - placeholder where item will go */
.file-card.sortable-ghost {
    opacity: 0.4;
}

.file-card.sortable-ghost .file-thumbnail {
    border: 2px dashed var(--accent-color);
    background: var(--accent-light);
}

/* Chosen - the item being dragged */
.file-card.sortable-chosen {
    z-index: 100;
}

/* Drag - the original position */
.file-card.sortable-drag {
    opacity: 0;
}

/* Fallback for touch */
.file-card.sortable-fallback {
    opacity: 1 !important;
    z-index: 9999 !important;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.25) !important;
    transform: rotate(3deg) scale(1.05);
}

.file-card.sortable-fallback .file-thumbnail {
    border-color: var(--accent-color);
}

/* ==========================================================================
   11. Responsive Design
   ========================================================================== */

@media (max-width: 768px) {
    :root {
        --card-size: 110px;
    }

    .file-list {
        padding: 16px;
        gap: 16px;
        justify-content: center;
    }

    /* Always show actions on mobile */
    .file-actions {
        opacity: 1;
        transform: scale(1);
    }

    .file-remove-btn {
        width: 28px;
        height: 28px;
    }

    .file-name {
        font-size: 10px;
    }
}

@media (max-width: 480px) {
    :root {
        --card-size: 100px;
    }

    .file-list {
        padding: 12px;
        gap: 12px;
    }

    .file-number {
        width: 18px;
        height: 18px;
        font-size: 9px;
        top: -4px;
        left: -4px;
    }
}

/* ==========================================================================
   12. Dark Mode
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    :root {
        --card-bg: #1f2937;
        --card-border: #374151;
        --text-primary: #f3f4f6;
        --text-secondary: #9ca3af;
    }

    .file-list {
        background: #111827;
    }

    .file-thumbnail {
        background: var(--card-bg);
        border-color: var(--card-border);
    }

    .file-type-icon {
        background: linear-gradient(180deg, #1f2937 0%, #111827 100%);
    }

    .file-type-icon svg {
        color: #6b7280;
    }

    .add-thumbnail {
        background: #1f2937;
        border-color: #4b5563;
    }

    .add-icon {
        background: #374151;
        color: #6b7280;
    }

    .file-remove-btn {
        background: #374151;
        color: #f87171;
    }
}
