/* Shared mobile navigation for the portal and calculator. */
.mobile-bar,
.mobile-nav-toggle,
.mobile-nav-close,
.mobile-drawer-actions,
.mobile-drawer-filters,
.mobile-action-label,
.hub-mobile-drawer {
  display: none;
}

.mobile-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--tx);
  text-decoration: none;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.3;
}

.mobile-brand img {
  flex-shrink: 0;
  border-radius: 10px;
}

.mobile-brand small {
  display: block;
  color: var(--mu);
  font-size: 10px;
  font-weight: 600;
}

button.mobile-nav-toggle,
button.mobile-nav-close {
  display: none;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 14px;
}

.mobile-nav-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
  touch-action: none;
}

.mobile-nav-backdrop[hidden] {
  display: none;
}

@media (max-width: 1040px) {
  body.mobile-nav-open {
    position: fixed;
    width: 100%;
    overflow: hidden;
  }

  .mobile-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 30;
    padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
    background: var(--sidebar);
    border-bottom: 1px solid var(--bd-soft);
  }

  button.mobile-nav-toggle,
  button.mobile-nav-close {
    display: inline-grid;
  }

  .mobile-drawer {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 24px;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 101;
    width: min(320px, calc(100vw - 32px));
    height: 100vh;
    height: 100dvh;
    min-width: 0;
    padding: max(20px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    margin: 0;
    border: 0;
    border-right: 1px solid var(--bd);
    border-radius: 0 24px 24px 0;
    background: var(--sidebar);
    box-shadow: 12px 0 40px rgba(0, 0, 0, 0.2);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    visibility: hidden;
    transform: translateX(-100%);
    transition: transform 0.22s ease, visibility 0s linear 0.22s;
  }

  .mobile-nav-open .mobile-drawer {
    visibility: visible;
    transform: translateX(0);
    transition-delay: 0s;
  }

  .mobile-drawer .side-top {
    min-width: 0;
  }

  .mobile-drawer .brand {
    min-height: 44px;
    padding: 0 48px 0 4px;
    margin-bottom: 24px;
    letter-spacing: 0;
  }

  .mobile-drawer .brand-badge-square {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
  }

  .mobile-drawer .brand-badge-square svg {
    width: 28px;
    height: 28px;
  }

  .mobile-drawer .brand-text,
  .hub-header .brand-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    line-height: 1.3;
  }

  .mobile-drawer .brand-text small {
    color: var(--mu);
    font-size: 10px;
    font-weight: 600;
  }

  .mobile-drawer .mobile-nav-close {
    position: absolute;
    top: max(20px, env(safe-area-inset-top));
    right: 16px;
  }

  .mobile-drawer-brand {
    min-height: 44px;
    padding-right: 48px;
  }

  .mobile-drawer .side-nav,
  .mobile-drawer .hub-nav-links {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    width: 100%;
  }

  .mobile-drawer .nav-item,
  .mobile-drawer .hub-nav-link {
    min-height: 48px;
    padding: 12px 14px;
    border-radius: 14px;
    white-space: normal;
    overflow-wrap: anywhere;
    font-size: 14px;
  }

  .mobile-drawer .nav-left {
    min-width: 0;
  }

  .mobile-drawer .badge-count {
    flex-shrink: 0;
  }

  .mobile-drawer-actions {
    display: block;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--bd);
  }

  .hub-mobile-drawer .mobile-drawer-actions {
    margin-top: 0;
  }

  .mobile-drawer-filters {
    display: block;
    padding-top: 20px;
    border-top: 1px solid var(--bd);
  }

  .mobile-drawer .hub-subbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin: 0;
    padding: 0;
    border: 0;
  }

  .mobile-drawer .hub-search-box {
    flex: none;
    min-width: 0;
  }

  .mobile-drawer .hub-filter-selects {
    flex-direction: column;
    align-items: stretch;
  }

  .mobile-drawer .hub-search-box input,
  .mobile-drawer .hub-select {
    width: 100%;
    min-width: 0;
    height: 48px;
    border-radius: 14px;
    font-size: 16px;
  }

  .mobile-nav-heading {
    margin: 0 14px 12px;
    color: var(--mu);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .mobile-drawer-actions .header-actions,
  .mobile-drawer-actions .hub-header-actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .mobile-drawer-actions button.icon-circle {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    width: 100%;
    height: auto;
    min-height: 48px;
    padding: 12px 14px;
    border-radius: 14px;
    text-align: left;
    white-space: normal;
  }

  .mobile-drawer-actions .profile-pill {
    min-height: 52px;
    padding: 10px 14px;
    border-radius: 14px;
  }

  .mobile-action-label {
    display: inline;
    font-size: 14px;
  }

  .mobile-drawer-actions .mobile-nav-duplicate {
    display: none !important;
  }

  .mobile-drawer .side-promo {
    display: block;
    margin-top: auto;
    border-radius: 16px;
  }

  .mobile-drawer .side-promo button {
    min-height: 44px;
  }

  .workspace [id^="sec-"],
  .workspace #sec-overview {
    scroll-margin-top: 88px;
  }

  .hub-header-top {
    flex-wrap: nowrap;
  }

  .hub-container {
    padding: 12px 16px 32px;
  }

  .hub-header {
    padding: 12px 14px;
    margin-bottom: 20px;
  }

  /* Keep the header compact while its controls move into the drawer. */
  .hub-header [data-mobile-move],
  .workspace .top > .header-actions {
    display: none;
  }

  .mobile-drawer :is(a, button, input, select):focus-visible,
  .mobile-nav-toggle:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 3px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mobile-drawer {
    transition: none;
  }
}
