/**
 * UI — (titres, menus, boutons, formulaires, tableaux).
 * Dépend de theme.css. Ne pas y mettre de couleurs / polices en dur.
 */

* {
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: var(--dark) rgba(0, 0, 0, 0.03);
}

html,
body {
    min-height: 100vh;
    height: auto;
}

body {
    margin: 0;
    overflow: auto !important;
    background: var(--bg) !important;
    color: var(--text);
    font-family: var(--font-body);
    font-size: var(--font-size);
    -webkit-tap-highlight-color: transparent;
}

a {
    text-decoration: none;
    color: var(--dark);
}

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

h1, h2, h3, .panel-title {
    font-family: var(--font-title);
    font-weight: var(--font-title-weight);
}

/* ── Sidebar ── */

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    min-height: 100vh;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-ligne);
    display: flex;
    flex-direction: column;
    z-index: 10;
    color: var(--sidebar-text);
    padding: 0;
    transform: none;
}

.brand {
    padding: 30px 24px;
    border-bottom: 1px solid var(--sidebar-ligne);
    position: relative;
}

.brand-logo img {
    display: block;
    width: 100%;
    max-width: 180px;
    height: auto;
}

.brand-logo img.invert-logo {
    filter: brightness(0) invert(1);
}

.brand-pill {
    display: inline-block;
    margin-top: 14px;
    padding: 8px 12px;
    border: 1px solid var(--sidebar-text);
    background: transparent;
    color: var(--sidebar-text);
    font-size: 9px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    font-weight: 800;
    width: 100%;
    text-align: center;
}

.sidebar-nav {
    padding: 24px 0;
    overflow-y: auto;
    flex: 1;
}

.nav-section {
    padding: 8px 24px 12px;
    color: var(--sidebar-muted);
    font-size: 9px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    font-weight: 800;
}

.side-nav-link {
    height: 44px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--sidebar-muted);
    font-size: 14px;
    font-weight: 600;
    transition: background 0.15s ease, color 0.15s ease;
    border-left: 3px solid transparent;
}

.side-nav-link span {
    display: flex;
    align-items: center;
    gap: 14px;
}

.side-nav-link i {
    width: 16px;
}

.side-nav-link:hover {
    text-decoration: none;
    color: var(--sidebar-text);
    background: rgba(255, 255, 255, 0.06);
}

.side-nav-link.active {
    color: var(--sidebar-text);
    background: rgba(255, 255, 255, 0.08);
    border-left-color: var(--sidebar-text);
    font-weight: 800;
}

.sidebar-user {
    padding: 18px 24px 24px;
    border-top: 1px solid var(--sidebar-ligne);
}

