* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent; /* Elimina il riquadro di tap */
    -webkit-touch-callout: none; /* Disabilita il menu a comparsa su pressione prolungata (iOS) */
}

html, body {
    width: 100vw;
    height: 100dvh;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #1a1a1a;
    color: #fff;
    touch-action: manipulation;
    overscroll-behavior: none; /* Disabilita l'effetto rimbalzo/pull-to-refresh */
    -webkit-user-select: none;  /* Comportamento app: testo non selezionabile di default */
    user-select: none;
}

/* Permette la selezione solo nei campi dove l'utente deve digitare */
input, textarea {
    -webkit-user-select: auto;
    user-select: auto;
}


        
#canvas-container canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

/* ============================================================
   TOP BAR WITH BUTTONS
   ============================================================ */
#top-bar {
    position: fixed;
    top: max(10px, env(safe-area-inset-top));
    left: 0;
    right: 0;
    height: 40px;
    background: rgba(30, 30, 30, 0.95);
    border-bottom: 1px solid #444;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    padding: 4px 10px;
    box-sizing: border-box;
    z-index: 20;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
    gap: 4px;
}

#top-bar-left,
#top-bar-right,
#top-bar-left-tabs {
    display: flex;
    gap: 4px;
    align-items: center;
}

#top-bar-right {
    margin-left: auto;
}

.top-bar-btn {
    background: #2a2a2a;
    border: 1px solid #444;
    color: #888;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: bold;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.top-bar-btn:hover {
    background: #333;
    color: #fff;
}

.top-bar-btn.tab-btn.active {
    background: #1D9E75;
    border-color: #1D9E75;
    color: #fff;
}

/* ============================================================
   TOP BAR TABS LEFT (Digitize & Filters)
   ============================================================ */
#top-bar-tabs-left {
    position: fixed;
    top: 50px;
    left: max(10px, env(safe-area-inset-left));
    width: 165px;
    background: rgba(30, 30, 30, 0.95);
    border: 1px solid #444;
    border-radius: 8px;
    z-index: 19;
    max-height: calc(100dvh - 70px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px;
    box-sizing: border-box;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    display: none;
}

#top-bar-tabs-left.active {
    display: block;
}

.top-tab-content-left {
    display: none;
}

.top-tab-content-left.visible {
    display: block;
}

/* ============================================================
   TOP BAR TABS RIGHT (Sensor & Perf)
   ============================================================ */
#top-bar-tabs-content {
    position: fixed;
    top: 50px;
    right: 10px;
    background: rgba(30, 30, 30, 0.95);
    border: 1px solid #444;
    border-radius: 8px;
    z-index: 19;
    max-height: calc(100dvh - 70px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px;
    box-sizing: border-box;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    display: none;
}

#top-bar-tabs-content.active {
    display: block;
}

#top-bar-tabs-content .top-tab-content {
    display: none;
}

#top-bar-tabs-content .top-tab-content.visible {
    display: block;
}

/* ============================================================
   HIDE ORIGINAL PANELS IN LEFT SIDEBAR
   ============================================================ */
#ui #digitize-controls {
    display: none !important;
}

#ui #filter-section {
    display: none !important;
}

        /* UI Sinistra (Controlli Rilievo 3D) */
/* UI Sinistra (Controlli Rilievo 3D) */
#ui {
    position: absolute;
    top: max(45px, env(safe-area-inset-top));
    left: 10px;
    background: rgba(30, 30, 30, 0.95);
    padding: 8px; border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    z-index: 10;
    font-size: 11px;
    width: 170px;
    max-width: calc(100vw - 20px);

    /* CORREZIONE LANDSCAPE / IPHONE */
    max-height: calc(100dvh - max(20px, env(safe-area-inset-top) + 10px));
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;

    transition: all 0.2s ease-in-out;
    will-change: left, top;
}

.ui-hideable {
    max-height: calc(100dvh - 60px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.ui-hideable::-webkit-scrollbar { width: 4px; }
.ui-hideable::-webkit-scrollbar-thumb { background: #444; border-radius: 2px; }

#ui.dragging {
            transition: none !important;
        }
        #ui::-webkit-scrollbar { width: 4px; }
        #ui::-webkit-scrollbar-thumb { background: #444; border-radius: 2px; }

        #top-bar-tabs-left::-webkit-scrollbar { width: 4px; }
        #top-bar-tabs-left::-webkit-scrollbar-thumb { background: #444; border-radius: 2px; }

        #top-bar-tabs-content::-webkit-scrollbar { width: 4px; }
        #top-bar-tabs-content::-webkit-scrollbar-thumb { background: #444; border-radius: 2px; }

        #ui.collapsed .ui-hideable {
            display: none !important;
        }

        .ui-header {
            display: flex;
            align-items: center;
            gap: 6px;
            margin-bottom: 8px;
            border-bottom: 1px solid #444;
            padding-bottom: 6px;
        }

        .menu-container {
            position: relative;
        }

        .icon-btn {
            background: #2a2a2a;
            border: 1px solid #444;
            color: #1D9E75;
            border-radius: 4px;
            padding: 3px 7px;
            font-size: 14px;
            cursor: pointer;
            line-height: 1;
            margin-top: 0;
            width: auto;
            transition: background 0.2s, color 0.2s;
        }
        .icon-btn:hover { background: #333; color: #55ff55; }

        .dropdown-menu {
            display: none;
            position: absolute;
            top: 100%;
            left: 0;
            margin-top: 4px;
            background: #222;
            border: 1px solid #444;
            border-radius: 6px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.6);
            z-index: 9999;
            min-width: 130px;
            overflow: hidden;
        }

        .dropdown-menu.show {
            display: block;
        }

        .menu-item {
            padding: 7px 10px;
            font-size: 10px;
            font-weight: bold;
            color: #ddd;
            cursor: pointer;
            border-bottom: 1px solid #333;
            transition: background 0.2s, color 0.2s;
        }
        .menu-item:last-child { border-bottom: none; }
        .menu-item:hover { background: #1D9E75; color: #fff; }

/* CONTENITORE PANNELLI IN ALTO A DESTRA */
#top-right-container {
    position: absolute;
    top: 52px;
    right: 6px;
    width: 120px;
    background: rgba(30, 30, 30, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid #444; /* Cambiato da #1D9E75 a grigio #444 */
    border-radius: 8px;
    padding: 6px;
    z-index: 1001;
    box-shadow: 0 4px 15px rgba(0,0,0,0.6);
    display: none;
}

.dropdown-menu {
    display: none;
    position: fixed;
    z-index: 99999;
    background: #222;
    border: 1px solid #444;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.6);
    width: max-content;       /* Si adatta al testo interno */
    min-width: 140px;         /* Larghezza minima compatta */
    max-width: 190px;         /* Limite massimo di larghezza */
    padding: 4px 0;
    overflow: hidden;
}

.dropdown-menu .menu-item {
    padding: 8px 12px;
    font-size: 12px;
    color: #fff;
    cursor: pointer;
    white-space: nowrap;      /* Mantiene il testo su una sola riga */
}

.dropdown-menu .menu-item:hover {
    background-color: #333;
}


/* PULSANTI SCHEDE NEL PANNELLO IN ALTO A DESTRA */
.tab-btn {
    background: #2a2a2a;
    border: 1px solid #444;
    color: #888;
    padding: 2px 6px;
    font-size: 9px;
    font-weight: bold;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    background: #333;
    color: #fff;
}

.tab-btn.active {
    background: #1D9E75;
    border-color: #1D9E75;
    color: #fff;
}
/* ========== CORRECTED: Tab buttons TOP-RIGHT PANEL ========== */
.top-tab-btn {
    flex: 1;
        text-align: center;
        background: #2a2a2a;
    border: 1px solid #444;
    color: #888;
    padding: 4px 8px;
    font-size: 10px;
    font-weight: bold;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin: 0 2px;
    white-space: nowrap;
}

.top-tab-btn:hover {
    background: #333;
    color: #fff;
}

.top-tab-btn.active {
    background: #1D9E75;
    border-color: #1D9E75;
    color: #fff;
}
.top-tab-content {
    display: none;
}
.top-tab-content.visible {
    display: block;
}
.top-right-tabs {
    display: flex;
    gap: 4px;
    flex: 0 0 70%;
}
.top-right-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(30, 30, 30, 0.95);
    padding: 2px 2px;
    border-radius: 6px 6px 0 0;
    border: 1px solid #444;
    border-bottom: none;
    gap: 2px;
}
/* Stile handle a pallini ridimensionato */
#top-right-container .drag-handle {
    cursor: grab;
    padding: 0 1px; /* Padding ridotto da 4px a 1px */
    color: #aaa;
    font-weight: bold;
    user-select: none;
    touch-action: none;
    font-size: 13px; /* Ridotto da 17px per risparmiare spazio */
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 1;
}

