/**
 * Nexoria Hub — shell dashboard (layout, sidebar, header, footer, mobile)
 * Chargé après custom.css pour surcharger proprement.
 */

:root {
    --hub-sidebar-width: 16.5rem;
    --hub-header-height: 4rem;
    --hub-radius: 0.625rem;
    --hub-radius-sm: 0.45rem;
    --hub-surface: #ffffff;
    --hub-canvas: #f7f8fb;
    --hub-ink: #0f172a;
    --hub-muted: #64748b;
    --hub-line: #e5e9f0;
    --hub-sidebar-bg: #ffffff;
    --hub-sidebar-elev: #f8fafc;
    --hub-sidebar-text: #334155;
    --hub-sidebar-muted: #94a3b8;
    --hub-focus: rgba(27, 60, 255, 0.14);
}

/* ——— Page shell ——— */
body.dashboard-page {
    background: var(--hub-canvas);
    color: var(--hub-ink);
}

body.dashboard-page.hub-sidebar-open {
    overflow: hidden;
}

body.dashboard-page #main-content {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

.dashboard-layout {
    display: flex;
    flex: 1 1 auto;
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    align-items: flex-start; /* sticky sidebar + scroll page */
}

.dashboard-main {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--hub-canvas);
}

/* ——— Toggle (intégré header, plus flottant bizarre) ——— */
.sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border: 1px solid var(--hub-line);
    border-radius: var(--hub-radius-sm);
    background: var(--hub-surface);
    color: var(--hub-ink);
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
    box-shadow: none;
    position: static;
    top: auto;
    left: auto;
    z-index: auto;
}

.sidebar-toggle:hover,
.sidebar-toggle:focus-visible {
    background: #eef2ff;
    border-color: #c7d2fe;
    color: var(--color-brand);
    outline: none;
    transform: none;
}

/* ——— Sidebar (clair, sticky, scroll propre) ——— */
.dashboard-sidebar {
    width: var(--hub-sidebar-width);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    background: var(--hub-sidebar-bg) !important;
    color: var(--hub-sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 0 !important;
    border-right: 1px solid var(--hub-line);
    overflow: hidden;
    align-self: flex-start;
    z-index: 30;
    box-shadow: none !important;
}

.dashboard-sidebar .sidebar-brand {
    flex-shrink: 0;
    padding: 1rem 1rem 0.9rem;
    border-bottom: 1px solid var(--hub-line);
    margin: 0 !important;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.dashboard-sidebar .sidebar-brand-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0;
    border-radius: 0;
    color: inherit;
    text-decoration: none;
    min-width: 0;
    background: transparent !important;
}

.dashboard-sidebar .sidebar-brand-link:hover {
    background: transparent;
    color: var(--hub-ink);
}

.dashboard-sidebar .brand-logo {
    width: 2.1rem;
    height: 2.1rem;
    border-radius: 0.5rem;
    overflow: hidden;
    box-shadow: none !important;
    border: 1px solid var(--hub-line);
    background: #0b1220;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.dashboard-sidebar .brand-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.dashboard-sidebar .brand-name {
    font-family: var(--font-family-heading);
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -0.03em;
    color: var(--hub-ink);
    line-height: 1.15;
}

.dashboard-sidebar .brand-name small {
    display: block;
    margin-top: 0.1rem;
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--color-brand);
}

.sidebar-close {
    display: none;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border: 1px solid var(--hub-line);
    border-radius: var(--hub-radius-sm);
    background: transparent;
    color: var(--hub-muted);
    cursor: pointer;
}

.sidebar-close:hover {
    color: var(--hub-ink);
    background: var(--hub-sidebar-elev);
}

.sidebar-nav {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.75rem 0.65rem 1rem;
    scrollbar-gutter: stable;
    -webkit-overflow-scrolling: touch;
}

.sidebar-nav .nav-group {
    margin: 0 0 0.75rem;
}

.sidebar-nav .nav-group + .nav-group {
    margin-top: 0;
    padding-top: 0.55rem;
    border-top: 1px solid var(--hub-line);
}

