:root {
    --app-primary: #155eef;
    --app-primary-dark: #0f46c7;
    --app-primary-soft: #eef4ff;
    --app-accent: #0f766e;
    --app-danger: #b42318;
    --app-warning: #b54708;
    --app-success: #067647;
    --app-bg: #f6f8fb;
    --app-surface: #ffffff;
    --app-surface-muted: #f9fafb;
    --app-border: #d9e1ec;
    --app-border-soft: #e8edf4;
    --app-text: #172033;
    --app-muted: #627084;
    --app-shadow: 0 10px 28px rgba(18, 31, 53, .06);
    --app-radius: 8px;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100vh;
    background:
        linear-gradient(180deg, #fbfcff 0, var(--app-bg) 280px),
        var(--app-bg);
    color: var(--app-text);
    font-size: 15px;
    line-height: 1.48;
}

a {
    color: var(--app-primary);
    overflow-wrap: anywhere;
    text-decoration-thickness: .08em;
    text-underline-offset: .18em;
}

a:hover {
    color: var(--app-primary-dark);
}

img,
svg {
    max-width: 100%;
}

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

.sidebar {
    width: 268px;
    flex: 0 0 268px;
    background: var(--app-surface);
    border-right: 1px solid var(--app-border);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    min-height: 70px;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--app-border-soft);
    color: var(--app-primary);
    font-weight: 800;
    letter-spacing: 0;
    text-decoration: none;
}

.sidebar .nav {
    padding: 1rem !important;
}

.nav-link {
    min-height: 42px;
    padding: .62rem .72rem;
    color: #465568;
    border-radius: 7px;
    display: flex;
    align-items: center;
    gap: .65rem;
    font-weight: 600;
    text-decoration: none;
}

.nav-link i {
    width: 1.15rem;
    color: #6b7890;
    text-align: center;
}

.nav-link.active,
.nav-link:hover {
    color: var(--app-primary);
    background: var(--app-primary-soft);
}

.nav-link.active i,
.nav-link:hover i {
    color: var(--app-primary);
}

.main-content {
    flex: 1;
    min-width: 0;
    padding: 1.5rem;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.topbar > div {
    min-width: 0;
}

.topbar h1 {
    color: var(--app-text);
    font-size: clamp(1.25rem, 1vw + 1rem, 1.65rem);
    font-weight: 750;
    letter-spacing: 0;
    overflow-wrap: anywhere;
}

.panel,
.metric,
.module {
    background: var(--app-surface);
    border: 1px solid var(--app-border-soft);
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow);
}

.module {
    padding: 1rem;
}

.panel {
    padding: 1.05rem;
}

.panel h1,
.panel h2,
.panel h3 {
    color: var(--app-text);
    letter-spacing: 0;
}

.panel h2 {
    font-size: 1rem;
    font-weight: 750;
    margin-bottom: .9rem;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.panel-header h2 {
    margin-bottom: 0;
}

.metric {
    display: flex;
    align-items: center;
    gap: .95rem;
    min-height: 106px;
    padding: 1rem;
}

.metric i {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    color: var(--app-primary);
    background: var(--app-primary-soft);
    font-size: 1.35rem;
}

.metric .fs-3 {
    color: var(--app-text);
    line-height: 1.1;
}

.text-muted {
    color: var(--app-muted) !important;
}

.alert {
    border-radius: var(--app-radius);
    border-color: var(--app-border-soft);
}

.badge {
    max-width: 100%;
    white-space: normal;
    text-align: left;
    line-height: 1.25;
    font-weight: 700;
    border-radius: 6px;
}

.table-responsive {
    border: 1px solid var(--app-border-soft);
    border-radius: var(--app-radius);
    background: #fff;
}

.table {
    min-width: 720px;
    margin-bottom: 0;
}

.table th {
    color: #4a5668;
    background: var(--app-surface-muted);
    border-bottom-color: var(--app-border);
    font-size: .78rem;
    font-weight: 750;
    letter-spacing: 0;
    text-transform: uppercase;
}

.table td {
    color: var(--app-text);
}

.table th,
.table td {
    vertical-align: middle;
    padding: .78rem .85rem;
}

.table tbody tr:hover td {
    background: #fbfdff;
}

.pagination {
    flex-wrap: wrap;
    gap: .25rem;
    margin: 1rem 0 0;
}

.page-link {
    min-width: 38px;
    min-height: 38px;
    display: grid;
    place-items: center;
    border-radius: 7px;
    border-color: var(--app-border);
    color: var(--app-primary);
}

.page-item:first-child .page-link,
.page-item:last-child .page-link {
    border-radius: 7px;
}

.page-item.active .page-link {
    background: var(--app-primary);
    border-color: var(--app-primary);
}

.form-label {
    color: #344054;
    font-size: .88rem;
    font-weight: 700;
    margin-bottom: .38rem;
}

.form-control,
.form-select {
    min-height: 42px;
    border-color: #cfd8e6;
    border-radius: 7px;
    color: var(--app-text);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--app-primary);
    box-shadow: 0 0 0 .2rem rgba(21, 94, 239, .14);
}

