:root {
    --ink: #17231e;
    --green: #1f654b;
    --paper: #f4f3ee;
}

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 250px;
    min-height: 100vh;
    background: var(--ink);
    display: flex;
    flex-direction: column;
    flex: 0 0 250px;
    overflow: hidden;
    transition: flex-basis .18s ease, transform .18s ease, width .18s ease;
}

.brand {
    color: white;
    font-weight: 800;
    letter-spacing: .12em;
    white-space: nowrap;
}

.brand small {
    display: block;
    color: #94b6a5;
    font-size: .65rem;
}

.nav-link {
    align-items: center;
    color: #c6d1cb;
    border-radius: 6px;
    display: flex;
    gap: .75rem;
    padding: .7rem 1rem;
    white-space: nowrap;
}

.nav-link.active,
.nav-link:hover {
    color: white;
    background: #2b3c34;
}

.app-shell.sidebar-collapsed .sidebar {
    flex-basis: 82px;
    width: 82px;
}

.app-shell.sidebar-collapsed .brand small,
.app-shell.sidebar-collapsed .nav-label,
.app-shell.sidebar-collapsed .user-context,
.app-shell.sidebar-collapsed .user-name,
.app-shell.sidebar-collapsed .sidebar-user form {
    display: none;
}

.app-shell.sidebar-collapsed .brand-full {
    display: none;
}

.app-shell.sidebar-collapsed .brand::before {
    content: "M";
    display: block;
}

.app-shell.sidebar-collapsed .sidebar {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
}

.app-shell.sidebar-collapsed .nav-link {
    height: 42px;
    justify-content: center;
    padding-left: .55rem;
    padding-right: .55rem;
}

.app-shell.sidebar-collapsed .nav-label {
    display: none;
}

.app-shell.sidebar-collapsed .nav-link::before {
    align-items: center;
    border: 1px solid rgba(255, 255, 255, .18);
    border-radius: 6px;
    content: attr(data-short);
    display: inline-flex;
    flex: 0 0 28px;
    font-size: .75rem;
    font-weight: 800;
    height: 28px;
    justify-content: center;
}

.app-shell.sidebar-collapsed .sidebar-user {
    text-align: center;
}

.topbar {
    align-items: center;
    background: white;
    border-bottom: 1px solid #ddd;
    color: #66736d;
    display: flex;
    gap: 1rem;
    min-height: 57px;
}

.menu-toggle {
    align-items: center;
    background: transparent;
    border: 1px solid #d7d7d2;
    border-radius: 6px;
    display: inline-flex;
    flex-direction: column;
    gap: 4px;
    height: 36px;
    justify-content: center;
    padding: 0;
    width: 40px;
    cursor: pointer;
}

.menu-toggle span {
    background: var(--ink);
    border-radius: 1px;
    display: block;
    height: 2px;
    width: 18px;
}

.menu-backdrop {
    display: none;
}

.app-main {
    background: var(--paper);
    flex: 1 1 auto;
    min-height: 100vh;
    min-width: 0;
}

h1 {
    font-family: Georgia, serif;
    font-size: 2.5rem;
    color: var(--ink);
}

h2 {
    font-size: 1.1rem;
    color: var(--ink);
}

.eyebrow {
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .14em;
    color: var(--green);
}

.panel,
.stat {
    background: #fff;
    border: 1px solid #e3e1d9;
    border-radius: 8px;
    padding: 1.4rem;
    color: var(--ink);
    text-decoration: none;
}

.stat small,
.stat strong {
    display: block;
}

.stat strong {
    font: 2.5rem Georgia;
    margin-top: .7rem;
}

.stat.accent {
    background: var(--green);
    color: white;
}

.action-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    border-bottom: 1px solid #eee;
    color: var(--ink);
    text-decoration: none;
}

.action-row small {
    display: block;
    color: #77827d;
}

/* Badges de statut colores par categorie */
.status {
    background: #e1eee7;
    color: #216148;
    font-size: .75rem;
    padding: .3rem .65rem;
    border-radius: 4px;
    white-space: nowrap;
}

.status-encours {
    background: #d4edda;
    color: #155724;
}

.status-termine {
    background: #cce5ff;
    color: #004085;
}

.status-enattente,
.status-enpreparation,
.status-enreflexion {
    background: #fff3cd;
    color: #856404;
}

.status-aetudier {
    background: #e9ecef;
    color: #495057;
}

.status-abandonne {
    background: #f8d7da;
    color: #721c24;
}

.status-enretard {
    background: #f8d7da;
    color: #721c24;
}

.status-critique {
    background: #f8d7da;
    color: #721c24;
}

.status-haute {
    background: #fff3cd;
    color: #856404;
}

.status-moyenne {
    background: #e1eee7;
    color: #216148;
}

.status-faible {
    background: #e9ecef;
    color: #495057;
}

