/* =========================
   Header — layout + user pill + mobile drawer
   ========================= */

/* Teintes locales (s'appuient sur les tokens globaux) */
:root{
  --hdr-bg: rgba(15, 23, 42, 0.85);
  --hdr-border: rgba(255,255,255,.08);
  --border-color: rgba(255,255,255,.1);
  --border-color-hover: rgba(255,255,255,.2);
  --pill-bg: rgba(255,255,255,.06);
  --pill-bg-hover: rgba(255,255,255,.12);
  --menu-bg: #0f1729;
  --header-h: 70px; /* hauteur de barre */
  --header-space-below: 0;
  --header-blur: 20px;
}
:root[data-theme="light"]{
  --hdr-bg: rgba(255, 255, 255, 0.85);
  --hdr-border: rgba(0,0,0,.08);
  --border-color: rgba(0,0,0,.1);
  --border-color-hover: rgba(0,0,0,.2);
  --pill-bg: rgba(0,0,0,.05);
  --pill-bg-hover: rgba(0,0,0,.1);
  --menu-bg: #ffffff;
}

/* ====== Barre ====== */
.site-header{
  position: sticky; top: 0; z-index: 2000;
  background: var(--hdr-bg);
  backdrop-filter: blur(var(--header-blur));
  -webkit-backdrop-filter: blur(var(--header-blur));
  border-bottom: 1px solid var(--hdr-border);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
  margin-bottom: var(--header-space-below);
}
.header-inner{
  display: flex; align-items: center; gap: 16px;
  min-height: var(--header-h);
  padding: 0 1.5rem;
}

/* Logo / brand */
.brand{ 
  display: inline-flex; 
  align-items: center; 
  gap: 12px;
  padding: 8px 12px;
  border-radius: 12px;
  transition: background 0.2s ease;
}
.brand:hover{
  background: var(--pill-bg);
}
#brandLogo{ 
  width: 44px; 
  height: 44px; 
  display: block;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.15));
}

