/* Domelia - stile custom con sidebar */

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    min-height: 100vh;
}

/* ============ SIDEBAR ============ */
:root {
    --sidebar-width: 250px;
    --sidebar-bg: #1e293b;
    --sidebar-bg-hover: #334155;
    --sidebar-active: #0d6efd;
}

.sidebar,
.sidebar-offcanvas {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: #fff;
}

/* Desktop: sidebar fissa */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1030;
    box-shadow: 0 0 1rem rgba(0,0,0,.1);
}

/* Offcanvas mobile colorato come desktop */
.sidebar-offcanvas {
    background: var(--sidebar-bg);
    color: #fff;
}

.sidebar-header h4 {
    font-size: 1.25rem;
}

.sidebar-nav .nav-link {
    color: rgba(255,255,255,.75);
    border-radius: .5rem;
    padding: .65rem .9rem;
    margin-bottom: .15rem;
    font-weight: 500;
    transition: background .15s, color .15s;
}
.sidebar-nav .nav-link:hover {
    background: var(--sidebar-bg-hover);
    color: #fff;
}
.sidebar-nav .nav-link.active {
    background: var(--sidebar-active);
    color: #fff;
}
.sidebar-nav .nav-link i {
    width: 20px;
    text-align: center;
}

.sidebar-section-title {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: rgba(255,255,255,.45);
    padding: .25rem .9rem;
    margin-bottom: .25rem;
}

/* Sottomenu sidebar */
.submenu-arrow {
    font-size: .8rem;
    transition: transform .2s ease;
}
.sidebar-nav .nav-link[aria-expanded="true"] .submenu-arrow {
    transform: rotate(180deg);
}
.sidebar-nav .nav-link[data-bs-toggle="collapse"] {
    /* Override per la voce padre che ha sia link che chevron */
    cursor: pointer;
}

.sidebar-submenu {
    padding-left: .5rem;
    margin-top: .15rem;
    border-left: 2px solid rgba(255,255,255,.1);
    margin-left: .9rem;
}
.sidebar-submenu .nav-link {
    font-size: .85rem;
    padding: .4rem .8rem;
    color: rgba(255,255,255,.65);
    border-radius: .4rem;
    margin-bottom: .1rem;
}
.sidebar-submenu .nav-link:hover {
    background: var(--sidebar-bg-hover);
    color: #fff;
}
.sidebar-submenu .nav-link.active {
    background: var(--sidebar-active);
    color: #fff;
}
.sidebar-submenu .nav-link i {
    font-size: .85rem;
    width: 18px;
    text-align: center;
}

.sidebar-footer .dropdown-toggle::after {
    margin-left: auto;
}
.sidebar-footer .dropdown-menu {
    min-width: 200px;
}

/* Pulsante backup in fondo alla sidebar */
.sidebar-backup .btn {
    color: rgba(255,255,255,.85);
    border-color: rgba(255,255,255,.25);
    background: transparent;
    font-size: .85rem;
    font-weight: 500;
    transition: background .15s, border-color .15s;
}
.sidebar-backup .btn:hover {
    background: var(--sidebar-bg-hover);
    border-color: rgba(255,255,255,.45);
    color: #fff;
}
.sidebar-backup .btn i {
    font-size: 1rem;
}

/* ============ MAIN WRAPPER ============ */
.main-wrapper {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
.main-wrapper > main {
    flex-grow: 1;
}

/* Mobile: nessun margine, sidebar nascosta */
@media (max-width: 991.98px) {
    .main-wrapper {
        margin-left: 0;
        padding-top: 56px; /* spazio per la topbar mobile */
    }
}

/* Topbar mobile fissa */
.mobile-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    z-index: 1020;
}

/* ============ TASK CARDS ============ */
.task-card {
    transition: transform .15s ease, box-shadow .15s ease;
}
.task-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 .5rem 1rem rgba(0,0,0,.08) !important;
}

.card.shadow-sm {
    border-radius: .75rem;
}

.display-6 {
    font-size: 2rem;
}

footer {
    margin-top: 3rem;
}

.nav-pills .nav-link {
    color: #495057;
}
.nav-pills .nav-link.active {
    background-color: #0d6efd;
}

@media (max-width: 576px) {
    .display-6 { font-size: 1.5rem; }
}

