/**
 * Print & Go - Frontend Fixes CSS
 * Stili per layout icone, pagine, e opzioni
 */

/* ============================================
   ICONE SOPRA TESTO
   ============================================ */

.pg-mode-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.pg-mode-icon {
    display: block;
    margin-bottom: 8px;
}

.pg-mode-icon svg {
    display: block;
}

.pg-mode-label {
    display: block;
    text-align: center;
    font-weight: 500;
}

/* Stile pulsanti con icone - NON sovrascrive colori esistenti */
.pg-mode-option {
    flex: 1;
    cursor: pointer;
    transition: all 0.3s;
}

.pg-mode-option input[type="radio"] {
    display: none;
}

/* Mantiene gli stili esistenti per hover e checked */

/* Container pulsanti */
.pg-config-mode.pg-with-icons {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

/* ============================================
   PAGINE SELEZIONA - LAYOUT ORIZZONTALE
   ============================================ */

.pg-horizontal-pages-scroll {
    /* Layout dinamico gestito da .pg-horizontal-mode o .pg-grid-mode */
    padding: 15px;
}

.pg-page-horizontal-item {
    flex: 0 0 auto;
    width: 120px;
    position: relative;
}

.pg-page-horizontal-img {
    width: 100%;
    height: auto;
    display: block;
    border: 2px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.pg-page-horizontal-img:hover {
    border-color: #2271b1;
    transform: scale(1.05);
}

.pg-page-checkbox-horizontal:checked + .pg-page-horizontal-img {
    border-color: #2271b1;
    box-shadow: 0 0 0 3px rgba(34, 113, 177, 0.2);
}

/* Scrollbar gestita da .pg-horizontal-mode o .pg-grid-mode */

/* ============================================
   PULSANTE OPZIONI AVANZATE (Stirling)
   ============================================ */

.pg-advanced-toggle {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    background: white !important;
    border: 2px solid #2271b1 !important;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    color: #2271b1 !important;
    transition: all 0.2s;
}

.pg-advanced-toggle:hover {
    background: #f0f6fc !important;
    border-color: #135e96 !important;
}

.pg-toggle-icon {
    font-size: 20px;
    font-weight: bold;
    line-height: 1;
    transition: transform 0.2s;
}

/* ============================================
   OPZIONI STIRLING - LISTA VERTICALE
   ============================================ */

.pg-stirling-options-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 8px;
    margin-top: 12px;
}

.pg-stirling-option {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    background: white;
    transition: all 0.2s;
}

.pg-stirling-option:hover {
    border-color: #2271b1;
    background: #f0f6fc;
}

.pg-stirling-option input[type="checkbox"] {
    margin-top: 3px;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    cursor: pointer;
    accent-color: #2271b1;
}

.pg-stirling-option span {
    flex: 1;
    font-size: 14px;
    line-height: 1.5;
}

/* Parametri opzioni Stirling */
.pg-stirling-param {
    width: 100%;
    margin-top: 8px;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
}

/* ============================================
   OPZIONI CUSTOM (da backend)
   ============================================ */

.pg-custom-options {
    margin-top: 15px;
}

.pg-custom-options .pg-config-section {
    margin-bottom: 20px;
}

/* Gruppi opzioni con icone (se presenti) - FULL WIDTH */
.pg-custom-options .pg-config-mode {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    width: 100% !important;
}

/* Gruppi image-picker (opzioni con icone) - FULL WIDTH */
.pg-config-mode.pg-with-icons {
    width: 100% !important;
}

/* ============================================
   PICKER MENU (Dropdown)
   ============================================ */

.pg-picker-menu-wrapper {
    position: relative;
    width: 100%;
}

.pg-picker-menu-btn {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: white;
    border: 2px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
    transition: all 0.2s;
}

.pg-picker-menu-btn:hover {
    border-color: #2271b1;
    background: #f0f6fc;
}

.pg-picker-current {
    flex: 1;
    text-align: left;
    font-weight: 500;
}

.pg-picker-arrow {
    margin-left: 8px;
    transition: transform 0.2s;
}

.pg-picker-menu-options {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: white;
    border: 2px solid #2271b1;
    border-radius: 12px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.12);
    max-height: 300px;
    overflow-y: auto;
    z-index: 100;
    padding: 8px;
}

