/* ==========================================================================
   LAYOUT ARCHITECTURE (Header, Sidebar, Canvas, TOC, Responsive)
   ========================================================================== */

.page-wrapper {
  display: flex;
  min-height: calc(100vh - var(--header-height));
  position: relative;
  max-width: 1540px;
  margin: 0 auto;
}

/* --------------------------------------------------------------------------
   STICKY HEADER
   -------------------------------------------------------------------------- */
.site-header {
  position: sticky;
  top: 0;
  height: var(--header-height);
  background-color: rgba(253, 251, 212, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-border-subtle);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
}

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

.logo-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--color-primary-brown);
  letter-spacing: -0.02em;
}

.logo-container svg {
  height: 32px;
  width: auto;
}

.logo-badge {
  background-color: var(--color-primary-brown);
  color: var(--color-warm-bg);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-toggle-btn {
  display: none;
  background: none;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.6rem;
  color: var(--color-dark-brown);
  cursor: pointer;
}

.sidebar-toggle-btn svg {
  width: 20px;
  height: 20px;
  display: block;
}

.header-search-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background-color: var(--color-surface-white);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  padding: 0.45rem 0.85rem;
  color: var(--color-text-muted);
  font-size: 0.875rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  min-width: 240px;
  box-shadow: var(--shadow-sm);
}

.header-search-btn:hover {
  border-color: var(--color-accent-orange);
  color: var(--color-primary-brown);
  box-shadow: var(--shadow-md);
}

.search-shortcut {
  margin-left: auto;
  background-color: var(--color-surface-card);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.1rem 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--color-text-light);
}

.reading-progress-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  width: 0%;
  background: linear-gradient(90deg, var(--color-primary-brown), var(--color-accent-orange));
  transition: width 0.1s ease-out;
}

/* --------------------------------------------------------------------------
   STICKY COLLAPSIBLE SIDEBAR NAVIGATION
   -------------------------------------------------------------------------- */
.site-sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  background-color: var(--color-surface-sidebar);
  border-right: 1px solid var(--color-border-subtle);
  overflow-y: auto;
  padding: 1.5rem 1rem 3rem 1.25rem;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-strong) transparent;
}

.site-sidebar::-webkit-scrollbar {
  width: 6px;
}
.site-sidebar::-webkit-scrollbar-thumb {
  background-color: var(--color-border-strong);
  border-radius: var(--radius-full);
}

.sidebar-group {
  margin-bottom: 1.25rem;
}

.sidebar-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-primary-brown);
  margin-bottom: 0.5rem;
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  user-select: none;
  border-radius: var(--radius-sm);
  transition: background-color var(--transition-fast);
}

.sidebar-group-header:hover {
  background-color: var(--color-surface-card-hover);
}

.sidebar-group-header svg {
  width: 14px;
  height: 14px;
  transition: transform var(--transition-fast);
}

.sidebar-group.collapsed .sidebar-group-header svg {
  transform: rotate(-90deg);
}

.sidebar-group.collapsed .sidebar-nav-list {
  display: none;
}

.sidebar-nav-list {
  list-style: none;
}

.sidebar-nav-item {
  margin-bottom: 0.2rem;
}

.sidebar-nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-muted);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  line-height: 1.3;
}

.sidebar-nav-link:hover {
  background-color: var(--color-surface-card-hover);
  color: var(--color-primary-brown);
}