/* ============ CALENDARIO ============ */
.calendar-grid {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}
.calendar-grid thead th {
    background: #f8f9fa;
    text-align: center;
    padding: .6rem .3rem;
    font-size: .8rem;
    font-weight: 600;
    color: #495057;
    border-bottom: 1px solid #dee2e6;
}
.calendar-grid thead th.weekend {
    color: #dc3545;
}
.calendar-grid td {
    width: 14.285%;
    height: 110px;
    vertical-align: top;
    padding: .35rem;
    border: 1px solid #f1f3f5;
    background: #fff;
    overflow: hidden;
    position: relative;
}
.calendar-grid td.empty {
    background: #fafbfc;
}
.calendar-grid td.weekend:not(.empty) {
    background: #fefcfc;
}
.calendar-grid td.today {
    background: #e7f1ff;
    box-shadow: inset 0 0 0 2px #0d6efd;
}
.calendar-grid .day-number {
    font-weight: 600;
    font-size: .85rem;
    color: #495057;
    margin-bottom: .25rem;
}
.calendar-grid .today .day-number {
    color: #0d6efd;
}

.event-pill {
    display: block;
    font-size: .7rem;
    padding: 2px 6px;
    margin-bottom: 2px;
    border-radius: .25rem;
    color: #fff !important;
    text-decoration: none !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}
.event-pill:hover {
    filter: brightness(0.9);
}
.event-pill .event-text {
    font-weight: 500;
}

.legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
}

.badge-tipo {
    min-width: 90px;
    text-align: center;
}

@media (max-width: 768px) {
    .calendar-grid td {
        height: 80px;
        font-size: .75rem;
    }
    .event-pill .event-text {
        display: none;
    }
    .event-pill {
        padding: 2px 4px;
        text-align: center;
    }
}

/* Click sulle celle del calendario */
.calendar-grid td.clickable,
.week-grid td.clickable {
    cursor: pointer;
    transition: background .15s ease;
}
.calendar-grid td.clickable:hover {
    background: #eef4ff;
}