.pg-picker-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 8px;
    margin-bottom: 4px;
}

.pg-picker-option:last-child {
    margin-bottom: 0;
}

.pg-picker-option:hover {
    background: #f0f6fc;
}

.pg-picker-option input[type="radio"] {
    width: 20px;
    height: 20px;
    margin: 0;
    flex-shrink: 0;
    cursor: pointer;
    accent-color: #2271b1;
}

.pg-picker-option span {
    flex: 1;
    text-align: left;
    margin-right: 12px;
    font-size: 14px;
}

.pg-picker-option:has(input[type="radio"]:checked) span {
    font-weight: 600;
    color: #2271b1;
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    .pg-config-mode.pg-with-icons {
        flex-direction: column;
    }
    
    /* Solo gruppi con icone vanno in verticale su mobile */
    .pg-config-mode.pg-with-icons .pg-mode-option {
        width: 100%;
        margin: 0 0 15px 0;
    }
    
    .pg-config-mode.pg-with-icons .pg-mode-option:last-child {
        margin-bottom: 0;
    }
    
    .pg-horizontal-pages {
        max-width: 100%;
    }
    
    /* Container più alto su tablet */
    .pg-horizontal-mode,
    .pg-grid-mode {
        min-height: 350px !important;
        max-height: 75vh !important;
    }
    
    /* Item pagina tablet */
    .pg-page-horizontal-item {
        width: 120px !important;
        min-height: 200px !important;
    }
}

@media (max-width: 480px) {
    .pg-page-horizontal-item {
        width: 80px;
    }
    
    /* Solo gruppi con icone hanno padding ridotto */
    .pg-config-mode.pg-with-icons .pg-mode-option {
        padding: 12px;
    }
    
    .pg-mode-icon svg {
        width: 28px;
        height: 28px;
    }
    
    /* Container più alto su mobile - pagine non troncate */
    .pg-horizontal-mode,
    .pg-grid-mode {
        min-height: 400px !important; /* Altezza minima per vedere le pagine complete */
        max-height: 80vh !important; /* Max 80% viewport height */
    }
    
    /* Thumbnail più grandi su mobile */
    .pg-thumbnail-skeleton {
        min-height: 180px !important;
    }
    
    /* Item pagina più grande */
    .pg-page-horizontal-item {
        width: 140px !important;
        min-height: 220px !important;
    }
}

/* ============================================
   LAYOUT DINAMICO: HORIZONTAL vs GRID
   ============================================ */

