/* ============================================================================
   Mandy — Design System · App Layout (shell)
   ----------------------------------------------------------------------------
   The application frame: scalable grouped sidebar + topbar + content.
   Depends on tokens.css. Sidebar is built for many menu items (grouped +
   scrollable). Add `data-theme="dark"` on <html> for dark; the green rail
   variant is `.m-sidebar--green` on the <aside>.
   ============================================================================ */

.m-app { display: flex; height: 100vh; font-family: var(--font-sans); color: var(--text-default); background: var(--bg); }
.m-app *, .m-app *::before, .m-app *::after,
.m-auth *, .m-auth *::before, .m-auth *::after { box-sizing: border-box; }

/* —— Sidebar ——————————————————————————————————————————————————————————————— */
.m-sidebar { width: 256px; flex-shrink: 0; height: 100%; display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--border); }
.m-sidebar__brand { display: flex; align-items: center; gap: var(--space-3); padding: 18px 18px 14px; }
.m-sidebar__logo { display: grid; place-items: center; width: 36px; height: 36px; border-radius: var(--radius-md); background: var(--brand); color: var(--brand-on); font-size: var(--text-lg); font-weight: var(--fw-bold); }
.m-sidebar__name { font-size: var(--text-lg); font-weight: var(--fw-bold); letter-spacing: -.01em; color: var(--text-strong); line-height: 1.15; }
.m-sidebar__name small { display: block; font-size: var(--text-xs); font-weight: var(--fw-medium); color: var(--text-muted); }

.m-sidebar__search { display: flex; align-items: center; gap: var(--space-2); height: 38px; margin: 0 14px 8px; padding: 0 11px; background: var(--input-bg); border: 1px solid var(--border); border-radius: var(--radius-md); color: var(--text-muted); font-size: var(--text-sm); }
.m-sidebar__search kbd { margin-left: auto; font-size: 10.5px; padding: 1px 5px; border: 1px solid var(--border); border-radius: 4px; color: var(--text-muted); }

.m-sidebar__scroll { flex: 1; overflow-y: auto; padding: 6px 14px 14px; }
.m-navgroup { margin-top: var(--space-4); }
.m-navgroup:first-child { margin-top: 2px; }
.m-navgroup__label { padding: 6px 10px; font-size: var(--text-xs); font-weight: var(--fw-bold); letter-spacing: .07em; text-transform: uppercase; color: var(--text-muted); }
.m-navitem { position: relative; display: flex; align-items: center; gap: var(--space-3); min-height: 42px; padding: 8px 11px; border-radius: var(--radius-md); color: var(--text-muted); font-size: var(--text-base); font-weight: var(--fw-medium); text-decoration: none; white-space: nowrap; }
.m-navitem svg { width: 19px; height: 19px; flex-shrink: 0; opacity: .8; }
.m-navitem:hover { background: var(--brand-soft); color: var(--brand-text); }
.m-navitem.is-active { background: var(--brand-soft); color: var(--brand-text); font-weight: var(--fw-semibold); }
.m-navitem.is-active svg { opacity: 1; color: var(--brand-text); }
.m-navitem__badge { margin-left: auto; min-width: 20px; padding: 2px 7px; text-align: center; font-size: var(--text-xs); font-weight: var(--fw-bold); border-radius: var(--radius-pill); background: var(--brand-soft); color: var(--brand-text); }
.m-navitem.is-active .m-navitem__badge { background: color-mix(in srgb, var(--brand) 20%, var(--surface)); }

.m-sidebar__foot { padding: 12px 14px; border-top: 1px solid var(--border); }
.m-sidebar__user { display: flex; align-items: center; gap: var(--space-3); padding: 6px 8px; border-radius: var(--radius-md); cursor: pointer; }
.m-sidebar__user:hover { background: var(--brand-soft); }
.m-sidebar__user .who { min-width: 0; line-height: 1.25; }
.m-sidebar__user .who b { display: block; font-size: var(--text-sm); font-weight: var(--fw-semibold); color: var(--text-strong); }
.m-sidebar__user .who span { font-size: var(--text-xs); color: var(--text-muted); }
.m-sidebar__user svg { margin-left: auto; width: 16px; height: 16px; color: var(--text-muted); }