.sidebar-nav .nav-section {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin: 0 0 0.35rem;
    padding: 0 0.5rem;
}

.sidebar-nav .nav-section-entity {
    display: none;
}

.sidebar-nav .nav-section-label {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--hub-sidebar-muted);
    margin: 0;
}

.sidebar-nav .nav-section-hint {
    display: none;
}

.sidebar-nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.12rem;
}

.sidebar-nav .nav-item a {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.6rem;
    border-radius: var(--hub-radius-sm);
    color: var(--hub-sidebar-text);
    text-decoration: none;
    font-size: 0.86rem;
    font-weight: 500;
    line-height: 1.25;
    transition: background 0.12s ease, color 0.12s ease;
}

.sidebar-nav .nav-item a::before {
    display: none;
}

.sidebar-nav .nav-item a i {
    width: 1.1rem;
    min-width: 1.1rem;
    text-align: center;
    font-size: 0.85rem;
    opacity: 0.85;
    color: var(--hub-muted);
}

.sidebar-nav .nav-item a span {
    flex: 1;
    min-width: 0;
}

.sidebar-nav .nav-item a:hover {
    background: #f1f5f9;
    color: var(--hub-ink);
}

.sidebar-nav .nav-item a:hover i {
    color: var(--color-brand);
}

.sidebar-nav .nav-item.active a {
    background: #eef2ff;
    color: var(--color-brand);
    font-weight: 600;
    box-shadow: none;
}

.sidebar-nav .nav-item.active a i {
    color: var(--color-brand);
    opacity: 1;
}

.sidebar-nav .nav-item.disabled a {
    opacity: 0.4;
    pointer-events: none;
}

.sidebar-nav .nav-item a small.nav-badge {
    margin-left: auto;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    padding: 0.12rem 0.35rem;
    border-radius: 0.35rem;
    background: #f1f5f9;
    color: var(--hub-muted);
}

.sidebar-nav .nav-item a small.nav-badge--missing {
    background: #fffbeb;
    color: #b45309;
}

.sidebar-nav .nav-item a small.nav-badge--soon {
    background: #f8fafc;
    color: #94a3b8;
}

.sidebar-footer {
    flex-shrink: 0;
    padding: 0.75rem 0.85rem 1rem;
    border-top: 1px solid var(--hub-line);
    margin: 0;
}

.sidebar-project-chip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.65rem;
    border-radius: var(--hub-radius-sm);
    background: var(--hub-sidebar-elev);
    border: 1px solid var(--hub-line);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--hub-sidebar-text);
    max-width: 100%;
    box-shadow: none;
}

.sidebar-project-chip i {
    color: var(--color-brand);
    font-size: 0.75rem;
}

.sidebar-project-chip span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-nav::-webkit-scrollbar {
    width: 5px;
}
.sidebar-nav::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 999px;
}
.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

/* ——— Header ——— */
.dashboard-header {
    position: sticky;
    top: 0;
    z-index: 200;
    min-height: var(--hub-header-height);
    padding: 0.7rem 1.5rem;
    background: #ffffff;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    border-bottom: 1px solid var(--hub-line);
    box-shadow: none;
    margin-left: 0 !important;
}

.dashboard-header .header-left {
    min-width: 0;
    flex: 1 1 auto;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
}

.header-titles {
    min-width: 0;
    flex: 1;
}

.header-breadcrumb {
    display: none; /* redondant avec le titre */
}

