/* =====================================================
   LAYOUT PLATEFORME — Shell, Sidebar, Main, Topbar
   Styles communs au layout principal. Les apps
   (dashboard, coupons, etc.) stylent #app-content.
   ===================================================== */

/* --- Variables globales --- */
:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-soft: #fbfbfc;
  --text: #141821;
  --muted: #737b8c;
  --line: #e8ebf0;
  --blue: #2f6df6;
  --blue-dark: #0c1425;
  --blue-mid: #111f38;
  --green: #1eb564;
  --orange: #f6a11a;
  --red: #ef5753;
  --shadow: 0 10px 30px rgba(16, 24, 40, 0.06);
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --sidebar-w: 280px;
  --content-max: 1180px;
  /* Modif : police Inter (sans espaces après virgules) */
  --font: Inter,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;
}

/* Reset / base */
* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

body {
  min-height: 100vh;
}

img {
  display: block;
  max-width: 100%;
}

button,
input,
select {
  font: inherit;
}

/* --- App shell : grille sidebar + main --- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* =========================
   SIDEBAR
   ========================= */
/* Conteneur de référence ; padding-top réserve la zone du logo (logo n’influence pas la nav) */
.sidebar {
  position: relative;
  background: #081a2d;
  color: #fff;
  padding: 120px 20px 28px;  /* réduire si logo remonté (ex. 110–130) pour éviter chevauchement nav */
  overflow-x: hidden;
  overflow-y: auto;
}

/* Logo sorti de la barre : position absolue, affiché par-dessus (z-index) */
.brand {
  position: absolute;
  top: 14px;   /* remonter le logo : diminuer cette valeur (ex. 0, 8, 12) */
  left: 20px;
  right: 20px;
  display: flex;
  justify-content: center;
  z-index: 2;
}

.logo-img {
  width: 240px;
  height: auto;
  object-fit: contain;
}

.brand-copy {
  line-height: 1;
}

.brand-copy strong {
  display: block;
  font-size: 21px;
  letter-spacing: 0.04em;
  font-weight: 800;
}

.brand-copy span {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  letter-spacing: 0.18em;
  color: #80b91b;
  font-weight: 700;
}

/* Nav sans marge : commence juste sous la zone logo (logo au-dessus, z-index, ne pousse rien) */
.nav-group {
  margin-top: 0;
  position: relative;
  z-index: 1;
}

/* Sections sidebar : espacement uniquement (pas de traits entre blocs) */
.nav-label {
  padding: 0 18px;
  margin: 0 0 12px;
  color: rgba(255,255,255,0.55);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
}

.nav-item + .nav-label {
  margin-top: 24px;
}

/* Modif design cible : spacing sidebar (nav-item + nav-text) */
.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  border: 0;
  background: transparent;
  color: rgba(255,255,255,0.9);
  text-align: left;
  padding: 8px 12px;
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}

/* Modif design cible : hover sidebar plus visible */
.nav-item:hover {
  background: rgba(255,255,255,0.08);
}

.nav-item.active {
  background: linear-gradient(180deg, rgba(255,255,255,0.09), rgba(255,255,255,0.045));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.05);
  position: relative;
}

/* Barre verticale à gauche pour l’item actif */
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 12px;
  bottom: 12px;
  width: 3px;
  border-radius: 999px;
  background: transparent;
}

.menu-indicator {
  position: absolute;
  left: 0;
  top: 0;
  width: 3px;
  border-radius: 999px;
  background: #ffffff;
  pointer-events: none;
  transition: transform 0.2s ease, height 0.2s ease;
  z-index: 0;
}

