@use '../styles/_globals.scss' as *;

:host {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.app-container {
  display: flex;
  height: 100vh;
  min-height: 100vh;
  // mobile viewport bug fix
  min-height: -webkit-fill-available;
}

// Vertical action bar (opt-in via misc.isVerticalActionBar): reserve a
// column on the right for the fixed action strip teleported by main-header
// (desktop only). The strip is position: fixed, so this padding keeps the
// main content + right-panel to the left of it.
.app-container.has-vertical-action-bar {
  @include mq(xs) {
    padding-right: var(--vertical-action-bar-width);
  }
}

:host-context([dir='rtl']) .app-container.has-vertical-action-bar {
  @include mq(xs) {
    padding-right: 0;
    padding-left: var(--vertical-action-bar-width);
  }
}

// Native mobile: body has safe area padding that pushes content down,
// so the container must be shorter than 100vh to stay within the visible viewport.
// Without this, bottom items (like Settings) in the sidebar are clipped off-screen.
:host-context(body.isNativeMobile) .app-container {
  height: calc(100vh - var(--safe-area-top) - var(--safe-area-bottom));
  min-height: calc(100vh - var(--safe-area-top) - var(--safe-area-bottom));
}

// When keyboard is visible or bottom nav is present, body only has top padding
:host-context(body.isNativeMobile.isKeyboardVisible) .app-container,
:host-context(body.isNativeMobile.hasMobileBottomNav) .app-container {
  height: calc(100vh - var(--safe-area-top));
  min-height: calc(100vh - var(--safe-area-top));
}

// iOS keeps 100vh tied to the layout viewport while the soft keyboard is open.
// Use visualViewport height from JS so the app shell shrinks above the keyboard.
:host-context(body.isIOS.isKeyboardVisible) .app-container {
  height: calc(var(--visual-viewport-height) - var(--safe-area-top));
  min-height: calc(var(--visual-viewport-height) - var(--safe-area-top));
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0; // Prevent flex item from growing beyond container
  overflow: hidden;
}

// First-run onboarding is a focused full-window takeover, so hide the app
// shell's navigation behind it. Necessary for translucent themes (e.g.
// liquid-glass sets `--bg: transparent`) where the nav would otherwise show
// through the onboarding backdrop and overlap its content (#7885).
// Use `visibility: hidden` (not `display: none`) so the nav keeps its layout
// space — when onboarding finishes the nav reveals in place instead of the
// content reflowing as it pops back in.
.app-container.is-onboarding {
  magic-side-nav,
  mobile-bottom-nav {
    visibility: hidden !important;
  }
}

// Mobile bottom nav spacing
.has-mobile-bottom-nav {
  @include mq(xs, max) {
    .main-content {
      padding-bottom: calc(var(--bottom-nav-height) + var(--bottom-nav-safe-area));
    }
  }
}

// Override magic-side-nav styles for flex layout integration
// Use desktop layout overrides only on larger screens
@include mq(xs) {
  mobile-bottom-nav {
    display: none !important;
  }

  magic-side-nav {
    ::ng-deep .nav-sidenav {
      position: relative !important;
      top: auto !important;
      left: auto !important;
      bottom: auto !important;
      height: 100% !important;
      z-index: auto !important;
    }
  }
}

.header-wrapper {
  position: relative;
  z-index: var(--z-main-header-wrapper);
  display: block;
  transition: var(--transition-enter);
  border-bottom: 1px solid transparent;
  border-color: var(--extra-border-color);

  &.isNotScrolled {
    border-color: transparent !important;
  }
}

.route-wrapper {
  flex-grow: 1;
  position: relative;
  overflow: hidden;
  -webkit-app-region: no-drag !important;
  height: 100%;
  container-type: inline-size;
  container-name: main-content;

  > ::ng-deep router-outlet + * {
    position: absolute;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    overflow-x: hidden;
    @include scrollY();
  }

  > ::ng-deep {
    tag-task-page,
    project-task-page {
      overflow: hidden;
    }
  }
}

.backdrop {
  // global styles in backdrop.scss
}

add-task-bar {
  z-index: var(--z-add-task-bar);
}

main-header {
  position: relative;
  z-index: var(--z-main-header);
}

.right-panel {
  min-width: 300px;
  width: 40vw;
  max-width: 700px;
  min-height: 100vh;
  // mobile viewport bug fix
  min-height: -webkit-fill-available;

  .mat-drawer-over & {
    width: 80vw;

    @include mq(xs, max) {
      width: 90vw;
    }
  }
}

// SIDENAV
// -------
:host ::ng-deep .mat-drawer-content {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

mat-sidenav-container.mat-sidenav-container {
  background: transparent;
}

mat-sidenav,
mat-sidenav-container {
  height: 100%;
}

// sidebars
mat-sidenav ::ng-deep .mat-drawer-inner-container {
  @include scrollYImportant();

  background: var(--sidenav-bg);
}

mat-sidenav {
  width: fit-content;
  z-index: var(--z-side-nav);
}

// Remove right border/shadow of the side nav

:host ::ng-deep .mat-drawer.mat-drawer-side {
  border-right-color: var(--sidebar-border-color);
}

@include mq(component) {
  button.mat-mdc-menu-item {
    width: 600px;
  }
}

.bg-image {
  position: absolute;
  inset: 0;
  pointer-events: none;
  width: 100%;
  height: 100%;
  background-size: cover !important;
  background-position: center !important;
  background-attachment: fixed;

  &.is-blurred {
    transform: scale(1.12);
  }
}

// App entrance animation after onboarding preset selection
@keyframes entrance-slide-left {
  from {
    opacity: 0;
    transform: translateX(-30px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes entrance-slide-up {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.app-entrance {
  // Main content area fades + slides up as a whole
  .main-content {
    animation: entrance-slide-up 450ms ease-out 150ms backwards;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-entrance {
    .main-content {
      animation: none;
    }
  }
}
