// Variables
$sidebar-width: 320px;
$sidebar-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.06);
$active-bg: rgba(99, 102, 241, 0.15);
$active-color: #818cf8;
$transition-fast: 150ms ease;
$transition-normal: 200ms ease;

// Overlay
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(1px);
  z-index: 12000;
  animation: fadeIn $transition-normal;

  &.closing {
    animation: fadeOut $transition-normal forwards;
  }
}

// Sidebar container - positioned on the RIGHT
.sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: $sidebar-width;
  background: $sidebar-bg;
  display: flex;
  flex-direction: column;
  color: $text-primary;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.3);
  animation: slideInRight 250ms cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 12001;

  &.closing {
    animation: slideOutRight 200ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
  }
}

// Header
.sidebar-header {
  display: flex;
  align-items: center;
  padding: 20px 16px;
  border-bottom: 1px solid $border-color;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03) 0%, transparent 100%);
}

.sidebar-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  color: $text-primary;
}

// Tabs
.tabs {
  display: flex;
  border-bottom: 1px solid $border-color;
  background: rgba(0, 0, 0, 0.2);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px;
  background: none;
  border: none;
  color: $text-secondary;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: color $transition-fast, background $transition-fast;
  position: relative;

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

  &.active {
    color: $active-color;

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

.tab-icon {
  width: 18px;
  height: 18px;
}

.badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 20px);
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: $active-color;
  color: white;
  font-size: 10px;
  font-weight: 600;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

// Content area
.content {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;

  &::-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);
    }
  }
}

// Item list
.item-list {
  list-style: none;
  margin: 0;
  padding: 8px 0;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background $transition-fast;

  &:hover {
    background: $hover-bg;

    .delete-btn {
      opacity: 1;
    }
  }
}

.item-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

// Notes
.notes-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.notes-search-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid $border-color;

  .search-icon {
    color: $text-muted;
    flex-shrink: 0;
  }

  .search-input {
    flex: 1;
    background: none;
    border: none;
    color: $text-primary;
    font-size: 14px;
    outline: none;

    &::placeholder {
      color: $text-muted;
    }
  }

  .clear-btn {
    width: 24px;
    height: 24px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    color: $text-secondary;
    cursor: pointer;
    transition: background $transition-fast, color $transition-fast;
    flex-shrink: 0;

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

.note-item {
  align-items: flex-start;

  &:hover .action-buttons {
    opacity: 1;
  }
}

.note-bar {
  width: 3px;
  align-self: stretch;
  border-radius: 2px;
  flex-shrink: 0;
}

.note-text {
  font-size: 13px;
  color: $text-primary;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

.note-selected-text {
  font-size: 12px;
  font-style: italic;
  color: $text-secondary;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 4px;
  opacity: 0;
  transition: opacity $transition-fast;
}

.edit-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 6px;
  color: $text-muted;
  cursor: pointer;
  transition: background $transition-fast, color $transition-fast;
  flex-shrink: 0;

  svg {
    width: 16px;
    height: 16px;
  }

  &:hover {
    background: rgba(99, 102, 241, 0.15);
    color: $active-color;
  }
}

.item-chapter {
  font-size: 11px;
  color: $text-secondary;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-meta {
  font-size: 11px;
  color: $text-muted;
}

.delete-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 6px;
  color: $text-muted;
  cursor: pointer;
  opacity: 0;
  transition: opacity $transition-fast, background $transition-fast, color $transition-fast;
  flex-shrink: 0;

  svg {
    width: 16px;
    height: 16px;
  }

  &:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
  }
}

// Empty state
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  color: $text-secondary;
}

.empty-icon {
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-state p {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 500;
}

.empty-hint {
  font-size: 12px;
  color: $text-muted;
}

// Search
.search-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.search-input-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid $border-color;

  .search-icon {
    color: $text-muted;
    flex-shrink: 0;
  }

  .search-input {
    flex: 1;
    background: none;
    border: none;
    color: $text-primary;
    font-size: 14px;
    outline: none;

    &::placeholder {
      color: $text-muted;
    }
  }

  .clear-btn {
    width: 24px;
    height: 24px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    color: $text-secondary;
    cursor: pointer;
    transition: background $transition-fast, color $transition-fast;
    flex-shrink: 0;

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

.search-progress {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;

  .progress-bar {
    height: 3px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;

    .progress-fill {
      height: 100%;
      background: $active-color;
      border-radius: 2px;
      transition: width 200ms ease-out;
    }
  }

  .progress-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .progress-text {
    font-size: 11px;
    color: $text-muted;
  }

  .cancel-search-btn {
    width: 22px;
    height: 22px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    border-radius: 50%;
    color: $text-muted;
    cursor: pointer;
    transition: background $transition-fast, color $transition-fast;
    flex-shrink: 0;

    &:hover {
      background: rgba(239, 68, 68, 0.15);
      color: #ef4444;
    }
  }
}

.search-results-header {
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  color: $text-secondary;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid $border-color;
}

.search-results {
  flex: 1;
  overflow-y: auto;
}

.search-result-item {
  .item-content {
    gap: 6px;
  }
}

.search-excerpt {
  font-size: 13px;
  color: $text-secondary;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;

  .excerpt-context {
    color: $text-secondary;
  }

  .excerpt-match {
    background: rgba(255, 255, 0, 0.25);
    color: $text-primary;
    font-weight: 500;
    padding: 1px 2px;
    border-radius: 2px;
  }
}

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

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

@keyframes slideInRight {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

@keyframes slideOutRight {
  from { transform: translateX(0); }
  to { transform: translateX(100%); }
}
