/* ============================================
   LEDPIXMAP - Responsive CSS v2.0
   Ottimizzato per Desktop, Tablet e Mobile
   ============================================ */

/* Reset e Base */
* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    overflow-x: hidden;
    font-family: Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    display: flex;
    flex-direction: column;
    background-color: #777777;
    position: relative;
}

/* Header Fisso */
.menu-header {
    width: 100%;
    height: 50px;
    background-color: #000000;
    z-index: 1006;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    padding: 0 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.menu-icon {
    position: relative;
    z-index: 1002;
    display: flex;
    align-items: center;
    font-size: 20px;
    cursor: pointer;
    color: white;
    padding: 5px;
    min-width: 40px;
    height: 40px;
    justify-content: center;
}

.menu-icon #TEXT {
    color: white;
    font-size: 10px;
    margin-left: 5px;
    white-space: nowrap;
}

.total-resolution-display {
    min-width: 60px;
    font-size: 10px;
    color: #ffffff;
    padding: 8px 12px;
    background-color: #6B6B6B;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 4px;
    margin: 0 5px;
}

.menu-header #screenNumber {
    min-width: 70px;
    font-size: 10px;
    color: #FFFFFF;
    padding: 8px 12px;
    background-color: #FF0000;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 4px;
    margin: 0 5px;
    font-weight: bold;
}

