/* layout.css - Grid, Sidebar, Topbar, Reading Layout */

.app-layout {
  display: flex;
  min-height: 100vh;
  width: 100vw;
  position: relative;
}

/* Reading Progress Bar */
#reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), #60a5fa);
  width: 0%;
  z-index: 1000;
  transition: width 80ms ease-out;
}

/* Sidebar TOC */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 150;
  transition: transform var(--trans-normal);
}

/* Book Switcher Tabs */
.book-switcher {
  display: flex;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 2px;
  margin-bottom: 0.85rem;
  gap: 2px;
}

.book-tab-btn {
  flex: 1;
  border: none;
  background: none;
  font-family: var(--font-sans);
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--text-muted);
  padding: 0.4rem 0.3rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--trans-fast);
  text-align: center;
  white-space: nowrap;
}

.book-tab-btn.active {
  background-color: var(--bg-surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.sidebar-header {
  padding: 1.25rem 1.25rem 0.85rem;
  border-bottom: 1px solid var(--border-subtle);
}

.badge-brand {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary);
  background-color: var(--primary-subtle);
  padding: 0.25rem 0.625rem;
  border-radius: 9999px;
  margin-bottom: 0.5rem;
}

.sidebar-title {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-main);
}

.sidebar-subtitle {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.75rem;
}

.nav-group-label {
  font-family: var(--font-display);
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  padding: 0.5rem 0.75rem 0.375rem;
}

.toc-link {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.875rem;
  line-height: 1.4;
  transition: all var(--trans-fast);
  cursor: pointer;
  margin-bottom: 2px;
}

.toc-link:hover {
  background-color: var(--bg-hover);
  color: var(--text-main);
}

.toc-link.active {
  background-color: var(--primary-subtle);
  color: var(--primary);
  font-weight: 600;
}

.toc-num {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  opacity: 0.8;
  padding-top: 0.1rem;
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Main Content Area */
.main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: relative;
}

/* Sticky Topbar */
.topbar {
  position: sticky;
  top: 0;
  background-color: rgba(251, 249, 245, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  height: var(--topbar-height);
  padding: 0 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 100;
}

[data-theme="dark"] .topbar {
  background-color: rgba(18, 20, 23, 0.88);
}

[data-theme="sepia"] .topbar {
  background-color: rgba(243, 235, 217, 0.88);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.menu-toggle-btn {
  display: none;
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--text-main);
  cursor: pointer;
  padding: 0.375rem;
  border-radius: 6px;
}

.current-chapter-indicator {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--primary);
  background-color: var(--primary-subtle);
  padding: 0.25rem 0.625rem;
  border-radius: 9999px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--trans-fast);
}

.tool-btn:hover {
  background-color: var(--bg-hover);
  color: var(--text-main);
  border-color: var(--border-medium);
}

/* Theme Switcher Segmented Control */
.theme-selector {
  display: flex;
  background-color: var(--bg-subtle);
  padding: 2px;
  border-radius: 9999px;
}

.theme-pill {
  border: none;
  background: none;
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: 9999px;
  cursor: pointer;
  transition: all var(--trans-fast);
}

.theme-pill.active {
  background-color: var(--bg-surface);
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}

/* Reading Container */
.article-wrapper {
  max-width: var(--reader-max-width);
  width: 100%;
  margin: 0 auto;
  padding: 3.5rem 1.5rem 6rem;
}

/* Chapter Bottom Navigator */
.chapter-bottom-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-subtle);
}

.chapter-nav-card {
  display: flex;
  flex-direction: column;
  padding: 1rem 1.25rem;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  background-color: var(--bg-surface);
  text-decoration: none;
  color: var(--text-main);
  transition: all var(--trans-fast);
  max-width: 48%;
  cursor: pointer;
}

.chapter-nav-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.nav-card-dir {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--primary);
  margin-bottom: 0.25rem;
}

.nav-card-title {
  font-family: var(--font-display);
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.35;
}

/* Responsive */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .main-wrapper {
    margin-left: 0;
  }
  .menu-toggle-btn {
    display: inline-flex;
  }
}