textarea.form-control {
    min-height: 110px;
}

.form-check {
    min-height: 28px;
}

.form-check-input {
    border-color: #98a2b3;
}

.form-check-input:checked {
    background-color: var(--app-primary);
    border-color: var(--app-primary);
}

.btn {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    border-radius: 7px;
    font-weight: 700;
    letter-spacing: 0;
    white-space: nowrap;
}

.btn-sm {
    min-height: 34px;
    padding-inline: .7rem;
}

.btn-primary {
    background: var(--app-primary);
    border-color: var(--app-primary);
}

.btn-primary:hover,
.btn-primary:focus {
    background: var(--app-primary-dark);
    border-color: var(--app-primary-dark);
}

.btn-outline-primary {
    color: var(--app-primary);
    border-color: #a9c1ff;
}

.btn-outline-primary:hover {
    background: var(--app-primary);
    border-color: var(--app-primary);
}

.btn-link {
    color: var(--app-primary);
    text-decoration: none;
}

.btn-link:hover {
    color: var(--app-primary-dark);
    text-decoration: underline;
}

.action-group {
    display: inline-flex;
    justify-content: flex-end;
    align-items: center;
    flex-wrap: wrap;
    gap: .4rem;
}

.action-group form {
    display: inline-flex;
    margin: 0;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1rem;
    background:
        linear-gradient(135deg, rgba(21, 94, 239, .10), transparent 38%),
        linear-gradient(180deg, #ffffff 0, #eef4ff 100%);
}

.auth-card {
    width: min(460px, 100%);
    background: #fff;
    padding: 2rem;
    border-radius: 10px;
    border: 1px solid var(--app-border-soft);
    box-shadow: 0 22px 70px rgba(18, 31, 53, .13);
}

.auth-card h1 {
    font-weight: 800;
    letter-spacing: 0;
}

.attachment {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
}

.timeline-item {
    border-left: 3px solid #c9d8ff;
    padding: .25rem 0 .9rem 1rem;
    margin-left: .35rem;
}

.timeline-item strong {
    display: inline-block;
    margin-right: .35rem;
}

.calendar-grid,
.planning-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(190px, 1fr));
    gap: .9rem;
    overflow-x: auto;
    padding-bottom: .5rem;
    scroll-snap-type: x proximity;
}

.calendar-grid .day,
.planning-day {
    min-height: 190px;
    scroll-snap-align: start;
}

.calendar-event {
    border-left: 3px solid var(--app-primary);
    padding: .65rem .7rem;
    background: #f8fbff;
    margin-bottom: .55rem;
    border-radius: 7px;
}

.install-banner {
    position: fixed;
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    z-index: 1080;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    align-items: center;
    gap: .75rem;
    max-width: 860px;
    margin: 0 auto;
    padding: .85rem;
    border: 1px solid var(--app-border);
    border-radius: 10px;
    background: rgba(255, 255, 255, .98);
    box-shadow: 0 18px 60px rgba(18, 31, 53, .18);
}

.install-banner[hidden] {
    display: none !important;
}

.install-banner__icon {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    color: #fff;
    background: var(--app-primary);
    font-size: 1.2rem;
}

.install-banner__content {
    display: grid;
    gap: .1rem;
    min-width: 0;
}

.install-banner__content span,
.install-banner__content small {
    color: var(--app-muted);
    line-height: 1.3;
}

.install-banner__close {
    color: var(--app-muted);
    text-decoration: none;
}

.site-actions,
.hero-actions,
.panel-header > div,
.d-flex.gap-2 {
    min-width: 0;
}

.site-actions .btn,
.hero-actions .btn {
    flex: 0 0 auto;
}

