/* 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/. */

/* Each color uses its legacy value by default and, when browser.nova.enabled
   is on, the refreshed value from the design-system palette. The legacy values
   have no design-system token, so they stay literal. Kept in sync with
   CONTAINER_COLORS (code / codeNova) in ContextualIdentityService. */
.identity-color-blue {
  --identity-tab-color: #37adff;
  --identity-icon-color: #37adff;

  @media -moz-pref("browser.nova.enabled") {
    --identity-tab-color: light-dark(var(--color-blue-30), var(--color-blue-50));
    --identity-icon-color: light-dark(var(--color-blue-30), var(--color-blue-50));
    --identity-pill-color: light-dark(var(--color-blue-50), var(--color-blue-20));
  }
}

.identity-color-cyan {
  --identity-tab-color: #00c79a;
  --identity-icon-color: #00c79a;

  @media -moz-pref("browser.nova.enabled") {
    --identity-tab-color: light-dark(var(--color-cyan-30), var(--color-cyan-50));
    --identity-icon-color: light-dark(var(--color-cyan-30), var(--color-cyan-50));
    --identity-pill-color: light-dark(var(--color-cyan-50), var(--color-cyan-20));
  }
}

.identity-color-green {
  --identity-tab-color: #51cd00;
  --identity-icon-color: #51cd00;

  @media -moz-pref("browser.nova.enabled") {
    --identity-tab-color: light-dark(var(--color-green-30), var(--color-green-50));
    --identity-icon-color: light-dark(var(--color-green-30), var(--color-green-50));
    --identity-pill-color: light-dark(var(--color-green-50), var(--color-green-20));
  }
}

.identity-color-yellow {
  --identity-tab-color: #ffcb00;
  --identity-icon-color: #ffcb00;

  @media -moz-pref("browser.nova.enabled") {
    --identity-tab-color: light-dark(var(--color-yellow-30), var(--color-yellow-50));
    --identity-icon-color: light-dark(var(--color-yellow-30), var(--color-yellow-50));
    --identity-pill-color: light-dark(var(--color-yellow-50), var(--color-yellow-20));
  }
}

.identity-color-orange {
  --identity-tab-color: #ff9f00;
  --identity-icon-color: #ff9f00;

  @media -moz-pref("browser.nova.enabled") {
    --identity-tab-color: light-dark(var(--color-orange-30), var(--color-orange-50));
    --identity-icon-color: light-dark(var(--color-orange-30), var(--color-orange-50));
    --identity-pill-color: light-dark(var(--color-orange-50), var(--color-orange-20));
  }
}

.identity-color-red {
  --identity-tab-color: #ff613d;
  --identity-icon-color: #ff613d;

  @media -moz-pref("browser.nova.enabled") {
    --identity-tab-color: light-dark(var(--color-red-30), var(--color-red-50));
    --identity-icon-color: light-dark(var(--color-red-30), var(--color-red-50));
    --identity-pill-color: light-dark(var(--color-red-50), var(--color-red-20));
  }
}

.identity-color-pink {
  --identity-tab-color: #ff4bda;
  --identity-icon-color: #ff4bda;

  @media -moz-pref("browser.nova.enabled") {
    --identity-tab-color: light-dark(var(--color-pink-30), var(--color-pink-50));
    --identity-icon-color: light-dark(var(--color-pink-30), var(--color-pink-50));
    --identity-pill-color: light-dark(var(--color-pink-50), var(--color-pink-20));
  }
}

.identity-color-purple {
  --identity-tab-color: #af51f5;
  --identity-icon-color: #af51f5;

  @media -moz-pref("browser.nova.enabled") {
    --identity-tab-color: light-dark(var(--color-purple-30), var(--color-purple-50));
    --identity-icon-color: light-dark(var(--color-purple-30), var(--color-purple-50));
    --identity-pill-color: light-dark(var(--color-purple-50), var(--color-purple-20));
  }
}

.identity-color-violet {
  --identity-tab-color: #764edd;
  --identity-icon-color: #764edd;

  @media -moz-pref("browser.nova.enabled") {
    --identity-tab-color: light-dark(var(--color-violet-30), var(--color-violet-50));
    --identity-icon-color: light-dark(var(--color-violet-30), var(--color-violet-50));
    --identity-pill-color: light-dark(var(--color-violet-50), var(--color-violet-20));
  }
}

.identity-color-gray {
  --identity-tab-color: currentColor;
  --identity-icon-color: currentColor;

  @media -moz-pref("browser.nova.enabled") {
    --identity-tab-color: light-dark(var(--color-gray-30), var(--color-gray-50));
    --identity-icon-color: light-dark(var(--color-gray-30), var(--color-gray-50));
    --identity-pill-color: light-dark(var(--color-gray-50), var(--color-gray-20));
  }
}

.identity-icon-fence {
  --identity-icon: url("resource://usercontext-content/fence.svg");
}

.identity-icon-fingerprint {
  --identity-icon: url("resource://usercontext-content/fingerprint.svg");
}

