/* ==========================================================================
       1. DESIGN TOKENS & THEMING
       ========================================================================== */
    :root {
      --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
      --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
      
      /* Light Theme (Solid, Opaque Surfaces) */
      --bg-canvas: #e8ebf0;
      --bg-surface: #ffffff;
      --border-color: rgba(0, 0, 0, 0.08);
      --border-subtle: rgba(0, 0, 0, 0.04);
      --text-main: #111827;
      --text-muted: #6b7280;
      --text-faint: #9ca3af;
      
      --accent: #2563eb;
      --accent-soft: rgba(37, 99, 235, 0.09);
      --accent-hover: rgba(37, 99, 235, 0.15);
      
      --hover-bg: rgba(0, 0, 0, 0.04);
      --active-bg: rgba(0, 0, 0, 0.07);
      
      --sidebar-width: 240px;
      --rail-width: 64px;
      --banner-height: 54px;
      --mobile-header-height: 48px;
      
      --radius-item: 8px;
      --radius-island: 14px;
      --shadow-island: 0 10px 30px -4px rgba(0, 0, 0, 0.08), 0 4px 12px -2px rgba(0, 0, 0, 0.04);
      --shadow-drawer: 0 20px 40px rgba(0, 0, 0, 0.28);
    }

    [data-theme="dark"] {
      --bg-canvas: #09090b;
      --bg-surface: #141417;
      --border-color: rgba(255, 255, 255, 0.08);
      --border-subtle: rgba(255, 255, 255, 0.04);
      --text-main: #f4f4f5;
      --text-muted: #a1a1aa;
      --text-faint: #52525b;
      
      --accent: #3b82f6;
      --accent-soft: rgba(59, 130, 246, 0.18);
      --accent-hover: rgba(59, 130, 246, 0.25);
      
      --hover-bg: rgba(255, 255, 255, 0.06);
      --active-bg: rgba(255, 255, 255, 0.1);
      
      --shadow-island: 0 12px 36px -4px rgba(0, 0, 0, 0.7), 0 4px 12px -2px rgba(0, 0, 0, 0.5);
      --shadow-drawer: 0 20px 40px rgba(0, 0, 0, 0.75);
    }

    * {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
      -webkit-font-smoothing: antialiased;
    }

    /* Base Body Stage */
    body {
      font-family: var(--font-stack);
      background-color: var(--bg-canvas);
      color: var(--text-main);
      height: 100vh;
      width: 100vw;
      overflow: hidden;
      user-select: none;
      transition: background-color 200ms ease;
      position: relative;
    }

    /* Ambient background gradient spheres (visible around floating islands and in glass mode) */
    body::before {
      content: "";
      position: absolute;
      width: 440px;
      height: 440px;
      background: radial-gradient(circle, rgba(59, 130, 246, 0.25) 0%, rgba(147, 51, 234, 0.15) 50%, transparent 70%);
      top: -80px;
      left: -80px;
      border-radius: 50%;
      pointer-events: none;
      z-index: 1;
    }
    body::after {
      content: "";
      position: absolute;
      width: 400px;
      height: 400px;
      background: radial-gradient(circle, rgba(16, 185, 129, 0.2) 0%, transparent 70%);
      bottom: -60px;
      left: 120px;
      border-radius: 50%;
      pointer-events: none;
      z-index: 1;
    }

    /* Root Flex Container */
    #appRoot {
      width: 100%;
      height: 100%;
      display: flex;
      position: relative;
      overflow: hidden;
      z-index: 5;
    }

    /* ==========================================================================
       2. REUSABLE CORE SURFACES & COMPONENT PRIMITIVES
       ========================================================================== */
    #appShell {
      background: var(--bg-surface);
      display: flex;
      flex-direction: column;
      position: relative;
      z-index: 100;
      flex-shrink: 0;
      transition: width 220ms cubic-bezier(0.4, 0, 0.2, 1),
                  height 220ms cubic-bezier(0.4, 0, 0.2, 1),
                  transform 240ms cubic-bezier(0.4, 0, 0.2, 1),
                  background 200ms ease,
                  margin 200ms ease,
                  border-radius 200ms ease,
                  box-shadow 200ms ease;
    }

    .main-workspace {
      flex: 1;
      min-width: 0;
      min-height: 0;
      display: flex;
      flex-direction: column;
      height: 100%;
      overflow: hidden;
      position: relative;
      background: var(--bg-surface);
      transition: all 200ms ease;
    }

    .brand {
      display: flex;
      align-items: center;
      gap: 10px;
      font-weight: 600;
      font-size: 14px;
      color: var(--text-main);
      text-decoration: none;
      cursor: pointer;
      white-space: nowrap;
    }
    .brand-icon {
      width: 28px;
      height: 28px;
      border-radius: 7px;
      background: linear-gradient(135deg, #3b82f6, #1d4ed8);
      color: white;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
      box-shadow: 0 2px 5px rgba(37, 99, 235, 0.3);
    }
    .toggle-btn {
      background: none;
      border: none;
      width: 32px;
      min-width: 32px;
      height: 32px;
      min-height: 32px;
      padding: 0;
      border-radius: 6px;
      color: var(--text-muted);
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: background 120ms ease, color 120ms ease;
    }
    .toggle-btn svg {
      width: 18px;
      height: 18px;
      flex: 0 0 18px;
      fill: none;
      stroke: currentColor;
      stroke-width: 1.8;
      stroke-linecap: round;
      stroke-linejoin: round;
      transition: transform 150ms ease;
    }
    #appShell[data-collapsed="true"] .toggle-btn svg { transform: rotate(180deg); }
    .toggle-btn:hover {
      background: var(--hover-bg);
      color: var(--text-main);
    }

    .section-title {
      font-size: 11px;
      font-weight: 600;
      letter-spacing: 0.05em;
      text-transform: uppercase;
      color: var(--text-faint);
      padding: 12px 8px 6px 8px;
      white-space: nowrap;
    }

    .nav-item {
      display: flex;
      align-items: center;
      gap: 10px;
      height: 36px;
      padding: 0 10px;
      border-radius: var(--radius-item);
      color: var(--text-muted);
      font-size: 13.5px;
      font-weight: 450;
      cursor: pointer;
      text-decoration: none;
      position: relative;
      transition: background 120ms ease, color 120ms ease;
      white-space: nowrap;
      flex-shrink: 0;
    }
    .nav-item:hover {
      background: var(--hover-bg);
      color: var(--text-main);
    }
    .nav-item svg {
      width: 18px;
      height: 18px;
      flex-shrink: 0;
      stroke-width: 1.8;
      stroke: currentColor;
      fill: none;
    }
    .nav-label {
      flex: 1;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .badge {
      font-size: 11px;
      font-weight: 500;
      background: var(--hover-bg);
      padding: 2px 6px;
      border-radius: 10px;
      color: var(--text-muted);
    }
    .shortcut {
      margin-left: auto;
      font-size: 10px;
      line-height: 1;
      font-family: var(--font-mono);
      font-weight: 500;
      letter-spacing: -0.01em;
      color: var(--text-faint);
      opacity: 0.72;
      border: 1px solid var(--border-subtle);
      border-radius: 4px;
      padding: 2px 4px;
      transition: background 120ms ease, color 120ms ease, opacity 120ms ease;
    }

    .collapse-control {
      display: flex;
      align-items: center;
      gap: 6px;
      margin-left: auto;
    }

    .nav-item:hover .shortcut {
      color: var(--text-muted);
      opacity: 1;
    }
    .chevron {
      width: 14px !important;
      height: 14px !important;
      transition: transform 150ms ease;
    }
    .nav-item.open .chevron {
      transform: rotate(90deg);
    }

    .sub-menu {
      padding-left: 28px;
      display: flex;
      flex-direction: column;
      gap: 2px;
      max-height: 200px;
      overflow: hidden;
      transition: max-height 180ms ease, opacity 150ms ease;
    }
    .sub-menu.collapsed {
      max-height: 0;
      opacity: 0;
      pointer-events: none;
    }


    /* Collapsed rail tooltip: one fixed layer, so it is never clipped by nav scrolling. */
    .app-shell-tooltip {
      position: fixed;
      z-index: 1200;
      pointer-events: none;
      max-width: 240px;
      padding: 6px 9px;
      border: 1px solid var(--border-color);
      border-radius: 7px;
      background: var(--bg-surface);
      color: var(--text-main);
      box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
      font-size: 12px;
      font-weight: 500;
      white-space: nowrap;
      opacity: 0;
      transform: translate(4px, -50%) scale(0.98);
      transform-origin: left center;
      transition: opacity 120ms ease, transform 120ms ease, background 120ms ease, color 120ms ease;
    }

    .app-shell-tooltip.visible {
      opacity: 1;
      transform: translate(0, -50%) scale(1);
    }

    /* Ultra-thin sidebar scrollbar. The thumb is transparent until scrolling. */
    #appShell .shell-body {
      scrollbar-width: thin;
      scrollbar-color: transparent transparent;
      transition: scrollbar-color 180ms ease;
    }

    #appShell .shell-body.is-scrolling {
      scrollbar-color: color-mix(in srgb, var(--text-faint) 46%, transparent) transparent;
    }

    #appShell .shell-body::-webkit-scrollbar {
      width: 4px;
      height: 4px;
    }

    #appShell .shell-body::-webkit-scrollbar-track {
      background: transparent;
    }

    #appShell .shell-body::-webkit-scrollbar-thumb {
      background: transparent;
      border-radius: 999px;
      transition: background 180ms ease;
    }

    #appShell .shell-body.is-scrolling::-webkit-scrollbar-thumb {
      background: color-mix(in srgb, var(--text-faint) 46%, transparent);
    }

    /* Indicator Styling */
    body.indicator-pill .nav-item.active {
      background: var(--accent-soft);
      color: var(--accent);
      font-weight: 550;
    }
    body.indicator-pill .nav-item.active svg {
      stroke: var(--accent);
    }
    body.indicator-pill .nav-item.active .badge {
      background: var(--accent-hover);
      color: var(--accent);
    }

    body.indicator-bar .nav-item.active {
      background: var(--hover-bg);
      color: var(--text-main);
      font-weight: 550;
      border-radius: 0 var(--radius-item) var(--radius-item) 0;
    }
    body.indicator-bar .nav-item.active::before {
      content: "";
      position: absolute;
      left: -8px;
      top: 6px;
      bottom: 6px;
      width: 3.5px;
      background: var(--accent);
      border-radius: 2px;
    }

    body.indicator-glow .nav-item.active {
      background: transparent;
      color: var(--text-main);
      font-weight: 600;
    }
    body.indicator-glow .nav-item.active svg {
      stroke: var(--accent);
      filter: drop-shadow(0 0 6px rgba(37, 99, 235, 0.45));
    }

    .profile-card {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 6px 8px;
      border-radius: var(--radius-item);
      cursor: pointer;
      transition: background 120ms ease, color 120ms ease;
    }
    .profile-card:hover {
      background: var(--hover-bg);
    }
    .avatar {
      width: 28px;
      height: 28px;
      border-radius: 50%;
      background: #e2e8f0;
      border: 1px solid var(--border-color);
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 11px;
      font-weight: 600;
      flex-shrink: 0;
      color: #334155;
    }
    .profile-info {
      flex: 1;
      overflow: hidden;
      line-height: 1.25;
    }
    .profile-name {
      font-size: 13px;
      font-weight: 500;
      color: var(--text-main);
    }
    .profile-role {
      font-size: 11px;
      color: var(--text-muted);
    }

    /* Workspace Toolbar & Content */
    
    
    
    


    
    

    
    
    
    
    
    
    

    
    
    
    

    /* Mobile Header & Backdrop */
    .mobile-nav-bar {
      display: none;
      height: var(--mobile-header-height);
      width: 100%;
      background: var(--bg-surface);
      border-bottom: 1px solid var(--border-color);
      align-items: center;
      justify-content: space-between;
      padding: 0 12px;
      z-index: 80;
      flex-shrink: 0;
    }
    .hamburger-btn {
      background: none;
      border: none;
      color: var(--text-main);
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      width: 36px;
      height: 36px;
      border-radius: 6px;
      transition: background 120ms ease, color 120ms ease;
    }
    .hamburger-btn:hover {
      background: var(--hover-bg);
    }

    .mobile-backdrop {
      display: none;
      position: fixed;
      inset: 0;
      background: rgba(0, 0, 0, 0.45);
      backdrop-filter: blur(4px);
      -webkit-backdrop-filter: blur(4px);
      z-index: 900;
      opacity: 0;
      transition: opacity 200ms ease;
    }
    .mobile-backdrop.active {
      display: block;
      opacity: 1;
    }

    /* ==========================================================================
       3. STRUCTURAL AESTHETICS
       ========================================================================== */

    /* AESTHETIC 1: FLOATING ISLAND (Crisp Solid White Rounded Cards) */
    body.style-island:not(.tier-phone) #appRoot[data-layout="vertical"] #appShell {
        height: calc(100vh - 20px);
        margin: 10px 0 10px 10px;
        border-radius: var(--radius-island);
        border: 1px solid var(--border-color);
        box-shadow: var(--shadow-island);
        background: var(--bg-surface);
      }
      body.style-island:not(.tier-phone) #appRoot[data-layout="vertical"] .main-workspace {
        height: calc(100vh - 20px);
        margin: 10px 10px 10px 10px;
        border-radius: var(--radius-island);
        border: 1px solid var(--border-color);
        box-shadow: var(--shadow-island);
        background: var(--bg-surface);
      }

      body.style-island:not(.tier-phone) #appRoot[data-layout="topnav"] #appShell {
        width: calc(100% - 20px);
        margin: 10px 10px 0 10px;
        border-radius: var(--radius-island);
        border: 1px solid var(--border-color);
        box-shadow: var(--shadow-island);
        background: var(--bg-surface);
      }
      body.style-island:not(.tier-phone) #appRoot[data-layout="topnav"] .main-workspace {
        height: calc(100vh - var(--banner-height) - 30px);
        margin: 10px 10px 10px 10px;
        border-radius: var(--radius-island);
        border: 1px solid var(--border-color);
        box-shadow: var(--shadow-island);
        background: var(--bg-surface);
      }

    /* AESTHETIC 2: FLUSH SEAMLESS (Full Height/Width, 0 margin, 0 radius) */
    body.style-flush:not(.tier-phone) #appRoot[data-layout="vertical"] #appShell {
        border-right: 1px solid var(--border-color);
        margin: 0;
        border-radius: 0;
        box-shadow: none;
        background: var(--bg-surface);
      }
      body.style-flush:not(.tier-phone) .main-workspace {
        margin: 0;
        border-radius: 0;
        box-shadow: none;
        background: var(--bg-surface);
      }

    /* AESTHETIC 3: FROSTED GLASS (ONLY in this mode is there translucent blur) */
    body.style-glass #appShell {
      background: rgba(255, 255, 255, 0.6) !important;
      backdrop-filter: blur(28px) saturate(190%) !important;
      -webkit-backdrop-filter: blur(28px) saturate(190%) !important;
    }
    body.style-glass .main-workspace {
      background: rgba(255, 255, 255, 0.45) !important;
      backdrop-filter: blur(16px) !important;
      -webkit-backdrop-filter: blur(16px) !important;
    }
    
    
    body.style-glass .mobile-nav-bar {
      background: rgba(255, 255, 255, 0.6) !important;
      backdrop-filter: blur(20px) saturate(180%) !important;
      -webkit-backdrop-filter: blur(20px) saturate(180%) !important;
    }
    [data-theme="dark"] body.style-glass #appShell {
      background: rgba(18, 18, 22, 0.65) !important;
    }
    [data-theme="dark"] body.style-glass .main-workspace {
      background: rgba(18, 18, 22, 0.5) !important;
    }
    
    
    [data-theme="dark"] body.style-glass .mobile-nav-bar {
      background: rgba(18, 18, 22, 0.65) !important;
    }

    