/* Boutons d'icône (thème, burger) */
.icon-btn{
  all: unset;
  display: inline-grid; place-items: center;
  width: 40px; height: 40px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--pill-bg);
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 1.1rem;
}
.icon-btn:hover{
  background: var(--pill-bg-hover);
  border-color: var(--border-color-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.icon-btn:active{
  transform: translateY(0);
}
.icon-btn:focus-visible{ outline: 2px solid #7aa2ff; outline-offset: 2px; }

/* Espaces autour du bouton thème (logo ↔ thème ↔ menus) */
:root { --header-gap-x: 16px; }
#themeToggle { margin-inline: var(--header-gap-x); }

/* Active users badge */
.active-users{
  display: inline-flex; 
  align-items: center; 
  gap: .6rem;
  padding: .5rem .9rem;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: var(--pill-bg);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  position: relative;
  cursor: pointer;
  user-select: none;
  font-size: 0.9rem;
  transition: all 0.2s ease;
}
.active-users strong{ 
  font-weight: 700;
  color: #00d9ff;
}
.active-users{ margin-left: 0; }
.active-users:hover,
.active-users.open{
  background: var(--pill-bg-hover);
  border-color: var(--border-color-hover);
  box-shadow: 0 6px 20px rgba(0,0,0,.2);
  transform: translateY(-1px);
}

/* ===== Notifications bell (between Active Users and Profile) ===== */
.notif-bell-wrap{
  position: relative;
  display: inline-flex;
  align-items: center;
}
/* When active-users is present, keep a small gap between it and the bell */
.active-users + .notif-bell-wrap{ margin-left: 0; }
/* Ensure the profile pill doesn't add another auto margin when following the bell */
.notif-bell-wrap + .userbox{ margin-left: 0; }
/* And when both are present: active-users → bell → userbox */
.active-users + .notif-bell-wrap + .userbox{ margin-left: 0; }
.notif-btn{
  all: unset;
  display: inline-grid; place-items: center;
  width: 36px; height: 36px;
  border: 1px solid var(--border-color);
  border-radius: 10px; cursor: pointer; user-select: none;
  background: var(--pill-bg);
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease, transform .1s ease;
}
.notif-btn:hover{ background: var(--pill-bg-hover); border-color: var(--border-color-hover); box-shadow: 0 6px 18px rgba(0,0,0,.18); }
.notif-btn:active{ transform: translateY(1px); }
.notif-btn:focus-visible{ outline: 2px solid #7aa2ff; outline-offset: 2px; }
.notif-dot{
  position: absolute; top: -2px; right: -2px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 999px; background: #ff5a76; color: white;
  font-size: 11px; line-height: 16px; text-align: center;
  box-shadow: 0 0 0 2px var(--hdr-bg);
}
.notif-popover{
  position: absolute; top: calc(100% + 8px); right: 0; min-width: 280px; max-width: 340px; max-height: 60vh;
  overflow: auto; background: var(--menu-bg); color: inherit;
  border: 1px solid var(--border-color); border-radius: .6rem;
  box-shadow: 0 12px 34px rgba(0,0,0,.35);
  padding: .35rem; z-index: 2100; display: none;
}
.notif-bell-wrap.open .notif-popover{ display: block; }
.notif-head{ font-weight: 700; padding: .4rem .5rem; }
.notif-empty{ padding: .6rem .7rem; opacity: .8; }
.notif-list{ list-style: none; margin: .25rem 0 0; padding: 0; }
.notif-item{ display: flex; align-items: flex-start; gap: .55rem; padding: .55rem .6rem; border-radius: .5rem; position: relative; }
.notif-item:hover{ background: rgba(255,255,255,.06); }
.notif-item .ni-icon{ flex: 0 0 20px; text-align: center; opacity: .9; }
.notif-item .ni-content{ flex: 1 1 auto; }
.notif-item .ni-title{ font-weight: 600; }
.notif-item .ni-meta{ font-size: .85em; opacity: .7; margin-top: .15rem; }
.notif-item .ni-mark-read{
  all: unset;
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s ease;
}
.notif-item .ni-mark-read:hover{
  background: rgba(16, 185, 129, 0.25);
  transform: scale(1.1);
}
.notif-item .ni-mark-read:active{
  transform: scale(0.95);
}
.notif-item .ni-button{
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.35rem 0.75rem;
  background: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.2s ease;
}
.notif-item .ni-button:hover{
  background: rgba(59, 130, 246, 0.25);
  transform: translateY(-1px);
}
.notif-item .ni-button:active{
  transform: translateY(0);
}

/* Popover listing active users */
.active-users-popover{
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  max-width: 300px;
  max-height: 60vh;
  overflow: auto;
  background: var(--menu-bg);
  color: inherit;
  border: 1px solid var(--border-color);
  border-radius: .6rem;
  box-shadow: 0 12px 34px rgba(0,0,0,.35);
  padding: .5rem;
  z-index: 2080;
  display: none;
}
.active-users.open .active-users-popover{ display: block; }
.active-users-popover .au-title{ font-weight: 700; padding: .3rem .35rem .5rem; }
.active-users-popover .au-sub{ font-size: .9em; opacity: .8; padding: 0 .35rem .35rem; }
.active-users-popover .au-list{ list-style: none; margin: .25rem 0 0; padding: 0; }
.active-users-popover .au-item{ padding: .45rem .45rem; border-radius: .45rem; }
.active-users-popover .au-item:hover{ background: rgba(255,255,255,.06); }

/* notification styles remain for future use */

/* Nav principale (desktop) */
.nav{
  display: flex; 
  align-items: center; 
  gap: 8px;
  margin-left: auto;
  margin-right: 16px;
  flex-wrap: nowrap;
}
.nav a{
  color: inherit; 
  opacity: .85; 
  text-decoration: none;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 500;
  transition: all 0.2s ease;
  position: relative;
}
.nav a::after{
  content: '';
  position: absolute;
  bottom: 8px;
  left: 16px;
  right: 16px;
  height: 2px;
  background: var(--accent);
  opacity: 0;
  transform: scaleX(0);
  transition: all 0.2s ease;
}
.nav a:hover{
  opacity: 1; 
  background: var(--pill-bg);
}
.nav a[data-active]{ 
  opacity: 1; 
  color: var(--accent);
  background: var(--pill-bg);
}
.nav a[data-active]::after{
  opacity: 1;
  transform: scaleX(1);
}

/* Item avec sous-menu */
.nav .has-sub{ position: relative; }

/* Carret optionnel après “Fish” */
.nav .has-sub > a .carret{ margin-left: .35rem; font-size: .85em; opacity: .8; }

/* ---- Sous-menu (popover desktop) ---- */
.nav .subnav{
  /* caché par défaut */
  display: none;

  /* popover sous le parent */
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 220px;

  background: var(--menu-bg);
  color: inherit;
  border: 1px solid var(--border-color);
  border-radius: .6rem;
  box-shadow: 0 12px 34px rgba(0,0,0,.35);
  padding: .35rem;
  z-index: 2050; /* > header, < user-menu (2100) */
}

/* Lien du sous-menu */
.nav .subnav a{
  display: block;
  padding: .6rem .7rem;
  border-radius: .45rem;
  text-decoration: none;
  white-space: nowrap;
}
.nav .subnav a:hover{ background: rgba(255,255,255,.06); }

/* Affichage au survol ou au focus clavier */
.nav .has-sub:hover .subnav,
.nav .has-sub:focus-within .subnav{
  display: block;
}

/* Pont anti-"trou" entre l'item parent et le popover (évite la fermeture au passage souris) */
.nav .has-sub::after{
  content:"";
  position:absolute;
  left:0; right:0;
  top:100%;
  height:10px;           /* zone tampon */
}

/* Actions; contient le hamburger */
.right-actions{ display: flex; align-items: center; gap: 8px; }

/* La zone user est poussée complètement à droite */
.userbox{ margin-left: 0; display: flex; align-items: center; }

/* ====== Pill + dropdown ====== */
.user-logged{ position: relative; }

.user-pill{
  all: unset;
  display: inline-flex; 
  align-items: center; 
  gap: .7rem;
  padding: .5rem .8rem .5rem .5rem;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: var(--pill-bg);
  color: inherit; 
  cursor: pointer; 
  user-select: none; 
  transition: all 0.2s ease;
}
.user-pill:hover,
.user-logged.open .user-pill{
  background: var(--pill-bg-hover);
  border-color: var(--border-color-hover);
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
  transform: translateY(-1px);
}
.user-pill:active{ transform: translateY(0); }
.user-pill:focus-visible{ outline: 2px solid #7aa2ff; outline-offset: 2px; }

.user-pill .avatar{
  width: 32px; 
  height: 32px; 
  border-radius: 50%;
  object-fit: cover; 
  display: block;
  border: 2px solid var(--border-color);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.user-pill .name{
  font-weight: 600; 
  max-width: 160px; 
  white-space: nowrap;
  overflow: hidden; 
  text-overflow: ellipsis;
  font-size: 0.95rem;
  line-height: 1.2;
  display: flex;
  align-items: center;
}
.user-pill .chev{ 
  font-size: .85rem; 
  opacity: .6; 
  transition: all 0.2s ease; 
}
.user-pill:hover .chev{
  opacity: .9;
}
.user-logged.open .chev{ 
  transform: rotate(180deg); 
}

/* Menu déroulant (profil / déconnexion) */
.user-menu{
  position: absolute; top: calc(100% + 8px); right: 0; min-width: 220px;
  background: var(--menu-bg); color: inherit;
  border: 1px solid var(--border-color); border-radius: .6rem;
  box-shadow: 0 12px 34px rgba(0,0,0,.35);
  padding: .35rem; display: none; z-index: 2100; /* > header + subnav */
}
.user-logged.open .user-menu{ display: block; }

.user-menu a, .user-menu button{
  all: unset;
  display: flex; align-items: center; gap: .5rem; width: 100%;
  padding: .6rem .7rem; border-radius: .45rem; cursor: pointer;
}
.user-menu a:hover, .user-menu button:hover{ background: rgba(255,255,255,.06); }
.user-menu .logout{ color: #ff6464; }
.user-menu .logout:hover{ background: rgba(255,100,100,.15); }

/* Separator inside user menu */
.user-menu .menu-sep{
  height: 1px;
  margin: .35rem .35rem;
  background: var(--border-color);
  opacity: .7;
}

/* Teck-bits wallet row aligned to the right */
.user-menu .user-wallet{
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 6px 10px;
}

.user-menu .wallet-chip{
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: 4px 8px;
  background: rgba(90, 150, 255, 0.12);         /* bleu doux */
  border: 1px solid rgba(90, 150, 255, 0.28);    /* contour léger */
  border-radius: 999px;                           /* pilule arrondie autour valeur+symbole */
  opacity: .95;
}

.user-menu .wallet-symb{ font-weight: 700; }

/* ====== Login button (modern pill) ====== */
.btn.btn-login{
  all: unset;
  display: inline-flex; 
  align-items: center; 
  justify-content: center;
  padding: .6rem 1.2rem; 
  border-radius: 999px;
  background: linear-gradient(135deg, #00d9ff 0%, #0088ff 100%);
  color: #fff; 
  font-weight: 700; 
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 136, 255, 0.3);
  border: none;
  transition: all 0.2s ease;
}
.btn.btn-login:hover{
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 136, 255, 0.4);
}
.btn.btn-login:active{
  transform: translateY(0);
  box-shadow: 0 2px 12px rgba(0, 136, 255, 0.3);
}
.btn.btn-login:focus-visible{
  outline: 2px solid rgba(0, 136, 255, 0.5);
  outline-offset: 2px;
}

/* ====== Drawer mobile ====== */
#navToggle { display: none; }               /* caché par défaut (desktop) */
.header-inner { position: relative; }

@media (max-width: 900px) {
  /* largeur du tiroir */
  :root { --drawer-w: 220px; }

  /* Mettre le hamburger tout à gauche (avant le logo) */
  .right-actions { order: -2; }
  .brand        { order: -1; }
  #navToggle    {
    display: inline-grid; place-items: center;
    width: 36px; height: 36px;
  }

  .nav{ margin-left: 0; margin-right: 0; }

  /* La nav devient un tiroir latéral gauche, sous la barre */
  .nav{
    position: fixed; top: var(--header-h); left: 0; bottom: 0;
    width: var(--drawer-w);
    display: flex; flex-direction: column;
    gap: 8px;
    background: var(--menu-bg);
    border-right: 1px solid var(--border-color);
    padding: 12px;
    box-shadow: 0 12px 34px rgba(0,0,0,.35);
    transform: translateX(-100%); visibility: hidden;
    transition: transform .2s ease, visibility .2s;
    z-index: 2010;                           /* ↑ au-dessus du backdrop */
    text-align: left;
    overflow-y: auto;
    max-height: calc(100vh - var(--header-h));
  }

  /* Liens = boutons cliquables, alignés à gauche */
  .nav a{
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    text-align: left;
    padding: 12px 10px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
  .nav a + a { margin-top: 4px; }

  .nav a:hover,
  .nav a:active,
  .nav a[data-active="true"]{
    background: rgba(255,255,255,.06);
    color: var(--accent);
  }

  .nav[data-open="true"]{
    transform: translateX(0);
    visibility: visible;
  }

  /* Backdrop qui ne couvre pas la barre (laisse logo + thème visibles) */
  .nav-backdrop{
    position: fixed; top: var(--header-h); left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,.4);
    opacity: 0; pointer-events: none;
    transition: opacity .2s ease;
    z-index: 1900;                           /* ↓ sous le header + nav */
  }
  .nav-backdrop.open{ opacity: 1; pointer-events: auto; }

  /* Empêcher le scroll de la page quand le tiroir est ouvert */
  html.nav-open, body.nav-open { overflow: hidden; }

  /* Sous-menu dans le tiroir : en pile, pas en popover */
  .nav .has-sub::after{ display:none; }      /* pas besoin du pont en mobile */
  .nav .subnav{
    position: static;
    display: block;
    box-shadow: none;
    border: none;
    padding: 0;
  }
  .nav .subnav a{ padding: 10px 12px; }
}

/* Responsive : on cache le pseudo si l’espace manque */
@media (max-width: 520px){
  .user-pill .name{ display: none; }
}

@media (max-width: 700px){
  :root { --header-space-below: 12px; }
}

/* ===== NAVBAR (dropdown Fish) ===== */

/* Desktop : dropdown au hover + pont anti trou d’air */
@media (min-width: 901px){
  #primaryNav .has-sub{ position: relative; }
  #primaryNav .has-sub::after{
    content: "";
    position: absolute;
    left: 0; top: 100%;
    width: 100%; height: 8px;   /* comble l’écart visuel */
    pointer-events: auto;
    background: transparent;
    z-index: 1;
  }
  #primaryNav .has-sub > a{
    display: inline-flex; align-items: center; gap: 6px;
  }
  #primaryNav .has-sub .carret{ font-size: .85rem; opacity: .7; }

  #primaryNav .subnav{
    position: absolute; top: calc(100% + 8px); left: 0;  /* 8px = pont */
    min-width: 200px;
    background: var(--menu-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    box-shadow: 0 12px 34px rgba(0,0,0,.35);
    display: none;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity .15s ease, transform .15s ease;
    z-index: 2050;
    pointer-events: auto;
  }
  #primaryNav .has-sub:hover .subnav{ display: block; opacity: 1; transform: translateY(0); }

  #primaryNav .subnav a{
    display: block; padding: 8px 10px; border-radius: 6px; text-align: left;
  }
  #primaryNav .subnav a:hover,
  #primaryNav .subnav a[data-active="true"]{
    background: rgba(255,255,255,.06); color: var(--accent);
  }
}

/* Mobile (drawer) : sous-menu visible sous "Fish", aligné à gauche */
@media (max-width: 900px){
  #primaryNav .has-sub{ display: flex; flex-direction: column; }
  #primaryNav .has-sub > a{
    display: flex; align-items: center; justify-content: space-between; padding-right: 6px;
  }
  #primaryNav .has-sub .carret{ opacity: .7; }
  #primaryNav .subnav{
    display: block; padding-left: 8px; margin-top: 4px; border-left: 2px solid var(--border-color);
  }
  #primaryNav .subnav a{
    display: block; padding: 10px 8px; border-radius: 8px; text-align: left;
  }
  #primaryNav .subnav a:hover,
  #primaryNav .subnav a[data-active="true"]{
    background: rgba(255,255,255,.06); color: var(--accent);
  }
}
