/* ============================================================
   HARD DÉCO — Lot 9E-1
   Coque de navigation : topbar, sidebar et navigation mobile.
   Cette couche ne modifie aucun composant métier.
   ============================================================ */

:root {
  --app-topbar-h: 64px;
  --app-sidebar-w: 244px;
  --app-sidebar-w-collapsed: 76px;
  --app-mobile-nav-h: 68px;
  --header-h: var(--app-topbar-h);
}

body.app-shell-visible {
  --app-content-offset: var(--app-sidebar-w);
}

body.app-shell-visible.app-sidebar-collapsed {
  --app-content-offset: var(--app-sidebar-w-collapsed);
}

body.app-shell-visible #main-content {
  min-height: 100dvh;
  margin-left: var(--app-content-offset);
  padding-top: calc(var(--app-topbar-h) + env(safe-area-inset-top, 0px));
  transition: margin-left .2s ease;
}

body.app-shell-visible #main-content > .toolbar {
  top: calc(var(--app-topbar-h) + env(safe-area-inset-top, 0px));
}

.app-shell-root [hidden] { display: none !important; }

.header.app-shell {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 1000;
  height: calc(var(--app-topbar-h) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  overflow: visible;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  box-shadow: 0 1px 0 rgba(15, 23, 42, .025);
  backdrop-filter: blur(14px);
}

.header.app-shell .app-topbar {
  width: 100%;
  max-width: none;
  height: var(--app-topbar-h);
  margin: 0;
  padding: 0 18px;
  display: grid;
  grid-template-columns: minmax(210px, auto) minmax(120px, 1fr) auto;
  align-items: center;
  gap: 18px;
}

.app-topbar-start,
.app-topbar-actions,
.app-brand,
.app-route-context {
  display: flex;
  align-items: center;
}

.app-topbar-start { gap: 8px; min-width: 0; }
.app-topbar-actions { position: relative; gap: 6px; justify-content: flex-end; }
.header.app-shell #tipAccount { gap: 4px; }

.app-sidebar-toggle {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  border: 1px solid transparent;
  box-shadow: none;
}

.app-sidebar-toggle:hover { border-color: var(--border); }
.app-sidebar-toggle .lucide { width: 19px; height: 19px; }

.app-brand { min-width: 0; gap: 10px; border-radius: 10px; }
.app-brand:focus-visible { outline: none; box-shadow: var(--ring); }
.app-brand .logoCircle { flex: 0 0 34px; width: 34px; height: 34px; }
.app-brand .logoCircle img { width: 32px; height: 32px; }
.app-brand-copy { min-width: 0; display: flex; flex-direction: column; line-height: 1.05; }
.app-brand-copy strong { font-size: 13px; font-weight: 750; letter-spacing: -.01em; }
.app-brand-copy small { margin-top: 3px; color: var(--muted); font-size: 10px; font-weight: 550; letter-spacing: .08em; text-transform: uppercase; }

.app-route-context {
  justify-self: center;
  min-width: 0;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.app-route-context .lucide { width: 16px; height: 16px; color: var(--accent); }

.app-global-new {
  min-height: 38px;
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 13px;
  box-shadow: none;
}
.app-global-new .lucide { width: 16px; height: 16px; }

.header.app-shell .actions .iconbtn {
  width: 38px;
  height: 38px;
  box-shadow: none;
}

.header.app-shell .pop { top: calc(100% + 12px); }

/* Le bouton de création est désormais permanent dans la topbar. L’accueil
   conserve son moteur d’actions, mais n’affiche pas un second déclencheur. */
body.app-shell-visible .home-command {
  grid-template-columns: auto minmax(300px, 1fr);
}
body.app-shell-visible .home-command > .home-command-copy { grid-column: 1; }
body.app-shell-visible .home-command > .home-search { grid-column: 2; }
body.app-shell-visible .home-command > .home-new-button { display: none !important; }

/* Sidebar --------------------------------------------------- */
.app-sidebar {
  position: fixed;
  inset: calc(var(--app-topbar-h) + env(safe-area-inset-top, 0px)) auto 0 0;
  z-index: 995;
  width: var(--app-sidebar-w);
  padding: 12px 10px 16px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-right: 1px solid var(--border);
  background: var(--panel);
  transition: width .2s ease;
  scrollbar-width: thin;
}

.app-sidebar #mainNav {
  width: 100%;
  min-width: 0;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 7px;
}

.app-nav-group {
  display: grid;
  gap: 2px;
  padding: 0 0 7px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 72%, transparent);
}

