/* redesign.css — Phase 6A app-shell (global bar + module rail + command
   palette). Loaded ONLY when general.ui_redesign is on (see base.php), and
   every rule is scoped under body.ui-redesign so it has ZERO effect on the
   legacy layout. Consumes the existing style.css design tokens — no new
   color/space values, so all 6 themes resolve automatically. Desktop only;
   the legacy mobile shell is unaffected (mobile path returns before this). */

:root {
  --mb-bar-h: 56px;
  --mb-rail-w: 232px;
}

/* ---- shell offset: push all body content clear of the fixed bar + rail ---- */
body.ui-redesign { padding-top: var(--mb-bar-h); padding-left: var(--mb-rail-w); }

/* ============================ GLOBAL BAR ============================ */
.mb-gbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--mb-bar-h);
  display: flex; align-items: center; gap: var(--space-3);
  padding: 0 var(--space-4);
  background: var(--color-bg-card);
  border-bottom: 1px solid var(--color-border);
  z-index: var(--z-sticky);
}
.mb-brand {
  display: flex; align-items: center; gap: var(--space-2);
  font-weight: var(--font-weight-bold); color: var(--color-text-primary);
  text-decoration: none; white-space: nowrap; flex-shrink: 0;
}
.mb-brand img { height: 28px; width: auto; display: block; }
.mb-brand-mark {
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: #fff; display: grid; place-items: center; font-weight: 700;
}
/* favicon in the global bar (top-left) — square */
.mb-brand-img { width: 34px; height: 34px; border-radius: var(--radius-sm); object-fit: cover; display: block; flex-shrink: 0; }
/* community logo in the rail, above Create — theme-aware (light logo on dark
   themes, dark logo on the light theme) */
/* Logo sized to the +Create button below it: full rail-content width, and
   twice the button's height (2 × .btn min-height 44px = 88px). object-fit
   keeps the logo undistorted + centered within that box. */
.mb-rail-logo { display: block; width: 100%; padding: 2px 0 var(--space-2); text-align: center; }
.mb-rail-logo-img { display: block; width: 100%; height: calc(44px * 2); margin: 0 auto; object-fit: contain; }
.mb-rail-logo--light { display: none; }
.mb-rail-logo--dark  { display: block; }
[data-theme="light"] .mb-rail-logo--dark  { display: none; }
[data-theme="light"] .mb-rail-logo--light { display: block; }
.mb-brand-name { font-size: var(--font-size-sm); }

/* search — a real GET form to /search (parity), with a ⌘K hint that opens the palette */
.mb-search {
  /* centered relative to the screen width, independent of brand/actions */
  position: absolute; left: 50%; transform: translateX(-50%);
  width: min(520px, 42vw); display: flex; align-items: center; gap: var(--space-2);
  background: var(--color-bg-elevated); border: 1px solid var(--color-border);
  border-radius: var(--radius-pill); padding: 6px var(--space-3); margin: 0;
}
.mb-search:focus-within { border-color: var(--color-primary); }
.mb-search i { color: var(--color-text-muted); }
.mb-search input {
  flex: 1; border: 0; background: transparent; color: var(--color-text-primary);
  font: inherit; font-size: var(--font-size-sm); outline: none; min-width: 0;
}
.mb-kbd {
  font-size: var(--font-size-xs); color: var(--color-text-muted);
  border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  padding: 1px 6px; background: var(--color-bg-card);
}
.mb-spacer { flex: 1 1 auto; }
.mb-gactions { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }
.mb-icon-link {
  position: relative; display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: var(--radius-pill);
  color: var(--color-text-secondary); text-decoration: none;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.mb-icon-link:hover { background: var(--color-bg-hover); color: var(--color-text-primary); }
.mb-icon-link .mb-dot {
  position: absolute; top: 4px; right: 4px; min-width: 16px; height: 16px;
  padding: 0 4px; border-radius: var(--radius-pill); background: var(--color-danger);
  color: #fff; font-size: 10px; line-height: 16px; text-align: center; font-weight: 700;
}
/* the reused user-menu dropdown should hang from the right edge of the bar */
.mb-gactions .user-menu-dropdown { right: 0; left: auto; }
/* grouped section labels inside the name dropdown */
.mb-gactions .mb-menu-label {
  padding: var(--space-2) var(--space-3) 2px;
  font-size: var(--font-size-xs); text-transform: uppercase; letter-spacing: .08em;
  color: var(--color-text-muted);
}

/* ============================ MODULE RAIL ============================ */
.mb-rail {
  position: fixed; top: var(--mb-bar-h); bottom: 0; left: 0; width: var(--mb-rail-w);
  display: flex; flex-direction: column; gap: 2px; overflow-y: auto;
  padding: var(--space-3) var(--space-2);
  background: var(--color-bg-sidebar);
  border-right: 1px solid var(--color-border);
  z-index: calc(var(--z-sticky) - 1);
}
.mb-create {
  display: flex; align-items: center; justify-content: center; gap: var(--space-2);
  margin-bottom: var(--space-2); width: 100%;
}
/* Focused Create menu opened by the rail Create button. Fixed-positioned by JS
   so the rail's overflow can't clip it. Semantic tokens → resolves in every theme. */
.mb-create-menu {
  position: fixed; z-index: var(--z-modal);
  min-width: 220px; padding: var(--space-2);
  background: var(--color-bg-card); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; gap: 1px;
}
.mb-create-menu[hidden] { display: none; }
.mb-create-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-md);
  color: var(--color-text-primary); text-decoration: none;
  font-size: var(--font-size-sm); white-space: nowrap;
  transition: background var(--transition-fast);
}
.mb-create-item:hover, .mb-create-item:focus-visible {
  background: var(--color-bg-hover); color: var(--color-text-primary); outline: none;
}
.mb-create-item i { width: 18px; text-align: center; color: var(--color-primary); }
.mb-create-item__label { flex: 1; }
.mb-create-item__hint { font-size: var(--font-size-xs); color: var(--color-text-muted); }
.mb-create-sep { height: 1px; background: var(--color-border); margin: var(--space-1) 0; }
.mb-rail-group {
  font-size: var(--font-size-xs); text-transform: uppercase; letter-spacing: .08em;
  color: var(--color-text-muted); padding: var(--space-3) var(--space-3) var(--space-1);
}
.mb-rail-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-md);
  color: var(--color-text-secondary); text-decoration: none;
  font-size: var(--font-size-sm); white-space: nowrap;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.mb-rail-item:hover { background: var(--color-bg-hover); color: var(--color-text-primary); }