#top-right-container .drag-handle:active {
    cursor: grabbing;
    color: #1D9E75;
}

/* Compattamento dei pulsanti e schede all'interno dell'header */
.top-right-header button,
.top-right-header .top-tab-btn {
    padding: 2px 3px !important;
    margin: 0 !important;
    min-width: 0 !important;
}

/* Gestione visibilità contenuto quando compresso */
#top-right-container.collapsed #top-right-content {
    display: none !important;
}

#top-right-container.collapsed .top-right-header {
    border-radius: 6px;
    border-bottom: 1px solid #444;
}


#declination-ui, #sensor-ui, #polyline-metrics-ui, #perf-controls-ui {
    pointer-events: auto;
    background: transparent;
    padding: 2px;
    font-size: 10px;
    width: 100%;
    border: none; /* Rimosso il bordo interno verde */
    box-shadow: none; /* Rimosso l'ombra interna duplicata */
}

/* Ingrandimento 150% per i checkbox */
#declination-ui input[type="checkbox"],
#sensor-ui input[type="checkbox"] {
    transform: scale(1.5);
    transform-origin: left center;
    margin-right: 6px;
    cursor: pointer;
}

/* Spostamento testo a sinistra e allineamento compatto */
#declination-ui label,
#sensor-ui label {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding-left: 0;
    margin-left: -2px;
    font-size: 10px;
    white-space: nowrap;
}

/* Ottimizzazione griglia campi specifici per sensor-ui (es. decl°) */
#sensor-ui .field-group {
    grid-template-columns: auto 1fr;
    gap: 3px;
}

#sensor-ui .field-group label {
    font-size: 9px;
}

#sensor-ui .field-group input[type="number"] {
    padding: 2px 3px;
    font-size: 10px;
}

        .title { font-weight: bold; font-size: 11px; color: #1D9E75; flex-grow: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
        .info { margin: 3px 0; color: #ccc; }
        .metric-highlight { color: #55ff55; font-weight: bold; }

.field-group {
    display: grid;
    grid-template-columns: 82px 1fr; /* Ridotto per dare massima larghezza all'input */
    align-items: center;
    margin: 5px 0;
    gap: 4px;
    width: 100%;
}

.field-group label {
    color: #aaa;
    font-size: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.field-group input,
.field-group select {
    width: 100%;
    min-width: 0;
    background: #2a2a2a;
    border: 1px solid #444;
    color: #fff;
    padding: 3px 5px;
    border-radius: 4px;
    font-size: 10px;
    box-sizing: border-box;
}
        
        .filter-section { margin-top: 8px; border-top: 1px solid #444; padding-top: 6px; }
        .filter-title { font-weight: bold; color: #1D9E75; font-size: 11px; margin-bottom: 4px; }
        .filter-category { font-weight: bold; color: #888; font-size: 10px; margin-top: 4px; margin-bottom: 2px; }
        .filter-list { max-height: 65px; overflow-y: auto; background: #222; border: 1px solid #333; border-radius: 4px; padding: 3px 5px; margin-bottom: 4px; }
        .filter-item { display: flex; align-items: center; font-size: 10px; color: #ddd; margin-bottom: 2px; cursor: pointer; }
        .filter-item input { margin-right: 5px; cursor: pointer; accent-color: #1D9E75; }

        #status { margin-top: 6px; font-weight: bold; color: #e0a800; word-break: break-all; font-size: 10px; }
        
        button {
            background: #1D9E75; color: white; border: none; padding: 6px 10px; border-radius: 4px; cursor: pointer; width: 100%; margin-top: 5px; font-weight: bold; font-size: 10px;
        }
        button:hover { background: #0F6E56; }
        button.start-btn { background: #28a745; }
        button.stop-btn { background: #dc3545; }
        button.sensor-btn { background: #28a745; font-size: 9px; padding: 4px 2px; margin-top: 4px; }

        /* CONTROLLI IN BASSO A SINISTRA */
#bottom-left-controls {
    position: fixed !important;
    bottom: 0px !important;
    left: 10px !important;
    z-index: 99999 !important;
    display: flex;
    gap: 3px;
    background: rgba(25, 25, 25, 0.95);
    padding: 3px 4px;
    border-radius: 6px;
    border: 1px solid #1D9E75;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.7);
}

.mini-btn {
    background: #2a2a2a !important;
    border: 1px solid #444 !important;
    color: #fff !important;
    padding: 3px 5px !important;
    border-radius: 4px;
    cursor: pointer;
    font-size: 8.5px;
    font-weight: bold;
    width: auto !important;
    margin-top: 0 !important;
    transition: background 0.2s, border-color 0.2s;
    box-shadow: 0 2px 6px rgba(0,0,0,0.4);
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
}
        .mini-btn:hover {
            background: #383838 !important;
            border-color: #1D9E75 !important;
        }

        /* POP-UP INFORMAZIONI FEATURE SELEZIONATA */
        #feature-info-popup {
            position: fixed;
            bottom: 15px;
            right: 10px;
            width: 250px;
            max-height: 320px;
            background: rgba(25, 25, 25, 0.95);
            border: 1px solid #1D9E75;
            border-radius: 8px;
            padding: 10px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.7);
            z-index: 99999;
            font-size: 11px;
            overflow-y: auto;
            color: #ddd;
        }

        #feature-info-popup::-webkit-scrollbar { width: 4px; }
        #feature-info-popup::-webkit-scrollbar-thumb { background: #1D9E75; border-radius: 2px; }

        .popup-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-weight: bold;
            color: #1D9E75;
            border-bottom: 1px solid #444;
            padding-bottom: 4px;
            margin-bottom: 6px;
        }

        .popup-close-btn {
            background: transparent !important;
            border: none !important;
            color: #aaa !important;
            font-size: 12px !important;
            cursor: pointer;
            padding: 0 4px !important;
            width: auto !important;
            margin-top: 0 !important;
        }
        .popup-close-btn:hover { color: #fff !important; }

        .popup-info-row {
            margin: 4px 0;
            display: flex;
            justify-content: space-between;
            border-bottom: 1px dashed #333;
            padding-bottom: 2px;
        }
        .popup-info-label { color: #888; font-size: 10px; }
        .popup-info-value { font-weight: bold; color: #55ff55; text-align: right; word-break: break-all; font-size: 10px; }

        /* POP-UP CESTINO / ELIMINA */
        #feature-delete-popup {
            position: fixed;
            bottom: 15px;
            right: 270px;
            width: 44px;
            height: 44px;
            background: rgba(167, 40, 40, 0.95);
            border: 1px solid #ff4444;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 20px;
            cursor: pointer;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.7);
            z-index: 99999;
            transition: transform 0.2s, background 0.2s;
        }
        #feature-delete-popup:hover {
            background: rgba(220, 53, 53, 1);
            transform: scale(1.1);
        }

        /* STEREONET WINDOW */
        #stereonet-window {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: #1a1a1a;
            z-index: 999999;
            flex-direction: column;
            overflow: hidden;
            pointer-events: auto !important;
        }

        #stereonet-window.show {
            display: flex; !important;
            pointer-events: auto !important;
        }

        #stereonet-header {
            background: #222;
            border-bottom: 1px solid #444;
            padding: 12px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-shrink: 0;
        }

        #stereonet-title {
            font-size: 14px;
            font-weight: 600;
            color: #1D9E75;
        }

        #stereonet-close-btn {
            background: #2a2a2a;
            border: 1px solid #444;
            color: #fff;
            padding: 6px 12px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 12px;
        }

        #stereonet-close-btn:active {
            background: #333;
        }

        #stereonet-container {
            display: flex;
            flex: 1;
            overflow: hidden;
            gap: 10px;
            padding: 10px;
        }

        #stereonet-canvas-wrapper {
            flex: 1;
            display: flex;
            justify-content: center;
            align-items: center;
            background: #1a1a1a;
            border-radius: 8px;
            position: relative;
        }

        #stereonet-canvas {
            display: block;
            max-width: 95%;
            max-height: 95%;
        }

        #stereonet-controls {
            width: 200px;
            background: rgba(30, 30, 30, 0.95);
            border: 1px solid #444;
            border-radius: 8px;
            padding: 10px;
            overflow-y: auto;
            display: flex;
            flex-direction: column;
            gap: 8px;
        }
