/* =========================================================
   ImagoPDF - File Uploader Component
   Uso: merge, image_to_pdf, compress, etc.
   ========================================================= */

/* ---------- Input oculto ---------- */

.file-input {
    display: none;
}

/* ---------- Área de upload ---------- */

.upload-area {
    text-align: center;
    padding: 32px 24px;
    border: 2px dashed rgba(107, 78, 255, 0.22);
    border-radius: 16px;
    background: var(--surface);
    transition: border-color 0.2s ease, background 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
    cursor: pointer;
    margin-bottom: 20px;
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
}

.upload-area:hover {
    border-color: rgba(107, 78, 255, 0.4);
    background: rgba(107, 78, 255, 0.04);
}

.upload-area.dragover {
    border-color: var(--accent2);
    background: rgba(107, 78, 255, 0.07);
    transform: translateY(-1px);
}

.upload-icon {
    font-size: 2.6rem;
    color: var(--accent2);
    display: block;
    margin-bottom: 12px;
    line-height: 1;
}

.upload-title {
    font-family: 'Syne', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 8px;
    line-height: 1.25;
}

.upload-hint {
    color: var(--muted);
    font-size: 0.92rem;
    line-height: 1.5;
    max-width: 560px;
    margin: 0 auto;
}

.upload-formats {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 18px;
}

.upload-format-tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 7px 12px;
    border-radius: 999px;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    box-sizing: border-box;
}

/* ---------- Resumo / status ---------- */

