/* ============================================================
   1. RESET E BASE
   ============================================================ */
body {
    margin: 0;
    padding: 0;
    background-color: #0a1d29;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: white;
}

/* ============================================================
   2. SCHERMATA DI LOGIN E NOTIFICHE
   ============================================================ */
#login-overlay {
    position: fixed;
    inset: 0;
    background: #0a1d29;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.btn-discord {
    background: #5865F2;
    color: white;
    padding: 15px 30px;
    font-weight: bold;
    border-radius: 8px;
    text-decoration: none;
    transition: 0.3s;
    font-size: 1.1rem;
    border: none;
    cursor: pointer;
}

.btn-discord:hover {
    background: #4752c4;
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(88, 101, 242, 0.4);
}

#banner-notifiche {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10001;
    background: rgba(180, 40, 40, 0.9);
    padding: 8px 20px;
    border-radius: 0 0 8px 8px;
    transition: 0.5s;
    font-weight: bold;
    border: 1px solid #ff4444;
}

/* ============================================================
   3. SIDEBAR FISSA (SINISTRA)
   ============================================================ */
#main-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 60px;
    height: 100vh;
    background: #050f14;
    border-right: 1px solid #1e3a5f;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 0;
    z-index: 9999;
    box-shadow: 4px 0 10px rgba(0, 0, 0, 0.5);
}

.sidebar-logo {
    color: #ff8c00;
    font-weight: bold;
    font-size: 1.2rem;
    margin-bottom: 30px;
    border: 2px solid #ff8c00;
    padding: 4px;
}

.sidebar-icon {
    font-size: 24px;
    margin-bottom: 25px;
    cursor: pointer;
    filter: grayscale(1);
    opacity: 0.6;
    transition: 0.2s;
}

.sidebar-icon:hover,
.sidebar-icon.active {
    filter: grayscale(0);
    opacity: 1;
    transform: scale(1.1);
}

.sidebar-spacer {
    flex-grow: 1;
}

/* ============================================================
   4. LAYOUT PANNELLI DINAMICI
   ============================================================ */
#contenitore-pannelli-dinamico {
    position: fixed;
    top: 0;
    left: 60px;
    display: flex;
    height: 100vh;
    z-index: 9000;
    pointer-events: none;
    padding-left: 10px;
}

/* AGGIUNTO #pannello-icone alla lista per dargli colore e animazioni */
#pannello,
#pannello-icone,
#sidebar,
#sidebar-orbita,
#terminal-wrapper {
    pointer-events: auto;
    height: 100vh;
    background: rgba(10, 25, 35, 0.95);
    backdrop-filter: blur(10px);
    border-right: 1px solid #1e3a5f;
    display: flex !important;
    flex-direction: column;
    transition: width 0.3s ease, opacity 0.3s ease;
    box-sizing: border-box;
}

#sidebar-orbita {
    pointer-events: auto !important;
}

#pannello {
    width: 400px;
}

#pannello-icone {
    width: 340px;
}

/* Larghezza del nuovo pannello icone */
#sidebar {
    width: 300px;
}

#sidebar-orbita {
    width: 350px;
}

#terminal-wrapper {
    width: 400px;
    background: rgba(0, 0, 0, 0.9);
}

.nascosto {
    width: 0 !important;
    opacity: 0 !important;
    padding: 0 !important;
    overflow: hidden;
    pointer-events: none;
    border: none !important;
}

.pannello-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 20px;
    box-sizing: border-box;
    padding-bottom: 40px !important;
    /* Diamo respiro in fondo per il tablet */
}

/* ============================================================
   5. ELEMENTI UI (BOTTONI, INPUT, TITOLI)
   ============================================================ */

.suggerimento-item {
    padding: 10px;
    border-bottom: 1px solid #333;
    cursor: pointer;
    color: white;
    font-family: monospace;
    transition: background 0.2s;
}

.suggerimento-item:hover {
    background: #00ffcc;
    color: #000;
    font-weight: bold;
}

.suggerimento-path {
    font-size: 10px;
    color: #888;
    display: block;
}

.suggerimento-item:hover .suggerimento-path {
    color: #333;
}

h3 {
    font-size: 1.1rem;
    letter-spacing: 1px;
    margin-bottom: 15px;
    border-bottom: 1px solid #1e3a5f;
    padding-bottom: 5px;
    color: #ff8c00;
}

label {
    font-size: 0.8rem;
    color: #88a0b0;
    margin-top: 10px;
    display: block;
    text-transform: uppercase;
}