.howto {
    display: none; /* Nascosto di default, visibile solo su desktop grande */
    font-size: 10px;
    text-align: left;
    color: white;
    flex: 1;
    margin: 0 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.menu-header img {
    width: 80px;
    height: auto;
    max-height: 40px;
    object-fit: contain;
    margin-left: auto;
}

/* Container Principale */
.container {
    display: flex;
    width: 100%;
    margin: 0;
    padding: 0;
    margin-top: 50px; /* Spazio per header fisso */
    height: calc(100vh - 50px);
    position: relative;
}

/* Menu Laterale */
.menu-container {
    position: fixed;
    width: 420px;
    height: calc(100vh - 50px);
    z-index: 1000;
    top: 50px;
    left: 0;
    display: flex;
    flex-direction: column;
    background-color: transparent;
    overflow: hidden; /* Previeni overflow del container */
}

.menu-scrollable {
    width: 420px;
    height: 100%;
    max-height: calc(100vh - 50px);
    background-color: #f0f0f0;
    padding: 10px 12px;
    padding-bottom: 36px;
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform 0.3s ease;
    transform: translateX(0px);
    z-index: 1000;
    -webkit-overflow-scrolling: touch; /* Smooth scroll su iOS */
    position: relative; /* Assicura che lo scroll funzioni correttamente */
    box-sizing: border-box; /* Include padding nell'altezza */
}

.menu-scrollable::-webkit-scrollbar {
    width: 8px;
}

.menu-scrollable::-webkit-scrollbar-track {
    background: #e0e0e0;
}

.menu-scrollable::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.menu-scrollable::-webkit-scrollbar-thumb:hover {
    background: #666;
}

/* Titolo Menu */
.menu-scrollable h1 {
    color: #000FBD;
    font-size: 11px;
    text-align: left;
    font-family: Arial, sans-serif;
    padding: 0;
    margin: 0 0 6px 0;
    border-bottom: 1px solid #ccc;
    padding-bottom: 4px;
    line-height: 1.25;
}

.menu-collapse {
    margin: 0;
    border: none;
}

.menu-collapse + .menu-collapse {
    margin-top: 0;
}

.signal-flow-hint {
    font-size: 9px;
    color: #0057b7;
    line-height: 1.3;
    margin-bottom: 4px;
    justify-content: flex-start;
}

.menu-collapse > summary.menu-section-title {
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.menu-collapse > summary.menu-section-title::-webkit-details-marker {
    display: none;
}

.menu-collapse > summary.menu-section-title::before {
    content: '▸ ';
    font-size: 9px;
    color: #666;
}

.menu-collapse[open] > summary.menu-section-title::before {
    content: '▾ ';
}

.menu-collapse .menu-row:first-of-type,
.menu-collapse .upload-logo-row:first-of-type {
    margin-top: 2px;
}

/* Sezioni Menu */
.menu-section-title {
    width: 100%;
    font-weight: bold;
    font-size: 10px;
    margin-top: 5px;
    margin-bottom: 2px;
    border-top: 1px solid #ccc;
    padding-top: 4px;
    color: #333;
    line-height: 1.2;
}

.menu-row {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1px;
    gap: 6px;
    min-height: 22px;
}

.menu-row label {
    flex: 1;
    white-space: nowrap;
    text-align: left;
    font-size: 9px;
    color: #333;
    min-width: 0;
    line-height: 1.15;
}

.menu-row span {
    font-size: 8px;
    color: #666;
    white-space: nowrap;
    margin-left: 3px;
}

.menu-row input[type="number"],
.menu-row input[type="text"],
.menu-row select {
    flex: 0 0 108px;
    height: 22px;
    padding: 2px 6px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 10px;
    text-align: right;
}

.menu-row input[type="color"] {
    width: 34px;
    height: 24px;
    padding: 1px;
    border: 1px solid #ccc;
    border-radius: 3px;
    cursor: pointer;
}

.menu-row input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    margin-left: auto;
}

.menu-row-color-toggle input[type="color"] {
    flex: 0 0 34px;
    margin-left: 6px;
}

.menu-row-color-toggle input[type="checkbox"] {
    margin-left: auto;
}

.menu-row button {
    flex: 1;
    min-height: 24px;
    font-size: 9px;
    font-weight: 800;
    background-color: #dc3545;
    color: white;
    border-radius: 4px;
    border: 1px solid #000;
    cursor: pointer;
    padding: 4px 8px;
    transition: background-color 0.2s;
    margin: 1px;
}

.menu-row button:hover {
    background-color: #c82333;
}

.menu-row input[readonly] {
    background-color: #e8e8e8;
    cursor: default;
}

.menu-row input.total-resolution-field {
    flex: 1;
    text-align: left;
    font-size: 10px;
}

/* Credits */
.buttons-container {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 8px 0;
}

.buttons-container button {
    flex: 1;
    min-width: calc(50% - 2px);
}

.buttons-container button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.buttons-row-pair {
    display: flex;
    flex: 1 1 100%;
    width: 100%;
    gap: 4px;
}

.buttons-row-pair button {
    flex: 1;
    min-width: 0;
}

.screen-selector {
    flex: 1;
    min-width: calc(50% - 2px);
    padding: 6px 8px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    border: 1px solid #333;
    border-radius: 3px;
    background: #fff;
    color: #222;
    cursor: pointer;
}

canvas.preview-screen-active {
    outline: 3px solid #0078d4;
    outline-offset: 2px;
}

.credits {
    width: 100%;
    text-align: left;
    font-size: 8px;
    margin-top: 8px; /* Ridotto da 15px */
    padding-top: 6px; /* Ridotto da 10px */
    border-top: 1px solid #ccc;
    color: #666;
    line-height: 1.3; /* Ridotto da 1.4 */
}

/* Area Result */
.result {
    position: relative;
    margin-left: 420px;
    width: calc(100% - 420px);
    height: 100%;
    z-index: 900;
    background-color: #e8e8e8;
    overflow-x: auto;
    overflow-y: auto;
    padding: 20px;
    -webkit-overflow-scrolling: touch;
}

.result::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

.result::-webkit-scrollbar-track {
    background: #d0d0d0;
}

.result::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 6px;
}

.result::-webkit-scrollbar-thumb:hover {
    background: #666;
}

.image-container {
    display: inline-block;
    white-space: nowrap; /* Le immagini vanno in orizzontale, non a capo */
    line-height: 0; /* Rimuove spazio tra immagini inline */
    vertical-align: top;
    overflow: visible;
}