@media (max-width: 1199.98px) {
    .sidebar {
        width: 244px;
        flex-basis: 244px;
    }

    .main-content {
        padding: 1.25rem;
    }
}

@media (max-width: 991.98px) {
    body {
        background: var(--app-bg);
    }

    .app-shell {
        display: block;
    }

    .sidebar {
        display: none !important;
    }

    .main-content {
        padding: 1rem;
    }

    .navbar {
        position: sticky;
        top: 0;
        z-index: 1030;
        box-shadow: 0 8px 24px rgba(18, 31, 53, .08);
    }

    #mobileNav .nav {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: .35rem;
        padding: .75rem !important;
    }

    #mobileNav .nav-link {
        min-height: 44px;
        padding: .65rem .75rem;
        background: #fff;
        border: 1px solid var(--app-border-soft);
    }

    .topbar {
        align-items: flex-start;
        flex-wrap: wrap;
    }

    .topbar form {
        margin-left: auto;
    }

    .panel {
        padding: 1rem;
    }

    .panel-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .panel-header > .btn,
    .panel-header > div {
        width: 100%;
    }

    .panel-header > div {
        display: flex;
        flex-wrap: wrap;
    }

    .panel-header > div .btn {
        flex: 1 1 150px;
    }

    .calendar-grid,
    .planning-grid {
        grid-template-columns: repeat(7, minmax(220px, 76vw));
        margin-right: -1rem;
        padding-right: 1rem;
    }
}

@media (max-width: 767.98px) {
    body {
        font-size: 14px;
    }

    .row.g-4 {
        --bs-gutter-y: 1rem;
    }

    .metric {
        min-height: 88px;
    }

    .metric i {
        width: 38px;
        height: 38px;
        flex-basis: 38px;
        font-size: 1.15rem;
    }

    .table {
        min-width: 680px;
    }

    .table th,
    .table td {
        padding: .68rem .72rem;
    }

    .auth-page {
        align-items: start;
        padding: .85rem;
    }

    .auth-card {
        padding: 1.25rem;
        border-radius: 8px;
    }

    .site-actions {
        width: 100%;
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: .5rem !important;
    }

    .site-actions .btn {
        width: 100%;
    }

    .hero-actions {
        display: grid !important;
        grid-template-columns: 1fr;
    }

    .hero-actions .btn {
        width: 100%;
    }
}

@media (max-width: 575.98px) {
    .main-content {
        padding: .75rem;
    }

    .navbar-brand {
        max-width: calc(100vw - 88px);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #mobileNav .nav {
        grid-template-columns: 1fr;
    }

    .topbar {
        gap: .75rem;
        margin-bottom: 1rem;
    }

    .topbar form,
    .topbar form .btn {
        width: 100%;
    }

    .panel,
    .metric {
        box-shadow: 0 6px 18px rgba(18, 31, 53, .05);
    }

    .panel {
        padding: .85rem;
    }

    .panel-header > div .btn,
    form .btn,
    .auth-card .btn,
    .alert .btn {
        width: 100%;
    }

    .d-flex.gap-2:not(.site-actions):not(.hero-actions) {
        flex-wrap: wrap;
    }

    .d-flex.gap-2:not(.site-actions):not(.hero-actions) > .btn {
        flex: 1 1 140px;
    }

    .btn {
        min-height: 42px;
        white-space: normal;
    }

    .btn-sm {
        min-height: 36px;
    }

    .form-control,
    .form-select {
        min-height: 44px;
    }

    dl.row dt,
    dl.row dd {
        width: 100%;
    }

    dl.row dd {
        margin-bottom: .75rem;
    }

    .install-banner {
        left: .75rem;
        right: .75rem;
        bottom: .75rem;
        grid-template-columns: auto minmax(0, 1fr);
    }

    .install-banner .btn {
        grid-column: 1 / -1;
        width: 100%;
    }

    .install-banner__close {
        min-height: 34px;
    }

    /* Masquer les labels texte des boutons d'action dans les tables */
    .btn-label {
        display: none;
    }

    /* Filtres : s'assurer que le groupe de boutons s'empile */
    .filter-actions {
        display: flex;
        flex-wrap: wrap;
        gap: .5rem;
        width: 100%;
    }

    .filter-actions .btn {
        flex: 1 1 auto;
    }

    /* Panel-header : empiler btn-group + actions */
    .panel-header .btn-group,
    .panel-header .d-flex {
        width: 100%;
    }

    .panel-header .btn-group .btn {
        flex: 1;
    }
}
