/* Anonari Apps — Layout : AppShell, sidebar, barre mobile, en-tête de page,
   grilles. Infrastructure générique, réutilisée par la Home, les Apps, la fiche
   tiers et le Designer. */

/* ── AppShell ────────────────────────────────────────────────────────────── */
.ax-shell { display: flex; min-height: 100vh; }
.ax-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.ax-content {
  width: 100%;
  max-width: var(--ax-main-max);
  padding: clamp(20px, 3.4vw, 40px) clamp(16px, 3.4vw, 48px) 64px;
  display: flex;
  flex-direction: column;
  gap: clamp(28px, 3.2vw, 44px);
}
.ax-content--dense { gap: var(--ax-s6); }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.ax-sidebar {
  width: var(--ax-sidebar-w);
  flex: none;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: var(--ax-s6) var(--ax-s4);
  display: flex;
  flex-direction: column;
  gap: 28px;
  background: var(--ax-bg-sidebar);
  border-right: 1px solid var(--ax-line);
}
.ax-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 var(--ax-s2);
  color: var(--ax-ink);
  text-decoration: none;
  font-size: 16px;
  font-weight: var(--ax-fw-semi);
  letter-spacing: -0.01em;
}
.ax-brand:hover { color: var(--ax-ink); }
.ax-brand__mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--ax-ink);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: var(--ax-fw-bold);
  font-size: 15px;
}
.ax-brand__suffix { color: var(--ax-muted); font-weight: var(--ax-fw-medium); }

/* TenantContext : l'entreprise active. Le tenant vient de la session, il ne se
   change pas depuis l'URL — d'où un bloc d'information, pas un sélecteur. */
.ax-tenant {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border-radius: var(--ax-r-md);
  background: var(--ax-surface);
  border: 1px solid var(--ax-line);
  box-shadow: var(--ax-shadow-xs);
}
.ax-tenant__label { font-size: 11.5px; font-weight: var(--ax-fw-medium); color: var(--ax-muted); }
.ax-tenant__name  { font-size: var(--ax-fs-ui); font-weight: var(--ax-fw-semi); overflow-wrap: anywhere; }
.ax-tenant__meta  { font-size: var(--ax-fs-xs); color: var(--ax-muted); }

.ax-nav { display: flex; flex-direction: column; gap: 2px; }
.ax-nav__link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--ax-touch);
  padding: 10px 12px;
  border-radius: 9px;
  color: var(--ax-ink-2);
  text-decoration: none;
  font-size: var(--ax-fs-ui);
  font-weight: var(--ax-fw-medium);
  transition: background var(--ax-ease), color var(--ax-ease);
}
.ax-nav__link::before {
  content: '';
  width: 7px; height: 7px;
  flex: none;
  border-radius: 2px;
  background: var(--ax-axis-line);
}
.ax-nav__link:hover { background: var(--ax-bg-hover); color: var(--ax-ink); }
.ax-nav__link[aria-current="page"] {
  background: var(--ax-surface);
  box-shadow: var(--ax-shadow-sm);
  color: var(--ax-ink);
  font-weight: var(--ax-fw-semi);
}
.ax-nav__link[aria-current="page"]::before { background: var(--ax-link); }
.ax-nav__text { flex: 1; }

.ax-sidebar__section { display: flex; flex-direction: column; gap: var(--ax-s2); padding: 0 12px; }
.ax-sidebar__title { font-size: 11.5px; font-weight: var(--ax-fw-semi); color: var(--ax-muted); }

.ax-sidebar__foot { margin-top: auto; display: flex; flex-direction: column; gap: 14px; }
.ax-sidebar__back {
  font-size: var(--ax-fs-label);
  color: var(--ax-muted);
  text-decoration: none;
  padding: 0 12px;
}
.ax-sidebar__back:hover { color: var(--ax-ink); }

/* Session : Anonari ne connaît ni le nom ni l'e-mail de l'utilisateur — le
   bloc affiche le rôle effectif, jamais une identité. */