.preview-screen-wrapper {
    overflow: visible;
}

.preview-screen-selectable {
    cursor: pointer;
}

.preview-screen-selectable:hover canvas {
    outline: 2px solid #0078d4;
    outline-offset: 2px;
}

.menu-row-disabled {
    opacity: 0.45;
}

.menu-row-disabled select:disabled {
    cursor: not-allowed;
}

.image-container img {
    display: inline-block;
    vertical-align: top; /* Default, verrà sovrascritto da JS in base a layoutAlign */
    margin: 0;
    padding: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    border-radius: 4px;
}

/* Stato Menu Nascosto */
body.menu-hidden .menu-container {
    pointer-events: none;
    width: 0;
    overflow: hidden;
}

body.menu-hidden .menu-scrollable {
    transform: translateX(-100%);
}

body.menu-hidden .result {
    margin-left: 0;
    width: 100%;
}

/* ============================================
   MEDIA QUERIES - TABLET (iPad) 768px - 1024px
   ============================================ */
@media (max-width: 1024px) and (min-width: 768px) {
    .menu-container {
        width: 380px;
        overflow: hidden;
    }
    
    .menu-scrollable {
        width: 380px;
        height: 100%;
        max-height: calc(100vh - 55px);
        padding-bottom: 50px;
        overflow-y: auto;
        overflow-x: hidden;
        box-sizing: border-box;
    }
    
    .result {
        margin-left: 380px;
        width: calc(100% - 380px);
    }
    
    .menu-header {
        height: 55px;
    }
    
    .container {
        margin-top: 55px;
        height: calc(100vh - 55px);
    }
    
    .menu-container {
        top: 55px;
        height: calc(100vh - 55px);
    }
    
    .howto {
        display: none;
    }
    
    .total-resolution-display {
        font-size: 9px;
        padding: 6px 10px;
    }
    
    .menu-header #screenNumber {
        font-size: 9px;
        padding: 6px 10px;
    }
}

/* ============================================
   MEDIA QUERIES - MOBILE < 768px
   ============================================ */
