/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

tab-group {
  & .tabbrowser-tab {
    margin-inline-start: 0 !important;
  }
}

tab-group[split-view-group] {
  display: flex;
  flex-wrap: nowrap;
  border-radius: var(--border-radius-medium);
  padding: 0 2px;
  margin-inline: var(--tab-block-margin);
  margin-block: var(--tab-block-margin);
  min-height: var(--tab-min-height);
  outline: var(--tab-outline);
  outline-offset: var(--tab-outline-offset);
  outline-color: var(--tab-selected-outline-color);
  transition: scale 0.1s ease;
  align-items: center;
  --zen-split-view-active-tab-bg: color-mix(
    in srgb,
    var(--zen-toolbar-element-bg),
    transparent 40%
  );

  :root:not([zen-sidebar-expanded='true']) & {
    padding: 0 2px;
    --tab-min-height: 30px;
    --tab-collapsed-width: 38px;
    margin: 2px 0;
    --tab-min-width: 34px;
  }

  & > .tabbrowser-tab {
    --tab-selected-bgcolor: var(--zen-split-view-active-tab-bg);
    --tab-hover-background-color: transparent;
    --tab-selected-shadow: none;
    --border-radius-medium: var(--tab-border-radius);
    --zen-active-tab-scale: 1;

    :root[zen-sidebar-expanded='true'] & {
      --tab-min-height: 28px;
    }

    container-type: inline-size;
    container-name: browser-tab;

    flex: 1 !important;
    padding-inline: 2px !important;
    overflow: clip;

    &:not(:last-child)::after {
      content: '';
      width: 1px;
      height: 16px;
      background-color: light-dark(rgba(0, 0, 0, 0.1), rgba(255, 255, 255, 0.2));
      position: absolute;
      right: 0;
      top: 50%;
      transform: translateY(-50%);
    }

    :root:not([zen-sidebar-expanded='true']) &:not(:last-child)::after {
      width: 16px;
      height: 1px;
      top: auto;
      bottom: 0;
      right: 50%;
      transform: translateX(50%);
    }

    & .tab-content {
      min-width: 0;
      :root[zen-sidebar-expanded='true'] & {
        justify-content: unset !important;
      }
    }
  }

  &:has(> tab:is([visuallyselected], [multiselected])) {
    background-color: var(--tab-selected-bgcolor);
    box-shadow: var(--tab-selected-shadow);

    & > .tabbrowser-tab {
      --tab-hover-background-color: var(--zen-split-view-active-tab-bg);
      & .tab-background {
        background-color: var(--zen-split-view-active-tab-bg) !important;
      }

      &::after {
        display: none;
      }
    }
  }

  &:active {
    scale: var(--zen-active-tab-scale);
  }

  &:hover {
    background-color: var(--zen-toolbar-element-bg);
  }

  & .tab-close-button,
  & .tab-reset-button {
    margin-inline-end: -3px !important;
    display: none !important;
  }

  @container browser-tab (min-width: 70px) {
    :root[zen-sidebar-expanded='true'] &:hover > .tabbrowser-tab:not([pinned]) .tab-close-button {
      display: block !important;
    }
  }

  @media (prefers-reduced-motion: no-preference) {
    #tabbrowser-tabs[movingtab] & {
      transition: var(--tab-dragover-transition);
    }
  }
}

:root:not([zen-sidebar-expanded='true']) {
  tab-group {
    flex-direction: column;
  }
}

tab-group[split-view-group] .tabbrowser-tab {
  width: 100%;
  max-width: unset;
}

tab-group[split-view-group] .tab-group-label-container {
  visibility: collapse;
}

tab-group[split-view-group] .tab-close-button {
  display: block;
  visibility: visible;
}

tab-group[split-view-group] .tab-group-line {
  display: none;
  background: transparent;
}

tab-group:not([split-view-group]) {
  & .tab-group-label-container {
    min-width: fit-content;
    max-width: 100%;
    height: fit-content !important;
    display: flex;
    justify-content: start;
    margin-top: 10px;
    margin-bottom: 10px;
  }

  & .tab-group-label {
    text-align: start;
    flex-grow: 1 !important;
    min-width: fit-content;
    max-width: 100%;
    font-size: 14px !important;
    display: block !important;
    padding-right: 8px;
  }

  & .tab-group-line {
    display: none !important;
  }

  &[collapsed] .tabbrowser-tab {
    display: none !important;
  }

  &:not([collapsed]) .tabbrowser-tab {
    margin-left: 10px;
  }

  &:not([collapsed]) .tabbrowser-tab::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 2px;
    height: 100%;
    background-color: var(--tab-group-color);
  }
}

.tab-group-line {
  display: none !important;
}
