/* ============================================================
   layout.css — Page shell: navigation, sections, flex helpers
   Loaded on every page via Page::displayHeader()
   ============================================================ */

/* ── Navigation (desktop) ──────────────────────────────── */

.main-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  padding: 4px 8px;
  margin-bottom: var(--space-3);
  background: #fff;
  border-bottom: 1px solid var(--color-border);
}

.nav-brand {
  flex-shrink: 0;
  padding: 4px;
  cursor: pointer;
}

.nav-brand img {
  display: block;
}

.nav-items {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  flex: 1;
}

.menu-icon {
  display: none;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 6px;
  width: 75px;
  font-size: 11px;
  line-height: 1.3;
}

/* br between icon and label — not needed with flexbox gap */
.menu-icon br {
  display: none;
}

.menu-icon.is-active {
  background: var(--color-primary-light);
  border-radius: 8px;
  font-weight: 700;
  color: var(--color-primary);
}

.menu-icon a {
  color: inherit;
  text-decoration: none;
}

.menu-icon img {
  margin-bottom: 3px;
}

/* kept for legacy compatibility */
.menu-item {
  display: inline-flex;
  align-items: center;
  width: 60px;
  padding-right: 6px;
}

.tab {
  display: inline-flex;
  align-items: center;
  padding-left: 25px;
}

.menu-logged-in {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 16px;
  text-align: center;
  color: silver;
  font-size: 11px;
}

.nav-logout {
  display: flex;
  align-items: center;
  padding: 0 6px;
}

/* ── Profile dropdown ───────────────────────────────────── */

.nav-profile {
  position: relative;
  margin-left: auto;
  flex-shrink: 0;
}

.nav-profile-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px 7px 8px;
  border: 2px solid var(--color-brand);
  border-radius: var(--radius-pill);
  background: var(--color-brand);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

.nav-profile-btn:hover {
  background: var(--color-brand-hover);
  border-color: var(--color-brand-hover);
  color: #fff;
}

/* Avatar circle inside the button */
.nav-profile-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.nav-profile-name {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-profile-chevron {
  flex-shrink: 0;
  transition: transform 0.2s;
}

.nav-profile-btn[aria-expanded="true"] .nav-profile-chevron {
  transform: rotate(180deg);
}

.nav-profile-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 4px 0;
  z-index: 200;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  /* Full list visible on desktop (same entries as mobile drawer); scroll only if the viewport is short */
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.nav-profile-menu[hidden] {
  display: none;
}

/* Bandeau profil vert en tête du menu déroulant (desktop, comme le tiroir mobile) */
@media (min-width: 769px) {
  .nav-profile-name {
    max-width: min(50vw, 28rem);
  }

  .nav-profile-menu {
    padding: 0 0 4px;
    min-width: 260px;
  }

  .nav-profile-menu > .nav-drawer-profile {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-4) var(--space-4);
    background: var(--color-brand);
    color: #fff;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
  }

  .nav-profile-menu > .nav-drawer-profile .nav-drawer-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .nav-profile-menu > .nav-drawer-profile .nav-drawer-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
  }

  .nav-profile-menu > .nav-drawer-profile .nav-drawer-name {
    font-weight: 700;
    font-size: var(--text-md, 1rem);
    line-height: var(--leading-tight, 1.25);
    word-break: break-word;
    color: #fff;
  }

  .nav-profile-menu > .nav-drawer-profile .nav-drawer-role {
    font-size: var(--text-xs, 0.8rem);
    opacity: 0.78;
    color: #fff;
  }
}

.nav-profile-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  font-size: 13px;
  color: var(--color-text);
  text-decoration: none;
  transition: background 0.12s;
}