#stereonet-controls.collapsed {
    display: none !important;
}
        .stereo-section {
            border-bottom: 1px solid #333;
            padding-bottom: 8px;
            margin-bottom: 8px;
        }

        .stereo-section:last-child {
            border-bottom: none;
            margin-bottom: 0;
        }

        .stereo-section-title {
            font-size: 10px;
            font-weight: 700;
            color: #1D9E75;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            margin-bottom: 6px;
        }

        .stereo-toggle {
            display: flex;
            align-items: center;
            gap: 6px;
            font-size: 11px;
            color: #ccc;
            margin: 4px 0;
            cursor: pointer;
        }

        .stereo-toggle input {
            cursor: pointer;
            accent-color: #1D9E75;
        }

        .stereo-filter-item {
            display: flex;
            align-items: center;
            gap: 6px;
            font-size: 10px;
            color: #ccc;
            margin: 3px 0;
            cursor: pointer;
        }

        .stereo-filter-item input {
            cursor: pointer;
            accent-color: #1D9E75;
        }

        .stereo-color-dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            flex-shrink: 0;
            border: 1px solid #555;
        }

        .stereo-filter-label {
            flex: 1;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .stereo-count {
            font-size: 9px;
            color: #666;
            margin-left: 2px;
        }

        /* Modal Dialog CSS */
        #modal-overlay {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.7);
            z-index: 10000;
            justify-content: center;
            align-items: center;
        }

        #modal-overlay.show {
            display: flex;
        }

        #modal-dialog {
            background: #222;
            border: 1px solid #444;
            border-radius: 12px;
            padding: 24px;
            max-width: 280px;
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.8);
            text-align: center;
        }

        #modal-title {
            font-size: 16px;
            font-weight: 600;
            margin-bottom: 16px;
            color: #fff;
        }

        #modal-message {
            font-size: 14px;
            margin-bottom: 20px;
            color: #ccc;
            line-height: 1.4;
        }

        #modal-buttons {
            display: flex;
            gap: 12px;
            justify-content: center;
        }

        .modal-btn {
            flex: 1;
            padding: 10px 16px;
            border: 1px solid #444;
            border-radius: 6px;
            font-size: 13px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.2s;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        #modal-btn-yes {
            background: #1D9E75;
            color: #fff;
            border-color: #1D9E75;
        }

        #modal-btn-yes:active {
            background: #158862;
            transform: scale(0.98);
        }

        #modal-btn-no {
            background: #2a2a2a;
            color: #ccc;
            border-color: #444;
        }

        #modal-btn-no:active {
            background: #333;
            transform: scale(0.98);
        }
/* NOTE MODE PANEL */
        #note-tabs { display: flex; gap: 4px; margin-bottom: 6px; }

        .note-tab {
            flex: 1;
            background: #2a2a2a !important;
            border: 1px solid #444 !important;
            color: #aaa !important;
            padding: 6px 4px !important;
            font-size: 13px;
            border-radius: 4px;
            cursor: pointer;
            margin-top: 0 !important;
        }
        .note-tab.active {
            background: #1D9E75 !important;
            border-color: #1D9E75 !important;
            color: #fff !important;
        }

        .note-panel textarea {
            width: 100%;
            background: #2a2a2a;
            border: 1px solid #444;
            color: #fff;
            padding: 8px;
            border-radius: 4px;
            font-size: 12px;
            font-family: inherit;
            resize: vertical;
            box-sizing: border-box;
        }

        .note-placeholder {
            text-align: center;
            color: #666;
            font-size: 11px;
            padding: 24px 10px;
            background: #1a1a1a;
            border: 1px dashed #444;
            border-radius: 6px;
        }
#note-photo-preview-wrapper button {
            margin-top: 0;
        }
        .note-photo-full {
            width: 100%;
            border-radius: 6px;
            margin-top: 4px;
            display: block;
        }
        .note-photo-missing {
            text-align: center;
            color: #888;
            font-size: 10px;
            padding: 16px 8px;
            background: #1a1a1a;
            border: 1px dashed #555;
            border-radius: 6px;
        }
#note-photo-caption {
            width: 100%;
            background: #2a2a2a;
            border: 1px solid #444;
            color: #fff;
            padding: 8px;
            border-radius: 4px;
            font-size: 12px;
            font-family: inherit;
            resize: vertical;
            box-sizing: border-box;
        }
#sketch-window {
            display: none;
            position: fixed;
            top: 0; left: 0; right: 0; bottom: 0;
            background: #1a1a1a;
            z-index: 6000;
            flex-direction: column;
            overflow: hidden;
        }
        #sketch-window.show { display: flex; }

        #sketch-header {
            background: #222;
            border-bottom: 1px solid #444;
            padding: 12px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-shrink: 0;
        }
        #sketch-title { font-size: 14px; font-weight: 600; color: #1D9E75; }
        #sketch-close-btn {
            background: #2a2a2a; border: 1px solid #444; color: #fff;
            padding: 6px 12px; border-radius: 4px; cursor: pointer; font-size: 12px;
        }

        #sketch-bg-row { display: flex; gap: 6px; padding: 8px 12px; flex-shrink: 0; }
        .sketch-bg-btn {
            background: #2a2a2a !important; border: 1px solid #444 !important; color: #aaa !important;
            padding: 6px 10px !important; font-size: 11px; border-radius: 4px; cursor: pointer; margin-top: 0 !important;
        }
        .sketch-bg-btn.active { background: #1D9E75 !important; border-color: #1D9E75 !important; color: #fff !important; }

        #sketch-canvas-wrapper {
            flex: 1;
            display: flex;
            align-items: center;
            justify-content: center;
            overflow: hidden;
            padding: 6px;
            min-height: 0;
        }