select,
button {
    width: 100%;
    background: #1a3344 !important;
    color: white;
    border: 1px solid #2f61a1;
    padding: 8px;
    border-radius: 4px;
    font-size: 0.9rem;
    margin-top: 5px;
    cursor: pointer;
    transition: all 0.2s ease;
}

button:hover {
    background: #2f61a1 !important;
}

#btn-gomma.attiva {
    background: #631414 !important;
    border-color: #ff4444 !important;
    box-shadow: 0 0 10px rgba(255, 68, 68, 0.4);
}

#btn-matita.attiva {
    background: #daa520 !important;
    border-color: #ff8c00 !important;
    box-shadow: 0 0 10px rgba(255, 140, 0, 0.4);
}

#btn-testo.attiva {
    background: #0be6ba !important;
    border-color: #00d4ff !important;
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.4);
}

/* ============================================================================
   STRUMENTO: GONIOMETRO TATTICO GLOBALE
============================================================================ */
.stile-goniometro-trasparente {
    background: transparent !important;
    border: none !important;
}

.goniometro-wrapper {
    width: 300px;
    height: 300px;
    cursor: move;
    transition: transform 0.1s linear;
    filter: drop-shadow(0px 0px 5px rgba(0, 0, 0, 0.8));
}

.goniometro-popup {
    text-align: center;
    color: #333;
    min-width: 150px;
}

.goniometro-popup .titolo {
    font-weight: bold;
    font-family: monospace;
}

.goniometro-popup input[type="range"] {
    width: 100%;
    margin: 8px 0;
    cursor: pointer;
}

.goniometro-popup .valore-gradi {
    font-weight: bold;
    font-size: 18px;
    color: #ff4444;
}

/* ============================================================
   TOGGLE MODALITÀ ESCLUSIVA
   ============================================================ */
.pannello-toggle-esclusivo {
    margin-bottom: 15px;
    padding: 10px;
    background: #1a3344;
    border-radius: 4px;
    border: 1px solid #2f61a1;
    display: flex;
    align-items: center;
    gap: 10px;
}

.checkbox-esclusivo {
    width: 18px;
    height: 18px;
    cursor: pointer;
    flex-shrink: 0;
    /* Evita che il quadratino si schiacci sui tablet */
}

.label-esclusivo {
    margin: 0 !important;
    font-size: 11px !important;
    cursor: pointer;
    color: #ffffff !important;
    text-transform: none !important;
    /* Disabilita il maiuscolo automatico delle altre label */
}

/* ============================================================
   6. GRIGLIA ICONE (FLEXBOX)
   ============================================================ */
#icone-container {
    margin-top: 20px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid #1e3a5f;
    border-radius: 4px;
    display: flex;
    flex-wrap: wrap;
    /* Le icone vanno a capo automaticamente */
    gap: 12px;
    flex-grow: 1;
    overflow-y: auto;
    align-content: flex-start;
}

/* Titoli delle categorie (occupano tutta la riga forzando l'a capo) */
#icone-container>*:not(button):not(img):not(.icona-item) {
    width: 100%;
    color: #88a0b0;
    font-size: 0.8rem;
    font-weight: bold;
    text-transform: uppercase;
    margin-top: 15px;
    margin-bottom: 5px;
    border-bottom: 1px solid #1e3a5f;
    padding-bottom: 2px;
}

#icone-container>*:first-child {
    margin-top: 0;
}

/* Le icone stesse (dimensione fissa per non deformarle) */
#icone-container img,
.icona-item {
    width: 45px;
    height: 45px;
    object-fit: contain;
    background: #0d1a25;
    border: 1px solid #1e3a5f;
    padding: 5px;
    border-radius: 4px;
    cursor: grab;
    transition: transform 0.1s ease;
}

#icone-container img:hover,
.icona-item:hover {
    border-color: #ff8c00;
    background: #1a3344;
    transform: scale(1.1);
}

/* ============================================================
   7. MAPPA E SCROLLBAR
   ============================================================ */
#map {
    position: absolute;
    top: 0;
    left: 60px;
    width: calc(100vw - 60px) !important;
    height: 100vh;
    background: #0a1d29 !important;
    z-index: 1;
    touch-action: none;
    /* Disabilita il comportamento di zoom e pan predefinito su mobile */
}

.leaflet-container {
    background: #0a1d29 !important;
}

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-thumb {
    background: #1e3a5f;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #ff8c00;
}

/* Classe per la Modalità Notturna */
.night-vision-active {
    /* Effetto viraggio rosso/scuro stile HUD militare */
    filter: sepia(1) saturate(3) hue-rotate(-50deg) brightness(0.7) contrast(1.2) !important;
}

