@use 'sass:color';
@use 'sass:math';

// Colors related to torrent status
$blue-100: #dbedff;
$blue-300: #79b8ff;
$green-200: #bef5cb;
$green-300: #85e89d;
$green-500: #28a745;
$grey-200: #e1e4e8;
$grey-500: #828282;
$grey-700: #373737;
$grey-800: #292929;
$grey-900: #191919;
$red-500: #d73a49;
$white: #fff;
$yellow-300: #ffea7f;
$grey-40: #666;
$nice-grey: #f8f8f8;
$nice-grey-darker: #f0f0f0;
$dark-mode-black: #121212;
$default-accent-color: #fff8c5;
$default-accent-color-dark: #0c2d6b;
$default-border-dark: #575757;
$default-border-light: #aeaeae;

// Z-INDEX ENUM
// $z-index-progressbar: 1;
$z-index-popup: 2;

// ICONS -- see assets/img/README.md for sources and license details
// Are you a designer? New icon PRs welcomed!
$image-alt-speed-disabled: '../img/modern-tortoise.png';
$image-alt-speed-enabled: '../img/modern-tortoise-blue.png';
$image-baseline: '../img/horizontal-rule.svg';
$image-chevron-dn: '../img/chevron-down.svg';
$image-chevron-up: '../img/chevron-up.svg';
$image-lock-fill: '../img/lock-fill.svg';
$image-magnet: '../img/magnet.svg';
$image-pause-circle-active: '../img/pause-circle-active.svg';
$image-pause-circle-idle: '../img/pause-circle-idle.svg';
$image-play-circle-active: '../img/play-circle-active.svg';
$image-play-circle-idle: '../img/play-circle-idle.svg';

/// MIXINS

@mixin for-phone-only {
  @media (max-width: 599px) {
    @content;
  }
}

@mixin for-tablet-portrait-up {
  @media (min-width: 600px) {
    @content;
  }
}

@mixin button {
  border: 1px solid var(--color-border);
  cursor: pointer;
  display: inline-block;
  padding: 3px;
  user-select: none;
}

/// GLOBAL

:root {
  --progress: 100%;
  --color-fg-error: #{$red-500};
  --color-fg-port-closed: #{$red-500};
  --color-fg-port-open: #{$green-500};
  --color-progressbar-background-2: #{$grey-500};
  --color-progressbar-verify: #{$yellow-300};
  --color-progressbar-magnet: #{$yellow-300};
  --color-progressbar-paused: #{$grey-200};
  --color-progressbar-leech: #{$blue-300};
  --color-progressbar-queued: #{$blue-100};

  color-scheme: light dark;

  @media (prefers-color-scheme: dark) {
    --color-bg-hover: #{$grey-40};
    --color-fg-primary: #fff;
    --color-bg-primary: #{$grey-800};
    --color-bg-primary-hover: #{$grey-700};
    --color-bg-odd: #{$grey-900};
    --color-bg-even: #{$grey-800};
    --color-bg-menu: #{$grey-800};
    --color-fg-secondary: #{$nice-grey};
    --color-fg-on-popup: #{$nice-grey};
    --color-fg-disabled: #{$nice-grey};
    --color-bg-popup: #{$grey-800};
    --color-bg-warn: #cf6679;
    --color-fg-warn: #{$dark-mode-black};
    --color-border: #{$nice-grey};
    --color-border-selected: #d0d7de;
    --color-fg-tertiary: #{$grey-500};
    --color-toolbar-background: #{$grey-800};
    --color-inspector-background: #{$grey-800};
    --color-inspector-tabs: #{$nice-grey};
    --color-bg-selected: #{$default-accent-color-dark};
    --color-bg-tabs: #{$grey-700};
    --color-progressbar-background-1: #426389;
    --color-default-border: #{$default-border-dark};
    --color-progressbar-seed-1: #{$green-500};
    --color-progressbar-seed-2: #{$green-300};
    --color-progressbar-paused: #{$grey-500};
    --color-progressbar-seed-paused: #{$grey-500};
  }
  @media (prefers-color-scheme: light) {
    --color-bg-hover: #{$nice-grey};
    --color-fg-primary: #404040;
    --color-bg-primary: #fff;
    --color-bg-even: #{$white};
    --color-bg-odd: #{$nice-grey};
    --color-bg-menu: #{$nice-grey};
    --color-fg-on-popup: #{$grey-900};
    --color-bg-popup: #{$white};
    --color-fg-secondary: #{$grey-500};
    --color-border: #{$grey-500};
    --color-border-selected: #d0d7de;
    --color-fg-tertiary: #{$grey-500};
    --color-bg-warn: #e4606d5b;
    --color-fg-warn: #cf212e;
    --color-fg-disabled: #{$grey-500};
    --color-toolbar-background: #{$nice-grey};
    --color-inspector-background: #{$white};
    --color-bg-tabs: #{$nice-grey-darker};
    --color-inspector-tabs: #{$nice-grey};
    --color-bg-selected: #{$default-accent-color};
    --color-progressbar-background-1: #{$nice-grey};
    --color-default-border: #{$default-border-light};
    --color-dialog-border: #{$nice-grey};
    --color-progressbar-seed-1: #{$green-300};
    --color-progressbar-seed-2: #{$green-200};
    --color-progressbar-seed-paused: #{$grey-200};
  }
}

