/* em-styles.css */

/* Layout wrapper */
.em-layout {
  display: grid;
  grid-template-columns: 280px 1fr 240px;
  min-height: 100vh;
  position: relative;
}

/* Left Sidebar (Navigation) */
.em-sidebar-left {
  background-color: #ffffff;
  border-right: 1px solid var(--border-color);
  padding: 2rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  transition: transform 0.3s ease;
  z-index: 100;
}

.em-sidebar-left ul {
  list-style: none;
  padding-left: 0;
}

/* Chapters Collapsible */
.em-chapter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 0 0.75rem;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  user-select: none;
}

.em-chapter-header strong {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted-color);
  margin: 0;
  padding: 0;
}

.em-chevron {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted-color);
  border-bottom: 2px solid var(--muted-color);
  transform: rotate(45deg);
  transition: transform 0.2s;
  margin-right: 0.5rem;
}

.em-chapter:not(.expanded) .em-chevron {
  transform: rotate(-45deg);
}

.em-chapter:not(.expanded) > ul {
  display: none;
}

.em-sidebar-left ul ul {
  padding-left: 0;
  margin-top: 0.25rem;
  margin-bottom: 0;
}

.em-sidebar-left li {
  margin-bottom: 0.15rem;
}

.em-sidebar-left a {
  display: block;
  color: #3B454E;
  font-size: 0.95rem;
  padding: 0.4rem 0.75rem;
  border-radius: 4px;
  transition: background-color 0.2s, color 0.2s;
}

.em-sidebar-left a.active {
  color: var(--accent-color);
  background-color: #E1ECFF;
  font-weight: 500;
}

.em-sidebar-left a:not(.active):hover {
  background-color: var(--hover-bg);
  color: var(--text-color);
}

/* Middle Content Area */
.em-content {
  padding: 3rem 4rem;
  display: flex;
  justify-content: center;
}

.em-content-inner {
  width: 100%;
  max-width: 800px;
  font-size: 1.05rem;
  color: var(--text-color);
}

.em-content-inner p {
  margin-bottom: 1.5rem;
  line-height: 1.7;
}

.em-content-inner h1 { font-size: 2.25rem; border-bottom: 1px solid var(--border-color); padding-bottom: 0.5rem; }
.em-content-inner h2 { font-size: 1.75rem; margin-top: 2.5rem; }
.em-content-inner h3 { font-size: 1.35rem; margin-top: 2rem; }

/* Right TOC */
.em-sidebar-right {
  padding: 3rem 1.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.em-toc-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-color);
  margin-bottom: 1rem;
  font-weight: 700;
}

.em-toc {
  list-style: none;
  padding-left: 0;
  margin: 0;
  border-left: 1px solid var(--border-color);
}

.em-toc li {
  margin-bottom: 0.1rem;
}

.em-toc li.toc-h3 {
  padding-left: 1rem;
}

.em-toc a {
  color: var(--muted-color);
  font-size: 0.85rem;
  text-decoration: none;
  display: block;
  line-height: 1.4;
  padding: 0.4rem 0 0.4rem 1rem;
  margin-left: -1px;
  border-left: 1px solid transparent;
  transition: all 0.2s;
}

.em-toc a.active {
  color: var(--accent-color);
  border-left-color: var(--accent-color);
  font-weight: 500;
}

.em-toc a:hover:not(.active) {
  color: var(--text-color);
  border-left-color: var(--muted-color);
}

/* Mobile Header / FAB */
.em-mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: var(--bg-color);
  border-bottom: 1px solid var(--border-color);
  z-index: 90;
  align-items: center;
  padding: 0 1rem;
}

.em-menu-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.5rem;
  color: var(--text-color);
}

/* Mobile Overlay */
.em-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 95;
  opacity: 0;
  transition: opacity 0.3s;
}
.em-overlay.open {
  display: block;
  opacity: 1;
}

/* Mobile Responsive */
@media (max-width: 1024px) {
  .em-layout {
    grid-template-columns: 240px 1fr 200px;
  }
}

@media (max-width: 768px) {
  .em-layout {
    display: block;
  }
  .em-mobile-header {
    display: flex;
  }
  .em-content {
    padding-top: 5rem;
  }
  .em-sidebar-right {
    display: none;
  }
  .em-sidebar-left {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }
  .em-sidebar-left.open {
    transform: translateX(0);
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
  }
}

/* Navigation Buttons */
.em-page-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-color);
  gap: 1rem;
}

.em-page-nav a {
  display: flex;
  flex-direction: column;
  padding: 1rem;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  text-decoration: none;
  color: var(--text-color);
  flex: 1;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.em-page-nav a:hover {
  border-color: var(--accent-color);
  box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

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

.em-nav-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--muted-color);
  margin-bottom: 0.5rem;
  letter-spacing: 0.05em;
}

.em-nav-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent-color);
}

/* Table Styles */
.em-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 2rem 0;
  font-size: 0.95rem;
}

.em-content th {
  background-color: var(--sidebar-bg); /* fallback to sidebar bg */
  color: var(--text-color);
  font-weight: 600;
  text-align: left;
  padding: 1rem;
  border-bottom: 2px solid var(--border-color);
}

.em-content td {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  vertical-align: top;
}

.em-content tr:last-child td {
  border-bottom: none;
}
