/* Small, hand-written CSS overrides/additions that we want available on every page. */

/* Ensure the flow tab indicator can animate (slide) without covering labels.
   We do this by putting the tabbar snapshot above the indicator snapshot. */
::view-transition-group(root) {
  z-index: 0;
}

::view-transition-group(flow-panel-tabbar) {
  z-index: 2;
}

::view-transition-old(flow-panel-tabbar),
::view-transition-new(flow-panel-tabbar) {
  animation: none;
  opacity: 1;
}

::view-transition-group(flow-panel-tab-indicator) {
  z-index: 1;
  animation-duration: 240ms;
  animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

/* For the tab indicator we want spatial movement, not cross-fade. */
::view-transition-old(flow-panel-tab-indicator),
::view-transition-new(flow-panel-tab-indicator) {
  opacity: 1;
}

/* Generic "loading" affordance for Datastar @post actions.
   Pattern: set `el.classList.add('is-loading')` before @post; clear on morph re-render. */
.ds-loading-indicator {
  display: none;
}

.ds-loading-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: opacity 120ms ease;
}

.is-loading {
  pointer-events: none;
  opacity: 0.65;
}

.is-loading .ds-loading-label {
  opacity: 0;
}

.is-loading .ds-loading-indicator {
  display: inline-flex;
}

/* Overlay-only loading for link navigation (keeps content visible, dims it). */
.is-loading-overlay {
  pointer-events: none;
}

.is-loading-overlay .step-loading-content {
  opacity: 0.65;
}

.is-loading-overlay .ds-loading-indicator {
  display: flex;
}

/* Enhanced Resource UI navigation keeps the app shell mounted, so expose a
   central-panel loading affordance in place of the browser tab spinner. */
[data-resource-ui-content-scroll] {
  position: relative;
}

[data-resource-ui-content-scroll]::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 35;
  height: 2px;
  opacity: 0;
  pointer-events: none;
  transform: scaleX(0);
  transform-origin: left center;
  transition: opacity 120ms ease-out;
  background:
    linear-gradient(90deg,
      rgb(var(--color-primary) / 0) 0%,
      rgb(var(--color-primary) / 0.96) 18%,
      rgb(var(--color-link) / 1) 68%,
      rgb(var(--color-yellow) / 1) 100%);
  box-shadow: 0 1px 6px rgb(var(--color-primary) / 0.2);
}

body.breyta-resource-ui-navigating [data-resource-ui-content-scroll]::before {
  opacity: 1;
  animation: breyta-resource-ui-progress 1.25s cubic-bezier(0.22, 1, 0.36, 1) infinite;
}

body.breyta-resource-ui-navigating [data-resource-ui-content-scroll] > #main {
  opacity: 0.34;
  will-change: opacity;
}

[data-resource-ui-content-scroll] > #main {
  opacity: 1;
  transition: opacity 180ms ease-out;
}

[data-resource-ui-content-scroll] > #main[data-resource-ui-loading-reset="true"] {
  opacity: 1;
  will-change: auto;
}

@keyframes breyta-resource-ui-progress {
  0% {
    opacity: 0;
    transform: translateX(-20%) scaleX(0);
  }

  18% {
    opacity: 1;
  }

  58% {
    opacity: 1;
    transform: translateX(0) scaleX(0.72);
  }

  100% {
    opacity: 0;
    transform: translateX(72%) scaleX(0.28);
  }
}

/* Artifact sidepeek fullscreen transition: smooth expansion in-place. */
.agent-panel-resize-handle,
.agent-panel-desktop-only,
.agent-panel-desktop-content,
.app-sidebar-desktop,
.sidepeek-resize-handle,
.sidepeek-desktop-only {
  display: none;
}

.agent-panel-mobile-root,
.agent-panel-mobile-shell,
.resource-mobile-menu-root,
.resource-mobile-menu-trigger,
.resource-mobile-notifications-trigger,
.resource-mobile-notifications-sheet,
.sidepeek-mobile-root,
.sidepeek-mobile-shell {
  display: block;
}

.resource-ui-shell {
  padding-left: 0;
}

/* Panel transitions are applied on-demand by __breytaPanelTransition()
   so panels don't animate on page navigation/reload. */

#sidepeek-panel-container.sidepeek-panel-shell.sidepeek-artifact-fullscreen {
  width: calc(100dvw - 4rem) !important;
  max-width: calc(100dvw - 4rem);
  margin-left: 0 !important;
}

#agent-panel-container.agent-panel-shell.agent-panel-fullscreen {
  width: calc(100dvw - 4rem) !important;
  max-width: calc(100dvw - 4rem);
  margin-left: 0 !important;
}

#agent-panel-container.agent-panel-shell.agent-panel-fullscreen .agent-panel-content {
  width: 100%;
}

#sidepeek-panel-container.sidepeek-panel-shell.sidepeek-artifact-fullscreen .sidepeek-panel-content {
  width: 100%;
}