html,
body {
  color: var(--color-fg-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,
    Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
  height: 100%;
  margin: 0;
}

img {
  border: 0;
}

a {
  color: var(--color-fg-primary);
  outline: 0;
  text-decoration: underline;
}

.hidden {
  display: none;
}

.even {
  background-color: var(--color-bg-even);
}

.odd {
  background-color: var(--color-bg-odd);
}

.mainwin {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;

  > * {
    margin: 0;
    padding: 0;
  }
}

.mainwin-workarea {
  display: flex;
  flex: 1;
  flex-direction: row;
  overflow: auto;
}

input {
  border: 1px solid var(--color-border);
  border-radius: 3px;
  padding: 4px 5px;
}

/// TOOLBAR

$toolbar-height-number: 50;
$toolbar-height: $toolbar-height-number * 1px;

#mainwin-toolbar {
  align-items: center;
  background: var(--color-toolbar-background);
  border-bottom: 1px solid var(--color-default-border);
  display: flex;
  flex-direction: row;
  height: $toolbar-height;
  margin: 0;
  width: 100%;

  button {
    background-color: transparent;
    background-position: center;
    background-repeat: no-repeat;
    border: 0;
    border-radius: 5px;
    cursor: pointer;
    height: $toolbar-height;
    margin-right: 6px;
    user-select: none;
    width: $toolbar-height;

    svg {
      stroke: var(--color-fg-primary); // ios only? idk yet
    }

    &:disabled {
      cursor: default;
      opacity: 0.25;
    }
  }

  > .toolbar-separator {
    border-left: 1px solid var(--color-default-border);
    height: 25px;
    margin: 0 6px 0 0;
  }

  :nth-last-child(2) {
    border: 0;
    flex-grow: 1;
  }
}

.toolbar-icon {
  stroke: var(--color-fg-primary);
}

#toolbar-inspector {
  svg {
    color: var(--color-fg-primary);
  }
}

#toolbar-overflow {
  margin-right: 4px;

  svg {
    fill: var(--color-fg-primary);
    height: 36px;
    width: 36px;
  }

  &.alt-speed-enabled {
    background-image: url($image-alt-speed-enabled);
    background-position: bottom left;
    background-size: 20px;
  }
}

/// FILTERBAR

.mainwin-filterbar {
  align-items: center;
  background: var(--color-toolbar-background);
  border-bottom: 1px solid var(--color-default-border);
  display: flex;
  flex-direction: row;
  height: 30px;
  width: 100%;

  @include for-phone-only {
    padding: 5px 10px;

    :not(select):not(input):not(option) {
      display: none;
    }

    #torrent-search {
      padding: 5px;
    }
  }

  > * {
    margin-right: 5px;
    padding: 0 5px;
  }
}

$speed-icon-size: 20px;

.speed-up-icon {
  fill: var(--color-fg-primary);
  margin: 0 auto;

  svg {
    width: $speed-icon-size;
  }
}

.speed-dn-icon {
  fill: var(--color-fg-primary);
  margin: 0 auto;

  svg {
    width: $speed-icon-size;
  }
}

#speed-dn-label,
#speed-up-label {
  text-align: right;
  width: 70px;
}

/// TORRENT CONTAINER

$pauseresume-size-number: 20;
$pauseresume-size: $pauseresume-size-number * 1px;
$progressbar-border: 1;
$progressbar-height: 20;
$popup-top: 61px; // TODO: ugly that this is hardcoded

.flex {
  flex-grow: 1;
}

#torrent-container {
  flex-grow: 1;
  left: 0;
  margin: 0;
  overflow: auto;
  padding: 0;
  right: 0;
}

