/**
 * Action Bar Component
 *
 * Combines breadcrumb navigation with page actions (like Share)
 * Layout: Breadcrumbs (left) | Actions (right)
 */

/* ============================================================================
   Main Container
   ============================================================================ */

.action-bar-container {
  margin-bottom: var(--space-6);
  margin-inline: auto;
  width: 100%;
  max-width: var(--prose-width);
}

/* Align action bar with prose content inside docs-main */
.docs-main .action-bar-container {
  max-width: var(--content-width, 75ch);
}

/* Action bar inside tag-page/tags-page containers inherits container width */
.tag-page .action-bar-container,
.tags-page .action-bar-container {
  max-width: 100%;
}

.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-2) var(--space-4);
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  min-height: 40px;
  width: 100%;
  box-sizing: border-box;
  position: relative;
  /* Use visible overflow to allow dropdown to extend beyond container */
  /* Blobs are clipped via border-radius on the container itself */
  overflow: visible;
  /* Ensure proper stacking context for dropdown */
  isolation: isolate;
}

/* Blob background animation for action bar - optimized for horizontal bar layout */
/* Left blob */
.action-bar::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 10%;
  transform: translateY(-50%);
  width: 120px;
  height: 120px;
  background: radial-gradient(circle,
      color-mix(in srgb, var(--blob-color-1) 10%, transparent) 0%,
      color-mix(in srgb, var(--blob-color-2) 6%, transparent) 40%,
      transparent 70%);
  border-radius: 50%;
  filter: blur(20px);
  animation: actionBarBlobLeft 8s ease-in-out infinite;
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
  transition: opacity 0.3s ease;
  /* Clip blob to action bar border-radius while allowing dropdown overflow */
  clip-path: inset(0 round var(--radius-lg));
}

/* Right blob */
.action-bar::after {
  content: '';
  position: absolute;
  top: 50%;
  right: 15%;
  transform: translateY(-50%);
  width: 100px;
  height: 100px;
  background: radial-gradient(circle,
      color-mix(in srgb, var(--blob-color-2) 9%, transparent) 0%,
      color-mix(in srgb, var(--blob-color-3) 5%, transparent) 35%,
      transparent 65%);
  border-radius: 50%;
  filter: blur(18px);
  animation: actionBarBlobRight 7s ease-in-out infinite;
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
  transition: opacity 0.3s ease;
  /* Clip blob to action bar border-radius while allowing dropdown overflow */
  clip-path: inset(0 round var(--radius-lg));
}

.action-bar:hover::before,
.action-bar:hover::after {
  opacity: 0.8;
}

.action-bar>* {
  position: relative;
  z-index: 1;
}

/* Horizontal bar blob animations - subtle horizontal movement */
@keyframes actionBarBlobLeft {
  0%,
  100% {
    transform: translateY(-50%) translateX(0) scale(1);
  }
  33% {
    transform: translateY(-50%) translateX(15px) scale(1.1);
  }
  66% {
    transform: translateY(-50%) translateX(-10px) scale(0.9);
  }
}

@keyframes actionBarBlobRight {
  0%,
  100% {
    transform: translateY(-50%) translateX(0) scale(1);
  }
  33% {
    transform: translateY(-50%) translateX(-12px) scale(1.08);
  }
  66% {
    transform: translateY(-50%) translateX(8px) scale(0.92);
  }
}

/* Fallback for browsers without color-mix */
@supports not (color: color-mix(in srgb, black, white)) {
  .action-bar::before {
    background: radial-gradient(circle,
        rgba(59, 130, 246, 0.1) 0%,
        rgba(76, 175, 80, 0.06) 40%,
        transparent 70%);
  }

  .action-bar::after {
    background: radial-gradient(circle,
        rgba(76, 175, 80, 0.09) 0%,
        rgba(255, 152, 0, 0.05) 35%,
        transparent 65%);
  }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .action-bar::before,
  .action-bar::after {
    animation: none !important;
  }
}

/* ============================================================================
   Breadcrumbs (Left Side)
   ============================================================================ */

.action-bar-nav {
  flex: 1;
  min-width: 0;
  /* Allow text truncation */
}

.action-bar-breadcrumbs {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  list-style: none;
  padding: 0;
  margin: 0;
  flex-wrap: wrap;
}

