/* --- RESET INIZIALE --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: Arial, sans-serif;
}

body, html {
    width: 100%;
    min-height: 100%;
    background-color: #f5f5f5;
}

body {
    padding-top: 72px; /* Spazio per l'header fisso */
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* --- HEADER (uniformato a index.css) --- */
header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 72px;
    background: #0d3b66;
    margin-bottom: 0 !important;
    padding: 10px 20px !important;
    box-shadow: 0 2px 10px rgba(0,0,0,.25);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-sizing: border-box;
}

/* --- LOGO (uniformato a index.css) --- */
.logo {
    position: absolute;
    left: 25px;
    top: 18px;
    font-size: 30px;
    font-weight: bold;
    color: white;
    letter-spacing: 1px;
    background-color: transparent;
    text-shadow: none;
    z-index: 10000;
}

/* --- NAV (uniformata a index.css) --- */
nav {
    position: absolute;
    right: 35px;
    top: 22px;
    z-index: 10000;
}

nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    gap: 25px;
}

nav ul li a {
    color: white;
    text-decoration: none;
    font-size: 20px;
    font-weight: 600;
    transition: .25s;
    background-color: transparent;
    text-shadow: none;
    line-height: normal;
}

nav ul li a:hover {
    color: #8fd3ff;
}

main {
    margin-top: 0px; 
    flex: 1;
    padding: 20px;
}

main h1 {
    margin-top: 0;
}

.container {
    display: block;
    margin-bottom: 20px;
}

.box {
    border: 1px solid #ccc;
    padding: 15px;
    width: 300px;
    background: white;
}

#pyramidCanvas {
    width: 900px !important;
    height: 650px !important;
    max-width: 900px !important;
    max-height: 650px !important;
    min-width: 900px !important;
    min-height: 650px !important;
    box-sizing: content-box !important;
}

/* --- TOP RIGHT LINKS --- */
.top-links {
    position: absolute;
    top: 20px;
    right: 20px;
}

.top-links a {
    font-weight: bold;
    text-decoration: none;
    margin-left: 20px;
    font-size: 16px;
}

.top-links a:first-child {
    color: #0077cc; 
}

.top-links a:last-child {
    color: #d00; 
}

#indiciContainer {
    min-width: 260px;
}

#tabellaIndici {
    border-collapse: collapse;
    width: 100%;
    font-size: 18px;
    background: white;
}

#tabellaIndici th, #tabellaIndici td {
    border: 1px solid #999;
    padding: 6px 10px;
    text-align: center;
}

/* Tooltip generico */
.tip {
    position: relative;
    cursor: help;
}

/* Box del tooltip */
.tip:hover::after {
    content: attr(data-tip);
    position: absolute;
    left: 50%;
    top: 100%;
    transform: translateX(-50%);
    background: #333;
    color: #fff;
    padding: 6px 10px;
    border-radius: 6px;
    white-space: normal;
    width: 240px;
    font-size: 13px;
    z-index: 9999;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

/* Freccetta */
.tip:hover::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 95%;
    transform: translateX(-50%);
    border-width: 6px;
    border-style: solid;
    border-color: transparent transparent #333 transparent;
    z-index: 9999;
}

#pannelloPiramide {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 20px;
}

#tabellaTraspostaContainer {
    border: 3px solid red;
    margin-top: 20px;
    padding: 10px;
    background-color: #f8f8f8;
    max-height: none;
    overflow: auto;
    max-width: 100%;
}

/* Layout generale: due colonne */
#layoutGenerale {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 20px;
}

#colonnaSinistra select[name="risultatiComune"] {
    min-height: 220px;
    max-height: 260px;
    overflow-y: auto;
    display: block;
    width: 300px;
}

#colonnaSinistra {
    width: 300px;     
    flex-shrink: 0;    
}

#colonnaDestra {
    border: 3px solid red;
    flex-grow: 1;     
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 40px;
    min-height: calc(100vh - 140px); 
    height: auto;
    background: white;
}

select[name="risultatiComune"] {
    display: block;
    width: 100%;
    min-height: 200px;
    overflow-y: auto;
}

#layoutPiramide {
    overflow-x: auto;
    width: 100%;
    min-width: 600px;
}

#layoutPiramide canvas {
    display: block;
}

.box-teorico {
    margin-top: 20px;
    padding: 15px;
    background: #f4f4f4;
    border-left: 4px solid #0077cc;
    border-radius: 6px;
}

.box-teorico h3 {
    margin-top: 0;
}

.box-teorico ul {
    margin-left: 20px;
}

#overlayAttesa {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(2px);
}

#overlayAttesa .box {
    background: white;
    padding: 25px 40px;
    border-radius: 10px;
    text-align: center;
    font-size: 18px;
    box-shadow: 0 0 20px rgba(0,0,0,0.3);
}

#overlayAttesa .spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #ccc;
    border-top-color: #007bff;
    border-radius: 50%;
    margin: 0 auto 15px auto;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- FOOTER / CONTATTI (uniformato a index.css) --- */
#contatti, footer {
    background: #0d3b66;
    color: white;
    text-align: center;
    padding: 20px;
    font-size: 1rem;
    line-height: normal;
    width: 100%;
    margin-top: auto;
}

#contatti a, footer a {
    color: #8fd3ff;
    text-decoration: none;
}

#contatti a:hover, footer a:hover {
    text-decoration: underline;
}

/* Media query dispositivi mobili */
@media(max-width:900px){
    .logo {
        position: static;
        text-align: center;
        margin-top: 5px;
    }
    nav {
        position: static;
        margin-top: 10px;
        text-align: center;
    }
    nav ul {
        flex-direction: column;
        gap: 10px;
    }
    header {
        height: auto;
        padding-bottom: 20px;
    }
    body {
        padding-top: 120px;
    }
    #layoutGenerale {
        flex-direction: column;
    }
    #colonnaSinistra {
        width: 100%;
    }
    #colonnaSinistra select[name="risultatiComune"] {
        width: 100%;
    }
}