.mb-rail-item.is-active { background: var(--color-bg-hover); color: var(--color-text-primary); font-weight: var(--font-weight-semibold); }
.mb-rail-item.is-active i { color: var(--color-primary); }
.mb-rail-item i { width: 20px; text-align: center; font-size: 1rem; }
.mb-rail-item .mb-count {
  margin-left: auto; background: var(--color-primary); color: #fff;
  font-size: 11px; font-weight: 700; border-radius: var(--radius-pill);
  padding: 0 7px; line-height: 18px; min-width: 18px; text-align: center;
}
.mb-rail-spacer { flex: 1 1 auto; }

/* ============================ COMMAND PALETTE ============================ */
.mb-palette-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: none; align-items: flex-start; justify-content: center;
  z-index: var(--z-modal); padding-top: 12vh;
}
.mb-palette-backdrop.is-open { display: flex; }
.mb-palette {
  width: min(640px, 92vw); max-height: 70vh; overflow: hidden;
  background: var(--color-bg-card); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
}
.mb-palette > input {
  border: 0; border-bottom: 1px solid var(--color-border); background: transparent;
  color: var(--color-text-primary); font: inherit; font-size: var(--font-size-md);
  padding: var(--space-4); outline: none;
}
.mb-palette-results { overflow-y: auto; padding: var(--space-2); }
.mb-palette-group {
  font-size: var(--font-size-xs); text-transform: uppercase; letter-spacing: .08em;
  color: var(--color-text-muted); padding: var(--space-2) var(--space-3) var(--space-1);
}
.mb-palette-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-md);
  color: var(--color-text-primary); text-decoration: none; cursor: pointer;
}
.mb-palette-item:hover, .mb-palette-item.is-sel { background: var(--color-bg-hover); }
.mb-palette-item i { width: 20px; text-align: center; color: var(--color-text-muted); }
.mb-palette-item .mb-pk { margin-left: auto; font-size: var(--font-size-xs); color: var(--color-text-muted); }
.mb-palette-item[hidden] { display: none; }

/* ============ LEFT-JUSTIFY CONTENT (all pages) ============
   The site .container is a centered max-width:1200px column (margin-inline:
   auto). Inside the rail-padded shell that leaves content floating in the
   middle of the remaining space. Anchor it to the left (rail edge) instead,
   keeping the comfortable max-width. Footer/other .container stay centered. */
body.ui-redesign .main-content .container { margin-inline: 0; }
/* The footer sits below the rail-offset body; left-justify its container too so
   the multi-column footer lines up with page content instead of floating. */
body.ui-redesign .footer .container { margin-inline: 0; }

/* ============ DEDUPE BREADCRUMBS ============
   Files pages render their own contextual .fe-breadcrumb AND the controller
   sets the global $breadcrumbs, so two trails show. Suppress the generic
   global breadcrumb only on pages that carry the nicer .fe-breadcrumb (Files);
   every other page keeps its single global breadcrumb. */