/* Stable handoff point: application owns everything inside this slot. */
.app-workspace-slot {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: auto;
}
.mobile-brand {
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.mobile-brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}
.mobile-avatar {
  width: 26px !important;
  height: 26px !important;
  font-size: 10px !important;
}

/* ==========================================================================
       4. RESPONSIVE TIERS
       The tier is derived from the app's rendered width (not the browser's raw
       viewport width), so real resizing and developer preview presets behave
       identically.
       ========================================================================== */

    /* TIER A: DESKTOP (> 1024px rendered app width) */
    body.tier-desktop #appRoot[data-layout="vertical"] { flex-direction: row; }
    body.tier-desktop #appRoot[data-layout="vertical"] #appShell {
      width: var(--sidebar-width); height: 100%;
    }
    body.tier-desktop #appRoot[data-layout="vertical"] #appShell[data-collapsed="true"] { width: var(--rail-width); }
    body.tier-desktop #appRoot[data-layout="vertical"] #appShell .shell-header {
      height: 64px; min-height: 64px; padding: 16px 14px; display: flex; align-items: center; justify-content: space-between;
    }
    body.tier-desktop #appRoot[data-layout="vertical"] #appShell .shell-body {
      flex: 1; overflow-y: auto; padding: 6px 8px; display: flex; flex-direction: column; gap: 2px;
    }
    body.tier-desktop #appRoot[data-layout="vertical"] #appShell .shell-footer {
      height: 98px; min-height: 98px; padding: 8px; border-top: 1px solid var(--border-subtle); display: flex; flex-direction: column; gap: 2px;
    }
    body.tier-desktop #appRoot[data-layout="vertical"] #appShell[data-collapsed="true"] .brand-title,
    body.tier-desktop #appRoot[data-layout="vertical"] #appShell[data-collapsed="true"] .nav-label,
    body.tier-desktop #appRoot[data-layout="vertical"] #appShell[data-collapsed="true"] .badge,
    body.tier-desktop #appRoot[data-layout="vertical"] #appShell[data-collapsed="true"] .shortcut,
    body.tier-desktop #appRoot[data-layout="vertical"] #appShell[data-collapsed="true"] .chevron,
    body.tier-desktop #appRoot[data-layout="vertical"] #appShell[data-collapsed="true"] .sub-menu,
    body.tier-desktop #appRoot[data-layout="vertical"] #appShell[data-collapsed="true"] .profile-info { display: none !important; }
    body.tier-desktop #appRoot[data-layout="vertical"] #appShell[data-collapsed="true"] .collapse-control {
      display: none !important;
    }
    /* Collapsing a vertical rail is a horizontal-only transformation. Section
       titles keep their box so every navigation icon stays at the same Y
       coordinate as its expanded counterpart. */
    body.tier-desktop #appRoot[data-layout="vertical"] #appShell[data-collapsed="true"] .section-title {
      visibility: hidden;
      padding-left: 0;
      padding-right: 0;
    }
    /* A collapsed rail is the expanded rail with text removed: never change
       vertical padding, row height, section spacing, or footer geometry. */
    body.tier-desktop #appRoot[data-layout="vertical"] #appShell[data-collapsed="true"] .brand,
    body.tier-desktop #appRoot[data-layout="vertical"] #appShell[data-collapsed="true"] .profile-card {
      justify-content: center;
    }
    body.tier-desktop #appRoot[data-layout="vertical"] #appShell[data-collapsed="true"] .nav-item {
      justify-content: center; padding: 0; width: 44px; height: 36px; margin: 0 auto;
    }

    /* Desktop top navigation: no permanent rail. */
    body.tier-desktop #appRoot[data-layout="topnav"] { flex-direction: column; }
    body.tier-desktop #appRoot[data-layout="topnav"] #appShell {
      width: 100%; height: var(--banner-height); display: flex; flex-direction: row; align-items: center;
      padding: 0 16px; border-bottom: 1px solid var(--border-color);
    }
    body.tier-desktop #appRoot[data-layout="topnav"] #appShell .shell-header { padding: 0 16px 0 0; border-bottom: none; }
    body.tier-desktop #appRoot[data-layout="topnav"] #appShell .toggle-btn,
    body.tier-desktop #appRoot[data-layout="topnav"] #appShell .section-title { display: none !important; }
    body.tier-desktop #appRoot[data-layout="topnav"] #appShell .shell-body {
      flex: 1 1 auto; min-width: 0; display: flex; flex-direction: row; align-items: center; overflow: hidden; padding: 0 8px; gap: 6px;
    }
    body.tier-desktop #appRoot[data-layout="topnav"] #appShell .sub-menu { display: flex; flex-direction: row; padding-left: 0; gap: 6px; }
    body.tier-desktop #appRoot[data-layout="topnav"] #appShell .sub-menu.collapsed { display: none; }
    body.tier-desktop #appRoot[data-layout="topnav"] #appShell .shell-footer {
      display: flex; flex-direction: row; align-items: center; border-top: none; border-left: 1px solid var(--border-subtle);
      padding: 0 0 0 12px; margin-left: auto; gap: 8px;
    }
    /* TopNavigationShell: application destinations are text-first. Settings
       stays in the account utility group; its compact treatment is opt-in via
       settings.iconOnly, not consumer CSS. */
    body.tier-desktop #appRoot[data-layout="topnav"] #appShell .shell-body > .nav-item > svg:not(.chevron),
    body.tier-desktop #appRoot[data-layout="topnav"] #appShell .shell-body .sub-menu > .nav-item > svg {
      display: none;
    }
    body.tier-desktop #appRoot[data-layout="topnav"] #appShell .shell-footer .app-shell-settings-endpoint.is-icon-only {
      width: 34px; height: 34px; padding: 0; justify-content: center; gap: 0;
    }
    body.tier-desktop #appRoot[data-layout="topnav"] #appShell .shell-footer .app-shell-settings-endpoint.is-icon-only .nav-label {
      display: none;
    }

    /* TIER B: TABLET (601px–1024px rendered app width) */
    body.tier-tablet #appRoot[data-layout="vertical"] { flex-direction: row; }
    body.tier-tablet #appRoot[data-layout="vertical"] #appShell {
      width: var(--rail-width); height: 100%; display: flex; flex-direction: column;
    }
    body.tier-tablet #appRoot[data-layout="vertical"] #appShell .toggle-btn,
    body.tier-tablet #appRoot[data-layout="vertical"] #appShell .brand-title,
    body.tier-tablet #appRoot[data-layout="vertical"] #appShell .nav-label,
    body.tier-tablet #appRoot[data-layout="vertical"] #appShell .section-title,
    body.tier-tablet #appRoot[data-layout="vertical"] #appShell .badge,
    body.tier-tablet #appRoot[data-layout="vertical"] #appShell .shortcut,
    body.tier-tablet #appRoot[data-layout="vertical"] #appShell .chevron,
    body.tier-tablet #appRoot[data-layout="vertical"] #appShell .sub-menu,
    body.tier-tablet #appRoot[data-layout="vertical"] #appShell .profile-info { display: none !important; }
    body.tier-tablet #appRoot[data-layout="vertical"] #appShell .shell-header,
    body.tier-tablet #appRoot[data-layout="vertical"] #appShell .brand,
    body.tier-tablet #appRoot[data-layout="vertical"] #appShell .profile-card { justify-content: center; padding: 14px 0; }
    body.tier-tablet #appRoot[data-layout="vertical"] #appShell .nav-item {
      justify-content: center; padding: 0; width: 44px; height: 44px; margin: 0 auto 4px auto;
    }
    body.tier-tablet #appRoot[data-layout="vertical"] #appShell .shell-body {
      flex: 1; overflow-y: auto; padding: 6px 0; display: flex; flex-direction: column;
    }
    body.tier-tablet #appRoot[data-layout="vertical"] #appShell .shell-footer {
      padding: 8px 0; border-top: 1px solid var(--border-subtle); display: flex; flex-direction: column; margin-top: auto;
    }

    /* Tablet top navigation remains a banner until Phone tier. */
    body.tier-tablet #appRoot[data-layout="topnav"] { flex-direction: column; }
    body.tier-tablet #appRoot[data-layout="topnav"] #appShell {
      width: 100%; height: var(--banner-height); display: flex; flex-direction: row; align-items: center;
      padding: 0 14px; border-bottom: 1px solid var(--border-color);
    }
    body.tier-tablet #appRoot[data-layout="topnav"] #appShell .shell-header { padding: 0 14px 0 0; border-bottom: none; }
    body.tier-tablet #appRoot[data-layout="topnav"] #appShell .toggle-btn,
    body.tier-tablet #appRoot[data-layout="topnav"] #appShell .section-title { display: none !important; }
    body.tier-tablet #appRoot[data-layout="topnav"] #appShell .shell-body {
      flex: 1 1 auto; min-width: 0; display: flex; flex-direction: row; align-items: center; overflow: hidden; padding: 0 8px; gap: 6px;
    }
    body.tier-tablet #appRoot[data-layout="topnav"] #appShell .sub-menu { display: flex; flex-direction: row; padding-left: 0; gap: 6px; }
    body.tier-tablet #appRoot[data-layout="topnav"] #appShell .sub-menu.collapsed { display: none; }
    body.tier-tablet #appRoot[data-layout="topnav"] #appShell .shell-footer {
      display: flex; flex-direction: row; align-items: center; border-top: none; border-left: 1px solid var(--border-subtle);
      padding: 0 0 0 10px; margin-left: auto; gap: 8px;
    }
    body.tier-tablet #appRoot[data-layout="topnav"] #appShell .shell-body > .nav-item > svg:not(.chevron),
    body.tier-tablet #appRoot[data-layout="topnav"] #appShell .shell-body .sub-menu > .nav-item > svg {
      display: none;
    }
    body.tier-tablet #appRoot[data-layout="topnav"] #appShell .shell-footer .app-shell-settings-endpoint.is-icon-only {
      width: 34px; height: 34px; padding: 0; justify-content: center; gap: 0;
    }
    body.tier-tablet #appRoot[data-layout="topnav"] #appShell .shell-footer .app-shell-settings-endpoint.is-icon-only .nav-label {
      display: none;
    }

    /* Topnav overflow and the optional structural module-action row. Apps own
       the controls placed in the row; APP-SHELL owns its placement only. */
    .app-shell-topnav-overflow { position: relative; flex: 0 0 auto; }
    .app-shell-topnav-overflow[hidden] { display: none; }
    .app-shell-topnav-more {
      min-height: 32px; display: inline-flex; align-items: center; gap: 4px; padding: 0 9px;
      border: 1px solid var(--border-subtle); border-radius: var(--radius-item); background: transparent;
      color: var(--text-muted); font: 500 12px/1 var(--font-stack); cursor: pointer;
    }
    .app-shell-topnav-more:hover, .app-shell-topnav-more:focus-visible { background: var(--hover-bg); color: var(--text-main); outline: none; }
    .app-shell-topnav-more:focus-visible { box-shadow: 0 0 0 2px var(--accent-soft); }
    .app-shell-topnav-overflow-menu {
      position: absolute; z-index: 1300; top: calc(100% + 6px); right: 0; min-width: 180px; max-width: min(280px, calc(100vw - 20px));
      padding: 5px; border: 1px solid var(--border-color); border-radius: 10px; background: var(--bg-surface); box-shadow: var(--shadow-island);
    }
    .app-shell-topnav-overflow-menu .nav-item { width: 100%; min-width: 0; }
    .app-shell-topnav-overflow-menu .sub-menu { display: flex !important; flex-direction: column !important; padding: 2px 0 2px 16px !important; }
    .app-shell-topnav-overflow-separator { height: 1px; margin: 5px; background: var(--border-subtle); }
    .app-shell-topnav-overflow-utilities { display: grid; gap: 2px; }
    .app-shell-topnav-overflow-utilities > * { min-width: 0; }
    .app-shell-topnav-overflow-utilities :is(button, a)[role="menuitem"] {
      display: flex; width: 100%; align-items: center; min-height: 32px; padding: 0 8px; border: 0; border-radius: 6px;
      background: transparent; color: var(--text-main); font: 500 12px/1 var(--font-stack); text-align: left; text-decoration: none; cursor: pointer;
    }
    .app-shell-topnav-overflow-utilities :is(button, a)[role="menuitem"]:hover,
    .app-shell-topnav-overflow-utilities :is(button, a)[role="menuitem"]:focus-visible { background: var(--hover-bg); outline: none; }
    .app-shell-module-bar { flex: 0 0 auto; min-height: 0; border-bottom: 1px solid var(--border-subtle); background: var(--bg-surface); }
    .app-shell-module-bar[hidden] { display: none; }
    .app-shell-module-bar-content { min-width: 0; }
    #appRoot[data-layout="topnav"] .app-shell-module-bar:not([hidden]) + .main-workspace { height: auto; }
    body.tier-desktop #appRoot[data-layout="topnav"] .app-shell-module-bar,
    body.tier-tablet #appRoot[data-layout="topnav"] .app-shell-module-bar { display: block; }

    /* TIER C: PHONE (<= 600px rendered app width) */
    body.tier-phone #appRoot { flex-direction: column !important; }
    body.tier-phone .mobile-nav-bar { display: flex !important; }
    body.tier-phone #appShell {
      position: fixed !important; top: 0 !important; bottom: auto !important; left: 0 !important;
      width: 270px !important; height: 100vh !important; height: 100dvh !important; min-height: 100dvh !important; max-height: 100dvh !important; margin: 0 !important; border-radius: 0 16px 16px 0 !important;
      box-shadow: var(--shadow-drawer) !important; transform: translateX(-100%) !important; z-index: 1000 !important;
      display: flex !important; flex-direction: column !important; padding: 0 !important;
      border-right: 1px solid var(--border-color) !important; border-bottom: none !important;
      transition: transform 240ms cubic-bezier(0.4, 0, 0.2, 1) !important;
    }
    body.tier-phone #appShell.mobile-open { transform: translateX(0) !important; }
    body.tier-phone #appShell .shell-header {
      display: flex !important; flex-direction: row !important; justify-content: space-between !important;
      padding: 16px 14px !important; border-bottom: 1px solid var(--border-subtle) !important;
    }
    body.tier-phone #appShell .brand { display: flex !important; justify-content: flex-start !important; width: auto !important; }
    body.tier-phone #appShell .brand-title, body.tier-phone #appShell .nav-label, body.tier-phone #appShell .section-title,
    body.tier-phone #appShell .badge, body.tier-phone #appShell .shortcut, body.tier-phone #appShell .chevron,
    body.tier-phone #appShell .sub-menu, body.tier-phone #appShell .profile-info { display: block !important; }
    body.tier-phone #appShell .toggle-btn { display: none !important; }
    body.tier-phone #appShell .shell-body {
      flex: 1 1 auto !important; min-height: 0 !important; display: flex !important; flex-direction: column !important; overflow-y: auto !important;
      padding: 6px 8px !important; gap: 2px !important;
    }
    body.tier-phone #appShell .sub-menu { padding-left: 28px !important; }
    body.tier-phone #appShell .sub-menu.collapsed { display: none !important; }
    body.tier-phone #appShell .nav-item {
      display: flex !important; flex-direction: row !important; justify-content: flex-start !important; padding: 0 10px !important;
      width: 100% !important; height: 38px !important; margin: 0 0 2px 0 !important;
    }
    body.tier-phone #appShell .shell-footer {
      display: flex !important; flex: 0 0 auto !important; min-height: 0 !important; flex-direction: column !important; border-top: 1px solid var(--border-subtle) !important;
      border-left: none !important; padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px)) !important; margin-top: auto !important; margin-left: 0 !important;
    }
    body.tier-phone #appShell .profile-card {
      display: flex !important; flex-direction: row !important; margin-top: 4px !important; padding: 6px 8px !important;
    }
    body.tier-phone .main-workspace {
      width: 100% !important; flex: 1 !important; height: calc(100vh - var(--mobile-header-height)) !important;
      margin: 0 !important; border-radius: 0 !important; box-shadow: none !important;
    }
    body.tier-phone .app-shell-module-bar { display: block; }
    body.tier-phone .app-shell-topnav-overflow { margin: 0 8px 8px; }
    body.tier-phone .app-shell-topnav-overflow-menu { top: auto; right: auto; left: 0; bottom: calc(100% + 6px); }
    
    

    /* Phone structural styles remain visually distinct. */
    body.tier-phone.style-island #appRoot {
      padding: 8px !important;
      gap: 8px !important;
    }
    body.tier-phone.style-island .mobile-nav-bar {
      width: 100% !important;
      border: 1px solid var(--border-color) !important;
      border-radius: 12px !important;
      box-shadow: var(--shadow-island) !important;
      background: var(--bg-surface) !important;
    }
    body.tier-phone.style-island .main-workspace {
      width: 100% !important;
      min-height: 0 !important;
      height: auto !important;
      margin: 0 !important;
      border: 1px solid var(--border-color) !important;
      border-radius: var(--radius-island) !important;
      box-shadow: var(--shadow-island) !important;
      background: var(--bg-surface) !important;
    }
    body.tier-phone.style-island #appShell {
      top: 8px !important;
      bottom: 8px !important;
      left: 8px !important;
      height: calc(100vh - 16px) !important;
      height: calc(100dvh - 16px) !important;
      min-height: 0 !important;
      border: 1px solid var(--border-color) !important;
      border-radius: var(--radius-island) !important;
      box-shadow: var(--shadow-drawer) !important;
    }

    body.tier-phone.style-flush #appRoot {
      padding: 0 !important;
      gap: 0 !important;
    }

    /* Phone glass needs enough transparency for the ambient stage to read through. */
    body.tier-phone.style-glass #appRoot {
      padding: 8px !important;
      gap: 8px !important;
    }
    body.tier-phone.style-glass .mobile-nav-bar {
      width: 100% !important;
      border: 1px solid rgba(255,255,255,0.42) !important;
      border-radius: 12px !important;
      box-shadow: var(--shadow-island) !important;
      background: rgba(255,255,255,0.34) !important;
      backdrop-filter: blur(22px) saturate(185%) !important;
      -webkit-backdrop-filter: blur(22px) saturate(185%) !important;
    }
    body.tier-phone.style-glass .main-workspace {
      width: 100% !important;
      min-height: 0 !important;
      height: auto !important;
      margin: 0 !important;
      border: 1px solid rgba(255,255,255,0.38) !important;
      border-radius: var(--radius-island) !important;
      box-shadow: var(--shadow-island) !important;
      background: rgba(255,255,255,0.24) !important;
      backdrop-filter: blur(18px) saturate(170%) !important;
      -webkit-backdrop-filter: blur(18px) saturate(170%) !important;
    }
    
    
    
    body.tier-phone.style-glass #appShell {
      top: 8px !important;
      bottom: 8px !important;
      left: 8px !important;
      height: calc(100vh - 16px) !important;
      height: calc(100dvh - 16px) !important;
      min-height: 0 !important;
      border: 1px solid rgba(255,255,255,0.38) !important;
      border-radius: var(--radius-island) !important;
      background: rgba(255,255,255,0.34) !important;
      backdrop-filter: blur(28px) saturate(190%) !important;
      -webkit-backdrop-filter: blur(28px) saturate(190%) !important;
    }

    [data-theme="dark"] body.tier-phone.style-glass .mobile-nav-bar,
    [data-theme="dark"] body.tier-phone.style-glass #appShell {
      background: rgba(18,18,22,0.40) !important;
      border-color: rgba(255,255,255,0.10) !important;
    }
    [data-theme="dark"] body.tier-phone.style-glass .main-workspace {
      background: rgba(18,18,22,0.30) !important;
      border-color: rgba(255,255,255,0.10) !important;
    }


