//
// Copyright © 2021 Anticrm Platform Contributors.
// 
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// 
// See the License for the specific language governing permissions and
// limitations under the License.
//

/* CLEAR */
a {
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  color: var(--theme-content-accent-color);
  outline: none;
  &:hover {
    color: var(--theme-caption-color);
    text-decoration: underline;
  }
  &:active {
    color: var(--theme-content-accent-color);
    text-decoration: underline;
  }
  &:visited { color: var(--theme-caption-color); }
}
button {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0;
  padding: 0;
  font-size: inherit;
  background-color: transparent;
  border: 1px solid transparent;
  outline: none;
  cursor: pointer;
  user-select: none;
}
input {
  min-width: 0;
  font: inherit;
  background-color: transparent;
  outline: none;
  color: var(--caption-color);
  &::placeholder { color: var(--dark-color); }
  &.wrong-input { background-color: var(--system-error-color) !important; }
}
audio, canvas, embed, iframe, img, object, svg, video {
  display: block;
  vertical-align: middle;
}
input:-webkit-autofill,
input:-webkit-autofill:hover, 
input:-webkit-autofill:focus
input:-webkit-autofill, 
textarea:-webkit-autofill,
textarea:-webkit-autofill:hover
textarea:-webkit-autofill:focus,
select:-webkit-autofill,
select:-webkit-autofill:hover,
select:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--theme-caption-color);
  transition: background-color 5000s ease-in-out 0s;
  background: transparent;
}

table, caption, tbody, tfoot, thead, tr, th, td {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: middle;
}
table {
  border-collapse: collapse;
  border-spacing: 0;
}

/* Common */
* {
  --modal-padding: 1.5rem;
}

p { user-select: text; }
p:first-child { margin-block-start: 0; } // First and last padding
p:last-child { margin-block-end: 0; }

.p-inline {
  line-height: 150%;
  a {
    word-break: break-all;
    word-break: break-word;
    hyphens: auto;
  }
}

.inline-height2 {
  line-height: 200%;
}

.float-left-box {
  box-sizing: border-box;
  width: 100%;
  float: left;
}

.float-left {
  float: left;
}

input.search {
  margin: 0;
  color: #d6d6d6;
  border: none;
  caret-color: var(--caret-color);

  &.padding { padding: .625rem .75rem; }
}

