// 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/.
//
// Copyright (c) KALEIDOS INC Sucursal en España SL

@use "ds/typography.scss" as t;
@use "ds/colors.scss" as *;
@use "ds/spacing.scss" as *;
@use "ds/_borders.scss" as *;
@use "ds/_sizes.scss" as *;
@use "ds/_utils.scss" as *;
@use "ds/z-index.scss" as *;
@use "common/refactor/common-dashboard";
@use "common/refactor/common-refactor.scss" as deprecated;

// SIDEBAR COMPONENT
.dashboard-sidebar {
  display: grid;
  grid-row: 1 / span 2;
  grid-column: 1 / span 2;
  grid-template-rows: 1fr auto;
  height: 100%;
  width: 100%;
  padding: var(--sp-l) 0 0 0;
  margin: 0 var(--sp-l) 0 0;
  border-right: $b-1 solid var(--panel-border-color);
  background-color: var(--panel-background-color);
}

// SIDEBAR CONTENT COMPONENT
.sidebar-content-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.sidebar-content {
  display: grid;
  grid-template-rows: auto auto auto auto 1fr;
  gap: var(--sp-xxl);
  flex: 1;
  min-height: 0;
  padding: 0;
  overflow: hidden auto;
}

.sidebar-content-nitrate {
  padding: var(--sp-m) 0 0 0;
  border-block-start: $b-1 solid var(--color-background-quaternary);
}

.separator {
  height: var(--sp-xxs);
  width: 94%;
  margin-left: 3%;
}

.overflow-separator {
  border-bottom: $b-1 solid var(--color-background-quaternary);
}

.sidebar-section-title {
  @include t.use-typography("headline-small");

  padding: 0 var(--sp-s) var(--sp-s) var(--sp-xxl);
  color: var(--color-foreground-secondary);
}

// SIDEBAR TEAM SWITCH
.sidebar-team-switch {
  position: relative;
  margin: var(--sp-xs) var(--sp-l);
}

.switch-content {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  height: $sz-48;
  width: 100%;
  border-radius: $br-8;
  border: $b-1 solid var(--menu-background-color);
  background-color: var(--menu-background-color);
}

.current-team {
  @include deprecated.button-style;

  display: grid;
  align-items: center;
  grid-template-columns: 1fr auto;
  gap: var(--sp-s);
  height: 100%;
  padding: 0 var(--sp-m) 0 var(--sp-l);
}

.team-name {
  display: grid;
  align-items: center;
  grid-template-columns: auto 1fr;
  gap: var(--sp-s);
  height: $sz-40;
}

.team-name-no-logo {
  grid-template-columns: 1fr;
}

.team-text {
  @include deprecated.text-ellipsis;
  @include t.use-typography("title-small");

  width: auto;
  text-align: left;
  color: var(--menu-foreground-color-hover);
}

.team-text-with-icon {
  display: flex;
  gap: var(--sp-s);
  max-width: 100%;
  overflow: hidden;
}

// This icon still use the old svg
.penpot-icon {
  @include deprecated.flex-center;

  svg {
    fill: var(--icon-foreground);
    width: var(--sp-xxl);
    height: var(--sp-xxl);
  }
}

.team-picture {
  @include deprecated.flex-center;

  border-radius: 50%;
  height: var(--sp-xxl);
  width: var(--sp-xxl);
}

.arrow-icon {
  @extend %button-icon;

  transform: rotate(90deg);
  stroke: var(--icon-foreground);
}

.switch-options {
  @include deprecated.button-style;
  @include deprecated.flex-center;

  max-width: var(--sp-xxl);
  min-width: deprecated.$s-28;
  height: 100%;
  border-left: $b-1 solid var(--panel-background-color);
  background-color: transparent;
}

.menu-icon {
  @extend %button-icon;

  stroke: var(--icon-foreground);
}

// DROPDOWNS

.teams-dropdown {
  @extend %menu-dropdown;

  left: 0;
  top: deprecated.$s-52;
  height: fit-content;
  max-height: $sz-480;
  min-width: deprecated.$s-248;
  width: 100%;
  overflow: hidden auto;
}

