// Variables
$sidebar-width: 300px;
$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(74, 144, 226, 0.15);
$active-color: #4a90e2;
$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(2px);
  z-index: 12000;
  animation: fadeIn $transition-normal;

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

// Sidebar container
.sidebar {
  position: fixed;
  top: 0;
  left: 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: slideIn 250ms cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 12001;

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

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

.book-cover {
  width: 60px;
  height: 90px;
  object-fit: cover;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
}

.book-meta {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  gap: 6px;
}

.book-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  margin: 0;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.book-authors {
  font-size: 12px;
  color: $text-secondary;
  margin: 0;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  overflow: hidden;
}

// 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);
    }
  }
}

// Page list
.page-list {
  list-style: none;
  margin: 0;
  padding: 8px 0;
}

.page-row {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 12px 16px;
  background: none;
  border: none;
  color: $text-primary;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background $transition-fast;
  gap: 12px;

  &:hover {
    background: $hover-bg;
  }

  &.active {
    background: $active-bg;
    color: $active-color;
    font-weight: 500;
  }
}

.page-number {
  min-width: 32px;
  text-align: right;
  font-size: 12px;
  font-weight: 600;
  opacity: 0.7;
}

.page-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

// PDF Outline list
.outline-list {
  list-style: none;
  margin: 0;
  padding: 8px 0;
}

.outline-item {
  list-style: none;
}

.outline-children {
  list-style: none;
  margin: 0;
  padding: 0;
}

.outline-row {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 10px 16px;
  padding-right: 12px;
  background: none;
  border: none;
  color: $text-primary;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background $transition-fast;
  gap: 8px;

  &:hover {
    background: $hover-bg;
  }

  &.active {
    background: $active-bg;
    color: $active-color;
    font-weight: 500;
  }

  &.has-children {
    font-weight: 500;
  }
}

.expand-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: $text-muted;
  transition: transform $transition-fast;
  border-radius: 4px;

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

  &.expanded {
    transform: rotate(90deg);
  }
}

.outline-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.outline-page {
  font-size: 11px;
  color: $text-muted;
  flex-shrink: 0;
  min-width: 28px;
  text-align: right;
}

// Item list (bookmarks & notes)
.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,
    .action-buttons {
      opacity: 1;
    }
  }
}

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

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

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

.item-title {
  font-size: 13px;
  font-weight: 500;
  color: $text-primary;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.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;
}

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

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

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

.edit-btn,
.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;
  transition: background $transition-fast, color $transition-fast;
  flex-shrink: 0;
  opacity: 0;

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

.list-item:hover .edit-btn,
.list-item:hover .delete-btn {
  opacity: 1;
}

.edit-btn:hover {
  background: rgba(74, 144, 226, 0.15);
  color: $active-color;
}

.delete-btn:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

// Notes container
.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;
    }
  }
}

// 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;
  }

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

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

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

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

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

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