/* ============================================
   TOPBAR HORIZONTAL (Navigation top)
   ============================================ */

.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height-expanded, 90px);
    background-color: var(--color-surface, #ffffff);
    border-bottom: 1px solid var(--color-divider, #edf2f7);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-lg, 1.5rem);
    padding: 0 var(--spacing-xl, 2rem);
    z-index: 1010;
    box-shadow: var(--shadow-sm, 0 1px 3px rgba(0, 0, 0, 0.1));
    transition: height 0.4s cubic-bezier(0.4, 0, 0.2, 1), 
                top 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                padding 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.4s ease;
}

/* Topbar réduite quand on scrolle */
.topbar--compact {
    height: var(--topbar-height, 64px);
    padding: 0 var(--spacing-lg, 1.5rem);
    box-shadow: var(--shadow-md, 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06));
}

/* Topbar cachée lors du scroll vers le bas */
.topbar--hidden {
    top: calc(-1 * var(--topbar-height-expanded, 90px));
}

.topbar--compact.topbar--hidden {
    top: calc(-1 * var(--topbar-height, 64px));
}

.topbar__left {
    display: flex;
    align-items: center;
    gap: var(--spacing-md, 1rem);
    flex: 0 0 auto;
}

.topbar__brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--color-primary, #365957);
}

/* Logo optimisé avec inline SVG */
.topbar__logo {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), 
                opacity 0.3s ease;
    border-radius: var(--radius-md, 0.5rem);
}

.topbar__logo:hover {
    transform: scale(1.08);
    opacity: 0.85;
}

.topbar__logo:active {
    transform: scale(0.95);
}

.topbar__logo-svg {
    width: 48px;
    height: 48px;
    display: block;
    transition: filter 0.3s ease;
}

.topbar--compact .topbar__logo-svg {
    width: 40px;
    height: 40px;
}

/* Nom de marque "Scriverse" affiché à côté du logo */
.topbar__brand-name {
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--color-primary, #365957);
    font-family: var(--font-heading, inherit);
    user-select: none;
    white-space: nowrap;
}

@media (max-width: 768px) {
    .topbar__brand-name {
        display: none;
    }
}

/* Fallback pour les anciennes implémentations avec <img> */
.topbar__brand-logo {
    height: 36px;
    width: auto;
}

.topbar__brand-text {
    font-weight: 600;
}

.topbar__tabs {
    display: flex;
    gap: var(--spacing-xs, 0.25rem);
}

.topbar__tab {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm, 0.5rem);
    padding: var(--spacing-sm, 0.5rem) var(--spacing-md, 1rem);
    border-radius: var(--radius-md, 0.75rem);
    color: var(--color-text-light, #718096);
    font-weight: 500;
    font-size: var(--font-size-sm, 0.875rem);
    transition: all var(--transition-fast, 250ms ease-in-out);
    text-decoration: none;
}

