// Variables matching sidebar styling
$dialog-bg: #1a1a1a;
$text-primary: rgba(255, 255, 255, 0.95);
$text-secondary: rgba(255, 255, 255, 0.6);
$text-muted: rgba(255, 255, 255, 0.4);
$border-color: rgba(255, 255, 255, 0.08);
$hover-bg: rgba(255, 255, 255, 0.08);
$active-color: #818cf8;
$active-bg: rgba(129, 140, 248, 0.15);
$transition-fast: 150ms ease;
$transition-normal: 200ms ease;

.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  z-index: 12000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn $transition-normal;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.dialog {
  background: $dialog-bg;
  border: 1px solid $border-color;
  border-radius: 12px;
  width: 90%;
  max-width: 520px;
  height: 600px;
  max-height: 85vh;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: slideUp 250ms cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.tabs-row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid $border-color;
  background: rgba(0, 0, 0, 0.2);
  padding: 0 20px;
  justify-content: center;
  position: relative;
}

.tabs {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 1 auto;
}

.tab {
  background: none;
  border: none;
  color: $text-secondary;
  padding: 14px 20px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  position: relative;
  transition: color $transition-fast;
  text-align: center;
  min-width: 90px;
  display: flex;
  align-items: center;
  justify-content: center;

  &:hover {
    color: $text-primary;
  }

  &.active {
    color: $active-color;

    &::after {
      content: '';
      position: absolute;
      left: 16px;
      right: 16px;
      bottom: 0;
      height: 2px;
      background: $active-color;
      border-radius: 1px 1px 0 0;
    }
  }
}

.close-btn {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: $text-muted;
  font-size: 18px;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: background $transition-fast, color $transition-fast;
  line-height: 1;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;

  &:hover {
    background: $hover-bg;
    color: $text-primary;
  }
}

.dialog-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1 1 0;
  min-height: 0;
  max-height: 100%;

  &::-webkit-scrollbar {
    width: 6px;
  }

  &::-webkit-scrollbar-track {
    background: transparent;
  }

  &::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;

    &:hover {
      background: rgba(255, 255, 255, 0.25);
    }
  }
}

.tab-content {
  animation: fadeIn $transition-normal;
}

.section-header {
  color: $text-muted;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 24px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid $border-color;

  &:first-child {
    margin-top: 0;
  }

  &.dark-mode-header {
    display: flex;
    align-items: center;
    font-size: 11px;
    font-weight: 600;
    gap: 30px;
    padding-bottom: 8px;
    margin-bottom: 24px;
    border-bottom: 1px solid $border-color;
  }
}

.mode-switch-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mode-icon {
  font-size: 18px;
  opacity: 0.3;
  transition: all 300ms ease;
  user-select: none;

  &.active {
    opacity: 1;
    transform: scale(1.1);
  }

  &.sun {
    filter: grayscale(100%);

    &.active {
      filter: grayscale(0%);
    }
  }

  &.moon {
    filter: grayscale(100%);

    &.active {
      filter: grayscale(0%);
    }
  }
}

.toggle-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  margin-bottom: 2px;

  span {
    color: $text-primary;
    font-size: 14px;
    font-weight: 500;
  }
}