.nav-main {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

/* Modif design cible : taille texte nav */
.nav-text {
  font-size: 16px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-chevron {
  color: rgba(255,255,255,0.65);
  font-size: 14px;
  font-weight: 700;
}

.menu-badge {
  background: #ef4444;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 999px;
  margin-left: auto;
  min-width: 18px;
  text-align: center;
}

/* Pied de sidebar (ex. logout) */
.sidebar-footer {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 32px;
  z-index: 1;
  margin-top: 24px;
  padding-top: 8px;
}

/* Icônes génériques (sidebar + topbar) */
.icon {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: currentColor;
  flex: 0 0 20px;
}

.icon svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Badge compteur (ex. plaintes) */
.badge-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  border-radius: 999px;
  padding: 0 8px;
  background: #ef5753;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

/* =========================
   MAIN
   ========================= */
.main {
  padding: 28px 28px 34px;
  min-width: 0; /* évite débordement horizontal dans la grille app-shell */
}

/* Zone contenu apps (#app-content) : pleine largeur utile (plus de max-width / centrage) */
.content {
  width: 100%;
  max-width: none;
  margin: 0;
}

/* Empêche tout débordement horizontal (apps avec grilles / tableaux larges) */
#app-content {
  overflow-x: hidden;
  min-width: 0;
}

/* --- Topbar : recherche, actions, user --- */
/* Modif : topbar premium (padding 12px 20px, bordure, fond blanc) */
.topbar {
  display: flex;
  align-items: center;
  height: 72px;
  padding: 0 24px;
  margin-bottom: 26px;
  border-bottom: 1px solid #e9edf3;
  background: transparent;
}

.topbar-left {
  flex: 1;
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
}

.pwa-btn {
  background: linear-gradient(135deg, #2f6df6, #1e4ed8);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.pwa-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(47,109,246,0.3);
}

.pwa-btn:active {
  transform: translateY(0);
  box-shadow: none;
}

.pwa-btn::before {
  content: "\2B07  ";
}

.pwa-modal {
  position: fixed;
  inset: 0;
  z-index: 999;
}

.pwa-modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

.pwa-modal-content {
  position: relative;
  max-width: 420px;
  margin: 80px auto;
  background: #1f3b64;
  color: #fff;
  padding: 24px;
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}

.pwa-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}

.pwa-section {
  background: rgba(255, 255, 255, 0.08);
  padding: 12px;
  border-radius: 10px;
  margin-top: 14px;
}

.hidden {
  display: none;
}

/* Modif design cible : searchbar border-radius 12px */
.searchbar {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 48px;
  padding: 0 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 1px 0 rgba(16,24,40,0.02);
}

.searchbar input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 17px;
}

.searchbar input::placeholder {
  color: #666f82;
}

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  height: 32px;
  border-radius: 10px;
  background: #f5f6f9;
  border: 1px solid #e8ebf0;
  color: #616a7c;
  font-size: 14px;
  font-weight: 700;
  padding: 0 10px;
}

/* Modif design cible : primary-btn border-radius 12px */
.primary-btn {
  height: 48px;
  border: 0;
  border-radius: 12px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(180deg, #3774f8 0%, #2766ef 100%);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  box-shadow: 0 12px 24px rgba(47, 109, 246, 0.22);
  cursor: pointer;
}

/* Modif design cible : espacement top-actions */
.top-actions {
  display: flex;
  align-items: center;
  gap: 20px;
}

.topbar-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #6b7280;
}

.topbar-info .env {
  font-weight: 600;
  color: #111827;
}

.separator {
  opacity: 0.4;
}

.icon-btn {
  position: relative;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #151a23;
}

.icon-btn .badge-small {
  position: absolute;
  top: -8px;
  right: -8px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg);
}

.divider-vert {
  width: 1px;
  height: 34px;
  background: var(--line);
}

/* --- User profile (carte cliquable + dropdown) --- */
.user-profile {
  position: relative;
}

.user-profile-card {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 12px;
  transition: background 0.2s ease;
}

.user-profile-card:hover {
  background: rgba(0, 0, 0, 0.04);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(17, 24, 39, 0.15);
}

.user-avatar.avatar-placeholder {
  background: linear-gradient(135deg, #6d4c41, #c6a27c 55%, #f3ddc5);
  object-fit: none;
}

.user-profile-info {
  min-width: 0;
}

.user-name {
  display: block;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.2;
  color: var(--text);
}

.user-role {
  display: block;
  margin-top: 2px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
}

.user-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  min-width: 220px;
  padding: 8px 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
}

.user-dropdown.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-item {
  display: block;
  width: 100%;
  padding: 10px 16px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease;
}

.dropdown-item:hover {
  background: #f5f6f8;
}