@media (max-width: 767px) {
    html, body {
        overflow-x: hidden;
        height: 100%;
        position: relative;
    }
    
    body.menu-open {
        overflow: hidden; /* Previeni scroll del body quando menu è aperto */
        position: fixed;
        width: 100%;
    }
    
    /* Header Mobile */
    .menu-header {
        height: 60px;
        padding: 0 8px;
        flex-wrap: wrap;
    }
    
    .menu-icon {
        font-size: 24px;
        min-width: 44px;
        height: 44px;
    }
    
    .menu-icon #TEXT {
        display: none; /* Nascondi testo su mobile */
    }
    
    .total-resolution-display {
        font-size: 9px;
        padding: 6px 8px;
        min-width: 50px;
        margin: 0 3px;
    }
    
    .menu-header #screenNumber {
        font-size: 9px;
        padding: 6px 8px;
        min-width: 55px;
        margin: 0 3px;
    }
    
    .menu-header img {
        width: 60px;
        max-height: 35px;
    }
    
    .howto {
        display: none;
    }
    
    /* Container Mobile */
    .container {
        margin-top: 60px;
        height: calc(100vh - 60px);
    }
    
    /* Menu Mobile - Full Screen Drawer */
    .menu-container {
        width: 100%;
        max-width: 100%;
        height: calc(100vh - 60px);
        top: 60px;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    
    .menu-scrollable {
        width: 100%;
        height: 100%;
        max-height: 100%;
        padding: 12px;
        padding-bottom: 150px; /* Spazio extra molto aumentato per pulsanti e credits */
        background-color: #f5f5f5;
        overflow-y: auto;
        overflow-x: hidden;
        position: relative;
        box-sizing: border-box;
        -webkit-overflow-scrolling: touch;
        flex: 1;
        min-height: 0; /* Importante per flex */
    }
    
    .menu-scrollable h1 {
        font-size: 14px;
        margin-bottom: 12px;
    }
    
    .menu-section-title {
        font-size: 12px;
        margin-top: 12px;
        margin-bottom: 6px;
    }
    
    .menu-row {
        margin-bottom: 10px;
        flex-wrap: wrap;
    }
    
    .menu-row label {
        font-size: 11px;
        width: 100%;
        margin-bottom: 4px;
    }
    
    .menu-row input[type="number"],
    .menu-row input[type="text"],
    .menu-row select {
        flex: 1;
        min-width: 120px;
        height: 36px; /* Touch target più grande */
        font-size: 14px;
    }
    
    .menu-row input[type="color"] {
        width: 50px;
        height: 36px;
    }
    
    .menu-row input[type="checkbox"] {
        width: 24px;
        height: 24px;
    }
    
    .menu-row button {
        min-height: 44px; /* Touch target minimo 44px */
        font-size: 12px;
        padding: 12px;
        margin: 4px 0;
    }
    
    /* Container pulsanti su mobile - assicura visibilità */
    .buttons-container {
        margin-bottom: 20px !important;
        margin-top: 15px !important;
        padding-bottom: 20px !important;
        position: relative;
        z-index: 10;
    }
    
    .buttons-container button {
        min-height: 48px !important;
        font-size: 12px !important;
        margin-bottom: 8px !important;
    }
    
    /* Credits su mobile - assicura visibilità */
    .credits {
        margin-bottom: 30px !important;
        padding-bottom: 30px !important;
        position: relative;
    }
    
    /* Container pulsanti su mobile - assicura visibilità */
    .buttons-container {
        margin-bottom: 25px !important;
        margin-top: 15px !important;
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
        padding-bottom: 25px !important;
        position: relative;
        z-index: 10;
    }
    
    .buttons-container button {
        flex: 1 1 calc(50% - 4px) !important;
        min-width: calc(50% - 4px) !important;
        min-height: 48px !important; /* Aumentato per migliore visibilità */
        font-size: 12px !important;
        margin-bottom: 8px !important;
    }
    
    /* Credits su mobile - assicura visibilità */
    .credits {
        margin-bottom: 40px !important;
        padding-bottom: 40px !important;
        position: relative;
    }
    
    /* Result Area Mobile */
    .result {
        margin-left: 0;
        width: 100%;
        padding: 15px;
        overflow-x: auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
    }
    
    .image-container {
        display: inline-block;
        white-space: nowrap;
        line-height: 0;
        width: max-content;
        min-width: min-content;
        overflow: visible;
    }

    .preview-screen-wrapper {
        display: inline-block !important;
        vertical-align: top !important;
        position: relative !important;
        flex-shrink: 0;
        overflow: visible;
    }

    .preview-screen-wrapper canvas {
        display: block !important;
        position: absolute !important;
        max-width: none !important;
    }

    .image-container img {
        display: inline-block;
        vertical-align: top;
        margin: 0;
        padding: 0;
        max-width: 100vw; /* Limita alla larghezza viewport */
        height: auto;
    }
    
    /* Pulsante VIEW RESULT - visibile solo su mobile */
    .view-result-btn {
        display: block !important;
        width: 100% !important;
        margin-top: 10px !important;
        background-color: #007bff !important;
        color: white !important; /* Testo bianco per leggibilità */
        font-weight: bold !important;
    }
    
    .view-result-btn:hover {
        background-color: #0056b3 !important;
    }
    
    
    /* Credits Mobile */
    .credits {
        font-size: 9px;
        line-height: 1.5;
    }
}

/* ============================================
   MEDIA QUERIES - DESKTOP LARGE > 1400px
   ============================================ */
