/* This Source Code Form is subject to the terms of the Creative Commons
 * Attribution-NonCommercial-ShareAlike International License, v. 4.0.
 * If a copy of the CC BY-NC-SA 4.0 was not distributed with this file,
 * You can obtain one at http://creativecommons.org/licenses/by-nc-sa/4.0/ */

:root {
  --script-icon-size: 32px;
}

#categories {
  .category {
    cursor: default;
    text-decoration: none;

    &[name='scripts'] {
      background-image: url('chrome://browser/skin/trending.svg');
    }

    &[name='settings'] {
      background-image: url('chrome://global/skin/icons/settings.svg');
    }
  }
}

.view-header {
  display: inline;

  .sticky-container {
    padding-bottom: 16px;

    .main-search {
      padding-bottom: 30px;

      .search-textbox {
        display: flex;
        cursor: text;
        width: 20em;
        min-height: 32px;
        box-sizing: border-box;
        margin: 0;
        padding: 2px 8px 3px;
        appearance: none;
        border: 1px solid var(--in-content-box-border-color);
        border-radius: 4px;
        color: inherit;
        background-color: var(--in-content-box-background);

        &:focus-within {
          border-color: transparent;
          outline: var(--in-content-focus-outline);
          outline-offset: -1px;
        }

        input {
          border: none;
          padding: 0 1px;
          background-color: transparent;
          outline: none;
          color: inherit;
          font: inherit;
          text-shadow: inherit;
          box-sizing: border-box;
          flex: 1;
          min-width: 0;
          text-align: inherit;
        }

        .textbox-search-sign {
          width: 12px;
          background: url('chrome://global/skin/icons/search-textbox.svg') no-repeat center/contain;
          margin-inline-end: 5px;
          pointer-events: none;

          &:-moz-locale-dir(rtl) {
            transform: scaleX(-1);
          }
        }

        .textbox-search-clear {
          margin: revert;
          padding: revert;
          min-height: revert;
          min-width: revert;
          width: 14px;
          background: url('resource://content-accessible/searchfield-cancel.svg') no-repeat center/14px;
          margin-inline-start: 5px;

          &:not([disabled]) {
            cursor: default;
          }
        }
      }

      .search-spacer {
        min-height: 32px;
      }
    }

    .main-heading {
      min-height: 32px;
      padding: 0;

      .back-button {
        height: 32px;
        width: 32px;
      }

      .header-button-description:not(:empty) {
        margin-inline: 8px;
      }

      .header-button-box button {
        min-height: 32px;
        padding-block: 0;
        margin: 0;
      }
    }

    .message-box {
      margin-top: 4px;
      margin-inline-start: var(--main-margin-start);
      max-width: var(--section-width);

      p {
        margin: 0;
        line-height: 1.8em;
      }
    }
  }
}