.ax-session {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--ax-line);
}
.ax-session__avatar {
  width: 32px; height: 32px;
  flex: none;
  border-radius: 50%;
  background: var(--ax-action-soft);
  color: var(--ax-action);
  display: grid;
  place-items: center;
  font-size: var(--ax-fs-xs);
  font-weight: var(--ax-fw-bold);
}
.ax-session__text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.ax-session__name { font-size: var(--ax-fs-label); font-weight: var(--ax-fw-semi); }
.ax-session__role { font-size: var(--ax-fs-xs); color: var(--ax-muted); }
.ax-session__meta { font-size: var(--ax-fs-xs); color: var(--ax-muted); opacity: .8; }
.ax-session form { margin: 0; }
.ax-linkbtn {
  border: 0;
  background: none;
  padding: 4px;
  cursor: pointer;
  font-size: var(--ax-fs-xs);
  color: var(--ax-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.ax-linkbtn:hover { color: var(--ax-ink); }

/* ── Barre compacte (tablette / mobile) ──────────────────────────────────── */
.ax-topbar { display: none; }

@media (max-width: 899px) {
  .ax-sidebar { display: none; }
  .ax-topbar {
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--ax-bg-sidebar);
    border-bottom: 1px solid var(--ax-line);
  }
  .ax-topbar__row { display: flex; align-items: center; gap: 10px; padding: 12px 16px; }
  .ax-topbar .ax-brand { flex: 1; padding: 0; font-size: 15px; }
  .ax-topbar .ax-brand__mark { width: 28px; height: 28px; font-size: 14px; }
  .ax-topbar__tenant {
    display: inline-flex;
    align-items: center;
    max-width: 40vw;
    min-height: var(--ax-touch);
    padding: 0 12px;
    border-radius: var(--ax-r-md);
    border: 1px solid var(--ax-line);
    background: var(--ax-surface);
    font-size: var(--ax-fs-label);
    font-weight: var(--ax-fw-semi);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .ax-topbar__menu { position: relative; }
  .ax-topbar__menu > summary {
    list-style: none;
    width: var(--ax-touch); height: var(--ax-touch);
    display: grid;
    place-items: center;
    border-radius: var(--ax-r-md);
    border: 1px solid var(--ax-line);
    background: var(--ax-surface);
    color: var(--ax-ink);
    font-size: 18px;
  }
  .ax-topbar__menu > summary::-webkit-details-marker { display: none; }
  .ax-topbar__panel {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 220px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--ax-s2);
    background: var(--ax-surface);
    border: 1px solid var(--ax-line);
    border-radius: var(--ax-r-lg);
    box-shadow: var(--ax-shadow-hover);
  }
  .ax-topbar__panel a, .ax-topbar__panel button {
    display: flex;
    align-items: center;
    min-height: var(--ax-touch);
    padding: 0 12px;
    border: 0;
    border-radius: var(--ax-r-sm);
    background: none;
    text-align: left;
    text-decoration: none;
    font-size: var(--ax-fs-ui);
    color: var(--ax-ink);
    cursor: pointer;
    width: 100%;
  }
  .ax-topbar__panel a:hover, .ax-topbar__panel button:hover { background: var(--ax-bg-hover); }
  .ax-topbar__panel form { margin: 0; }
  .ax-tabs { display: flex; gap: var(--ax-s1); padding: 0 12px; overflow-x: auto; scrollbar-width: none; }
  .ax-tabs::-webkit-scrollbar { display: none; }
  .ax-tabs a {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: var(--ax-touch);
    padding: 0 12px;
    font-size: var(--ax-fs-ui);
    font-weight: var(--ax-fw-medium);
    color: var(--ax-muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
  }
  .ax-tabs a[aria-current="page"] { color: var(--ax-ink); font-weight: var(--ax-fw-semi); border-bottom-color: var(--ax-ink); }
}

/* ── En-tête de page ─────────────────────────────────────────────────────── */
.ax-page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--ax-s4) var(--ax-s5);
}
.ax-page-header__text { display: flex; flex-direction: column; gap: var(--ax-s2); min-width: 0; }
.ax-page-header__eyebrow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--ax-s2);
  font-size: var(--ax-fs-label);
  color: var(--ax-muted);
  font-weight: var(--ax-fw-medium);
}
.ax-page-header__title { font-size: var(--ax-fs-h1-page); }
.ax-page-header--hero .ax-page-header__title { font-size: var(--ax-fs-h1); line-height: 1.08; letter-spacing: -0.025em; }
.ax-page-header__lead { font-size: var(--ax-fs-lead); color: var(--ax-muted); max-width: 70ch; }
.ax-page-header__actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.ax-page-intro { display: flex; flex-direction: column; gap: 14px; }