.dashboard-header .header-title {
    font-family: var(--font-family-heading);
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin: 0;
    line-height: 1.25;
    color: var(--hub-ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dashboard-header .header-subtitle {
    margin: 0.15rem 0 0;
    font-size: 0.8125rem;
    color: var(--hub-muted);
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.dashboard-header .header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.header-quick-action {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.9rem;
    font-weight: 600;
    font-size: 0.8125rem;
    border-radius: var(--hub-radius-sm);
    white-space: nowrap;
}

.header-project {
    display: none; /* déjà dans sidebar footer */
}

.dashboard-header .user-menu .user-menu-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--hub-surface);
    border-radius: var(--hub-radius-sm);
    padding: 0.3rem 0.55rem 0.3rem 0.3rem;
    border: 1px solid var(--hub-line);
    box-shadow: none;
}

.dashboard-header .user-menu .user-menu-toggle:hover {
    border-color: #c7d2fe;
    box-shadow: 0 0 0 3px var(--hub-focus);
}

.user-menu-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 0.45rem;
    background: #eef2ff;
    color: var(--color-brand);
    font-size: 0.72rem;
    font-weight: 700;
}

.user-menu-name {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--hub-ink);
}

.user-menu-role {
    font-size: 0.7rem;
    color: var(--hub-muted);
}

.user-menu-dropdown {
    min-width: 15rem;
    border-radius: var(--hub-radius);
    border: 1px solid var(--hub-line);
    box-shadow: none;
    padding: 0.35rem;
    margin-top: 0.4rem !important;
}

.user-menu-dropdown .dropdown-header {
    text-transform: none;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--hub-muted);
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid var(--hub-line);
    margin-bottom: 0.25rem;
}

.user-menu-dropdown .dropdown-item {
    border-radius: var(--hub-radius-sm);
    font-size: 0.875rem;
    padding: 0.55rem 0.7rem;
    gap: 0.55rem;
}

.user-menu-dropdown .dropdown-item:hover,
.user-menu-dropdown .dropdown-item.active {
    background: #f1f5f9;
    color: var(--hub-ink);
}

.user-menu-dropdown .dropdown-item.disabled {
    opacity: 0.4;
}

/* ——— Content + cards ——— */
.dashboard-content {
    padding: 1.35rem 1.5rem 2rem;
    flex: 1;
    min-width: 0;
}

.dashboard-container {
    padding: 0;
    max-width: 100%;
}

.card-block,
.dashboard-content .card {
    background: var(--hub-surface);
    border-radius: var(--hub-radius);
    padding: 1.15rem 1.25rem;
    box-shadow: none !important;
    border: 1px solid var(--hub-line);
}

.card:hover,
.card-block:hover {
    transform: none !important;
    box-shadow: none !important;
}

.card-block .table-responsive,
.dashboard-content .table-responsive {
    margin: 0;
    border-radius: var(--hub-radius-sm);
    border: 1px solid var(--hub-line);
    overflow: hidden;
}

.dashboard-content .table {
    margin-bottom: 0;
    font-size: 0.875rem;
    border-color: var(--hub-line);
}

.dashboard-content .table > :not(caption) > * > * {
    padding: 0.7rem 0.85rem;
    vertical-align: middle;
    border-bottom-color: var(--hub-line);
}

.dashboard-content .table thead th {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--hub-muted);
    border-bottom: 1px solid var(--hub-line);
    white-space: nowrap;
    background: #f8fafc;
}

.dashboard-content .table tbody tr:hover {
    background: #fafbfc;
}

.dashboard-content .table tbody tr:last-child > * {
    border-bottom: 0;
}

.dashboard-content .btn {
    border-radius: var(--hub-radius-sm);
    font-weight: 600;
    box-shadow: none !important;
}

.dashboard-content .form-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #334155;
    margin-bottom: 0.35rem;
}

.dashboard-content .form-control,
.dashboard-content .form-select,
.dashboard-content textarea.form-control {
    border-radius: var(--hub-radius-sm);
    border: 1px solid var(--hub-line);
    background: #fff;
    font-size: 0.9rem;
    padding: 0.55rem 0.75rem;
    box-shadow: none !important;
    min-height: 2.4rem;
}

.dashboard-content .form-control:hover,
.dashboard-content .form-select:hover {
    border-color: #cbd5e1;
}

.dashboard-content .form-control:focus,
.dashboard-content .form-select:focus {
    border-color: #93a4ff;
    box-shadow: 0 0 0 3px var(--hub-focus) !important;
}