.team-dropdown-item {
  @extend %menu-item-base;

  display: grid;
  grid-template-columns: var(--sp-xxl) 1fr auto;
  gap: var(--sp-s);
  height: $sz-40;
  padding-inline-start: var(--sp-m);
}

.team-dropdown-item-no-logo {
  grid-template-columns: 1fr auto;
}

.organization-dropdown-item {
  @extend %menu-item-base;

  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: var(--sp-s);
  height: $sz-40;
  padding-inline-start: var(--sp-m);
}

.action {
  --sidebar-action-icon-color: var(--icon-foreground);
  --sidebar-icon-backgroun-color: var(--color-background-secondary);

  &:hover {
    --sidebar-action-icon-color: var(--color-background-secondary);
    --sidebar-icon-backgroun-color: var(--color-accent-primary);
  }
}

.icon-wrapper {
  @include deprecated.flex-center;

  width: var(--sp-xxl);
  height: var(--sp-xxl);
  border-radius: 50%;
  background-color: var(--sidebar-icon-backgroun-color);
}

.add-icon {
  @extend %button-icon;

  width: var(--sp-xxl);
  height: var(--sp-xxl);
  stroke: var(--sidebar-action-icon-color);
}

.team-separator {
  border-top: $b-1 solid var(--color-background-quaternary);
  margin: 0;
}

.organization-section-label {
  @include t.use-typography("headline-small");

  color: var(--color-foreground-secondary);
  list-style: none;
  padding: var(--sp-m) $sz-6 $sz-6 var(--sp-m);
  text-transform: uppercase;
}

.tick-icon {
  @extend %button-icon-small;

  stroke: var(--icon-foreground);
}

.options-dropdown {
  @extend %menu-dropdown;

  right: var(--sp-xxs);
  top: deprecated.$s-52;
  max-height: $sz-480;

  &:not(.teams-dropdown) {
    min-width: var(--sp-l) 0;
  }
}

.team-options-item {
  @extend %menu-item-base;

  height: $sz-40;
}

.team-option-separator {
  height: deprecated.$s-1;
  margin: 0;
  border-top: $b-1 solid var(--dropdown-separator-color);
}

// Sections
.sidebar-nav {
  margin: 0;
  user-select: none;
}

.pinned-projects {
  overflow-y: auto;
}

.sidebar-nav-item {
  cursor: pointer;

  &:hover {
    background-color: var(--sidebar-element-background-color-hover);

    span {
      color: var(--sidebar-element-foreground-color-hover);
    }
  }

  &.current {
    background-color: var(--sidebar-element-background-color-selected);

    .element-title {
      color: var(--sidebar-element-foreground-color-selected);
    }
  }
}

.recent-projects svg {
  stroke: var(--main-icon-foreground);
}

.sidebar-link {
  display: block;
  padding: var(--sp-s) var(--sp-s) var(--sp-s) var(--sp-xxl);
  font-weight: deprecated.$fw400;
  width: 100%;

  &:hover {
    text-decoration: none;
  }
}

.project-element {
  padding: var(--sp-s) var(--sp-s) var(--sp-s) var(--sp-xxl);
}

.element-title {
  @include deprecated.text-ellipsis;

  width: deprecated.$s-256;
  color: var(--color-foreground-primary);
  font-size: deprecated.$fs-14;
}

// Pinned projects

.sidebar-empty-placeholder {
  padding: var(--sp-m);
  color: var(--empty-message-foreground-color);
  display: flex;
  align-items: center;
}

.pin-icon {
  @extend %button-icon-small;

  stroke: var(--icon-foreground);
  margin: 0 var(--sp-m);
}

.empty-text {
  font-size: deprecated.$fs-12;
}

// Search

.sidebar-search {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
  border: $b-1 solid transparent;
  margin: 0 var(--sp-l);
  border-radius: $br-8;
  background-color: var(--search-bar-input-background-color);
}