.torrent-container {
  background-color: $white;
}

$app-image: '../img/box.svg';
$audio-image: '../img/music.svg';
$folder-image: '../img/folder.svg';
$font-image: '../img/type.svg';
$image-image: '../img/image.svg';
$package-image: '../img/package.svg';
$text-image: '../img/file-text.svg';
$video-image: '../img/film.svg';

@mixin mime-icon-compact($mime-icon) {
  &[data-icon-multifile='true'] {
    background-image: url($folder-image);
    background-position: center;
    background-size: 16px;
  }
}

@mixin mime-icon($mime-icon) {
  // background-image: url($mime-icon);
  background-color: var(--color-fg-primary);
  -webkit-mask-image: url($mime-icon);
  mask-image: url($mime-icon);
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;

  &[data-icon-multifile='true'] {
    -webkit-mask-image: url($mime-icon), url($folder-image);
    mask-image: url($mime-icon), url($folder-image);
    -webkit-mask-position: top left, bottom right;
    mask-position: top left, bottom right;
    -webkit-mask-repeat: no-repeat, no-repeat;
    mask-repeat: no-repeat, no-repeat;
    -webkit-mask-size: 16px, 16px;
    mask-size: 16px, 16px;
  }
}

.torrent-list {
  cursor: pointer;
  list-style-type: none;
  margin: 0;
  padding: 0;
  text-align: left;
  width: 100%;

  .torrent {
    border-bottom: 1px solid var(--color-default-border);
    user-select: none;

    .icon {
      // color the background svg fill
      background-color: var(--color-fg-primary);
      background-position: center, top left;

      &[data-icon-mime-type='audio'] {
        @include mime-icon($audio-image);
      }

      &[data-icon-mime-type='application'] {
        @include mime-icon($app-image);
      }

      &[data-icon-mime-type='font'] {
        @include mime-icon($font-image);
      }

      &[data-icon-mime-type='image'] {
        @include mime-icon($image-image);
      }

      &[data-icon-mime-type='model'] {
        @include mime-icon($package-image);
      }

      &[data-icon-mime-type='text'] {
        @include mime-icon($text-image);
      }

      &[data-icon-mime-type='video'] {
        @include mime-icon($video-image);
      }
    }

    .torrent-name {
      font-weight: bold;
      margin-bottom: 2px;
      margin-top: 2px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;

      &.compact {
        font-size: 1em;
        font-weight: normal;
      }

      &:not(.paused) {
        color: var(--color-fg-primary);
      }
    }

    .torrent-labels {
      font-size: x-small;
      font-weight: normal;
      margin-bottom: 2px;
      margin-top: 2px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;

      &.compact {
        flex: 1;
        font-size: x-small;
      }
    }

    .torrent-progress-details.error,
    .torrent-peer-details.error {
      color: var(--color-fg-error);
    }

    .torrent-progress-details,
    .torrent-peer-details {
      color: var(--color-fg-primary);
      font-size: x-small;
    }

    &.compact {
      $icon-size-num: 16;
      $icon-size: $icon-size-num * 1px;

      align-items: center;
      display: flex;
      flex-direction: row-reverse;

      .icon {
        flex-shrink: 0;
        height: $icon-size;
        -webkit-mask-size: $icon-size, $icon-size-num * 0.5px;
        mask-size: $icon-size, $icon-size-num * 0.5px;
        width: $icon-size;

        &[data-icon-multifile='true'] {
          @include mime-icon($folder-image);
        }
      }

      > * {
        margin: 5px;
      }
    }

    &:not(.compact) {
      $icon-size-num: 32;
      $icon-size: $icon-size-num * 1px;
      align-items: center;
      display: grid;
      grid-column-gap: 12px;
      grid-template-areas:
        'icon name labels'
        'icon peers peers'
        'icon progressbar progressbar'
        'icon progress-text progress-text';
      grid-template-columns: $icon-size auto 1fr;
      padding: 6px 12px;

      .icon {
        background-size: $icon-size, $icon-size-num * 0.5px;
        grid-area: icon;
        height: $icon-size;
        width: $icon-size;
      }

      .torrent-name {
        color: var(--color-fg-primary);
        grid-area: name;

        &.paused {
          color: var(--color-fg-disabled);
        }
      }

      .torrent-labels {
        grid-area: labels;
      }

      .torrent-peer-details {
        grid-area: peers;
      }

      .torrent-progress {
        display: flex;
        flex-direction: row;
        grid-area: progressbar;
      }

      .torrent-progress-details {
        grid-area: progress-text;
      }

      > * {
        margin: 1px 0;
      }
    }

    &.selected {
      background-color: var(--color-bg-selected);
    }
  }

  .icon {
    background-position: center;
    background-repeat: no-repeat;
  }

  .torrent-pauseresume-button {
    background-position: center center;
    background-repeat: no-repeat;
    background-size: $pauseresume-size;
    margin-left: math.floor(math.div($pauseresume-size-number, 2)) * 1px;
    width: $pauseresume-size;

    &[data-action='pause'] {
      background-image: url($image-pause-circle-idle);

      &:active,
      &:hover {
        background-image: url($image-pause-circle-active);
      }
    }

    &[data-action='resume'] {
      background-image: url($image-play-circle-idle);

      &:active,
      &:hover {
        background-image: url($image-play-circle-active);
      }
    }
  }

  .torrent-progress-bar {
    background-repeat: no-repeat;
    border-color: var(--color-border-selected);
    border-radius: 3px;
    border-style: solid;
    border-width: 1px;
    height: ($progressbar-height - ($progressbar-border * 2)) * 1px;

    &.full {
      flex-grow: 1;
      margin: 2px 0;
    }

    &.compact {
      min-width: 50px;
      width: 10vw;
    }

    &.leech.queued {
      background: linear-gradient(
          to right,
          var(--color-progressbar-queued) 0,
          var(--color-progressbar-queued) var(--progress, 30%),
          transparent var(--progress, 30%)
        ),
        no-repeat;
    }

    &.leech {
      background: linear-gradient(
          to right,
          var(--color-progressbar-leech) 0,
          var(--color-progressbar-leech) var(--progress, 30%),
          transparent var(--progress, 30%)
        ),
        no-repeat;
    }

    &.magnet {
      background: linear-gradient(
          to right,
          var(--color-progressbar-magnet) 0,
          var(--color-progressbar-magnet) var(--progress, 30%),
          transparent var(--progress, 30%)
        ),
        no-repeat;
    }

    &.seed.paused {
      background-color: var(--color-progressbar-seed-paused);
    }

    &.seed {
      background-color: var(--color-progressbar-seed-1);
    }

    &.seed.full:not(.paused) {
      background: linear-gradient(
          to right,
          var(--color-progressbar-seed-1) 0,
          var(--color-progressbar-seed-1) var(--progress, 30%),
          var(--color-progressbar-seed-2) var(--progress, 30%)
        ),
        no-repeat;
    }

    &.seed.queued {
      background-color: var(--color-progressbar-seed-paused);
    }

    &.verify {
      background: linear-gradient(
          to right,
          var(--color-progressbar-verify) 0,
          var(--color-progressbar-verify) var(--progress, 30%),
          transparent var(--progress, 30%)
        ),
        no-repeat;
    }

    &.paused {
      background: linear-gradient(
          to right,
          var(--color-progressbar-paused) 0,
          var(--color-progressbar-paused) var(--progress, 30%),
          transparent var(--progress, 30%)
        ),
        no-repeat;
    }
  }
}

