/* ============================================================
   GESTIONALE CAF/PATRONATO — Stile principale
   Tema: Slate dark sidebar + Blue accent (#3b82f6)
============================================================ */

/* ---- Variabili ---- */
:root {
    --sidebar-width:     240px;
    --sidebar-collapsed:  68px;
    --topbar-height:      60px;

    /* Colori sidebar — identici al tema di riferimento */
    --sb-bg:             #1e293b;
    --sb-hover:          #334155;
    --sb-active:         #3b82f6;
    --sb-text:           #cbd5e1;
    --sb-label:          #475569;
    --sb-border:         rgba(255,255,255,.07);

    /* Page */
    --page-bg:           #f0f2f5;
    --card-radius:       10px;
    --shadow-sm:         0 1px 4px rgba(0,0,0,.08);
    --shadow-md:         0 4px 16px rgba(0,0,0,.12);

    /* Palette entrate/uscite */
    --c-entrata:         #10b981;
    --c-uscita:          #ef4444;

    --transition:        .18s ease;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; }
body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 14px;
    background: var(--page-bg);
    color: #1e293b;
    margin: 0;
}

/* ============================================================
   LAYOUT WRAPPER
============================================================ */
#app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* ============================================================
   SIDEBAR
============================================================ */
#sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--sb-bg);
    position: fixed;
    top: 0; left: 0;
    z-index: 1030;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width var(--transition);
}

/* Brand / Logo */
.sidebar-brand-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 22px 16px 16px;
    border-bottom: 1px solid var(--sb-border);
    text-decoration: none;
    gap: 8px;
}
.sidebar-logo {
    height: 68px;
    width: auto;
    filter: brightness(0) invert(1);
    object-fit: contain;
    transition: height var(--transition);
}
.sidebar-app-name {
    font-size: 11px;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: .6px;
    text-align: center;
    white-space: nowrap;
    transition: opacity var(--transition);
}

/* Nav */
.sidebar-nav {
    flex: 1;
    padding: 10px 10px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--sb-hover) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--sb-hover); }

.nav-section-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: var(--sb-label);
    padding: 14px 10px 4px;
    white-space: nowrap;
    transition: opacity var(--transition);
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    color: var(--sb-text);
    text-decoration: none;
    border-radius: 6px;
    margin-bottom: 2px;
    font-size: 13.5px;
    transition: background var(--transition), color var(--transition);
    white-space: nowrap;
}
.sidebar-link i {
    font-size: 1rem;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}
.sidebar-link:hover {
    background: var(--sb-hover);
    color: #fff;
}
.sidebar-link.active {
    background: var(--sb-active);
    color: #fff;
    font-weight: 600;
}

/* Sidebar footer utente */
.sidebar-footer {
    padding: 14px 12px;
    border-top: 1px solid var(--sb-border);
}
.sidebar-footer .user-line {
    font-size: 12px;
    color: #94a3b8;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity var(--transition);
}
.sidebar-footer .user-line strong { color: var(--sb-text); }
.sidebar-footer .user-line .badge { font-size: 10px; }
.sidebar-footer .btn-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    font-size: 12.5px;
    transition: opacity var(--transition);
}

/* ============================================================
   MAIN CONTENT
============================================================ */
#main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    transition: margin-left var(--transition);
}

/* ---- Topbar: safe area iOS (notch / Dynamic Island) ---- */
#topbar {
    height: var(--topbar-height);
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    padding: 0 24px;
    padding-top: env(safe-area-inset-top);
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 1020;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
    /* L'altezza cresce automaticamente per la safe area */
    min-height: calc(var(--topbar-height) + env(safe-area-inset-top));
}
.topbar-toggle {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: #64748b;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    line-height: 1;
    transition: background var(--transition);
}
.topbar-toggle:hover { background: #f1f5f9; color: #1e293b; }
.topbar-title {
    font-size: 15px;
    font-weight: 700;
    color: #1e293b;
    flex: 1;
}
.topbar-date {
    font-size: 12px;
    color: #94a3b8;
}

/* Page body */
.page-body {
    padding: 24px;
    flex: 1;
}

/* Page footer */
#page-footer {
    background: #fff;
    border-top: 1px solid #e2e8f0;
    padding: 10px 24px;
    font-size: 12px;
    color: #94a3b8;
    text-align: center;
}

/* Flash */
.flash-container { padding: 16px 24px 0; }

/* ============================================================
   CARD
============================================================ */
.card {
    border: none;
    border-radius: var(--card-radius);
    box-shadow: var(--shadow-sm);
}
.card-header {
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    font-weight: 600;
    border-radius: var(--card-radius) var(--card-radius) 0 0 !important;
    padding: 12px 18px;
    font-size: 13.5px;
}

