/* ==========================================================================
   1. VARIABILI E RESET
   ========================================================================== */
:root {
    --primary-color: #1e3a8a;
    --primary-light: rgba(30, 58, 138, 0.05);
    --accent-color: #3b82f6;
    --accent-light: rgba(59, 130, 246, 0.1);
    --success-color: #27ae60;
    --error-color: #e74c3c;
    --text-color: #1e293b;
    --text-muted: #64748b;
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --border-color: #cbd5e1;
    --nav-height: 50px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-color);
    padding-top: var(--nav-height);
}

/* ==========================================================================
   2. LAYOUT GENERALE
   ========================================================================== */
.container {
    width: 95%;
    max-width: 1100px;
    margin: 20px auto;
    background: var(--bg-card);
    padding: 25px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
}

.area-wrapper {
    display: flex;
    min-height: calc(100vh - var(--nav-height));
    align-items: stretch;
}

.area-content {
    flex-grow: 1;
    padding: 20px 40px;
    overflow-y: auto;
}

/* Sidebar */
.sidebar-area {
    width: 280px;
    background-color: var(--bg-card);
    border-right: 1px solid var(--border-color);
    padding: 20px 0;
    flex-shrink: 0;
}

.sidebar-area li {
    display: flex;
    align-items: center;
    padding: 14px 25px;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s;
    border-left: 4px solid transparent;
    font-weight: 500;
}

.sidebar-area li.active {
    background-color: var(--primary-light);
    color: var(--primary-color);
    border-left-color: var(--primary-color);
    font-weight: 700;
}

/* ==========================================================================
   3. ELEMENTI FORM E INPUT
   ========================================================================== */
.form-group { margin-bottom: 15px; }

label {
    display: block;
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 5px;
    color: #475569;
}

input, select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    transition: all 0.2s;
}

input:focus, select:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px var(--accent-light);
    outline: none;
}

.form-control-plaintext {
    font-weight: bold;
    color: #2c3e50;
    border-bottom: 1px solid #eee;
    padding: 5px 0;
    background: transparent;
    border-top: none; border-left: none; border-right: none;
}

/* ==========================================================================
   4. BOTTONI E AZIONI
   ========================================================================== */
.btn-base, .btn-primary, .btn-search, .btn-manage, .btn-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    font-size: 0.85rem;
}