/* Vista settimanale */
.week-grid {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}
.week-grid thead th {
    width: 14.285%;
    padding: .6rem .3rem;
    text-align: center;
    border-bottom: 2px solid #dee2e6;
    background: #f8f9fa;
    vertical-align: top;
}
.week-grid thead th.weekend { color: #dc3545; }
.week-grid thead th.today {
    background: #e7f1ff;
    border-bottom-color: #0d6efd;
}
.week-grid thead th.today .h4 { color: #0d6efd; }
.week-grid tbody td {
    width: 14.285%;
    min-height: 320px;
    height: 320px;
    vertical-align: top;
    padding: .4rem;
    border: 1px solid #f1f3f5;
    background: #fff;
    overflow-y: auto;
}
.week-grid tbody td.weekend { background: #fefcfc; }
.week-grid tbody td.today {
    background: #e7f1ff;
    box-shadow: inset 2px 0 0 #0d6efd, inset -2px 0 0 #0d6efd, inset 0 -2px 0 #0d6efd;
}
.week-grid tbody td.clickable:hover { background: #eef4ff; }

.event-pill-week {
    padding: .4rem .5rem;
    margin-bottom: .35rem;
    border-radius: .25rem;
    background: #f8f9fa;
}
.event-pill-week .x-small {
    font-size: .7rem;
}

@media (max-width: 768px) {
    .week-grid tbody td {
        min-height: 180px;
        height: 180px;
    }
    .week-grid thead th .h4 {
        font-size: 1.1rem;
    }
}

/* Modal dettagli giorno */
#dettagliGiornoModal .list-group-item {
    transition: background .15s;
}
#dettagliGiornoModal .list-group-item:hover {
    background: #f8f9fa;
}

/* ============================================================
   MOBILE LAYER
   Ogni nuova feature deve rispettare queste regole:
   - touch target >= 44px
   - tabelle dati: usare class="table table-mobile" e data-label su td
   - container: usare px-md-4 e ridurre padding su <576px
   - modal: usare modal-fullscreen-sm-down per UX migliore
   ============================================================ */

/* Tabelle responsive: su mobile diventano "card view" */
@media (max-width: 767.98px) {
    .table-mobile thead {
        display: none;
    }
    .table-mobile,
    .table-mobile tbody,
    .table-mobile tr,
    .table-mobile td {
        display: block;
        width: 100%;
    }
    .table-mobile tr {
        background: #fff;
        border: 1px solid #e9ecef !important;
        border-radius: .5rem;
        padding: .75rem;
        margin-bottom: .75rem;
        box-shadow: 0 1px 3px rgba(0,0,0,.04);
    }
    .table-mobile tr.table-danger {
        border-left: 4px solid #dc3545 !important;
    }
    .table-mobile td {
        border: none !important;
        padding: .35rem 0 !important;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: .5rem;
        text-align: right;
    }
    .table-mobile td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #6c757d;
        font-size: .8rem;
        text-align: left;
        flex: 0 0 40%;
        text-transform: uppercase;
        letter-spacing: .03em;
    }
    .table-mobile td.text-end {
        text-align: right;
        justify-content: flex-end;
    }
    /* Le celle azioni e quelle senza data-label vanno a tutta larghezza */
    .table-mobile td[data-label="Azioni"],
    .table-mobile td:last-child {
        border-top: 1px dashed #e9ecef !important;
        padding-top: .6rem !important;
        margin-top: .25rem;
        justify-content: flex-end;
        flex-wrap: wrap;
    }
    .table-mobile td[data-label="Azioni"]::before {
        display: none;
    }

    /* Container padding ridotto su mobile */
    main.container-fluid,
    main.container {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }

    /* Headings page leggermente piu' piccoli */
    main h2 { font-size: 1.4rem; }
    main h2 + p { font-size: .85rem; }

    /* Touch target: bottoni piccoli almeno 38px in altezza */
    .btn-sm {
        min-height: 38px;
        padding-top: .35rem;
        padding-bottom: .35rem;
    }
    /* Bottoni nelle celle azioni dei task/bollette/auto un po' piu' grandi */
    .table-mobile td .btn {
        min-height: 40px;
        min-width: 40px;
    }

    /* Stat cards: 2 per riga sempre, padding ridotto */
    .row.g-3 .card-body { padding: .75rem; }
    .display-6 { font-size: 1.4rem; }

    /* Modal fullscreen su small screens */
    .modal-dialog:not(.modal-fullscreen-sm-down) {
        margin: .5rem;
    }
    .modal-lg .modal-dialog,
    .modal:not(.modal-fullscreen-sm-down) .modal-dialog.modal-lg {
        max-width: calc(100% - 1rem);
    }

    /* Form: stack pulsanti modali sotto */
    .modal-footer .btn { min-height: 44px; }

    /* Nav pills filtri: piu' compatti */
    .nav-pills .nav-link {
        padding: .4rem .7rem;
        font-size: .85rem;
    }

    /* Card spacing */
    .card-body { padding: 1rem; }

    /* Calendario mese: nasconde colonna weekend separator visivo */
    .calendar-grid td { padding: .25rem !important; }
    .calendar-grid .day-number {
        font-size: .75rem;
    }
    .event-pill {
        font-size: .65rem;
        padding: 1px 3px;
    }

    /* Calendario settimana: scrolla orizzontalmente se necessario, ma tieni leggibile */
    .week-grid {
        font-size: .8rem;
    }
    .week-grid thead th {
        padding: .35rem .15rem;
    }
    .week-grid thead th .h4 { font-size: 1rem; }
    .week-grid thead th .small { font-size: .65rem; }
    .week-grid tbody td { padding: .25rem; }
    .event-pill-week { padding: .25rem .35rem; }
    .event-pill-week .small { font-size: .7rem; }
    .event-pill-week .x-small { font-size: .6rem; }

    /* Sidebar mobile: rimuovi indentazioni eccessive */
    .sidebar-offcanvas { width: 80vw; max-width: 280px; }

    /* Filtri form: bottoni stack su mobile */
    form .col-md-3,
    form .col-md-4 {
        margin-bottom: .5rem;
    }

    /* Stack action buttons negli header pagina */
    .d-flex.justify-content-between.flex-wrap > .btn {
        width: 100%;
        margin-top: .5rem;
    }

    /* Riduce le label nei filtri */
    .form-check-label.badge { font-size: .75rem; }

    /* Lista prossime scadenze: layout vertical su mobile */
    .list-group-item.d-flex {
        flex-wrap: wrap !important;
    }

    /* Badge tipo a larghezza intera quando solo in mobile */
    .badge-tipo { min-width: auto; }
}

/* Screen molto piccoli (<= 380px) */
@media (max-width: 380px) {
    main h2 { font-size: 1.2rem; }
    .display-6 { font-size: 1.2rem; }
    .h3 { font-size: 1rem; }
    .card-body { padding: .75rem; }
}

/* Migliora il tap su iOS: rimuove highlight blu fastidioso */
a, button { -webkit-tap-highlight-color: transparent; }

/* Form input su mobile: 16px previene zoom iOS */
@media (max-width: 767.98px) {
    .form-control, .form-select { font-size: 16px; }
}
