/* ═══════════════════════════════════════════════════════════════════════════
   Mobile bottom-tab navigation + drawer - Phase 1a
   ----------------------------------------------------------------------------
   ADDITIVE-ONLY: every selector is gated by max-width: 840px, so anything
   ≥ 841px (tablet landscape + desktop) sees ZERO of these styles. The
   existing top-nav (#nav) is hidden ≤ 840px to make room for this shell.

   Visibility map by zone (defined in breakpoints.css):
     phone (≤640)            → bottom tabs + drawer + slim top header
     tablet portrait (641–840) → same as phone
     tablet landscape (841–1280) → existing top nav, untouched
     desktop (≥1281)         → existing top nav, UNTOUCHED
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Default state: completely invisible, doesn't affect layout ─────────── */
#mobile-bottom-nav,
#mobile-top-bar,
#mobile-drawer,
#mobile-drawer-backdrop {
  display: none;
}

/* Hide the desktop top-nav and inject the mobile shell - only ≤ 840px. */
@media (max-width: 840px) {

  /* ── Hide existing desktop nav + summary bar ──────────────────────── */
  #nav {
    /* Hidden completely on small screens - the bottom-tab nav replaces it.
       Note: this DOES affect existing #nav element's display, but only
       within the gated media query, so desktop is not affected. */
    display: none !important;
  }
  /* The legacy #toolbar bar (search/filters) is kept visible because
     individual screens own their own search affordances; we don't try to
     replace it here. Phase 1c can revisit. */

  /* ── Mobile top bar (slim, brand + identity avatar + drawer trigger) ─ */
  #mobile-top-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px;
    /* Stack above page content, sit under iOS notch. */
    padding-top: calc(8px + var(--safe-top));
    background: linear-gradient(180deg, #0F1419 0%, #06080B 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    color: #FFFFFF;
    position: sticky;
    top: 0;
    z-index: 90;
  }
  .mtb-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
  }
  .mtb-brand-mark {
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
  }
  .mtb-brand-name {
    font-family: 'IBM Plex Sans', sans-serif;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.02em;
    color: #FFFFFF;
    white-space: nowrap;
  }
  .mtb-brand-name .brand-org      { color: #FFFFFF; }
  .mtb-brand-name .brand-foundry  { color: var(--orange-bright, #FF5A00); }
  .mtb-page-title {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.65);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .mtb-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--orange-bright, #FF5A00);
    color: #FFFFFF;
    border: 0;
    font-weight: 800;
    font-size: 13px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 36px;
    font-family: 'IBM Plex Sans', sans-serif;
  }
  .mtb-avatar:active {
    transform: scale(0.96);
  }

  /* ── Bottom tab bar ────────────────────────────────────────────────── */
  #mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    /* Lift above the soft keyboard (Phase 0b) so the tabs don't hide under it. */
    bottom: calc(var(--keyboard-height, 0px));
    background: #0F1419;
    border-top: 1px solid rgba(255, 255, 255, 0.10);
    padding-bottom: var(--safe-bottom);
    z-index: 100;
    /* Subtle shadow upward to separate from content underneath. */
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.3);
  }
  /* Hide the bar entirely while a soft keyboard is open - gives the user
     all of their viewport to type and prevents the visual jank of the bar
     bouncing as the keyboard animates. */
  body[data-keyboard-open="true"] #mobile-bottom-nav {
    transform: translateY(100%);
    transition: transform 150ms ease-out;
  }

  .mob-tab {
    flex: 1 1 0;
    min-width: 0;
    background: transparent;
    border: 0;
    color: rgba(255, 255, 255, 0.55);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    /* Touch-friendly tap target: 44px min height per Phase 0a contract. */
    min-height: 56px;
    padding: 6px 4px 8px;
    font-family: 'IBM Plex Sans', sans-serif;
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    transition: color 0.12s ease, background 0.12s ease;
    -webkit-tap-highlight-color: transparent;
  }
  .mob-tab:active {
    background: rgba(255, 255, 255, 0.06);
  }
  .mob-tab-icon {
    font-size: 20px;
    line-height: 1;
    color: inherit;
  }
  .mob-tab-label {
    color: inherit;
    font-size: 9.5px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }
  .mob-tab.mob-tab-active {
    color: var(--orange-bright, #FF5A00);
  }
  .mob-tab.mob-tab-active .mob-tab-icon {
    color: var(--orange-bright, #FF5A00);
  }
  /* Subtle top-edge indicator on the active tab. */
  .mob-tab.mob-tab-active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 20%;
    right: 20%;
    height: 2px;
    background: var(--orange-bright, #FF5A00);
    border-radius: 0 0 2px 2px;
  }
  .mob-tab {
    position: relative;
  }

  /* Phase 2c: pending-count badge on a tab (currently HC only) */
  .mob-tab .mob-tab-badge {
    position: absolute;
    top: 6px;
    right: calc(50% - 22px);
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--orange-bright, #FF5A00);
    color: #FFFFFF;
    font-size: 10px;
    font-weight: 800;
    line-height: 18px;
    text-align: center;
    box-shadow: 0 0 0 2px #0F1419; /* halo so it pops on the dark bar */
    pointer-events: none;
  }

  /* ── Body padding so content doesn't hide under the fixed bottom nav ── */
  body {
    /* 56px tab + safe-area-bottom + a touch of breathing room. */
    padding-bottom: calc(60px + var(--safe-bottom));
  }
  body[data-keyboard-open="true"] {
    /* When the keyboard pushes the tabs offscreen, drop the padding too. */
    padding-bottom: 0;
  }

  /* ── Drawer (slides in from left, contains secondary nav) ─────────── */
  #mobile-drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 110;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--sheet-anim-duration, 220ms) var(--sheet-anim-ease, ease);
  }
  #mobile-drawer-backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
  }
  #mobile-drawer {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(85vw, 320px);
    background: #0F1419;
    color: #FFFFFF;
    z-index: 120;
    transform: translateX(-100%);
    transition: transform var(--sheet-anim-duration, 220ms) var(--sheet-anim-ease, ease);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
  }
  #mobile-drawer.is-open {
    transform: translateX(0);
  }

  .mob-drawer-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }
  .mob-drawer-header .mtb-brand-mark { width: 32px; height: 32px; flex: 0 0 32px; }
  .mob-drawer-header .mtb-brand-name { font-size: 15px; }
  .mob-drawer-close {
    margin-left: auto;
    background: transparent;
    border: 0;
    color: rgba(255, 255, 255, 0.5);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
  }

  .mob-drawer-section {
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  }
  .mob-drawer-section:last-child {
    border-bottom: 0;
  }
  .mob-drawer-section-title {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.4);
    padding: 8px 18px;
    margin: 0;
  }
  .mob-drawer-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    background: transparent;
    border: 0;
    color: rgba(255, 255, 255, 0.85);
    padding: 12px 18px;
    min-height: 48px;
    font-family: 'IBM Plex Sans', sans-serif;
    font-size: 13px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.12s ease, color 0.12s ease;
  }
  .mob-drawer-item:active {
    background: rgba(255, 255, 255, 0.06);
  }
  .mob-drawer-item.mob-drawer-item-active {
    background: rgba(255, 90, 0, 0.10);
    color: var(--orange-bright, #FF5A00);
  }
  .mob-drawer-item-icon {
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: inherit;
    flex: 0 0 22px;
  }
  .mob-drawer-item-label {
    flex: 1;
    color: inherit;
  }

  /* The drawer scrolls internally if the section list overflows. */
  .mob-drawer-scroll {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .mob-drawer-footer {
    padding: 14px 18px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    line-height: 1.4;
  }
}

/* ════════════════════════════════════════════════════════════════════════
   Tablet landscape + desktop (≥841px) sees ZERO of the above. Everything
   is inside @media (max-width: 840px). The existing top nav, summary bar,
   workspace layout, side detail panel - completely untouched.
   ════════════════════════════════════════════════════════════════════════ */