.action-bar-breadcrumbs li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: var(--weight-light);
  color: var(--color-text-secondary);
  min-width: 0;
  /* Allow flex children to shrink */
  flex-shrink: 1;
  /* Allow items to shrink if needed */
}

/* Separator (›) */
.action-bar-breadcrumbs li:not(:last-child)::after {
  content: '›';
  color: var(--color-text-tertiary);
  font-size: 1rem;
  opacity: 0.5;
}

.action-bar-breadcrumb-link {
  color: var(--color-text-secondary);
  font-weight: var(--weight-light);
  text-decoration: none;
  transition: color 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
  /* Prevent super long breadcrumbs */
}

.action-bar-breadcrumb-link:hover {
  color: var(--color-primary);
}

.action-bar-breadcrumb-current-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  min-width: 0;
  /* Allow truncation */
}

.action-bar-breadcrumb-current {
  color: var(--color-text-primary);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 250px;
  /* Slightly longer for current page */
}

/* Metadata Toggle Button - Compact neumorphic style matching nav buttons */
.action-bar-meta-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.375rem;
  max-width: 1.375rem;
  height: 1.375rem;
  padding: 0;
  background: linear-gradient(180deg,
      var(--color-surface, var(--color-bg-elevated)),
      var(--color-bg-secondary));
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-medium, 6px);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast, 0.15s);
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: var(--neumorphic-subtle);
}

.action-bar-meta-toggle:hover {
  color: var(--color-text-primary);
  box-shadow: var(--neumorphic-hover);
  transform: translateY(-1px);
}

.action-bar-meta-toggle:active {
  box-shadow: var(--neumorphic-subtle-pressed);
  transform: translateY(0) scale(0.98);
}

/* Dark mode inherits via CSS variables - no explicit overrides needed */

.action-bar-meta-toggle-icon {
  transition: transform 0.15s ease;
  width: var(--icon-size-sm);
  height: var(--icon-size-sm);
  flex-shrink: 0;
  display: block;
}

.action-bar-meta-toggle[aria-expanded="true"] .action-bar-meta-toggle-icon {
  transform: rotate(180deg);
}

/* ============================================================================
   Expandable Metadata Panel
   ============================================================================ */

.action-bar-metadata {
  display: none;
  margin-top: 0.5rem;
  padding: 0.625rem 1rem;
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  animation: slideDown 0.2s ease;
}

.action-bar-metadata[aria-hidden="false"] {
  display: block;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }

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

.action-bar-metadata-content {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  align-items: center;
}

.action-bar-meta-item {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.action-bar-meta-item svg {
  flex-shrink: 0;
  opacity: 0.5;
  width: var(--icon-size-sm);
  height: var(--icon-size-sm);
  display: block;
}

/* ============================================================================
   Actions (Right Side)
   ============================================================================ */

.action-bar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

/* ============================================================================
   Share Button
   ============================================================================ */

.action-bar-share {
  position: relative;
}

.action-bar-share-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.5rem 0.25rem 0.375rem;
  background: linear-gradient(180deg,
      var(--color-surface, var(--color-bg-elevated)),
      var(--color-bg-secondary));
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-medium, 6px);
  color: var(--color-text-secondary);
  font-size: var(--text-xs, 0.75rem);
  font-weight: var(--weight-medium, 500);
  cursor: pointer;
  transition: all var(--transition-fast, 0.15s);
  white-space: nowrap;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow: var(--neumorphic-subtle);
}

.action-bar-share-trigger:hover {
  color: var(--color-text-primary);
  box-shadow: var(--neumorphic-hover);
  transform: translateY(-1px);
}

.action-bar-share-trigger:active {
  box-shadow: var(--neumorphic-subtle-pressed);
  transform: translateY(0) scale(0.92);
  transition: transform 0.1s ease-out, box-shadow 0.1s ease-out;
}