.topbar__tab:hover {
    background-color: var(--color-bg, #f8f9fa);
    color: var(--color-primary, #365957);
}

.topbar__tab--active {
    background-color: rgba(54, 89, 87, 0.1);
    color: var(--color-primary, #365957);
}

.topbar__center {
    flex: 1;
    display: flex;
    justify-content: center;
    max-width: 600px;
    margin: 0 auto;
}

.topbar__right {
    display: flex;
    align-items: center;
    gap: var(--spacing-md, 1rem);
    flex: 0 0 auto;
    margin-left: auto;
}

/* ============================================
   BARRE DE RECHERCHE
   ============================================ */
.search-bar {
    position: relative;
    width: 100%;
}

.search-bar__icon {
    position: absolute;
    left: var(--spacing-md, 1rem);
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-muted, #a0aec0);
    pointer-events: none;
}

.search-bar__input {
    width: 100%;
    padding: var(--spacing-sm, 0.5rem) var(--spacing-xl, 2rem);
    padding-left: calc(var(--spacing-xl, 2rem) + 20px);
    border: 1px solid var(--color-border, #e2e8f0);
    border-radius: var(--radius-full, 9999px);
    background-color: var(--color-bg, #f8f9fa);
    transition: all var(--transition-fast, 250ms ease-in-out);
    font-size: var(--font-size-sm, 0.875rem);
}

.search-bar__input:focus {
    outline: none;
    border-color: var(--color-primary, #365957);
    background-color: var(--color-surface, #ffffff);
    box-shadow: 0 0 0 3px rgba(54, 89, 87, 0.1);
}

.search-bar__clear {
    position: absolute;
    right: var(--spacing-md, 1rem);
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted, #a0aec0);
    opacity: 0;
    pointer-events: none;
    transition: all var(--transition-fast, 250ms ease-in-out);
    background: none;
    border: none;
    cursor: pointer;
}

.search-bar__input:not(:placeholder-shown) ~ .search-bar__clear {
    opacity: 1;
    pointer-events: all;
}

.search-bar__clear:hover {
    background-color: var(--color-bg, #f8f9fa);
    color: var(--color-error, #f56565);
}

/* ============================================
   BOUTONS ICÔNES TOPBAR
   ============================================ */
.topbar__button {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm, 0.5rem);
    padding: var(--spacing-sm, 0.5rem);
    border-radius: var(--radius-md, 0.5rem);
    color: var(--color-text-light, #718096);
    transition: all var(--transition-fast, 250ms ease-in-out);
    background: none;
    border: none;
    cursor: pointer;
    font-size: var(--font-size-sm, 0.875rem);
}

.topbar__button:hover {
    background-color: var(--color-bg, #f8f9fa);
    color: var(--color-primary, #365957);
}

.topbar__icon-btn {
    position: relative;
    min-width: 40px;
    height: 40px;
    border-radius: var(--radius-lg, 0.75rem);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-light, #718096);
    transition: all var(--transition-fast, 250ms ease-in-out);
    background: none;
    border: none;
    cursor: pointer;
}

.topbar__icon-btn:hover {
    background-color: var(--color-bg, #f8f9fa);
    color: var(--color-primary, #365957);
}

/* ============================================
   BADGE NOTIFICATIONS
   ============================================ */
/* 
   Système de badge générique
   Pour utiliser un badge, le conteneur parent DOIT avoir position: relative.
   Vous pouvez utiliser la classe utilitaire .has-badge sur le parent si nécessaire.
*/
.has-topbar-badge {
    position: relative;
    display: inline-flex;
}

.topbar-notification-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-xs);
    font-weight: 700;
    border-radius: var(--radius-full, 9999px);
    pointer-events: none;
    border: 2px solid var(--color-surface, #ffffff);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 10;
}

.topbar-notification-badge--notification {
    background-color: var(--color-error, #e53e3e);
    color: white;
}

.topbar-notification-badge--primary {
    background-color: var(--color-primary, #365957);
    color: white;
}

.topbar-notification-badge--success {
    background-color: var(--color-success, #48bb78);
    color: white;
}

.topbar-notification-badge--warning {
    background-color: var(--color-warning, #ed8936);
    color: white;
}

.topbar-notification-badge--danger {
    background-color: var(--color-error, #f56565);
    color: white;
}

.topbar-notification-badge--info {
    background-color: var(--color-info, #4299e1);
    color: white;
}

/* ============================================
   MENU UTILISATEUR
   ============================================ */
.topbar__user-menu {
    position: relative;
}

.topbar__user-btn {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm, 0.5rem);
    padding: var(--spacing-xs, 0.25rem) var(--spacing-sm, 0.5rem);
    border-radius: var(--radius-lg, 0.75rem);
    transition: background-color var(--transition-fast, 250ms ease-in-out);
    background: none;
    border: none;
    cursor: pointer;
}

.topbar__user-btn:hover {
    background-color: var(--color-bg, #f8f9fa);
}

/* Compat : ancien sélecteur + avatar unifié dans la topbar */
.topbar__user-avatar,
.topbar__user-btn .entity-cell__avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: none;
}

.topbar__user-name {
    font-weight: 500;
    font-size: var(--font-size-sm, 0.875rem);
    color: var(--color-text, #2d3748);
}

.topbar__user-btn i {
    font-size: var(--font-size-xs, 0.75rem);
    color: var(--color-text-muted, #a0aec0);
}

/* ============================================
   DROPDOWN MENU
   ============================================ */
.dropdown-menu {
    position: absolute;
    top: calc(100% + var(--spacing-sm, 0.5rem));
    right: 0;
    min-width: 200px;
    background-color: var(--color-surface, #ffffff);
    border-radius: var(--radius-lg, 0.75rem);
    box-shadow: var(--shadow-lg, 0 10px 15px rgba(0, 0, 0, 0.1));
    padding: var(--spacing-sm, 0.5rem);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all var(--transition-fast, 250ms ease-in-out);
    z-index: 1000;
}

.topbar__item--dropdown:hover .dropdown-menu,
.dropdown-menu--open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* User menu dropdown */
.topbar__user-menu:hover .dropdown-menu,
.topbar__user-menu .dropdown-menu--open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-menu__header {
    padding: 0.75rem 1rem;
    font-weight: 600;
    font-size: var(--font-size-sm, 0.875rem);
    color: var(--color-text, #2d3748);
    border-bottom: 1px solid var(--color-divider, #edf2f7);
    margin-bottom: 0.5rem;
}

.dropdown-menu__item {
    display: flex;
    align-items: center;
    gap: var(--spacing-md, 1rem);
    padding: var(--spacing-sm, 0.5rem) var(--spacing-md, 1rem);
    border-radius: var(--radius-md, 0.5rem);
    color: var(--color-text, #2d3748);
    font-size: var(--font-size-sm, 0.875rem);
    transition: background-color var(--transition-fast, 250ms ease-in-out);
    text-decoration: none;
}

.dropdown-menu__item:hover {
    background-color: var(--color-bg, #f8f9fa);
}

.dropdown-menu__item--danger {
    color: var(--color-error, #f56565);
}

.dropdown-menu__item--danger:hover {
    background-color: rgba(245, 101, 101, 0.1);
}

.dropdown-menu__icon {
    width: 20px;
    text-align: center;
    flex-shrink: 0;
    color: var(--color-text-light, #718096);
}

.dropdown-menu__text {
    flex: 1;
}

.dropdown-menu__badge {
    padding: 0.125rem 0.5rem;
    font-size: var(--font-size-xs);
    font-weight: 600;
    border-radius: var(--radius-full, 9999px);
    background-color: var(--color-bg, #f8f9fa);
    color: var(--color-text-light, #718096);
}

.dropdown-menu__badge--primary {
    background-color: rgba(54, 89, 87, 0.1);
    color: var(--color-primary, #365957);
}

.dropdown-menu__badge--danger {
    background-color: rgba(245, 101, 101, 0.1);
    color: var(--color-error, #f56565);
}

.dropdown-menu__divider {
    height: 1px;
    background-color: var(--color-divider, #edf2f7);
    margin: var(--spacing-sm, 0.5rem) 0;
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    /* Padding pour compenser le topbar fixed sur mobile */
    body {
        padding-top: var(--topbar-height, 64px);
    }
    
    .topbar {
        padding: 0 1rem;
        padding-left: 72px; /* Espace augmenté pour le hamburger + marge */
        gap: 0.5rem;
        position: fixed;
        left: 0;
        right: 0;
        top: 0;
        height: var(--topbar-height, 64px);
        justify-content: flex-start; /* Alignement à gauche pour le logo */
        transition: top 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                    height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    /* Logo mobile - plus petit et positionné correctement */
    .topbar__logo {
        margin-right: auto; /* Pousse les autres éléments à droite */
    }
    
    .topbar__logo-svg {
        width: 36px;
        height: 36px;
    }
    
    /* Pas de mode compact sur mobile */
    .topbar--compact {
        height: var(--topbar-height, 64px);
    }
    
    /* Topbar cachée sur mobile */
    .topbar--hidden {
        top: calc(-1 * var(--topbar-height, 64px));
    }
    
    /* Cacher la partie gauche (tabs/brand) */
    .topbar__left {
        display: none;
    }
    
    /* Cacher la search bar */
    .topbar__center {
        display: none;
    }
    
    /* Tout aligner à droite */
    .topbar__right {
        margin-left: 0;
        flex: 1;
        justify-content: flex-end;
    }
    
    /* Afficher tous les boutons en icônes uniquement */
    .topbar__icon-btn span:not(.topbar-notification-badge),
    .topbar__button span:not(.topbar-notification-badge),
    .topbar__user-name,
    .topbar__tab span {
        display: none;
    }
    
    /* Garder les badges de notification visibles */
    .topbar-notification-badge {
        display: inline-flex !important;
    }
    
    /* Ajuster la taille des boutons */
    .topbar__icon-btn,
    .topbar__button {
        height: 44px;
        min-width: 44px;
        padding: 0;
        justify-content: center;
    }
    
    /* Menu utilisateur mobile */
    .topbar__user-btn {
        padding: 0;
        min-width: 44px;
    }
    
    .topbar__user-avatar {
        width: 36px;
        height: 36px;
    }
    
    /* Cacher la flèche du menu user */
    .topbar__user-btn .fa-chevron-down {
        display: none;
    }
    
    /* Afficher les tabs en version icône seulement */
    .topbar__tabs {
        display: flex;
        gap: 0.25rem;
    }
    
    .topbar__tab {
        width: 44px;
        height: 44px;
        padding: 0;
        justify-content: center;
        min-width: 44px;
    }
}

@media (max-width: 480px) {
    .topbar {
        padding: 0 0.5rem;
        padding-left: 68px; /* Espace pour hamburger sur très petits écrans */
        gap: 0.5rem;
    }
    
    /* Logo encore plus petit sur très petits écrans */
    .topbar__logo-svg {
        width: 32px;
        height: 32px;
    }
    
    .topbar__button {
        width: 36px;
        height: 36px;
    }
    
    .search-bar__input {
        padding: 0.375rem 1.5rem;
        padding-left: calc(1.5rem + 20px);
    }
}
