/**
 * InForma — design system (globale)
 */
:root {
    /* Palette precedente (header originale + ANPAS) */
    --if-font: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --if-bg: #f4f6f9;
    --if-bg-elevated: #f8f9fb;
    --if-surface: #ffffff;
    --if-border: #dee2e6;
    --if-text: #243042;
    --if-text-muted: #5c6570;
    --if-primary: #0b57d0;
    --if-primary-hover: #0948b0;
    --if-primary-soft: rgba(11, 87, 208, 0.1);
    --if-sidebar-bg: #131a24;
    --if-sidebar-border: rgba(255, 255, 255, 0.06);
    --if-sidebar-text: #e8edf5;
    --if-sidebar-muted: #aeb8c8;
    --if-accent-admin: #0b57d0;
    --if-accent-cdf: #0dcaf0;
    --if-accent-ente: #d9381e;
    --if-radius: 12px;
    --if-radius-sm: 8px;
    --if-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
    --if-shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

/* Pagine con sidebar: niente scroll sul body, così la colonna menu resta fissa */
html:has(.main-wrapper) {
    height: 100%;
}

html:has(.main-wrapper) body {
    height: 100%;
    overflow: hidden;
}

html.app-sidebar-collapsed:has(.main-wrapper) {
    overflow-x: hidden;
}

html.app-sidebar-collapsed:has(.main-wrapper) body {
    overflow-x: hidden;
}

body {
    font-family: var(--if-font);
    background-color: var(--if-bg);
    color: var(--if-text);
    -webkit-font-smoothing: antialiased;
}

/* Layout app */
.main-wrapper {
    display: flex;
    min-height: 100vh;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
    min-width: 0;
}

.content-area {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    max-height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    background-color: var(--if-bg);
    overscroll-behavior: contain;
}

/* ente/index: titolo e filtri fermi, scroll solo tabella */
.content-area.content-area--ente-split {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-bottom: 0 !important;
}

.content-area.content-area--ente-split .ente-militi-top {
    flex-shrink: 0;
    padding-bottom: 1.5rem;
}

@media (min-width: 768px) {
    .content-area.content-area--ente-split .ente-militi-top {
        padding-bottom: 2rem;
    }
}

.content-area.content-area--ente-split .ente-militi-table-panel {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 1.5rem;
    margin-bottom: 0;
}

/* Nessun overflow nascosto tra pannello e tabella: altrimenti thead sticky non funziona */
.content-area.content-area--ente-split .ente-militi-table-panel > .ente-militi-table-card {
    overflow: visible;
}

/* `border-collapse: collapse` (Bootstrap `.table`) può impedire thead sticky in alcuni browser */
.content-area.content-area--ente-split .ente-militi-table-panel .table-if {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
}

.content-area.content-area--ente-split .ente-militi-table-panel .table-if thead th {
    position: sticky;
    top: 0;
    z-index: 4;
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.08);
}

/* Sidebar (shell = larghezza animata; interno = scroll) */
:root {
    --if-sidebar-shell-width: 280px;
    --if-sidebar-shell-collapsed: 56px;
}

.app-sidebar-shell {
    width: var(--if-sidebar-shell-width);
    flex: 0 0 var(--if-sidebar-shell-width);
    max-width: var(--if-sidebar-shell-width);
    min-height: 0;
    height: 100vh;
    max-height: 100vh;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-right: 1px solid var(--if-sidebar-border);
    background: var(--if-sidebar-bg);
    overflow-x: hidden;
    transition: width 0.22s ease, flex-basis 0.22s ease, max-width 0.22s ease;
}

html.app-sidebar-collapsed .app-sidebar-shell {
    width: var(--if-sidebar-shell-collapsed);
    flex: 0 0 var(--if-sidebar-shell-collapsed);
    max-width: var(--if-sidebar-shell-collapsed);
    min-width: var(--if-sidebar-shell-collapsed);
    overflow-x: clip;
    overflow-y: hidden;
    z-index: 1040;
}

.app-sidebar {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    min-width: 0;
    background: transparent;
    color: var(--if-sidebar-text);
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
}

.app-sidebar .sidebar-brand-row {
    flex-wrap: nowrap;
}

.app-sidebar .sidebar-collapse-toggle {
    flex-shrink: 0;
    line-height: 1;
    opacity: 0.9;
}

.app-sidebar .sidebar-collapse-toggle:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.08);
}

html.app-sidebar-collapsed .app-sidebar .sidebar-brand-text,
html.app-sidebar-collapsed .app-sidebar .sidebar-macro-toggle .section-title,
html.app-sidebar-collapsed .app-sidebar .sidebar-macro-toggle .sidebar-macro-chevron,
html.app-sidebar-collapsed .app-sidebar .sidebar-footer-text,
html.app-sidebar-collapsed .app-sidebar .sidebar-user-text {
    display: none !important;
}