.axis:hover {
    border-color: var(--green);
    transform: translateY(-2px);
}

label {
    font-size: .75rem;
    text-transform: uppercase;
    color: #78827e;
    font-weight: bold;
}

.comment {
    border-left: 3px solid #c8ddd1;
    padding-left: 1rem;
    margin: 1rem 0;
}

th {
    font-size: .72rem;
    text-transform: uppercase;
    color: #718078 !important;
    padding: 1rem !important;
}

td {
    padding: 1rem !important;
}

.group-header {
    align-items: center;
    background: #fff;
    border: 0;
    border-bottom: 1px solid #e3e1d9;
    color: var(--ink);
    display: flex;
    font-weight: 700;
    justify-content: space-between;
    padding: 1rem 1.4rem;
    text-align: left;
    width: 100%;
}

.child-row td:first-child {
    padding-left: 2rem !important;
}

.login-shell {
    align-items: center;
    display: flex;
    justify-content: center;
    min-height: 80vh;
}

.login-panel,
.narrow {
    max-width: 460px;
}

.calendar-nav {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    justify-content: flex-end;
}

.calendar-title {
    align-items: center;
    border-bottom: 1px solid #e3e1d9;
    display: flex;
    justify-content: space-between;
    padding: 1rem 1.4rem;
}

.calendar-title h2 {
    margin: 0;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(120px, 1fr));
}

.calendar-weekday {
    background: #f8f7f2;
    border-bottom: 1px solid #e3e1d9;
    color: #718078;
    font-size: .72rem;
    font-weight: 800;
    padding: .75rem;
    text-transform: uppercase;
}

.calendar-day {
    border-bottom: 1px solid #e3e1d9;
    border-right: 1px solid #e3e1d9;
    min-height: 150px;
    padding: .65rem;
}

.calendar-day.muted {
    background: #faf9f5;
    color: #a0a7a3;
}

.calendar-day.today {
    box-shadow: inset 0 0 0 2px var(--green);
}

.calendar-day-number {
    font-weight: 800;
    margin-bottom: .45rem;
}

.calendar-event {
    border-left: 4px solid #9aa79f;
    color: var(--ink);
    display: block;
    font-size: .78rem;
    margin-bottom: .35rem;
    padding: .35rem .4rem;
    text-decoration: none;
}

.calendar-event span,
.calendar-legend {
    display: block;
    font-size: .65rem;
    font-weight: 800;
    text-transform: uppercase;
}