/* Transizione fluida per la mappa */
#map {
    transition: filter 0.5s ease-in-out;
    background: #000;
    /* Sfondo nero per evitare flash bianchi */
}

/* ============================================================
   8. ALTRI COMPONENTI E GRIGLIA
   ============================================================ */
.btn-logout {
    margin-top: 15px;
    background: #631414 !important;
    border-color: #ff4444 !important;
    font-weight: bold;
    flex-shrink: 0;
}

#lista-operatori,
#orbita-container {
    padding: 15px;
    flex-grow: 1;
    overflow-y: auto;
}

#terminal {
    background: black;
    color: #00ff00;
    font-family: 'Courier New', Courier, monospace;
    padding: 10px;
    flex-grow: 1;
    overflow-y: auto;
    font-size: 0.85rem;
    border: 1px solid #004400;
}

.griglia-principale {
    stroke: #1e3a5f !important;
    stroke-width: 2;
    pointer-events: none;
}

.griglia-sub {
    stroke: #228b22 !important;
    stroke-width: 1;
    stroke-dasharray: 8, 5;
    pointer-events: none;
}

.label-griglia {
    color: #00ff00;
    font-weight: bold;
    text-shadow: 2px 2px 4px #000;
    font-size: 14px;
}

/* ========================================================================== */
/* STILI ADMIN CONTROLS E CONSOLE */
/* ========================================================================== */

.admin-panel {
    padding: 10px;
    background: #1a1a1a;
    border-bottom: 2px solid #333;
}

.admin-panel h4 {
    margin: 0 0 10px 0;
    color: #ff8c00;
    font-size: 12px;
}

.admin-row {
    display: flex;
    gap: 5px;
    margin-bottom: 10px;
}

.admin-select {
    flex: 1;
    padding: 2px 6px;
    background: #333;
    color: white;
    border: 1px solid #555;
    font-size: 11px;
    box-sizing: border-box;
    height: 26px;
    cursor: pointer;
}

.admin-btn {
    flex: 2;
    color: white;
    padding: 0;
    font-size: 11px;
    font-weight: bold;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    height: 26px;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-approva {
    background: #28a745;
}

.btn-revoca {
    background: #dc3545;
}

.admin-divider {
    border-color: #333;
    margin: 10px 0;
}

.btn-nuke {
    width: 100%;
    background: #aa0000;
    border: 1px solid #ff4444;
    padding: 6px;
    height: auto;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-nuke:hover {
    background: #cc0000;
}

/* ========================================================================== */
/* OTTIMIZZAZIONE TABLET (Zoom, Selezione e Scorrimento) */
/* ========================================================================== */

html,
body {
    overscroll-behavior: none;
}

#main-sidebar,
#main-sidebar *,
#contenitore-pannelli-dinamico,
#contenitore-pannelli-dinamico * {
    touch-action: manipulation !important;
    -webkit-user-select: none !important;
    user-select: none !important;
}

input,
textarea,
select {
    -webkit-user-select: auto !important;
    user-select: auto !important;
    touch-action: manipulation !important;
}

/* SBLOCCO SCORRIMENTO PANNELLI LATERALI (Per Tablet e Schermi Piccoli) */
#pannello,
#pannello-icone,
#sidebar,
#sidebar-orbita {
    max-height: 100vh;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
}

/* ============================================================
   ANIMAZIONE PING TATTICO
   ============================================================ */
.ping-animato {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border-style: solid;
    border-width: 4px;
    animation: esplosione-ping 1s ease-out infinite;
    pointer-events: none;
    /* Evita che il cerchio blocchi altri click */
}

@keyframes esplosione-ping {
    0% {
        transform: scale(0.1);
        opacity: 1;
    }

    100% {
        transform: scale(2.5);
        opacity: 0;
    }
}

/* ============================================================
   FORZA LE IMMAGINI DELLE ICONE E BLOCCA MENU IPAD/TABLET
   ============================================================ */
.wrapper-icona img {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain;
    display: block;

    /* Blocca il menu "Salva immagine" e la selezione testuale */
    -webkit-touch-callout: none;
    /* Specifica per iOS/iPadOS */
    -webkit-user-select: none;
    /* Safari */
    user-select: none;
    /* Standard per gli altri browser */
    pointer-events: none;
    /* Passa il tocco direttamente alla mappa, ignorando l'immagine pura */
}

/* ============================================================
   MI CREA IL BAGLIORE SULLE ICONE QUANDO LE TRASCINO, QUESTO LE RENDE PIÙ VISIBILI E CHIARE DURANTE IL DRAG (SOPRATTUTTO SU TABLET)
   ============================================================ */