/// PREFERENCES DIALOG

@include for-phone-only {
  html,
  body {
    overflow: hidden;
  }

  input[type='checkbox'] {
    height: 20px;
    width: 20px;
  }
}

#inspector,
#prefs-dialog {
  @include for-phone-only {
    left: 0;
  }
  @include for-tablet-portrait-up {
    border-left: 1px solid var(--color-default-border);
    width: 570px;
  }
}

#prefs-dialog {
  $background-color: var(--color-inspector-background);
  background: $background-color;
  border: 0;
  bottom: 0;
  box-shadow: 0 3px 6px -4px #0000001f, 0 6px 16px #00000014,
    0 9px 28px 8px #0000000d;
  position: absolute;
  right: 0;
  top: $popup-top;
  z-index: $z-index-popup;

  .tabs-page {
    grid-column-gap: 8px;
    grid-row-gap: 5px;
    grid-template-columns: 1fr 1fr;
    margin: 20px;

    &:not(.hidden) {
      display: grid;
    }

    .section-label {
      font-weight: bold;
      grid-column: span 2;
      // margin-left: -20px;
      padding-bottom: 5px;

      &:not(:first-of-type) {
        margin-top: 20px;
      }
    }
  }

  .alt-speed-section-label {
    background: transparent url($image-alt-speed-enabled) no-repeat;
    background-position: left;
    background-position-y: 4px;
    background-size: 20px;
    padding-left: 22px;
  }

  :disabled,
  .disabled {
    color: var(--color-fg-disabled);
  }

  #alt-times-div,
  #autostart-div,
  #port-forwarding,
  #randomize-port,
  #suffix-div,
  #use-dht-div,
  #use-lpd-div,
  #use-pex-div,
  #utp-enabled,
  .alt-speed-label {
    grid-column: span 2;
  }

  #default-trackers {
    height: 300px;
  }

  .blocklist-size-label,
  .blocklist-update-button,
  .register-handler-button,
  .port-status {
    grid-column: 2 / 3;
  }

  .blocklist-size-label {
    font-size: smaller;
  }

  .blocklist-size-number {
    font-weight: bolder;
  }

  .port-status-label {
    display: inline-block;
    font-weight: bold;
    margin-left: 5px;

    &[data-open='true'] {
      color: var(--color-fg-port-open);
    }

    &[data-open='false'] {
      color: var(--color-fg-port-closed);
    }
  }

  #default-trackers,
  .default-trackers-label {
    grid-column: 1 / 3;
  }

  .alt-speed-label {
    font-size: smaller;
    font-style: lighter;
    // nudge it up next to the section label
    margin: -10px 0 10px;
  }
}

