/* Compact floating navigation for phones and tablets. */
.mobile-bottom-nav {
  display: none;
}

@media (max-width: 1023px) {
  :root {
    --mobile-bottom-nav-height: 62px;
    --mobile-bottom-nav-gap: 8px;
    --mobile-bottom-nav-inset: 10px;
    --mobile-bottom-nav-safe-bottom: 0px;
    --mobile-bottom-nav-safe-bottom: constant(safe-area-inset-bottom);
    --mobile-bottom-nav-safe-bottom: env(safe-area-inset-bottom, 0px);
    --mobile-bottom-nav-offset: calc(
      var(--mobile-bottom-nav-height) + var(--mobile-bottom-nav-gap) + var(--mobile-bottom-nav-safe-bottom)
    );
  }

  .mobile-bottom-nav {
    position: fixed;
    z-index: 900;
    right: var(--mobile-bottom-nav-inset);
    bottom: var(--mobile-bottom-nav-gap);
    bottom: calc(var(--mobile-bottom-nav-gap) + constant(safe-area-inset-bottom));
    bottom: calc(var(--mobile-bottom-nav-gap) + env(safe-area-inset-bottom, 0px));
    left: var(--mobile-bottom-nav-inset);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0;
    box-sizing: border-box;
    width: auto;
    max-width: calc(100vw - (var(--mobile-bottom-nav-inset) * 2));
    height: var(--mobile-bottom-nav-height);
    /* Keep left/right inset identical so the dock reads centered. */
    padding: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior: contain;
    overscroll-behavior-y: none;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    touch-action: pan-x;
    isolation: isolate;
    contain: layout paint style;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    background: var(--ref-panel-bg, var(--card-bg, #fff));
    border: 1px solid var(--ref-border, var(--border-color, #e5e7eb));
    border-radius: 18px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.16);
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
  }

  .mobile-bottom-nav::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
  }

  .mobile-bottom-nav-item,
  .mobile-bottom-nav-item.el-button {
    box-sizing: border-box;
    flex: 1 1 0;
    width: 0;
    min-width: 0;
    max-width: none;
    height: 50px;
    min-height: 50px;
    margin: 0 !important;
    padding: 4px 2px !important;
    display: inline-flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 3px !important;
    color: var(--text-secondary, #64748b);
    background: transparent;
    border: 0 !important;
    border-radius: 12px;
    line-height: 1 !important;
    text-align: center !important;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
  }

  /* Element Plus wraps slot content; force a centered column stack. */
  .mobile-bottom-nav-item.el-button > span {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 3px !important;
    width: 100% !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    line-height: 1 !important;
    text-align: center !important;
  }

  /* Element Plus adds margin-left to text after icons — kill it for vertical layout. */
  .mobile-bottom-nav-item.el-button [class*=el-icon] + span,
  .mobile-bottom-nav-item.el-button .el-icon + span {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  .mobile-bottom-nav-item .el-icon,
  .mobile-bottom-nav-item.el-button .el-icon {
    display: inline-flex !important;
    flex: 0 0 19px !important;
    align-items: center !important;
    justify-content: center !important;
    width: 19px !important;
    height: 19px !important;
    margin: 0 auto !important;
    padding: 0 !important;
    font-size: 19px !important;
    line-height: 1 !important;
  }

  .mobile-bottom-nav-item .el-icon svg {
    display: block !important;
    width: 1em !important;
    height: 1em !important;
    margin: 0 auto !important;
  }

  .mobile-bottom-nav-item > span > span,
  .mobile-bottom-nav-item.el-button > span > span,
  .mobile-bottom-nav-item.el-button [class*=el-icon] + span {
    display: block !important;
    box-sizing: border-box;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden;
    color: inherit;
    font-size: 9px !important;
    font-weight: 500;
    line-height: 14px !important;
    text-align: center !important;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-bottom-nav-item.active {
    color: var(--ref-primary, var(--admin-primary, #409eff));
    background: var(--ref-primary-soft, var(--admin-primary-soft, rgba(64, 158, 255, 0.12)));
  }

  .mobile-bottom-nav-item:focus-visible {
    outline: 2px solid var(--ref-primary, var(--admin-primary, #409eff));
    outline-offset: -2px;
  }

  /* The bottom nav is the mobile menu entry, so remove the duplicate left rail. */
  .element-admin-topbar .element-admin-topbar-left,
  .mobile-topbar-left {
    display: none !important;
    width: 0 !important;
    min-width: 0 !important;
    flex: 0 0 0 !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .element-admin-topbar .element-admin-topbar-content {
    justify-content: flex-end !important;
    padding: 0 12px !important;
  }

  .element-admin-topbar .element-admin-topbar-right {
    width: 100% !important;
    justify-content: flex-end !important;
  }

  .mobile-topbar-actions {
    width: 100% !important;
    max-width: 100% !important;
    gap: 0 !important;
    justify-content: stretch !important;
  }

  .mobile-topbar-actions > * {
    display: flex !important;
    flex: 1 1 0 !important;
    min-width: 0 !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .mobile-topbar-actions .mobile-topbar-icon {
    width: 30px !important;
    min-width: 30px !important;
    height: 34px !important;
  }

  .mobile-topbar-actions .mobile-avatar-btn {
    width: 38px !important;
    min-width: 38px !important;
  }

  .console-shell > .console-page:not(.game-page) {
    padding-bottom: calc(var(--mobile-bottom-nav-offset) + 34px) !important;
    scroll-padding-bottom: calc(var(--mobile-bottom-nav-offset) + 34px);
  }

  /* Game center: hide bottom nav; keep topbar clean (exit via 返回首页). */
  .element-admin-layout.is-game-center .mobile-bottom-nav {
    display: none !important;
  }

  .element-admin-layout.is-game-center .element-admin-topbar .element-admin-topbar-left,
  .element-admin-layout.is-game-center .mobile-topbar-left,
  .element-admin-layout.is-game-center .mobile-fish-mark,
  .element-admin-layout.is-game-center .topbar-theme-custom-action,
  .element-admin-layout.is-game-center .topbar-theme-action {
    display: none !important;
  }

  .element-admin-layout.is-game-center .console-shell > .game-page {
    padding-bottom: calc(16px + var(--mobile-bottom-nav-safe-bottom)) !important;
    scroll-padding-bottom: calc(16px + var(--mobile-bottom-nav-safe-bottom));
  }
}

@media (max-width: 1023px) and (max-height: 480px) {
  :root {
    --mobile-bottom-nav-height: 52px;
    --mobile-bottom-nav-gap: 6px;
  }

  .mobile-bottom-nav {
    height: var(--mobile-bottom-nav-height);
    padding: 4px;
    border-radius: 14px;
  }

  .mobile-bottom-nav-item,
  .mobile-bottom-nav-item.el-button {
    height: 44px;
    min-height: 44px;
  }
}
