/**
 * NFT Studio mobile shell — drawer + Vault-style topbar.
 * Loaded last. Desktop layout unchanged above 768px.
 */

.topbar-head-row {
  display: contents;
}

.mobile-nav-cb,
.mobile-ai-cb {
  position: fixed;
  left: -100vw;
  width: 1px;
  height: 1px;
  opacity: 0;
  margin: 0;
  padding: 0;
  pointer-events: none;
  border: 0;
  clip: rect(0 0 0 0);
  overflow: hidden;
}

.mobile-nav-backdrop,
.mobile-menu-btn,
.mobile-nav-close,
.topbar-overflow-btn,
.topbar-overflow-backdrop,
.topbar-context {
  display: none;
}

@media (max-width: 768px) {
  .app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-height: 100dvh;
    min-height: 0;
    max-width: 100%;
    overflow: hidden;
  }

  body.mobile-nav-open {
    overflow: hidden;
  }

  .mobile-menu-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    padding: 0 10px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--surface-card-grad);
    color: var(--text);
    font-family: inherit;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    box-shadow: var(--surface-shadow);
    flex-shrink: 0;
  }

  .mobile-menu-btn svg {
    display: block;
  }

  .topbar-overflow-btn,
  .topbar-overflow-backdrop {
    display: none !important;
  }

  .mobile-nav-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 210;
    background: rgba(0, 0, 0, 0.48);
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  #mobile-nav-drawer:checked ~ .mobile-nav-backdrop {
    display: block;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(300px, 88vw);
    max-width: 100%;
    z-index: 220;
    grid-area: unset;
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    border-right: 1px solid var(--shell-sidebar-border);
    border-bottom: none;
    padding: 16px 14px calc(20px + env(safe-area-inset-bottom, 0px));
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
    background: rgba(11, 10, 18, 0.98) !important;
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
  }

  html.light .sidebar {
    background: rgba(255, 255, 255, 0.98) !important;
  }

  #mobile-nav-drawer:checked ~ .sidebar {
    transform: translateX(0);
  }

  .mobile-nav-close {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    align-self: flex-end;
    width: 40px;
    height: 40px;
    margin-bottom: 4px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--surface-card-grad);
    color: var(--muted);
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-nav-close:hover {
    color: var(--text);
    border-color: var(--line-2);
  }

  .sidebar .brand {
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    padding: 4px 0 12px;
    width: 100%;
  }

  .sidebar .brand-text {
    display: flex;
    align-items: flex-start;
    text-align: left;
  }

  .sidebar .brand-lockup-primary {
    align-items: flex-start;
  }

  .sidebar .brand-sub {
    text-align: left;
  }

  .sidebar .nav-btn {
    min-height: 44px;
    width: 100%;
    justify-content: flex-start;
  }

  .sidebar .nav-btn span {
    display: inline;
  }

  .sidebar .nav-label,
  .sidebar .sidebar-side-label,
  .sidebar .sidebar-wallet-name,
  .sidebar .sidebar-wallet-sub,
  .sidebar .sidebar-connected-label {
    display: block;
  }

  .sidebar .sidebar-network-chip span:not(.dot),
  .sidebar .sidebar-network-chip svg,
  .sidebar .sidebar-chain-note {
    display: inline;
  }

  .collapsed .nav-btn > span,
  .collapsed .nav-label,
  .collapsed .sidebar-side-label,
  .collapsed .sidebar-wallet-name,
  .collapsed .sidebar-wallet-sub,
  .collapsed .sidebar-connected-label,
  .collapsed .sidebar-network-chip span:not(.dot),
  .collapsed .sidebar-network-chip svg,
  .collapsed .sidebar-chain-note,
  .collapsed .brand-text,
  .collapsed .sidebar-wallet-head > div:first-child {
    display: revert;
  }

  .collapsed .nav-btn > span {
    display: inline;
  }

  .collapsed .nav-label,
  .collapsed .sidebar-side-label,
  .collapsed .sidebar-wallet-name,
  .collapsed .sidebar-wallet-sub,
  .collapsed .sidebar-connected-label {
    display: block;
  }

  .collapsed .brand-text {
    display: flex;
  }

  .collapsed .sidebar-wallet-head > div:first-child {
    display: block;
  }

  .sidebar-connected {
    margin-top: 14px;
    padding-top: 13px;
    border-top: 1px solid var(--line);
    justify-content: space-between;
  }

  .sidebar-side-card {
    padding: 14px;
    align-items: stretch;
  }

  .sidebar-wallet-head {
    justify-content: space-between;
  }

  .sidebar-wallet-head > div:first-child {
    display: block;
  }

  /* ── Mobile topbar: hamburger + actions on row 1; page context on row 2 ── */
  .topbar {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    order: 0;
    width: 100%;
    min-width: 0;
    flex-shrink: 0;
    padding: calc(8px + env(safe-area-inset-top, 0px)) 10px 10px;
    box-sizing: border-box;
    position: relative;
    z-index: 220;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .topbar > .mobile-menu-btn {
    display: none !important;
  }

  .topbar-head-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    min-width: 0;
    width: 100%;
  }

  .topbar-context {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
    gap: 2px;
    padding-left: 2px;
  }

  .topbar-actions {
    display: flex !important;
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    flex: 0 0 auto;
    margin-left: auto;
    min-width: 0;
    width: auto;
    position: static;
    top: auto;
    right: auto;
    left: auto;
    z-index: auto;
    max-width: none;
    max-height: none;
    overflow: visible;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    -webkit-overflow-scrolling: touch;
  }

  .topbar-actions .icon-btn {
    width: 42px;
    min-width: 42px;
    min-height: 42px;
    flex-shrink: 0;
    justify-content: center;
  }

  .topbar-actions .theme-toggle {
    height: 42px;
    padding: 3px;
    border-radius: 20px;
    flex-shrink: 0;
  }

  .topbar-actions .explorer-lang-btn {
    height: 42px;
    min-height: 42px;
  }

  .topbar-actions .theme-toggle-btn {
    width: 28px;
    height: 34px;
    border-radius: 16px;
  }

  .topbar-actions .connect-wallet,
  .topbar-actions .topbar-auth-btn {
    flex: 0 0 auto;
    min-width: 42px;
    width: 42px;
    min-height: 42px;
    padding: 12px;
    justify-content: center;
    font-size: 11px;
    line-height: 1.2;
  }

  .topbar-actions .connect-wallet span:not(.gicon),
  .topbar-actions .topbar-auth-btn [data-unara-auth-label],
  .topbar-actions .topbar-auth-btn span:not(.gicon) {
    display: none !important;
  }

  .topbar-context-title {
    font-size: 15px;
    font-weight: 650;
    letter-spacing: -0.02em;
    line-height: 1.25;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar-context-sub {
    font-size: 11px;
    line-height: 1.3;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* ── Scroll container: main (body stays overflow:hidden on desktop pattern) ── */
  .main {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    width: 100%;
    padding: 8px 10px calc(12px + env(safe-area-inset-bottom, 0px));
    order: 0;
    overflow-x: clip;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 768px) and (prefers-reduced-motion: reduce) {
  .sidebar {
    transition: none;
  }
}
