/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f8f9fb;
  --bg-card: #ffffff;
  --bg-sidebar: #1e293b;
  --bg-sidebar-hover: #334155;
  --bg-sidebar-active: #3b82f6;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-sidebar: #cbd5e1;
  --text-sidebar-active: #ffffff;
  --border: #e2e8f0;
  --accent: #3b82f6;
  --accent-light: #dbeafe;
  --accent-dark: #1d4ed8;
  --success: #22c55e;
  --success-bg: #dcfce7;
  --warning: #f59e0b;
  --code-bg: #f1f5f9;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.1);
  --radius: 8px;
  --sidebar-w: 280px;
  --header-h: 56px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'JetBrains Mono', monospace;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-sidebar: #0f172a;
  --bg-sidebar-hover: #1e293b;
  --border: #334155;
  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --accent-light: #1e3a5f;
  --code-bg: #1e293b;
  --shadow: 0 1px 3px rgba(0,0,0,.3);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.4);
}

html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  display: flex;
  min-height: 100vh;
}

/* === Sidebar === */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  color: var(--text-sidebar);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 100;
  transition: transform .3s ease;
  display: flex;
  flex-direction: column;
}

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

.sidebar-header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.01em;
}

.sidebar-header .subtitle {
  font-size: .75rem;
  color: #94a3b8;
  margin-top: 2px;
}

/* Search */
.sidebar-search {
  padding: 12px 16px;
  flex-shrink: 0;
}

.sidebar-search input {
  width: 100%;
  padding: 8px 12px 8px 32px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 6px;
  color: #fff;
  font-size: .85rem;
  outline: none;
  transition: border-color .2s;
}

.sidebar-search input::placeholder { color: #64748b; }
.sidebar-search input:focus { border-color: var(--accent); }

.sidebar-search .search-wrapper {
  position: relative;
}

.sidebar-search .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: #64748b;
  font-size: .8rem;
  pointer-events: none;
}

/* Nav */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.nav-section {
  margin-bottom: 4px;
}

.nav-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #64748b;
  cursor: pointer;
  user-select: none;
  transition: color .2s;
}

.nav-section-title:hover { color: #94a3b8; }

.nav-section-title .chevron {
  font-size: .6rem;
  transition: transform .2s;
}

.nav-section.collapsed .chevron { transform: rotate(-90deg); }
.nav-section.collapsed .nav-items { display: none; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px 7px 28px;
  font-size: .84rem;
  color: var(--text-sidebar);
  text-decoration: none;
  cursor: pointer;
  transition: all .15s;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background: var(--bg-sidebar-hover);
  color: #fff;
}

.nav-item.active {
  background: rgba(59,130,246,.15);
  color: var(--text-sidebar-active);
  border-left-color: var(--accent);
  font-weight: 500;
}

.nav-item .check {
  font-size: .7rem;
  color: var(--success);
  margin-left: auto;
  opacity: 0;
  transition: opacity .2s;
}

.nav-item.completed .check { opacity: 1; }

/* Progress bar */
.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,.1);
  flex-shrink: 0;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  font-size: .75rem;
  color: #94a3b8;
  margin-bottom: 6px;
}

.progress-bar {
  height: 4px;
  background: rgba(255,255,255,.1);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--success);
  border-radius: 2px;
  transition: width .4s ease;
}

/* === Main Content === */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
}

.main-header {
  position: sticky;
  top: 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 50;
  backdrop-filter: blur(8px);
}

.breadcrumb {
  font-size: .85rem;
  color: var(--text-secondary);
}

.breadcrumb span { color: var(--text); font-weight: 500; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1rem;
  transition: all .15s;
}

.btn-icon:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.burger {
  display: none;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
}

/* Content area */
.content {
  max-width: 800px;
  margin: 0 auto;
  padding: 32px;
}

.page { display: none; }
.page.active { display: block; }

/* === Home page === */
.home-hero {
  text-align: center;
  padding: 48px 0 32px;
}

.home-hero h2 {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.home-hero p {
  color: var(--text-secondary);
  font-size: 1rem;
}

.exam-structure {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin: 24px 0;
  box-shadow: var(--shadow);
}

.exam-structure h3 {
  font-size: 1rem;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.exam-table {
  width: 100%;
  border-collapse: collapse;
}

.exam-table th, .exam-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
}

.exam-table th {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.section-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 32px;
}

.section-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: all .2s;
  box-shadow: var(--shadow);
}

.section-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.section-card .card-icon {
  font-size: 1.5rem;
  margin-bottom: 8px;
}

.section-card h4 {
  font-size: .95rem;
  margin-bottom: 4px;
}

.section-card p {
  font-size: .8rem;
  color: var(--text-secondary);
}

.section-card .card-progress {
  margin-top: 12px;
  font-size: .75rem;
  color: var(--success);
  font-weight: 500;
}

/* === Typography in content pages === */
.page-content h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 32px 0 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--accent);
  color: var(--text);
}

.page-content h2:first-child { margin-top: 0; }

.page-content h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 24px 0 12px;
  color: var(--text);
}

.page-content h4 {
  font-size: 1rem;
  font-weight: 600;
  margin: 16px 0 8px;
}

.page-content p {
  margin-bottom: 12px;
}

