/* ── AIEA Book Website Stylesheet ── */
:root {
  --text: #1a1a1a;
  --bg: #ffffff;
  --accent: #003366;
  --accent-light: #e8f0fa;
  --accent-hover: #004a99;
  --border: #ddd;
  --code-bg: #f5f5f5;
  --sidebar-bg: #f8f9fa;
  --sidebar-width: 280px;
  --insight-width: 320px;
  --content-max: 60rem;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Layout ── */
body {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  display: flex;
  min-height: 100vh;
}

.main-content {
  margin-left: var(--sidebar-width);
  max-width: var(--content-max);
  padding: 2rem 2.5rem 3rem;
  flex: 1;
  min-height: 100vh;
  transition: margin-right 0.3s ease;
}

body.has-insights .main-content {
  margin-right: var(--insight-width);
}

/* ── Sidebar ── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  overflow-y: auto;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 0.84rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.1rem 1.2rem;
  border-bottom: 2px solid var(--accent);
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  letter-spacing: 0.03em;
}

.sidebar-title:hover { color: var(--accent-hover); }

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.3rem;
  color: var(--accent);
  cursor: pointer;
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0 2rem;
}

/* Part headers */
.sidebar-part {
  padding: 1rem 1.2rem 0.3rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #888;
  font-weight: 700;
}

/* Chapter links */
.sidebar-chapter { position: relative; }

.chapter-link {
  display: flex;
  align-items: baseline;
  padding: 0.4rem 1.2rem;
  color: var(--text);
  text-decoration: none;
  line-height: 1.4;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
}

.chapter-link:hover {
  background: var(--accent-light);
  color: var(--accent);
}

.chapter-num {
  color: var(--accent);
  font-weight: 600;
  margin-right: 0.15rem;
  flex-shrink: 0;
}

/* Active chapter */
.sidebar-chapter.active > .chapter-link {
  color: var(--accent);
  font-weight: 600;
  background: var(--accent-light);
  border-left: 3px solid var(--accent);
  padding-left: calc(1.2rem - 3px);
}

/* Expand/collapse arrow */
.chapter-link::after {
  content: "";
  display: none;
}

.sidebar-chapter:has(.sidebar-sections) > .chapter-link::after {
  content: "▸";
  display: inline;
  margin-left: auto;
  padding-left: 0.5rem;
  font-size: 0.7rem;
  color: #aaa;
  transition: transform 0.2s;
}

.sidebar-chapter.active > .chapter-link::after,
.sidebar-chapter.expanded > .chapter-link::after {
  content: "▾";
  color: var(--accent);
}

/* Collapsible subsections */
.sidebar-sections {
  list-style: none;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.sidebar-chapter.active .sidebar-sections,
.sidebar-chapter.expanded .sidebar-sections {
  max-height: 800px;
}

.sidebar-sections li a {
  display: block;
  padding: 0.2rem 1.2rem 0.2rem 2.2rem;
  color: #555;
  text-decoration: none;
  font-size: 0.78rem;
  line-height: 1.4;
  transition: color 0.15s, background 0.15s;
}

.sidebar-sections li a:hover {
  color: var(--accent);
  background: rgba(0, 51, 102, 0.04);
}

.sidebar-sections li a.current {
  color: var(--accent);
  font-weight: 600;
}

/* Mobile menu button */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 0.8rem;
  left: 0.8rem;
  z-index: 50;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  width: 2.5rem;
  height: 2.5rem;
  font-size: 1.3rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

/* Overlay for mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.4);
  z-index: 90;
}

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

/* ══════════════════════════════════════════
   ── Insight Panel (Right Side) ──
   ══════════════════════════════════════════ */

.insight-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: var(--insight-width);
  height: 100vh;
  background: #fafbfd;
  border-left: 2px solid var(--accent);
  z-index: 40;
  display: flex;
  flex-direction: column;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 0.88rem;
}

.insight-header {
  padding: 1rem 1.2rem 0.7rem;
  background: var(--accent);
  color: #fff;
  flex-shrink: 0;
}

.insight-header-title {
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 0.02em;
}

.insight-header-sub {
  font-size: 0.72rem;
  opacity: 0.8;
  margin-top: 0.15rem;
}

.audio-player {
  background: var(--accent-light);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0.7rem 0.8rem;
  margin-bottom: 1rem;
}

.audio-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  margin-bottom: 0.4rem;
}