.user-line {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.user-avatar,
.client-avatar {
    width: 38px;
    height: 38px;
    background: var(--sidebar-text);
    color: var(--sidebar-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-title);
    font-size: 13px;
    font-weight: 400;
    flex-shrink: 0;
}

.client-avatar {
    background: var(--dark);
    color: var(--light);
}

.user-name {
    font-size: 13px;
    font-weight: 800;
    color: var(--sidebar-text);
}

.user-subtitle {
    font-size: 11px;
    color: var(--sidebar-muted);
    font-weight: 600;
}

.logout-btn {
    height: 40px;
    border: 1px solid var(--sidebar-ligne);
    color: var(--sidebar-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 700;
    transition: border-color 0.15s ease, color 0.15s ease;
}

.logout-btn:hover {
    border-color: var(--sidebar-text);
    color: var(--sidebar-text);
}

/* ── Layout ── */

.main-content {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    width: auto;
    background: var(--bg);
}

.topbar {
    height: var(--topbar-h);
    padding: 0 36px;
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--ligne);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 5;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

.menu-toggle,
.sidebar-close {
    display: none;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--ligne);
    background: var(--light);
    color: var(--dark);
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    font-size: 18px;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.menu-toggle:hover,
.sidebar-close:hover {
    border-color: var(--dark);
}

.sidebar-close {
    position: absolute;
    top: 18px;
    right: 18px;
    border-color: var(--sidebar-ligne);
    background: transparent;
    color: var(--sidebar-text);
}

.sidebar-close:hover {
    border-color: var(--sidebar-text);
    background: rgba(255, 255, 255, 0.08);
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 18;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.sidebar-overlay.is-visible {
    opacity: 1;
    visibility: visible;
}

body.menu-open {
    overflow: hidden;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.search-box {
    width: 220px;
    height: 40px;
    padding: 0 12px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    background: var(--light);
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
}

.search-box input {
    border: 0;
    outline: 0;
    background: transparent;
    width: 100%;
    font-size: 12px;
    font-family: var(--font-body);
    color: var(--text);
}

.round-btn {
    width: 40px;
    height: 40px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    background: var(--light);
    color: var(--muted);
    position: relative;
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease;
}

.round-btn:hover {
    border-color: var(--dark);
    color: var(--dark);
}

.page-body,
main.main {
    padding: 36px;
    flex: 1;
    overflow: visible;
    height: auto;
    min-height: calc(100vh - var(--topbar-h));
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

.footer {
    margin-top: auto;
    padding-top: 24px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

/* ── Formulaires & login ── */

.form-app label,
.form-app .form-label {
    display: block;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-weight: 800;
    margin-bottom: 6px;
}

.form-app .form-control,
.form-app .form-select {
    border-color: var(--ligne);
    border-radius: var(--radius);
    min-height: 42px;
    color: var(--text);
    font-family: var(--font-body);
}

.form-app .form-control:focus,
.form-app .form-select:focus {
    border-color: var(--dark);
    box-shadow: 0 0 0 0.15rem rgba(0, 0, 0, 0.1);
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: var(--bg);
}

.login-card {
    width: 100%;
    max-width: 430px;
    background: var(--light);
    border: 1px solid var(--ligne);
    padding: 34px;
}

.login-card .brand-logo img {
    display: block;
    margin: 0 auto;
    max-width: 180px;
    height: auto;
}

.panel-title {
    font-size: 22px;
    line-height: 1;
}

.btn-link-sm {
    color: var(--dark);
    font-size: 12px;
    font-weight: 800;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.btn-app {
    border: 1px solid var(--dark);
    background: var(--dark);
    color: var(--light) !important;
    padding: 9px 16px;
    font-size: 12px;
    font-weight: 800;
    display: inline-flex;
    gap: 8px;
    align-items: center;
    cursor: pointer;
    font-family: var(--font-body);
    transition: background 0.15s ease, color 0.15s ease;
}

.btn-app:hover {
    background: var(--light);
    color: var(--dark) !important;
}

.btn-app:disabled {
    background: var(--light);
    color: var(--dark);
    opacity: 0.45;
    cursor: not-allowed;
}

.btn-app-outline {
    background: transparent;
    border: 1px solid var(--ligne);
    color: var(--muted);
    padding: 9px 16px;
    font-size: 12px;
    font-weight: 800;
    display: inline-flex;
    gap: 8px;
    align-items: center;
    cursor: pointer;
    font-family: var(--font-body);
    transition: background 0.15s ease, color 0.15s ease;
}

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

a.btn-app,
a.btn-app-outline {
    color: inherit;
    text-decoration: none;
}

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

/* ── Listes / panneaux ── */

.card-panel {
    background: var(--light);
    border: 1px solid var(--ligne);
    overflow: hidden;
    margin-bottom: 24px;
}

.panel-header {
    min-height: 66px;
    padding: 12px 24px;
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--ligne);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.panel-header .panel-title {
    margin: 0;
    font-family: var(--font-title);
    font-weight: var(--font-title-weight);
}

.panel-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.filtre-select {
    min-width: 180px;
    width: auto;
    min-height: 40px;
    padding: 0 12px;
    border: 1px solid var(--ligne);
    background: var(--light);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 600;
    border-radius: var(--radius);
}

.app-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
}

.app-table th,
.app-table td {
    padding: 16px 20px;
    border-top: 1px solid var(--ligne);
    vertical-align: middle;
    background: transparent;
}

.app-table thead th {
    color: var(--muted);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-weight: 800;
    border-bottom: 0;
}

.app-table tbody tr {
    transition: background 0.15s ease;
}

.app-table tbody tr:hover {
    background: rgba(0, 0, 0, 0.02);
}

.app-table tbody tr.is-clickable {
    cursor: pointer;
}

.app-table .btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.badge-status {
    display: inline-block;
    padding: 6px 12px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border: 1px solid var(--ligne);
    white-space: nowrap;
}

button.badge-status {
    font-family: inherit;
    line-height: inherit;
    background: var(--topbar-bg);
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
}

.card-panel table.dataTable thead th.sorting,
.card-panel table.dataTable thead th.sorting_asc,
.card-panel table.dataTable thead th.sorting_desc {
    cursor: pointer;
}

button.badge-status:disabled {
    opacity: 0.6;
    cursor: wait;
}

.badge-status.success,
.badge-status.livree {
    background: var(--vert);
    color: var(--sauge-dark);
    border-color: var(--sauge);
}

.badge-status.warning,
.badge-status.attente {
    background: var(--or);
    color: var(--or-text);
    border-color: var(--or-text);
}

.badge-status.gris {
    background: var(--topbar-bg);
    color: var(--muted);
    border-color: var(--ligne);
}

.badge-status.danger {
    background: var(--danger-bg);
    color: var(--danger-text);
    border-color: var(--danger-border);
}

.badge-status.info,
.badge-status.transit {
    background: var(--bleu);
    color: var(--bleu-text);
    border-color: var(--bleu-text);
}

.card-panel .dataTables_wrapper {
    padding: 8px 20px 20px;
    font-family: var(--font-body);
    font-size: 13px;
}

.card-panel .dataTables_wrapper .app-table {
    width: 100% !important;
}

.card-panel .dataTables_length,
.card-panel .dataTables_filter,
.card-panel .dataTables_info,
.card-panel .dataTables_paginate {
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    padding: 8px 0;
}

.card-panel .dataTables_filter input,
.card-panel .dataTables_length select {
    border: 1px solid var(--ligne);
    background: var(--light);
    min-height: 36px;
    padding: 4px 10px;
    font-family: var(--font-body);
    color: var(--text);
}

.card-panel .dataTables_paginate .paginate_button {
    border: 1px solid transparent !important;
    background: transparent !important;
    color: var(--muted) !important;
    border-radius: var(--radius) !important;
    padding: 6px 12px !important;
}

.card-panel .dataTables_paginate .paginate_button.current,
.card-panel .dataTables_paginate .paginate_button.current:hover {
    background: var(--dark) !important;
    color: var(--light) !important;
    border-color: var(--dark) !important;
}

.card-panel .dataTables_paginate .paginate_button:hover {
    background: transparent !important;
    color: var(--dark) !important;
    border-color: var(--ligne) !important;
}

/* ── Bootstrap primary / secondary ── */

.btn-primary {
    --bs-btn-bg: var(--bs-primary);
    --bs-btn-border-color: var(--bs-primary);
    --bs-btn-hover-bg: var(--brand-primary-hover);
    --bs-btn-hover-border-color: var(--brand-primary-hover);
    --bs-btn-hover-color: #fff;
    --bs-btn-active-bg: var(--brand-primary-hover);
    --bs-btn-active-border-color: var(--brand-primary-hover);
    --bs-btn-disabled-bg: var(--bs-primary);
    --bs-btn-disabled-border-color: var(--bs-primary);
    background-color: var(--bs-primary) !important;
    border-color: var(--bs-primary) !important;
    color: #fff !important;
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-weight: 800;
    font-size: 12px;
}

.btn-primary:hover,
.btn-primary:focus {
    background-color: var(--brand-primary-hover) !important;
    border-color: var(--brand-primary-hover) !important;
    color: #fff !important;
}

.btn-secondary {
    --bs-btn-bg: var(--bs-secondary);
    --bs-btn-border-color: var(--bs-secondary);
    --bs-btn-hover-bg: var(--brand-secondary-hover);
    --bs-btn-hover-border-color: var(--brand-secondary-hover);
    --bs-btn-hover-color: #fff;
    background-color: var(--bs-secondary) !important;
    border-color: var(--bs-secondary) !important;
    color: #fff !important;
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-weight: 800;
    font-size: 12px;
}

.btn-secondary:hover,
.btn-secondary:focus {
    background-color: var(--brand-secondary-hover) !important;
    border-color: var(--brand-secondary-hover) !important;
    color: #fff !important;
}

.btn-outline-primary {
    --bs-btn-color: var(--bs-primary);
    --bs-btn-border-color: var(--bs-primary);
    --bs-btn-hover-bg: var(--bs-primary);
    --bs-btn-hover-border-color: var(--bs-primary);
    --bs-btn-active-bg: var(--bs-primary);
    --bs-btn-active-border-color: var(--bs-primary);
    color: var(--bs-primary) !important;
    border-color: var(--bs-primary) !important;
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 12px;
}

.btn-outline-primary:hover,
.btn-outline-primary:focus {
    background-color: var(--bs-primary) !important;
    border-color: var(--bs-primary) !important;
    color: #fff !important;
}

.btn-outline-secondary {
    color: var(--bs-secondary) !important;
    border-color: var(--bs-secondary) !important;
    border-radius: var(--radius);
}

.btn-outline-secondary:hover,
.btn-outline-secondary:focus {
    background-color: var(--bs-secondary) !important;
    border-color: var(--bs-secondary) !important;
    color: #fff !important;
}

.btn-outline-danger {
    border-radius: var(--radius);
}

.text-primary {
    color: var(--bs-primary) !important;
}

.text-secondary {
    color: var(--bs-secondary) !important;
}

.bg-primary {
    background-color: var(--bs-primary) !important;
}

.bg-secondary {
    background-color: var(--bs-secondary) !important;
}

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

input[type="checkbox"],
input[type="radio"],
.form-check-input {
    width: var(--check-size) !important;
    height: var(--check-size) !important;
    min-width: var(--check-size);
    min-height: var(--check-size);
    margin-top: 0;
    flex-shrink: 0;
    cursor: pointer;
    accent-color: var(--dark);
    background-size: contain;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: var(--check-size);
}

.form-check-input {
    float: none;
}

.table th,
.table td {
    vertical-align: middle;
}

.notif-item {
    min-height: 72px;
    padding: 14px 24px;
    border-bottom: 1px solid var(--ligne);
    display: flex;
    align-items: center;
    gap: 14px;
}

.notif-icon {
    width: 36px;
    height: 36px;
    border: 1px solid var(--ligne);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
}

.notif-icon.rose { background: var(--rose); color: var(--rose-text); }
.notif-icon.vert { background: var(--vert); color: var(--sauge-dark); }
.notif-icon.or { background: var(--or); color: var(--or-text); }
.notif-icon.bleu { background: var(--bleu); color: var(--bleu-text); }

.notif-text {
    font-size: 13px;
    line-height: 1.4;
    font-weight: 600;
}

.notif-time {
    margin-top: 4px;
    font-size: 11px;
    color: var(--muted);
    font-weight: 600;
}

.client-row {
    min-height: 72px;
    padding: 14px 24px;
    border-bottom: 1px solid var(--ligne);
    display: flex;
    align-items: center;
    gap: 14px;
}

.client-name {
    font-size: 13px;
    font-weight: 800;
}

.client-last {
    margin-top: 4px;
    font-size: 11px;
    color: var(--muted);
    font-weight: 600;
}

.client-row-link {
    color: inherit;
    text-decoration: none;
}

.client-row-link:hover {
    background: rgba(0, 0, 0, 0.02);
    color: inherit;
}

.etat-vide {
    margin: 0;
    padding: 24px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.dash-kpi {
    display: block;
    background: var(--light);
    border: 1px solid var(--ligne);
    padding: 20px 22px;
    height: 100%;
    color: inherit;
    text-decoration: none;
}

a.dash-kpi:hover {
    border-color: var(--dark);
    color: inherit;
}

.dash-kpi-label {
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-weight: 800;
}

.dash-kpi-value {
    margin: 10px 0 6px;
    font-family: var(--font-title);
    font-size: 28px;
    font-weight: 400;
    line-height: 1.1;
}

.dash-kpi-trend {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.dash-kpi-trend.up {
    color: var(--sauge-dark);
}

.dash-kpi-trend.down {
    color: var(--danger-text);
}

.dash-caption {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
}

.dash-chart {
    height: 280px;
    padding: 16px 20px 20px;
}

.dash-chart-top {
    height: 300px;
}

.dash-sante-item {
    padding: 20px 24px;
    border-top: 1px solid var(--ligne);
}

@media (min-width: 768px) {
    .dash-sante-item {
        border-top: 0;
        border-right: 1px solid var(--ligne);
    }

    .dash-sante .col-md-3:last-child .dash-sante-item {
        border-right: 0;
    }
}

.dash-sante-item strong {
    display: block;
    font-size: 22px;
    font-family: var(--font-title);
    font-weight: 400;
}

.dash-sante-item span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.check-borne label {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
    text-transform: none;
    letter-spacing: 0;
    cursor: pointer;
}

.check-borne-hint {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.apercu-photo {
    min-height: 180px;
    padding: 16px;
    background: var(--topbar-bg);
    border: 1px solid var(--ligne);
    display: flex;
    align-items: center;
    justify-content: center;
}

.apercu-photo img {
    max-height: 220px;
    max-width: 100%;
    object-fit: contain;
}

.apercu-photo-vide {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.apercu-photo-vide i {
    font-size: 28px;
}

.apercu-photo-portrait {
    min-height: 280px;
}

.apercu-photo-portrait img {
    max-height: 360px;
    aspect-ratio: 3 / 4;
    object-fit: cover;
}

/* ── Scrollbar ── */

::-webkit-scrollbar {
    width: 8px;
    background: rgba(0, 0, 0, 0.03);
}

::-webkit-scrollbar-thumb {
    background: var(--dark);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

::-webkit-scrollbar-corner {
    background: transparent;
}

/* ── Responsive ── */

@media (max-width: 991px) {
    .menu-toggle,
    .sidebar-close {
        display: inline-flex;
    }

    .sidebar {
        width: min(300px, 88vw);
        z-index: 20;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 8px 0 32px rgba(0, 0, 0, 0.18);
    }

    .sidebar.is-open {
        transform: translateX(0);
    }

    .brand {
        padding-right: 56px;
    }

    .side-nav-link {
        min-height: 48px;
        height: auto;
        padding-top: 12px;
        padding-bottom: 12px;
    }

    .main-content {
        margin-left: 0;
    }

    .topbar {
        height: auto;
        min-height: 56px;
        padding: 8px 16px;
        flex-wrap: wrap;
        align-items: center;
    }

    .topbar-actions {
        flex-shrink: 0;
        gap: 8px;
    }

    .search-box {
        order: 3;
        width: 100%;
        flex: 1 1 100%;
    }

    .page-body,
    main.main {
        padding: 18px;
        min-height: calc(100vh - 56px);
    }

    .panel-header {
        padding: 12px 16px;
    }

    .app-table th,
    .app-table td {
        padding: 12px 14px;
    }
}

@media (max-width: 575px) {
    .topbar-help {
        display: none;
    }

    .topbar-actions {
        gap: 6px;
    }

    .search-box {
        height: 38px;
    }

    .round-btn {
        width: 38px;
        height: 38px;
    }
}