.app-nav-group:last-child { border-bottom: 0; }
.app-nav-group-bottom { margin-top: auto; }

.app-nav-heading {
  min-height: 26px;
  padding: 8px 10px 4px;
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: .075em;
  text-transform: uppercase;
  white-space: nowrap;
}

.app-sidebar #mainNav :is(a, .app-nav-action) {
  position: relative;
  width: 100%;
  min-height: 39px;
  margin: 0;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 11px;
  border: 0;
  border-radius: 9px;
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 530;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}

.app-sidebar #mainNav :is(a, .app-nav-action):hover {
  background: var(--hover);
  color: var(--text);
}

.app-sidebar #mainNav :is(a, .app-nav-action):focus-visible {
  box-shadow: var(--ring);
}

.app-sidebar #mainNav a[aria-current="page"] {
  background: color-mix(in srgb, var(--accent) 10%, var(--panel));
  color: var(--accent);
  font-weight: 680;
}

.app-sidebar #mainNav a[aria-current="page"]::before {
  content: "";
  position: absolute;
  inset: 8px auto 8px 0;
  width: 3px;
  border-radius: 999px;
  background: var(--accent);
}

.app-sidebar #mainNav :is(a, .app-nav-action) > .lucide {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  color: var(--muted);
}

.app-sidebar #mainNav a[aria-current="page"] > .lucide,
.app-sidebar #mainNav :is(a, .app-nav-action):hover > .lucide { color: var(--accent); }

.app-nav-label { overflow: hidden; text-overflow: ellipsis; }
.app-sidebar #ink { display: none; }