.artifact-panel-shell {
  transition-property: opacity, transform;
  transition-duration: 240ms;
  transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
  opacity: 0.98;
  transform: translateX(0.125rem);
}

.artifact-panel-shell.artifact-panel-fullscreen {
  opacity: 1;
  transform: translateX(0);
}

.artifact-panel-shell.artifact-panel-fullscreen .artifact-output-content {
  padding-left: 2rem;
  padding-right: 2rem;
}

.artifact-output-content > article {
  max-width: 64rem;
  margin-left: auto;
  margin-right: auto;
}

/* Sparkle button surface: warm peach → yellow gradient used by
   `button-icon-sparkle` / `:intent :sparkle`. Derived from the 194px figma
   export (peach #E0917B @ ~64%/69%, yellow #FFFC92 @ ~93%/122%). */
.btn-sparkle-surface {
  /* Warmer, more saturated base so the gradient reads punchy even at 40px. */
  background-color: #f7c9a4;
  background-image:
    radial-gradient(circle at 62% 66%, rgba(226, 132, 104, 1) 0%, rgba(226, 132, 104, 0.55) 45%, rgba(226, 132, 104, 0) 78%),
    radial-gradient(circle at 96% 120%, rgba(255, 236, 94, 1) 0%, rgba(255, 236, 94, 0.55) 45%, rgba(255, 236, 94, 0) 82%);
  background-repeat: no-repeat;
  transition: filter 160ms ease-out, box-shadow 160ms ease-out;
}

.btn-sparkle-surface:hover {
  filter: saturate(1.18) brightness(1.05);
}

.btn-sparkle-surface:active {
  filter: saturate(1.25) brightness(0.97);
}

@media (prefers-reduced-motion: no-preference) {
  [data-dropdown-menu-id] [data-dropdown-menu-item] {
    animation: breyta-dropdown-menu-item-in 180ms cubic-bezier(0.32, 0.72, 0, 1) both;
  }
}

@keyframes breyta-dropdown-menu-item-in {
  from {
    opacity: 0;
    transform: translateY(0.25rem);
  }

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

.breyta-table-row-selected {
  position: relative;
}

[data-table-scroll-root]:has(.breyta-table-row-selected) {
  overflow: visible;
}

[data-table-scroll-viewport]:has(.breyta-table-row-selected) {
  margin: -2px;
  padding: 2px;
}

[data-table-scroll-root]:has(.breyta-table-row-selected)
  [data-table-scroll-frame] > [data-table-scroll-left] {
  left: -2px;
}

[data-table-scroll-root]:has(.breyta-table-row-selected)
  [data-table-scroll-frame] > [data-table-scroll-right] {
  right: -2px;
}

.breyta-table-row-selected::after {
  content: "";
  position: absolute;
  inset: -2px;
  z-index: 20;
  pointer-events: none;
  border: 2px solid rgb(var(--color-link) / 1);
  border-radius: 0.375rem;
}

.breyta-streaming-cursor::after {
  content: "";
  display: inline-block;
  width: 0.38em;
  height: 1em;
  margin-left: 0.12em;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.42;
  transform: translateY(0.12em);
  animation: breyta-streaming-cursor-pulse 1s ease-in-out infinite;
}

@keyframes breyta-streaming-cursor-pulse {
  0%,
  100% {
    opacity: 0.22;
  }

  50% {
    opacity: 0.62;
  }
}

@media (min-width: 768px) {
  .agent-panel-resize-handle,
  .agent-panel-desktop-only,
  .app-sidebar-desktop,
  .sidepeek-resize-handle,
  .sidepeek-desktop-only {
    display: block;
  }

  .agent-panel-desktop-content {
    display: flex;
  }

  .agent-panel-mobile-root,
  .agent-panel-mobile-shell,
  .resource-mobile-menu-root,
  .resource-mobile-menu-trigger,
  .resource-mobile-notifications-trigger,
  .resource-mobile-notifications-sheet,
  .sidepeek-mobile-root,
  .sidepeek-mobile-shell {
    display: none;
  }

  .resource-ui-shell {
    padding-left: 4rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.breyta-resource-ui-navigating [data-resource-ui-content-scroll]::before,
  [data-resource-ui-content-scroll] > #main,
  #agent-panel-container.agent-panel-shell,
  #agent-panel-container.agent-panel-shell .agent-panel-content,
  #sidepeek-panel-container.sidepeek-panel-shell,
  #sidepeek-panel-container.sidepeek-panel-shell .sidepeek-panel-content,
  .artifact-panel-shell,
  .breyta-streaming-cursor::after {
    transition-duration: 0ms !important;
    animation-duration: 0ms !important;
  }

  body.breyta-resource-ui-navigating [data-resource-ui-content-scroll] > #main {
    opacity: 1;
  }
}

/* Dark mode: disabled dropdown items should read clearly as inactive. */
[data-theme="dark"] [data-dropdown-menu-item][aria-disabled="true"] {
  opacity: 0.3;
}