/* Satisfying spring-back on release */
.action-bar-share-trigger:not(:active) {
  transition: all var(--transition-fast, 0.15s),
              transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.action-bar-share-trigger svg {
  flex-shrink: 0;
  width: var(--icon-size-sm, 14px);
  height: var(--icon-size-sm, 14px);
  display: block;
  opacity: 0.7;
}

.action-bar-share-trigger:hover svg {
  opacity: 1;
}

/* Responsive Bengal cat symbol */
.action-bar-share-trigger>span:first-child {
  font-size: var(--icon-size-sm, 14px);
  line-height: 1;
  flex-shrink: 0;
}

.action-bar-share-chevron {
  width: var(--icon-size-xs, 12px);
  height: var(--icon-size-xs, 12px);
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.action-bar-share-trigger[aria-expanded="true"] {
  color: var(--color-primary);
  box-shadow: var(--neumorphic-hover);
}

/* Ensure SVG icon stays visible when expanded */
.action-bar-share-trigger[aria-expanded="true"] svg {
  stroke: var(--color-text-primary);
  color: var(--color-text-primary);
}

.action-bar-share-trigger[aria-expanded="true"] .action-bar-share-chevron {
  transform: rotate(180deg);
}

/* ============================================================================
   Share Dropdown - POPOVER PATTERN
   See: assets/COMPONENT-PATTERNS.md

   - Element: <div id="..." popover class="*--popover">
   - Browser handles: show/hide, light dismiss, escape key, top layer
   - JS handles: Copy actions, AI share functionality
   - Suffix: --popover indicates this pattern
   ============================================================================ */

.action-bar-share-dropdown--popover {
  /* Reset popover defaults */
  margin: 0;
  padding: 0;
  border: none;

  /* Fixed positioning - top layer handles stacking */
  position: fixed;
  inset: unset;

  /* Appearance */
  min-width: 240px;
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.12),
    0 1px 3px rgba(0, 0, 0, 0.08);

  /* Hidden by default */
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.15s ease, transform 0.15s ease,
              display 0.15s allow-discrete, overlay 0.15s allow-discrete;
}

/* Open state - visible */
.action-bar-share-dropdown--popover:popover-open {
  opacity: 1;
  transform: translateY(0);
}

/* Entry animation starting point */
@starting-style {
  .action-bar-share-dropdown--popover:popover-open {
    opacity: 0;
    transform: translateY(-8px);
  }
}

/* Dark mode popover */
[data-theme="dark"] .action-bar-share-dropdown--popover {
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.3),
    0 1px 3px rgba(0, 0, 0, 0.2);
}

/* ============================================================================
   Metadata Panel - POPOVER PATTERN
   ============================================================================ */

.action-bar-metadata--popover {
  /* Reset popover defaults */
  margin: 0;
  padding: 0;
  border: none;

  /* Fixed positioning - JS sets exact position relative to trigger */
  position: fixed;
  inset: unset;

  /* Appearance */
  padding: 0.625rem 1rem;
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.12),
    0 1px 3px rgba(0, 0, 0, 0.08);

  /* Hidden by default */
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.15s ease, transform 0.15s ease,
              display 0.15s allow-discrete, overlay 0.15s allow-discrete;
}

/* Open state - visible */
.action-bar-metadata--popover:popover-open {
  opacity: 1;
  transform: translateY(0);
}

/* Entry animation starting point */
@starting-style {
  .action-bar-metadata--popover:popover-open {
    opacity: 0;
    transform: translateY(-8px);
  }
}

/* Dark mode popover */
[data-theme="dark"] .action-bar-metadata--popover {
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.3),
    0 1px 3px rgba(0, 0, 0, 0.2);
}

/* Reduced motion - no animations */
@media (prefers-reduced-motion: reduce) {
  .action-bar-share-dropdown--popover,
  .action-bar-metadata--popover {
    transition: none;
  }

  @starting-style {
    .action-bar-share-dropdown--popover:popover-open,
    .action-bar-metadata--popover:popover-open {
      opacity: 1;
      transform: none;
    }
  }

  /* Disable micro-interaction animations */
  .action-bar-share-trigger:active,
  .action-bar-share-trigger:not(:active),
  .action-bar-share-item.success,
  .action-bar-share-item.success svg {
    animation: none !important;
    transition: none !important;
  }
}

.action-bar-share-content {
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

/* ============================================================================
   Dropdown Menu Items
   ============================================================================ */

.action-bar-share-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  background: transparent;
  border: none;
  border-radius: var(--radius-lg);
  color: var(--color-text-primary);
  font-size: 0.875rem;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease;
  width: 100%;
  text-align: left;
}