.calendar-event b {
    display: block;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.calendar-event.start,
.calendar-legend.start {
    background: #e9f1f8;
    border-color: #3175a4;
}

.calendar-event.due,
.calendar-legend.due {
    background: #f9ece8;
    border-color: #b14b34;
}

.calendar-event.done,
.calendar-legend.done {
    background: #e6f2ea;
    border-color: #2f7f52;
}

.calendar-event.milestone,
.calendar-legend.milestone {
    background: #f6f0dc;
    border-color: #a98628;
}

.calendar-event.milestone-done,
.calendar-legend.milestone-done {
    background: #ece8f5;
    border-color: #7655a6;
}

.calendar-event.municipal,
.calendar-legend.municipal,
.status.municipal {
    background: #e9f1f4;
    border-color: #3e7f91;
    color: #23515e;
}

.calendar-legend {
    border-left: 4px solid;
    padding: .35rem .55rem;
}

.event-user-grid {
    display: grid;
    gap: .5rem;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.event-user-option {
    align-items: center;
    background: #f8f7f2;
    border: 1px solid #e3e1d9;
    border-radius: 8px;
    color: var(--ink);
    display: flex;
    gap: .6rem;
    padding: .7rem .85rem;
    text-transform: none;
}

.calendar-list-day {
    border-top: 1px solid #eee;
    padding-top: 1rem;
}

.maintenance-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.maintenance-grid div {
    background: #f8f7f2;
    border: 1px solid #e3e1d9;
    border-radius: 8px;
    padding: 1rem;
}

.maintenance-grid small,
.maintenance-grid b {
    display: block;
}

.maintenance-grid small {
    color: #718078;
    font-size: .7rem;
    font-weight: 800;
    margin-bottom: .45rem;
    text-transform: uppercase;
}

.maintenance-grid b {
    overflow-wrap: anywhere;
}

.script-output {
    background: #111b17;
    border-radius: 8px;
    color: #d8eadf;
    max-height: 460px;
    overflow: auto;
    padding: 1rem;
    white-space: pre-wrap;
}

@media (max-width: 900px) {
    .app-shell {
        display: block;
    }

    .sidebar {
        bottom: 0;
        box-shadow: 16px 0 30px rgba(0, 0, 0, .18);
        left: 0;
        min-height: 100vh;
        position: fixed;
        top: 0;
        transform: translateX(-100%);
        width: min(82vw, 310px);
        z-index: 20;
    }

    .app-shell.mobile-menu-open .sidebar {
        transform: translateX(0);
    }

    .app-shell.mobile-menu-open .menu-backdrop {
        background: rgba(23, 35, 30, .45);
        border: 0;
        bottom: 0;
        display: block;
        left: 0;
        padding: 0;
        position: fixed;
        right: 0;
        top: 0;
        z-index: 10;
    }

    .app-shell.sidebar-collapsed .sidebar,
    .app-shell.mobile-menu-open .sidebar {
        flex-basis: auto;
        width: min(82vw, 310px);
    }

    .app-shell.sidebar-collapsed .brand-full,
    .app-shell.sidebar-collapsed .brand small,
    .app-shell.sidebar-collapsed .nav-label,
    .app-shell.sidebar-collapsed .user-context,
    .app-shell.sidebar-collapsed .user-name,
    .app-shell.sidebar-collapsed .sidebar-user form {
        display: initial;
    }

    .app-shell.sidebar-collapsed .brand-full {
        display: initial;
        font-size: inherit;
        letter-spacing: .12em;
        overflow: visible;
        width: auto;
    }

    .app-shell.sidebar-collapsed .brand::before {
        display: none;
    }

    .app-shell.sidebar-collapsed .nav-link,
    .app-shell.mobile-menu-open .nav-link {
        height: auto;
        justify-content: flex-start;
        padding: .7rem 1rem;
    }

    .topbar {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
        position: sticky;
        top: 0;
        z-index: 5;
    }

    .app-main > article > .d-flex {
        align-items: flex-start !important;
        flex-direction: column;
        gap: 1rem;
    }

    article.p-5 {
        padding: 1rem !important;
    }

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

    .calendar-weekday {
        display: none;
    }

    .calendar-day {
        min-height: auto;
    }

    /* Zones tactiles minimum 44px (normes Apple/Google) */
    .btn,
    .btn-sm,
    .nav-link,
    .action-row {
        min-height: 44px;
    }

    .btn-sm {
        padding: .5rem .75rem;
        font-size: .85rem;
    }

    /* Empecher le zoom auto sur iOS lors du focus sur les inputs */
    input,
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* Mobile : tableaux d'actions en cartes empilees */
@media (max-width: 600px) {
    .table-cards thead {
        display: none;
    }

    .table-cards tbody {
        display: grid;
        gap: .75rem;
    }

    .table-cards tr {
        background: #fff;
        border: 1px solid #e3e1d9;
        border-radius: 8px;
        display: grid;
        gap: .25rem;
        padding: 1rem;
    }

    .table-cards td {
        border: 0 !important;
        padding: .15rem 0 !important;
    }

    .table-cards td:empty {
        display: none;
    }

    .table-cards td[data-label]::before {
        color: #718078;
        content: attr(data-label) ": ";
        font-size: .72rem;
        font-weight: 800;
        text-transform: uppercase;
    }

    /* Le bouton Ouvrir occupe toute la largeur en mode carte */
    .table-cards td:last-child .btn {
        width: 100%;
        margin-top: .5rem;
    }

    /* Stats en 2 colonnes au lieu de 4 */
    .stat-grid .col-md-3 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    .stat strong {
        font-size: 1.8rem;
    }
}

/* Panneau d'alertes */
.alert-panel {
    border-left: 4px solid #dc3545;
}

/* Timeline verticale pour les echeances */
.timeline {
    display: grid;
    gap: .5rem;
}

.timeline-item {
    align-items: flex-start;
    border-bottom: 1px solid #eee;
    color: var(--ink);
    display: flex;
    gap: 1rem;
    padding: .75rem 0;
    text-decoration: none;
}

.timeline-item:last-child {
    border-bottom: 0;
}

.timeline-date {
    background: #f4f3ee;
    border-radius: 6px;
    flex: 0 0 auto;
    font-size: .85rem;
    font-weight: 800;
    min-width: 52px;
    padding: .35rem .5rem;
    text-align: center;
}

.timeline-body {
    flex: 1 1 auto;
}

.timeline-body small {
    display: block;
    color: #718078;
    font-size: .72rem;
    font-weight: 800;
    text-transform: uppercase;
}

.timeline-body b {
    display: block;
}

/* Section activite recente : masquee par defaut sur mobile */
@media (max-width: 600px) {
    .activity-section {
        display: none;
    }
}

.maintenance-request-list,
.maintenance-log-list {
    display: grid;
    gap: .75rem;
}

.maintenance-request-card,
.maintenance-log-details {
    background: #f8f7f2;
    border: 1px solid #e3e1d9;
    border-radius: 8px;
    padding: 1rem;
}

.maintenance-request-card span,
.maintenance-request-card strong {
    display: block;
    overflow-wrap: anywhere;
}

.maintenance-log-details summary {
    cursor: pointer;
    font-weight: 700;
    overflow-wrap: anywhere;
}