/* ============================================================
   KPI CARDS (naming = riferimento)
============================================================ */
.kpi-card {
    border: none;
    border-radius: 12px;
    padding: 20px 24px;
    color: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,.12);
    position: relative;
    overflow: hidden;
    transition: transform var(--transition), box-shadow var(--transition);
}
.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.kpi-card::after {
    content: '';
    position: absolute;
    right: -10px; top: 50%;
    transform: translateY(-50%);
    width: 72px; height: 72px;
    border-radius: 50%;
    background: rgba(255,255,255,.1);
}
.kpi-card .kpi-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    opacity: .85;
    margin-bottom: 4px;
}
.kpi-card .kpi-value {
    font-size: 26px;
    font-weight: 800;
    margin: 0;
    line-height: 1.1;
}
.kpi-card .kpi-sub {
    font-size: 11px;
    opacity: .75;
    margin-top: 4px;
}
.kpi-card .kpi-icon {
    font-size: 2.2rem;
    opacity: .2;
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
}

/* Gradienti colori esatti dal progetto di riferimento */
.kpi-blue   { background: linear-gradient(135deg, #3b82f6, #1d4ed8); }
.kpi-green  { background: linear-gradient(135deg, #10b981, #047857); }
.kpi-red    { background: linear-gradient(135deg, #ef4444, #b91c1c); }
.kpi-orange { background: linear-gradient(135deg, #f59e0b, #b45309); }
.kpi-purple { background: linear-gradient(135deg, #8b5cf6, #6d28d9); }
.kpi-slate  { background: linear-gradient(135deg, #64748b, #334155); }

/* ============================================================
   TABELLE
============================================================ */
.table { font-size: 13.5px; }
.table thead th {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: #64748b;
    background: #f8fafc;
    border-bottom: 2px solid #e2e8f0 !important;
}
.table tbody tr { transition: background var(--transition); }
.table tbody tr:hover td { background: #f0f4ff !important; }

/* DataTables */
.dataTables_wrapper .dataTables_filter input {
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    padding: 4px 10px;
    font-size: 13px;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.dataTables_wrapper .dataTables_filter input:focus {
    border-color: var(--sb-active);
    box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}
.dataTables_wrapper .dataTables_length select {
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    padding: 3px 8px;
    font-size: 13px;
}

/* ============================================================
   BADGE STATO PRATICHE
============================================================ */
.badge-aperta           { background: #dbeafe; color: #1d4ed8; }
.badge-in_lavorazione   { background: #fef3c7; color: #92400e; }
.badge-completata       { background: #d1fae5; color: #065f46; }
.badge-annullata        { background: #f1f5f9; color: #475569; }

/* ============================================================
   IMPORTI COLORATI
============================================================ */
.text-entrata { color: var(--c-entrata) !important; font-weight: 600; }
.text-uscita  { color: var(--c-uscita)  !important; font-weight: 600; }

/* ============================================================
   AUTOCOMPLETE CLIENTE
============================================================ */
#autocomplete-list {
    position: absolute;
    z-index: 9999;
    width: 100%;
    max-height: 220px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 8px 24px rgba(0,0,0,.1);
}
#autocomplete-list .autocomplete-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    transition: background var(--transition);
}
#autocomplete-list .autocomplete-item:hover { background: #f0f4ff; }

/* ============================================================
   BOTTONI
============================================================ */
.btn-primary {
    background: var(--sb-active);
    border-color: var(--sb-active);
}
.btn-primary:hover, .btn-primary:focus {
    background: #2563eb;
    border-color: #2563eb;
}
.btn { border-radius: 6px; font-size: 13.5px; }
.btn-sm { border-radius: 5px; font-size: 12.5px; }

/* ============================================================
   LOGIN PAGE
============================================================ */
.login-wrapper {
    min-height: 100vh;
    background: var(--sb-bg) url('/assets/sfondo.jpg') center/cover no-repeat fixed;
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-box {
    background: rgba(255,255,255,.97);
    border-radius: 16px;
    padding: 44px 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-logo {
    height: 110px;
    width: auto;
    display: block;
    margin: 0 auto 14px;
    object-fit: contain;
}
.login-title {
    font-size: 19px;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 4px;
}
.login-sub {
    font-size: 13px;
    color: #64748b;
    margin-bottom: 28px;
}

/* ============================================================
   RICERCA GLOBALE
============================================================ */
.global-search-wrap {
    position: relative;
}
.global-search-wrap .form-control:focus {
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
    border-color: var(--sb-active);
}
#globalSearchResults {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    min-width: 340px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,.15);
    z-index: 2000;
    max-height: 420px;
    overflow-y: auto;
}
.gs-group-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: #94a3b8;
    padding: 8px 12px 4px;
}
.gs-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    transition: background var(--transition);
    border-bottom: 1px solid #f1f5f9;
}
.gs-item:last-child { border-bottom: none; }
.gs-item:hover { background: #f0f4ff; color: inherit; }
.gs-item-icon {
    width: 32px; height: 32px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: .85rem;
    flex-shrink: 0;
}
.gs-item-icon.ci-primary  { background: #dbeafe; color: #1d4ed8; }
.gs-item-icon.ci-success  { background: #d1fae5; color: #065f46; }
.gs-item-icon.ci-danger   { background: #fee2e2; color: #b91c1c; }
.gs-item-text { flex: 1; min-width: 0; }
.gs-item-label { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gs-item-sub   { font-size: 11px; color: #64748b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gs-empty { padding: 16px 12px; text-align: center; color: #94a3b8; font-size: 13px; }

/* ============================================================
   MOBILE OVERLAY
============================================================ */
#sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 1025;
}

/* ============================================================
   RESPONSIVE
============================================================ */
@media (max-width: 991.98px) {
    #sidebar { transform: translateX(-100%); transition: transform var(--transition); }
    #sidebar.show { transform: translateX(0); }
    #sidebar-overlay.show { display: block; }
    #main-content { margin-left: 0; }
}

@media (min-width: 992px) {
    body.sidebar-collapsed #sidebar             { width: var(--sidebar-collapsed); }
    body.sidebar-collapsed .sidebar-app-name,
    body.sidebar-collapsed .nav-section-label,
    body.sidebar-collapsed .sidebar-link span,
    body.sidebar-collapsed .sidebar-footer .user-line,
    body.sidebar-collapsed .sidebar-footer .btn-logout span { display: none; }
    body.sidebar-collapsed .sidebar-link        { justify-content: center; padding: 8px; }
    body.sidebar-collapsed .sidebar-logo        { height: 36px; }
    body.sidebar-collapsed .sidebar-brand-wrap  { padding: 16px 8px; }
    body.sidebar-collapsed .sidebar-footer      { padding: 10px 6px; }
    body.sidebar-collapsed .sidebar-footer .btn-logout { padding: 6px; }
    body.sidebar-collapsed #main-content        { margin-left: var(--sidebar-collapsed); }
}

/* ---- Sidebar flat — voci sempre visibili, sezioni come intestazioni ---- */
.sidebar-sublink { font-size: 13.5px !important; padding: 7px 12px !important; }

/* ============================================================
   RESPONSIVE MOBILE — PWA / App nativa feel
   ============================================================ */

/* ---- Topbar hamburger sempre visibile su mobile ---- */
@media (max-width: 767.98px) {
    /* Topbar fixed, altezza base + safe area iOS */
    #topbar {
        padding: env(safe-area-inset-top) 12px 0;
        min-height: calc(56px + env(safe-area-inset-top));
        position: fixed;
        top: 0; left: 0; right: 0;
        z-index: 1050;
    }
    .topbar-toggle {
        display: flex;
        width: 44px; height: 44px;
        font-size: 22px;
    }
    /* Spinge il contenuto sotto la topbar fissa (56px base + safe area) */
    #main-content { padding-top: calc(56px + env(safe-area-inset-top)); }
    .page-body { padding: 14px 12px; }

    /* Sidebar overlay mobile (già funziona) */
    #sidebar { z-index: 1060; }

    /* Nasconde elementi non essenziali nella topbar */
    .topbar-date { display: none !important; }
    #globalSearchInput { width: 140px !important; }

    /* KPI card: 2 colonne su mobile */
    .row > [class*="col-xl-3"] { flex: 0 0 50%; max-width: 50%; }
    .kpi-card { padding: 14px 12px; }
    .kpi-value { font-size: 1.2rem; }

    /* Bottoni azione principali → larghezza piena */
    .btn-new-action {
        width: 100%;
        justify-content: center;
    }

    /* Tabelle: forza overflow su mobile se responsive DT non attivo */
    .table-responsive { -webkit-overflow-scrolling: touch; }

    /* Form modali: più spaziosi per il touch */
    .modal-dialog { margin: 0.5rem; }
    .form-control, .form-select { font-size: 16px; } /* evita zoom su iOS */
    .btn { min-height: 40px; }

    /* Card padding ridotto */
    .card-body { padding: 12px; }

    /* Footer compatto */
    #page-footer { font-size: 10px; padding: 6px 12px; }
    #page-footer p { font-size: 10px; }
}

/* ---- FAB (Floating Action Button) su mobile ---- */
.fab-mobile {
    display: none;
}
@media (max-width: 767.98px) {
    .fab-mobile {
        display: flex;
        position: fixed;
        bottom: 20px;
        right: 20px;
        z-index: 1040;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: #3b82f6;
        color: #fff;
        font-size: 24px;
        border: none;
        box-shadow: 0 4px 16px rgba(59,130,246,.5);
        align-items: center;
        justify-content: center;
        text-decoration: none;
        transition: transform .15s, box-shadow .15s;
    }
    .fab-mobile:hover, .fab-mobile:focus {
        color: #fff;
        transform: scale(1.08);
        box-shadow: 0 6px 20px rgba(59,130,246,.6);
    }
    /* Nascondi il bottone "Nuova X" desktop quando FAB è visibile */
    .hide-on-mobile { display: none !important; }
}
@media (min-width: 768px) {
    .fab-mobile { display: none !important; }
    .hide-on-mobile { display: inline-flex !important; }
}


/* ---- DataTables Responsive child rows ---- */
table.dataTable.dtr-inline.collapsed > tbody > tr > td.dtr-control::before,
table.dataTable.dtr-inline.collapsed > tbody > tr > th.dtr-control::before {
    background-color: #3b82f6;
}