.page-content ul, .page-content ol {
  margin: 8px 0 16px 24px;
}

.page-content li { margin-bottom: 4px; }

/* Ticket block */
.ticket {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin: 20px 0;
  box-shadow: var(--shadow);
  position: relative;
}

.ticket-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.ticket-number {
  font-size: .75rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-light);
  padding: 3px 10px;
  border-radius: 12px;
}

.ticket-check {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  transition: all .2s;
  font-size: .8rem;
  flex-shrink: 0;
}

.ticket-check:hover { border-color: var(--success); }

.ticket-check.checked {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

/* Definition, theorem, proof boxes */
.def, .thm, .proof, .example, .note, .warn {
  padding: 16px 20px;
  border-radius: var(--radius);
  margin: 12px 0;
  font-size: .92rem;
}

.def {
  background: var(--accent-light);
  border-left: 4px solid var(--accent);
}

.thm {
  background: #fef3c7;
  border-left: 4px solid var(--warning);
}

[data-theme="dark"] .thm {
  background: rgba(245,158,11,.1);
}

.proof {
  background: var(--code-bg);
  border-left: 4px solid #94a3b8;
  font-size: .88rem;
}

.proof::before {
  content: 'Доказательство.';
  font-weight: 700;
  display: block;
  margin-bottom: 8px;
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--text-secondary);
}

.proof-end {
  text-align: right;
  font-weight: 700;
  margin-top: 4px;
}

.example {
  background: var(--success-bg);
  border-left: 4px solid var(--success);
}

[data-theme="dark"] .example {
  background: rgba(34,197,94,.08);
}

.note {
  background: var(--code-bg);
  border-left: 4px solid var(--text-secondary);
}

.warn {
  background: #fef2f2;
  border-left: 4px solid #ef4444;
}

[data-theme="dark"] .warn {
  background: rgba(239,68,68,.08);
}

.label {
  font-weight: 700;
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  margin-bottom: 6px;
  display: block;
}

.def .label { color: var(--accent-dark); }
.thm .label { color: #b45309; }
.example .label { color: #15803d; }
.note .label { color: var(--text-secondary); }
.warn .label { color: #dc2626; }

[data-theme="dark"] .def .label { color: #60a5fa; }
[data-theme="dark"] .thm .label { color: #fbbf24; }

/* Math display */
.math-display {
  overflow-x: auto;
  padding: 12px 0;
  text-align: center;
}

/* Tables */
.page-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: .9rem;
}

.page-content th, .page-content td {
  padding: 10px 14px;
  border: 1px solid var(--border);
  text-align: left;
}

.page-content th {
  background: var(--code-bg);
  font-weight: 600;
  font-size: .85rem;
}

.page-content tr:hover {
  background: var(--code-bg);
}

/* Mnemonic */
.mnemonic {
  background: linear-gradient(135deg, var(--accent-light), #ede9fe);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 16px 0;
  font-size: .9rem;
}

[data-theme="dark"] .mnemonic {
  background: linear-gradient(135deg, rgba(59,130,246,.1), rgba(139,92,246,.1));
}

.mnemonic .label { color: var(--accent-dark); }

/* Algorithm flowchart */
.algo {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin: 16px 0;
  font-family: var(--font-mono);
  font-size: .82rem;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-x: auto;
}

/* Summary table */
.summary-table {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 16px 0;
}

.summary-table table { margin: 0; }
.summary-table th { background: var(--accent); color: #fff; }
[data-theme="dark"] .summary-table th { background: #1e40af; }

/* Search results highlight */
mark {
  background: #fde047;
  color: #000;
  padding: 0 2px;
  border-radius: 2px;
}

[data-theme="dark"] mark {
  background: #854d0e;
  color: #fde047;
}

.search-results {
  padding: 8px 16px;
  max-height: 400px;
  overflow-y: auto;
}

.search-result-item {
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: .84rem;
  color: var(--text-sidebar);
  transition: background .15s;
}

.search-result-item:hover { background: var(--bg-sidebar-hover); }

.search-result-item .result-section {
  font-size: .7rem;
  color: #64748b;
}

/* Overlay for mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 90;
}

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

/* === Responsive === */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

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

  .main { margin-left: 0; }

  .burger { display: flex; }

  .content { padding: 20px 16px; }

  .main-header { padding: 0 16px; }

  .section-cards {
    grid-template-columns: 1fr;
  }

  .home-hero h2 { font-size: 1.4rem; }

  .ticket { padding: 16px; }
}

@media (max-width: 480px) {
  .page-content h2 { font-size: 1.2rem; }
  .page-content h3 { font-size: 1.05rem; }
  .exam-table { font-size: .8rem; }
  .exam-table th, .exam-table td { padding: 8px; }
}

/* Print */
@media print {
  .sidebar, .main-header { display: none !important; }
  .main { margin-left: 0 !important; }
  .page { display: block !important; page-break-before: always; }
  .ticket { break-inside: avoid; }
}

/* Smooth transitions */
.page-content { animation: fadeIn .3s ease; }

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

/* KaTeX overrides */
.katex { font-size: 1.05em; }
.katex-display { margin: .8em 0; overflow-x: auto; overflow-y: hidden; }
