/* Application styles */

/* Safe area: keep content clear of notch/status bar and home indicator/tab bar.
   With viewport-fit=cover (native), env() returns real insets; otherwise 0. */
body {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* Prevent body scroll when a modal dialog or the mobile drawer is open */
body:has(dialog[open]),
body:has(#main-drawer:checked) {
  overflow: hidden;
}

/* Disable overscroll only in Hotwire Native WKWebView to prevent rubber-band getting stuck.
   Regular mobile browsers need overscroll for pull-to-refresh. */
body[data-native] {
  overscroll-behavior-y: none;
}

/* In native, body has safe-area padding, so inner content min-height must subtract
   those insets — otherwise body padding + 100dvh inner = more than viewport height,
   causing unwanted scroll on short pages. */
body[data-native] .drawer-content {
  min-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
}

/* WKWebView doesn't fire mouseout on navigation, so :hover states get stuck
   when returning via back. Disable hover backgrounds on native menu links. */
body[data-native] .menu li > a:hover,
body[data-native] .menu li > button:hover,
body[data-native] .menu li > label:hover {
  background-color: transparent;
}

/* Chart.js canvases capture touch events for tooltips, blocking page scroll
   in WKWebView. Allow vertical pan-scrolling through chart containers. */
body[data-native] canvas {
  touch-action: pan-y !important;
}

/* Force mobile layout in Hotwire Native — neutralise lg: desktop-shell styles
   so iPad always renders the mobile-optimised view. */
@media (min-width: 64rem) {
  body[data-native] {
    height: auto;
    overflow: visible;
  }

  body[data-native] .drawer > .drawer-toggle ~ .drawer-side {
    position: fixed;
    visibility: hidden;
    pointer-events: none;
  }

  body[data-native] .drawer-content {
    height: auto;
    overflow-y: visible;
    background-color: var(--color-base-100);
  }

  body[data-native] .drawer-content > :first-child {
    margin: 0;
    border: 0;
    border-radius: 0;
  }
}

/* PWA display-mode utilities */
.hide-in-pwa {
  @media (display-mode: standalone) {
    display: none;
  }
}

.hide-in-browser {
  @media (display-mode: browser) {
    display: none;
  }
}

.hide-in-ios-pwa {
  @media (display-mode: standalone) {
    @supports (-webkit-touch-callout: none) {
      display: none;
    }
  }
}

/* View transitions intentionally disabled for static-page navigation clarity. */

/* Hide chevron and nested menu styling when sidebar is collapsed */
[data-expanded='false'] .menu li > details > summary::after {
  display: none;
}

[data-expanded='false'] .menu li ul {
  margin-inline-start: 0;
  padding-inline-start: 0;
}

[data-expanded='false'] .menu li ul::before {
  display: none;
}

/* CTA button */
.btn-cta {
  position: relative;
  overflow: hidden;
  animation: cta-glow 2.5s ease-in-out infinite;
}

.btn-cta:hover {
  animation: cta-glow-hover 2s ease-in-out infinite;
}

.btn-cta::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(110deg, transparent 25%, oklch(1 0 0 / 0.15) 50%, transparent 75%);
  animation: cta-shimmer 3s ease-in-out infinite;
}

@keyframes cta-shimmer {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

@keyframes cta-glow {
  0%,
  100% {
    box-shadow: 0 4px 20px color-mix(in oklch, var(--color-primary) 30%, transparent);
  }
  50% {
    box-shadow: 0 4px 30px color-mix(in oklch, var(--color-primary) 50%, transparent);
  }
}

@keyframes cta-glow-hover {
  0%,
  100% {
    box-shadow: 0 4px 25px color-mix(in oklch, var(--color-primary) 45%, transparent);
  }
  50% {
    box-shadow: 0 6px 40px color-mix(in oklch, var(--color-primary) 65%, transparent);
  }
}

/* Modal open/close animations using @starting-style */
dialog.modal {
  opacity: 1;
  transition:
    opacity 0.2s ease-out,
    overlay 0.2s ease-out allow-discrete,
    display 0.2s ease-out allow-discrete;

  @starting-style {
    opacity: 0;
  }
}

dialog.modal > .modal-box {
  transform: scale(1);
  transition: transform 0.2s ease-out;

  @starting-style {
    transform: scale(0.95);
  }
}

dialog.modal::backdrop {
  opacity: 1;
  transition:
    opacity 0.2s ease-out,
    overlay 0.2s ease-out allow-discrete,
    display 0.2s ease-out allow-discrete;

  @starting-style {
    opacity: 0;
  }
}

/* Slide-in from right for side panel modals */
dialog.modal.modal-end > .modal-box {
  @starting-style {
    transform: translateX(100%);
  }
}

/* iOS-style bottom sheet modals on mobile */
/* Below Tailwind `sm` (640px) — keep in sync with tailwind config */
@media (max-width: 639px) {
  dialog.modal {
    align-items: flex-end;
  }

  dialog.modal > .modal-box {
    max-width: 100%;
    width: 100%;
    margin: 0;
    border-radius: 1rem 1rem 0 0;
    max-height: 92dvh;
    overflow-y: auto;
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));

    @starting-style {
      transform: translateY(100%);
    }
  }
}

/* Scroll-snap for horizontal tab navigation */
nav[role='tablist'] {
  scroll-snap-type: x proximity;
}

nav[role='tablist'] > a[role='tab'] {
  scroll-snap-align: center;
}

/* Visual loading feedback for Turbo Frames — Turbo sets aria-busy="true" while fetching */
turbo-frame[aria-busy='true'] {
  opacity: 0.6;
  cursor: wait;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

/* Skip rendering off-screen list content for better scroll performance */
turbo-frame[id*='list'],
turbo-frame[id*='items'] {
  content-visibility: auto;
  contain-intrinsic-size: auto 500px;
}

/* Floating UI tooltip styles */
.floating-tooltip {
  position: absolute;
  z-index: 9999;
  max-width: min(250px, 80vw);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  background-color: var(--color-neutral);
  color: var(--color-neutral-content);
  border-radius: 0.375rem;
  white-space: normal;
  text-align: left;
  pointer-events: none;
}