/* Optional utility search (v1.3) */
.app-shell-search-control {
  position: relative;
  width: 35px;
  height: 34px;
  padding: 2px;
  flex: 0 0 auto;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: rgba(0,0,0,.05);
  transition: width 180ms ease, background 120ms ease, border-color 120ms ease;
}
[data-theme="dark"] .app-shell-search-control { background: rgba(255,255,255,.06); }
.app-shell-search-control.is-open { width: min(230px, 42vw); }
.app-shell-search-button {
  position: absolute;
  z-index: 3;
  top: 2px;
  right: 2px;
  width: 29px;
  height: 28px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.app-shell-search-button:hover,
.app-shell-search-control.is-open .app-shell-search-button {
  color: var(--text-main);
  background: var(--bg-surface);
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
}
.app-shell-search-button svg { width: 15px; height: 15px; }
.app-shell-search-field {
  position: absolute;
  z-index: 2;
  top: 0;
  right: 34px;
  width: calc(100% - 38px);
  min-width: 0;
  opacity: 0;
  transform: translateX(8px) scaleX(.96);
  transform-origin: right center;
  pointer-events: none;
  transition: opacity 150ms ease, transform 180ms ease;
}
.app-shell-search-control.is-open .app-shell-search-field {
  opacity: 1;
  transform: translateX(0) scaleX(1);
  pointer-events: auto;
}
.app-shell-search-field input {
  width: 100%;
  height: 32px;
  padding: 0 9px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  outline: 0;
  background: var(--bg-surface);
  color: var(--text-main);
  font: 500 11px/1 var(--font-stack);
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.app-shell-search-field input:focus-visible {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border-color));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}
.app-shell-search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  display: grid;
  gap: 2px;
  max-height: min(42vh, 280px);
  overflow: auto;
  padding: 5px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-surface);
  box-shadow: 0 10px 28px rgba(15,23,42,.14);
}
.app-shell-search-results:empty { display: none; }
.app-shell-search-result {
  min-height: 30px;
  padding: 6px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-main);
  text-align: left;
  cursor: pointer;
  font: 500 11px/1.2 var(--font-stack);
}
.app-shell-search-result:hover { background: var(--hover-bg); }
.app-shell-search-result small { display: block; margin-top: 2px; color: var(--text-faint); font-size: 10px; }