.dropdown-item.logout {
  color: var(--red);
  font-weight: 600;
}

.dropdown-language {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.dropdown-select {
  padding: 4px 8px;
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.dropdown-divider {
  height: 1px;
  margin: 6px 0;
  background: var(--line);
}

/* --- Éléments layout mobile (masqués sur desktop) --- */
.mobile-header,
.mobile-menu-overlay,
.mobile-nav {
  display: none;
}

/* =========================
   RESPONSIVE
   ========================= */
@media (max-width: 1240px) {
  .app-shell {
    grid-template-columns: 290px 1fr;
  }

  .topbar {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }
}

@media (max-width: 720px) {
  .main {
    padding: 16px;
  }
}

/* =========================
   LAYOUT MOBILE / PWA (≤1024px)
   Desktop inchangé : uniquement règles conditionnelles
   ========================= */
@media (max-width: 1024px) {
  body,
  .app-shell {
    overflow-x: hidden;
  }

  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
    height: 56px;
    padding: 0 16px;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
    z-index: 1002;
  }
  .mobile-header__menu {
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }
  .mobile-header__menu:hover {
    background: rgba(0, 0, 0, 0.06);
  }
  .mobile-header__hamburger {
    width: 22px;
    height: 2px;
    background: var(--text);
    border-radius: 1px;
    box-shadow: 0 6px 0 var(--text), 0 -6px 0 var(--text);
  }
  .mobile-header__logo {
    height: 28px;
    width: auto;
    max-width: 140px;
    object-fit: contain;
    flex-shrink: 0;
  }
  .mobile-header__avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    cursor: pointer;
  }

  .mobile-menu-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1000;
  }
  body.mobile-menu-open .mobile-menu-overlay {
    display: block;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    display: block;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-w);
    z-index: 1001;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    overflow-y: auto;
  }
  body.mobile-menu-open .sidebar {
    transform: translateX(0);
  }
  .topbar {
    visibility: hidden;
    height: 0;
    padding: 0;
    overflow: visible;
    border: none;
  }
  .topbar .user-dropdown.open {
    visibility: visible;
    position: fixed;
    top: 56px;
    right: 16px;
    z-index: 1003;
  }

  .main {
    padding-top: 56px;
    padding-bottom: 72px;
    padding-left: 0;
    padding-right: 0;
    overflow-x: hidden;
    box-sizing: border-box;
  }
  .content {
    width: 100%;
    max-width: none;
    margin: 0;
    padding-left: 16px;
    padding-right: 16px;
    box-sizing: border-box;
  }

  .mobile-nav {
    display: flex;
    align-items: center;
    justify-content: space-around;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
    height: 60px;
    background: var(--bg);
    border-top: 1px solid var(--line);
    z-index: 1002;
    padding: 0 8px;
  }
  .mobile-nav__item {
    flex: 1;
    max-width: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px 4px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 8px;
    transition: color 0.15s ease, background 0.15s ease;
  }
  .mobile-nav__item:hover,
  .mobile-nav__item.active {
    color: var(--primary);
    background: rgba(0, 0, 0, 0.04);
  }
  .mobile-nav__icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .mobile-nav__icon svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
  }

  /* Grilles mobiles : max 2 colonnes (KPI 2x2, reste 1 col) */
  #app-content .admin-dash.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
  #app-content .traffic-grid {
    grid-template-columns: 1fr;
    grid-column: 1 / -1;
  }
  #app-content [class*="grid"]:not(.dashboard-grid):not(.admin-dash) {
    grid-template-columns: 1fr;
  }

  /* Cartes : pleine largeur, marge, ombre, padding mobile */
  #app-content .admin-tile,
  #app-content .traffic-card,
  #app-content [class*="card"],
  #app-content [class*="tile"] {
    width: 100%;
    min-width: 0;
    margin-bottom: 16px;
    box-sizing: border-box;
  }
  #app-content .admin-tile {
    min-height: 0;
    padding: 12px 10px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
  }
  #app-content .traffic-card {
    padding: 12px 14px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
  }

  /* Graphiques : pleine largeur, pas de débordement */
  #app-content .traffic-chart,
  #app-content .traffic-section,
  #app-content [class*="chart"] {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }
  #app-content .traffic-chart {
    height: 220px;
  }
  #app-content .traffic-card,
  #app-content [class*="chart-container"] {
    overflow-x: auto;
  }
  #app-content .traffic-section {
    grid-column: 1 / -1;
  }

  /* Texte mobile : titres et labels légèrement réduits */
  #app-content h1 { font-size: 1.35rem; }
  #app-content h2 { font-size: 1.2rem; }
  #app-content h3 { font-size: 1.05rem; }
  #app-content .admin-tile__label { font-size: 12px; }
  #app-content .admin-tile__value { font-size: 1.35rem; }
  #app-content .traffic-title { font-size: 14px; }
  #app-content .traffic-subtitle { font-size: 12px; }
  /* Exclut la toolbar Synthèse (meeting) : styles définis dans Apps-meeting/meetings.css */
  #app-content button:not(.meeting-page .editor-toolbar button),
  #app-content .btn,
  #app-content [role="button"] {
    padding: 8px 12px;
    font-size: 13px;
  }

  #dashboard-section {
    margin: 0;
  }
}