#prefs-dialog.ui-tabs .ui-tabs-panel {
  padding: 0;
  user-select: none;
}

.prefs-section {
  text-align: left;

  > * {
    padding: 0 8px 8px;
  }

  .title {
    color: var(--color-fg-primary);
    font-size: larger;
    font-weight: bold;
    margin-bottom: 10px;
    padding-left: 0;
  }

  .row {
    .key {
      float: left;
      padding-top: 3px;

      > * {
        margin-left: 0;
      }
    }

    .value {
      margin-left: 150px;

      > * {
        width: 100%;
      }
    }
  }
}

/// TABS

.tabs-container {
  align-items: stretch;
  background: var(--color-inspector-background);
  bottom: 0;
  display: flex;
  flex-direction: column;
  position: absolute;
  right: 0;
  top: $popup-top;
  z-index: $z-index-popup;
  @include for-phone-only {
    left: 0;
  }
  @include for-tablet-portrait-up {
    width: 550px;
  }
}

.tabs-buttons {
  align-self: center;
  background-color: var(--color-bg-tabs);
  border: 1px solid var(--color-border-selected);
  border-radius: 6px;
  display: flex;
  margin: 10px 0;

  button {
    appearance: none;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--color-fg-primary);
  }
}

.tabs-pages {
  box-sizing: border-box;
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  @include for-phone-only {
    padding: 0 8px 20px;
  }
  @include for-tablet-portrait-up {
    padding: 0 20px 20px;
  }
}

.tabs-button {
  background-color: var(--color-bg-tabs);
  border: 1px solid transparent;
  font-size: 14px;
  padding: 3px 8px;

  &:active,
  &:checked,
  &.selected {
    background-color: var(--color-bg-even);
    border: 1px solid var(--color-fg-primary);
    border-radius: 6px;
    font-weight: 500;
  }
}

/// INSPECTOR

#inspector {
  box-shadow: 0 3px 6px rgba(58, 58, 58, 0.7);
}

.inspector-info-page {
  font-size: 14px;
  // TODO: this is (mostly) copied from prefs-dialog.
  // can it be folded into a single set of rules?

  grid-column-gap: 8px;
  grid-row-gap: 8px;
  grid-template-columns: auto 1fr;
  margin: 20px;
  padding: 12px;

  &:not(.hidden) {
    display: grid;
  }

  .section-label {
    font-size: 16px;
    font-weight: bold;
    grid-column: span 2;
    padding-bottom: 5px;

    &:not(:first-of-type) {
      margin-top: 20px;
    }
  }

  label {
    font-weight: 500;
  }

  :not(.section-label) {
    // this section is not copied
    overflow-x: hidden;
    text-overflow: ellipsis;
  }
}

.inspector-info-magnet {
  button {
    background-color: var(--color-border);

    background-position: top;
    background-repeat: no-repeat;
    border: 0;
    cursor: pointer;
    height: 1rem;
    -webkit-mask: url($image-magnet) no-repeat center / 14px;
    mask: url($image-magnet) no-repeat center / 14px;
    vertical-align: middle;
    width: 1rem;
  }
}

#inspector .tabs-button,
#prefs-dialog .tabs-button {
  height: 30px;
  margin: 0;
  min-width: 40px;
}