html.app-sidebar-collapsed .app-sidebar .sidebar-brand-row {
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
}

html.app-sidebar-collapsed .app-sidebar .sidebar-brand-row > a {
    justify-content: center;
}

html.app-sidebar-collapsed .app-sidebar .sidebar-macro-toggle {
    justify-content: center;
    padding-left: 0.35rem !important;
    padding-right: 0.35rem !important;
}

html.app-sidebar-collapsed .app-sidebar .sidebar-macro-icon {
    margin-right: 0 !important;
}

html.app-sidebar-collapsed .app-sidebar .nav-link {
    font-size: 0;
    line-height: 0;
    text-align: center;
    padding: 0.45rem 0.35rem !important;
}

html.app-sidebar-collapsed .app-sidebar .nav-link > i[class^="bi-"],
html.app-sidebar-collapsed .app-sidebar .nav-link > i.bi {
    font-size: 1.15rem;
    line-height: 1.2;
    margin: 0 !important;
    vertical-align: middle;
}

html.app-sidebar-collapsed .app-sidebar .dropdown > a.dropdown-toggle {
    justify-content: center;
}

html.app-sidebar-collapsed .app-sidebar .dropdown > a.dropdown-toggle::after {
    display: none;
}

html.app-sidebar-collapsed .app-sidebar {
    overflow-x: clip;
    overscroll-behavior-x: none;
    padding-left: 0.35rem !important;
    padding-right: 0.35rem !important;
}

html.app-sidebar-collapsed .app-sidebar .dropdown-menu {
    margin-left: 2px;
}

html.app-sidebar-collapsed .app-sidebar li.nav-item.mt-3 > small {
    display: none !important;
}

html.app-sidebar-collapsed .app-sidebar .nav-link.active {
    padding-left: 0.35rem !important;
    border-left-width: 2px;
}

.app-sidebar .section-title {
    color: var(--if-sidebar-muted);
    letter-spacing: 0.06em;
    font-size: 0.65rem !important;
}

.app-sidebar .nav-link {
    color: var(--if-sidebar-text) !important;
    border-radius: var(--if-radius-sm);
    padding: 0.5rem 0.75rem;
    margin-bottom: 2px;
    font-weight: 500;
    font-size: 0.9rem;
}

.app-sidebar .nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff !important;
}

.app-sidebar .nav-link.active {
    background: rgba(255, 255, 255, 0.12) !important;
    color: #fff !important;
    font-weight: 600;
    border-left: 3px solid #fff;
    padding-left: calc(0.75rem - 3px);
}

.app-sidebar .nav-link.active.bg-primary {
    background: rgba(99, 102, 241, 0.35) !important;
    border-left-color: var(--if-accent-admin);
}

.app-sidebar .nav-link.active.bg-info {
    background: rgba(2, 132, 199, 0.35) !important;
    border-left-color: var(--if-accent-cdf);
}

.app-sidebar .nav-link.active.bg-danger {
    background: rgba(190, 18, 60, 0.35) !important;
    border-left-color: var(--if-accent-ente);
}

.app-sidebar .role-label {
    color: #cbd5e1;
    font-size: 0.75rem;
}

.app-sidebar .dropdown-menu {
    background: #1e293b;
    border: 1px solid var(--if-sidebar-border);
}

.app-sidebar .dropdown-item {
    color: var(--if-sidebar-text);
}

.app-sidebar .dropdown-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.app-brand-mark {
    width: 36px;
    height: 36px;
    border-radius: var(--if-radius-sm);
    background: linear-gradient(135deg, var(--if-primary) 0%, #003366 100%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.app-brand-mark .bi {
    font-size: 1.15rem;
    color: #fff;
}

/* Page chrome */
.page-header-block {
    margin-bottom: 1.75rem;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--if-text);
    margin-bottom: 0.25rem;
}

.page-subtitle {
    color: var(--if-text-muted);
    font-size: 0.95rem;
    margin-bottom: 0;
}

.link-back {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--if-primary);
    text-decoration: none;
    margin-bottom: 0.5rem;
}

.link-back:hover {
    text-decoration: underline;
    color: var(--if-primary-hover);
}

/* Cards */
.if-card {
    background: var(--if-surface);
    border: 1px solid var(--if-border);
    border-radius: var(--if-radius);
    box-shadow: var(--if-shadow);
}