#sketch-canvas-stack {
            position: relative;
            line-height: 0;
        }
        #sketch-bg-canvas, #sketch-draw-canvas {
            display: block;
            border-radius: 6px;
            touch-action: none;
        }
        #sketch-draw-canvas {
            position: absolute;
            top: 0; left: 0;
        }

        #sketch-toolbar {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 8px 12px;
            flex-shrink: 0;
            flex-wrap: wrap;
        }
        #sketch-color-input {
            width: 34px; height: 30px; padding: 0; border: 1px solid #444; border-radius: 4px; background: none; cursor: pointer;
        }
        #sketch-thickness-group { display: flex; align-items: center; gap: 4px; flex: 1; min-width: 100px; }
        #sketch-thickness-group label { font-size: 10px; color: #aaa; white-space: nowrap; }
        #sketch-thickness-input { flex: 1; accent-color: #1D9E75; }

        #sketch-toolbar button {
            width: auto !important; margin-top: 0 !important;
            background: #2a2a2a !important; border: 1px solid #444 !important; color: #fff !important;
            padding: 6px 10px !important; font-size: 14px; border-radius: 4px; cursor: pointer;
        }
        #sketch-eraser-btn.active { background: #1D9E75 !important; border-color: #1D9E75 !important; }

        #sketch-caption {
            margin: 0 12px 8px 12px;
            background: #2a2a2a; border: 1px solid #444; color: #fff;
            padding: 8px; border-radius: 4px; font-size: 12px; font-family: inherit;
            resize: vertical; box-sizing: border-box; flex-shrink: 0;
        }
        #sketch-save-btn { margin: 0 12px 12px 12px; width: calc(100% - 24px); flex-shrink: 0; }




/* ============================================================
   TEMA CHIARO (LIGHT THEME OVERRIDES - ALTO CONTRASTO NERO PURO)
   ============================================================ */

/* SFONDI E TESTI GENERALI */
body.light-theme {
    background: #eef1f5 !important;
    color: #000000 !important;
}
/* ============================================================
   TOP BAR & TAB PANELS (MATITA / OCCHIO) - TEMA CHIARO
   ============================================================ */

/* Barra superiore in tema chiaro */
body.light-theme #top-bar {
    background: rgba(255, 255, 255, 0.98) !important;
    border-bottom: 1px solid #cbd5e1 !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
}

/* Pulsanti generali della top bar */
body.light-theme .top-bar-btn {
    background: #ffffff !important;
    border-color: #cbd5e1 !important;
    color: #334155 !important;
}

body.light-theme .top-bar-btn:hover {
    background: #f1f5f9 !important;
    color: #000000 !important;
}

/* Stato attivo dei pulsanti tab nella top bar */
body.light-theme .top-bar-btn.active,
body.light-theme .top-bar-btn.tab-btn.active {
    background: #1D9E75 !important;
    border-color: #1D9E75 !important;
    color: #ffffff !important;
}

/* Pannelli a comparsa dei tab di sinistra (Matita / Occhio) e destra */
body.light-theme #top-bar-tabs-left,
body.light-theme #top-bar-tabs-content {
    background: rgba(255, 255, 255, 0.98) !important;
    border: 1px solid #cbd5e1 !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15) !important;
    color: #000000 !important;
}

/* Testi ed etichette all'interno dei pannelli tab */
body.light-theme #top-bar-tabs-left,
body.light-theme #top-bar-tabs-content,
body.light-theme #top-bar-tabs-left label,
body.light-theme #top-bar-tabs-content label,
body.light-theme #top-bar-tabs-left span,
body.light-theme #top-bar-tabs-content span,
body.light-theme #top-bar-tabs-left div {
    color: #000000 !important;
}

/* Scrollbar dei pannelli a comparsa in tema chiaro */
body.light-theme #top-bar-tabs-left::-webkit-scrollbar-thumb,
body.light-theme #top-bar-tabs-content::-webkit-scrollbar-thumb {
    background: #94a3b8 !important;
}
/* PANNELLO PRINCIPALE SINISTRA (#ui) */
body.light-theme #ui {
    background: rgba(255, 255, 255, 0.98) !important;
    border: 1px solid #cbd5e1 !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15) !important;
    color: #000000 !important;
}
body.light-theme .top-bar-btn {
    background: #f0f0f0;
    border-color: #ddd;
    color: #555;
}

body.light-theme .top-bar-btn:hover {
    background: #e0e0e0;
    color: #000;
}

body.light-theme #input-crs {
    background: #f0f0f0;
    border-color: #ddd;
    color: #555;
}
body.light-theme .ui-header {
    border-bottom-color: #cbd5e1 !important;
}

body.light-theme .ui-hideable::-webkit-scrollbar-thumb {
    background: #94a3b8 !important;
}

/* BOTTONI CON ICONA E DROPDOWN */
body.light-theme .icon-btn {
    background: #ffffff !important;
    border-color: #94a3b8 !important;
    color: #0f6e56 !important;
    font-weight: bold !important;
}

body.light-theme .icon-btn:hover {
    background: #e2e8f0 !important;
    color: #054a38 !important;
}

body.light-theme .dropdown-menu {
    background: #ffffff !important;
    border-color: #94a3b8 !important;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2) !important;
}

body.light-theme .menu-item {
    color: #000000 !important;
    border-bottom-color: #e2e8f0 !important;
    font-weight: bold !important;
}

body.light-theme .menu-item:hover {
    background: #1D9E75 !important;
    color: #ffffff !important;
}

/* CONTENITORE IN ALTO A DESTRA E DRAG HANDLES */
body.light-theme .top-right-header {
    background: rgba(255, 255, 255, 0.98) !important;
    border-color: #cbd5e1 !important;
}

body.light-theme #top-right-container .drag-handle,
body.light-theme .drag-handle {
    color: #000000 !important;
}
/* PULSANTI SCHEDE TEMA CHIARO */
body.light-theme .top-tab-btn {
    background: #ffffff !important;
    border-color: #94a3b8 !important;
    color: #000000 !important;
}

body.light-theme .top-tab-btn:hover {
    background: #e2e8f0 !important;
    color: #0f6e56 !important;
}

body.light-theme .top-tab-btn.active {
    background: #1D9E75 !important;
    border-color: #1D9E75 !important;
    color: #ffffff !important;
}
body.light-theme #declination-ui,
body.light-theme #sensor-ui,
body.light-theme #polyline-metrics-ui,
body.light-theme #perf-controls-ui {
    background: rgba(255, 255, 255, 0.98) !important;
    border-color: #0f6e56 !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12) !important;
    color: #000000 !important;
}

/* CAMPI DI INPUT, SELECT, ETICHETTE E TESTI */
body.light-theme .field-group label,
body.light-theme .info,
body.light-theme #declination-ui label,
body.light-theme #sensor-ui label,
body.light-theme #sensor-data-box,
body.light-theme #declination-status {
    color: #000000 !important;
    font-weight: 600 !important;
}

body.light-theme .field-group input,
body.light-theme .field-group select,
body.light-theme textarea,
body.light-theme input[type="text"],
body.light-theme input[type="number"],
body.light-theme #input-crs {
    background: #ffffff !important;
    border-color: #94a3b8 !important;
    color: #000000 !important;
    font-weight: bold !important;
}

