/* ============================================
   Buffett Wisdom Book - Enhanced CSS
   ============================================ */

:root {
  --primary: #2c5f2d;
  --primary-light: #4a8f4b;
  --secondary: #1a3a1a;
  --accent: #97bc62;
  --accent2: #ffc107;
  --bg-light: #f8f9fa;
  --bg-dark: #1e1e1e;
  --text-dark: #333;
  --text-light: #f0f0f0;
  --text-muted: #666;
  --card-bg: #fff;
  --card-radius: 12px;
  --card-shadow: 0 2px 8px rgba(0,0,0,0.08);
  --sidebar-width: 280px;
  --header-height: 60px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans SC', sans-serif;
  line-height: 1.7;
  color: var(--text-dark);
  background: var(--bg-light);
}

/* ===== Layout ===== */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(180deg, var(--secondary) 0%, var(--primary) 100%);
  color: var(--text-light);
  position: fixed;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-logo {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo span:first-child {
  font-size: 26px;
}

.sidebar-nav {
  padding: 16px 0;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}

.nav-section {
  padding: 0;
}

.nav-section-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: rgba(255,255,255,0.5);
  padding: 12px 20px 4px;
}

.nav-item {
  display: block;
  padding: 8px 20px;
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  font-size: 13px;
  border-left: 3px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-item:hover {
  background: rgba(255,255,255,0.08);
  border-left-color: var(--accent);
  color: #fff;
}

.nav-item.active {
  background: rgba(255,255,255,0.12);
  border-left-color: var(--accent2);
  color: #fff;
  font-weight: 600;
}

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
}

.topbar {
  background: #fff;
  height: var(--header-height);
  border-bottom: 1px solid #eee;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--secondary);
}

.topbar-actions {
  display: flex;
  gap: 12px;
}

.btn {
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover { background: var(--primary-light); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--primary);
  color: var(--primary);
}