/* Existing Settings endpoint -> shell-managed settings panel (v1.3) */
.app-shell-settings-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1390;
  background: rgba(0,0,0,.18);
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease;
}
.app-shell-settings-backdrop.active { opacity: 1; pointer-events: auto; }
.app-shell-settings-panel {
  position: fixed;
  z-index: 1400;
  top: 18px;
  right: 18px;
  width: min(380px, calc(100vw - 24px));
  max-height: calc(100vh - 36px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  background: var(--bg-surface);
  color: var(--text-main);
  box-shadow: 0 18px 60px rgba(15,23,42,.2);
  opacity: 0;
  transform: translateY(-8px) scale(.985);
  pointer-events: none;
  transition: opacity 150ms ease, transform 160ms ease, background 120ms ease, color 120ms ease;
}
.app-shell-settings-panel.open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.app-shell-settings-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: 0 0 auto;
  padding: 16px 16px 0;
  margin-bottom: 14px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.app-shell-settings-close {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  font-size: 21px;
  line-height: 1;
  cursor: pointer;
}
.app-shell-settings-close:hover { background: var(--hover-bg); color: var(--text-main); }
.app-shell-settings-scroll {
  min-height: 0;
  flex: 1 1 auto;
  overflow: auto;
  padding: 0 16px 16px;
  border-radius: 0 0 13px 13px;
  scrollbar-gutter: stable;
}
.app-shell-settings-content { font-size: 12px; }
body.tier-phone .app-shell-settings-panel { top: 10px; right: 10px; width: calc(100vw - 20px); max-height: calc(100vh - 20px); }
