/**
 * Tabs Component CSS
 * Simplified and Robust
 *
 * NOTE: Directive base CSS (bengal/assets/css/directives/tabs.css) provides
 * functional styles: show/hide panes, list resets, accessibility.
 * This file provides aesthetic styles: layout, colors, animations.
 *
 * The !important declarations below are kept for extra safety against
 * prose contamination from markdown containers.
 */

/* Container */
.tabs {
  position: relative;
  margin: var(--space-6) 0;
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  background-color: var(--color-bg-primary);
  overflow: visible;
  /* Allow tooltips to overflow */
}

/* Clip navigation to border-radius while allowing tooltips to overflow */
.tabs>.tab-nav {
  overflow: hidden;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

/* Allow tab-content to overflow for tooltips - individual elements handle their own clipping */
.tabs>.tab-content {
  overflow: visible;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.tabs.gradient-border {
  border: none;
}

/* Navigation - layout and aesthetics
 * Note: list-style/margin/padding resets are in base CSS, but we keep !important
 * here for extra safety against prose container contamination */
.tab-nav {
  display: flex !important;
  flex-wrap: wrap;
  align-items: center;
  list-style: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border-bottom: 1px solid var(--color-border-light);
  background-color: var(--color-bg-secondary);
}

/* Extra prose contamination safety (base CSS handles basic reset) */
.prose .tab-nav,
.prose .tab-nav li {
  list-style: none !important;
  margin: 0 !important;
  padding: 0 !important;
}

.tab-nav li {
  margin: 0 !important;
  padding: 0 !important;
  list-style: none !important;
}

.tab-nav a {
  display: block;
  padding: var(--space-2) var(--space-3);
  color: var(--color-text-tertiary);
  text-decoration: none;
  font-weight: var(--weight-medium);
  font-size: var(--text-sm);
  border-bottom: 2px solid transparent;
  transition: all var(--transition-fast) var(--ease-out);
  cursor: pointer;
}

.tab-nav a:hover {
  color: var(--color-text-primary);
  background-color: var(--color-bg-hover);
}

.tab-nav li.active a {
  color: var(--color-primary);
  border-bottom-color: transparent;
  background-color: var(--color-primary-light);
  font-weight: var(--weight-semibold);
  position: relative;
}

/* Glowing bottom edge for active tab */
.tab-nav li.active a::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg,
      color-mix(in srgb, var(--color-primary) 40%, transparent) 0%,
      var(--color-primary) 50%,
      color-mix(in srgb, var(--color-primary) 40%, transparent) 100%);
  animation: tab-accent-glow 8s ease-in-out infinite;
}

@keyframes tab-accent-glow {

  0%,
  100% {
    box-shadow: 0 2px 8px 0 color-mix(in srgb, var(--color-primary) 10%, transparent);
  }

  50% {
    box-shadow: 0 3px 15px 0 color-mix(in srgb, var(--color-primary) 25%, transparent);
  }
}

[data-theme="dark"] .tab-nav li.active a::after {
  animation: tab-accent-glow-dark 8s ease-in-out infinite;
}

@keyframes tab-accent-glow-dark {

  0%,
  100% {
    box-shadow: 0 2px 10px 0 color-mix(in srgb, var(--color-primary) 15%, transparent);
  }

  50% {
    box-shadow: 0 4px 20px 0 color-mix(in srgb, var(--color-primary) 35%, transparent);
  }
}

/* Content */
.tab-content {
  padding: var(--space-4);
}

/* Tab pane show/hide is handled by base CSS.
 * This adds aesthetic animation on top. */
.tab-pane.active {
  animation: tabFadeIn var(--duration-200) var(--ease-out);
}