.audio-player audio {
  width: 100%;
  height: 36px;
}

.podcast-player {
  background: #f5eef8;
  border-color: #8e44ad;
}

.podcast-player .audio-label {
  color: #8e44ad;
}

.insight-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.2rem;
}

.insight-card {
  display: none;
  animation: insightFadeIn 0.3s ease;
}

.insight-card.active {
  display: block;
}

@keyframes insightFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.insight-section-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-bottom: 0.6rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.insight-text {
  color: #2c3e50;
  line-height: 1.65;
  font-size: 0.88rem;
}

.mustknow {
  margin-top: 1rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--border);
}

.mustknow-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #c0392b;
  margin-bottom: 0.4rem;
}

.mustknow ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.mustknow li {
  position: relative;
  padding-left: 1rem;
  margin-bottom: 0.35rem;
  font-size: 0.82rem;
  line-height: 1.5;
  color: #34495e;
}

.mustknow li::before {
  content: "\25B8";
  position: absolute;
  left: 0;
  color: #c0392b;
  font-size: 0.7rem;
  top: 0.1rem;
}

.insight-empty {
  color: #999;
  font-style: italic;
  font-size: 0.85rem;
  margin-top: 2rem;
  text-align: center;
}

/* Scrollbar styling for insight panel */
.insight-body::-webkit-scrollbar {
  width: 5px;
}
.insight-body::-webkit-scrollbar-track {
  background: transparent;
}
.insight-body::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}
.insight-body::-webkit-scrollbar-thumb:hover {
  background: #aaa;
}

/* ── Index Page ── */
.book-header {
  text-align: center;
  padding: 3rem 0 2rem;
  border-bottom: 2px solid var(--accent);
  margin-bottom: 2.5rem;
}

.book-header h1 {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 2rem;
  color: var(--accent);
  line-height: 1.3;
  margin-bottom: 0.5rem;
  border: none;
}

.book-header .subtitle {
  font-size: 1.15rem;
  color: #555;
  font-style: italic;
}

.book-header .author {
  font-size: 1rem;
  color: #666;
  margin-top: 0.3rem;
}

.index-content { margin-top: 1rem; }

.toc-part {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 0.95rem;
  color: #555;
  margin: 1.8rem 0 0.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-weight: 600;
}

.toc-list {
  list-style: none;
  padding-left: 0;
}

.toc-list li {
  margin: 0.3rem 0;
  padding: 0.5rem 0.8rem;
  border-radius: 4px;
  transition: background 0.15s;
}

.toc-list li:hover { background: var(--accent-light); }

.toc-list li a {
  color: var(--accent);
  text-decoration: none;
  font-size: 1.05rem;
  display: block;
}

.toc-list li a:hover { text-decoration: underline; }

.toc-preface { font-style: italic; }

.nb-badge {
  font-size: 0.85rem;
  margin-left: 0.3rem;
}

/* ── Typography ── */
h1, h2, h3, h4 {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: var(--accent);
  margin-top: 2.5rem;
  margin-bottom: 0.8rem;
}

h1 {
  font-size: 1.8rem;
  border-bottom: 2px solid var(--accent);
  padding-bottom: 0.5rem;
}

h2 {
  font-size: 1.4rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3rem;
}

h3 { font-size: 1.15rem; }
h4 { font-size: 1.05rem; }

p { margin: 0.8rem 0; }

/* Links */
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }

/* Code */
pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem 1.2rem;
  overflow-x: auto;
  font-size: 0.88rem;
  line-height: 1.5;
  margin: 1.2rem 0;
}

code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.88em;
}