.btn-outline:hover { background: var(--primary); color: #fff; }

.content-wrapper {
  padding: 32px 48px;
  max-width: 1200px;
}

/* ===== Hero ===== */
.hero {
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: #fff;
  padding: 56px;
  border-radius: 16px;
  margin-bottom: 40px;
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  right: -30px;
  bottom: -30px;
  width: 250px;
  height: 250px;
  background: rgba(255,255,255,0.05);
  border-radius: 50%;
}

.hero-badge {
  display: inline-block;
  background: var(--accent);
  color: var(--secondary);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 16px;
}

.hero h1 {
  font-size: 38px;
  font-weight: 800;
  margin-bottom: 12px;
  line-height: 1.2;
}

.hero-subtitle {
  font-size: 16px;
  opacity: 0.9;
  margin-bottom: 24px;
  max-width: 600px;
}

.hero-stats {
  display: flex;
  gap: 40px;
  margin-top: 32px;
}

.stat-item {
  text-align: center;
}

.stat-value {
  font-size: 36px;
  font-weight: 700;
  color: var(--accent);
}

.stat-label {
  font-size: 12px;
  opacity: 0.8;
}

/* ===== Cards ===== */
.card {
  background: var(--card-bg);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  padding: 24px;
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.card-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.card-icon.blue { background: #dbeafe; }
.card-icon.green { background: #dcfce7; }
.card-icon.amber { background: #fef3c7; }
.card-icon.red { background: #fee2e2; }
.card-icon.purple { background: #f3e8ff; }
.card-icon.cyan { background: #cffafe; }

.card-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--secondary);
}

.card h3 {
  font-size: 19px;
  margin-bottom: 12px;
  color: var(--secondary);
}

/* ===== Grid ===== */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* ===== Quote Blocks ===== */
.quote-block {
  background: linear-gradient(135deg, var(--secondary) 0%, var(--primary) 100%);
  color: #fff;
  padding: 28px;
  border-radius: 12px;
  margin: 20px 0;
  position: relative;
}

.quote-block::before {
  content: '"';
  position: absolute;
  top: 5px;
  left: 16px;
  font-size: 70px;
  opacity: 0.15;
  font-family: Georgia, serif;
  line-height: 1;
}

.quote-text {
  font-size: 18px;
  font-style: italic;
  line-height: 1.6;
  margin-bottom: 12px;
  position: relative;
  z-index: 1;
}

.quote-author {
  font-size: 13px;
  opacity: 0.8;
}

.quote-author strong { color: var(--accent); }

/* ===== Theme Cards ===== */
.theme-card {
  background: #fff;
  border-radius: var(--card-radius);
  padding: 20px;
  box-shadow: var(--card-shadow);
  transition: all 0.3s;
  cursor: pointer;
}

.theme-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(0,0,0,0.1);
}

.theme-card .theme-icon {
  font-size: 36px;
  margin-bottom: 12px;
}

.theme-card h4 {
  font-size: 14px;
  margin-bottom: 6px;
  color: var(--secondary);
}

.theme-card p {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ===== Chapter Header ===== */
.chapter-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: #fff;
  padding: 40px;
  border-radius: 12px;
  margin-bottom: 32px;
}

.chapter-badge {
  display: inline-block;
  background: var(--accent);
  color: var(--secondary);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 12px;
}

.chapter-header h1 {
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 8px;
}

.chapter-intro {
  font-size: 15px;
  opacity: 0.9;
  max-width: 600px;
}

/* ===== Lesson Cards ===== */
.lessons-section {
  margin-top: 24px;
}

.lessons-section h2 {
  font-size: 20px;
  margin-bottom: 20px;
  color: var(--secondary);
}

.lesson-count {
  font-weight: normal;
  font-size: 14px;
  color: var(--text-muted);
}

.lesson-card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  margin-bottom: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s;
}

.lesson-card:hover {
  box-shadow: 0 3px 12px rgba(0,0,0,0.1);
}

.lesson-card h4 {
  padding: 16px 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--secondary);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  line-height: 1.5;
}

.lesson-title {
  color: var(--secondary);
  font-weight: 600;
}

.lesson-title-en {
  color: #888;
  font-weight: 400;
  font-size: 12px;
}

.lesson-original-title {
  color: #666;
  font-size: 13px;
  border-bottom: 1px solid #eee;
  padding-bottom: 10px;
  margin-bottom: 10px;
}

.lesson-original-title strong {
  color: #888;
}

.lesson-body {
  font-size: 14px;
  line-height: 1.7;
  color: #555;
}

.lesson-body .bullet {
  color: var(--primary);
  margin-right: 8px;
}

.lesson-body blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 12px 0;
  font-style: italic;
  color: #666;
}

.lesson-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  font-size: 12px;
  flex-shrink: 0;
}

.toggle-icon {
  margin-left: auto;
  font-size: 11px;
  color: #999;
  transition: transform 0.2s;
}

.lesson-card.open .toggle-icon {
  transform: rotate(180deg);
}

.lesson-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  background: #fafafa;
}

.lesson-content.show {
  max-height: 600px;
}

.lesson-content p {
  padding: 16px 20px;
  font-size: 14px;
  color: #555;
  line-height: 1.7;
  border-top: 1px solid #eee;
}

.lesson-content strong {
  color: var(--primary);
}

/* ===== Quote Mini ===== */
.quotes-section {
  margin-top: 40px;
  padding-top: 32px;
  border-top: 1px solid #eee;
}

.quotes-section h3 {
  font-size: 18px;
  margin-bottom: 20px;
  color: var(--secondary);
}

.quote-mini {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
  border-left: 4px solid var(--accent);
}

.quote-mini blockquote {
  font-size: 14px;
  font-style: italic;
  color: #444;
  line-height: 1.6;
  margin-bottom: 8px;
}

.quote-mini cite {
  font-size: 12px;
  color: #888;
  font-style: normal;
}

/* ===== Chapter Navigation ===== */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid #eee;
}