/* Green-rail variant — set on <aside class="m-sidebar m-sidebar--green"> */
.m-sidebar--green { background: #222a24; border-right-color: #313a32; }
[data-theme="dark"] .m-sidebar--green { background: #19211b; border-right-color: #283027; }
.m-sidebar--green .m-sidebar__name,
.m-sidebar--green .m-sidebar__name small,
.m-sidebar--green .m-navgroup__label { color: #8a948b; }
.m-sidebar--green .m-sidebar__name { color: #fff; }
.m-sidebar--green .m-navitem { color: #aeb8af; }
.m-sidebar--green .m-navitem:hover,
.m-sidebar--green .m-navitem.is-active { background: color-mix(in srgb, var(--brand) 32%, #222a24); color: #fff; }
.m-sidebar--green .m-navitem.is-active svg { color: #fff; }
.m-sidebar--green .m-sidebar__search { background: rgba(255,255,255,.04); border-color: #313a32; color: #8a948b; }
.m-sidebar--green .m-sidebar__user:hover { background: rgba(255,255,255,.05); }
.m-sidebar--green .m-sidebar__user .who b { color: #fff; }
.m-sidebar--green .m-sidebar__foot { border-top-color: #313a32; }

/* —— Main column —————————————————————————————————————————————————————————— */
.m-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.m-topbar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-5); height: 64px; flex-shrink: 0; padding: 0 var(--space-7); background: var(--surface); border-bottom: 1px solid var(--border); }
.m-topbar__search { display: flex; align-items: center; gap: var(--space-3); width: 420px; max-width: 44%; min-width: 0; height: 42px; padding: 0 14px; background: var(--input-bg); border: 1px solid var(--border-strong); border-radius: var(--radius-md); color: var(--text-muted); font-size: var(--text-sm); }
.m-topbar__search span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-topbar__search svg { width: 17px; height: 17px; flex-shrink: 0; }
.m-topbar__actions { display: flex; align-items: center; gap: var(--space-3); }

.m-content { flex: 1; overflow-y: auto; padding: var(--space-6) var(--space-7) var(--space-8); }
.m-pagehead { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-6); }
.m-pagehead__sub { font-size: var(--text-base); color: var(--text-muted); margin-top: var(--space-1); }
.m-pagehead__actions { display: flex; gap: var(--space-3); }

/* —— Common grids ————————————————————————————————————————————————————————— */
.m-stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); margin-bottom: var(--space-6); }
.m-toolbar { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; padding: var(--space-4); }

@media (max-width: 1100px) { .m-stats-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 720px)  { .m-sidebar { display: none; } .m-stats-grid { grid-template-columns: 1fr; } }

/* —— Density: compact (set data-density="compact" on <html>) ———————————————— */
[data-density="compact"] .m-topbar { height: 56px; }
[data-density="compact"] .m-content { padding-top: var(--space-5); }
[data-density="compact"] .m-navitem { min-height: 38px; padding-top: 6px; padding-bottom: 6px; }
[data-density="compact"] .m-stats-grid { margin-bottom: var(--space-5); }

/* —— Authentication layout: dark brand panel (form) + hero image ————————————————
   Form on the left over an always-dark brand surface; the manda.fr/hub-login
   Parisian photo on the right. The panel is intentionally dark in both themes
   (like .m-sidebar--green), so the few literal colors below are deliberate. */
.m-auth { min-height: 100vh; display: flex; font-family: var(--font-sans); }

/* Form side — always-dark brand panel. */
.m-auth__main { position: relative; display: flex; flex: 1; align-items: center; justify-content: center; padding: var(--space-8) var(--space-6); background: #161b17; }
.m-auth__topbar { position: absolute; top: var(--space-6); right: var(--space-6); z-index: 2; }
.m-auth__panel { width: 100%; max-width: 400px; }
/* Brand lockup on the form side — mobile only; on desktop the brand lives as the
   logo on the image panel. */
.m-auth__brand { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-7); }
@media (min-width: 900px) { .m-auth__brand { display: none; } }
.m-auth__logo { display: grid; place-items: center; width: 40px; height: 40px; border-radius: var(--radius-md); background: var(--brand); color: var(--brand-on); }
.m-auth__name { font-family: var(--font-display); font-size: var(--text-2xl); font-weight: 400; color: #fff; line-height: 1; }
.m-auth__flash { margin-bottom: var(--space-4); }

/* Image side — the hub-login hero with the Manda wordmark centered on it, shown
   from 900px up. A gradient keeps the white logo legible. */
.m-auth__aside { position: relative; display: none; flex: 1.1; align-items: center; justify-content: center; padding: var(--space-8); background-size: cover; background-position: center; }
@media (min-width: 900px) { .m-auth__aside { display: flex; } }
.m-auth__aside::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(20,26,21,.28), rgba(20,26,21,.55)); }
.m-auth__aside-logo { position: relative; z-index: 1; width: min(240px, 55%); height: auto; }

/* —— Language dropdown (built on .m-menu) —————————————————————————————————————— */
.m-langmenu__trigger { display: inline-flex; align-items: center; gap: var(--space-2); height: 36px; padding: 0 10px; font: inherit; font-size: var(--text-sm); font-weight: var(--fw-medium); color: var(--text-default); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-md); cursor: pointer; }
.m-langmenu__trigger:hover { border-color: var(--text-muted); }
.m-langmenu__trigger svg { width: 15px; height: 15px; color: var(--text-muted); }
.m-langmenu__caret { margin-left: -2px; }
.m-langmenu .m-menu__list { left: auto; right: 0; min-width: 160px; }
.m-menu__item.is-active { color: var(--brand-text); font-weight: var(--fw-semibold); }
/* On the always-dark auth panel the (light-locked) tokens read dark, so force light. */
.m-auth .m-langmenu__trigger { color: rgba(255,255,255,.82); background: rgba(255,255,255,.04); border-color: rgba(255,255,255,.16); }
.m-auth .m-langmenu__trigger:hover { border-color: rgba(255,255,255,.34); }
.m-auth .m-langmenu__trigger svg { color: rgba(255,255,255,.6); }