.if-card-header {
    padding: 0.875rem 1.25rem;
    font-weight: 600;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--if-border);
    background: var(--if-bg-elevated);
    border-radius: var(--if-radius) var(--if-radius) 0 0;
}

/* Legacy alias used in gestione corso / presenze */
.card-custom {
    border: 1px solid var(--if-border) !important;
    border-radius: var(--if-radius) !important;
    box-shadow: var(--if-shadow) !important;
}

/* Tabella ente militi — intestazione */
.table-if thead th {
    background-color: var(--if-primary);
    color: #fff;
    border: none;
    font-size: 0.72rem;
}

.table-if thead th[data-sort] {
    cursor: pointer;
    user-select: none;
}

.badge-qualifica {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.03em;
}

/* CDF dashboard KPI */
.cdf-kpi-card {
    border: 1px solid var(--if-border);
    border-radius: var(--if-radius);
    border-bottom-width: 4px;
    border-bottom-color: var(--if-primary);
    box-shadow: var(--if-shadow);
    transition: box-shadow 0.2s ease;
}

.cdf-kpi-card:hover {
    box-shadow: var(--if-shadow-md);
}

.cdf-kpi-card--success {
    border-bottom-color: #15803d;
}

.cdf-kpi-card--muted {
    border-bottom-color: #64748b;
}

.cdf-kpi-card--accent {
    border-bottom-color: #ca8a04;
}

.card-corso {
    border: 1px solid var(--if-border);
    border-radius: var(--if-radius);
    border-left: 4px solid #15803d;
    box-shadow: var(--if-shadow);
}

.card-corso.chiuso {
    border-left-color: #64748b;
    opacity: 0.92;
}

.sticky-col {
    position: sticky;
    top: 1.25rem;
}

/* Card rete CDF (admin) */
.centro-affilia-card {
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.centro-affilia-card:hover {
    box-shadow: var(--if-shadow-md);
    transform: translateY(-3px);
}

.chip {
    background: var(--if-bg-elevated);
    border: 1px solid var(--if-border);
    border-radius: 999px;
    padding: 0.25rem 0.65rem;
    font-size: 0.78rem;
    color: var(--if-text);
}

/* KPI tiles */
.kpi-tile {
    background: var(--if-surface);
    border: 1px solid var(--if-border);
    border-radius: var(--if-radius);
    box-shadow: var(--if-shadow);
    padding: 1.25rem 1.5rem;
    border-left: 4px solid var(--if-primary);
}

.kpi-tile .kpi-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--if-text-muted);
}

.kpi-tile .kpi-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--if-text);
}

.kpi-tile--slate {
    border-left-color: #64748b;
}

.kpi-tile--rose {
    border-left-color: #e11d48;
}

.kpi-tile--teal {
    border-left-color: #0d9488;
}

.kpi-tile--amber {
    border-left-color: #d97706;
}

/* Tables */
.table {
    --bs-table-bg: transparent;
}

.table thead th {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    color: var(--if-text-muted);
    border-bottom-width: 1px;
}

.table-hover tbody tr:hover {
    background-color: rgba(11, 87, 208, 0.06);
}

/* Bootstrap `.table thead th` imposta colore testo mutato e vince sull’intestazione blu */
.table.table-if thead th {
    color: #fff !important;
    background-color: var(--if-primary) !important;
    border-color: rgba(255, 255, 255, 0.18) !important;
    font-weight: 600;
}

/* Tabs (gestione corso) */
.nav-tabs-if {
    border-bottom: 1px solid var(--if-border);
    gap: 0.25rem;
}

.nav-tabs-if .nav-link {
    color: var(--if-text-muted);
    font-weight: 600;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    padding: 0.65rem 1rem;
    margin-bottom: -1px;
}

.nav-tabs-if .nav-link:hover {
    color: var(--if-text);
    border-color: transparent;
}

.nav-tabs-if .nav-link.active {
    color: var(--if-primary);
    background: transparent;
    border-bottom-color: var(--if-primary);
}