#inspector-file-list {
  margin: 0;
  padding: 0;

  .inspector-torrent-file-list-entry {
    display: grid;
    grid-column-gap: 5px;
    grid-template-areas:
      'check   name  priority'
      'blank1  info  blank2';
    grid-template-columns: 20px 1fr 65px;
    margin-bottom: 4px;
    padding: 5px;

    &.skip {
      opacity: 0.5;
    }
  }

  .file-wanted-control {
    grid-area: check;
  }

  .inspector-torrent-file-list-entry-name {
    color: var(--color-fg-primary);
    cursor: pointer;
    font-size: 14px;
    grid-area: name;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .inspector-torrent-file-list-entry.skip
    > .inspector-torrent-file-list-entry-name {
    color: var(--color-fg-disabled);
  }

  .inspector-torrent-file-list-entry-progress {
    color: var(--color-fg-secondary);
    font-size: 12px;
    grid-area: info;
  }

  .single-file .inspector-torrent-file-list-entry > .file-wanted-control,
  .inspector-torrent-file-list-entry.complete > .file-wanted-control {
    cursor: default;
  }
}

#inspector-header {
  margin: 8px 0;
}

#torrent-inspector-name {
  font-size: large;
  font-weight: bold;
}

#inspector-tiers-list {
  color: var(--color-fg-primary);
  margin: 0 10px;
  padding: 0 12px;

  .tier-list-row {
    display: grid;
    font-size: 12px;
    grid-column-gap: 8px;
    grid-row-gap: 4px;
    margin-top: 8px;
  }

  .tier-list-torrent {
    color: var(--color-fg-primary);
    font-weight: bolder;
    margin-left: -12px;
    overflow-x: hidden;
    padding-top: 20px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tier-list-tracker {
    font-size: 14px;
    font-weight: bolder;
    grid-column: span 2;
    margin-top: 8px;
    padding-bottom: 4px;
  }

  .tier-announce,
  .tier-scrape,
  .tier-state {
    text-align: left;
  }

  .tier-downloads,
  .tier-leechers,
  .tier-seeders {
    text-align: right;
  }
}

// Peers Tab

.peer-list {
  $table-border: 1px solid var(--color-default-border);

  border: $table-border;
  border-collapse: collapse;
  cursor: default;
  table-layout: fixed;
  text-align: left;
  width: 100%;

  td,
  th {
    font-size: smaller;
    padding: 5px;
  }

  td {
    border: $table-border;
    color: var(--color-fg-secondary);
    // padding: 5px 10px;
  }

  .torrent-row td {
    background: var(--color-default-border);
    color: var(--color-fg-primary);
    font-size: normal;
    font-weight: bolder;
    overflow-x: hidden;
    padding: 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .encryption {
    &[data-encrypted='true'] {
      background-color: var(--color-border-selected);
      -webkit-mask: url($image-lock-fill) no-repeat center / 14px;
      mask: url($image-lock-fill) no-repeat center / 14px;
      width: 10px;
    }
  }

  .peer-address,
  .percent-done,
  .speed-down,
  .speed-up {
    text-align: right;
  }

  .percent-done {
    width: 10%;

    @include for-phone-only {
      width: 12%;
    }
  }

  .speed-down,
  .speed-up {
    width: 15%;
  }

  .peer-address {
    overflow-x: hidden;
    text-overflow: ellipsis;
    width: 25%;

    @include for-phone-only {
      text-align: left;
      width: 20%;
    }
  }

  .peer-app-name {
    overflow-x: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    @include for-tablet-portrait-up {
      width: 20%;
    }
  }

  .status {
    cursor: pointer;
  }
}

/// FILE PRIORITY BUTTONS

.file-priority-radiobox {
  $size-number: 20;
  $size: $size-number * 1px;
  $halfsize: math.floor(math.div($size-number, 2)) * 1px;

  grid-area: priority;

  > * {
    appearance: none;
    background-color: var(--color-border-selected);
    background-position: center;
    background-repeat: no-repeat;
    background-size: $halfsize, $size;
    border: 1px solid var(--color-border);
    height: $size;
    margin: 0;
    padding: 0;
    width: $size;
  }

  > .low {
    background-image: url($image-chevron-dn);
    border-right-width: 0;
  }

  > .normal {
    background-image: url($image-baseline);
  }

  > .high {
    background-image: url($image-chevron-up);
    border-left-width: 0;
  }

  //if input is checked then change the background color
  > .checked {
    background-color: var(--color-bg-hover);
  }
}

/// CONTEXT MENU

.context-menu {
  $disabled-color: var(--color-fg-disabled);
  background-color: var(--color-bg-primary);
  border-radius: 5px;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.7);
  color: var(--color-fg-on-popup);
  padding: 10px 5px;
  position: absolute;
  z-index: 9999;

  .context-menuitem {
    font-size: 13px;
    font-weight: 400;
    list-style: none;
    margin-right: 10px;
    padding: 5px 15px;

    &:hover:not(:disabled),
    &:focus:not(:disabled) {
      background-color: var(--color-bg-hover);
      border-radius: 6px;
      cursor: pointer;
      font-weight: 500;
    }

    &:disabled {
      color: $disabled-color;
      cursor: none;
    }

    &.warning:hover {
      background-color: var(--color-bg-warn);
      color: var(--color-fg-warn);
    }
  }
}