.nav-profile-item:hover {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.nav-profile-item--logout {
  color: #c0392b;
}

.nav-profile-item--logout:hover {
  background: #fdf2f2;
  color: #c0392b;
}

.nav-profile-sep {
  height: 1px;
  background: var(--color-border);
  margin: 4px 0;
}

/* ── Mobile drawer (hidden on desktop) ──────────────────── */

.nav-drawer-profile,
.nav-drawer-list,
.nav-drawer-sep {
  display: none;
}

.nav-drawer-item {
  display: none;
}

/* kept for legacy inline uses in page content (search bars, toolbars) */
.vertical-align {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
}

/* ── Footer ─────────────────────────────────────────────── */

.footer {
  color: gray;
  overflow: hidden;
  padding: 8px;
  background-color: ghostwhite;
  font-size: 12px;
  text-align: center;
}

/* ── Float sections (panier-contenu, etc.) ──────────────── */

.left-section {
  width: 65%;
  float: left;
  border-collapse: collapse;
  overflow: auto;
}

.right-section {
  width: 35%;
  float: right;
  border-collapse: collapse;
  overflow: auto;
}

.top-section {
  width: 100%;
  border-collapse: collapse;
}

/* ── Flex layout helpers ────────────────────────────────── */

.container {
  width: 100%;
}

.row {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
}

.bloc {
  padding: 10px;
  box-sizing: border-box;
}

.bloc-gauche {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

.bloc-droite {
  background-color: ghostwhite;
  border: solid 1px var(--color-primary);
  width: 300px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.bloc-image {
  width: 100%;
  text-align: center;
  margin-top: 10px;
}

.bloc-full {
  width: 100%;
  margin-top: 10px;
}

/* ── Mobile overrides ───────────────────────────────────── */

@media (max-width: 768px) {

  /* Top bar: logo | bouton profil (ouvre le panneau mobile à la place de l’ancien burger) */
  .main-nav {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    align-items: center;
    column-gap: 8px;
    row-gap: 0;
    flex-wrap: nowrap;
    box-sizing: border-box;
    max-width: 100%;
    position: relative;
    z-index: 20;
  }

  .nav-brand {
    grid-column: 1;
    grid-row: 1;
    justify-self: start;
    min-width: 0;
  }

  .nav-profile {
    display: block;
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    align-self: center;
    margin-left: 0;
    min-width: 0;
  }

  .nav-profile-name {
    max-width: min(40vw, 180px);
  }

  /* Panneau déroulant desktop : pas utilisé sur mobile (menu = tiroir) */
  .nav-profile-menu {
    display: none !important;
  }

  .nav-items {
    grid-column: 1 / -1;
    grid-row: 2;
    flex: none;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    display: none;
    flex-direction: column;
    align-items: stretch;
    align-self: stretch;
    justify-content: flex-start;
    border-top: 1px solid var(--color-border);
    padding: 0;
    margin: 0;
    background: #fff;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.10);
  }

  .nav-items.is-open {
    display: flex;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    overflow: hidden;
  }

  /* Hide desktop icon items when drawer opens */
  .menu-icon,
  .nav-items.is-open .menu-icon {
    display: none;
  }

  /* ── Drawer: green profile header ─── */

  .nav-items.is-open .nav-drawer-profile {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-5) var(--space-4) var(--space-4);
    background: var(--color-brand);
    color: #fff;
  }

  .nav-drawer-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .nav-drawer-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
  }

  .nav-drawer-name {
    font-weight: 700;
    font-size: var(--text-md);
    line-height: var(--leading-tight);
    word-break: break-word;
  }

  .nav-drawer-role {
    font-size: var(--text-xs);
    opacity: 0.78;
  }

  /* ── Drawer: flat item list ──────── */

  .nav-items.is-open .nav-drawer-list {
    display: block;
  }

  .nav-drawer-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 16px;
    font-size: 14px;
    color: var(--color-text);
    text-decoration: none;
    border-bottom: 1px solid var(--color-border);
    transition: background 0.12s;
  }

  .nav-drawer-item.is-active {
    border-left: 3px solid var(--color-primary);
    padding-left: 13px;
    background: var(--color-primary-light);
    color: var(--color-primary);
    font-weight: 700;
  }

  .nav-drawer-item:hover,
  .nav-drawer-item:active {
    background: var(--color-primary-light);
    color: var(--color-primary);
  }

  .nav-drawer-item--logout {
    color: #c0392b;
  }

  .nav-drawer-item--logout:hover,
  .nav-drawer-item--logout:active {
    background: #fdf2f2;
    color: #c0392b;
  }

  .nav-items.is-open .nav-drawer-sep {
    display: block;
    height: 1px;
    background: var(--color-border);
    margin: 4px 0;
  }

  /* Stack float sections vertically; remove fixed heights */
  .left-section,
  .right-section {
    width: 100%;
    float: none;
    height: auto;
  }

  /* Sidebar becomes full-width */
  .bloc-droite {
    width: 100%;
  }
}

/* ── Lignes panier (#panier-contenu, APIs charger / produit) ─── */

#panier-contenu > .panier-ligne {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 8px 6px;
  margin: 0 0 6px;
  box-sizing: border-box;
  border-radius: 8px;
}

#panier-contenu > .panier-ligne:nth-child(even) {
  background: rgba(42, 122, 184, 0.09);
}

#panier-contenu > .panier-ligne:nth-child(odd) {
  background: #f8fafc;
}

#panier-contenu .panier-ligne__qty {
  flex: 0 0 auto;
  min-width: 0;
}

#panier-contenu .panier-ligne__qty-field {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

#panier-contenu .panier-ligne__qty-stepper {
  flex-wrap: nowrap;
  gap: 2px;
  align-items: center;
}

#panier-contenu .panier-qty-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  min-width: 2rem;
  height: 2.35rem;
  margin: 0;
  padding: 0;
  font: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1;
  color: var(--color-primary, #2a7ab8);
  background: #e8f1f8;
  border: 2px solid #c5d8e8;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

#panier-contenu .panier-qty-btn:hover {
  background: var(--color-primary-light, #d6e8f4);
  border-color: #8eb8d4;
}

#panier-contenu .panier-qty-btn:active {
  background: #d0e0ed;
}

#panier-contenu .panier-qty-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(42, 122, 184, 0.22);
}

#panier-contenu .panier-qty-input {
  width: 3rem;
  min-width: 2.75rem;
  max-width: 4.25rem;
  padding: 6px 2px;
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  border: 2px solid #c5d8e8;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  transition: border-color 0.15s, box-shadow 0.15s;
  -moz-appearance: textfield;
  appearance: textfield;
}

#panier-contenu .panier-qty-input::-webkit-outer-spin-button,
#panier-contenu .panier-qty-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

#panier-contenu .panier-qty-input:hover {
  border-color: #8eb8d4;
}

#panier-contenu .panier-qty-input:focus {
  border-color: var(--color-primary, #2a7ab8);
  outline: none;
  box-shadow: 0 0 0 3px rgba(42, 122, 184, 0.22);
}

#panier-contenu .panier-ligne__unite {
  font-size: 0.82rem;
  font-weight: 700;
  color: #4a5568;
  line-height: 1;
  align-self: center;
}

#panier-contenu .panier-ligne__thumb {
  flex: 0 0 auto;
}

#panier-contenu .panier-ligne__img {
  display: block;
  width: 50px;
  height: 50px;
  object-fit: cover;
  border-radius: 8px;
}

#panier-contenu .panier-ligne__nom {
  flex: 1 1 auto;
  min-width: 0;
  align-self: center;
  line-height: 1.35;
  overflow-wrap: break-word;
  word-wrap: break-word;
  font-weight: 600;
  color: #1a202c;
}
