/* ==========================================================================
   Tabs — moey.js pairs each .tab with the .tab-panel in the same position.

   <div class="tabs">
     <div class="tab-list">
       <button class="tab">Overview</button>
       <button class="tab">Orders <span class="badge badge-count">3</span></button>
     </div>
     <div class="tab-panel">…</div>
     <div class="tab-panel">…</div>
   </div>

   Styles: underline (default) · .tabs-pills · .tabs-segmented
   Layout: .tabs-vertical · .tabs-fill (equal widths) · .tabs-sm · theme-* colors the indicator
   A panel elsewhere: <button class="tab" aria-controls="panel-id">. Start on another tab: aria-selected="true".
   ========================================================================== */

.tabs {
  --mo-tab-height: 2.5rem;
  --mo-tab-padding-x: .25rem;
  --mo-tab-gap: 1.5rem;
  --mo-tab-radius: var(--mo-radius-control);
  --mo-tab-indicator: var(--mo-theme-base);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.tab-list {
  position: relative;
  display: flex;
  gap: var(--mo-tab-gap);
  min-width: 0;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  box-shadow: inset 0 -1px 0 var(--mo-border-color);   /* the line under underline tabs (a separator) */
}
.tab-list::-webkit-scrollbar { display: none; }

.tab {
  position: relative;
  z-index: 1;
  display: inline-flex;
  flex-shrink: 0;
  gap: .5rem;
  align-items: center;
  justify-content: center;
  height: var(--mo-tab-height);
  padding: 0 var(--mo-tab-padding-x);
  font: inherit;
  font-size: .875rem;
  font-weight: var(--mo-font-weight-medium);
  color: var(--mo-fg-3);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  background: none;
  border: 0;
  border-radius: var(--mo-tab-radius);
  transition: color var(--mo-duration) var(--mo-ease), background-color var(--mo-duration) var(--mo-ease);
}
.tab:hover { color: var(--mo-fg-body); }
.tab:is([aria-selected="true"], .active) { color: var(--mo-fg-body); }
.tab:focus-visible { outline: var(--mo-focus-ring-width) solid var(--mo-theme-focus-ring); outline-offset: -2px; }
.tab:is(:disabled, .disabled, [aria-disabled="true"]) { pointer-events: none; opacity: .45; }
.tab > .mi { flex-shrink: 0; font-size: 1rem; }

/* Underline (default): a bar under the selected tab.
   Without moey.js each tab draws its own; with it, one indicator slides between tabs. */
.tab:is([aria-selected="true"], .active)::after {
  position: absolute;
  inset: auto 0 0;
  height: 2px;
  content: "";
  background: var(--mo-tab-indicator);
  border-radius: 2px;
}

/* The sliding indicator (moey.js sets --mo-tab-x/-y/-w/-h on the list) */
.tab-list.has-indicator .tab::after { display: none; }
.tab-list.has-indicator::after {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 0;
  width: var(--mo-tab-w);
  height: 2px;
  pointer-events: none;
  content: "";
  background: var(--mo-tab-indicator);
  border-radius: 2px;
  translate: var(--mo-tab-x) calc(var(--mo-tab-y) + var(--mo-tab-h) - 2px);
}
@media (prefers-reduced-motion: no-preference) {
  .tab-list.is-animated::after {
    transition: translate .28s var(--mo-ease), width .28s var(--mo-ease), height .28s var(--mo-ease);
  }
}

/* Pills: the selected tab gets a soft tinted background */
.tabs-pills { --mo-tab-gap: .25rem; --mo-tab-padding-x: .875rem; --mo-tab-height: 2.25rem; }
.tabs-pills > .tab-list { box-shadow: none; }
.tabs-pills .tab:hover { background-color: color-mix(in oklab, var(--mo-fg-body) 5%, transparent); }
.tabs-pills .tab:is([aria-selected="true"], .active) { color: var(--mo-theme-fg-emphasis); background-color: var(--mo-theme-bg-subtle); }
.tabs-pills .tab::after { display: none; }
.tabs-pills > .tab-list.has-indicator .tab:is([aria-selected="true"], .active) { background-color: transparent; }
.tabs-pills > .tab-list.has-indicator::after {
  height: var(--mo-tab-h);
  background: var(--mo-theme-bg-subtle);
  border-radius: var(--mo-tab-radius);
  translate: var(--mo-tab-x) var(--mo-tab-y);
}

/* Segmented: a tray with a raised selected tab (like the segmented control) */
.tabs-segmented { --mo-tab-gap: 0; --mo-tab-padding-x: .875rem; --mo-tab-height: calc(var(--mo-control-height) - 6px); }
.tabs-segmented > .tab-list {
  align-self: flex-start;
  max-width: 100%;
  padding: 3px;
  background: color-mix(in oklab, var(--mo-fg-body) 6%, transparent);
  border-radius: var(--mo-radius-control);
  box-shadow: none;
}
.tabs-segmented .tab { --mo-tab-radius: calc(var(--mo-radius-control) - 3px); color: var(--mo-fg-2); }
.tabs-segmented .tab:hover { color: var(--mo-fg-body); }
.tabs-segmented .tab:is([aria-selected="true"], .active) {
  color: var(--mo-fg-body);
  background-color: light-dark(var(--mo-bg-raised), color-mix(in oklab, var(--mo-fg-body) 17%, var(--mo-bg-surface)));
}
.tabs-segmented .tab::after { display: none; }
.tabs-segmented > .tab-list.has-indicator .tab:is([aria-selected="true"], .active) { background-color: transparent; }
.tabs-segmented > .tab-list.has-indicator::after {
  top: 0;
  height: var(--mo-tab-h);
  background: light-dark(var(--mo-bg-raised), color-mix(in oklab, var(--mo-fg-body) 17%, var(--mo-bg-surface)));
  border-radius: calc(var(--mo-radius-control) - 3px);
  translate: var(--mo-tab-x) var(--mo-tab-y);
}

/* Equal-width tabs that fill the row */
.tabs-fill > .tab-list { align-self: stretch; }
.tabs-fill .tab { flex: 1 1 0; }

.tabs-sm { --mo-tab-height: 2rem; }
.tabs-sm .tab { font-size: .8125rem; }
.tabs-sm.tabs-segmented { --mo-tab-height: calc(var(--mo-control-height-sm) - 6px); }

/* Vertical: the list on the side (becomes a horizontal row on phones) */
@media (width >= 576px) {
  .tabs-vertical { flex-direction: row; gap: 1.5rem; }
  .tabs-vertical > .tab-list {
    flex-direction: column;
    flex-shrink: 0;
    align-self: flex-start;
    min-width: 11rem;
    overflow: visible;
    box-shadow: inset 1px 0 0 var(--mo-border-color);
  }
  .tabs-vertical:not(.tabs-pills, .tabs-segmented) { --mo-tab-gap: 0; --mo-tab-padding-x: 1rem; }
  .tabs-vertical .tab { justify-content: flex-start; }
  .tabs-vertical:not(.tabs-pills, .tabs-segmented) .tab:is([aria-selected="true"], .active)::after { inset: 0 auto 0 0; width: 2px; height: auto; }
  .tabs-vertical:not(.tabs-pills, .tabs-segmented) > .tab-list.has-indicator::after {
    width: 2px;
    height: var(--mo-tab-h);
    translate: 0 var(--mo-tab-y);
  }
  .tabs-vertical:is(.tabs-pills, .tabs-segmented) > .tab-list { box-shadow: none; }
  .tabs-vertical > .tab-panel { flex: 1; min-width: 0; }
}

/* Panels */
.tab-panel { min-width: 0; }
.tab-panel:focus-visible { outline: var(--mo-focus-ring-width) solid var(--mo-theme-focus-ring); outline-offset: 2px; border-radius: var(--mo-radius-control); }
.tabs:not(.is-ready) > .tab-panel ~ .tab-panel { display: none; }   /* before moey.js: just the first */
@media (prefers-reduced-motion: no-preference) {
  .tabs.is-ready > .tab-panel:not([hidden]) { animation: mo-tab-in .2s var(--mo-ease); }
  @keyframes mo-tab-in { from { opacity: 0; translate: 0 4px; } }
}