@keyframes tabFadeIn {
  from {
    opacity: 0;
    transform: translateY(var(--space-1));
  }

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

/* Code Tabs Variant */
.code-tabs {
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  margin: var(--space-6) 0;
}

.code-tabs .tab-nav {
  background-color: transparent;
  padding: 0 var(--space-2);
}

.code-tabs .tab-nav a {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
}

.code-tabs .tab-content {
  padding: 0;
}

.code-tabs .tab-pane pre {
  margin: 0;
  border: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

/* Dark Mode */
[data-theme="dark"] .tabs,
[data-theme="dark"] .code-tabs {
  border-color: var(--color-border-dark);
}

[data-theme="dark"] .tab-nav {
  border-bottom-color: var(--color-border-dark);
  background-color: var(--color-bg-secondary);
}

[data-theme="dark"] .tab-nav li.active a {
  background-color: var(--color-primary-light);
  border-bottom-width: 3px;
}

[data-theme="dark"] .tab-nav a:hover {
  background-color: var(--color-bg-hover);
}

/* ============================================
   PALETTE-SPECIFIC ACTIVE TAB STYLING
   ============================================ */

/* Brown Bengal - Warm amber active tabs */
[data-palette="brown-bengal"] .tab-nav li.active a {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  border-bottom-width: 3px;
  background-color: var(--color-primary-light);
}

[data-theme="dark"][data-palette="brown-bengal"] .tab-nav li.active a {
  background-color: var(--color-primary-light);
  border-bottom-width: 3px;
}

/* Blue Bengal - Soft powder blue active tabs */
[data-palette="blue-bengal"] .tab-nav li.active a {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  border-bottom-width: 3px;
  background-color: var(--color-primary-light);
}

[data-theme="dark"][data-palette="blue-bengal"] .tab-nav li.active a {
  background-color: var(--color-primary-light);
  border-bottom-width: 3px;
}

/* Silver Bengal - High contrast monochrome active tabs */
[data-palette="silver-bengal"] .tab-nav li.active a {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  border-bottom-width: 3px;
  background-color: var(--color-primary-light);
}

[data-theme="dark"][data-palette="silver-bengal"] .tab-nav li.active a {
  background-color: var(--color-primary-light);
  border-bottom-width: 3px;
}

/* Charcoal Bengal - Dramatic slate active tabs */
[data-palette="charcoal-bengal"] .tab-nav li.active a {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  border-bottom-width: 3px;
  background-color: var(--color-primary-light);
}

[data-theme="dark"][data-palette="charcoal-bengal"] .tab-nav li.active a {
  background-color: var(--color-primary-light);
  border-bottom-width: 3px;
}

/* ==============================================
   TAB ICONS, BADGES, AND DISABLED STATE
   ============================================== */

/* Tab Icon */
.tab-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: var(--space-1);
  font-size: 1em;
  opacity: 0.75;
  vertical-align: middle;
}

.tab-icon svg {
  width: 1em;
  height: 1em;
}

.tab-nav li.active .tab-icon {
  opacity: 1;
}

/* Tab Badge */
.tab-badge {
  display: inline-flex;
  align-items: center;
  margin-left: var(--space-1);
  padding: 0.0625rem 0.375rem;
  font-size: 0.625rem;
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--color-text-inverse);
  background: var(--color-primary);
  border-radius: var(--radius-full);
  vertical-align: middle;
}

/* Badge color variants */
.tab-badge[data-variant="new"],
.tab-badge:has-text("New") {
  background: var(--color-success);
}

.tab-badge[data-variant="beta"] {
  background: var(--color-warning);
  color: var(--color-text-primary);
}

.tab-badge[data-variant="pro"] {
  background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
}

/* Disabled Tab */
.tab-nav li.disabled a {
  color: var(--color-text-disabled);
  cursor: not-allowed;
  pointer-events: none;
  opacity: 0.5;
}

.tab-nav li.disabled a:hover {
  background-color: transparent;
  color: var(--color-text-disabled);
}

.tab-nav li.disabled .tab-icon {
  opacity: 0.3;
}

.tab-nav li.disabled .tab-badge {
  background: var(--color-text-disabled);
}

