/* ========== RESET E VARIABILI ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Colori del tema moderno */
    --primary-color: #6366f1;
    --primary-light: #818cf8;
    --secondary-color: #4f46e5;
    --accent-color: #ec4899;
    --bg-color: #0f172a;
    --bg-secondary: #1e293b;
    --text-color: #f1f5f9;
    --text-muted: #94a3b8;
    --control-bg: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    --hover-color: #334155;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* ========== HEADER ========== */
header {
    background: var(--control-bg);
    padding: 18px 24px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    box-shadow: var(--shadow-md);
    z-index: 100;
    border-bottom: 2px solid var(--primary-color);
}

header h1 {
    font-size: 1.8rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--accent-color) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 0;
}

.header-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
    width: 100%;
}

/* ========== MAIN AREA ========== */
main {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    scroll-behavior: smooth;
}

/* ========== SEZIONE UPLOAD ========== */
.upload-section {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    min-height: 100%;
    padding: 40px 20px;
    gap: 40px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}



/* ========== CONTENITORE PDF - SPLIT SCREEN ========== */
.pdf-container {
    display: flex;
    gap: 0;
    height: 100%;
    background: linear-gradient(180deg, var(--bg-color) 0%, var(--bg-secondary) 100%);
    overflow: hidden;
}

/* Pannello NOTE (fisso a sinistra) */
.notes-panel {
    flex: 0 0 35%;
    max-width: 450px;
    min-width: 300px;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--bg-secondary);
    border-right: 2px solid var(--primary-color);
    padding: 24px;
    transition: all 0.3s ease;
}

.notes-panel.hidden {
    flex: 0 0 0;
    min-width: 0;
    max-width: 0;
    padding: 0;
    border: none;
    overflow: hidden;
}

/* Pannello SPARTITO (scrollabile a destra) */
.sheet-panel {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px;
    -webkit-overflow-scrolling: touch;
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
}

/* Quando le note sono nascoste, centra lo spartito */
.notes-panel.hidden + .sheet-panel {
    justify-content: center;
}

#notesCanvas,
#pdfCanvas {
    max-width: 100%;
    height: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6), 0 0 0 1px rgba(99, 102, 241, 0.1);
    border-radius: 12px;
}

/* ========== PULSANTI ========== */
.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    border: none;
    padding: 16px 48px;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-height: 50px;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.btn-primary::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s;
}

.btn-primary:hover::before {
    left: 100%;
}

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.5);
}

.btn-primary:active {
    transform: translateY(-1px);
}

.btn-control {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--hover-color) 100%);
    border: 2px solid transparent;
    color: var(--text-color);
    padding: 14px;
    font-size: 1.3rem;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-height: 56px;
    min-width: 56px;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* Stile per le icone SVG nei pulsanti */
.btn-control svg {
    width: 26px;
    height: 26px;
    fill: currentColor;
    transition: all 0.3s ease;
}

.btn-round {
    aspect-ratio: 1/1;
}

.btn-play-pause {
    min-height: 64px;
    min-width: 64px;
    width: 64px;
    height: 64px;
    font-size: 1.6rem;
}

.btn-play-pause svg {
    width: 32px;
    height: 32px;
}

.btn-control:hover {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
    border-color: var(--primary-light);
}

.btn-control:active {
    transform: scale(0.95);
}

/* ========== CONTROLLO VELOCITÀ ========== */
.speed-control {
    display: flex;
    align-items: center;
    gap: 12px;
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--hover-color) 100%);
    padding: 12px 20px;
    border-radius: 50px;
    box-shadow: var(--shadow-sm);
    border: 2px solid rgba(99, 102, 241, 0.2);
}

.speed-control label {
    font-weight: 600;
    white-space: nowrap;
    color: var(--text-muted);
    font-size: 0.95rem;
}

#speedSlider {
    width: 150px;
    height: 8px;
    background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
    outline: none;
    border-radius: 10px;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.3);
}

