/*
 * 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[split-view-group] {
  display: block;
  @media (prefers-reduced-motion: no-preference) {
    #tabbrowser-tabs[movingtab] &:not(:active) {
      transition: var(--tab-dragover-transition);
    }
  }
  --zen-split-view-active-tab-bg: color-mix(
    in srgb,
    var(--zen-toolbar-element-bg),
    transparent 40%
  );

  margin-inline-start: var(--zen-folder-indent) !important;

  #tabbrowser-tabs[movingtab] & {
    transition: margin-inline-start 0.15s ease-in-out;
  }

  & .tab-group-container {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;

    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;
    margin-inline-start: 0 !important;

    :root:not([zen-sidebar-expanded='true']) & {
      padding: 0;
      --tab-collapsed-width: 38px;
      overflow: clip;
      --tab-min-width: 34px;
      outline: 2px solid var(--zen-colors-border-contrast);
      outline-offset: -2px;
    }

    & > .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;
      --zen-folder-indent: 0 !important;

      :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 .tab-group-container {
    flex-direction: column;
  }
}

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

tab-group[split-view-group] .tab-group-label-container {
  position: absolute;
  width: 100%;
  height: 40px;
  visibility: hidden;
  padding: 0 !important;
  margin: 0 !important;
}

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-line {
  display: none !important;
}

zen-folder {
  display: flex;
  flex-direction: column;
  --zen-folder-behind-bgcolor: light-dark(
    color-mix(in srgb, var(--zen-primary-color) 85%, white),
    color-mix(in srgb, var(--zen-primary-color) 75%, white)
  );
  --zen-folder-front-bgcolor: light-dark(
    color-mix(in srgb, var(--zen-primary-color), white 70%),
    color-mix(in srgb, var(--zen-primary-color), black 20%)
  );
  --zen-folder-stroke: light-dark(
    color-mix(in srgb, var(--zen-primary-color) 70%, black),
    color-mix(in srgb, var(--zen-colors-primary) 20%, var(--toolbox-textcolor))
  );

  -moz-window-dragging: no-drag;
  transition: margin-inline-start 0.15s ease-in-out;

  margin-inline-start: var(--zen-folder-indent) !important;

  &[selected] > .tab-group-label-container::before {
    background-color: color-mix(in srgb, var(--zen-colors-border) 60%, transparent);
  }

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

  :root:not([zen-sidebar-expanded]) & {
    width: var(--tab-min-width) !important;
    margin: var(--tab-block-margin) auto !important;

    & .tab-group-label {
      visibility: hidden !important;
    }
  }

  & > .tab-group-container {
    :root[zen-sidebar-expanded] & > * {
      --zen-folder-indent: 14px; /* Can get overriden by the JS */
      margin-inline-start: var(--zen-folder-indent) !important;
    }

    & > zen-folder {
      transition: margin-inline-start 0.15s ease-in-out;
    }

    & > tab::before {
      background: none !important;
    }
  }

  margin: 0 var(--tab-block-margin);
  margin-inline-end: 0;

  & > .tab-group-label-container {
    flex: 0 0 auto !important;
    top: 0 !important;
    --tab-group-color-pale: transparent !important;
    --tab-group-color: transparent !important;
    padding-block-end: 0 !important;
    margin: 0 !important;
    height: 40px;
    padding-inline: var(--tab-group-label-padding);
    align-items: center;

    :root:not([zen-sidebar-expanded]) {
      width: var(--tab-min-width) !important;
    }

    .tab-group-folder-icon {
      width: 30px;
      height: 28px;
      align-content: center;
      pointer-events: none;
      position: absolute;
      pointer-events: none;

      :root[zen-sidebar-expanded] & {
        left: 2px;
      }

      & svg {
        filter: contrast(150%);
        transition: 0.2s scale;
        transform-origin: right bottom;

        :root:not([zen-sidebar-expanded]) & {
          transform-origin: center bottom;
        }

        & image {
          fill-opacity: 0.9;
          -moz-context-properties: fill, fill-opacity;
          fill: var(--zen-folder-stroke);
          transform: translate(-180%, 8%);
        }
      }

      & svg[state='open'] {
        scale: 0.92;
      }
    }

    &::before {
      content: '';
      position: absolute;
      top: 2px;
      left: 2px;
      width: calc(100% - 4px);
      height: calc(100% - 4px);
      background-color: transparent;
      border-radius: var(--border-radius-medium);
      z-index: -1;
    }

    &:hover::before {
      background-color: var(--tab-hover-background-color) !important;
    }

    &:after {
      display: none;
    }

    & > label,
    & > #tab-label-input {
      padding: 0 0 0 30px !important;
      width: 100%;
    }

    & > label {
      width: 100% !important;
      background: transparent !important;
      border: none !important;
      color: var(--sidebar-text-color) !important;
      margin: 0 !important;
      font-weight: 600;
      display: flex;
      align-items: center;
      height: 100% !important;
      text-align: start;

      :root:not([zen-sidebar-expanded]) & {
        padding: 0 !important;
        max-width: 100% !important;
      }
    }
  }

  &[collapsed] {
    & > .tabbrowser-tab:not([hidden]) {
      display: flex;
    }

    & > .tab-group-container {
      overflow-y: clip;
    }
  }
}