.ax-breadcrumb { display: flex; flex-wrap: wrap; align-items: center; gap: var(--ax-s2); font-size: var(--ax-fs-label); color: var(--ax-muted); }
.ax-breadcrumb ol { display: contents; list-style: none; }
.ax-breadcrumb li { display: flex; align-items: center; gap: var(--ax-s2); margin: 0; }
.ax-breadcrumb li + li::before { content: '/'; color: var(--ax-muted); }
.ax-breadcrumb a { color: var(--ax-muted); text-decoration: none; }
.ax-breadcrumb a:hover { color: var(--ax-ink); text-decoration: underline; }
.ax-breadcrumb [aria-current] { color: var(--ax-ink); font-weight: var(--ax-fw-medium); }

/* ── Sections ────────────────────────────────────────────────────────────── */
.ax-section { display: flex; flex-direction: column; gap: var(--ax-s4); min-width: 0; }
.ax-section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--ax-s2) var(--ax-s3);
}
.ax-section-header__text { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; }
.ax-section-header__title { font-size: var(--ax-fs-h2); font-weight: var(--ax-fw-semi); }
.ax-section-header__meta { font-size: var(--ax-fs-label); color: var(--ax-muted); }
.ax-section-header__link { font-size: 13.5px; font-weight: var(--ax-fw-semi); text-decoration: none; }

/* ── Grilles ─────────────────────────────────────────────────────────────── */
.ax-grid-kpi {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr));
  gap: var(--ax-s3);
}
.ax-grid-kpi--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
/* Cartes d'App : min. 320 px. 3 colonnes ≥ 1280, 2 ≥ 720, 1 en dessous. */
.ax-grid-apps {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
  gap: var(--ax-s5);
}
.ax-grid-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: var(--ax-s3);
}
.ax-split { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: var(--ax-s4); align-items: start; }
.ax-stack { display: flex; flex-direction: column; gap: var(--ax-s4); min-width: 0; }

@media (max-width: 1100px) {
  .ax-grid-kpi--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ax-split { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  /* Mobile : KPI en 2 colonnes, le reste sur une colonne. */
  .ax-grid-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ax-page-header__actions { width: 100%; }
}
@media (max-width: 380px) {
  .ax-grid-kpi, .ax-grid-kpi--4 { grid-template-columns: 1fr; }
}

/* ── Pied de page « données minimisées » ─────────────────────────────────── */
.ax-footnote {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--ax-s3);
  padding-top: var(--ax-s4);
  border-top: 1px solid var(--ax-line);
  font-size: var(--ax-fs-xs);
  color: var(--ax-muted);
}
.ax-footnote__lhs { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }

/* ── Pages hors session (connexion, erreur) ──────────────────────────────── */
.ax-auth {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--ax-s6);
  padding: var(--ax-s6) var(--ax-s4);
}
.ax-auth__box { width: 100%; max-width: 480px; display: flex; flex-direction: column; gap: var(--ax-s5); }
.ax-auth__box .ax-brand { justify-content: center; }