#speedSlider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 26px;
    height: 26px;
    background: linear-gradient(135deg, #ffffff 0%, var(--primary-light) 100%);
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.6), 0 0 0 4px rgba(99, 102, 241, 0.2);
    border: 2px solid white;
}

#speedSlider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.8), 0 0 0 6px rgba(99, 102, 241, 0.3);
}

#speedSlider::-moz-range-thumb {
    width: 26px;
    height: 26px;
    background: linear-gradient(135deg, #ffffff 0%, var(--primary-light) 100%);
    cursor: pointer;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.6);
}

#speedValue {
    min-width: 48px;
    text-align: center;
    font-weight: 700;
    font-size: 1.1rem;
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--accent-color) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ========== RESPONSIVE TABLET/MOBILE ========== */
@media (max-width: 768px) {
    /* Fix per Android: permetti scroll su body */
    body {
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }
    
    main {
        overflow: visible;
        height: auto;
        flex: none;
    }
    
    /* PDF split screen su mobile */
    .pdf-container {
        flex-direction: column;
        height: auto;
    }
    
    /* Note panel nascosto su mobile per default */
    .notes-panel {
        display: none;
    }
    
    .sheet-panel {
        padding: 10px;
    }
    
    /* Upload section ottimizzata per mobile */
    .upload-section {
        padding: 20px 15px;
        gap: 25px;
        justify-content: flex-start;
        height: auto;
        min-height: auto;
    }
    
    .library-section {
        margin-bottom: 20px;
    }
    
    /* Header compatto */
    header {
        padding: 14px 12px;
    }
    
    header h1 {
        font-size: 1.3rem;
    }
    
    .header-controls {
        gap: 10px;
    }
    
    .control-btn {
        min-height: 36px;
        min-width: 36px;
        padding: 6px;
        font-size: 1rem;
    }
    
    .btn-control {
        min-height: 52px !important;
        min-width: 52px !important;
        width: 52px !important;
        height: 52px !important;
        font-size: 1.2rem;
        padding: 10px;
    }
    
    .btn-control svg {
        width: 24px;
        height: 24px;
    }
    
    .btn-play-pause {
        min-height: 58px !important;
        min-width: 58px !important;
        width: 58px !important;
        height: 58px !important;
        font-size: 1.4rem;
    }
    
    .btn-play-pause svg {
        width: 28px;
        height: 28px;
    }
    
    .speed-control {
        padding: 10px 16px;
        gap: 10px;
    }
    
    .speed-control label {
        font-size: 0.85rem;
    }
    
    #speedSlider {
        width: 100px;
        height: 8px;
    }
    
    #speedSlider::-webkit-slider-thumb {
        width: 22px;
        height: 22px;
    }
    
    #speedSlider::-moz-range-thumb {
        width: 22px;
        height: 22px;
    }
    
    #speedValue {
        font-size: 0.9rem;
        min-width: 40px;
    }
    
    .upload-box {
        padding: 25px 20px;
        max-width: 350px;
    }
    
    .pdf-container {
        padding: 10px;
    }
}

/* ========== FULLSCREEN MODE ========== */
:fullscreen,
:-webkit-full-screen,
:-moz-full-screen,
:-ms-fullscreen {
    background-color: var(--bg-color);
}

:fullscreen main,
:-webkit-full-screen main,
:-moz-full-screen main,
:-ms-fullscreen main {
    background-color: var(--bg-color);
}



/* ========== ANIMAZIONI ========== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.pdf-container {
    animation: fadeIn 0.5s ease;
}

/* ========== TOAST NOTIFICATIONS ========== */
.toast-container {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--hover-color) 100%);
    color: var(--text-color);
    padding: 16px 24px;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    min-width: 300px;
    max-width: 400px;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.7s;
    border-left: 4px solid var(--primary-color);
    pointer-events: auto;
}

.toast.error {
    border-left-color: #ef4444;
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.2) 0%, var(--bg-secondary) 100%);
}

.toast.warning {
    border-left-color: #f59e0b;
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.2) 0%, var(--bg-secondary) 100%);
}