.chapter-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 32px;
  background: #fff;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text-dark);
  box-shadow: var(--card-shadow);
  transition: all 0.2s;
  min-width: 160px;
}

.chapter-nav a:hover {
  background: var(--primary);
  color: #fff;
}

.chapter-nav .prev-chapter { align-items: flex-start; }
.chapter-nav .next-chapter { align-items: flex-end; margin-left: auto; }

.chapter-nav span {
  font-size: 12px;
  opacity: 0.7;
}

.chapter-nav .disabled {
  padding: 16px;
  color: #ccc;
}

/* ===== Table ===== */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 14px;
}

th {
  background: #f5f5f5;
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid #ddd;
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid #eee;
}

tr:hover { background: #fafafa; }

/* ===== Tags ===== */
.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  margin-right: 4px;
  margin-bottom: 4px;
}

.tag-blue { background: #dbeafe; color: #1d4ed8; }
.tag-green { background: #dcfce7; color: #15803d; }
.tag-amber { background: #fef3c7; color: #b45309; }
.tag-red { background: #fee2e2; color: #dc2626; }

/* ===== Search ===== */
.search-box {
  position: relative;
  margin-bottom: 32px;
}

.search-box input {
  width: 100%;
  padding: 14px 20px 14px 48px;
  border: 2px solid #e5e7eb;
  border-radius: 10px;
  font-size: 15px;
  transition: border-color 0.2s;
}

.search-box input:focus {
  outline: none;
  border-color: var(--primary);
}

/* ===== Guide Box ===== */
.guide-box {
  padding: 18px 22px;
  border-radius: 10px;
  margin: 16px 0;
}

.guide-box.target {
  background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
  border-left: 4px solid #3b82f6;
}

.guide-box.prerequisite {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border-left: 4px solid #f59e0b;
}

.guide-box.gain {
  background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
  border-left: 4px solid #22c55e;
}

.guide-box strong {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
}

/* ===== Footer ===== */
.footer {
  background: var(--secondary);
  color: rgba(255,255,255,0.7);
  padding: 32px;
  text-align: center;
  margin-top: 64px;
}

.footer a { color: var(--accent); }
.footer p { margin: 4px 0; }

/* ===== Mobile Toggle ===== */
.mobile-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 8px;
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .main-content {
    margin-left: 0;
  }
  
  .mobile-toggle {
    display: block;
  }
  
  .content-wrapper {
    padding: 20px;
  }
  
  .hero {
    padding: 32px 24px;
  }
  
  .hero h1 {
    font-size: 26px;
  }
  
  .hero-stats {
    flex-wrap: wrap;
    gap: 20px;
  }
  
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
  }
  
  .topbar {
    padding: 0 16px;
  }
  
  .topbar-title {
    font-size: 14px;
  }
  
  .chapter-nav {
    flex-direction: column;
    gap: 12px;
  }
  
  .chapter-nav a {
    width: 100%;
    align-items: center;
  }
  
  .chapter-nav .next-chapter {
    align-items: center;
    margin-left: 0;
  }
}

/* ===== Dark Mode ===== */
@media (prefers-color-scheme: dark) {
  body.dark-mode {
    background: var(--bg-dark);
    color: var(--text-light);
  }
  
  body.dark-mode .card,
  body.dark-mode .theme-card,
  body.dark-mode .lesson-card,
  body.dark-mode .quote-mini {
    background: #2a2a2a;
    color: var(--text-light);
  }
  
  body.dark-mode .topbar {
    background: #2a2a2a;
    border-color: #444;
  }
  
  body.dark-mode .topbar-title {
    color: var(--text-light);
  }
  
  body.dark-mode .lesson-content {
    background: #252525;
  }
  
  body.dark-mode .lesson-content p {
    color: #aaa;
  }
  
  body.dark-mode table th {
    background: #333;
  }
  
  body.dark-mode table td {
    border-color: #444;
  }
  
  body.dark-mode tr:hover {
    background: #333;
  }
}