.context-menu-separator {
  border-bottom: 1px solid var(--color-fg-secondary);
  margin-bottom: 10px;
  padding-bottom: 10px;
}

/// OVERFLOW MENU

.overflow-menu {
  background: var(--color-bg-popup);
  border-radius: 5px;
  box-shadow: 0 3px 6px -4px #0000001f, 0 6px 16px #00000014,
    0 9px 28px 8px #0000000d;
  color: var(--color-fg-on-popup);
  margin: 6px;
  overflow: auto;
  padding: 10px;
  position: absolute;

  right: 0;
  top: 50px;
  z-index: $z-index-popup;

  @include for-phone-only() {
    height: 80vh;
  }

  fieldset {
    border: 0;
    display: block;
    margin: 8px 0;
  }

  fieldset ul {
    margin: 0;
    padding-left: 0;

    li {
      list-style-type: none;
    }

    a {
      cursor: pointer;
    }
  }

  .table-row {
    align-items: center;
    border-radius: 6px;
    display: flex;
    flex-direction: row;
    padding: 3px 0;

    // hide the fullscreen button unless we're on mobile
    @include for-tablet-portrait-up {
      &.display-fullscreen-row {
        display: none;
      }
    }
  }

  legend {
    color: var(--color-fg-primary);
    font-weight: bolder;
    margin: 12px 0 4px;
  }

  a,
  button,
  label {
    display: inline-flex;
    font-size: 1em;
    width: 100%;
  }

  a,
  button {
    background: transparent;
    border: 0;
    cursor: pointer;
    display: block;
    padding: 4px 0;
    text-align: left;
    text-decoration: none;
    width: 150px;
  }

  .input-and-label {
    align-items: center;
    display: inline-flex;
    flex-direction: row;
  }

  #display-options {
    display: flex;
    flex-direction: column;
  }

  #speed-options {
    display: flex;
    flex-direction: column;

    > .speed-up,
    > .speed-down {
      align-items: center;
      display: flex;
      flex-direction: row;
      padding: 4px 0;

      > label {
        overflow: hidden;
        width: 80px;
      }
    }

    .alt-speed {
      display: grid;
      grid-column-gap: 5px;
      grid-row-gap: 5px;
      grid-template-areas:
        'check   lb'
        'turtle  values';
      grid-template-columns: 22px 1fr;
      margin-bottom: 4px;
    }

    #alt-speed-check {
      grid-area: check;

      &:checked ~ #alt-speed-image {
        background-image: url($image-alt-speed-enabled);
        background-position: left;
        background-size: 22px;
      }

      &:not(:checked) ~ #alt-speed-image {
        background-image: url($image-alt-speed-disabled);
        background-size: 22px;
      }
    }

    #alt-speed-image {
      background-position: center;
      background-repeat: no-repeat;
      grid-area: turtle;
    }

    #alt-speed-label {
      grid-area: lb;
    }

    #alt-speed-values-label {
      font-size: small;
      grid-area: values;
    }
  }
}

/// DIALOGS

$dialog-padding-number: 20;
$dialog-logo-padding-number: math.div($dialog-padding-number * 2, 3);
$logo-size: 64px;