.input-text {
  @include t.use-typography("title-small");

  height: $sz-40;
  width: 100%;
  padding: $sz-6 var(--sp-m);
  margin: 0;
  border: transparent;
  border-radius: $br-8;
  background: transparent;
  color: var(--search-bar-foreground-color);

  &:focus,
  &:focus-within,
  &:focus-visible {
    outline: none;
    border: $b-1 solid var(--search-bar-input-border-color-focus);
  }

  ::placeholder {
    color: var(--search-bar-placeholder-foreground-color);
  }
}

.search-btn {
  @include deprecated.button-style;
  @include deprecated.flex-center;

  position: absolute;
  right: 0;
  height: var(--sp-xxl);
  width: var(--sp-xxxl);
  padding: 0 var(--sp-s);
}

.search-icon,
.clear-search-btn {
  @extend %button-icon;

  --sidebar-search-foreground-color: var(--search-bar-icon-foreground-color);

  stroke: var(--sidebar-search-foreground-color);
}

.clear-search-btn:hover {
  --sidebar-search-foreground-color: var(--search-bar-icon-foreground-color-hover);
}

// Profile
.profile-section {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  padding: var(--sp-m) var(--sp-l);
  border-top: $b-1 solid var(--panel-border-color);
  background-color: var(--profile-section-background-color);
  cursor: pointer;
}

.profile {
  @include deprecated.button-style;

  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--sp-s);
  cursor: pointer;
  text-align: left;
}

.profile-fullname {
  @include t.use-typography("title-small");
  @include deprecated.text-ellipsis;

  align-self: center;
  max-width: var(--sp-l) 0;
  color: var(--profile-foreground-color);
}

.profile-img {
  height: $sz-40;
  width: $sz-40;
  border-radius: $br-circle;
}

.profile-dropdown {
  @extend %menu-dropdown;

  inset-inline-start: var(--sp-s);
  inset-block-end: px2rem(72); // 72 is the height of the profile button
  min-width: calc(100% - var(--sp-s));

  // TODO ADD animation fadeInUp
}

.profile-dropdown-item {
  @extend %menu-item-base;
  @include t.use-typography("body-medium");

  block-size: $sz-40;
  margin-block-end: var(--sp-xs);
  padding: var(--sp-s);
  padding-inline-start: var(--sp-l);

  &:hover {
    color: var(--menu-foreground-color-hover);

    .open-arrow {
      --icon-stroke-color: var(--menu-foreground-color-hover);
    }
  }
}

.profile-dropdown-item .open-arrow {
  @include deprecated.flex-center;
}

.profile-dropdown-item .open-arrow svg {
  @extend %button-icon;

  stroke: var(--icon-foreground);
}

.sub-menu {
  @extend %menu-dropdown;

  inset-inline-start: calc(deprecated.$s-292 + var(--sp-s));
  min-width: deprecated.$s-192;
}

// Each submenu is positioned via its bottom edge; the visual top lands
// at `inset-block-end + submenu_height`. Help & Learning (3 items,
// taller) needs the same inset as Community (2 items, shorter) so that
// its top edge sits one row above Community — aligning with the
// "Help & Learning" trigger row in the parent menu.
.sub-menu.help-learning {
  inset-block-end: deprecated.$s-120;
}

.sub-menu.community {
  inset-block-end: deprecated.$s-120;
}

.sub-menu.about {
  inset-block-end: $sz-24;
}

.submenu-item {
  @extend %menu-item-base;
  @include t.use-typography("body-medium");

  block-size: $sz-40;
  margin-block-end: var(--sp-xs);
  padding-block: var(--sp-s);
  padding-inline: var(--sp-l);

  &:hover {
    color: var(--menu-foreground-color-hover);
  }
}

.about-penpot {
  align-items: baseline;
  display: grid;
  grid-template-columns: auto 1fr;
}

.menu-version {
  @include t.use-typography("code-font");
  @include deprecated.text-ellipsis;

  color: var(--color-foreground-secondary);
  margin-inline-start: var(--sp-s);
  text-transform: uppercase;
}

.profile-separator {
  height: $sz-6;
  border-top: $b-1 solid var(--color-background-quaternary);
}

.item-with-icon {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--sp-s);
}

