/* Mobile bottom navigation dock (<= 680px) */

/* Header actions that only exist on mobile (settings beside the bell) */
.is-mobile-only {
  display: none;
}

@media (max-width: 680px) {
  .app-layout,
  .app-layout.is-collapsed {
    --current-sidebar-width: 0px;
  }

  .sidebar {
    position: fixed;
    inset: auto 0 0 0;
    width: 100% !important;
    height: auto;
    min-height: 0;
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
    flex-direction: row;
    align-items: center;
    gap: 2px;
    border-right: 0;
    border-top: 1px solid var(--border-subtle);
    background-color: var(--bg-elevated);
    overflow: hidden;
    z-index: 40;
  }

  .sidebar-top,
  .user-info,
  .sidebar-toggle {
    display: none !important;
  }

  .sidebar-upper {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: row;
    gap: 0;
  }

  .sidebar-nav {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 2px;
    width: 100%;
    min-width: 0;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar-nav::-webkit-scrollbar {
    display: none;
  }

  .sidebar-nav .nav-item {
    flex: 1 1 0;
    width: auto !important;
    min-width: 44px;
    max-width: 76px;
    height: 48px;
    padding: 0 4px;
    justify-content: center;
  }

  /* Routes that do not fit in the bar move behind "Mais" instead of
     sliding off-screen with no way to reach them */
  .sidebar-nav .nav-item[data-dock="more"] {
    display: none;
  }

  .sidebar-nav .nav-item.dock-more-btn {
    display: flex;
  }

  .sidebar-nav .nav-label {
    display: none !important;
  }

  /* Sync and settings stay pinned to the right edge of the dock */
  .sidebar-bottom {
    flex: 0 0 auto;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 2px;
    margin-left: 2px;
  }

  .sidebar-sync-wrap {
    display: flex;
    align-items: center;
  }

  .sidebar-sync-btn {
    width: 44px;
    height: 48px;
    padding: 0;
    justify-content: center;
    border: 0;
    background: transparent;
  }

  .sidebar-sync-btn svg {
    width: 18px;
    height: 18px;
  }

  .sidebar-sync-btn .nav-label,
  .app-layout.is-collapsed .sidebar-sync-btn .nav-label {
    display: none !important;
  }

  .sidebar-footer {
    flex-shrink: 0;
    position: static;
    display: flex;
    align-items: center;
    min-height: 0;
    padding: 0 !important;
    border-top: 0;
  }

  .sidebar-footer .icon-btn,
  .app-layout.is-collapsed .sidebar-footer .icon-btn {
    position: static !important;
    width: 44px;
    height: 48px;
  }

  .is-mobile-only {
    display: inline-flex;
  }

  .page-header .backup-group {
    margin-left: auto;
    gap: 6px;
  }

  /* On the dashboard settings lives in the header, next to the notifications */
  body[data-route="dashboard"] .sidebar-footer {
    display: none;
  }

  .main-content {
    margin-left: 0 !important;
    padding:
      calc(var(--space-md) + env(safe-area-inset-top))
      calc(14px + env(safe-area-inset-right))
      calc(72px + env(safe-area-inset-bottom))
      calc(14px + env(safe-area-inset-left));
  }
}

@media (min-width: 681px) {
  .dock-more-btn {
    display: none !important;
  }
}

/* Bottom sheet holding the dock routes that do not fit in the bar */
.dock-sheet {
  position: fixed;
  inset: auto 0 0 0;
  width: 100%;
  max-width: 100%;
  max-height: min(72dvh, 540px);
  margin: 0;
  padding: 6px 10px calc(12px + env(safe-area-inset-bottom));
  border: 0;
  border-top: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--bg-elevated);
  color: var(--text-primary);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.dock-sheet[open] {
  animation: dock-sheet-in 180ms ease;
}

.dock-sheet::backdrop {
  background: rgba(17, 18, 22, 0.45);
}

.dock-sheet-handle {
  width: 36px;
  height: 4px;
  margin: 2px auto 10px;
  border-radius: 999px;
  background: var(--border-strong);
}

.dock-sheet-title {
  margin: 0 8px 6px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.dock-sheet-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dock-sheet-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.dock-sheet-item .nav-icon {
  width: 24px;
  height: 24px;
}

.dock-sheet-item .nav-icon svg {
  width: 20px;
  height: 20px;
}

.dock-sheet-item.is-active {
  background: var(--bg-subtle);
  color: var(--accent-primary);
  font-weight: 600;
}

@keyframes dock-sheet-in {
  from {
    transform: translateY(14%);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .dock-sheet[open] {
    animation: none;
  }
}