body.light-theme .metric-highlight {
    color: #0f6e56 !important;
    font-weight: bold !important;
}

body.light-theme .filter-section {
    border-top-color: #cbd5e1 !important;
}

body.light-theme .filter-title {
    color: #0f6e56 !important;
}

body.light-theme .filter-category {
    color: #000000 !important;
    font-weight: bold !important;
}

body.light-theme .filter-list {
    background: #f1f5f9 !important;
    border-color: #94a3b8 !important;
}

body.light-theme .filter-item {
    color: #000000 !important;
    font-weight: 600 !important;
}

body.light-theme #status {
    color: #92400e !important;
    font-weight: bold !important;
}

/* CONTROLLI IN BASSO A SINISTRA E PULSANTI MINI */
body.light-theme #bottom-left-controls {
    background: rgba(255, 255, 255, 0.98) !important;
    border-color: #0f6e56 !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15) !important;
}

body.light-theme .mini-btn {
    background: #ffffff !important;
    border-color: #94a3b8 !important;
    color: #000000 !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08) !important;
}

body.light-theme .mini-btn:hover {
    background: #e2e8f0 !important;
    border-color: #0f6e56 !important;
}

/* POP-UP FEATURE INFO */
body.light-theme #feature-info-popup {
    background: rgba(255, 255, 255, 0.98) !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2) !important;
    color: #000000 !important;
    border-color: #0f6e56 !important;
}

body.light-theme .popup-header {
    border-bottom-color: #cbd5e1 !important;
    color: #0f6e56 !important;
}

body.light-theme .popup-close-btn {
    color: #000000 !important;
}

body.light-theme .popup-close-btn:hover {
    color: #dc2626 !important;
}

body.light-theme .popup-info-row {
    border-bottom-color: #cbd5e1 !important;
}

body.light-theme .popup-info-label {
    color: #000000 !important;
    font-weight: 600 !important;
}

body.light-theme .popup-info-value {
    color: #0f6e56 !important;
    font-weight: bold !important;
}

/* MODALI E FINESTRE DI DIALOGO */
body.light-theme #modal-dialog {
    background: #ffffff !important;
    border-color: #94a3b8 !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2) !important;
}

body.light-theme #modal-title,
body.light-theme #modal-message {
    color: #000000 !important;
}

body.light-theme #modal-btn-no {
    background: #e2e8f0 !important;
    color: #000000 !important;
    border-color: #94a3b8 !important;
}

/* PANNELLO NOTE */
body.light-theme .note-tab {
    background: #e2e8f0 !important;
    border-color: #94a3b8 !important;
    color: #000000 !important;
    font-weight: bold !important;
}

body.light-theme .note-placeholder,
body.light-theme .note-photo-missing {
    background: #ffffff !important;
    border-color: #94a3b8 !important;
    color: #000000 !important;
}

/* FINESTRA STEREONET */
body.light-theme #stereonet-window,
body.light-theme #stereonet-canvas-wrapper {
    background: #eef1f5 !important;
}

body.light-theme #stereonet-header {
    background: #ffffff !important;
    border-bottom-color: #cbd5e1 !important;
}

body.light-theme #stereonet-title,
body.light-theme .stereo-section-title {
    color: #0f6e56 !important;
}

body.light-theme #stereonet-close-btn {
    background: #ffffff !important;
    border-color: #94a3b8 !important;
    color: #000000 !important;
    font-weight: bold !important;
}

body.light-theme #stereonet-controls {
    background: rgba(255, 255, 255, 0.98) !important;
    border-color: #94a3b8 !important;
}

body.light-theme .stereo-section {
    border-bottom-color: #cbd5e1 !important;
}

body.light-theme .stereo-toggle,
body.light-theme .stereo-filter-item {
    color: #000000 !important;
    font-weight: 600 !important;
}

/* FINESTRA SKETCH */
body.light-theme #sketch-window {
    background: #eef1f5 !important;
}

body.light-theme #sketch-header {
    background: #ffffff !important;
    border-bottom-color: #cbd5e1 !important;
}

body.light-theme #sketch-title {
    color: #0f6e56 !important;
}

body.light-theme #sketch-close-btn,
body.light-theme .sketch-bg-btn,
body.light-theme #sketch-toolbar button {
    background: #ffffff !important;
    border-color: #94a3b8 !important;
    color: #000000 !important;
    font-weight: bold !important;
}

body.light-theme #sketch-caption {
    background: #ffffff !important;
    border-color: #94a3b8 !important;
    color: #000000 !important;
}

body.light-theme #sketch-thickness-group label {
    color: #000000 !important;
    font-weight: bold !important;
}

/* MENU ROTAZIONE MODELLO (IN BASSO) */
body.light-theme #rotate-model-menu {
    background: #ffffff !important;
    border-top-color: #cbd5e1 !important;
    color: #000000 !important;
}

body.light-theme #rotate-model-menu button,
body.light-theme #rotate-model-menu span {
    color: #000000 !important;
}

body.light-theme #rotate-num-input {
    background: #ffffff !important;
    color: #000000 !important;
    border-color: #94a3b8 !important;
}

/* CONTENITORI DINAMICI & INLINE OVERRIDES */
body.light-theme #manual-orient-inputs,
body.light-theme #note-mode-inputs,
body.light-theme #custom-fields-container,
body.light-theme .custom-field-row {
    background: #f1f5f9 !important; /* 👈 Sfondo chiaro per il contenitore dei campi personalizzati */
    border: 1px solid #cbd5e1 !important;
    color: #000000 !important;
}

body.light-theme button[onclick*="addCustomFieldInput"] {
    background: #ffffff !important;
    color: #000000 !important;
    border-color: #94a3b8 !important;
    font-weight: bold !important;
}

body.light-theme #custom-fields-container input,
body.light-theme #custom-fields-container select,
body.light-theme #custom-fields-container label,
body.light-theme #custom-fields-container span {
    background: #ffffff !important;
    color: #000000 !important;
    border-color: #94a3b8 !important;
}

/* Garantisce lo scorrimento orizzontale su iPhone se i pulsanti superano lo schermo */
#bottom-left-controls {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    max-width: calc(100vw - 20px);
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
}

/* ==========================================================================
   POPUP CLIPPING PLANES
   ========================================================================== */

/* Garantisce che padding e bordi non facciano sbordare i contenuti */
#clipping-ui, #clipping-ui * {
    box-sizing: border-box;
}

#clipping-ui {
    position: fixed;
    bottom: calc(55px + env(safe-area-inset-bottom));
    left: 10px;
    background: #1e1e1e;
    border: 1px solid #008744;
    border-radius: 8px;
    padding: 8px 12px;
    z-index: 99999;
    pointer-events: auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 12px;
    width: 165px;
    transition: background 0.3s, color 0.3s, border-color 0.3s;
}

/* Allineamento compatto delle righe */
#clipping-ui .field-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

/* Input numerici (misura e rientro ottimizzati) */
#clipping-ui input {
    width: 58px;
    background: #222;
    color: #00ffcc;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 2px 4px;
    text-align: right;
    font-family: monospace;
    font-size: 12px;
}

/* --------------------------------------------------------------------------
   SUPPORTO TEMA CHIARO (Light Theme)
   -------------------------------------------------------------------------- */
body.light-theme #clipping-ui,
.light-theme #clipping-ui {
    background: #ffffff;
    border-color: #008744;
    color: #111111;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
}

