/* Table of Contents Styles */

/* TOC Toggle Button */
.toc-toggle {
    background: transparent;
    border: none;
    color: var(--heading-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 8px;
    border-radius: 4px;
    margin-right: 8px;
  }
  
  .toc-toggle:hover {
    background-color: var(--bg-color);
  }
  
  /* TOC Panel */
  .toc-panel {
    position: absolute;
    top: 60px;
    left: 15px;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px var(--shadow-color);
    width: 280px;
    max-height: calc(100% - 120px);
    display: flex;
    flex-direction: column;
    z-index: 1002;
    display: none;
    transition: transform 0.3s ease, opacity 0.3s ease;
    transform: translateX(-20px);
    opacity: 0;
  }
  
  .toc-panel.active {
    display: flex;
    transform: translateX(0);
    opacity: 1;
  }
  
  /* TOC Header */
  .toc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
  }
  
  .toc-item:empty {
    display: block;
    height: 0;
    margin: 0;
    padding: 0;
    min-height: 1px; /* Keeps enough height for the anchor to work */
  }

  .toc-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--heading-color);
  }
  
  .toc-close-btn {
    background: transparent;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 4px;
  }
  
  .toc-close-btn:hover {
    background-color: var(--border-color);
  }
  
  /* TOC Tabs */
  .toc-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
  }
  
  .toc-tab {
    flex: 1;
    background-color: transparent;
    border: none;
    padding: 10px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-color);
    cursor: pointer;
    transition: background-color 0.2s;
    border-bottom: 2px solid transparent;
  }
  
  .toc-tab:hover {
    background-color: rgba(0, 0, 0, 0.05);
  }
  
  .toc-tab.active {
    color: var(--heading-color);
    font-weight: 600;
    border-bottom-color: var(--heading-color);
  }
  
  /* TOC Content Container */
  .toc-content-container {
    overflow-y: auto;
    flex: 1;
  }
  
  .toc-content {
    padding: 12px 0;
  }
  
  /* TOC List */
  .toc-list,
  .bookmarks-list {
    list-style: none;
    padding: 0;
    margin: 0;
  }
  
  .toc-item {
    padding: 0;
    margin: 0;
  }
  
  .toc-link {
    display: block;
    padding: 6px 16px;
    text-decoration: none;
    color: var(--text-color);
    font-size: 0.95rem;
    text-align: left;
    border: none;
    background: transparent;
    width: 100%;
    cursor: pointer;
    transition: background-color 0.2s;
    border-left: 2px solid transparent;
    line-height: 1.4;
  }
  
  .toc-link:hover {
    background-color: rgba(0, 0, 0, 0.05);
  }
  
  .toc-link.active {
    color: var(--heading-color);
    font-weight: 600;
    background-color: rgba(0, 0, 0, 0.05);
    border-left-color: var(--heading-color);
  }
  
  /* TOC Heading Levels */
  .toc-item.level-1 .toc-link {
    font-weight: 600;
    font-size: 1rem;
  }
  
  .toc-item.level-2 .toc-link {
    padding-left: 24px;
  }
  
  .toc-item.level-3 .toc-link {
    padding-left: 32px;
    font-size: 0.9rem;
  }
  
  .toc-item.level-4 .toc-link,
  .toc-item.level-5 .toc-link,
  .toc-item.level-6 .toc-link {
    padding-left: 40px;
    font-size: 0.85rem;
    opacity: 0.9;
  }
  
  /* TOC Empty and Loading States */
  .toc-empty,
  .toc-loading,
  .bookmark-empty {
    padding: 16px;
    text-align: center;
    color: var(--text-color);
    opacity: 0.7;
    font-style: italic;
    font-size: 0.9rem;
  }
  
  /* Bookmark Styles */
  .bookmark-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px 8px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 8px;
  }
  
  .bookmark-header h4 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--heading-color);
  }
  
  .add-bookmark-btn {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
  }
  
  .add-bookmark-btn:hover {
    background-color: var(--border-color);
  }
  
  .add-bookmark-btn svg {
    color: var(--heading-color);
  }
  
  .bookmark-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8px;
    margin: 0;
  }
  
  .bookmark-info {
    flex: 1;
    overflow: hidden;
  }
  
  .bookmark-link {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px;
    text-decoration: none;
    color: var(--text-color);
    font-size: 0.9rem;
    text-align: left;
    border: none;
    background: transparent;
    width: 100%;
    cursor: pointer;
    transition: background-color 0.2s;
    border-radius: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  
  .bookmark-link svg {
    flex-shrink: 0;
    color: var(--heading-color);
  }
  
  .bookmark-link:hover {
    background-color: rgba(0, 0, 0, 0.05);
  }
  
  .bookmark-page {
    display: block;
    font-size: 0.75rem;
    color: var(--text-color);
    opacity: 0.7;
    margin-left: 28px;
  }
  
  .bookmark-delete {
    background: transparent;
    border: none;
    color: var(--text-color);
    opacity: 0.5;
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    visibility: hidden;
  }
  
  .bookmark-item:hover .bookmark-delete {
    visibility: visible;
  }
  
  .bookmark-delete:hover {
    opacity: 1;
    background-color: rgba(0, 0, 0, 0.05);
    color: #e53e3e;
  }
  
 /* Continuation of responsive styles */
@media (max-width: 768px) {
    .toc-panel {
      top: 70px;
      left: 10px;
      right: 10px;
      width: calc(100% - 20px);
      max-height: 60vh;
    }
    
    .toc-toggle {
      padding: 6px;
    }
    
    .toc-link {
      padding: 8px 16px;
    }
    
    .bookmark-item {
      padding: 2px 8px;
    }
    
    .toc-header h3 {
      font-size: 1rem;
    }
    
    .toc-tab {
      padding: 8px;
      font-size: 0.85rem;
    }
  }
  
  /* Dark theme adjustments */
  .theme-dark .toc-panel {
    background-color: var(--bg-color);
    border-color: var(--border-color);
  }
  
  .theme-dark .toc-tab:hover,
  .theme-dark .toc-link:hover,
  .theme-dark .bookmark-link:hover,
  .theme-dark .bookmark-delete:hover {
    background-color: rgba(255, 255, 255, 0.1);
  }
  
  .theme-dark .toc-tab.active {
    border-bottom-color: var(--heading-color);
  }
  
  /* Sepia theme adjustments */
  .theme-sepia .toc-panel {
    background-color: var(--bg-color);
    border-color: var(--border-color);
  }
  
  .theme-sepia .toc-tab:hover,
  .theme-sepia .toc-link:hover,
  .theme-sepia .bookmark-link:hover,
  .theme-sepia .bookmark-delete:hover {
    background-color: rgba(139, 115, 85, 0.1);
  }
  
  /* Animation for TOC panel */
  @keyframes slideFadeIn {
    from {
      opacity: 0;
      transform: translateX(-20px);
    }
    to {
      opacity: 1;
      transform: translateX(0);
    }
  }
  
  .toc-panel.active {
    animation: slideFadeIn 0.3s ease forwards;
  }
  
  /* For print: hide the TOC panel */
  @media print {
    .toc-panel, .toc-toggle {
      display: none !important;
    }
  }
  
  /* Add mini chapter indicators for current location */
  .chapter-indicator {
    position: absolute;
    right: 20px;
    bottom: 70px;
    background-color: var(--bg-color);
    color: var(--text-color);
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 0.85rem;
    opacity: 0.9;
    box-shadow: 0 2px 8px var(--shadow-color);
    pointer-events: none;
    transition: opacity 0.3s ease;
  }
  
  .chapter-indicator.fadeout {
    opacity: 0;
  }
  
  /* Optional: Add subtle animations for TOC-related actions */
  @keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
  }
  
  .bookmark-added {
    animation: pulse 0.5s ease;
  }
  
  /* Adjust TOC toggle button when settings button is present */
  .book-header:has(.settings-toggle) .toc-toggle {
    margin-right: 0;
  }
  
  /* Focus styles for accessibility */
  .toc-toggle:focus,
  .toc-link:focus,
  .bookmark-link:focus,
  .bookmark-delete:focus,
  .add-bookmark-btn:focus,
  .toc-tab:focus,
  .toc-close-btn:focus {
    outline: 2px solid var(--heading-color);
    outline-offset: 2px;
  }
  
  /* Hide/show bookmark delete button for touch devices */
  @media (hover: none) {
    .bookmark-delete {
      visibility: visible;
      opacity: 0.7;
    }
  }

  /* Error message styling */
.toc-error {
    padding: 16px;
    text-align: center;
    color: #e53e3e;
    font-style: italic;
    font-size: 0.9rem;
  }
  
  /* Additional helper to make sure TOC extraction works */
  .book-viewer .book-page h1[id],
  .book-viewer .book-page h2[id],
  .book-viewer .book-page h3[id],
  .book-viewer .book-page h4[id],
  .book-viewer .book-page h5[id],
  .book-viewer .book-page h6[id] {
    scroll-margin-top: 20px;
    position: relative;
  }
  
  /* Optional highlight effect for navigation */
  @keyframes headingHighlight {
    0% { background-color: transparent; }
    30% { background-color: rgba(255, 255, 0, 0.2); }
    100% { background-color: transparent; }
  }
  
  .heading-highlight {
    animation: headingHighlight 2s ease-in-out;
  }