/* ===== RESET & BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ===== CSS VARIABLES ===== */
:root {
    --bg: #f7f5ed;
    --fg: #171717;
    --card-bg: #f5f5f5;
    --card-shadow: rgba(0, 0, 0, 0.08);
    --btn-bg: #171717;
    --btn-fg: #f7f5ed;
    --btn-hover: #2a2a2a;
    --btn-progress: #5a8570;
    --toggle-bg: rgba(0, 0, 0, 0.08);
    --toggle-hover: rgba(0, 0, 0, 0.15);
    --transition: 0.3s ease;
}

html[data-theme="dark"] {
    --bg: #171717;
    --fg: #f7f5ed;
    --card-bg: #1a1a1a;
    --card-shadow: rgba(255, 255, 255, 0.05);
    --btn-bg: #f7f5ed;
    --btn-fg: #171717;
    --btn-hover: #e0e0e0;
    --btn-progress: #4a6b58;
    --toggle-bg: rgba(255, 255, 255, 0.08);
    --toggle-hover: rgba(255, 255, 255, 0.15);
}

/* ===== GLOBAL STYLES ===== */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background-color: #f7f5ed;
    color: #171717;
    transition: background-color 0.42s ease, color 0.42s ease;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    position: relative;
}

html[data-theme="dark"] body {
    background-color: #171717;
    color: #f7f5ed;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.015;
    pointer-events: none;
    z-index: -1;
    background-image:
        repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,.03) 2px, rgba(0,0,0,.03) 4px),
        repeating-linear-gradient(90deg, transparent, transparent 2px, rgba(0,0,0,.03) 2px, rgba(0,0,0,.03) 4px);
    background-size: 100px 100px;
    transition: opacity 0.3s ease, background-image 0.3s ease;
}

html[data-theme="dark"] body::before {
    opacity: 0.025;
    background-image:
        repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(255,255,255,.05) 2px, rgba(255,255,255,.05) 4px),
        repeating-linear-gradient(90deg, transparent, transparent 2px, rgba(255,255,255,.05) 2px, rgba(255,255,255,.05) 4px);
}

/* ===== MAIN CONTAINER ===== */
main {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2.5rem;
    max-width: 600px;
    width: 100%;
}

/* ===== PDF PREVIEW ===== */
.pdf-preview {
    width: 100%;
    aspect-ratio: 16 / 9; /* Full HD */
    background: var(--card-bg);
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12),
                0 1px 2px rgba(0, 0, 0, 0.24);
    overflow: hidden;
}

html[data-theme="dark"] .pdf-preview {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4),
                0 4px 12px rgba(0, 0, 0, 0.3);
}

.pdf-page {
    width: 100%;
    height: 100%;
    position: relative;
}

/* Placeholder - rimuovi quando usi immagine reale */
.placeholder-preview {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--fg);
    opacity: .95;
}

.pdf-page img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}


/* ===== DOWNLOAD BUTTON ===== */
.download-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 2.5rem;
    background: var(--btn-bg);
    color: var(--btn-fg);
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    position: relative;
    overflow: hidden;
    letter-spacing: -0.005rem;
}

.download-btn::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 2px;
    background: var(--btn-progress);
    transition: width 0.4s ease;
}

.download-btn:hover::after {
    width: 94%;
}

.download-btn.downloading::after {
    width: 100%;
    transition: width 0.3s ease;
}

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

.download-btn:active {
    transform: scale(0.98);
}

.btn-icon {
    width: 20px;
    height: 20px;
}

.download-btn.downloading .btn-icon {
    animation: download-icon 0.4s ease-out;
}

@keyframes download-icon {
    0% { transform: translateY(0); }
    40% { transform: translateY(3px); opacity: 0.5; }
    100% { transform: translateY(0); opacity: 1; }
}

/* ===== THEME TOGGLE ===== */
.theme-toggle {
    position: fixed;
    bottom: 1.5rem;
    left: 1.5rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--toggle-bg);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s ease, background-color 0.2s ease;
    opacity: 0.25;
}

.theme-toggle:hover {
    opacity: 0.7;
    background: var(--toggle-hover);
}

.theme-toggle svg {
    width: 20px;
    height: 20px;
    position: absolute;
    transition: all var(--transition);
}

.sun-icon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

.moon-icon {
    opacity: 0;
    transform: rotate(90deg) scale(0);
}

html[data-theme="dark"] .sun-icon {
    opacity: 0;
    transform: rotate(-90deg) scale(0);
}

html[data-theme="dark"] .moon-icon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    body {
        padding: 1rem;
    }

    main {
        gap: 2rem;
    }

    .download-btn {
        padding: 0.875rem 2rem;
        font-size: 0.9375rem;
    }

    /* Mobile: mostra barra fino a 85% al tap, 100% quando downloading */
    .download-btn:active::after {
        width: 94%;
    }

    .download-btn.downloading::after {
        width: 100%;
    }

    .theme-toggle {
        width: 36px;
        height: 36px;
        bottom: 1rem;
        left: 1rem;
    }

    .theme-toggle svg {
        width: 18px;
        height: 18px;
    }
}

@media (max-width: 480px) {
    .pdf-preview {
        border-radius: 6px;
    }

    .download-btn {
        width: 100%;
        justify-content: center;
    }
}

/* Touch devices: gestisci hover come tap */
@media (hover: none) and (pointer: coarse) {
    .download-btn:active::after {
        width: 85%;
    }

    .download-btn.downloading::after {
        width: 100%;
    }
}
