/* ==========================================================================
   Base Styles & Dark Theme Tokens
   ========================================================================== */
:root {
  --bg-color: #121214;
  --surface-color: rgba(26, 26, 30, 0.75);
  --surface-border: rgba(255, 255, 255, 0.08);
  --primary-color: #3b82f6;
  --primary-hover: #2563eb;
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --active-state: rgba(59, 130, 246, 0.2);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  --transition-fast: 0.2s ease;
  --transition-normal: 0.3s ease;
  --toolbar-height: 56px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
}

/* ==========================================================================
   Loader Overlay
   ========================================================================== */
.loader-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-color);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  transition: opacity var(--transition-normal);
}

.loader-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--surface-border);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loader-status {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.progress-bar-container {
  width: 240px;
  height: 6px;
  background: var(--surface-border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: var(--primary-color);
  transition: width var(--transition-fast);
}

/* ==========================================================================
   App Container & Glassmorphism Toolbar
   ========================================================================== */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

.top-toolbar {
  height: var(--toolbar-height);
  background: var(--surface-color);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--surface-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
  z-index: 100;
}

.toolbar-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 250px;
}

.icon-button {
  background: transparent;
  border: none;
  color: var(--text-main);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.icon-button:hover {
  background: rgba(255, 255, 255, 0.1);
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.page-counter {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.page-counter input {
  width: 44px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--surface-border);
  border-radius: 4px;
  color: var(--text-main);
  text-align: center;
  padding: 4px;
  font-size: 0.85rem;
}

.zoom-controls {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  padding: 2px;
}

.zoom-dropdown {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: 0.85rem;
  padding: 0 4px;
  cursor: pointer;
  outline: none;
}

.zoom-dropdown option {
  background: #1a1a1e;
  color: var(--text-main);
}

/* ==========================================================================
   Workspace & Sidebar
   ========================================================================== */
.workspace {
  display: flex;
  flex: 1;
  height: calc(100vh - var(--toolbar-height));
  position: relative;
  overflow: hidden;
}

.sidebar {
  width: 320px;
  background: var(--surface-color);
  backdrop-filter: blur(12px);
  border-right: 1px solid var(--surface-border);
  display: flex;
  flex-direction: column;
  transition: margin-left var(--transition-normal);
  z-index: 90;
}

.sidebar.collapsed {
  margin-left: -320px;
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--surface-border);
}

.tab-btn {
  flex: 1;
  padding: 12px 0;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--transition-fast), border-bottom var(--transition-fast);
}

.tab-btn.active {
  color: var(--primary-color);
  border-bottom: 2px solid var(--primary-color);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Thumbnails */
.thumbnail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.thumbnail-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: background var(--transition-fast);
}

.thumbnail-item:hover, .thumbnail-item.active {
  background: var(--active-state);
}

.thumbnail-item canvas {
  width: 100%;
  height: auto;
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.thumbnail-item span {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* TOC & Search Tree */
.toc-tree, .search-results-list, .bookmarks-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toc-item, .search-result-item, .bookmark-item {
  padding: 8px 12px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.toc-item:hover, .search-result-item:hover, .bookmark-item:hover {
  background: var(--active-state);
}

.search-box {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.search-box input {
  flex: 1;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--surface-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

.primary-button, .secondary-button {
  padding: 8px 12px;
  border-radius: 6px;
  border: none;
  background: var(--primary-color);
  color: white;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}

.secondary-button {
  background: rgba(255, 255, 255, 0.1);
  width: 100%;
}

.search-status-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* ==========================================================================
   Viewport & Flipbook Area
   ========================================================================== */
.viewport {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow:scroll;
  overflow-x: hidden;
  position: relative;
  background: radial-gradient(circle at center, #1e1e24 0%, #121214 100%);
}

.zoom-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  transition: transform var(--transition-fast);
  transform-origin: center center;
}

.flipbook-wrapper {
  box-shadow: var(--shadow-lg);
  border-radius: 4px;
}

.page-node {
  background: white;
  overflow: hidden;
}

.page-node canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .app-title {
    display: none;
  }
  .sidebar {
    position: absolute;
    height: 100%;
  }
  .zoom-controls {
    display: none;
  }
}

/* Ensure toolbar buttons and SVG icons are visible */
.icon-button {
  background: rgba(255, 255, 255, 0.08); /* Dark subtle background */
  border: 1px solid var(--surface-border);
  color: #ffffff !important;               /* Force icon color to white */
  width: 38px;
  height: 38px;
  min-width: 38px;                         /* Prevents squishing on small screens */
  min-height: 38px;
  border-radius: 8px;
  display: flex !important;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  z-index: 10;
}

.icon-button:hover {
  background: var(--primary-color);        /* Highlight blue on hover */
  color: #ffffff !important;
}

/* Force SVG vectors to render clearly */
.icon-button svg {
  width: 22px !important;
  height: 22px !important;
  fill: currentColor !important;            /* Uses button's text color */
  display: block;
}