.squadra-selezionata .immagine-custom {
    filter: drop-shadow(0 0 25px #d41bce) brightness(1.2);
    box-shadow: 0 0 30px #e466d8;
    border-radius: 10%;
    /* se serve */
}

/* 1. Il contenitore principale del popup */
.leaflet-popup-content-wrapper {
    background: #1c1c1c85 !important;
    /* Grigio antracite molto scuro */
    color: #eeeeee !important;
    /* Testo quasi bianco */
    border: 1px solid #444;
    /* Un leggero bordo per staccare dalla mappa */
    border-radius: 5px;
    /* Angoli meno arrotondati per un look più "tech" */
    box-shadow: 0 3px 14px rgba(0, 0, 0, 0.8);
}

/* 2. La "freccetta" in basso del popup */
.leaflet-popup-tip {
    background: #1c1c1c !important;
    border: 1px solid #444;
}

/* 3. Il testo e i titoli dentro il tuo popup */
.squadra-popup h3 {
    color: #ff8c00;
    /* Arancione per i titoli, molto leggibile sul nero */
    margin-bottom: 10px;
    border-bottom: 1px solid #333;
    padding-bottom: 5px;
}

/* 4. Stilizziamo anche gli input e le textarea dentro il popup */
.squadra-popup input,
.squadra-popup textarea {
    background: #2b2b2b !important;
    color: #fff !important;
    border: 1px solid #555 !important;
    padding: 4px;
    border-radius: 3px;
    width: 100%;
    box-sizing: border-box;
    /* Evita che l'input esca dai bordi */
}

/* 5. Il tasto di chiusura (la "X" in alto a destra) */
.leaflet-popup-close-button {
    color: #888 !important;
}

.leaflet-popup-close-button:hover {
    color: #fff !important;
}

/* ============================================================
   ETICHETTA NOME SOTTO L'ICONA (HUD STYLE)
   ============================================================ */
.etichetta-nome {
    position: absolute;
    top: 100%;
    /* Si posiziona esattamente sotto l'icona */
    left: 50%;
    transform: translateX(-50%);
    /* La centra perfettamente */

    /* SFONDO E BORDI */
    background-color: rgba(20, 20, 20, 0.85);
    /* Grigio antracite molto scuro e quasi opaco */
    border: 1px solid #ff8c00;
    /* Bordino arancione per richiamare il tema HUD */
    border-radius: 3px;
    /* Angoli leggermente smussati */

    /* TESTO */
    color: #ff8c00;
    /* Testo arancione (molto più leggibile del bianco) */
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
    white-space: nowrap;
    /* Impedisce al nome di andare a capo */

    /* SPAZIATURA E OMBRA */
    padding: 2px 6px;
    margin-top: 5px;
    /* Distanza dall'icona */
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
    /* Ombra per dare profondità */

    /* SICUREZZA */
    pointer-events: none;
    /* Fondamentale: i click passano "attraverso" la scritta */
    z-index: 1000;
}


#orbita-container {
    display: flex;
    flex-wrap: wrap;
    /* Le icone vanno a capo da sole */
    gap: 12px;
    /* Spazio tra le icone */
    padding: 15px;
    justify-content: flex-start;
    /* Allinea a sinistra */
    align-content: flex-start;
    height: auto;
}

.icona-parcheggiata {
    width: 55px;
    height: 55px;
    background: rgba(255, 140, 0, 0.05);
    border: 1px solid #ff8c00;
    border-radius: 4px;
    padding: 5px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.icona-parcheggiata:hover {
    transform: scale(1.1);
    box-shadow: 0 0 10px rgba(255, 140, 0, 0.5);
    background: rgba(255, 140, 0, 0.15);
}

/* 1. Il contenitore principale nella sidebar */
#orbita-container {
    display: flex;
    flex-wrap: wrap;
    /* Permette alle icone di andare a capo */
    gap: 15px;
    /* Spazio tra un'icona e l'altra */
    padding: 15px;
    justify-content: flex-start;
    /* Allinea a sinistra */
    align-content: flex-start;
    /* Allinea in alto */
    height: auto;
    overflow-y: visible;
    /* Importante per non tagliare le etichette */
}

/* 2. Il wrapper che contiene Icona + Nome */
.icona-parcheggiata-wrapper {
    display: flex !important;
    flex-direction: column !important;
    /* Mette nome sotto icona */
    align-items: center !important;
    /* Centra orizzontalmente */
    justify-content: center !important;
    width: 70px !important;
    /* Larghezza fissa del quadratino */
    height: 90px !important;
    /* Altezza fissa del quadratino */
    padding: 5px !important;
    background: rgba(255, 140, 0, 0.03);
    border: 1px solid rgba(255, 140, 0, 0.15);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-sizing: border-box;
    /* Include padding nel calcolo altezza/larghezza */
}

