/**
 * GestRestoSco — Application CSS
 * Ce fichier contient l'intégralité des styles de l'interface applicative.
 * Bootstrap 5 et Font Awesome sont chargés via CDN dans le layout.
 */

/* ============================================================
   Variables CSS globales
   ============================================================ */
:root {
    --app-primary: #1a5276;
    --app-secondary: #154360;
    --app-accent: #2e86c1;
    --app-sidebar-w: 260px;
    --app-sidebar-w-collapsed: 52px;
    --app-topbar-h: 56px;
}

html,
body {
    margin: 0;
    padding: 0;
}

/* ============================================================
   Body & base
   ============================================================ */
body {
    background: #f4f6f9;
    font-family: 'Segoe UI', Arial, sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ============================================================
   Topbar
   ============================================================ */
.app-topbar {
    background: var(--app-primary);
    height: var(--app-topbar-h);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1030;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.app-topbar .brand {
    color: #fff;
    font-weight: 700;
    font-size: 1.15rem;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.app-topbar .tenant-name {
    color: #aed6f1;
    font-size: 0.85rem;
    margin-left: 1rem;
    /* Responsive : tronqué sur mobile */
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (min-width: 768px) {
    .app-topbar .tenant-name {
        max-width: 260px;
    }
}

.app-topbar .ms-auto a,
.app-topbar .ms-auto .btn-link {
    color: #aed6f1;
    text-decoration: none;
    font-size: 0.9rem;
}

.app-topbar .ms-auto a:hover,
.app-topbar .ms-auto .btn-link:hover {
    color: #fff;
}

/* ============================================================
   Sidebar
   ============================================================ */
.app-sidebar {
    background: var(--app-secondary);
    width: var(--app-sidebar-w);
    position: fixed;
    top: var(--app-topbar-h);
    left: 0;
    bottom: 0;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1020;
    transition: transform 0.25s ease, width 0.22s ease;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 6px 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    margin-bottom: 4px;
}

.sidebar-collapse-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    border-radius: 6px;
    color: #aed6f1;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

.sidebar-collapse-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
}

.app-sidebar .nav-section {
    padding: 0.75rem 1rem 0.25rem;
    text-transform: uppercase;
    font-size: 0.7rem;
    color: #7fb3d3;
    letter-spacing: 0.08em;
    display: block;
}

.app-sidebar .nav-link {
    color: #d6eaf8;
    padding: 0.55rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    border-radius: 6px;
    margin: 2px 8px;
    font-size: 0.9rem;
    transition: background 0.15s;
}

.app-sidebar .nav-link:hover,
.app-sidebar .nav-link.active {
    background: var(--app-accent);
    color: #fff;
}

.app-sidebar .nav-link i {
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}

/* ============================================================
   Contenu principal
   ============================================================ */
.app-main {
    margin-left: var(--app-sidebar-w);
    margin-top: var(--app-topbar-h);
    padding: 1.75rem;
    min-height: calc(100vh - var(--app-topbar-h));
    box-sizing: border-box;
    transition: margin-left 0.22s ease;
}

/* Liens légaux bas de sidebar */
.sidebar-legal {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 8px;
    padding: 10px 14px 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    margin-top: auto;
}

.sidebar-legal a {
    font-size: 0.68rem;
    color: rgba(255, 255, 255, 0.4);
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.15s;
}

.sidebar-legal a:hover {
    color: rgba(255, 255, 255, 0.75);
    text-decoration: underline;
}

body.sidebar-collapsed .sidebar-legal {
    display: none;
}

/* ============================================================
   Sidebar collapsed (desktop)
   ============================================================ */
/* Pas de transition au chargement initial (classe retirée par JS après init) */
body.no-sidebar-transition .app-sidebar,
body.no-sidebar-transition .app-main {
    transition: none !important;
}

body.sidebar-collapsed .app-sidebar {
    width: var(--app-sidebar-w-collapsed);
}

body.sidebar-collapsed .app-main {
    margin-left: var(--app-sidebar-w-collapsed);
}

body.sidebar-collapsed .app-sidebar .nav-text {
    display: none;
}

body.sidebar-collapsed .app-sidebar .nav-section {
    visibility: hidden;
    height: 0;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden;
}

body.sidebar-collapsed .app-sidebar .nav-link {
    justify-content: center;
    padding: 0.6rem;
    margin: 2px 4px;
}

body.sidebar-collapsed .app-sidebar .nav-link i {
    width: auto;
}

body.sidebar-collapsed .sidebar-header {
    justify-content: center;
    padding: 6px 4px 0;
}

/* ============================================================
   Stat-cards (tableau de bord)
   ============================================================ */
.stat-card {
    border: none;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
}

.stat-card-icon {
    flex-shrink: 0;
}

/* ============================================================
   Flash messages
   ============================================================ */
.flash-container {
    position: sticky;
    top: 0;
    z-index: 100;
}

/* ============================================================
   Titres de section (couleur primaire)
   ============================================================ */
.page-title {
    color: var(--app-primary);
}

/* ============================================================
   Bouton couleur primaire (override Bootstrap)
   ============================================================ */
.btn-app-primary {
    background-color: var(--app-primary);
    border-color: var(--app-primary);
    color: #fff;
}

.btn-app-primary:hover,
.btn-app-primary:focus {
    background-color: var(--app-secondary);
    border-color: var(--app-secondary);
    color: #fff;
}

/* ============================================================
   Icônes colorées des stat-cards (dashboard)
   ============================================================ */
.stat-icon {
    width: 50px;
    height: 50px;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.stat-icon-blue {
    background: #eaf4fb;
}

.stat-icon-green {
    background: #eafaf1;
}

.stat-icon-yellow {
    background: #fef9e7;
}

.stat-icon-red {
    background: #fdedec;
}

/* ============================================================
   Tableau d'informations (colonne label)
   ============================================================ */
.table-label {
    width: 140px;
}

/* ============================================================
   Badges inline (plan tenant)
   ============================================================ */
.badge-plan-premium {
    --bs-bg-opacity: 1;
    background-color: #198754 !important;
}

.badge-plan-standard {
    --bs-bg-opacity: 1;
    background-color: #0d6efd !important;
}

.badge-plan-trial {
    --bs-bg-opacity: 1;
    background-color: #6c757d !important;
}

/* ============================================================
   Bouton hamburger mobile
   ============================================================ */
.sidebar-hamburger {
    display: none !important;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    margin-right: 0.5rem;
    font-size: 1.1rem;
    flex-shrink: 0;
    transition: background 0.15s;
}

.sidebar-hamburger:hover {
    background: rgba(255, 255, 255, 0.28);
}

/* Overlay fond mobile */
#sidebarOverlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1019;
}

#sidebarOverlay.active {
    display: block;
}

/* ============================================================
   Responsive — masquer sidebar sur mobile
   ============================================================ */
@media (max-width: 768px) {
    .sidebar-hamburger {
        display: flex !important;
    }

    .app-sidebar {
        transform: translateX(-100%);
        width: var(--app-sidebar-w) !important;
    }

    .app-sidebar.open {
        transform: translateX(0);
    }

    .app-main {
        margin-left: 0 !important;
    }

    .sidebar-collapse-btn {
        display: none;
    }
}

/* ============================================================
   Recherche globale et statut réseau
   ============================================================ */
.search-toggle-btn {
    display: flex;
    align-items: center;
    gap: .45rem;
    padding: .3rem .75rem;
    border: none;
    border-radius: 6px;
    background: rgba(255, 255, 255, .15);
    color: #fff;
    font-size: .85rem;
    cursor: pointer;
    transition: background .2s;
}

.app-topbar .search-toggle-btn {
    appearance: none;
    line-height: normal;
    white-space: nowrap;
}

.search-toggle-btn:hover {
    background: rgba(255, 255, 255, .25);
}

.search-toggle-btn kbd {
    font-size: .7rem;
    padding: .1rem .35rem;
    border-radius: 4px;
    background: rgba(255, 255, 255, .2);
    border: 1px solid rgba(255, 255, 255, .3);
    color: #fff;
}

.search-overlay {
    position: fixed;
    inset: 0;
    z-index: 2100;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 80px;
    background: rgba(0, 0, 0, .45);
    backdrop-filter: blur(2px);
}

.search-modal {
    background: #fff;
    border-radius: 12px;
    width: min(680px, 94vw);
    max-height: 75vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
    overflow: hidden;
}

.search-modal-header {
    display: flex;
    align-items: center;
    padding: .75rem 1rem;
    border-bottom: 1px solid #e5e7eb;
}

.search-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 1.05rem;
    background: transparent;
    color: #111;
}

.search-close-btn {
    border: none;
    background: none;
    font-size: 1.1rem;
    color: #6b7280;
    cursor: pointer;
    padding: .2rem .5rem;
    border-radius: 4px;
}

.search-close-btn:hover {
    background: #f3f4f6;
}

.search-body {
    overflow-y: auto;
    flex: 1;
    padding: .5rem 0;
}

.search-section {
    padding: 0 .5rem .5rem;
}

.search-section-header {
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #9ca3af;
    padding: .4rem .75rem .2rem;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .5rem .75rem;
    cursor: pointer;
    border-radius: 6px;
    text-decoration: none;
    color: inherit;
    margin: 0 .25rem;
    transition: background .15s;
}

.search-result-item:hover,
.search-result-item.active {
    background: #eff6ff;
    color: inherit;
    text-decoration: none;
}

.search-result-label {
    font-size: .9rem;
    font-weight: 500;
    line-height: 1.3;
}

.search-result-label mark {
    background: #fef3c7;
    padding: 0 2px;
    border-radius: 2px;
}

.search-result-desc {
    font-size: .78rem;
    color: #6b7280;
    line-height: 1.2;
}

.search-badge {
    font-size: .65rem;
}

.search-footer {
    display: flex;
    gap: 1rem;
    padding: .5rem 1rem;
    border-top: 1px solid #e5e7eb;
    font-size: .72rem;
    color: #9ca3af;
}

.search-footer kbd {
    font-size: .65rem;
    padding: .1rem .3rem;
    background: #f3f4f6;
    border: 1px solid #d1d5db;
    border-radius: 3px;
    color: #374151;
}

.network-status {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    font-size: .78rem;
    padding: .18rem .55rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, .14);
    color: #e5e7eb;
    border: 1px solid rgba(255, 255, 255, .22);
}

.network-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #10b981;
}

.network-status.offline {
    background: rgba(239, 68, 68, .2);
    color: #fee2e2;
    border-color: rgba(239, 68, 68, .4);
}

.network-status.offline .network-status-dot {
    background: #ef4444;
}

.brand-logo {
    width: 28px;
    height: 28px;
    display: inline-block;
    vertical-align: middle;
}

.app-topbar .brand-logo {
    width: 28px !important;
    height: 28px !important;
    object-fit: contain;
}

/* ── Impression ─────────────────────────────────────────────────────────── */
@media print {

    .app-topbar,
    .app-sidebar,
    .btn,
    .no-print {
        display: none !important;
    }

    .app-main {
        margin-left: 0 !important;
        margin-top: 0 !important;
        padding: 0 !important;
    }

    body {
        background: #fff !important;
    }

    .card {
        box-shadow: none !important;
        border: 1px solid #dee2e6 !important;
    }

    .table {
        font-size: 11px;
    }
}