.identity-icon-briefcase {
  --identity-icon: url("resource://usercontext-content/briefcase.svg");
}

.identity-icon-dollar {
  --identity-icon: url("resource://usercontext-content/dollar.svg");
}

.identity-icon-cart {
  --identity-icon: url("resource://usercontext-content/cart.svg");
}

.identity-icon-circle {
  --identity-icon: url("resource://usercontext-content/circle.svg");
}

.identity-icon-vacation {
  --identity-icon: url("resource://usercontext-content/vacation.svg");
}

.identity-icon-gift {
  --identity-icon: url("resource://usercontext-content/gift.svg");
}

.identity-icon-food {
  --identity-icon: url("resource://usercontext-content/food.svg");
}

.identity-icon-fruit {
  --identity-icon: url("resource://usercontext-content/fruit.svg");
}

.identity-icon-pet {
  --identity-icon: url("resource://usercontext-content/pet.svg");
}

.identity-icon-tree {
  --identity-icon: url("resource://usercontext-content/tree.svg");
}

.identity-icon-chill {
  --identity-icon: url("resource://usercontext-content/chill.svg");
}

#userContext-indicator {
  height: 16px;
  width: 16px;
  margin-inline-start: 3px;
}

#userContext-label {
  color: var(--identity-tab-color);
  margin: 0;
  max-width: 8em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;

  @media -moz-pref("browser.nova.enabled") {
    color: var(--identity-pill-color);
    /* Reorder hack; fix the DOM order and drop it once nova ships (Bug 2046350). */
    order: 2;
  }
}

#userContext-icons {
  align-items: center;

  /* When nova is enabled the container indicator is rendered as a pill
     (icon + name) with a tinted background derived from the container color. */
  @media -moz-pref("browser.nova.enabled") {
    gap: var(--space-xxsmall);
    padding: var(--space-xxsmall) var(--space-small);
    border-radius: var(--border-radius-circle);
    background-color: color-mix(in srgb, var(--identity-pill-color) 15%, transparent);
    cursor: pointer;

    &:hover {
      background-color: color-mix(in srgb, var(--identity-pill-color) 25%, transparent);
    }

    &:hover:active {
      background-color: color-mix(in srgb, var(--identity-pill-color) 40%, transparent);
    }
  }
}

.tabbrowser-tab[usercontextid] > .tab-stack > .tab-background > .tab-context-line {
  background-color: var(--identity-icon-color);
  height: 2px;
  border-radius: 2px;
  margin: 0 calc(var(--tab-border-radius) / 2);
  position: relative;

  @media -moz-pref("browser.nova.enabled") {
    height: 4px;
    border-radius: 4px;
    /* From the favicon center to the close button center. */
    margin-inline: calc(var(--tab-inline-padding) + 8px) calc(var(--tab-inline-padding) / 2 + 12px);
    inset-block-start: -6px;
  }

  #tabbrowser-tabs[orient="vertical"] & {
    height: auto;
    width: 2px;
    margin: calc(var(--tab-border-radius) / 2) 0;

    @media -moz-pref("browser.nova.enabled") {
      width: 4px;
      height: 16px;
      margin: 0;
      inset-inline-end: -9px;
      inset-block-start: 50%;
      transform: translateY(-50%);
    }
  }
}

@media -moz-pref("browser.nova.enabled") {
  /* Pinned tabs have no label or close button, so center the stroke. */
  .tabbrowser-tab[usercontextid][pinned] > .tab-stack > .tab-background > .tab-context-line {
    width: 16px;
    margin-inline: auto;
  }

  /* Extend the clip region so the trailing-gap stroke isn't clipped. */
  #tabbrowser-tabs[orient="vertical"] .tabbrowser-tab[usercontextid][pinned] {
    overflow-clip-margin: content-box 12px;
  }
}

.userContext-icon,
.subviewbutton[usercontextid] > .toolbarbutton-icon,
#userContext-indicator {
  background-image: var(--identity-icon);
  -moz-context-properties: fill;
  fill: var(--identity-icon-color);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center center;
}

@media -moz-pref("browser.nova.enabled") {
  #userContext-indicator {
    /* Reorder hack; fix the DOM order and drop it once nova ships (Bug 2046350). */
    order: 1;
    margin-inline-start: 0;
    fill: var(--identity-pill-color);
  }
}

.menuitem-iconic[data-usercontextid] {
  --menuitem-icon: var(--identity-icon);
  --menuitem-icon-fill: var(--identity-icon-color);

  /* When nova is enabled the container icon sits inside a round tinted
     background, mirroring the about:preferences#containers list. */
  @media -moz-pref("browser.nova.enabled") {
    --menuitem-icon-fill: var(--identity-pill-color);

    > .menu-icon {
      width: var(--icon-size-large);
      height: var(--icon-size-large);
      padding: var(--space-xsmall);
      border-radius: var(--border-radius-circle);
      background-color: color-mix(in srgb, var(--identity-pill-color) 15%, transparent);
    }
  }
}