p > code, li > code, td > code {
  background: var(--code-bg);
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  font-size: 0.85em;
  color: #c7254e;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.93rem;
}

th, td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.7rem;
  text-align: left;
}

th {
  background: var(--accent);
  color: #fff;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-weight: 600;
}

tr:nth-child(even) { background: #f7f9fc; }
tr:hover { background: var(--accent-light); }

/* Images / SVG */
img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5rem auto;
}

img[src*="chapters/"] {
  max-width: 100%;
  max-height: 500px;
  width: auto;
  object-fit: contain;
}

figure {
  margin: 1.5rem 0;
  text-align: center;
}

figcaption {
  font-size: 0.9rem;
  color: #555;
  font-style: italic;
  margin-top: 0.5rem;
}

/* Blockquotes */
blockquote {
  border-left: 4px solid var(--accent);
  margin: 1.5rem 0;
  padding: 0.8rem 1.2rem;
  color: #333;
  background: #f0f4f8;
  border-radius: 0 6px 6px 0;
}

/* Lists */
ul, ol { margin: 0.8rem 0; padding-left: 1.8rem; }
li { margin: 0.3rem 0; }

/* Bold */
strong { color: #111; }

/* Horizontal rules */
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

/* ── Bottom Navigation ── */
.bottom-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.2rem 0;
  border-top: 2px solid var(--border);
  margin-top: 3rem;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 0.88rem;
  gap: 1rem;
}

.bottom-nav a {
  color: var(--accent);
  text-decoration: none;
  max-width: 40%;
}

.bottom-nav a:hover { text-decoration: underline; }

.bottom-nav > a:nth-child(2) {
  font-weight: 600;
  white-space: nowrap;
}

/* ── Print ── */
@media print {
  .sidebar, .mobile-menu-btn, .bottom-nav, .insight-panel { display: none !important; }
  .main-content { margin-left: 0; margin-right: 0 !important; max-width: none; font-size: 11pt; }
  body.has-insights .main-content { margin-right: 0 !important; }
  pre { white-space: pre-wrap; }
}

/* ── Wide screen: content + insight panel side by side ── */
@media (min-width: 1400px) {
  body.has-insights .main-content {
    max-width: calc(100vw - var(--sidebar-width) - var(--insight-width) - 2rem);
  }
}

/* ── Tablet ── */
@media (max-width: 1024px) {
  :root { --sidebar-width: 240px; --insight-width: 280px; }
  .main-content { padding: 2rem 1.5rem 3rem; }
}

/* ── Mobile ── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    width: 280px;
  }

  .sidebar.open { transform: translateX(0); }

  .main-content {
    margin-left: 0;
    padding: 3.5rem 1rem 2rem;
    font-size: 1rem;
    max-width: 100%;
    width: 100%;
  }

  .mobile-menu-btn { display: block; }

  .insight-panel { display: none; }
  body.has-insights .main-content { margin-right: 0; }

  .book-header h1 { font-size: 1.4rem; }
  .book-header .subtitle { font-size: 0.95rem; }
  h1 { font-size: 1.4rem; }
  h2 { font-size: 1.15rem; }
  h3 { font-size: 1.05rem; }
  pre { font-size: 0.78rem; padding: 0.7rem; overflow-x: auto; }
  table { font-size: 0.85rem; display: block; overflow-x: auto; }

  img { max-width: 100%; height: auto; }
  img[src*="chapters/"] { max-height: 300px; }

  .bottom-nav { font-size: 0.78rem; flex-wrap: wrap; gap: 0.5rem; }
  .bottom-nav a { max-width: 45%; }

  .index-content { padding: 0 0.5rem; }
  .toc-list { font-size: 0.95rem; }
  .toc-part { font-size: 0.9rem; }
}

/* ── Small mobile ── */
@media (max-width: 480px) {
  .main-content { padding: 3rem 0.7rem 1.5rem; }
  .book-header h1 { font-size: 1.2rem; }
  h1 { font-size: 1.2rem; }
  h2 { font-size: 1.05rem; }
  body { font-size: 0.95rem; }
}