/* HORIZONTAL MODE (< 30 pagine) - Scroll orizzontale */
.pg-horizontal-mode {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 15px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    scroll-snap-type: x proximity;
    padding: 20px 15px 40px 15px; /* Più spazio sotto per scrollbar GRANDE */
    background: linear-gradient(135deg, #e3f2fd 0%, #f5f5f5 100%);
    border: 3px solid #2271b1;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(34, 113, 177, 0.15);
    position: relative;
    justify-content: flex-start; /* ← Inizia sempre da sinistra */
}

/* Hint più grande e visibile - scompare dopo 5 secondi */
.pg-horizontal-mode::before {
    content: 'Usa la scrollbar sotto per vedere tutte le pagine →';
    position: absolute;
    bottom: 12px; /* ← Più su per scrollbar grande */
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #2271b1, #1565c0);
    color: white;
    padding: 10px 20px;
    border-radius: 16px;
    font-size: 16px; /* ← PIÙ GRANDE */
    font-weight: 700;
    z-index: 20;
    white-space: nowrap;
    animation: fadeOutHint 5s ease-in-out forwards;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(34, 113, 177, 0.5);
    letter-spacing: 0.5px;
}

@keyframes fadeOutHint {
    0% { 
        opacity: 1; 
        transform: translateX(-50%) scale(1);
    }
    10% { 
        transform: translateX(-50%) scale(1.1);
    }
    20% { 
        transform: translateX(-50%) scale(1);
    }
    70% { 
        opacity: 1;
        transform: translateX(-50%) scale(1);
    }
    100% { 
        opacity: 0; 
        visibility: hidden;
        transform: translateX(-50%) scale(0.95);
    }
}

.pg-horizontal-mode .pg-page-horizontal-item {
    flex-shrink: 0 !important;
    width: 180px !important;
    scroll-snap-align: start;
}

/* GRID MODE (≥ 30 pagine) - 2 RIGHE con scroll orizzontale */
.pg-grid-mode {
    display: flex !important;
    flex-direction: column !important;
    gap: 15px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    scroll-snap-type: x proximity;
    padding: 20px 15px 40px 15px; /* Più spazio sotto per scrollbar GRANDE */
    background: linear-gradient(135deg, #e8f5e9 0%, #f5f5f5 100%);
    border: 3px solid #00897b;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 137, 123, 0.15);
    position: relative;
}

/* Container per le 2 righe */
.pg-grid-mode > * {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 15px !important;
}

/* Prima riga (metà pagine) */
.pg-grid-mode-row-1 {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 15px !important;
}

/* Seconda riga (metà pagine) */
.pg-grid-mode-row-2 {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 15px !important;
}

/* Hint più grande e visibile - scompare dopo 5 secondi */
.pg-grid-mode::before {
    content: 'Usa la scrollbar sotto per vedere tutte le pagine →';
    position: absolute;
    bottom: 12px; /* ← Più su per scrollbar grande */
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #00897b, #00695c);
    color: white;
    padding: 10px 20px;
    border-radius: 16px;
    font-size: 16px; /* ← PIÙ GRANDE */
    font-weight: 700;
    z-index: 20;
    white-space: nowrap;
    animation: fadeOutHint 5s ease-in-out forwards;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0, 137, 123, 0.5);
    letter-spacing: 0.5px;
}

.pg-grid-mode .pg-page-horizontal-item {
    flex-shrink: 0 !important;
    width: 180px !important;
    scroll-snap-align: start;
}

/* ============================================
   SCROLLBAR VISIBILE E USER-FRIENDLY
   ============================================ */

/* Scrollbar orizzontale (< 30 pagine) - EXTRA GRANDE E VISIBILE */
.pg-horizontal-mode::-webkit-scrollbar {
    height: 24px !important; /* ← PIÙ GRANDE */
}

.pg-horizontal-mode::-webkit-scrollbar-track {
    background: linear-gradient(to bottom, #e3f2fd, #bbdefb) !important;
    border-radius: 12px !important;
    margin: 0 10px;
    box-shadow: inset 0 3px 8px rgba(0,0,0,0.2);
    border: 2px solid #2271b1; /* ← Bordo più spesso */
}

.pg-horizontal-mode::-webkit-scrollbar-thumb {
    background: linear-gradient(to bottom, #2271b1, #1565c0) !important;
    border-radius: 12px !important;
    border: 4px solid #e3f2fd !important; /* ← Bordo più spesso */
    box-shadow: 0 3px 10px rgba(0,0,0,0.4);
    cursor: grab;
    transition: all 0.2s ease;
}

.pg-horizontal-mode::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(to bottom, #1565c0, #0d47a1) !important;
    transform: scale(1.05);
}

.pg-horizontal-mode::-webkit-scrollbar-thumb:active {
    cursor: grabbing;
}

/* Scrollbar orizzontale (≥ 30 pagine con 2 righe) - EXTRA GRANDE E VISIBILE */
.pg-grid-mode::-webkit-scrollbar {
    height: 24px !important; /* ← PIÙ GRANDE */
}

.pg-grid-mode::-webkit-scrollbar-track {
    background: linear-gradient(to bottom, #e8f5e9, #c8e6c9) !important;
    border-radius: 12px !important;
    margin: 0 10px;
    box-shadow: inset 0 3px 8px rgba(0,0,0,0.2);
    border: 2px solid #00897b; /* ← Bordo più spesso */
}

.pg-grid-mode::-webkit-scrollbar-thumb {
    background: linear-gradient(to bottom, #00897b, #00695c) !important;
    border-radius: 12px !important;
    border: 4px solid #e8f5e9 !important; /* ← Bordo più spesso */
    box-shadow: 0 3px 10px rgba(0,0,0,0.4);
    cursor: grab;
    transition: all 0.2s ease;
}

.pg-grid-mode::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(to bottom, #00695c, #004d40) !important;
    transform: scale(1.05);
}

.pg-grid-mode::-webkit-scrollbar-thumb:active {
    cursor: grabbing;
}

/* Firefox scrollbar - PIÙ SPESSO */
.pg-horizontal-mode {
    scrollbar-width: auto; /* thick deprecato, usa auto */
    scrollbar-color: #2271b1 #e3f2fd;
}

.pg-grid-mode {
    scrollbar-width: auto;
    scrollbar-color: #00897b #e8f5e9;
}

/* ============================================
   PAGINE PIÙ CLICCABILI E INTUITIVE
   ============================================ */

/* Indicatore visivo che le pagine sono cliccabili */
.pg-page-horizontal-item {
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    border: 3px solid transparent !important;
}

.pg-page-horizontal-item:hover {
    transform: translateY(-8px) scale(1.05) !important;
    box-shadow: 0 8px 24px rgba(34, 113, 177, 0.4) !important;
}

/* Stato selezionato più evidente */
.pg-page-horizontal-item:has(.pg-page-checkbox-horizontal:checked) {
    background: linear-gradient(135deg, #e0f2f1 0%, #b2dfdb 100%) !important;
    box-shadow: 0 4px 16px rgba(0, 137, 123, 0.5) !important;
}

/* NUOVO LAYOUT: Header sopra con checkbox + label */

/* Header pagina: checkbox + "Pag. X" side by side - CLICCABILE */
.pg-page-header {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    margin-bottom: 10px !important;
    padding: 6px 8px !important;
    background: rgba(255, 255, 255, 0.9) !important;
    border-radius: 8px !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1) !important;
    cursor: pointer !important; /* ← CLICCABILE! */
    transition: all 0.2s ease !important;
    user-select: none !important; /* Previene selezione testo */
}

.pg-page-header:hover {
    background: rgba(34, 113, 177, 0.15) !important;
    box-shadow: 0 3px 10px rgba(34, 113, 177, 0.3) !important;
    transform: scale(1.02) !important;
}

.pg-page-header:active {
    transform: scale(0.98) !important;
}

/* Checkbox PIÙ GRANDE */
.pg-page-checkbox-horizontal {
    width: 32px !important;
    height: 32px !important;
    cursor: pointer !important;
    border-radius: 6px !important;
    margin: 0 !important;
    flex-shrink: 0 !important;
    border: 3px solid #2271b1 !important;
}

.pg-page-checkbox-horizontal:hover {
    transform: scale(1.15) !important;
    box-shadow: 0 0 0 4px rgba(34, 113, 177, 0.2) !important;
}

.pg-page-checkbox-horizontal:checked {
    background: #2271b1 !important;
}

/* Label "Pag. X" più prominente */
.pg-page-number {
    font-size: 15px !important;
    font-weight: 700 !important;
    color: #333 !important;
    user-select: none !important;
}

/* Footer nascosto (non serve più) */
.pg-page-horizontal-footer {
    display: none !important;
}

/* Thumbnail cliccabile */
.pg-thumbnail-clickable {
    cursor: pointer !important;
    transition: transform 0.2s ease, box-shadow 0.2s ease !important;
}

.pg-thumbnail-clickable:hover {
    transform: scale(1.05) !important;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3) !important;
}

.pg-thumbnail-clickable:active {
    transform: scale(0.98) !important;
}

/* Indicatore "Click per selezionare" solo al primo caricamento */
.pg-horizontal-mode .pg-page-horizontal-item:first-child::after,
.pg-grid-mode .pg-page-horizontal-item:first-child::after {
    content: '👆 Click per selezionare';
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: #ff9800;
    color: white;
    padding: 6px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    animation: bounce 1s ease-in-out 3;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

@keyframes bounce {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(-5px); }
}

/* Nasconde l'indicatore dopo il primo click */
.pg-horizontal-mode:has(.pg-page-checkbox-horizontal:checked) .pg-page-horizontal-item:first-child::after,
.pg-grid-mode:has(.pg-page-checkbox-horizontal:checked) .pg-page-horizontal-item:first-child::after {
    display: none;
}