/* Mobile ≤768px : menu latéral lisible (Helpdesk), shell aligné sidebar — desktop inchangé */
@media (max-width: 768px) {
  /* 1. COULEUR UNIFORME (HEADER + FOOTER + SIDEBAR) */
  .mobile-header,
  .topbar,
  .bottom-nav,
  .mobile-footer,
  .mobile-nav,
  .sidebar {
    background: #0b2239 !important; /* même teinte que la sidebar */
    color: #fff;
  }

  /* 2. FOOTER NE CACHE PLUS LE CONTENU */
  body {
    padding-bottom: 80px;
  }

  .container,
  .content,
  #app-content {
    padding-bottom: 90px;
  }

  /* 3. SIDEBAR SCROLLABLE COMPLET */
  .sidebar,
  .mobile-menu {
    height: 100vh;
    overflow-y: auto;
    padding-bottom: 100px; /* espace pour voir Helpdesk */
  }

  /* 4. FIX COUPE HAUT SIDEBAR */
  .sidebar-header,
  .sidebar-logo,
  .brand {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #0b2239;
  }

  .brand {
    position: sticky !important;
    left: auto;
    right: auto;
  }

  /* OPTION PROPRE : cacher logo en mobile */
  .sidebar-logo,
  .logo-img {
    display: none;
  }

  /* Zone logo retirée : moins de padding haut pour libérer la liste */
  .sidebar {
    padding-top: 32px;
  }

  /* 5. FIX DERNIERS ITEMS (HELPDESK) */
  .sidebar a:last-child,
  .mobile-menu a:last-child,
  .sidebar .nav-item:last-child {
    margin-bottom: 60px;
  }
}

/* Mobile ≤768px : burger lisible, dashboard dégagé sous le header fixe — desktop inchangé */
@media (max-width: 768px) {
  /* 1. BURGER ICON BLANC */
  .mobile-header button,
  .mobile-header svg,
  .mobile-header .menu-toggle {
    color: #fff !important;
    fill: #fff !important;
  }

  .mobile-header__hamburger {
    background: #fff !important;
    box-shadow: 0 6px 0 #fff, 0 -6px 0 #fff !important;
  }

  /* 2. MENU NON CACHE PAR HEADER */
  .sidebar,
  .mobile-menu {
    top: 0; /* important */
    height: 100vh;
    padding-top: 60px; /* espace header */
    overflow-y: auto;
  }

  /* 3. HEADER FIX PROPRE — z-index > .sidebar (1001) pour que le burger reste cliquable */
  .mobile-header,
  .topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1002;
  }

  /* 4. EVITER QUE LE MENU PASSE SOUS HEADER */
  .sidebar-header {
    display: none; /* on supprime zone inutile */
  }

  /* 5. PREMIER ITEM (DASHBOARD) VISIBLE — nav : premier .nav-item (pas de <a>) */
  .sidebar a:first-child,
  .sidebar .nav-group .nav-item:first-of-type {
    margin-top: 10px;
  }
}