.icona-parcheggiata-wrapper:hover {
    background: rgba(255, 140, 0, 0.1);
    border-color: rgba(255, 140, 0, 0.5);
    transform: translateY(-2px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

/* 3. L'immagine vera e propria - QUI C'ERA IL PROBLEMA */
.icona-parcheggiata-img {
    width: 45px !important;
    /* Forziamo la larghezza piccola */
    height: 45px !important;
    /* Forziamo l'altezza piccola */
    object-fit: contain !important;
    /* Mantiene le proporzioni senza allungare */
    margin-bottom: 5px !important;
    /* Spazio prima del nome */
    display: block !important;
}

/* 4. L'etichetta del nome sotto l'icona */
.etichetta-nome-orbita {
    color: #ff8c00 !important;
    font-size: 10px !important;
    font-weight: bold !important;
    text-transform: uppercase;
    text-align: center;
    width: 100% !important;
    white-space: nowrap;
    /* Non va a capo */
    overflow: hidden;
    /* Taglia se troppo lungo */
    text-overflow: ellipsis;
    /* Mette i puntini sospensivi (...) se taglia */
    text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5);
    line-height: 1.1;
}

/* Animazione della pulsazione */
@keyframes pulse-rientro {
    0% {
        transform: scale(1);
        filter: brightness(1);
    }

    50% {
        transform: scale(1.4);
        filter: brightness(1.8);
        box-shadow: 0 0 25px #ff8c00;
    }

    100% {
        transform: scale(1);
        filter: brightness(1);
    }
}

/* Classe che attiva l'animazione */
.pulsazione-rientro {
    animation: pulse-rientro 0.6s ease-in-out 5;
    /* 0.6s x 5 volte = 3 secondi totali */
    z-index: 1000 !important;
    /* Porta l'icona sopra tutto il resto durante il ping */
}

/* Contenitore principale: ora incolonna gli elementi */
#orbita-container {
    display: flex;
    flex-direction: column;
    /* Una sotto l'altra */
    gap: 10px;
    padding: 10px;
    overflow-y: auto;
}

/* La riga dell'unità in orbita */
.icona-parcheggiata-row {
    display: flex;
    align-items: stretch;
    background: rgba(255, 140, 0, 0.05);
    border: 1px solid rgba(255, 140, 0, 0.2);
    border-radius: 4px;
    padding: 5px;
    gap: 10px;
    min-height: 80px;
}

/* Parte sinistra: Icona + Nome (cliccabile per rientro) */
.orbita-unit-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 80px;
    cursor: pointer;
    border-right: 1px dashed rgba(255, 140, 0, 0.3);
    padding-right: 5px;
}

.orbita-unit-section:hover {
    background: rgba(255, 140, 0, 0.1);
}

/* Parte destra: Il riquadro note */
.orbita-note-section {
    flex-grow: 1;
}

.orbita-note-textarea {
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3) !important;
    color: #fff !important;
    border: none !important;
    padding: 5px;
    font-size: 11px;
    resize: none;
    font-family: inherit;
    box-sizing: border-box;
}

.orbita-note-textarea:focus {
    outline: 1px solid #ff8c00;
}

/* STILI BOUNTY CALCULATOR */
.bounty-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 10px;
    font-size: 13px;
}

.bounty-table th,
.bounty-table td {
    border: 1px solid #7f8c8d;
    padding: 5px;
    text-align: left;
}

.bounty-table thead {
    background: #34495e;
}

.bounty-table tbody tr:nth-child(odd) {
    background: #263036;
}

.bounty-table tbody tr:nth-child(even) {
    background: #2d3840;
}

.bounty-table input {
    background: transparent;
    border: 1px solid #555;
    color: white;
    width: 100%;
    padding: 3px;
    box-sizing: border-box;
}

.bounty-table input:focus {
    outline: none;
    border-color: #ff8c00;
}

.bounty-add-btn {
    background: #34495e;
    color: white;
    border: 1px solid #7f8c8d;
    padding: 5px 10px;
    cursor: pointer;
    width: 100%;
}

.bounty-add-btn:hover {
    background: #ff8c00;
    color: #000;
}

.row-del-btn {
    background: transparent;
    border: none;
    color: #e74c3c;
    cursor: pointer;
    font-weight: bold;
    width: 100%;
}