.btn-primary { background: var(--primary-color); color: white; width: 100%; }
.btn-primary:hover { background: #162a63; transform: translateY(-1px); }

.btn-search { background: var(--accent-color); color: white; height: 42px; }
.btn-search:hover { background: #0056b3; }

.btn-manage { background: var(--accent-color); color: white; padding: 6px 12px; }

.btn-edit { background: var(--accent-color); color: white; }
.btn-delete { background: var(--error-color); color: white; }
.btn-save { background: var(--success-color); color: white; }

/* ==========================================================================
   5. COMPONENTI UI (Card, Tabelle, Badge)
   ========================================================================== */
/* Dashboard Tiles */
.dash-card, .main-tile {
    background: var(--bg-card);
    border-radius: 16px;
    border: 1px solid #e2e8f0;
    transition: all 0.3s ease;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    color: var(--text-color);
}

.dash-card:hover, .main-tile:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 25px rgba(0,0,0,0.1);
    border-color: var(--accent-color);
}

/* Tabelle */
.table-ssac {
    width: 100%;
    background: var(--bg-card);
    border-collapse: collapse;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.table-ssac th {
    background: var(--primary-color);
    color: white;
    padding: 12px;
    text-transform: uppercase;
    font-size: 0.8rem;
}

.table-ssac td {
    padding: 12px;
    border-bottom: 1px solid #f1f5f9;
}

/* Badge */
.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
}
.badge-attivo { background: #dcfce7; color: #166534; }
.badge-disattivo { background: #fee2e2; color: #991b1b; }

/* ==========================================================================
   6. MODULI SPECIFICI (Nav, Modali, Pastorale)
   ========================================================================== */
.top-nav-bar {
    height: var(--nav-height);
    background: #2c3e50;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    position: fixed;
    top: 0; left: 0; width: 100%;
    z-index: 9999;
}

#area-operativa {
    background-color: var(--white);
    border-top: 2px solid var(--border-color);
    margin-top: 20px;
    padding: 20px;
    min-height: 600px;
}

.modal-ssac {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

/* Utility */
.hidden { display: none !important; }
.text-primary { color: var(--primary-color); }
.text-success { color: var(--success-color); }
.text-danger { color: var(--error-color); }
.text-warning { color: #f59e0b; }

/* Login */
.container-login {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh; /* Occupa tutta l'altezza dello schermo */
    background-color: var(--bg-body);
}

.login-box {
    background: var(--white);
    padding: 40px;
    border-radius: 16px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-box h2 {
    margin-bottom: 25px;
    color: var(--primary-color);
    font-weight: 800;
}

.login-footer {
    margin-top: 25px;
    font-size: 0.9rem;
}

.login-footer hr {
    margin: 20px 0;
    border: 0;
    border-top: 1px solid var(--border-color);
}

/* Bottone secondario (Inizia registrazione) */
.btn-secondary {
    background-color: var(--bg-body);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    width: 100%;
    margin-top: 10px;
}

.btn-secondary:hover {
    background-color: #e2e8f0;
}

.btn-link {
    background: none;
    border: none;
    color: var(--accent-color);
    text-decoration: underline;
    cursor: pointer;
    margin-top: 15px;
}

/* ==========================================================================
   6. DASHBOARD TILES (Versione Corretta)
   ========================================================================== */
.dashboard-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 25px;
    padding: 40px;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - var(--nav-height)); /* Occupa tutto lo spazio utile */
}

.main-tile {
    width: 220px;
    height: 220px;
    background: var(--white);
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--text-color);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

.main-tile:hover {
    transform: translateY(-10px);
    box-shadow: 0 15px 30px rgba(0,0,0,0.1);
    border-color: var(--accent-color);
}

.main-tile i {
    font-size: 60px; /* Icone belle grandi */
    margin-bottom: 15px;
}

.main-tile span {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* Rimuove lo scroll orizzontale se le tile sono tante */
#dashboard-container {
    max-width: 1200px;
    margin: 0 auto;
}

/* Rimpiccioliamo le card quando una sezione è attiva (opzionale con JS) */
.cards-minimized .dash-card {
    padding: 10px !important;
}
.cards-minimized .dash-card i {
    font-size: 1.5rem !important;
}

.modal-content-large {
    background: #ffffff; /* SFONDO BIANCO */
    width: 90%;
    max-width: 900px;
    max-height: 85vh; /* Non supera l'altezza dello schermo */
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2);
}

.comparison-container {
    display: flex;
    gap: 15px;
    padding: 20px;
    flex-grow: 1;
    overflow: hidden;
}

.comparison-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.json-viewer {
    background: #1e293b; /* Grigio scuro per il JSON */
    color: #f8fafc;     /* Testo chiaro per il JSON */
    padding: 15px;
    border-radius: 6px;
    overflow: auto;     /* Scroll interno se il JSON è lunghissimo */
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    flex-grow: 1;
}

/* =======================================
/*    STILI PER L'ORGANIGRAMMA
/*========================================


/* 1. Il contenitore che permette lo scroll orizzontale se l'albero è troppo largo */
/* 1. Contenitore di scroll: si adatta allo spazio disponibile senza uscire dal layout */
.org-scroll-wrapper {
    width: 100%;
    overflow-x: auto;      /* Mantiene la barra orizzontale */
    overflow-y: hidden;    /* Blocca lo scroll verticale interno */
    padding: 20px;
    background-color: #fff;
    border-radius: 8px;
    border: 1px solid #dee2e6;

    /* AGGIUNTE PER BLOCCARE LA BARRA IN VISTA */
    max-height: 75vh;      /* Il contenitore non sarà mai più alto del 75% dello schermo */
    overflow-y: auto;      /* Se l'albero è troppo alto, scrolla internamente */
}

/* 2. L'albero: non deve mai comprimersi */
.org-chart {
    display: inline-block; /* Fondamentale: permette la larghezza variabile */
    margin: 0 auto;
    text-align: center;
    min-width: 1000px; /* Larghezza minima per forzare lo scroll */
}

/* 3. Struttura albero */
.org-root, .org-root ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    justify-content: center;
}

.org-root li {
    padding: 10px;
    position: relative;
}

/* Box grafici */
/* 1. Manteniamo i box come blocchi, ma senza forzare white-space qui */
.node-box, .node-box-struttura {
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 10px;
    margin: 5px 0;
    background-color: white;
    display: block;      /* Mantiene la struttura verticale */
    min-width: 200px;    /* Larghezza minima per non essere striminziti */
}

/* 2. Il trucco: il "nowrap" sta solo qui */
.member-item {
    display: block;
    margin-bottom: 6px; /* Spazio tra una persona e l'altra */
}

/* 2. Il nome: resta su una riga, niente a capo */
.member-name {
    display: block;
    white-space: nowrap;
    font-weight: 600;      /* Un po' più grassetto per risaltare */
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 3. Il ruolo: va sotto, più piccolo e su una riga dedicata */
.member-role {
    display: block;
    font-size: 0.75rem;    /* Più piccolo */
    color: #6c757d;        /* Grigio tenue */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: -2px;      /* Piccolo aggiustamento per avvicinarlo al nome */
}

/* 3. Assicura che il titolo sia chiaro e non vada a capo */
.node-box-title {
    font-weight: bold;
    color: #0d6efd;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
    margin-bottom: 8px;
    white-space: nowrap;      /* Anche il titolo resta su una riga */
    overflow: hidden;
    text-overflow: ellipsis;
}