body.ui-redesign .main-content .container:has(.fe-breadcrumb) .breadcrumbs { display: none; }

/* mobieusKnow (/know/*) renders its own .wk-breadcrumb with the right trail
   (Home / mobieusKnow / Article). Suppress the generic global breadcrumb on
   those pages too, same pattern as Files. */
body.ui-redesign .main-content .container:has(.wk-breadcrumb) .breadcrumbs { display: none; }

/* ============ CHAT: flatten the boxy message cards ============
   chat-rooms.css gives every .mc-msg a card background + border, which reads
   heavy/sparse for short messages. Flatten to continuous rows (transparent,
   hover highlight, tighter spacing) — a modern chat look. Cosmetic bubble
   gradients (.mc-msg.cosmetic-bubble-* use !important) are unaffected. */
body.ui-redesign .mc-msg {
  background: transparent;
  border-color: transparent;
  padding: 0.3rem 0.5rem;
  margin-bottom: 0;
}
body.ui-redesign .mc-msg:hover { background: var(--color-bg-hover); }

/* The chat shell is position:fixed, full-viewport, with its 1280px content
   CENTERED (margin:0 auto) — so its left edge slides under the rail and clips
   the composer's placeholder. Anchor it to the content area: right of the
   rail, below the global bar, full remaining width (no centering). */
body.ui-redesign .mc-room-shell {
  left: var(--mb-rail-w);
  top: var(--mb-bar-h);
  max-width: none;
  margin: 0;
}
/* Composer reserved 96px on the right for the old bottom-right messenger FAB,
   which now lives in the rail — reclaim that space. */
body.ui-redesign .mc-composer { padding-right: var(--space-4); }

/* Empty states are centered by default; left-justify them in the shell so the
   page reads consistently left-aligned (Patrick). */
body.ui-redesign .ev-empty,
body.ui-redesign .empty-state {
  text-align: left;
  align-items: flex-start;
}

/* Help Desk portal wrapper is a centered 720px column; left-justify it. */
body.ui-redesign .p-shell { margin-inline: 0; }

/* ============ 6E GATED-STATE COMPONENTS ============
   Reusable vocabulary for entitlement states. Per the platform's absent-not-
   disabled rule, gated-OFF features stay absent (no scattered locks); these
   render for capacity (the meter) + discoverable opt-in/metered states. */
.mb-usage-meter {
  background: var(--color-bg-card); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); padding: var(--space-4); margin-bottom: var(--space-4);
}
.mb-usage-meter__head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-2); }
.mb-usage-meter__label { font-weight: var(--font-weight-semibold); color: var(--color-text-primary); }
.mb-usage-meter__count { font-size: var(--font-size-sm); color: var(--color-text-muted); }
.mb-usage-meter__bar { height: 8px; border-radius: 999px; background: var(--color-bg-elevated); overflow: hidden; margin-top: var(--space-2); }
.mb-usage-meter__fill { height: 100%; background: var(--color-success); transition: width var(--transition-fast); }
.mb-usage-meter.is-approaching .mb-usage-meter__fill,
.mb-usage-meter.is-over .mb-usage-meter__fill { background: var(--color-warning); }
.mb-usage-meter.is-approaching .mb-usage-meter__count { color: var(--color-warning); }
.mb-usage-meter.is-over .mb-usage-meter__fill { background: var(--color-danger); }
.mb-usage-meter.is-over .mb-usage-meter__count { color: var(--color-danger); }
.mb-usage-meter__note { margin: var(--space-2) 0 0; font-size: var(--font-size-sm); color: var(--color-text-muted); }

/* Entitlement chips (for discoverable gated features — opt-in / metered / locked) */
.mb-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: var(--font-size-xs); font-weight: var(--font-weight-semibold);
  padding: 1px 8px; border-radius: var(--radius-pill); line-height: 1.6;
  border: 1px solid var(--color-border); color: var(--color-text-muted); background: var(--color-bg-elevated);
}
.mb-chip--lock { color: var(--color-text-secondary); }
.mb-chip--optin { color: var(--color-primary); border-color: var(--color-primary); }
.mb-chip--metered { color: var(--color-warning); border-color: var(--color-warning); }

/* ============ 6F AD SURFACES — ads-off is canonical, zero footprint ============
   No ad container renders unless body.ads-on. The slot is display:none by
   default (no reserved track, no gap), so ads-off is the exact canonical
   layout and ads only reflow IN when a tenant enables them. */
.mb-ad-unit { display: none; }
body.ads-on .mb-ad-unit {
  display: block; position: relative;
  background: var(--color-bg-elevated); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); padding: var(--space-5) var(--space-4) var(--space-4);
  margin-bottom: var(--space-5); text-align: center; color: var(--color-text-muted);
  min-height: 90px; overflow: hidden;
}
body.ads-on .mb-ad-unit::before {
  content: 'Ad'; position: absolute; top: 5px; left: 9px;
  font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--color-text-muted);
}

