:root {
    --primary: #009640;
    /* Verde Comieco */
    --primary-dark: #007a33;
    --secondary: #2c3e50;
    --bg-color: #f4f6f8;
    --white: #ffffff;
    --text-color: #333;
    --border-color: #ddd;
    --capsule-bg: #e8f5e9;
    /* Light Green Default */
}

body.theme-blue {
    --primary: #2980b9;
    --primary-dark: #1e6091;
    --secondary: #34495e;
    --bg-color: #ecf0f1;
    --capsule-bg: #e3f2fd;
    /* Light Blue */
}

body.theme-sand {
    --primary: #8d6e63;
    --primary-dark: #5d4037;
    --secondary: #3e2723;
    --bg-color: #fdf5e6;
    --white: #fff8e1;
    --text-color: #4e342e;
    --border-color: #d7ccc8;
    --capsule-bg: #efebe9;
    /* Light Brown */
}

/* Sand theme overrides */
/* Sand theme overrides removed to preserve default shapes and rely on variables */

body.theme-sand .nav-item.active {
    color: #fff;
    background-color: var(--primary);
}

body.theme-contrast .nav-item.active {
    color: #000;
}

/* --- COLUMN LAYOUT REFINEMENTS --- */
/* Prevent text clipping and improve flow in 2-column sections */
/* --- COLUMN LAYOUT REMOVED (Single Column Vertical Flow) --- */
.main-content div[style*="column-count"] {
    column-count: 1 !important;
    width: 100%;
}

.main-content div[style*="column-count"] p,
.main-content div[style*="column-count"] ul,
.main-content div[style*="column-count"] section {
    break-inside: auto;
    margin-top: 0;
}


body {
    font-family: 'Roboto', sans-serif;
    margin: 0;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    height: 100vh;
    overflow: hidden;
    font-size: 18px;
}

/* Skip Link for Accessibility */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary);
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    z-index: 100;
}

.skip-link:focus {
    top: 0;
}

/* --- SIDEBAR --- */
.sidebar {
    width: 320px;
    background-color: var(--secondary);
    color: var(--white);
    display: flex;
    flex-direction: column;
    padding: 25px;
    box-shadow: 4px 0 10px rgba(0, 0, 0, 0.1);
    z-index: 100;
    overflow-y: auto;
}

.logo {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 40px;
    color: var(--white);
    border-bottom: 2px solid var(--primary);
    padding-bottom: 15px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.logo span {
    cursor: pointer;
}

.nav-item {
    padding: 15px 20px;
    cursor: pointer;
    border-radius: 8px;
    margin-bottom: 10px;
    transition: all 0.3s ease;
    font-size: 18px;
    display: flex;
    align-items: center;
}

.nav-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
    padding-left: 25px;
}

.nav-item.active {
    background-color: var(--primary);
    color: var(--white);
    font-weight: 500;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    transform: translateX(5px);
}

body.view-mode-respondent .nav-item.active {
    background-color: #7f8c8d;
    /* Grey for Respondent Mode */
}

.nav-item:focus {
    outline: 2px solid white;
    outline-offset: -2px;
    background: rgba(255, 255, 255, 0.15);
}