.sidebar-nav-link.active {
  background-color: var(--color-primary-brown);
  color: var(--color-text-inverse);
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.sidebar-nav-link .phase-tag {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  opacity: 0.8;
}

/* --------------------------------------------------------------------------
   MAIN CONTENT CANVAS & FLOATING TABLE OF CONTENTS
   -------------------------------------------------------------------------- */
.canvas-wrapper {
  flex: 1;
  display: flex;
  justify-content: center;
  min-width: 0;
}

.content-canvas {
  flex: 1;
  max-width: var(--content-max-width);
  padding: 2.5rem 2.5rem 6rem 2.5rem;
  min-width: 0;
}

/* Floating Table of Contents (Right Side) */
.floating-toc {
  width: var(--toc-width);
  min-width: var(--toc-width);
  position: sticky;
  top: calc(var(--header-height) + 2rem);
  height: calc(100vh - var(--header-height) - 4rem);
  overflow-y: auto;
  padding: 0.5rem 1rem;
  border-left: 1px solid var(--color-border-subtle);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  font-size: 0.825rem;
}

.toc-title {
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-primary-brown);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.toc-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.toc-link {
  display: block;
  color: var(--color-text-muted);
  padding: 0.2rem 0;
  line-height: 1.4;
  transition: all var(--transition-fast);
  border-left: 2px solid transparent;
  padding-left: 0.5rem;
  margin-left: -0.5rem;
}

.toc-link:hover {
  color: var(--color-accent-orange);
}

.toc-link.active {
  color: var(--color-primary-brown);
  font-weight: 700;
  border-left-color: var(--color-accent-orange);
}

.toc-link.indent-h3 {
  padding-left: 1.25rem;
}

/* --------------------------------------------------------------------------
   CHAPTER HEADER & META
   -------------------------------------------------------------------------- */
.chapter-header {
  margin-bottom: 2.5rem;
  border-bottom: 2px solid var(--color-border-subtle);
  padding-bottom: 1.5rem;
}

.chapter-header h1 {
  font-size: 2.25rem;
  font-weight: 800;
  color: var(--color-dark-brown);
  line-height: 1.2;
  letter-spacing: -0.03em;
  margin-top: 0.5rem;
  margin-bottom: 0.75rem;
}

.chapter-meta {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  font-size: 0.85rem;
  color: var(--color-text-light);
  flex-wrap: wrap;
}

.reading-time-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background-color: var(--color-surface-card);
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border-subtle);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.content-section {
  margin-bottom: 3.5rem;
}

.content-section h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-primary-brown);
  margin-bottom: 1rem;
  letter-spacing: -0.02em;
  padding-bottom: 0.4rem;
  border-bottom: 1px dashed var(--color-border-strong);
}

.content-section h3 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--color-dark-brown);
  margin: 1.75rem 0 0.75rem 0;
}

.content-section p {
  font-size: 1rem;
  color: var(--color-text-main);
  margin-bottom: 1.25rem;
  line-height: 1.7;
}

.content-section ul, .content-section ol {
  margin-bottom: 1.5rem;
  padding-left: 1.5rem;
}

.content-section li {
  margin-bottom: 0.5rem;
  line-height: 1.6;
}

/* --------------------------------------------------------------------------
   FOOTER NAVIGATION
   -------------------------------------------------------------------------- */
.footer-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 2px solid var(--color-border-subtle);
}

.nav-card {
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1.5rem;
  background-color: var(--color-surface-card);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-lg);
  transition: all var(--transition-normal);
  text-decoration: none !important;
}

.nav-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--color-accent-orange);
  background-color: var(--color-surface-card-hover);
}

.nav-card-next {
  text-align: right;
  align-items: flex-end;
}

.nav-card-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-light);
  margin-bottom: 0.3rem;
}

.nav-card-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-primary-brown);
  line-height: 1.3;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background-color: rgba(56, 36, 13, 0.5);
  backdrop-filter: blur(4px);
  z-index: 90;
}

/* --------------------------------------------------------------------------
   RESPONSIVE BREAKPOINTS
   -------------------------------------------------------------------------- */
@media (max-width: 1280px) {
  .floating-toc {
    display: none; /* Hide floating TOC on medium screens */
  }
}

@media (max-width: 1024px) {
  .sidebar-toggle-btn {
    display: block;
  }

  .site-sidebar {
    position: fixed;
    top: var(--header-height);
    left: -100%;
    z-index: 95;
    transition: left var(--transition-normal);
    box-shadow: var(--shadow-lg);
  }

  .site-sidebar.open {
    left: 0;
  }

  .sidebar-overlay.active {
    display: block;
  }

  .content-canvas {
    padding: 2rem 1.5rem 4rem 1.5rem;
  }
}

@media (max-width: 640px) {
  .header-search-btn {
    min-width: 140px;
    padding: 0.4rem 0.6rem;
  }

  .search-shortcut {
    display: none;
  }

  .footer-nav {
    grid-template-columns: 1fr;
  }

  .chapter-header h1 {
    font-size: 1.75rem;
  }
}