.toast.success {
    border-left-color: #22c55e;
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.2) 0%, var(--bg-secondary) 100%);
}

.toast-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.toast-message {
    flex: 1;
    font-size: 0.95rem;
    line-height: 1.4;
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeOut {
    to {
        opacity: 0;
        transform: translateX(400px);
    }
}

@media (max-width: 768px) {
    .toast-container {
        right: 10px;
        left: 10px;
        top: 70px;
    }
    
    .toast {
        min-width: auto;
        max-width: 100%;
    }
}

/* ========== LIBRERIA SPARTITI ========== */
.library-section {
    width: 100%;
    max-width: 1200px;
}

.library-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 0 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.library-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
}

.library-title {
    font-size: 1.8rem;
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--accent-color) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 0;
}

/* Pulsante sincronizzazione */
.btn-sync {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    border: none;
    border-radius: 8px;
    color: var(--text-color);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
    position: relative;
}

.btn-sync:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-sync:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-sync svg {
    width: 20px;
    height: 20px;
}

/* Pulsante pulizia cache */
.btn-clear-cache {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    border: none;
    border-radius: 8px;
    color: var(--text-color);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
}

.btn-clear-cache:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
}

.btn-clear-cache svg {
    width: 20px;
    height: 20px;
    animation: rotate-cache 3s linear infinite;
}

@keyframes rotate-cache {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.sync-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #ff4444;
    color: white;
    font-size: 0.7rem;
    font-weight: bold;
    padding: 0;
    border-radius: 50%;
    width: 14px;
    height: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(255, 68, 68, 0.5);
    animation: pulse-red 2s ease-in-out infinite;
}

@keyframes pulse-red {
    0%, 100% { 
        transform: scale(1);
        box-shadow: 0 2px 6px rgba(255, 68, 68, 0.5);
    }
    50% { 
        transform: scale(1.1);
        box-shadow: 0 3px 10px rgba(255, 68, 68, 0.8);
    }
}

/* Barra progresso sincronizzazione */
.sync-progress {
    width: 100%;
    padding: 15px 20px;
    background: rgba(99, 102, 241, 0.1);
    border-radius: 8px;
    margin-bottom: 20px;
}

.sync-progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-secondary);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.sync-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color) 0%, var(--accent-color) 100%);
    transition: width 0.3s ease;
    width: 0%;
}

.sync-progress-text {
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.category-card {
    cursor: pointer;
    min-height: 180px;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.15) 0%, rgba(236, 72, 153, 0.15) 100%);
    border: 3px solid var(--primary-color);
}

.category-card:hover {
    transform: translateY(-8px) scale(1.05);
    border-color: var(--accent-color);
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.25) 0%, rgba(236, 72, 153, 0.25) 100%);
}

.library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    padding: 0 20px;
}

.library-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 40px;
    background: rgba(99, 102, 241, 0.1);
    border-radius: 16px;
    border: 2px dashed rgba(99, 102, 241, 0.3);
}

.library-empty small {
    display: block;
    margin-top: 10px;
    font-size: 0.85rem;
}

.library-empty code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
}

.spartito-card {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--hover-color) 100%);
    border: 2px solid rgba(99, 102, 241, 0.2);
    border-radius: 16px;
    padding: 30px 24px;
    text-align: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 20px;
    min-height: 200px;
}

.spartito-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary-color);
    box-shadow: var(--shadow-lg);
    background: linear-gradient(135deg, var(--hover-color) 0%, var(--bg-secondary) 100%);
}

.spartito-title {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-color);
    word-break: break-word;
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 15px 0;
}

.btn-load {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 50px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
}

.btn-load:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.5);
}

/* ========== RESPONSIVE LIBRARY ========== */
@media (max-width: 768px) {
    .library-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 15px;
    }
    
    .spartito-card {
        padding: 20px 15px;
    }
    
    .spartito-icon {
        font-size: 2.5rem;
    }
    
    .spartito-title {
        font-size: 1rem;
    }
}