.action-bar-share-item:hover {
  background: var(--color-bg-secondary);
}

.action-bar-share-item:active {
  background: var(--color-bg-tertiary);
}

.action-bar-share-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
}

/* Removed flex: 1 from span to keep SVG icons close to text */

/* AI Links - with brand colors */
.action-bar-share-ai svg {
  opacity: 1;
}

.action-bar-share-ai[data-ai="claude"]:hover {
  background: rgba(168, 122, 80, 0.1);
  color: var(--color-primary);
}

.action-bar-share-ai[data-ai="chatgpt"]:hover {
  background: rgba(116, 195, 194, 0.1);
  color: #74c3c2;
}

.action-bar-share-ai[data-ai="gemini"]:hover {
  background: rgba(138, 180, 248, 0.1);
  color: #8ab4f8;
}

.action-bar-share-ai[data-ai="copilot"]:hover {
  background: rgba(66, 153, 225, 0.1);
  color: #4299e1;
}

/* ============================================================================
   Dropdown Decorations
   ============================================================================ */

.action-bar-share-separator {
  margin: 0.5rem 0;
  border: none;
  border-top: 1px solid var(--color-border);
}

.action-bar-share-section-header {
  padding: 0.5rem 0.75rem 0.25rem;
  font-size: 0.75rem;
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
}

/* Success feedback with satisfying burst */
.action-bar-share-item.success {
  background: var(--color-success-bg, rgba(34, 197, 94, 0.1));
  color: var(--color-success, #22c55e);
  animation: success-item-burst 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
}

.action-bar-share-item.success svg {
  opacity: 1;
  animation: checkmark-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes success-item-burst {
  0% { transform: scale(1); }
  20% { transform: scale(0.95); }
  40% { transform: scale(1.05); }
  60% { transform: scale(0.98); }
  100% { transform: scale(1); }
}

@keyframes checkmark-pop {
  0% { transform: scale(1); }
  30% { transform: scale(1.3) rotate(-5deg); }
  60% { transform: scale(0.9) rotate(3deg); }
  100% { transform: scale(1) rotate(0deg); }
}

/* ============================================================================
   Dark Mode - Action Bar Share Components
   ============================================================================ */


@keyframes checkmark {

  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.1);
  }
}

/* Spinning animation for loading state */
@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.action-bar-share-item svg.spinning {
  animation: spin 1s linear infinite;
}

/* ============================================================================
   Responsive Design
   ============================================================================ */

/* Tablet and below (md breakpoint) */
@media (max-width: 768px) {
  .action-bar {
    padding: 0.5rem 0.875rem;
    gap: 0.75rem;
  }

  .action-bar-metadata {
    padding: 0.5rem 0.875rem;
  }

  .action-bar-breadcrumbs {
    font-size: 0.8125rem;
  }

  /* Shorter truncation on tablet */
  .action-bar-breadcrumb-link {
    max-width: 150px;
  }

  .action-bar-breadcrumb-current {
    max-width: 180px;
  }

  /* Hide middle breadcrumb items on small screens */
  .action-bar-breadcrumbs li:not(:first-child):not(:last-child) {
    display: none;
  }

  /* Add ellipsis after first item when items are hidden */
  .action-bar-breadcrumbs li:first-child:not(:last-child)::after {
    content: '›';
  }

  /* Icons automatically scale via --icon-size-md token */

  /* Slightly more compact buttons on tablet */
  .action-bar-share-trigger {
    padding: 0.1875rem 0.375rem;
    font-size: 0.6875rem;
  }

  .action-bar-meta-toggle {
    width: 1.25rem;
    min-width: 1.25rem;
    max-width: 1.25rem;
    height: 1.25rem;
    min-height: 1.25rem;
  }

  /* Icon automatically scales via --icon-size-sm token */

  /* Slightly smaller dropdown items on tablet */
  .action-bar-share-item {
    padding: 0.5625rem 0.6875rem;
    font-size: 0.8125rem;
  }

  .action-bar-share-item svg {
    width: 17px;
    height: 17px;
  }
}