.status-info {
    display: none;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px 24px;
    margin-bottom: 16px;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.status-info.show {
    display: block;
}

.status-info-title {
    font-family: 'Syne', sans-serif;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 14px;
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.status-item {
    text-align: center;
    padding: 12px 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    transition: border-color 0.2s ease;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
}

.status-number {
    font-family: 'Syne', sans-serif;
    font-size: clamp(1.1rem, 6vw, 1.5rem);
    font-weight: 800;
    color: var(--accent);
    display: block;
    letter-spacing: -0.02em;
    line-height: 1.05;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.status-label {
    display: block;
    font-size: 0.7rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    line-height: 1.25;
}

.status-warning {
    grid-column: 1 / -1;
    text-align: center;
    color: #fcd34d;
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.2);
    padding: 10px;
    margin-top: 12px;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 600;
    box-sizing: border-box;
}

/* ---------- Dica de arrastar ---------- */

.drag-instruction {
    display: none;
    font-size: 0.8rem;
    color: var(--muted);
    padding: 10px 14px;
    background: rgba(107, 78, 255, 0.06);
    border: 1px solid rgba(107, 78, 255, 0.15);
    border-radius: 8px;
    margin-bottom: 16px;
    box-sizing: border-box;
}

.drag-instruction.show {
    display: block;
}

/* ---------- Painel de erros ---------- */

.file-errors-panel {
    display: none;
    margin-bottom: 16px;
    padding: 14px 16px;
    border-radius: 10px;
    border: 1px solid rgba(239, 68, 68, 0.25);
    background: rgba(239, 68, 68, 0.08);
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.file-errors-panel.show {
    display: block;
}

.file-errors-title {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #fca5a5;
    font-weight: 700;
    font-size: 0.88rem;
    margin-bottom: 10px;
}

.file-errors-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.file-error-item {
    font-size: 0.82rem;
    color: var(--text);
    background: rgba(0, 0, 0, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    padding: 10px 12px;
    line-height: 1.45;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.file-error-item strong {
    color: #fff;
}

.file-error-type {
    font-weight: 700;
    color: #fca5a5;
}

/* ---------- Container de miniaturas ---------- */

.thumbnails-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 16px;
    min-height: auto;
    padding: 20px;
    border: 2px dashed rgba(107, 78, 255, 0.2);
    border-radius: 14px;
    background: var(--surface);
    position: relative;
    transition: border-color 0.2s ease, background 0.2s ease, opacity 0.2s ease;
    overflow-x: hidden;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.thumbnails-container.has-files {
    border-style: solid;
    border-color: rgba(107, 78, 255, 0.35);
}

.thumbnails-container.drag-over {
    border-color: var(--accent);
    background: rgba(232, 255, 71, 0.03);
}

/* ---------- Estado vazio ---------- */

.empty-message {
    display: none;
}

/* ---------- Card de miniatura ---------- */

.thumbnail-item {
    position: relative;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    cursor: move;
    transition: all 0.25s ease;
    user-select: none;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.thumbnail-item:hover {
    border-color: rgba(107, 78, 255, 0.45);
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.thumbnail-item.dragging {
    opacity: 0.6;
    transform: rotate(2deg) scale(1.02);
    z-index: 100;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
}

.thumbnail-item.drag-target {
    border-color: var(--accent);
    background: rgba(232, 255, 71, 0.05);
}

.thumbnail-item.loading {
    background: linear-gradient(90deg, var(--surface2) 25%, var(--surface) 50%, var(--surface2) 75%);
    background-size: 200% 100%;
    animation: loading-shimmer 1.5s infinite;
}

.thumbnail-item.has-error {
    border-color: rgba(239, 68, 68, 0.35);
    background: rgba(239, 68, 68, 0.05);
}

@keyframes loading-shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* ---------- Preview ---------- */

.thumbnail-canvas {
    width: 100%;
    height: 150px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    margin-bottom: 10px;
    display: block;
    object-fit: contain;
    max-width: 100%;
    box-sizing: border-box;
}

.thumbnail-loading,
.thumbnail-error {
    width: 100%;
    height: 150px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: var(--muted);
    gap: 10px;
    font-size: 0.75rem;
    text-align: center;
    padding: 12px;
    max-width: 100%;
    box-sizing: border-box;
}

.thumbnail-error.invalid {
    background: rgba(239, 68, 68, 0.08);
    border-color: rgba(239, 68, 68, 0.22);
    color: #fca5a5;
}

.thumbnail-error.protected {
    background: rgba(245, 158, 11, 0.08);
    border-color: rgba(245, 158, 11, 0.22);
    color: #fcd34d;
}

.thumbnail-error-icon {
    font-size: 2rem;
    line-height: 1;
}

.thumbnail-error-label {
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1.3;
}

.loading-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--accent2);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* ---------- Info do arquivo ---------- */

.file-info-item {
    text-align: center;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.file-info-item .file-name {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
    line-height: 1.3;
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.file-info-item .file-size {
    font-size: 0.65rem;
    color: var(--muted);
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* ---------- Botão remover ---------- */

.remove-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    background: rgba(239, 68, 68, 0.8);
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: background 0.2s ease;
    line-height: 1;
    padding: 0;
}

.remove-btn:hover {
    background: var(--error);
}

/* ---------- Número da ordem ---------- */

.order-number {
    position: absolute;
    top: 6px;
    left: 6px;
    width: 22px;
    height: 22px;
    background: var(--accent2);
    color: #fff;
    border-radius: 50%;
    font-size: 0.65rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
}

/* ---------- Botão adicionar mais ---------- */

.add-more-item {
    background: transparent;
    border: 2px dashed rgba(107, 78, 255, 0.3);
    border-radius: 12px;
    padding: 14px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 220px;
    transition: all 0.25s ease;
    color: var(--muted);
    gap: 8px;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.add-more-item:hover {
    border-color: var(--accent2);
    color: var(--text);
    background: rgba(107, 78, 255, 0.05);
    transform: translateY(-2px);
}

.add-more-icon {
    font-size: 2rem;
    font-weight: 300;
    color: var(--accent2);
    line-height: 1;
}

.add-more-text {
    font-size: 0.78rem;
    font-weight: 600;
    text-align: center;
    line-height: 1.35;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* ---------- Drop zone ---------- */

.drop-zone {
    position: absolute;
    inset: 0;
    border-radius: 12px;
    pointer-events: none;
    z-index: -1;
}

.drop-zone.active {
    pointer-events: all;
    z-index: 50;
}

/* ---------- Overlay de loading ---------- */

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.loading-overlay.active {
    display: flex;
}

.loading-content {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 40px 48px;
    border-radius: 20px;
    text-align: center;
    min-width: 360px;
    max-width: calc(100vw - 32px);
    position: relative;
    overflow: hidden;
    box-sizing: border-box;
}

.loading-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent2), var(--accent), transparent);
}

.loading-title {
    font-family: 'Syne', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 24px;
}

.loading-progress-bar {
    width: 100%;
    height: 6px;
    background: var(--surface2);
    border-radius: 100px;
    overflow: hidden;
    margin: 16px 0;
}

.loading-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent2), var(--accent));
    border-radius: 100px;
    width: 0%;
    transition: width 0.3s ease;
    position: relative;
    overflow: hidden;
}

.loading-progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 60%;
    height: 100%;
    background: rgba(255, 255, 255, 0.25);
    animation: shimmer 1.2s ease infinite;
}

.loading-progress-text {
    font-size: 0.82rem;
    color: var(--muted);
    margin-top: 12px;
}

/* ---------- Blocos com risco de overflow ---------- */

.status-info,
.status-grid,
.status-item,
.thumbnail-item,
.add-more-item,
.file-info-item {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

/* ---------- Tema claro ---------- */

body.theme-light .file-errors-panel {
    background: #fef2f2;
    border: 1px solid #fca5a5;
}

body.theme-light .file-error-item {
    background: #fff;
    border: 1px solid #fecaca;
}

body.theme-light .file-error-type {
    color: #b91c1c;
}

body.theme-light .thumbnail-item {
    background: #fff;
    border-color: rgba(0, 0, 0, 0.08);
}

body.theme-light .thumbnail-item.has-error {
    background: #fff7f7;
    border-color: #fca5a5;
}

/* ---------- Responsivo ---------- */

@media (max-width: 768px) {
    .upload-area {
        padding: 28px 18px;
    }

    .upload-icon {
        font-size: 2.3rem;
    }

    .upload-title {
        font-size: 1rem;
    }

    .upload-hint {
        font-size: 0.86rem;
    }

    .status-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .status-item {
        padding: 10px 6px;
    }

    .status-number {
        font-size: clamp(0.9rem, 5vw, 1.2rem);
    }

    .status-label {
        font-size: 0.65rem;
    }

    .thumbnails-container {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        justify-items: center;
        gap: 14px;
        padding: 16px;
        min-height: auto;
        overflow-x: hidden;
        overflow-y: visible;
        width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }

    .thumbnail-item,
    .add-more-item {
        width: 80%;
        max-width: 80%;
        min-width: 0;
        margin: 0 auto;
        box-sizing: border-box;
    }

    .thumbnail-item {
        touch-action: none;
    }

    .thumbnail-canvas,
    .thumbnail-loading,
    .thumbnail-error {
        width: 100%;
        max-width: 100%;
        height: 220px;
        box-sizing: border-box;
    }

    .file-info-item,
    .file-info-item .file-name,
    .file-info-item .file-size {
        min-width: 0;
        max-width: 100%;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    .add-more-item {
        height: 160px;
    }

    .loading-content {
        min-width: 0;
        width: calc(100vw - 32px);
        padding: 28px 22px;
    }
}

@media (max-width: 480px) {
    .upload-area {
        padding: 24px 16px;
    }

    .upload-title {
        font-size: 0.96rem;
    }

    .upload-hint {
        font-size: 0.82rem;
    }

    .status-info {
        padding: 16px;
    }

    .thumbnails-container {
        padding: 14px;
    }

    .thumbnail-item,
    .add-more-item {
        width: 88%;
        max-width: 88%;
    }

    .thumbnail-canvas,
    .thumbnail-loading,
    .thumbnail-error {
        height: 200px;
    }
}