/* =========================================================
   DESIGN TOKENS (light/dark via data-theme)
   - Variabili di base per sfondo, tipografia e componenti
   - Usate come singola fonte di verità per i due temi
   ========================================================= */
:root {
    --bg: radial-gradient(circle at top, #f1f5f9 0%, #cbd5e1 70%);
    --panel: rgba(255, 255, 255, 0.35);
    --text: #0f172a;
    --muted: #475569;
    --border: rgba(148, 163, 184, 0.4);
    --shadow: 0 20px 40px rgba(15, 23, 42, 0.25);
    --accent: #0f766e;
    --bar: #0251c7;
    --bar-hover: #eab308;
    --axis: rgba(15, 23, 42, 0.35);
    --svg-bg: radial-gradient(circle, #e2e8f0 0%, #cbd5e1 60%, #94a3b8 90%);
}

/* =========================================================
   TEMA SCURO
   - Stesse chiavi del tema chiaro per mantenere il mapping 1:1
   - Il cambio avviene via body[data-theme="dark"]
   ========================================================= */
body[data-theme="dark"] {
    --bg: radial-gradient(circle at top, #1f2937 0%, #020617 70%);
    --panel: rgba(2, 6, 23, 0.4);
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: rgba(148, 163, 184, 0.2);
    --shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    --accent: #38bdf8;
    --bar: #0ea5e9;
    --bar-hover: #eab308;
    --axis: rgba(203, 213, 225, 0.25);
    --svg-bg: radial-gradient(circle, #020617 0%, #020617 60%, #000 90%);
}

/* =========================================================
   BASE LAYOUT
   - Rimuove margini
   - Centra la card con il grafico
   - Impedisce lo scroll (dashboard “fissa”)
   ========================================================= */
* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
    overflow: hidden;
}

body {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    transition: background 0.25s ease, color 0.25s ease;
    min-height: 100vh;
}

/* =========================================================
   TOGGLE TEMA (icona fissa in alto a destra)
   - Semplice <span> con ruolo button
   - Nessuna cornice di default, feedback hover
   ========================================================= */
.theme-icon {
    position: fixed;
    top: 14px;
    right: 18px;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    user-select: none;
    color: var(--text);
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    transition: transform 0.1s ease, opacity 0.2s ease;
    opacity: 0.75;
    z-index: 50;
}

.theme-icon:hover {
    opacity: 1;
    transform: scale(1.1);
}

.theme-icon:focus {
    outline: none;
}

/* =========================================================
   CONTAINER PRINCIPALE
   - Effetto glass-morphism
   - Dimensione max per desktop, fluido su mobile
   ========================================================= */
#container {
    background: var(--panel);
    backdrop-filter: blur(14px);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 1rem 1.5rem 0.8rem;
    box-shadow: var(--shadow);
    max-width: 1100px;
    width: 100%;
    margin: 1.2rem;
    position: relative;
}

/* =========================================================
   TITOLI / TESTO DI SUPPORTO
   ========================================================= */
#title {
    text-align: center;
    font-size: 1.4rem;
    margin-bottom: 0.4rem;
    letter-spacing: 0.04em;
}

#subtitle {
    text-align: center;
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 1rem;
}

/* =========================================================
   SVG / CHART AREA
   - Background coerente con tema
   - Angoli arrotondati per integrarsi col container
   ========================================================= */
svg {
    background: var(--svg-bg);
    border-radius: 16px;
    width: 100%;
    height: auto;
}

/* =========================================================
   BARRE DEL GRAFICO
   - Colore da token
   - Hover con transizione veloce
   ========================================================= */
.bar {
    fill: var(--bar);
    transition: 0.15s ease-out;
}

.bar:hover {
    fill: var(--bar-hover);
}

/* =========================================================
   ASSI D3
   - Testo con opacità ridotta per non dominare
   - Linee in tinta con il tema
   ========================================================= */
.axis text {
    fill: var(--text);
    opacity: 0.7;
    font-size: 0.6rem;
}

.axis path,
.axis line {
    stroke: var(--axis);
}

/* =========================================================
   TOOLTIP ASSOLUTO
   - Posizionato rispetto al container via JS
   - Nascosto di default
   ========================================================= */
#tooltip {
    position: absolute;
    background: rgba(15, 23, 42, 0.9);
    color: #e2e8f0;
    padding: 0.5rem 0.65rem 0.4rem;
    border-radius: 8px;
    pointer-events: none;
    font-size: 0.7rem;
    line-height: 1.2;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.07);
    opacity: 0;
    transition: opacity 0.1s ease-out;
    z-index: 9999;
    min-width: 125px;
    white-space: normal;
}

#tooltip strong {
    display: block;
    margin-bottom: 2px;
}

/* Label asse Y (testo verticale) */
.y-label {
    fill: var(--muted);
    font-size: 0.7rem;
}

/* =========================================================
   RESPONSIVE
   - Riduce padding e font su schermi piccoli
   ========================================================= */
@media (max-width: 950px) {
    #container {
        width: 100%;
        margin: 0.4rem;
        border-radius: 16px;
    }

    #title {
        font-size: 1.1rem;
    }

    #subtitle {
        font-size: 0.65rem;
    }

    #tooltip {
        max-width: 140px;
        font-size: 0.65rem;
    }
}

@media (max-width: 540px) {
    #container {
        padding: 0.7rem 0.6rem 0.6rem;
    }

    #tooltip {
        max-width: 130px;
    }
}