#main {
  margin-block: 16px 30px;

  .script.card {
    margin-bottom: var(--card-padding);
    transition: opacity 150ms, box-shadow 150ms;
    overflow: hidden;
    border: 0;
    padding: var(--card-padding);

    .script-card-collapsed {
      display: flex;

      .script-icon {
        flex-shrink: 0;
        width: var(--script-icon-size);
        height: var(--script-icon-size);
        margin-inline-end: 16px;
        -moz-context-properties: fill;
        fill: currentColor;
      }

      .card-contents {
        word-break: break-word;
        flex-grow: 1;
        display: flex;
        flex-direction: column;

        .script-name-container {
          /* Subtract the top line-height so the text and icon align at the top. */
          margin-top: -3px;
          display: flex;
          align-items: center;

          .script-name,
          .script-version {
            white-space: nowrap;
            overflow: clip;
            text-overflow: ellipsis;
            min-width: 0;
          }

          .script-name-button {
            appearance: none;
            min-width: 0;
            font-weight: revert;
            background: none;
            padding: 0;
            margin: 0;
            border: 0;
            color: inherit;
            cursor: inherit;
            min-height: 0;
            margin-inline-end: 8px;
            opacity: 1;
            user-select: auto;
            outline: none;
            box-shadow: none;
          }

          .script-name {
            font-size: 16px;
            font-weight: 600;
            line-height: 22px;
            margin: 0;
          }

          .script-version {
            font-size: 14px;
            color: var(--in-content-deemphasized-text);
            font-weight: 400;
          }

          .spacer {
            min-width: 10px;
          }
        }

        .script-description {
          font-size: 14px;
          line-height: 20px;
          color: var(--in-content-deemphasized-text);
          font-weight: 400;
          text-overflow: ellipsis;
          overflow: hidden;
        }
      }
    }

    .script-card-message {
      display: flex;
      flex-flow: row nowrap;
      overflow: hidden;
      border-radius: 4px;
      border-top-left-radius: 0;
      border-top-right-radius: 0;
      margin: 8px calc(var(--card-padding) * -1) calc(var(--card-padding) * -1);
      --info-icon-url: url('chrome://global/skin/icons/info-filled.svg');
      --warn-icon-url: url('chrome://global/skin/icons/warning.svg');
      --success-icon-url: url('chrome://global/skin/icons/check.svg');
      --error-icon-url: url('chrome://global/skin/icons/error.svg');
      --icon-size: 16px;
      --message-bar-background-color: var(--in-content-box-info-background);
      --message-bar-text-color: var(--in-content-text-color);
      --message-bar-icon-url: var(--info-icon-url);

      &[type='warning'] {
        --message-bar-background-color: hsla(48deg, 100%, 66%, 20%);
        --message-bar-icon-url: var(--warn-icon-url);
      }

      &[type='success'] {
        --message-bar-background-color: hsla(119deg, 80%, 66%, 20%);
        --message-bar-icon-url: var(--success-icon-url);
      }

      &[type='error'] {
        --message-bar-background-color: hsla(2deg, 100%, 66%, 15%);
        --message-bar-icon-url: var(--error-icon-url);
      }

      &[type='critical'] {
        --message-bar-background-color: hsla(0deg, 100%, 60%, 25%);
        --message-bar-icon-url: var(--error-icon-url);
      }

      .message-inner {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 8px;
        flex-grow: 1;
        background: var(--message-bar-background-color);
        color: var(--message-bar-text-color);

        .message-icon {
          padding: 4px;
          width: var(--icon-size);
          height: var(--icon-size);
          flex-shrink: 0;

          &::after {
            appearance: none;
            -moz-context-properties: fill, stroke;
            fill: currentColor;
            stroke: currentColor;
            content: var(--message-bar-icon-url);
          }
        }

        .message-content {
          margin-inline-start: 8px;
          display: flex;
          align-items: center;
          word-break: break-word;
          flex-flow: row nowrap;
          flex-grow: 1;
          justify-content: space-between;
          white-space: nowrap;

          .message-text {
            white-space: break-spaces;
            flex-shrink: 1;
            flex-grow: 1;
            overflow: hidden;
            overflow-wrap: break-word;
            text-overflow: ellipsis;
            text-align: start;
          }

          .update-button {
            min-width: -moz-fit-content !important;
            display: inline-block;
            flex-shrink: 0;
            margin: 0;
          }
        }
      }

      &:not([hidden]) + .script-card-expanded {
        .script-detail-rows {
          > :first-child {
            border-top: none;
          }
        }
      }

      &[hidden] + .script-card-expanded {
        .script-detail-rows {
          > :first-child {
            margin-top: var(--card-padding);
          }
        }
      }
    }

    .script-card-expanded {
      color: var(--in-content-deemphasized-text);

      .script-detail-rows {
        .script-detail-description-wrapper {
          border-top: 1px solid var(--in-content-border-color);
          margin: 0 calc(var(--card-padding) * -1);
          padding: var(--card-padding);
          color: var(--in-content-text-color);
          cursor: default;

          .script-detail-description {
            > * {
              margin: 0;
            }

            > .line-break {
              white-space: pre-wrap;

              :is(ol, ul) {
                white-space: normal;
              }

              > * {
                margin-block: 0;
              }
            }

            code {
              font-size: 85%;
              cursor: text;
            }

            .syntax-highlighted-code {
              code {
                background: none !important;
              }
            }

            :not(.syntax-highlighted-code) > code {
              background: var(--in-content-box-background-odd);
              padding: 0.15em 0.4em;
              border-radius: 4px;
              font-family: 'Fira Code', 'Fira Mono', SFMono-Regular, 'SF Mono', Menlo, Consolas, 'DejaVu Sans Mono', 'Liberation Mono', ui-monospace, monospace;
              white-space: break-spaces;
            }
          }

          button.script-detail-description-toggle {
            display: flex;
            min-width: 0;
            align-items: center;
            margin-top: 8px;
            font-weight: normal;
            gap: 4px;
          }

          &.script-detail-description-collapse {
            .script-detail-description {
              max-height: 20rem;
              overflow: hidden;
            }
          }
        }

        .script-detail-row {
          display: flex;
          justify-content: space-between;
          gap: var(--card-padding);
          align-items: center;
          border-top: 1px solid var(--in-content-border-color);
          margin: 0 calc(var(--card-padding) * -1);
          padding: var(--card-padding);
          color: var(--in-content-text-color);
          cursor: default;

          .script-detail-label {
            white-space: nowrap;
          }

          > :last-child {
            text-align: end;
          }
        }
      }
    }

    &:hover {
      box-shadow: var(--card-shadow);
    }

    &[active='false']:not([expanded], :hover) {
      opacity: 0.6;
    }

    &:not([expanded]) {
      cursor: pointer;
      user-select: none;

      &:hover {
        box-shadow: var(--card-shadow-hover);
      }

      &[focused] {
        outline: none;
        --card-outline-color: color-mix(in srgb, var(--in-content-accent-color) 70%, transparent);

        box-shadow: var(--card-shadow), 0 0 0 5px var(--card-outline-color);
      }

      .card-contents {
        width: 1px;
        white-space: nowrap;

        .script-name {
          text-overflow: ellipsis;
          overflow-x: hidden;
        }
      }
    }

    &[expanded] {
      cursor: default;
      padding-bottom: 0;

      .script-card-collapsed {
        .card-contents {
          width: 100%;

          .script-description {
            white-space: nowrap;
          }
        }
      }

      .script-card-message {
        border-radius: 0;
        margin-bottom: 0;
      }
    }
  }

  #settings {
    .settings-group {
      margin: 0 0 32px;

      h2 {
        margin: 16px 0 4px;
        font-size: 1.14em;
        line-height: normal;
      }
    }
  }
}