/* Flex */
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.flex-grow { flex-grow: 1; }
.flex-no-shrink { flex-shrink: 0; }
.flex-wrap { flex-wrap: wrap !important; }
.flex-nowrap { flex-wrap: nowrap !important; }
.flex-baseline {
  display: inline-flex;
  align-items: baseline;
}
.flex-center {
  display: flex;
  justify-content: center;
  align-items: center;
}
.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.flex-stretch {
  display: flex;
  align-items: stretch;
}
.flex-row-center {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  min-width: 0;
}
.flex-row-stretch {
  display: flex;
  align-items: stretch;
  flex-wrap: nowrap;
}
.flex-row-top {
  display: flex;
  align-items: flex-start;
}
.flex-row-reverse {
  display: flex;
  flex-direction: row-reverse;
  align-items: center;
}
.flex-reverse {
  flex-direction: row-reverse;
}
.flex-col {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  min-height: 0;
}
.flex-col-center {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.flex-col-stretch {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.justify-between { justify-content: space-between; }
.justify-start { justify-content: flex-start; }
.justify-end { justify-content: flex-end; }
.justify-center { justify-content: center; }
.items-baseline { align-items: baseline; }
.items-center { align-items: center; }

.flex-gap-3 { gap: .75rem; }
.flex-gap-2 { gap: .5rem; }
.flex-gap-1 { gap: .25rem; }

.flex-presenter, .inline-presenter {
  flex-wrap: nowrap;
  cursor: pointer;

  .icon {
    margin-right: .5rem;
    color: var(--theme-content-dark-color);

    &.circle {
      padding: .25rem;
      background-color: var(--avatar-bg-color);
      border-radius: 50%;
    }
  }
  .label {
    min-width: 0;
    font-weight: 500;
    text-align: left;
    color: var(--theme-content-accent-color);

    overflow: hidden;
    visibility: visible;
    display: -webkit-box;
    /* autoprefixer: ignore next */
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;  
    user-select: none;

    &.nowrap {
      white-space: nowrap;
      text-overflow: ellipsis;
    }
  }
  .action {
    visibility: hidden;
    margin-left: .75rem;
  }
  &:hover {
    .icon { color: var(--theme-caption-color); }
    .label {
      text-decoration: underline;
      color: var(--theme-caption-color);
    }
    .action { visibility: visible; }
  }
}
.flex-presenter {
  display: flex;
  align-items: center;
}
.inline-presenter {
  display: inline-flex;
  align-items: baseline;
  .icon { transform: translateY(.2rem); }
}

.buttons-group {
  display: grid;
  grid-auto-flow: column;
  justify-content: start;
  align-items: center;
  gap: .75rem;

  &.reverse { direction: rtl; }
  &.small-gap { gap: .5rem; }
  &.xsmall-gap { gap: .375rem; }
  &.xxsmall-gap { gap: .25rem; }
  &.short {
    grid-template-columns: repeat(4, min-content);
    grid-auto-flow: row;
  }
}
.buttons-divider {
  min-width: 1px;
  width: 1px;
  height: 1.5rem;
  background-color: var(--divider-color);
}

.gap-1, .gap-1-5, .gap-2 {
  & > *:not(:last-child) { margin-right: .25rem; }
  &.reverse {
    flex-direction: row-reverse;
    & > :last-child { margin-right: .25rem; }
    & > :first-child { margin-right: 0; }
  }
}
.gap-1-5 {
  & > * { margin-right: .375rem; }
  &.reverse > :last-child { margin-right: .375rem; }
}
.gap-2 {
  & > * { margin-right: .5rem; }
  &.reverse > :last-child { margin-right: .5rem; }
}

/* --------- */
.sm-tool-icon {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  white-space: nowrap;
  width: fit-content;
  color: var(--theme-caption-color);
  cursor: pointer;
  .icon {
    margin-right: .25rem;
    color: var(--theme-content-dark-color);
    &.small-size {
      width: 1.5rem;
      height: 1.5rem;
    }
  }
  &:hover .icon { color: var(--theme-caption-color); }
}

/* Margins & Paddings */
.step-lr25 + .step-lr25 { margin-left: .25rem; }
.step-lr75 + .step-lr75 { margin-left: .75rem; }
.step-tb75 + .step-tb75 { margin-top: .75rem; }

.ml-1 { margin-left: .25rem; }
.ml-1-5 { margin-left: .375rem; }
.ml-2 { margin-left: .5rem; }
.ml-3 { margin-left: .75rem; }
.ml-4 { margin-left: 1rem; }
.ml-6 { margin-left: 1.5rem; }
.ml-8 { margin-left: 2rem; }
.ml-10 { margin-left: 2.5rem; }
.ml-12 { margin-left: 3rem; }
.ml-22 { margin-left: 5.5rem; }
.ml-auto { margin-left: auto; }
.mr-1 { margin-right: .25rem; }
.mr-1-5 { margin-right: .375rem; }
.mr-2 { margin-right: .5rem; }
.mr-3 { margin-right: .75rem; }
.mr-4 { margin-right: 1rem; }
.mr-6 { margin-right: 1.5rem; }
.mr-8 { margin-right: 2rem; }
.mr-10 { margin-right: 2.5rem; }
.mt-0-5 { margin-top: .125rem; }
.mt-1 { margin-top: .25rem; }
.mt-2 { margin-top: .5rem; }
.mt-3 { margin-top: .75rem; }
.mt-4 { margin-top: 1rem; }
.mt-5 { margin-top: 1.25rem; }
.mt-6 { margin-top: 1.5rem; }
.mt-9 { margin-top: 2.25rem; }
.mt-10 { margin-top: 2.5rem; }
.mt-14 { margin-top: 3.5rem; }
.mb-1 { margin-bottom: .25rem; }
.mb-2 { margin-bottom: .5rem; }
.mb-3 { margin-bottom: .75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.mx-1 { margin: 0 .25rem; }
.mx-2 { margin: 0 .5rem; }
.mx-3 { margin: 0 .75rem; }
.mx-10 { margin: 0 2.5rem; }
.mx-auto { margin: 0 auto; }
.my-4 { margin: 1rem 0; }

.pl-1 { padding-left: .25rem; }
.pl-2 { padding-left: .5rem; }
.pl-3 { padding-left: .75rem; }
.pl-4 { padding-left: 1rem; }
.pl-8 { padding-left: 2rem; }
.pr-1 { padding-right: .25rem; }
.pr-2 { padding-right: .5rem; }
.pr-3 { padding-right: .75rem; }
.pr-4 { padding-right: 1rem; }
.pr-8 { padding-right: 2rem; }
.pr-24 { padding-right: 6rem; }
.pt-2 { padding-top: .5rem; }
.pt-3 { padding-top: .75rem; }
.pt-4 { padding-top: 1rem; }
.pb-2 { padding-bottom: .5rem; }
.pb-3 { padding-bottom: .75rem; }
.pb-4 { padding-bottom: 1rem; }
.pb-6 { padding-bottom: 1.5rem; }
.px-2 { padding: 0 .5rem; }
.px-3 { padding: 0 .75rem; }
.px-4 { padding: 0 1rem; }
.py-4 { padding: 1rem 0; }
.py-10 { padding: 2.5rem 0; }

.p-1 { padding: .25rem; }
.p-2 { padding: .5rem; }
.p-3 { padding: .75rem; }
.p-4 { padding: 1rem; }
.p-6 { padding: 1.5rem; }
.p-10 { padding: 2.5rem; }

/* --------- */
.no-word-wrap { word-wrap: none; }
.relative { position: relative; }
.absolute { position: absolute; }
.abs-lt-content {
  position: absolute;
  top: var(--modal-padding);
  left: var(--modal-padding);
}
.abs-rt-content {
  position: absolute;
  top: var(--modal-padding);
  right: var(--modal-padding);
}
.abs-lb-content {
  position: absolute;
  bottom: var(--modal-padding);
  left: var(--modal-padding);
}
.abs-rb-content {
  position: absolute;
  bottom: var(--modal-padding);
  right: var(--modal-padding);
}
.abs-full-content {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}

.vScroll {
  flex-grow: 1;
  overflow-x: hidden;
  overflow-y: auto;
}

.h-full { height: 100%; }
.h-2 { height: .5rem; }
.h-4 { height: 1rem; }
.h-6 { height: 1.5rem; }
.h-7 { height: 1.75rem; }
.h-8 { height: 2rem; }
.h-9 { height: 2.25rem; }
.h-14 { height: 3.5rem; }
.h-16 { height: 4rem; }
.h-18 { height: 4.5rem; }
.w-full { width: 100%;  }
.w-2 { width: .5rem; }
.w-9 { width: 2.25rem; }
.w-14 { width: 3.5rem; }
.w-16 { width: 4rem; }
.w-24 { width: 6rem; }
.w-60 { width: 15rem; }
.w-85 { width: 21.25rem; }
.w-165 { width: 41.25rem; }
.min-w-0 { min-width: 0; }
.min-w-4 { min-width: 1rem; }
.min-w-9 { min-width: 2.25rem; }
.min-w-80 { min-width: 20rem; }
.min-w-min { min-width: min-content; }
.min-h-0 { min-height: 0; }
.min-h-7 { min-height: 1.75rem; }
.max-h-125 { max-height: 31.25rem; }
.max-h-60 { max-height: 15rem; }
.max-w-60 { max-width: 15rem; }
.clear-mins {
  min-width: 0;
  min-height: 0;
}
.square-36 { width: 2.25rem; height: 2.25rem; }

/* --------- */
.svg-x-small {
  width: .857em;
  height: .857em;
}
.svg-small {
  width: 1.143em;
  height: 1.143em;
}
.svg-medium {
  width: 1.429em;
  height: 1.429em;
}
.svg-large {
  width: 1.715em;
  height: 1.715em;
}
.svg-full {
  width: inherit;
  height: inherit;
}
.svg-x-small, .svg-small, .svg-medium, .svg-large { flex-shrink: 0; }

.svg-mask {
  position: absolute;
  width: 0;
  height: 0;
}

.hover-trans {
  color: var(--theme-content-trans-color);
  cursor: pointer;
  &:hover { color: var(--theme-caption-color); }
  &:active { color: var(--theme-content-accent-color); }
}

/* Link */
a.no-line {
  text-decoration: none;
  color: var(--theme-caption-color);
  &:hover { color: var(--theme-caption-color); }
  &:active { color: var(--theme-content-accent-color); }
  &:visited { color: var(--theme-caption-color); }
}
.cursor-pointer { cursor: pointer; }
.cursor-default { cursor: default; }

.pointer-events-none { pointer-events: none; }
.select-text { user-select: text; }

/* Text */

.fs-title {
  font-weight: 500;
  font-size: 1rem;
  color: var(--caption-color);
  user-select: none;
}
.trans-title {
  text-transform: uppercase;
  font-weight: 600;
  font-size: .75rem;
  color: var(--theme-content-trans-color);
  user-select: none;
}
.text-xs { font-size: .625rem; }
.text-sm { font-size: .75rem; }
.text-md { font-size: .8125rem; }
.text-base {
  font-size: 1rem; /* 16px */
  line-height: 1.5rem; /* 24px */
}
.text-lg { font-size: 1.125rem; }
.font-normal { font-weight: 400; }
.font-medium { font-weight: 500; }
.font-semi-bold { font-weight: 600; }
.fs-bold { font-weight: 500; }
.uppercase { text-transform: uppercase; }
.text-left { text-align: left; }

.over-underline {
  cursor: pointer;
  &:hover { text-decoration: underline; }
}

.text-line-through { text-decoration: line-through; }

.hidden-text {
  position: absolute;
  visibility: hidden;
  overflow: hidden;
  white-space: pre-wrap;
  width: max-content;
  user-select: none;
  min-width: auto;
}
.overflow-label {
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  user-select: none;
  min-width: 0;
}

.lines-limit-2, .lines-limit-4 {
  min-width: 0;
  overflow: hidden;
  visibility: visible;
  display: -webkit-box;
  /* autoprefixer: ignore next */
  -webkit-box-orient: vertical;
}
.lines-limit-2 {
  -webkit-line-clamp: 2;
  line-clamp: 2;  
}
.lines-limit-4 {
  -webkit-line-clamp: 4;
  line-clamp: 4;  
}

.focused-button {
  background-color: var(--theme-button-bg-focused);
  border: 1px solid transparent;

  & > .icon { color: var(--theme-content-trans-color); }
  &.selected {
    background-color: var(--theme-button-bg-focused);
    border: 1px solid var(--theme-bg-accent-color);
  }
  &:hover {
    background-color: var(--theme-button-bg-pressed);
    border: 1px solid var(--theme-bg-accent-color);
    & > .icon { color: var(--theme-caption-color); }
  }
  &:focus {
    border: 1px solid var(--primary-button-focused-border);
    box-shadow: 0 0 0 3px var(--primary-button-outline);
    & > .icon { color: var(--theme-caption-color); }
  }
}

.overflow-x-auto { overflow-x: auto; }
.overflow-y-auto { overflow-y: auto; }
.whitespace-nowrap { white-space: nowrap; }

/* Scrollbars */
.scroll-m-0::-webkit-scrollbar-track { margin: 0; }
.scroll-m-10::-webkit-scrollbar-track { margin: 2.5rem; }

.scroll-bg-accent-color::-webkit-scrollbar-thumb {
  background-color: var(--theme-bg-accent-color);
  &:hover { background-color: var(--theme-menu-divider); }
}
.scroll-divider-color::-webkit-scrollbar-thumb {
  background-color: var(--divider-color);
  &:horizontal { border-radius: .25rem .25rem 0 0; }
  &:hover { background-color: var(--popup-bg-hover); }
}

/* Backgrounds & Colors */
.background-body-color { background-color: var(--body-color); }
.background-accent-bg-color { background-color: var(--accent-bg-color); }
.background-highlight-select { background-color: var(--highlight-select); }

.background-theme-content-accent { background-color: var(--theme-content-accent-color); }
.background-theme-bg-color { background-color: var(--theme-bg-color); }
.background-highlight-red { background-color: var(--highlight-red); }
.background-button-bg-color { background-color: var(--button-bg-color); }
.background-button-bg-enabled { background-color: var(--theme-button-bg-enabled); }
.background-button-noborder-bg-hover { background-color: var(--noborder-bg-hover); }
.background-menu-divider { background-color: var(--theme-menu-divider); }
.background-card-divider { background-color: var(--theme-card-divider); }
.background-primary-color { background-color: var(--primary-button-enabled); }
.background-bg-accent { background-color: var(--theme-bg-accent-color); }
.background-bg-accent-normal { background-color: var(--theme-bg-accent-normal); }

.dark-color { color: var(--dark-color); }
.content-color { color: var(--content-color); }
.content-trans-color { color: var(--theme-content-trans-color); }
.content-accent-color { color: var(--accent-color); }
.content-dark-color { color: var(--theme-content-dark-color); }
.caption-color { color: var(--caption-color); }

.red-color { color: var(--highlight-red); }
.error-color { color: var(--error-color); }

.border-radius-4 { border-radius: 1rem; }
.border-radius-3 { border-radius: 0.75rem; }
.border-radius-2 { border-radius: 0.5rem; }
.border-radius-1 { border-radius: 0.25rem; }
.border-radius-left-1 { border-top-left-radius: 0.25rem; border-bottom-left-radius: 0.25rem; }
.border-radius-right-1 { border-top-right-radius: 0.25rem; border-bottom-right-radius: 0.25rem; }
.border-radius-top-1 { border-top-right-radius: 0.25rem; border-top-left-radius: 0.25rem; }
.border-bg-accent {border: 1px solid var(--theme-bg-accent-color);}
.border-primary-button { border-color: var(--primary-button-border); }
.border-button-enabled { border: 1px solid var(--theme-button-border-enabled); }

.bottom-divider { border-bottom: 1px solid var(--divider-color); }
.bottom-highlight-select { border-bottom: 1px solid var(--highlight-select); }