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

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

.action-bar-container {
  margin-bottom: 1.5rem;
  width: 100%;
  max-width: var(--prose-width);
}

.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 1rem;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-md);
  min-height: 40px;
  width: 100%;
  box-sizing: border-box;
}

/* ============================================================================
   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;
  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);
  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: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 250px;
  /* Slightly longer for current page */
}

/* Metadata Toggle Button */
.action-bar-meta-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.125rem;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-sm);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.action-bar-meta-toggle:hover {
  background: var(--color-bg-tertiary);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.action-bar-meta-toggle-icon {
  transition: transform 0.15s ease;
}

.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(--border-radius-md);
  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;
}

/* ============================================================================
   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.5rem;
  padding: 0.375rem 0.75rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-md);
  color: var(--color-text-primary);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.action-bar-share-trigger:hover {
  background: var(--color-bg-tertiary);
  border-color: var(--color-primary);
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.action-bar-share-trigger:active {
  transform: translateY(0);
}

.action-bar-share-trigger svg {
  flex-shrink: 0;
}

.action-bar-share-chevron {
  transition: transform 0.15s ease;
}

.action-bar-share-trigger[aria-expanded="true"] {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

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

/* ============================================================================
   Share Dropdown
   ============================================================================ */

.action-bar-share-dropdown {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  min-width: 240px;
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-md);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.04);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
  z-index: 1000;
}

.action-bar-share-dropdown[aria-hidden="false"] {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.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(--border-radius-md);
  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;
}

.action-bar-share-item span {
  flex: 1;
}

/* 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: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
}

/* Success feedback */
.action-bar-share-item.success {
  background: var(--color-success-bg, rgba(34, 197, 94, 0.1));
  color: var(--color-success, #22c55e);
}

.action-bar-share-item.success svg {
  opacity: 1;
  animation: checkmark 0.3s ease;
}

@keyframes checkmark {

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

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

/* ============================================================================
   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: '›';
  }
}

/* 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.5rem 0.75rem;
    gap: 0.5rem;
  }

  .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;
  }

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

  /* More compact share button on mobile */
  .action-bar-share-trigger {
    padding: 0.375rem 0.5rem;
    font-size: 0.75rem;
    gap: 0.375rem;
  }

  /* Position dropdown relative to right edge on mobile */
  .action-bar-share-dropdown {
    right: 0;
    min-width: max(240px, 80vw);
    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;
  }

  /* Center dropdown on very small screens */
  .action-bar-share-dropdown {
    right: auto;
    left: 50%;
    transform: translateX(-50%) translateY(-10px);
    min-width: 280px;
    max-width: 90vw;
  }

  .action-bar-share-dropdown[aria-hidden="false"] {
    transform: translateX(-50%) translateY(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);
  }
}