/* Tabs popup */
#zen-folder-tabs-popup {
  --arrowpanel-padding: 0;
  width: 250px;

  & #zen-folder-tabs-search-no-results {
    height: 100%;
    align-items: center;
    text-align: center;
    padding: 2em 0;
    justify-content: center;
    max-width: calc(100% - 10px);
    margin: 0 auto;
  }
}

#zen-folder-tabs-popup * {
  max-width: -moz-available;
}

#zen-folder-tabs-popup .tabs-list-header {
  display: flex;
  flex-direction: row;
  padding: 6px;
  border-bottom: 1px solid color-mix(in srgb, currentColor, transparent 90%);
  margin-bottom: 2px;
}

#zen-folder-tabs-popup #zen-folder-tabs-list-search {
  background-color: transparent;
  border: none !important;
  outline: none !important;
}

#zen-folder-tabs-list {
  padding: 0 4px;
  max-height: 248px;
  overflow-y: auto;
}

#zen-folder-tabs-popup .zen-folder-tabs-list-search-icon {
  width: 16px;
  height: 16px;
  margin: 10px 2px 10px 10px;
  -moz-context-properties: fill;
  fill: currentColor;
  opacity: 0.7;
}

.folders-tabs-list-item-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  margin-inline-end: 10px;
  margin-inline-start: 4px;
}

.folders-tabs-list-item-labels {
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex: 1;
  min-width: 0;
  color: var(--toolbox-textcolor);
}

.folders-tabs-list-item-label,
.tab-list-item-secondary-label {
  position: relative;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 250px;
  color: light-dark(black, white);
}

.tab-list-item-secondary-label {
  opacity: 0.6;
  font-size: 0.7em;
  font-weight: 500;
}

#zen-folder-tabs-popup .tabs-list-scrollbox {
  overflow: scroll;
}

.folders-tabs-list-item {
  position: relative;
  border-radius: var(--zen-border-radius);
  cursor: default;
}

.folders-tabs-list-item-content {
  position: relative;
  height: 40px;
  display: flex;
  align-items: center;
  direction: ltr;
  padding: 0 var(--tab-inline-padding);
  border-radius: 4px;
  margin: 2px 0;

  .folders-tabs-list-item[selected] & {
    background-color: color-mix(in srgb, currentColor, transparent 90%);
  }

  &:last-child {
    border-bottom-left-radius: max(calc(var(--panel-border-radius) - 4px), 4px);
    border-bottom-right-radius: max(calc(var(--panel-border-radius) - 4px), 4px);
  }
}

.tab-group-overflow-count-container {
  display: none !important;
}