body.app-sidebar-collapsed .app-sidebar { width: var(--app-sidebar-w-collapsed); padding-inline: 9px; }
body.app-sidebar-collapsed .app-sidebar #mainNav { gap: 4px; }
body.app-sidebar-collapsed .app-nav-group { padding-bottom: 4px; }
body.app-sidebar-collapsed .app-nav-heading,
body.app-sidebar-collapsed .app-nav-label { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
body.app-sidebar-collapsed .app-sidebar #mainNav :is(a, .app-nav-action) { justify-content: center; min-height: 42px; padding-inline: 0; }
body.app-sidebar-collapsed .app-sidebar-toggle .lucide { transform: rotate(180deg); }

/* Navigation mobile ---------------------------------------- */
.app-mobile-nav,
.app-mobile-backdrop,
.app-mobile-sheet { display: none; }

@media (max-width: 1120px) and (min-width: 901px) {
  body.app-shell-visible { --app-content-offset: var(--app-sidebar-w-collapsed); }
  .app-sidebar { width: var(--app-sidebar-w-collapsed); padding-inline: 9px; }
  .app-sidebar #mainNav { gap: 4px; }
  .app-nav-group { padding-bottom: 4px; }
  .app-nav-heading,
  .app-sidebar .app-nav-label { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .app-sidebar #mainNav :is(a, .app-nav-action) { justify-content: center; min-height: 42px; padding-inline: 0; }
  .app-sidebar-toggle { visibility: hidden; }
  .app-brand-copy { display: none; }
}

@media (max-width: 900px) {
  :root { --app-topbar-h: 58px; }

  body.app-shell-visible { --app-content-offset: 0px; }
  body.app-shell-visible #main-content {
    margin-left: 0;
    padding-bottom: calc(var(--app-mobile-nav-h) + env(safe-area-inset-bottom, 0px) + 8px);
  }

  .header.app-shell .app-topbar {
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    padding-inline: 14px;
  }

  .app-sidebar-toggle,
  .app-sidebar { display: none; }
  .app-brand-copy { display: none; }
  .app-brand .logoCircle { width: 32px; height: 32px; }
  .app-brand .logoCircle img { width: 30px; height: 30px; }
  .app-route-context { justify-self: start; }
  .header.app-shell .actions { position: relative; inset: auto; }
  body.app-shell-visible .home-command { grid-template-columns: 1fr; }
  body.app-shell-visible .home-command > .home-command-copy { grid-column: 1; grid-row: 1; }
  body.app-shell-visible .home-command > .home-search { grid-column: 1; grid-row: 2; }

  .app-mobile-nav {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 1002;
    min-height: calc(var(--app-mobile-nav-h) + env(safe-area-inset-bottom, 0px));
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    gap: 2px;
    border-top: 1px solid var(--border);
    background: color-mix(in srgb, var(--panel) 96%, transparent);
    box-shadow: 0 -8px 28px rgba(15, 23, 42, .08);
    backdrop-filter: blur(16px);
  }

  .app-mobile-nav :is(a, button) {
    position: relative;
    flex: 1 1 0;
    min-width: 0;
    min-height: 52px;
    padding: 5px 2px 3px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border: 0;
    border-radius: 10px;
    outline: none;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 10px;
    font-weight: 620;
    cursor: pointer;
  }

  .app-mobile-nav :is(a, button) .lucide { width: 20px; height: 20px; }
  .app-mobile-nav :is(a[aria-current="page"], button[aria-expanded="true"]) {
    background: color-mix(in srgb, var(--accent) 9%, var(--panel));
    color: var(--accent);
  }
  .app-mobile-nav :is(a, button):focus-visible { box-shadow: var(--ring); }

  .app-mobile-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1003;
    display: block;
    visibility: hidden;
    opacity: 0;
    background: rgba(15, 23, 42, .42);
    transition: opacity .18s ease, visibility .18s ease;
  }

  .app-mobile-backdrop.is-open { visibility: visible; opacity: 1; }

  #mobileSheet.app-mobile-sheet {
    position: fixed;
    inset: auto 8px calc(var(--app-mobile-nav-h) + env(safe-area-inset-bottom, 0px) + 8px) 8px;
    z-index: 1004;
    width: auto;
    max-height: min(72dvh, 620px);
    padding: 0;
    display: flex;
    flex-direction: column;
    visibility: hidden;
    opacity: 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--panel);
    box-shadow: 0 24px 64px rgba(15, 23, 42, .24);
    transform: translateY(18px) scale(.985);
    transform-origin: bottom center;
    transition: opacity .18s ease, transform .18s ease, visibility .18s ease;
  }

  #mobileSheet.app-mobile-sheet.open { visibility: visible; opacity: 1; transform: translateY(0) scale(1); }

  .app-mobile-sheet-head {
    flex: 0 0 auto;
    padding: 14px 14px 11px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--border);
  }
  .app-mobile-sheet-head > div { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
  .app-mobile-sheet-head strong { font-size: 14px; }
  .app-mobile-sheet-head span { color: var(--muted); font-size: 11px; }

  #mobileSheet.app-mobile-sheet .list {
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    overflow-y: auto;
  }

  #mobileSheet.app-mobile-sheet .list :is(a, button) {
    min-width: 0;
    min-height: 48px;
    margin: 0;
    padding: 9px 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid transparent;
    border-radius: 10px;
    outline: none;
    background: var(--bg);
    color: var(--text);
    font: inherit;
    font-size: 12px;
    font-weight: 570;
    text-align: left;
    cursor: pointer;
  }

  #mobileSheet.app-mobile-sheet .list :is(a, button):hover { border-color: var(--border); color: var(--accent); }
  #mobileSheet.app-mobile-sheet .list :is(a, button):focus-visible { border-color: var(--accent); box-shadow: var(--ring); }
  #mobileSheet.app-mobile-sheet .list a[aria-current="page"] { color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, var(--panel)); }
  #mobileSheet.app-mobile-sheet .list .lucide { flex: 0 0 18px; width: 18px; height: 18px; color: var(--accent); }
}

@media (max-width: 620px) {
  .app-route-context { font-size: 12px; }
  .app-global-new { width: 38px; padding: 0; display: grid; place-items: center; }
  .app-global-new span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .header.app-shell .app-topbar { grid-template-columns: auto minmax(0, 1fr) auto; padding-inline: 10px; }
  .header.app-shell .app-topbar-actions { gap: 2px; }
  .header.app-shell .actions .iconbtn { width: 36px; height: 36px; }
}

@media (max-width: 390px) {
  .app-route-context .lucide { display: none; }
  #mobileSheet.app-mobile-sheet .list { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  body.app-shell-visible #main-content,
  .app-sidebar,
  .app-mobile-backdrop,
  #mobileSheet.app-mobile-sheet { transition: none !important; }
}