body.light-theme #clipping-ui input,
.light-theme #clipping-ui input {
    background: #f0f0f0;
    color: #006633;
    border: 1px solid #ccc;
}

body.light-theme #clipping-ui .popup-close-btn,
.light-theme #clipping-ui .popup-close-btn {
    color: #666;
}

body.light-theme #clipping-ui .popup-close-btn:hover,
.light-theme #clipping-ui .popup-close-btn:hover {
    color: #000;
}





#btn-gps-toggle:not(.pressed) {
    background-color: #2a2a2a !important;
    color: #aaa !important;
}

body.light-theme #btn-gps-toggle:not(.pressed) {
    background-color: #ffffff !important;
    color: #334155 !important;
    border-color: #cbd5e1 !important;
}

body.light-theme #btn-gps-toggle:not(.pressed):hover {
    background-color: #e2e8f0 !important;
    color: #000000 !important;
}

#btn-gps-toggle.pressed {
    background-color: #1D9E75 !important;
    color: #ffffff !important;
    border-color: #1D9E75 !important;
}
/* Sposa il menù clipping in alto quando la tastiera si apre / un input è a fuoco */
#clipping-ui:focus-within {
    bottom: auto !important;
    top: max(60px, env(safe-area-inset-top) + 50px) !important;
    transition: top 0.2s ease-in-out;
}

/* ==========================================
   STEREONET ADAPTIVE FULLSCREEN & CONTROLS FIX
   ========================================== */

#stereonet-window {
  position: absolute !important;
  z-index: 999999 !important;
  background-color: rgba(20, 20, 20, 0.95) !important;
  border: 1px solid rgba(255, 255, 255, 0.2) !important;
  border-radius: 8px !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6) !important;
  box-sizing: border-box !important;
  display: none;
  flex-direction: column !important;
  overflow: hidden !important;
}

/* Gestione dei controlli: abilita lo scroll se il contenuto supera l'altezza */
#stereonet-controls {
  overflow-y: auto !important;
  max-height: 100% !important;
  padding: 10px !important;
  box-sizing: border-box !important;
}

#stereonet-container {
  display: flex !important;
  flex: 1 1 auto !important;
  min-height: 0 !important;
  width: 100% !important;
  height: 100% !important;
}

#stereonet-canvas-wrapper {
  flex: 1 1 auto !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  min-width: 0 !important;
  min-height: 0 !important;
}

#stereonet-canvas {
  width: 100% !important;
  height: 100% !important;
  object-fit: contain !important;
}

/* 1. LAYOUT PORTRAIT (Verticale - Layout a colonna) */
@media screen and (orientation: portrait) {
  #stereonet-window {
    top: 2vh !important;
    bottom: 2vh !important;
    left: 2vw !important;
    right: 2vw !important;
    width: 96vw !important;
    height: 96vh !important;
  }
  
  #stereonet-container {
    flex-direction: column !important;
  }
  
  #stereonet-controls {
    width: 100% !important;
    max-height: 35vh !important;
  }
}

/* 2. LAYOUT LANDSCAPE (Orizzontale - Massimizzato + Controlli affiancati a destra) */
@media screen and (orientation: landscape) {
  #stereonet-window {
    top: 2vh !important;
    bottom: 2vh !important;
    left: 2vw !important;
    right: 2vw !important;
    width: 96vw !important;
    height: 96vh !important;
  }
  
  /* Dispone Canvas e Controlli affiancati */
  #stereonet-container {
    flex-direction: row !important;
  }
  
  #stereonet-canvas-wrapper {
    flex: 1 1 65% !important; /* Il grafico occupa il 65% dello spazio disponibile */
  }
  
  #stereonet-controls {
    flex: 0 0 35% !important; /* I controlli occupano il 35% sulla destra */
    border-left: 1px solid rgba(255, 255, 255, 0.1) !important;
  }
}
/* Corregge il clipping della colorbar e attiva lo scroll verticale dei controlli */
#stereonet-canvas-wrapper {
  padding-bottom: 35px !important; /* Spazio extra in basso per le etichette delle percentuali */
  overflow: visible !important;
}

#stereonet-controls {
  max-height: 45vh !important;
  overflow-y: auto !important; /* Abilita lo scroll se i controlli superano la vista */
  padding-bottom: 15px !important;
}
/* Espansione della colonna controlli in modalità Landscape */
@media screen and (orientation: landscape) {
  #stereonet-controls {
    max-height: 85vh !important; /* Aumenta l'altezza visibile fino all'85% della schermata */
    height: 100% !important;
    overflow-y: auto !important; /* Mantiene lo scroll attivo se necessario */
  }
}


/* ==========================================
   PANNELLO OFFSET Z (LARGHEZZA COMPATTA & MINIMIZZABILE)
   ========================================== */

.alt-slider-panel,
#alt-slider-panel {
  position: fixed;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 9999;
  
  width: 55px !important;
  min-width: 55px !important;
  max-width: 52px !important;
  box-sizing: border-box !important;
  
  background: rgba(20, 20, 20, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  
  padding: 6px 4px !important;
  display: flex;
  flex-direction: column !important;
  align-items: center !important;
  gap: 4px;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  transition: all 0.25s ease-in-out;
}
/* STATO MINIMIZZATO: Larghezza ridotta a 20px */
.alt-slider-panel.collapsed,
#alt-slider-panel.collapsed {
  width: 20px !important;
  min-width: 20px !important;
  max-width: 20px !important;
  padding: 4px 1px !important;
  border-radius: 8px;
}
.alt-slider-panel.active,
#alt-slider-panel.active {
  display: flex !important;
}
.alt-label-title {
  font-size: 8px !important;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #aaaaaa;
  text-align: center;
  white-space: nowrap;
}

.slider-wrapper {
  display: flex !important;
  justify-content: center !important;
  align-items: center !important;
  height: 200px !important; /* Ridotta l'altezza per non occupare lo schermo */
  width: 100% !important;
}
/* Pulsante di Toggle compatto per l'Offset Z (Solo freccia) */
.btn-alt-toggle {
  background: #2a2a2a !important;
  border: 1px solid #555 !important;
  color: #00e5ff !important;
  font-weight: bold;
  border-radius: 6px;
  padding: 0 !important;
  cursor: pointer;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 32px !important;
  height: 22px !important;
  box-sizing: border-box !important;
  margin: 0 !important;
}
/* ==========================================
   REGOLE CSS PER MINIMIZZARE IL PANNELLO OFFSET Z
   ========================================== */
.alt-slider-panel.collapsed .btn-alt-toggle {
  width: 100% !important;
}
/* Transizione per il corpo del pannello */
.alt-slider-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  overflow: hidden;
  transition: max-height 0.25s ease, opacity 0.2s ease;
  max-height: 320px;
  opacity: 1;
}

/* Quando il pannello ha la classe .collapsed, nasconde il contenuto */
.alt-slider-panel.collapsed .alt-slider-body {
  max-height: 0 !important;
  opacity: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  pointer-events: none !important;
}

/* Ruota la freccia quando è minimizzato */
.alt-slider-panel.collapsed .alt-toggle-icon {
  transform: rotate(180deg);
}

.btn-alt-toggle:hover {
  background: #333 !important;
  border-color: #00e5ff !important;
}

.alt-toggle-icon {
  font-size: 10px;
  line-height: 1;
  transition: transform 0.25s ease;
}
/* Slider verticale sottile */
.alt-slider-panel input[type="range"],
#input-alt-slider {
  -webkit-appearance: slider-vertical;
  writing-mode: bt-lr;
  width: 8px !important;
  height: 100% !important;
  cursor: pointer;
  accent-color: #00e5ff;
}