/* Dark mode adjustments */
[data-theme="dark"] .tab-badge {
  color: var(--color-text-inverse);
}

[data-theme="dark"] .tab-nav li.disabled a {
  color: var(--color-text-disabled);
}

/* ==============================================
   CODE TABS ENHANCED (RFC: Enhanced Code Tabs)
   - Language icons
   - Filename badges
   - Copy button per pane
   - Pygments integration
   ============================================== */

/* Tab Label - language name */
.code-tabs .tab-label {
  font-weight: var(--weight-medium);
}

/* Tab Filename Badge */
.code-tabs .tab-filename {
  display: inline-flex;
  align-items: center;
  margin-left: var(--space-2);
  padding: 0.125rem 0.5rem;
  font-size: var(--text-xxs);
  font-family: var(--font-mono);
  font-weight: var(--weight-normal);
  color: var(--color-text-muted);
  background: var(--color-bg-tertiary);
  border-radius: var(--radius-sm);
  opacity: 0.85;
}

.tab-nav li.active .tab-filename {
  color: var(--color-text-secondary);
  background: color-mix(in srgb, var(--color-primary) 15%, transparent);
  opacity: 1;
}

[data-theme="dark"] .code-tabs .tab-filename {
  background: var(--color-bg-tertiary);
}

[data-theme="dark"] .tab-nav li.active .tab-filename {
  background: color-mix(in srgb, var(--color-primary) 20%, transparent);
}

/* Tab link with icon and filename layout */
.code-tabs .tab-nav a {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

/* Tab icon positioning within code-tabs */
.code-tabs .tab-icon {
  margin-right: 0;
  flex-shrink: 0;
}

.code-tabs .tab-icon .bengal-icon {
  display: block;
}

/* Code Toolbar (contains copy button) */
.code-tabs .code-toolbar {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  z-index: 10;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.code-tabs .tab-pane:hover .code-toolbar,
.code-tabs .tab-pane:focus-within .code-toolbar {
  opacity: 1;
}

/* Copy Button in code-tabs */
.code-tabs .copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--space-8);
  height: var(--space-8);
  padding: 0;
  color: var(--color-text-secondary);
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.code-tabs .copy-btn:hover {
  color: var(--color-text-primary);
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.3);
}

.code-tabs .copy-btn:active {
  transform: scale(0.95);
}

.code-tabs .copy-btn.copied {
  color: var(--color-success);
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.3);
}

/* Dark mode copy button */
[data-theme="dark"] .code-tabs .copy-btn {
  background: rgba(0, 0, 0, 0.2);
  border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .code-tabs .copy-btn:hover {
  background: rgba(0, 0, 0, 0.3);
  border-color: rgba(255, 255, 255, 0.2);
}

/* Copy icon sizing */
.code-tabs .copy-icon {
  width: 16px;
  height: 16px;
}

/* Visually hidden but accessible */
.code-tabs .visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Tab pane with relative positioning for copy button */
.code-tabs .tab-pane {
  position: relative;
}

/* Reset Pygments styles within code-tabs */
.code-tabs .tab-pane .highlight,
.code-tabs .tab-pane pre {
  margin: 0;
  border: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  box-shadow: none;
  animation: none;
}

.code-tabs .tab-pane .highlighttable {
  margin: 0;
  border: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  box-shadow: none;
  animation: none;
}

/* Sync indicator (visual feedback when tabs sync) */
.code-tabs[data-sync] .tab-nav li.active a {
  position: relative;
}

/* Mobile adjustments */
@media (max-width: 639px) {
  .code-tabs .tab-filename {
    display: none;
  }

  .code-tabs .tab-nav a {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-xs);
  }

  .code-tabs .code-toolbar {
    opacity: 1;
  }
}

/* Reduced motion - base CSS handles this, but keep for code-tabs specific */
@media (prefers-reduced-motion: reduce) {
  .code-tabs .tab-nav li.active a::after {
    animation: none;
  }
}