/* Banner presenze / hero interni */
.page-banner {
    background: linear-gradient(120deg, #002244 0%, #003366 45%, #0b57d0 100%);
    color: #fff;
    padding: 1.75rem 0;
    margin-bottom: 1.5rem;
    border-radius: 0 0 var(--if-radius) var(--if-radius);
    box-shadow: var(--if-shadow-md);
}

.page-banner .breadcrumb {
    margin-bottom: 0.5rem;
}

.page-banner .breadcrumb-item,
.page-banner .breadcrumb-item a {
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.875rem;
}

.page-banner .breadcrumb-item.active {
    color: #fff;
}

.page-banner h1 {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0;
}

/* Alerts strip (dashboard) */
.alert-strip {
    border-radius: var(--if-radius-sm);
    border: 1px solid transparent;
}

/* Auth pages */
.auth-page {
    min-height: 100vh;
    background: linear-gradient(165deg, #eef1f6 0%, #e2e8f0 50%, #f4f6f9 100%);
}

.auth-page--center {
    display: flex;
    align-items: center;
}

.auth-panel {
    max-width: 420px;
    margin: 0 auto;
}

.auth-card {
    border: 1px solid var(--if-border);
    border-radius: var(--if-radius);
    box-shadow: var(--if-shadow-md);
    background: var(--if-surface);
}

.auth-brand {
    text-align: center;
    margin-bottom: 1.5rem;
}

.auth-brand .app-brand-mark {
    margin: 0 auto 0.75rem;
}

/* Post-login choice */
.choice-shell {
    max-width: 920px;
    margin: 0 auto;
}

.glass-card {
    border: 1px solid var(--if-border);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: var(--if-shadow-md);
}

.context-card {
    border: 1px solid var(--if-border);
    border-radius: var(--if-radius);
    transition: box-shadow 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
    background: var(--if-surface);
}

.context-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--if-shadow-md);
    border-color: #cbd5e1;
}

.icon-pill {
    width: 42px;
    height: 42px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
}

.role-centro {
    background: rgba(13, 202, 240, 0.15);
    color: #087990;
}

.role-ente {
    background: rgba(217, 56, 30, 0.12);
    color: var(--if-accent-ente);
}

.role-volontario {
    background: rgba(34, 139, 92, 0.14);
    color: #146c3e;
}

.role-admin {
    background: var(--if-primary-soft);
    color: var(--if-primary);
}

/* Post-login: pagina e gerarchia ruoli */
body.post-login-page {
    background: linear-gradient(160deg, #eef3fb 0%, #e8edf5 42%, var(--if-bg) 100%);
}

.post-login-sep {
    border: 0;
    border-top: 1px solid rgba(36, 48, 66, 0.08);
    margin: 1.35rem 0;
}

.post-login-sep--admin {
    border: 0;
    border-top: 2px solid rgba(11, 87, 208, 0.22);
    margin: 2rem 0 1.25rem;
}

.post-login-section-title {
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--if-text-muted);
    margin-bottom: 0.75rem;
}

.context-card.context-card--cdf {
    background: linear-gradient(145deg, rgba(13, 202, 240, 0.14), rgba(255, 255, 255, 0.97));
    border-color: rgba(13, 202, 240, 0.38);
}

.context-card.context-card--ente {
    background: linear-gradient(145deg, rgba(217, 56, 30, 0.1), rgba(255, 255, 255, 0.97));
    border-color: rgba(217, 56, 30, 0.28);
}

.context-card.context-card--vol {
    background: linear-gradient(145deg, rgba(34, 139, 92, 0.12), rgba(255, 255, 255, 0.97));
    border-color: rgba(34, 139, 92, 0.28);
}

.context-card.context-card--admin {
    background: linear-gradient(145deg, var(--if-primary-soft), rgba(255, 255, 255, 0.97));
    border-color: rgba(11, 87, 208, 0.35);
}

.admin-box {
    border-top: 1px dashed var(--if-border);
    padding-top: 1rem;
    margin-top: 1.25rem;
}

/* Autocomplete / liste intelligenti */
.smart-list {
    max-height: 250px;
    overflow-y: auto;
    z-index: 1050;
    display: none;
    background: var(--if-surface);
    border: 1px solid var(--if-border);
    border-radius: var(--if-radius-sm);
    box-shadow: var(--if-shadow-md);
}

/* Bootstrap overrides */
.btn-primary {
    --bs-btn-bg: var(--if-primary);
    --bs-btn-border-color: var(--if-primary);
    --bs-btn-hover-bg: var(--if-primary-hover);
    --bs-btn-hover-border-color: var(--if-primary-hover);
    font-weight: 600;
}

.btn-outline-primary {
    --bs-btn-color: var(--if-primary);
    --bs-btn-border-color: var(--if-primary);
    font-weight: 600;
}

.card {
    border-radius: var(--if-radius);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--if-primary);
    box-shadow: 0 0 0 0.2rem rgba(11, 87, 208, 0.18);
}

/* Accordion */
.accordion-button:not(.collapsed) {
    background-color: var(--if-bg-elevated);
    color: var(--if-text);
    box-shadow: none;
}

/* Print: neutralizza sfondo */
@media print {
    body {
        background: #fff;
    }
    .app-sidebar-shell,
    .app-sidebar,
    .no-print {
        display: none !important;
    }
    .content-area {
        width: 100% !important;
    }
}