/* Container compatto per l'input numerico editabile */
.alt-value-box {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid #00e5ff;
  border-radius: 5px;
  padding: 2px 2px !important;
  width: 46px !important;
  max-width: 46px !important;
  box-sizing: border-box !important;
}

#alt-offset-input {
  width: 30px !important;
  background: transparent !important;
  border: none !important;
  color: #00e5ff !important;
  font-size: 10px !important;
  font-weight: bold !important;
  text-align: center !important;
  outline: none !important;
  padding: 0 !important;
  margin: 0 !important;
  -moz-appearance: textfield;
}

/* Rimuove le freccette dall'input di tipo number */
#alt-offset-input::-webkit-outer-spin-button,
#alt-offset-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.alt-value-box span {
  color: #00e5ff;
  font-size: 9px;
  font-weight: bold;
}

/* Gruppo pulsanti reset e snap */
.alt-btn-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.btn-alt-reset {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  border-radius: 50%;
  width: 26px !important;
  height: 26px !important;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  padding: 0 !important;
  margin: 0 !important;
}

.btn-alt-reset:active {
  background: rgba(0, 229, 255, 0.4);
}

/* Pulsante Snap in stato attivo */
.btn-alt-reset.active-snap {
  position: relative;
  background: #222 !important;
}

/* Anello Pulsante Verde (Terreno trovato) */
.btn-alt-reset.snap-success::after {
  content: '';
  position: absolute;
  top: -4px; left: -4px; right: -4px; bottom: -4px;
  border-radius: 50%;
  border: 2px solid #00ff66;
  animation: pulse-ring-green 1.5s infinite;
  pointer-events: none;
}

/* Anello Pulsante Rosso (Terreno NON trovato) */
.btn-alt-reset.snap-fail::after {
  content: '';
  position: absolute;
  top: -4px; left: -4px; right: -4px; bottom: -4px;
  border-radius: 50%;
  border: 2px solid #ff3333;
  animation: pulse-ring-red 1.5s infinite;
  pointer-events: none;
}

@keyframes pulse-ring-green {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(0, 255, 102, 0.7); }
  70% { transform: scale(1.15); box-shadow: 0 0 0 6px rgba(0, 255, 102, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(0, 255, 102, 0); }
}

@keyframes pulse-ring-red {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(255, 51, 51, 0.7); }
  70% { transform: scale(1.15); box-shadow: 0 0 0 6px rgba(255, 51, 51, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(255, 51, 51, 0); }
}

/* Blocco grafico dello slider quando congelato */
.slider-frozen {
  opacity: 0.35 !important;
  pointer-events: none !important;
  filter: grayscale(100%);
}

/* Contenitore rettangolare per i pulsanti Perf */
.perf-presets-container {
    background: rgba(25, 25, 25, 0.95);
    padding: 6px 6px;
    border-radius: 4px;
    border: 1px solid #1D9E75;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
}

/* Bottoni Preset allineati al pannello sensori */
.vram-btn-compact {
    background: #222;
    color: #fff;
    border: 1px solid #444;
    padding: 3px 2px;
    border-radius: 3px;
    font-size: 9px;
    font-weight: bold;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
}

.vram-btn-compact:hover,
.vram-btn-compact.active {
    background: #1D9E75;
    border-color: #1D9E75;
    color: #fff;
}

/* Compatibilità Tema Chiaro */
body.light-theme #vram-perf-integrated-ui {
    border-top-color: #ccc !important;
}

body.light-theme #vram-perf-integrated-ui div[style*="background"] {
    background: rgba(0, 0, 0, 0.05) !important;
}

body.light-theme .vram-btn-compact {
    background: #fff;
    color: #333;
    border-color: #ccc;
}

body.light-theme .vram-btn-compact:hover {
    background: #0f6e56;
    color: #fff;
}

/* ==========================================
   PULSANTE DECL° E INPUT BOX DECLINAZIONE
   ========================================== */

#btn-load-declination,
#input-declination {
    display: inline-block !important;
    vertical-align: middle !important;
    position: static !important;
    transform: none !important;
    box-sizing: border-box !important;
    margin: 0 !important;
}

#btn-load-declination {
    height: 22px !important;
    width: 45px !important;      /* Larghezza forzata del pulsante */
    min-width: 0 !important;
    padding: 0 !important;
    font-size: 10px;
    font-weight: bold;
    background: #2a2a2a;
    border: 1px solid #444;
    color: #fff;
    border-radius: 4px;
    cursor: pointer;
}

#input-declination {
    height: 22px !important;
    width: 45px !important;      /* Larghezza forzata dell'input box */
    min-width: 0 !important;     /* Rimuove il blocco di larghezza minima del browser */
    padding: 0 2px !important;
    font-size: 10px;
    background: #2a2a2a;
    border: 1px solid #444;
    color: #fff;
    border-radius: 4px;
    text-align: center;
    margin-left: 10px !important; /* Distanza dal pulsante */
}

/* Override automatico per Tema Chiaro */
body.light-theme #btn-load-declination,
body.light-theme #input-declination {
    background: #ffffff !important;
    border-color: #94a3b8 !important;
    color: #000000 !important;
}

/* ============================================================
   OTTIMIZZAZIONI PER APP STANDALONE (iOS / Android / Desktop)
   ============================================================ */

/* --- iOS (WKWebView Standalone) --- */
body.platform-ios {
    /* Mantiene le dimensioni compatte senza zoom forzato */
    -webkit-text-size-adjust: 100%;
}

/* Aumenta l'area di tap per i pulsanti touch senza ingrandire i font */
body.platform-ios .mini-btn,
body.platform-ios .icon-btn,
body.platform-ios .top-tab-btn,
body.platform-ios .menu-item {
    min-height: 28px;
    display: inline-flex;
    align-items: center;
}

/* --- Android (Android WebView Standalone) --- */
body.platform-android {
    -webkit-text-size-adjust: 100%;
}

/* Scrollbar personalizzata sottile ed elegante */
body.platform-android ::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}

body.platform-android ::-webkit-scrollbar-thumb {
    background: rgba(29, 158, 117, 0.7);
    border-radius: 2px;
}