.setting-container {
  display: flex;
  align-items: center;

  .checkbox-container {
    display: flex;
    align-items: center;
    margin: 4px 2px;

    &.tail-with-learn-more {
      margin-inline: 0 10px;
    }

    .checkbox-text {
      margin: 1px 0;
      line-height: 1.8em;
    }
  }
}

/* PeriodInput.jsx */
.period-input {
  display: flex;
  align-items: center;
  border: 1px solid var(--in-content-box-border-color);
  border-radius: 4px;
  background-color: var(--in-content-box-background);
  padding: 7px 4px;
  margin: 0 10px;
  outline-offset: -1px; /* Prevents antialising around the corners */
  cursor: text;

  &:focus-within {
    border-color: transparent;
    outline: 2px solid var(--in-content-focus-outline-color);
  }

  .period-input-field {
    display: inline-grid;
    grid-auto-flow: column;
    margin: 0 0.2em;
    border-bottom: 1px solid var(--in-content-box-border-color);
    pointer-events: none;

    &:focus-within {
      outline: none;
      border-bottom-color: var(--in-content-focus-outline-color);
    }

    .period-input-sizer,
    input {
      grid-area: 1/1;
      font: inherit;
      text-align: end;
      background: none;
      border: none;
      border-radius: 0;
      box-sizing: border-box;
      padding: 0;
      padding-inline: 0.5em 1em;
      margin: 0;
      color: inherit;
      outline: none;
    }

    input {
      width: 0;
      min-width: 100%;
      pointer-events: auto;
    }

    .period-input-sizer {
      width: auto;
      min-width: 0;
      visibility: hidden;
      pointer-events: none;
      white-space: pre-wrap;
    }

    span {
      margin: 0;
      opacity: 0.54;
      padding-inline: 0.1em 0.5em;
      margin-inline-start: -1em;
      pointer-events: none;
      text-align: end;
    }
  }

  &.error {
    border-color: transparent;
    outline: 2px solid color-mix(in srgb, var(--in-content-border-invalid) 30%, transparent);

    &:focus-within {
      outline-color: var(--in-content-border-invalid);
    }

    .period-input-field:focus-within {
      border-bottom-color: var(--in-content-border-invalid);
    }
  }
}

.period-input-error-message {
  color: var(--in-content-error-text-color);
}

// copied from toggle-button.css (which has been replaced with a storybook
// component that we can't use with React, moz-toggle)
input[type='checkbox'].toggle-button {
  --button-height: 16px;
  --button-half-height: 8px;
  --button-width: 26px;
  --button-border-width: 1px;

  /* dot-size = button-height - 2*dot-margin - 2*button-border-width */
  --dot-size: 10px;
  --dot-margin: 2px;

  /* --dot-transform-x = button-width - 2*dot-margin - dot-size - 2*button-border-width */
  --dot-transform-x: 10px;
  --border-color: hsla(210deg,4%,10%,14%);
}

input[type='checkbox'].toggle-button {
  appearance: none;
  padding: 0;
  margin: 0;
  border: var(--button-border-width) solid var(--border-color);
  height: var(--button-height);
  width: var(--button-width);
  border-radius: var(--button-half-height);
  background: var(--in-content-button-background);
  box-sizing: border-box;
}

input[type='checkbox'].toggle-button:enabled:hover {
  background: var(--in-content-button-background-hover);
  border-color: var(--border-color);
}

input[type='checkbox'].toggle-button:enabled:active {
  background: var(--in-content-button-background-active);
  border-color: var(--border-color);
}

input[type='checkbox'].toggle-button:checked {
  background: var(--in-content-primary-button-background);
  border-color: var(--in-content-primary-button-background-hover);
}

input[type='checkbox'].toggle-button:checked:hover {
  background: var(--in-content-primary-button-background-hover);
  border-color: var(--in-content-primary-button-background-active);
}

input[type='checkbox'].toggle-button:checked:active {
  background: var(--in-content-primary-button-background-active);
  border-color: var(--in-content-primary-button-background-active);
}

input[type='checkbox'].toggle-button::before {
  display: block;
  content: '';
  background: #FFF;
  height: var(--dot-size);
  width: var(--dot-size);
  margin: var(--dot-margin);
  border-radius: 50%;
  outline: 1px solid var(--border-color);
  transition: transform 100ms;
  transform: translate(0, calc(50% - var(--dot-size) / 2));
}

input[type='checkbox'].toggle-button:checked::before {
  transform: translate(var(--dot-transform-x), calc(50% - var(--dot-size) / 2));
}

input[type='checkbox'].toggle-button:-moz-locale-dir(rtl)::before,
input[type='checkbox'].toggle-button:dir(rtl)::before {
  scale: -1;
}
