// Variables matching sidebar styling
$navbar-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;
$transition-fast: 150ms ease;
$transition-normal: 200ms ease;

.reader-navbar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 48px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 1000;
  background: $navbar-bg;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid $border-color;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.3);
  color: $text-primary;
  opacity: 0;
  pointer-events: none;
  transform: translateY(100%);
  transition: opacity 250ms cubic-bezier(0.4, 0, 0.2, 1),
              transform 250ms cubic-bezier(0.4, 0, 0.2, 1);

  &.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
  }
}

.icon-btn {
  background: none;
  border: none;
  color: $text-secondary;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: background $transition-fast, color $transition-fast;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;

  svg {
    display: block;
  }

  &:hover:not(:disabled) {
    background: $hover-bg;
    color: $text-primary;
  }

  &:disabled {
    opacity: 0.3;
    cursor: not-allowed;
  }

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

.progress-section {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;

  .location-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid $border-color;
    color: $text-primary;
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background $transition-fast, border-color $transition-fast;
    font-variant-numeric: tabular-nums;

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

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

  .progress-slider-wrapper {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;

    .progress-slider {
      flex: 1;
      height: 6px;
      border-radius: 3px;
      outline: none;
      -webkit-appearance: none;
      background: rgba(255, 255, 255, 0.12);
      position: relative;
      z-index: 1;
      cursor: pointer;

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

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

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

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

    .progress-ticks {
      position: absolute;
      left: 0;
      top: 50%;
      width: 100%;
      height: 10px;
      transform: translateY(-50%);
      pointer-events: none;
      z-index: 0;
    }

    .progress-tick {
      position: absolute;
      top: 0;
      width: 1.5px;
      height: 10px;
      background: rgba(255, 255, 255, 0.4);
      border-radius: 2px;
    }
  }
}

.location-popover {
  position: absolute;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: $navbar-bg;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid $border-color;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  z-index: 1001;
  min-width: 380px;
  animation: popoverSlideIn 200ms cubic-bezier(0.4, 0, 0.2, 1);
  color: $text-primary;

  .popover-content {
    padding: 16px 20px;
  }

  .time-info {
    display: flex;
    gap: 24px;
    align-items: center;
    justify-content: space-around;
    padding: 4px 0;

    .time-section {
      display: flex;
      flex-direction: column;
      gap: 4px;
      text-align: center;
      flex: 1;

      .label {
        font-size: 11px;
        color: $text-muted;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        font-weight: 600;
      }

      .value {
        font-size: 20px;
        font-weight: 600;
        letter-spacing: -0.3px;
        color: $text-primary;
      }
    }

    .separator {
      width: 1px;
      height: 44px;
      background: $border-color;
    }
  }

  .divider {
    height: 1px;
    background: $border-color;
    margin: 12px 0;
  }

  .book-info {
    display: flex;
    flex-direction: column;
    gap: 12px;

    .chapter-info {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 4px;
      text-align: center;

      .label {
        font-size: 11px;
        color: $text-muted;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        font-weight: 600;
      }

      .chapter-name {
        font-size: 14px;
        font-weight: 500;
        color: $text-primary;
        line-height: 1.3;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
      }
    }

    .info-row {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 24px;

      .info-column {
        display: flex;
        flex-direction: column;
        gap: 4px;
        text-align: center;

        .label {
          font-size: 11px;
          color: $text-muted;
          text-transform: uppercase;
          letter-spacing: 0.5px;
          font-weight: 600;
        }

        .value {
          font-size: 18px;
          font-weight: 600;
          letter-spacing: -0.3px;
          color: $text-primary;
        }
      }

      .info-separator {
        width: 1px;
        height: 36px;
        background: $border-color;
      }
    }
  }

  .nav-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .goto-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;

    label {
      font-size: 13px;
      font-weight: 500;
      color: $text-secondary;
    }

    input {
      width: 65px;
      padding: 6px 10px;
      background: rgba(255, 255, 255, 0.05);
      border: 1px solid $border-color;
      border-radius: 6px;
      color: $text-primary;
      font-size: 13px;
      text-align: right;
      transition: background $transition-fast, border-color $transition-fast;
      font-variant-numeric: tabular-nums;

      &:focus {
        outline: none;
        background: $hover-bg;
        border-color: $active-color;
      }
    }

    span {
      font-size: 13px;
      color: $text-secondary;
    }

    .go-btn {
      padding: 7px 18px;
      background: $active-color;
      border: none;
      border-radius: 6px;
      color: white;
      font-size: 13px;
      font-weight: 500;
      cursor: pointer;
      transition: background $transition-fast;
      flex-shrink: 0;

      &:hover {
        background: #9ba3fb;
      }
    }
  }

  .section-navigation {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;

    .nav-btn {
      background: none;
      border: none;
      color: $text-secondary;
      padding: 0;
      margin: 0;
      border-radius: 8px;
      cursor: pointer;
      transition: background $transition-fast, color $transition-fast, transform $transition-fast;
      width: 44px;
      height: 44px;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;

      svg {
        display: block;
      }

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

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

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

@keyframes popoverSlideIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

@media (max-width: 600px) {
  .reader-navbar {
    padding: 0 8px;
    height: 44px;
  }

  .location-popover {
    min-width: 320px;
    left: 16px;
    right: 16px;
    transform: none;

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