/* Mobile - Keep items on same line with aggressive compression */
/* Using 639px to avoid overlap with 640px min-width queries (--breakpoint-sm) */
@media (max-width: 639px) {
  .action-bar {
    /* NO flex-wrap to prevent wrapping */
    padding: 0.375rem 0.75rem;
    gap: 0.5rem;
    min-height: auto;
    /* Let content determine height */
    align-items: center;
    /* Ensure vertical centering */
  }

  .action-bar-metadata {
    padding: 0.5rem 0.75rem;
  }

  .action-bar-metadata-content {
    gap: 0.875rem;
    font-size: 0.75rem;
  }

  /* Aggressive truncation on mobile but keep items inline */
  .action-bar-nav {
    flex: 1;
    min-width: 0;
    max-width: calc(100% - 80px);
    /* Reserve space for action button */
  }

  .action-bar-breadcrumb-link {
    max-width: 80px;
  }

  .action-bar-breadcrumb-current {
    max-width: 100px;
  }

  .action-bar-breadcrumbs {
    font-size: 0.75rem;
    gap: 0.375rem;
    /* Reduce gap between breadcrumb items on mobile */
  }

  /* Reduce gap within breadcrumb list items on mobile */
  .action-bar-breadcrumbs li {
    gap: 0.375rem;
    /* 6px instead of 8px - tighter spacing */
  }

  /* Reduce gap between breadcrumb text and meta toggle on mobile */
  .action-bar-breadcrumb-current-wrapper {
    gap: 0.1875rem;
    /* 3px - tighter spacing on mobile */
  }

  /* Compact the actions area */
  .action-bar-actions {
    flex-shrink: 0;
  }

  /* More compact share button on mobile */
  .action-bar-share-trigger {
    padding: 0.125rem 0.3125rem;
    font-size: 0.625rem;
    gap: 0.1875rem;
  }

  /* Smaller meta toggle button on mobile */
  .action-bar-meta-toggle {
    width: 1rem;
    min-width: 1rem;
    max-width: 1rem;
    height: 1rem;
    min-height: 1rem;
    border-radius: var(--radius-sm);
    overflow: hidden;
  }

  /* Icon automatically scales via --icon-size-sm token */

  /* Smaller dropdown items on mobile */
  .action-bar-share-item {
    padding: 0.5rem 0.625rem;
    font-size: 0.8125rem;
    gap: 0.625rem;
  }

  /* Smaller dropdown item icons on mobile */
  .action-bar-share-item svg {
    width: 16px;
    height: 16px;
  }

  /* Smaller dropdown section headers on mobile */
  .action-bar-share-section-header {
    padding: 0.375rem 0.625rem 0.25rem;
    font-size: 0.6875rem;
  }

  /* Metadata item icons automatically scale via --icon-size-sm token */

  /* Position dropdown relative to right edge on mobile */
  .action-bar-share-dropdown {
    right: 0;
    min-width: max(200px, 75vw);
    max-width: 90vw;
  }
}

/* Very Small Mobile - Stack only when absolutely necessary */
/* Using --breakpoint-xxs (400px) -> apply at 399px to avoid overlap */
@media (max-width: 399px) {
  .action-bar {
    flex-wrap: wrap;
    gap: 0.625rem;
  }

  /* Allow nav to take full width when stacked */
  .action-bar-nav {
    flex: 1 1 100%;
    max-width: 100%;
  }

  .action-bar-actions {
    flex: 1 1 100%;
    justify-content: flex-end;
  }

  /* More aggressive truncation for XXS screens */
  .action-bar-breadcrumb-link {
    max-width: 60px;
    /* Reduced from 80px */
  }

  .action-bar-breadcrumb-current {
    max-width: 80px;
    /* Reduced from 100px */
  }

  /* Center dropdown on very small screens */
  .action-bar-share-dropdown {
    right: auto;
    left: 50%;
    /* Use translate3d for hardware acceleration in Safari */
    transform: translate3d(-50%, -10px, 0);
    min-width: 280px;
    max-width: 90vw;
  }

  .action-bar-share-dropdown[aria-hidden="false"] {
    transform: translate3d(-50%, 0, 0);
  }
}

/* ============================================================================
   Focus & Accessibility
   ============================================================================ */

.action-bar-share-trigger:focus-visible,
.action-bar-share-item:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ============================================================================
   Dark Mode Adjustments
   ============================================================================ */

@media (prefers-color-scheme: dark) {
  .action-bar-share-dropdown {
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3);
  }
}