/* --- Desktop (Electron / Tauri / Browser Desktop) --- */
body.platform-desktop {
    -webkit-user-select: auto;
    user-select: auto;
}
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-left: 4px;
}
.status-disconnected { background-color: #ff4444; }
.status-connecting   { background-color: #ffbb00; }
.status-connected    { background-color: #00C851; box-shadow: 0 0 6px #00C851; }

.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    z-index: 999999;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-card {
    background: #1e1e1e;
    color: #f0f0f0;
    width: 90%;
    max-width: 380px;
    border-radius: 10px;
    border: 1px solid #444;
    box-shadow: 0 8px 24px rgba(0,0,0,0.6);
    overflow: hidden;
}

.modal-header {
    padding: 12px 16px;
    background: #252525;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #333;
}
.modal-header h3 { margin: 0; font-size: 15px; }
.btn-close { background: none; border: none; color: #aaa; font-size: 20px; cursor: pointer; }

.modal-body { padding: 14px; }
.status-banner {
    background: #282828;
    padding: 8px 12px;
    border-radius: 6px;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    font-size: 12px;
}

.form-group { margin-bottom: 10px; }
.form-group label { display: block; font-size: 11px; color: #aaa; margin-bottom: 3px; }
.form-group input {
    width: 100%;
    padding: 6px 8px;
    background: #111;
    border: 1px solid #444;
    color: #fff;
    border-radius: 4px;
    box-sizing: border-box;
    font-size: 13px;
}

.form-row { display: flex; gap: 8px; }
.form-row .form-group { flex: 1; }

.modal-footer {
    padding: 10px 14px;
    background: #252525;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    border-top: 1px solid #333;
}

.btn-cancel { background: transparent; border: 1px solid #555; color: #ccc; padding: 6px 12px; border-radius: 4px; cursor: pointer; font-size: 12px; }
.btn-connect { background: #1D9E75; border: none; color: #fff; padding: 6px 14px; border-radius: 4px; font-weight: bold; cursor: pointer; font-size: 12px; }


/* Badge Stato Precisione RTK */
.rtk-badge {
    position: fixed;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    backdrop-filter: blur(6px);
    transition: all 0.3s ease;
}

/* RTK FIX: Massima Precisione (Verde) */
.rtk-fix {
    background: rgba(0, 200, 81, 0.25);
    border: 1px solid #00C851;
    color: #00E676;
    box-shadow: 0 0 10px rgba(0, 230, 118, 0.4);
}

/* RTK FLOAT: Precisione Intermedia (Giallo) */
.rtk-float {
    background: rgba(255, 187, 0, 0.25);
    border: 1px solid #ffbb00;
    color: #FFD54F;
}

/* SINGLE: GPS Normale Senza Correzione (Rosso/Grigio) */
.rtk-single {
    background: rgba(255, 68, 68, 0.25);
    border: 1px solid #ff4444;
    color: #FF8A80;
}
/* ==========================================
   SEZIONI COMPRIMIBILI (COLLAPSIBLE GROUPS)
   ========================================== */
.collapsible-group {
    margin-bottom: 6px;
}

.collapsible-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 6px;
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    font-size: 10px;
    color: #1D9E75;
    user-select: none;
    transition: background 0.2s;
}

.collapsible-header:hover {
    background: #333;
}

.collapsible-header .btn-toggle {
    background: transparent !important;
    border: none !important;
    color: #aaa !important;
    font-size: 11px !important;
    padding: 0 !important;
    width: auto !important;
    margin: 0 !important;
    line-height: 1 !important;
    transition: transform 0.2s ease;
    cursor: pointer;
}

/* Stato quando la sezione è chiusa */
.collapsible-group.collapsed .collapsible-content,
#manual-orient-inputs.collapsed #section-geometry {
    display: none !important;
}

.collapsible-group.collapsed .btn-toggle,
#manual-orient-inputs.collapsed .btn-toggle {
    transform: rotate(-90deg);
}

.collapsible-content {
    padding-top: 4px;
}

/* OVERRIDE TEMA CHIARO (LIGHT THEME) PER SEZIONI COMPRIMIBILI */
body.light-theme .collapsible-header {
    background: #ffffff !important;
    border-color: #cbd5e1 !important;
    color: #0f6e56 !important;
}

body.light-theme .collapsible-header:hover {
    background: #f1f5f9 !important;
}

body.light-theme .collapsible-header .btn-toggle {
    color: #000000 !important;
}
#top-bar-left {
    display: flex;
    gap: 4px;
    align-items: center;
    height: 32px;
}

#top-bar-left select {
    flex-shrink: 0;
}

/* Fix allineamento verticale menu CRS e select */
#top-bar select,
#crs-select {
    position: relative;
        top: 2px; /* Usa 1px o 2px (oppure -1px / -2px se è troppo in basso) */
        height: 32px !important;
    margin: 0 !important;
    padding: 0 6px !important;
    box-sizing: border-box !important;
    align-self: center !important;
    line-height: normal !important;
    display: inline-flex !important;
    align-items: center !important;
    border-radius: 4px;
}
/* Stile per pareggiare esattamente i pulsanti esistenti */
#btn-measure {
    font-family: inherit;
    font-size: 10px;
    font-weight: 600;
    height: 32px;
    padding: 0 10px;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    vertical-align: middle;
    margin: 0;
}

/* Stato attivo quando la misurazione è in corso */
#btn-measure.active {
    background-color: #ffc107 !important;
    color: #000000 !important;
    border-color: #e0a800 !important;
}


/* ============================================================
   PANNELLO DESTRA (TOP-RIGHT CONTAINER) - TEMA CHIARO
   ============================================================ */

/* Contenitore principale (speculare a quello di sinistra) */
body.light-theme #top-right-container {
    background: rgba(255, 255, 255, 0.98) !important;
    border: 1px solid #cbd5e1 !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15) !important;
    color: #000000 !important;
}

/* Testi generici e sotto-pannelli */
body.light-theme #top-right-container,
body.light-theme #top-right-container label,
body.light-theme #top-right-container span,
body.light-theme #perf-controls-ui,
body.light-theme #sensor-ui {
    color: #000000 !important;
}

/* Riquadro statistiche VRAM (Geom / Tex) */
body.light-theme #perf-controls-ui div[style*="background"] {
    background: #f1f5f9 !important;
    border: 1px solid #cbd5e1 !important;
}

body.light-theme #perf-controls-ui span[style*="color: #aaa"] {
    color: #475569 !important;
}

body.light-theme #stat-geometries {
    color: #0284c7 !important;
}

body.light-theme #stat-textures {
    color: #d97706 !important;
}

/* Pulsanti preset (Low, Mid, High, Ultra) e pulsante FPS */
body.light-theme .vram-btn-compact,
body.light-theme #btn-toggle-fps {
    background: #ffffff !important;
    border: 1px solid #94a3b8 !important;
    color: #000000 !important;
    font-weight: 600 !important;
}

body.light-theme .vram-btn-compact:hover,
body.light-theme #btn-toggle-fps:hover {
    background: #e2e8f0 !important;
}

body.light-theme .vram-btn-compact.active {
    background: #1D9E75 !important;
    border-color: #1D9E75 !important;
    color: #ffffff !important;
}
/* Riquadro Sensori come Pulsante Cliccabile */
#sensor-data-box {
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    border: 1px solid #444;
    background: rgba(255, 255, 255, 0.05);
    transition: background 0.2s, border-color 0.2s, transform 0.1s;
    user-select: none;
}

#sensor-data-box:hover {
    background: rgba(29, 158, 117, 0.25);
    border-color: #1D9E75;
}

#sensor-data-box:active {
    transform: scale(0.97);
    background: rgba(29, 158, 117, 0.5);
}

/* Tema Chiaro */
body.light-theme #sensor-data-box {
    background: #f8fafc;
    border-color: #cbd5e1;
}

body.light-theme #sensor-data-box:hover {
    background: #e2e8f0;
    border-color: #0f6e56;
}

/* Sposta lo slider in alto quando la tastiera si apre (input in focus) */
.alt-slider-panel:focus-within,
#alt-slider-panel:focus-within {
  top: max(60px, env(safe-area-inset-top) + 20px) !important;
  transform: translateY(0) !important;
  transition: top 0.25s ease-in-out, transform 0.25s ease-in-out !important;
}

/* Nasconde il pulsante RTK */
#btnNtrip {
    display: none !important;
}

/* Nasconde il pulsante PDF dentro lo Stereonet */
#stereonet-export-pdf-btn {
    display: none !important;
}


@keyframes mic-pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 68, 68, 0.7); }
    70% { transform: scale(1.05); box-shadow: 0 0 10px 10px rgba(255, 68, 68, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 68, 68, 0); }
}

.pulse-animation {
    animation: mic-pulse 1.5s infinite;
}