@include for-phone-only {
  .dialog-buttons {
    padding-top: $dialog-logo-padding-number * 1px;
  }

  .dialog-container {
    opacity: 96%;
    position: absolute;
    top: $popup-top;
    width: 100%;
  }

  .dialog-logo {
    padding-bottom: $dialog-logo-padding-number * 1px;
  }

  .dialog-window {
    align-items: center;
    display: flex;
    flex-direction: column;
  }
}
@include for-tablet-portrait-up {
  .dialog-container {
    min-width: 500px;
    position: absolute;
    top: $popup-top * 2;
  }

  .dialog-heading {
    grid-area: heading;
  }

  .dialog-logo {
    grid-area: icon;
    padding-right: $dialog-logo-padding-number * 1px;
  }

  .dialog-window {
    background-color: var(--color-bg-popup);
    color: var(--color-fg-on-popup);
    display: grid;
    grid-column-gap: 12px;
    grid-template-areas:
      'icon heading'
      'icon message'
      'icon workarea'
      'icon buttons';
    grid-template-columns: $logo-size 1fr;
    padding: 2px 12px;
  }
}

.dialog-buttons {
  display: flex;
  float: right;
  grid-area: buttons;
  margin: 10px 0 0;
  text-align: center;

  button {
    appearance: none;
    background: var(--color-bg-primary);
    border: 1px solid var(--color-default-border);
    border-radius: 5px;
    color: var(--color-fg-primary);
    margin-left: 8px;
    padding: 8px;
    text-decoration: none;
  }
}

.dialog-buttons-begin {
  flex-grow: 1;
}

.dialog-buttons-end {
  display: none;
}

dialog {
  border: 0;
}

.dialog-container {
  box-shadow: 0 3px 6px -4px #0000001f, 0 6px 16px #00000014,
    0 9px 28px 8px #0000000d;
  color: var(--color-fg-primary);
  display: block;
  padding: 0;
  z-index: $z-index-popup;

  @include for-tablet-portrait-up() {
    border: 0;
    border-radius: 8px;
    max-width: 50%;
  }
}

.dialog-heading {
  align-items: center;
  display: flex;
  font-size: 1.2em;
  font-weight: bold;
}

.dialog-logo {
  background: transparent url('../img/logo.png') top left no-repeat;
  height: $logo-size;
  width: $logo-size;
}

.dialog-message {
  grid-area: message;
  margin: 10px 0 0;
}

.dialog-window {
  background: var(--color-bg-primary);
  border-radius: 8px;
  padding: $dialog-padding-number * 1px;
}

.dialog-workarea {
  display: flex;
  flex-direction: column;
  grid-area: workarea;
  margin: 10px 0 0;

  > * {
    margin-bottom: 5px;
  }
}

/// ABOUT DIALOG

.about-dialog {
  max-width: initial;
}

.about-dialog .dialog-workarea > * {
  margin-bottom: 10px;
}

.about-dialog-version-number {
  margin-left: 4px;
}

.about-dialog-version-checksum {
  font-size: small;
  font-style: italic;
  font-weight: normal;
  margin-left: auto;
  padding-left: 10px;
}

/// OPEN TORRENT DIALOG
.open-torrent {
  input {
    margin-bottom: 15px;
  }

  #auto-start-label {
    margin-left: 5px;
  }

  input[type='file'] {
    box-sizing: border-box;
    width: 100%;
  }
}

/// HOTKEYS DIALOG

.shortcuts-dialog {
  table {
    border-collapse: collapse;
    width: 100%;
  }

  th,
  td {
    border: 1px solid var(--color-border);
    padding: 5px 10px;
  }
}

/// RENAME DIALOG

#torrent-rename-name {
  min-width: 400px;
}

/// SET-LOCATION DIALOG

#move-container #torrent-path {
  min-width: 400px;
}

/// STATISTICS DIALOG

.tabs-pages,
.inspector-info-page,
.statistics-dialog {
  .content {
    column-gap: 16px;
    display: grid;
    grid-row-gap: 6px;
    grid-template-columns: auto 1fr;
    margin-top: 4px;

    @include for-phone-only {
      margin: 4px 0 16px;
    }
    @include for-tablet-portrait-up {
      margin: 4px 16px 16px;
    }

    div {
      word-break: break-word;
    }
  }

  fieldset {
    border: 0;
    margin: 0;
    padding: 0;
  }

  legend {
    font-weight: bolder;
    margin-bottom: 4px;
  }
}

/// UPLOAD DIALOG

#free-space-text {
  display: inline-block;
  font-size: smaller;
  font-style: italic;
}

#torrent-upload-frame {
  border: 0;
  display: block; /* Don't change this : safari forms won't target hidden frames (they open a new window) */
  height: 0;
  left: -1000px;
  margin: 0;
  padding: 0;
  position: absolute;
  top: -1000px;
  width: 0;
}

.ui-menu {
  width: 200px;
}