.switch {
  position: relative;
  width: 44px;
  height: 24px;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: background 300ms ease;
  padding: 0;

  &.active {
    background: $active-color;

    .slider {
      transform: translateX(20px);
    }
  }

  .slider {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: #ffffff;
    border-radius: 50%;
    transition: transform 300ms ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  }

  &:hover {
    background: rgba(255, 255, 255, 0.2);

    &.active {
      background: #9aa3fa;
    }
  }

  &:focus-visible {
    outline: 2px solid $active-color;
    outline-offset: 2px;
  }
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

@media (max-width: 768px) {
  .theme-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.theme-option {
  cursor: pointer;

  input[type="radio"] {
    display: none;
  }

  .theme-card {
    background: rgba(255, 255, 255, 0.03);
    border: 2px solid $border-color;
    border-radius: 8px;
    padding: 10px;
    transition: all $transition-fast;
    display: flex;
    flex-direction: column;
    gap: 8px;

    &:hover {
      background: $hover-bg;
      border-color: rgba(255, 255, 255, 0.15);
    }
  }

  input:checked + .theme-card {
    border-color: $active-color;
    background: $active-bg;
  }

  .theme-colors {
    display: flex;
    gap: 4px;
    height: 24px;
  }

  .color-swatch {
    flex: 1;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.2);
  }

  .theme-name {
    color: $text-primary;
    font-size: 11px;
    font-weight: 500;
    text-align: center;
  }
}

.font-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.font-option {
  background: rgba(255, 255, 255, 0.03);
  border: 2px solid $border-color;
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  transition: all $transition-fast;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;

  &:hover {
    background: $hover-bg;
    border-color: rgba(255, 255, 255, 0.15);
  }

  &.active {
    border-color: $active-color;
    background: $active-bg;
  }

  .font-preview {
    font-size: 24px;
    color: $text-primary;
    line-height: 1;
  }

  .font-name {
    color: $text-secondary;
    font-size: 11px;
    font-weight: 500;
    text-align: center;
  }
}

.control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  min-height: 32px;

  &:last-child {
    margin-bottom: 0;
  }

  > label {
    color: $text-primary;
    font-size: 14px;
    font-weight: 500;
    flex-shrink: 0;
  }

  input[type="range"] {
    flex: 1;
    margin: 0 10px;
    height: 5px;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
    -webkit-appearance: none;

    &::-webkit-slider-thumb {
      -webkit-appearance: none;
      width: 14px;
      height: 14px;
      border-radius: 50%;
      background: $active-color;
      cursor: pointer;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
      transition: all $transition-fast;

      &:hover {
        transform: scale(1.1);
        box-shadow: 0 2px 8px rgba(129, 140, 248, 0.5);
      }
    }

    &::-moz-range-thumb {
      width: 14px;
      height: 14px;
      border-radius: 50%;
      background: $active-color;
      border: none;
      cursor: pointer;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    }
  }

  .value {
    color: $text-secondary;
    font-size: 12px;
    min-width: 42px;
    text-align: right;
    font-variant-numeric: tabular-nums;
  }
}

.control-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.gap-control {
  flex: 1;
  max-width: 200px;
  min-width: 160px;

  input[type="range"] {
    flex: 1;
    margin-right: 8px;
  }

  .value {
    min-width: 38px;
  }
}

.stepper {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.03);
  padding: 3px;
  border-radius: 6px;
  border: 1px solid $border-color;

  button {
    width: 28px;
    height: 28px;
    background: rgba(255, 255, 255, 0.05);
    color: $text-secondary;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all $transition-fast;
    font-weight: 300;

    &:hover {
      background: $hover-bg;
      color: $text-primary;
    }

    &:active {
      transform: scale(0.95);
    }
  }

  span {
    min-width: 48px;
    text-align: center;
    color: $text-primary;
    font-size: 13px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
  }
}

.radio-group {
  display: flex;
  gap: 18px;

  label {
    display: flex;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    font-size: 14px;
    color: $text-primary;
    font-weight: 500;
    position: relative;
    user-select: none;

    input[type="radio"] {
      appearance: none;
      width: 18px;
      height: 18px;
      border: 2px solid $active-color;
      border-radius: 50%;
      background: rgba(255, 255, 255, 0.05);
      margin: 0 6px 0 0;
      outline: none;
      transition: border-color $transition-fast, box-shadow $transition-fast;

      &:checked {
        background: $active-color;
        box-shadow: 0 0 0 2px rgba(129, 140, 248, 0.15);
        border-color: $active-color;
      }

      &:focus-visible {
        box-shadow: 0 0 0 2px $active-color;
      }
    }
  }
}

.annotation-colors {
  display: flex;
  gap: 14px;
  margin-bottom: 20px;
  justify-content: center;
  padding: 8px 0;
}

.color-picker-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.15);
  cursor: pointer;
  transition: all $transition-fast;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);

  &:hover {
    transform: scale(1.08);
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  }

  &:active {
    transform: scale(0.98);
  }

  &.active {
    border-color: $active-color;
    border-width: 3px;
    box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.25), 0 4px 12px rgba(0, 0, 0, 0.3);

    .check-icon {
      color: rgba(0, 0, 0, 0.7);
      font-size: 18px;
      font-weight: bold;
      text-shadow: 0 1px 2px rgba(255, 255, 255, 0.5);
    }
  }

  &:focus-visible {
    outline: 2px solid $active-color;
    outline-offset: 2px;
  }
}