/* Sidebar Bottom (Themes & Logos) */
.sidebar-bottom {
    margin-top: auto;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.theme-buttons {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
}

.theme-btn {
    flex: 1;
    margin: 0 5px;
    padding: 8px 0;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    color: white;
    text-transform: uppercase;
}

.theme-btn.green {
    background-color: #009640;
}

.theme-btn.blue {
    background-color: #2980b9;
}

.theme-btn.contrast {
    background-color: #8d6e63;
    color: white;
    border: none;
}

.theme-btn:focus {
    outline: 3px solid white;
    outline-offset: 2px;
    transform: scale(1.05);
}

.sidebar-logos {
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: white;
    padding: 10px;
    border-radius: 8px;
}

.sidebar-logos img {
    max-height: 80px;
    max-width: 45%;
}


/* --- MAIN CONTENT --- */
.main-content {
    flex: 1;
    padding: 50px;
    overflow-y: auto;
    position: relative;
    scroll-behavior: smooth;
}

.slide {
    display: none;
    animation: fadeIn 0.6s cubic-bezier(0.16, 1, 0.3, 1);
    max-width: 28cm;
    margin: 30px auto;
    background: rgba(255, 255, 255, 0.95);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    padding: 60px;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding-bottom: 100px;
}

.slide.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(15px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- TYPOGRAPHY --- */
h1 {
    color: var(--primary);
    font-size: 42px;
    margin-bottom: 30px;
    border-bottom: 3px solid #e0e0e0;
    padding-bottom: 15px;
}

h2 {
    color: var(--secondary);
    font-size: 30px;
    margin-top: 50px;
    margin-bottom: 20px;
    border-left: 6px solid var(--primary);
    padding-left: 20px;
}

h3 {
    color: var(--secondary);
    font-size: 24px;
    margin-top: 30px;
    margin-bottom: 15px;
}

p {
    line-height: 1.6;
    font-size: 20px;
    color: #444;
    /* Note: In contrast mode this might need override if strictly following variables */
    margin-bottom: 20px;
    text-align: justify;
}

body.theme-contrast p {
    color: #fff;
}

body.theme-contrast ul {
    color: #fff;
}

ul {
    margin-bottom: 25px;
    line-height: 1.6;
    color: #444;
    font-size: 20px;
}

li {
    margin-bottom: 12px;
}

.highlight {
    font-weight: bold;
    color: var(--primary);
}

/* --- CARDS & GRIDS --- */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 30px;
    margin-bottom: 50px;
}

.card {
    background: rgba(255, 255, 255, 0.7);
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
    padding: 30px;
    border-radius: 20px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.05);
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-top: 5px solid var(--primary);
    width: 100%;
    box-sizing: border-box;
    transition: transform 0.3s ease;
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.1);
}

#print-header,
#print-footer {
    display: none;
}

.big-number {
    font-size: 3.5em;
    font-weight: 700;
    color: var(--primary);
    display: block;
    margin-bottom: 10px;
}

.label {
    font-size: 1em;
    text-transform: uppercase;
    color: #777;
    letter-spacing: 1px;
    font-weight: 600;
}

body.theme-contrast .label {
    color: #ccc;
}

/* --- TABLES --- */
.table-container {
    background: rgba(255, 255, 255, 0.8);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.05);
    padding: 30px;
    margin-bottom: 40px;
    overflow-x: auto;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 20px;
}

th {
    background-color: var(--secondary);
    color: var(--white);
    text-align: left;
    padding: 15px 20px;
    font-weight: 500;
}

td {
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
}

/* Center all columns except the first one */
td:not(:first-child),
th:not(:first-child) {
    text-align: center;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover {
    background-color: #f9f9f9;
}

.trend-up {
    color: #27ae60;
    font-weight: bold;
}

.trend-down {
    color: #c0392b;
    font-weight: bold;
}

.trend-equal {
    color: #f39c12;
    font-weight: bold;
}

/* Delta Styles */
.delta-pos {
    color: #27ae60;
    font-weight: bold;
}

.delta-pos::before {
    content: "▲ ";
}

.delta-neg {
    color: #c0392b;
    font-weight: bold;
}

.delta-neg::before {
    content: "▼ ";
}

.delta-neu {
    color: #7f8c8d;
    font-weight: bold;
}

.delta-neu::before {
    content: "■ ";
    font-size: 0.8em;
}

/* Low Satisfaction Warning (< 85%) */
.low-sat,
td.low-sat {
    color: #c0392b !important;
    font-weight: bold !important;
    background-color: rgba(192, 57, 43, 0.1) !important;
}

/* --- CHARTS --- */
.chart-wrapper {
    background: rgba(255, 255, 255, 0.8);
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
    padding: 30px;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.05);
    margin-bottom: 40px;
    height: 500px;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.text-box {
    background: var(--white);
    padding: 35px;
    border-radius: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    margin-bottom: 40px;
}

/* --- AREA CARDS --- */
.content-wrapper-std {
    width: 95%;
    box-sizing: border-box;
    margin: 0 auto 20px auto;
}

.area-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 25px;
}

.area-card {
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.05);
    border-left: 6px solid var(--primary);
}

.area-card h4 {
    margin-top: 0;
    color: var(--secondary);
    font-size: 22px;
}


/* --- AREA STATS --- */
.area-stats {
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
    font-size: 16px;
}

.stat-box {
    text-align: center;
}

.stat-val {
    font-weight: bold;
    display: block;
    font-size: 22px;
    color: var(--primary);
}

.stat-lbl {
    font-size: 14px;
    color: #777;
}

