:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --panel-soft: #eef4ff;
  --text: #1b2430;
  --muted: #5b6675;
  --line: #d9e2ef;
  --accent: #2457d6;
  --accent-soft: #dce7ff;
  --success: #0d8b57;
  --warning: #b56a00;
  --shadow: 0 18px 50px rgba(28, 39, 60, 0.08);
}

body.dark {
  --bg: #101623;
  --panel: #151d2d;
  --panel-soft: #1a2437;
  --text: #e8eef9;
  --muted: #aab7ca;
  --line: #2a3850;
  --accent: #82a9ff;
  --accent-soft: #20345d;
  --success: #5ad39c;
  --warning: #ffbc65;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: Inter, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

code {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  padding: 0.15rem 0.4rem;
  border-radius: 0.45rem;
}

.app-shell {
  display: grid;
  grid-template-columns: 310px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 1.2rem;
  background: linear-gradient(180deg, var(--panel), var(--panel-soft));
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-bottom: 1rem;
}

.brand-badge {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: white;
  background: linear-gradient(135deg, var(--accent), #8c3dff);
  box-shadow: var(--shadow);
}

.brand h1,
.hero h2,
.doc-title { margin: 0; }
.brand p,
.hero p,
.doc-subtitle,
.status-box { color: var(--muted); }

.sidebar-card,
.hero,
.stat-card,
.doc-card,
.status-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.sidebar-card {
  padding: 1rem;
  margin-bottom: 1rem;
}

.label,
.stat-label,
.eyebrow {
  display: inline-block;
  font-size: 0.83rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.input {
  width: 100%;
  padding: 0.95rem 1rem;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--text);
  font-size: 0.98rem;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.8rem;
}
.section-title-row h2 {
  margin: 0;
  font-size: 1rem;
}

.chip-wrap,
.pill-row,
.toggle-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.chip,
.pill,
.ghost-btn,
.primary-btn,
.secondary-btn,
.favorite-btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  font: inherit;
}

.chip,
.ghost-btn,
.secondary-btn,
.favorite-btn {
  background: var(--panel-soft);
  color: var(--text);
}

.chip,
.ghost-btn,
.primary-btn,
.secondary-btn {
  padding: 0.65rem 0.9rem;
  cursor: pointer;
}

.chip.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.primary-btn {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  font-weight: 700;
}

.secondary-btn:hover,
.ghost-btn:hover,
.chip:hover,
.favorite-btn:hover,
.primary-btn:hover {
  transform: translateY(-1px);
}

.main-content {
  padding: 1.4rem;
}

.hero {
  padding: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.hero h2 {
  font-size: clamp(1.7rem, 4vw, 2.5rem);
  margin-top: 0.35rem;
  margin-bottom: 0.55rem;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
}

.stats-grid,
.docs-grid {
  display: grid;
  gap: 1rem;
}

.stats-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 1rem;
}

.stat-card {
  padding: 1.1rem;
}

.stat-card strong {
  display: block;
  margin-top: 0.25rem;
  font-size: 1.8rem;
}

.status-box {
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}

.controls-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.docs-grid {
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
}

.doc-card {
  padding: 1rem;
}

.doc-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.9rem;
}

.doc-subtitle {
  margin: 0.55rem 0 0;
  line-height: 1.55;
}

.favorite-btn {
  width: 42px;
  height: 42px;
  font-size: 1.2rem;
  cursor: pointer;
}

.pill {
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 700;
}

.level-pill {
  background: var(--accent-soft);
  color: var(--accent);
}

.type-pill {
  background: rgba(14, 139, 87, 0.11);
  color: var(--success);
}

.unit-card {
  border: 1px solid var(--line);
  border-radius: 20px;
  overflow: hidden;
  background: var(--panel-soft);
  margin-top: 0.8rem;
}

.unit-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.95rem 1rem;
}

.unit-summary::-webkit-details-marker { display: none; }
.unit-summary strong { font-size: 1rem; }
.unit-summary small { color: var(--muted); }

.unit-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.study-checkbox {
  width: 18px;
  height: 18px;
}

.unit-body {
  padding: 0 1rem 1rem;
  border-top: 1px solid var(--line);
}

.unit-body :is(h1,h2,h3,h4) {
  margin-top: 1rem;
  margin-bottom: 0.55rem;
}

.unit-body p,
.unit-body li {
  line-height: 1.7;
  color: var(--text);
}

.unit-body table {
  width: 100%;
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
}

.unit-body th,
.unit-body td {
  border: 1px solid var(--line);
  padding: 0.65rem;
  text-align: left;
  vertical-align: top;
}

.unit-body blockquote {
  margin: 1rem 0;
  padding: 0.9rem 1rem;
  border-left: 4px solid var(--accent);
  background: var(--panel);
  border-radius: 12px;
}

.doc-nav {
  display: grid;
  gap: 0.55rem;
}

.doc-nav a {
  text-decoration: none;
  color: var(--text);
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.75rem 0.85rem;
}

.toggle-inline {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--muted);
}

mark {
  background: #ffe69b;
  color: #111;
  padding: 0.1rem 0.2rem;
  border-radius: 0.2rem;
}

.empty-state {
  grid-column: 1 / -1;
  padding: 1.5rem;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 24px;
  background: var(--panel);
  color: var(--muted);
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  .main-content,
  .sidebar {
    padding: 1rem;
  }

  .hero,
  .controls-row {
    flex-direction: column;
    align-items: stretch;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .docs-grid {
    grid-template-columns: 1fr;
  }
}