/* ============ FLOATING WIDGETS — side by side at the bottom of the rail ============
   The messenger launcher (.messenger-root) and the mobieusAI wand
   (#mai-launcher) are pinned bottom-left at left:20px (over the Admin item).
   Sit them SIDE BY SIDE in the rail's bottom-right, just left of the rail
   divider (per Patrick): chat nearest the divider (-66px = 56px btn + 10px
   gap), wand to its left (-130px = -66 - 56 - 8px gap), both at bottom:20px.
   (Mobile is a separate layout and unaffected.) */
body.ui-redesign .messenger-root      { left: calc(var(--mb-rail-w) - 38px); bottom: 20px; }
body.ui-redesign .messenger-launcher  { width: 28px; height: 28px; font-size: 13px; }
body.ui-redesign #mai-launcher        { left: calc(var(--mb-rail-w) - 74px); bottom: 20px; width: 28px; height: 28px; }
body.ui-redesign #mai-launcher i      { font-size: 0.8rem; }
/* Shrink the messenger unread badge to match the smaller FAB (was 20px). */
body.ui-redesign .messenger-badge {
  min-width: 13px; height: 13px; line-height: 13px;
  font-size: 8px; padding: 0 2px; border-radius: 999px;
  top: -3px; right: -3px;
}

/* ============ 6C COMMUNITY LANDING (member Home hero) ============ */
.mb-landing-hero {
  position: relative; overflow: hidden;
  background: var(--color-bg-card); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); padding: var(--space-6);
  margin-bottom: var(--space-6);
}
.mb-landing-hero::before {
  content: ''; position: absolute; inset: 0;
  background: var(--color-primary);
  opacity: .10; pointer-events: none;
}
.mb-landing-hero > * { position: relative; }
.mb-landing-hero-main { display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap; }
.mb-landing-mark { width: 48px; height: 48px; font-size: 1.4rem; border-radius: var(--radius-md); flex-shrink: 0; }
.mb-landing-title { margin: 0; font-size: var(--font-size-xl); color: var(--color-text-primary); }
.mb-landing-sub { margin: 2px 0 0; }
.mb-landing-actions { margin-left: auto; display: flex; gap: var(--space-2); flex-wrap: wrap; }
.mb-tiles {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--space-3); margin-top: var(--space-5);
}
.mb-tile {
  display: flex; flex-direction: column; gap: 2px;
  background: var(--color-bg-elevated); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); padding: var(--space-4);
  text-decoration: none; color: var(--color-text-primary);
  transition: border-color var(--transition-fast), transform var(--transition-fast);
}
.mb-tile:hover { border-color: var(--color-primary); transform: translateY(-1px); }
.mb-tile i { color: var(--color-primary); font-size: 1.15rem; margin-bottom: 4px; }
.mb-tile b { font-weight: var(--font-weight-semibold); }
.mb-tile span { color: var(--color-text-muted); font-size: var(--font-size-xs); }

/* ============ 6D CONSISTENT MODULE-INDEX HEADER + SECONDARY NAV ============
   One header treatment for every module's index (replacing the per-module
   .forum-page-header / .fe-hero / .ev-hero / bare-h1 sprawl). Applied behind
   the flag, module by module, via redesign/module-header.php. */
.mb-module-header {
  display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap;
  padding-bottom: var(--space-3); margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}
.mb-mh-icon {
  flex-shrink: 0; width: 40px; height: 40px; display: grid; place-items: center;
  background: var(--color-bg-elevated); border-radius: var(--radius-md);
  color: var(--color-primary); font-size: 1.25rem;
}
.mb-module-header h1 { margin: 0; font-size: var(--font-size-xl); color: var(--color-text-primary); }
.mb-mh-sub { color: var(--color-text-muted); font-size: var(--font-size-sm); }
.mb-mh-actions { margin-left: auto; display: flex; gap: var(--space-2); flex-wrap: wrap; }

.mb-secnav {
  display: flex; gap: var(--space-1); flex-wrap: wrap;
  border-bottom: 1px solid var(--color-border); margin-bottom: var(--space-4);
}
.mb-secnav a {
  padding: var(--space-2) var(--space-3); color: var(--color-text-secondary);
  text-decoration: none; border-bottom: 2px solid transparent; font-size: var(--font-size-sm);
  transition: color var(--transition-fast), border-color var(--transition-fast);
}
.mb-secnav a:hover { color: var(--color-text-primary); }
.mb-secnav a.is-active { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: var(--font-weight-semibold); }