/* Formulaires métier (diagnostic, etc.) */
.diagnostic-form .diagnostic-section h5,
.dashboard-content .form-section-title {
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--hub-ink);
    border-bottom: 1px solid var(--hub-line) !important;
    padding-bottom: 0.55rem;
    margin-bottom: 1rem;
}

.diagnostic-form .form-control,
.diagnostic-form .form-select {
    background: #fff;
}

/* ——— Footer ——— */
.dashboard-footer {
    margin-top: auto;
    padding: 0.85rem 1.5rem;
    border-top: 1px solid var(--hub-line);
    background: var(--hub-surface);
    color: var(--hub-muted);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    font-size: 0.78rem;
}

.dashboard-footer p {
    margin: 0;
}

.dashboard-footer .footer-links {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    font-size: 0.78rem;
}

.dashboard-footer .footer-links a {
    color: var(--hub-muted);
    text-decoration: none;
}

.dashboard-footer .footer-links a:hover {
    color: var(--color-brand);
}

.dashboard-footer .separator {
    color: #cbd5e1;
}

/* ——— Overlay mobile ——— */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 14, 23, 0.55);
    backdrop-filter: blur(2px);
    z-index: 1040;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.sidebar-overlay.is-visible {
    display: block;
    opacity: 1;
    pointer-events: auto;
}

/* ——— Messages ——— */
body.dashboard-page .messages-container {
    top: calc(var(--hub-header-height) + 0.5rem);
    right: 1rem;
    z-index: 1080;
}

/* ——— Responsive ——— */
@media (max-width: 992px) {
    .sidebar-toggle {
        display: inline-flex !important;
        position: static !important;
    }

    .sidebar-close {
        display: inline-flex;
    }

    .dashboard-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: min(var(--hub-sidebar-width), 88vw);
        max-width: 20rem;
        height: 100vh;
        height: 100dvh;
        z-index: 1050;
        transform: translateX(-105%);
        transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: none;
        left: 0 !important; /* override old left: -272px */
    }

    .dashboard-sidebar.sidebar-open {
        transform: translateX(0);
        box-shadow: none;
        border-right: 1px solid var(--hub-line);
        left: 0 !important;
    }

    .dashboard-sidebar {
        position: fixed; /* mobile drawer */
        height: 100vh;
        height: 100dvh;
    }

    .dashboard-main {
        margin-left: 0;
        width: 100%;
    }

    .dashboard-header {
        padding: 0.65rem 0.85rem;
        flex-wrap: nowrap;
        gap: 0.5rem;
    }

    .dashboard-content {
        padding: 0.9rem 0.85rem 1.5rem;
    }

    .dashboard-footer {
        padding: 0.75rem 0.85rem;
        flex-direction: column;
        align-items: flex-start;
    }

    .header-subtitle {
        display: none !important;
    }

    .dashboard-header .header-title {
        font-size: 1.05rem;
    }
}

@media (max-width: 768px) {
    .dashboard-sidebar {
        width: min(18rem, 90vw);
        left: 0 !important;
    }

    .dashboard-sidebar.sidebar-open {
        left: 0 !important;
    }

    .header-quick-action span {
        display: none;
    }

    .header-quick-action {
        padding: 0.45rem 0.55rem;
    }

    .card-block {
        padding: 0.95rem 0.9rem;
        border-radius: var(--hub-radius-sm);
    }

    .dashboard-content .btn-group {
        flex-wrap: wrap;
    }

    /* Tables qui débordent */
    .dashboard-content .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-left: -0.25rem;
        margin-right: -0.25rem;
        padding-bottom: 0.25rem;
    }

    body.dashboard-page .messages-container {
        left: 0.75rem;
        right: 0.75rem;
        max-width: none;
    }

    /* Formulaires compacts */
    .dashboard-content .row.g-3 > [class*="col-"] {
        min-width: 0;
    }
}

@media (max-width: 480px) {
    .user-menu-caret {
        display: none;
    }

    .dashboard-header .header-actions {
        gap: 0.35rem;
    }
}