@media (min-width: 1401px) {
    .menu-container {
        width: 420px;
        overflow: hidden;
    }
    
    .menu-scrollable {
        width: 420px;
        height: 100%;
        max-height: calc(100vh - 50px);
        padding-bottom: 50px;
        overflow-y: auto;
        overflow-x: hidden;
        box-sizing: border-box;
    }
    
    .result {
        margin-left: 420px;
        width: calc(100% - 420px);
    }
    
    .howto {
        display: block;
        font-size: 10px;
    }
    
    .menu-header {
        height: 50px;
    }
    
    .container {
        margin-top: 50px;
        height: calc(100vh - 50px);
    }
}

/* ============================================
   UTILITIES
   ============================================ */
#signalFlow,
#layoutalign {
    margin-right: 10px;
}

/* VIEW RESULT nascosto di default su desktop, sarà mostrato solo su mobile */
.view-result-btn {
    display: none;
}

/* Upload Logo Section */
.upload-logo-row {
    display: flex;
    align-items: center;
    white-space: nowrap;
    width: 100%;
    margin: 4px 0;
    padding: 5px 6px;
    background-color: #fff;
    border-radius: 4px;
    border: 1px solid #ddd;
}

.upload-logo-label {
    font-weight: bold;
    font-size: 10px;
    color: black;
}

.upload-logo-actions {
    flex: 1;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-right: 10px;
    gap: 5px;
}

.upload-logo-choose {
    margin-left: 10px;
    background: #dc3545;
    padding: 3px 6px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 10px;
    color: white;
}

.upload-logo-submit {
    font-size: 8px;
    background: #007bff;
    color: white;
    border-radius: 8px;
    border: 1px solid black;
    padding: 3px 6px;
    font-weight: 800;
    cursor: pointer;
}

.menu-row input[type="range"] {
    flex: 0 0 120px;
    height: 24px;
}

.btn-secondary {
    width: 100%;
    min-height: 28px;
    font-size: 10px;
    font-weight: 800;
    background-color: #6c757d;
    color: white;
    border-radius: 6px;
    border: 1px solid #000;
    cursor: pointer;
    padding: 6px 10px;
}

.btn-secondary:hover {
    background-color: #5a6268;
}

.buttons-container .export-combined-row {
    flex: 1 1 100%;
    width: 100%;
    margin: 0;
}

.btn-export-video {
    background-color: #007bff !important;
    color: white !important;
    display: none;
}

.btn-export-video:hover {
    background-color: #0056b3 !important;
}

.export-mode-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.45);
    padding: 16px;
}

.export-mode-dialog {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
    padding: 20px 24px;
    max-width: 420px;
    width: 100%;
}

.export-mode-title {
    margin: 0 0 8px;
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 0.04em;
}

.export-mode-text {
    margin: 0 0 16px;
    font-size: 13px;
    line-height: 1.45;
    color: #333;
}

.export-mode-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.export-mode-actions .btn-secondary {
    width: 100%;
    text-align: center;
}

.export-mode-cancel {
    margin-top: 4px;
    background-color: #adb5bd !important;
}

.export-progress-dialog {
    text-align: center;
}

.export-progress-label {
    margin: 0 0 12px;
    font-size: 13px;
    line-height: 1.45;
    color: #333;
}

.export-progress-bar {
    width: 100%;
    height: 12px;
    border-radius: 6px;
    background: #e9ecef;
    overflow: hidden;
}

.export-progress-fill {
    width: 0%;
    height: 100%;
    border-radius: 6px;
    background: #0d6efd;
    transition: width 0.15s ease;
}

.export-progress-count {
    margin: 10px 0 0;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    color: #555;
    min-height: 16px;
}

.version-tag {
    font-weight: bold;
    color: #ff0000;
}

.image-container canvas {
    display: inline-block;
    margin: 0;
    padding: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    border-radius: 4px;
}

/* Miglioramenti Accessibilità */
button:focus,
input:focus,
select:focus {
    outline: 2px solid #0066cc;
    outline-offset: 2px;
}

/* Animazioni Smooth */
.menu-scrollable,
.result,
.menu-container {
    transition: transform 0.3s ease, margin-left 0.3s ease, width 0.3s ease;
}