/* --- CITAZIONI --- */
.quote-box {
    background: #fff;
    border-left: 5px solid var(--primary);
    padding: 20px 30px;
    margin-bottom: 25px;
    font-style: italic;
    color: #555;
    font-size: 20px;
    border-radius: 0 10px 10px 0;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.05);
}

.quote-pos {
    background-color: #e3f2fd;
    border-left-color: #3498db;
    color: #2c3e50;
}

.quote-neg {
    background-color: #fce4ec;
    border-left-color: #e91e63;
    color: #c0392b;
}

.quote-author {
    display: block;
    margin-top: 10px;
    font-size: 16px;
    font-weight: bold;
    color: var(--secondary);
    text-transform: uppercase;
}

body.theme-sand .area-card h4 {

    color: var(--secondary);
}

body.theme-sand .stat-lbl {
    color: #6d4c41;
}

body.theme-sand .quote-box {
    color: var(--text-color);
}

body.theme-sand .quote-author {
    color: var(--secondary);
}

/* --- GRID 50/50 --- */
.grid-50 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(550px, 1fr));
    gap: 30px;
    margin-bottom: 30px;
    align-items: start;
}

.grid-50>* {
    min-width: 0;
    /* Prevents grid blowout, allowing overflow-x to work */
}

/* --- RESPONSIVE --- */
@media (max-width: 1024px) {
    body {
        flex-direction: column;
        overflow-y: auto;
    }

    .sidebar {
        width: 100%;
        height: auto;
        flex-direction: row;
        padding: 15px;
        overflow-x: auto;
        box-sizing: border-box;
    }

    .logo {
        display: none;
    }

    .nav-item {
        margin-right: 20px;
        white-space: nowrap;
        margin-bottom: 0;
    }

    .main-content {
        padding: 25px;
        height: auto;
        overflow: visible;
    }

    .chart-wrapper {
        height: 350px;
    }

    .grid-50 {
        grid-template-columns: 1fr;
    }

    h1 {
        font-size: 32px;
    }

    h2 {
        font-size: 26px;
    }

    p,
    li,
    td {
        font-size: 16px;
    }

    .sidebar-bottom {
        display: none;
    }

    /* Hide complex sidebar footer on mobile for now */
}


/* --- VIEW MODE TOGGLE --- */
/* --- VIEW MODE TOGGLE --- */
.switch-container {
    padding: 15px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 15px;
    text-align: center;
}

.switch-label {
    font-size: 0.9em;
    font-weight: bold;
    display: block;
    margin-bottom: 8px;
    color: var(--white);
    letter-spacing: 1px;
}

.switch-wrapper {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 34px;
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 17px;
    cursor: pointer;
    overflow: hidden;
    vertical-align: middle;
}

.switch-wrapper input {
    display: none;
}

