/* Material Design 3 Tab Component
 * ==========================================================================
 * MD3 Tabs organize content across different screens and views
 * Reference: https://m3.material.io/components/tabs
 */

/* Tab Container
 * -------------------------------------------------------------------------- */

.tabs-container {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.tabs {
  position: relative;
  width: 100%;
  background: var(--color-bg--surface);
}

/* Tab Bar
 * -------------------------------------------------------------------------- */

.tabs__bar {
  display: flex;
  position: relative;
  width: 100%;
  min-height: 48px;
  align-items: center;
  border-bottom: 1px solid var(--color-border--light);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

/* Hide scrollbar but keep functionality */
.tabs__bar::-webkit-scrollbar {
  display: none;
}

.tabs--scrollable .tabs__bar {
  scrollbar-width: auto;
}

.tabs--scrollable .tabs__bar::-webkit-scrollbar {
  display: block;
  height: 4px;
}

.tabs--scrollable .tabs__bar::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 2px;
}

/* Center tabs */
.tabs--centered .tabs__bar {
  justify-content: center;
}

/* Tab Item
 * -------------------------------------------------------------------------- */

.tabs__item {
  /* Structure */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  position: relative;
  flex-shrink: 0;

  /* Sizing */
  min-height: 48px;
  padding: 0 1.5rem;
  min-width: 90px;

  /* Typography */
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.25;
  white-space: nowrap;

  /* Appearance */
  background: transparent;
  border: none;
  color: var(--color-ink--surface);
  opacity: 0.7;
  cursor: pointer;

  /* Interaction */
  transition: all 200ms cubic-bezier(0.4, 0, 0.2, 1);
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

/* Tab states */
.tabs__item:hover:not(:disabled) {
  opacity: 0.9;
  background: oklch(0 0 0 / 0.04);
}

.tabs__item:active:not(:disabled) {
  background: oklch(0 0 0 / 0.08);
}

.tabs__item:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
}

.tabs__item--selected {
  opacity: 1;
  color: var(--color-primary);
}

.tabs__item--disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

/* Tab indicator (underline) */
.tabs__item::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--color-primary);
  border-radius: 3px 3px 0 0;
  transform: scaleX(0);
  transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

.tabs__item--selected::after {
  transform: scaleX(1);
}

/* Tab elements
 * -------------------------------------------------------------------------- */

.tabs__icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}

.tabs__label {
  flex-shrink: 0;
}

/* Tab with badge */
.tabs__item .badge {
  margin-left: 0.25rem;
}

/* Secondary variant (pill style)
 * -------------------------------------------------------------------------- */

.tabs--secondary .tabs__bar {
  padding: 0.25rem;
  gap: 0.25rem;
  border-bottom: none;
  background: var(--color-bg--container);
  border-radius: 12px;
}

.tabs--secondary .tabs__item {
  border-radius: 8px;
  min-height: 40px;
  padding: 0 1.25rem;
}

.tabs--secondary .tabs__item::after {
  display: none;
}

.tabs--secondary .tabs__item--selected {
  background: var(--color-bg--surface);
  color: var(--color-ink--surface);
  box-shadow: 0 1px 3px oklch(0 0 0 / 0.12);
}

.tabs--secondary .tabs__item:hover:not(:disabled):not(.tabs__item--selected) {
  background: oklch(from var(--color-bg--container) calc(l * 0.95) c h);
}

/* Tab Panels
 * -------------------------------------------------------------------------- */

.tabs__panels {
  position: relative;
  width: 100%;
}

.tabs__panel {
  width: 100%;
  padding: 1.5rem 0;
  animation: tabs-panel-enter 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

.tabs__panel[hidden] {
  display: none;
}

.tabs__panel--active {
  display: block;
}

/* Panel animation */
@keyframes tabs-panel-enter {
  0% {
    opacity: 0;
    transform: translateY(8px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Fixed tabs (for app bars)
 * -------------------------------------------------------------------------- */

.tabs--fixed {
  position: sticky;
  top: 0;
  z-index: var(--layer-tabs);
  background: var(--color-bg--surface);
  box-shadow: 0 1px 3px oklch(0 0 0 / 0.12);
}

/* Icon-only tabs
 * -------------------------------------------------------------------------- */

.tabs__item--icon-only {
  min-width: 64px;
  padding: 0 1rem;
}

.tabs__item--icon-only .tabs__label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Color variants
 * -------------------------------------------------------------------------- */

.tabs--primary .tabs__item--selected {
  color: var(--color-primary);
}

.tabs--primary .tabs__item::after {
  background: var(--color-primary);
}

.tabs--secondary-color .tabs__item--selected {
  color: var(--color-secondary);
}

.tabs--secondary-color .tabs__item::after {
  background: var(--color-secondary);
}

.tabs--tertiary .tabs__item--selected {
  color: var(--color-tertiary);
}

.tabs--tertiary .tabs__item::after {
  background: var(--color-tertiary);
}

/* Dense variant
 * -------------------------------------------------------------------------- */

.tabs--dense .tabs__bar {
  min-height: 40px;
}

.tabs--dense .tabs__item {
  min-height: 40px;
  padding: 0 1rem;
  font-size: 0.8125rem;
}

/* Dark mode adjustments
 * -------------------------------------------------------------------------- */

[data-color-scheme="dark"] {
  .tabs__item:hover:not(:disabled) {
    background: oklch(1 0 0 / 0.04);
  }

  .tabs__item:active:not(:disabled) {
    background: oklch(1 0 0 / 0.08);
  }

  .tabs--secondary .tabs__item:hover:not(:disabled):not(.tabs__item--selected) {
    background: oklch(from var(--color-bg--container) calc(l * 1.05) c h);
  }
}

/* Responsive behavior
 * -------------------------------------------------------------------------- */

@media (max-width: 40em) {
  .tabs__bar {
    overflow-x: auto;
  }

  .tabs--centered .tabs__bar {
    justify-content: flex-start;
  }

  .tabs__item {
    min-width: auto;
    padding: 0 1rem;
  }
}

/* Examples of usage:
 * --------------------------------------------------------------------------
 *
 * Basic tabs:
 * <%= tab_bar do %>
 *   <%= tab_item("Tab 1", selected: true) %>
 *   <%= tab_item("Tab 2") %>
 *   <%= tab_item("Tab 3") %>
 * <% end %>
 *
 * <%= tab_panels do %>
 *   <%= tab_panel("tab-1", active: true) do %>
 *     Content 1
 *   <% end %>
 *   <%= tab_panel("tab-2") do %>
 *     Content 2
 *   <% end %>
 * <% end %>
 *
 * Tabs with icons:
 * <%= tab_bar(variant: :secondary) do %>
 *   <%= tab_item("Home", icon: :home, selected: true) %>
 *   <%= tab_item("Profile", icon: :user) %>
 *   <%= tab_item("Settings", icon: :settings) %>
 * <% end %>
 */