.exit-icon {
  @extend %button-icon;

  stroke: var(--icon-foreground);
}

.add-organization-icon {
  @extend %button-icon;

  width: var(--sp-l);
  height: var(--sp-l);
  stroke: var(--sidebar-action-icon-color);
}

.arrow-up-right-icon {
  @extend %button-icon;

  width: var(--sp-m);
  height: var(--sp-m);
  stroke: var(--sidebar-action-icon-color);
}

.upgrade-plan-section {
  @include deprecated.button-style;

  display: flex;
  justify-content: space-between;
  border: $b-1 solid var(--color-background-quaternary);
  border-radius: var(--sp-s);
  padding: var(--sp-m);
  margin: var(--sp-m);
  color: var(--color-foreground-secondary);
  cursor: pointer;
}

.penpot-free {
  @include t.use-typography("body-medium");

  display: flex;
  flex-direction: column;
  text-align: left;
}

.no-limits {
  @include t.use-typography("body-small");
}

.power-up {
  @include t.use-typography("body-small");

  color: var(--color-accent-tertiary);
}

.organizations-container {
  align-items: center;
  display: flex;
  height: calc(2 * var(--sp-xxxl));
  max-height: calc(2 * var(--sp-xxxl));
  justify-content: space-between;
  padding: 0 var(--sp-l);
}

.selected-organization {
  @include t.use-typography("body-medium");

  color: var(--color-foreground-primary);
  width: 100%;
  padding-inline-start: var(--sp-s);
  display: flex;
  align-items: center;
  gap: var(--sp-s);
}

.create-organization {
  margin-inline-start: auto;
  text-transform: uppercase;
}

.organization-penpot-icon {
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  height: var(--sp-xxxl);
  width: var(--sp-xxxl);
  background-color: var(--color-foreground-primary);

  svg {
    fill: var(--icon-stroke-color);
    width: var(--sp-xxl);
    height: var(--sp-xxl);
  }
}

.organization-icon {
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  height: var(--sp-xxl);
  width: var(--sp-xxl);
  background-color: var(--color-foreground-primary);

  svg {
    fill: var(--icon-stroke-color);
    width: var(--sp-xl);
    height: var(--sp-xl);
  }
}

.my-teams-icon {
  height: var(--sp-xxl);
  width: var(--sp-xxl);

  svg {
    fill: var(--icon-stroke-color);
    width: var(--sp-xxl);
    height: var(--sp-xxl);
  }
}

.my-teams-icon-xxxl {
  height: var(--sp-xxxl);
  width: var(--sp-xxxl);

  svg {
    fill: var(--icon-stroke-color);
    width: var(--sp-xxxl);
    height: var(--sp-xxxl);
  }
}

.sidebar-organization-switch {
  position: relative;
  width: 100%;
}

.current-organization {
  @include deprecated.button-style;

  text-transform: none;
  display: grid;
  align-items: center;
  grid-template-columns: 1fr auto auto;
  gap: var(--sp-s);
  height: 100%;
  padding: 0 0 0 px2rem(10);
  width: 100%;
}

.current-organization-no-options {
  gap: 0;
  padding: 0 px2rem(8) 0 px2rem(10);
}

.current-organization .arrow-icon {
  margin-inline-end: var(--sp-xs);
}

.organization-options {
  display: flex;
  justify-content: center;
  align-items: center;
  max-width: var(--sp-xxl);
  min-width: $sz-28;
  height: 100%;
}

.organization-switch-content {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  height: $sz-48;
  width: 100%;
}

.organization-options-btn {
  --icon-stroke: var(--icon-foreground);

  display: flex;
  justify-content: center;
  align-items: center;
  width: $sz-28;
  height: 100%;
  padding: 0;
  border-radius: 0 $br-8 $br-8 0;

  &:hover {
    --icon-stroke: var(--color-accent-primary);

    cursor: pointer;
  }
}

.organization-menu-icon {
  @extend %button-icon;

  stroke: var(--icon-stroke);
}

.organization-menu-icon-open {
  @extend %button-icon;

  stroke: var(--color-accent-primary);
}