.switch-button {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 30px;
    height: 30px;
    background-color: var(--white);
    border-radius: 50%;
    transition: transform 0.3s ease;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Logic for Toggle */
/* Default checked = COMPANY (Active) */
/* Unchecked = RESPONDENT (Inactive) */

body.view-mode-respondent .switch-wrapper {
    background-color: #bdc3c7;
    /* Grey */
}

body.view-mode-respondent .switch-button {
    transform: translateX(26px);
}

body.view-mode-company .switch-wrapper {
    background-color: var(--primary);
    /* Green/Theme Color */
}

body.view-mode-company .switch-button {
    transform: translateX(0);
}

.switch-wrapper:focus-within {
    outline: 2px solid white;
    outline-offset: 2px;
    border-radius: 20px;
}

/* Clean end of switch styles */

/* Visibility Control */
body.view-mode-respondent .view-company-only {
    display: none !important;
}

body.view-mode-company .view-respondent-only {
    display: none !important;
}

/* --- VIEW MODE VISUAL CUES --- */
/* Add an icon to headers when in Company Mode */
body.view-mode-company h1::after,
body.view-mode-company h2::after {
    content: " 🏢";
    /* Building icon */
    font-size: 0.8em;
    margin-left: 10px;
    opacity: 0.7;
    filter: grayscale(0.2);
}

/* Add an icon to headers when in Respondent Mode */
body.view-mode-respondent h1::after,
body.view-mode-respondent h2::after {
    content: " 👥";
    /* People icon */
    font-size: 0.8em;
    margin-left: 10px;
    opacity: 0.7;
    filter: grayscale(0.2);
}

/* Optional: Slight background tint for Company Mode */
body.view-mode-company .main-content {
    background-color: rgba(0, 150, 64, 0.03);
    /* Very subtle green tint */
}

/* --- OPERATIONAL AREA COLORS (TABLE ROWS) --- */
/* Defined for reusability across all chapters */

/* Base classes for rows */
tr.area-media-nazionale {
    background-color: #0066ff !important;
    color: #ffffff !important;
    font-weight: bold !important;
}

/* Base classes for rows - Light version */
tr.area-media-nazionale-light {
    background-color: #e6f3ff !important;
    color: #333 !important;
    font-weight: bold !important;
}


/* Company Mode Overrides - Verde Scuro */
body.view-mode-company tr.area-media-nazionale {
    background-color: #006837 !important;
    /* Verde scuro per modalità azienda */
}

/* Operational Areas */
tr.area-riciclo {
    background-color: rgba(39, 174, 96, 0.05);
    /* Green */
}

tr.area-audit {
    background-color: rgba(243, 156, 18, 0.05);
    /* Orange */
}

tr.area-amministrazione {
    background-color: rgba(41, 128, 185, 0.05);
    /* Blue */
}

tr.area-comunicazione {
    background-color: rgba(230, 126, 34, 0.05);
    /* Dark Orange */
}

tr.area-sistemi {
    background-color: rgba(142, 68, 173, 0.05);
    /* Purple */
}

tr.area-segreteria {
    background-color: rgba(149, 165, 166, 0.05);
    /* Grey */
}

tr.area-rd {
    background-color: rgba(22, 160, 133, 0.05);
    /* Teal */
}

/* Categories (Tipologia) */
tr.cat-convenzionati {
    background-color: rgba(102, 126, 234, 0.05);
    /* Light Blue */
}

tr.cat-piattaforme {
    background-color: rgba(79, 172, 254, 0.05);
    /* Lighter Blue */
}

tr.cat-cartiere {
    background-color: rgba(250, 112, 154, 0.05);
    /* Pink */
}

/* Total Rows */
tr.total-row {
    background-color: #f1f1f1 !important;
    font-weight: bold !important;
}

/* Year Highlights */
.highlight-year-header {
    background-color: #e8f5e9 !important;
    color: #009640 !important;
}

.highlight-year-cell {
    font-weight: bold !important;
    font-size: 22px !important;
    color: #009640 !important;
}

/* Utilities */
.text-center {
    text-align: center !important;
}

/* Card Area Colors */
.card-media-nazionale {
    background-color: rgba(0, 102, 255, 0.12);
    border-left-color: #0066ff !important;
}

.card-riciclo {
    background-color: rgba(39, 174, 96, 0.05);
    border-left-color: #27ae60 !important;
}

.card-amministrazione {
    background-color: rgba(41, 128, 185, 0.05);
    border-left-color: #2980b9 !important;
}

.card-audit {
    background-color: rgba(243, 156, 18, 0.05);
    border-left-color: #f39c12 !important;
}

.card-segreteria {
    background-color: rgba(149, 165, 166, 0.05);
    border-left-color: #95a5a6 !important;
}

.card-comunicazione {
    background-color: rgba(230, 126, 34, 0.05);
    border-left-color: #e67e22 !important;
}

.card-sistemi {
    background-color: rgba(142, 68, 173, 0.05);
    border-left-color: #8e44ad !important;
}

.card-rd {
    background-color: rgba(22, 160, 133, 0.05);
    border-left-color: #16a085 !important;
}

/* --- PRINT HELPERS --- */
.print-only {
    display: none !important;
}

/* PIE CHART CUSTOM LEGEND */
.pie-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 30px;
    margin-bottom: 40px;
    flex-wrap: wrap;
    background: white;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    box-sizing: border-box;
}

.pie-chart-area {
    flex: 1;
    min-width: 250px;
    height: 350px;
}

.custom-legend-container {
    flex: 0 0 250px;
}

.custom-legend-table {
    width: 100%;
    font-size: 14px;
    border-collapse: collapse;
}

.custom-legend-table td {
    padding: 6px 4px;
    vertical-align: middle;
    border: none !important;
}

.legend-color-box {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    display: inline-block;
}

.legend-label {
    color: #444;
    font-weight: 500;
}

.legend-value {
    text-align: right;
    font-weight: bold;
    color: #000;
}

/* Compact Table for Trend/Comparison sections */
.compact-table {
    font-size: 16px !important;
}

.compact-table th,
.compact-table td {
    padding: 8px 10px !important;
}

.table-container.compact-container {
    padding: 15px !important;
}