/* ============================================================
   Прикладная математика — Программа обучения
   ============================================================ */

/* ---------- Custom properties ---------- */
:root {
  --sidebar-w: 264px;
  --radius: 10px;
  --radius-sm: 6px;
  --transition: 200ms ease;

  /* Sidebar */
  --sb-bg: #0f172a;
  --sb-text: #94a3b8;
  --sb-text-active: #f8fafc;
  --sb-hover: rgba(255,255,255,.06);
  --sb-active-bg: rgba(99,102,241,.25);
  --sb-active-border: #6366f1;
  --sb-border: rgba(255,255,255,.07);

  /* Main surface */
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;

  /* Accent */
  --primary: #2563eb;
  --primary-light: #eff6ff;
  --indigo: #6366f1;
  --indigo-light: #eef2ff;
  --badge-bg: #fef3c7;
  --badge-text: #92400e;
  --badge-border: #fde68a;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow: 0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -1px rgba(0,0,0,.05);
  --shadow-md: 0 10px 15px -3px rgba(0,0,0,.07), 0 4px 6px -2px rgba(0,0,0,.05);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }
button { cursor: pointer; border: none; background: none; font: inherit; }
input { font: inherit; border: none; outline: none; background: transparent; }
svg { display: block; flex-shrink: 0; }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--sb-bg);
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 200;
  transition: transform var(--transition);
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 0 1.5rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.1) transparent;
}
.sidebar-inner::-webkit-scrollbar { width: 4px; }
.sidebar-inner::-webkit-scrollbar-track { background: transparent; }
.sidebar-inner::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 2px; }

/* Brand */
.brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--sb-border);
}
.brand-badge {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--indigo));
  color: #fff;
  font-weight: 700;
  font-size: .85rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  letter-spacing: .5px;
}
.brand-name {
  color: var(--sb-text-active);
  font-size: .85rem;
  font-weight: 600;
  line-height: 1.3;
}
.brand-sub {
  color: var(--sb-text);
  font-size: .73rem;
  margin-top: 1px;
}

/* Search */
.search-wrap {
  position: relative;
  margin: 1rem 1rem .5rem;
}
.search-icon {
  position: absolute;
  left: .65rem; top: 50%;
  transform: translateY(-50%);
  width: 14px; height: 14px;
  color: var(--sb-text);
  pointer-events: none;
}
.search-input {
  width: 100%;
  background: rgba(255,255,255,.07);
  border: 1px solid var(--sb-border);
  border-radius: var(--radius-sm);
  color: var(--sb-text-active);
  padding: .5rem .5rem .5rem 2rem;
  font-size: .8rem;
  transition: border-color var(--transition), background var(--transition);
}
.search-input::placeholder { color: var(--sb-text); }
.search-input:focus {
  border-color: var(--indigo);
  background: rgba(255,255,255,.1);
}
.search-clear {
  position: absolute;
  right: .5rem; top: 50%;
  transform: translateY(-50%);
  color: var(--sb-text);
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 .2rem;
  transition: color var(--transition);
}
.search-clear:hover { color: var(--sb-text-active); }

/* Semester nav */
.nav-label {
  color: var(--sb-text);
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: .75rem 1.25rem .4rem;
}

.semester-nav { padding: 0 .625rem; }
.semester-nav li { margin-bottom: 2px; }
.semester-nav a {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .45rem .625rem;
  border-radius: var(--radius-sm);
  color: var(--sb-text);
  font-size: .82rem;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  border-left: 2px solid transparent;
}
.semester-nav a:hover {
  background: var(--sb-hover);
  color: var(--sb-text-active);
}
.semester-nav a.active {
  background: var(--sb-active-bg);
  color: var(--sb-text-active);
  border-left-color: var(--sb-active-border);
  font-weight: 500;
}
.nav-sem-num {
  width: 20px; height: 20px;
  border-radius: 4px;
  background: rgba(255,255,255,.1);
  color: var(--sb-text-active);
  font-size: .7rem;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.semester-nav a.active .nav-sem-num {
  background: var(--indigo);
}

/* Sidebar stats */
.sidebar-stats {
  display: flex;
  justify-content: space-around;
  margin: 1.25rem 1rem 0;
  padding: .875rem .5rem;
  background: rgba(255,255,255,.05);
  border-radius: var(--radius-sm);
  border: 1px solid var(--sb-border);
}
.stat { text-align: center; }
.stat-value {
  display: block;
  color: var(--sb-text-active);
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.2;
}
.stat-name {
  display: block;
  color: var(--sb-text);
  font-size: .68rem;
  margin-top: 2px;
}

/* ---------- Main area ---------- */
.main {
  min-width: 0;
  grid-column: 2;
}

/* Header */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 2rem 2rem 1.5rem;
}
.header-inner { max-width: 960px; }
.header-title {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--text);
  line-height: 1.25;
}
.header-sub {
  margin-top: .4rem;
  color: var(--text-muted);
  font-size: .9rem;
}
.header-notice {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: 1rem;
  padding: .6rem .9rem;
  background: var(--indigo-light);
  border-radius: var(--radius-sm);
  border: 1px solid #c7d2fe;
  color: #4338ca;
  font-size: .82rem;
  max-width: 640px;
}
.header-notice svg { width: 15px; height: 15px; flex-shrink: 0; }

/* Content area */
.content {
  padding: 1.75rem 2rem 3rem;
  max-width: 1100px;
}

/* Semester sections */
.semester-section {
  margin-bottom: 2.5rem;
}

.semester-header {
  display: flex;
  align-items: baseline;
  gap: .75rem;
  margin-bottom: 1rem;
  padding-bottom: .6rem;
  border-bottom: 2px solid var(--border);
}
.semester-header:has(.active-section) {
  border-bottom-color: var(--indigo);
}

.semester-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}
.semester-year {
  font-size: .8rem;
  color: var(--text-muted);
  font-weight: 400;
}
.semester-count {
  margin-left: auto;
  font-size: .75rem;
  color: var(--text-muted);
}

/* Subject grid */
.subject-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: .875rem;
}

/* Subject card */
.subject-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), border-color var(--transition), transform var(--transition);
}
.subject-card:hover {
  box-shadow: var(--shadow-md);
  border-color: #c7d2fe;
  transform: translateY(-1px);
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .5rem;
}
.subject-name {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
}
.subject-icon {
  width: 30px; height: 30px;
  border-radius: 7px;
  background: var(--primary-light);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: var(--primary);
}
.subject-icon svg { width: 16px; height: 16px; }

.subject-desc {
  font-size: .79rem;
  color: var(--text-muted);
  line-height: 1.5;
  flex: 1;
}

.card-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: .1rem;
  padding-top: .6rem;
  border-top: 1px solid var(--border);
}

.notes-badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .72rem;
  font-weight: 500;
  color: var(--badge-text);
  background: var(--badge-bg);
  border: 1px solid var(--badge-border);
  border-radius: 4px;
  padding: .2rem .5rem;
}
.notes-badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #f59e0b;
}

.notes-link {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .8rem;
  font-weight: 500;
  color: var(--primary);
  padding: .3rem .7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--primary);
  transition: background var(--transition), color var(--transition);
}
.notes-link:hover {
  background: var(--primary);
  color: #fff;
}
.notes-link svg { width: 13px; height: 13px; }

/* Search highlight */
mark {
  background: #fef08a;
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

/* No results */
.no-results {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}
.no-results svg {
  width: 48px; height: 48px;
  margin: 0 auto 1rem;
  opacity: .4;
}
.no-results p {
  font-size: 1rem;
  margin-bottom: 1rem;
}
.btn-reset {
  display: inline-flex;
  align-items: center;
  padding: .5rem 1.25rem;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 500;
  transition: opacity var(--transition);
}
.btn-reset:hover { opacity: .85; }

.hidden { display: none !important; }

/* ---------- Mobile nav toggle ---------- */
.nav-toggle {
  display: none;
  position: fixed;
  top: .875rem;
  left: .875rem;
  z-index: 300;
  width: 38px; height: 38px;
  border-radius: var(--radius-sm);
  background: var(--sb-bg);
  border: 1px solid var(--sb-border);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: .4rem;
  box-shadow: var(--shadow);
}
.nav-toggle span {
  display: block;
  width: 18px; height: 2px;
  background: var(--sb-text-active);
  border-radius: 1px;
  transition: transform var(--transition), opacity var(--transition);
}
.nav-open .nav-toggle span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.nav-open .nav-toggle span:nth-child(2) { opacity: 0; }
.nav-open .nav-toggle span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* ---------- Overlay ---------- */
.overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 150;
  backdrop-filter: blur(1px);
}

/* ---------- Ready badge variant ---------- */
.notes-badge.ready {
  color: #065f46;
  background: #d1fae5;
  border-color: #6ee7b7;
}
.notes-badge.ready::before { background: #10b981; }

/* ---------- Notes placeholder page ---------- */
.notes-page {
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.notes-layout {
  max-width: 860px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  width: 100%;
}

/* ---------- Notes article (filled content) ---------- */
.notes-article {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.notes-header {
  padding: 2.5rem 2.5rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, var(--primary-light), var(--indigo-light));
}
.notes-semester {
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--indigo);
  margin-bottom: .5rem;
}
.notes-article h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--text);
  line-height: 1.3;
}

/* Table of contents */
.toc {
  padding: 1.5rem 2.5rem;
  border-bottom: 1px solid var(--border);
  background: #fafbfd;
}
.toc h2 {
  font-size: .85rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: .75rem;
}
.toc ol {
  list-style: none;
  counter-reset: toc;
  columns: 2;
  column-gap: 2rem;
}
.toc li {
  counter-increment: toc;
  break-inside: avoid;
  margin-bottom: .35rem;
}
.toc li::before {
  content: counter(toc) ". ";
  font-weight: 600;
  color: var(--primary);
}
.toc a {
  font-size: .87rem;
  color: var(--text);
  transition: color var(--transition);
}
.toc a:hover { color: var(--primary); }

/* Notes body */
.notes-body {
  padding: 2rem 2.5rem 3rem;
  line-height: 1.75;
  color: var(--text);
}
.notes-body h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  margin: 2.5rem 0 1rem;
  padding-bottom: .5rem;
  border-bottom: 2px solid var(--border);
}
.notes-body h2:first-child { margin-top: 0; }
.notes-body h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  margin: 1.8rem 0 .6rem;
}
.notes-body h4 {
  font-size: .95rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 1.3rem 0 .5rem;
}
.notes-body p {
  margin-bottom: .85rem;
}
.notes-body ul, .notes-body ol {
  margin: .5rem 0 1rem 1.5rem;
}
.notes-body ul { list-style: disc; }
.notes-body ol { list-style: decimal; }
.notes-body li {
  margin-bottom: .35rem;
  line-height: 1.6;
}
.notes-body strong { font-weight: 600; }

/* Info blocks: definition, theorem, proof, example, remark */
.def, .thm, .proof-block, .example, .remark {
  margin: 1.25rem 0;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-sm);
  border-left: 4px solid;
  font-size: .92rem;
}
.def {
  background: #eff6ff;
  border-color: #3b82f6;
}
.thm {
  background: #fefce8;
  border-color: #eab308;
}
.proof-block {
  background: #f8fafc;
  border-color: #94a3b8;
  font-style: italic;
}
.proof-block::before {
  content: "Доказательство. ";
  font-weight: 600;
  font-style: normal;
}
.proof-block::after {
  content: " ∎";
  font-style: normal;
}
.example {
  background: #f0fdf4;
  border-color: #22c55e;
}
.example::before {
  content: "Пример. ";
  font-weight: 600;
}
.remark {
  background: #fdf4ff;
  border-color: #a855f7;
}
.remark::before {
  content: "Замечание. ";
  font-weight: 600;
}

.def .label, .thm .label {
  display: block;
  font-weight: 700;
  margin-bottom: .4rem;
}

/* Math display blocks */
.notes-body .katex-display {
  margin: 1rem 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: .25rem 0;
}

/* Tables in notes */
.notes-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: .88rem;
}
.notes-body th, .notes-body td {
  border: 1px solid var(--border);
  padding: .5rem .75rem;
  text-align: left;
}
.notes-body th {
  background: #f1f5f9;
  font-weight: 600;
}
.notes-body tr:nth-child(even) { background: #f8fafc; }

/* Code blocks (for programming notes) */
.notes-body code {
  font-family: "JetBrains Mono", "Fira Code", "Consolas", monospace;
  font-size: .85em;
  background: #f1f5f9;
  padding: .15em .35em;
  border-radius: 3px;
  color: #0f172a;
}
.notes-body pre {
  background: #1e293b;
  color: #e2e8f0;
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  overflow-x: auto;
  margin: 1rem 0;
  font-size: .85rem;
  line-height: 1.6;
}
.notes-body pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}
.notes-body pre .kw { color: #c084fc; }
.notes-body pre .type { color: #67e8f9; }
.notes-body pre .str { color: #86efac; }
.notes-body pre .num { color: #fcd34d; }
.notes-body pre .cmt { color: #64748b; font-style: italic; }
.notes-body pre .fn { color: #93c5fd; }

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-size: .85rem;
  color: var(--primary);
  font-weight: 500;
  margin-bottom: 2.5rem;
  transition: gap var(--transition);
}
.back-btn:hover { gap: .6rem; }
.back-btn svg { width: 16px; height: 16px; }

.placeholder-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 3rem 2.5rem;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.placeholder-icon {
  width: 72px; height: 72px;
  border-radius: 18px;
  background: var(--indigo-light);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 1.5rem;
}
.placeholder-icon svg { width: 36px; height: 36px; color: var(--indigo); }

.placeholder-sem {
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--indigo);
  margin-bottom: .5rem;
}

.placeholder-title {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--text);
  margin-bottom: 1.25rem;
  line-height: 1.3;
}

.placeholder-status {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-size: .8rem;
  font-weight: 500;
  color: var(--badge-text);
  background: var(--badge-bg);
  border: 1px solid var(--badge-border);
  border-radius: 999px;
  padding: .3rem .9rem;
  margin-bottom: 1rem;
}
.placeholder-status::before {
  content: '';
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #f59e0b;
}

.placeholder-desc {
  color: var(--text-muted);
  font-size: .9rem;
  line-height: 1.6;
  max-width: 380px;
  margin: 0 auto;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .main {
    grid-column: 1;
  }
  .sidebar {
    transform: translateX(-100%);
  }
  .nav-open .sidebar {
    transform: translateX(0);
    box-shadow: var(--shadow-md);
  }
  .nav-open .overlay { display: block; }
  .nav-toggle { display: flex; }

  .site-header { padding: 1.25rem 1rem 1rem; }
  .header-title { font-size: 1.35rem; }

  .content { padding: 1.25rem 1rem 2rem; }

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

  .notes-layout { padding: 1.25rem 1rem; }
  .placeholder-card { padding: 2rem 1.25rem; }
  .placeholder-title { font-size: 1.15rem; }
  .notes-header { padding: 1.5rem 1.25rem 1rem; }
  .notes-article h1 { font-size: 1.25rem; }
  .toc { padding: 1rem 1.25rem; }
  .toc ol { columns: 1; }
  .notes-body { padding: 1.25rem 1.25rem 2rem; }
}

@media (max-width: 480px) {
  .header-notice { display: none; }
  .sidebar-stats { gap: .5rem; }
}

/* ---------- Scrollbar (desktop WebKit) ---------- */
@media (min-width: 769px) {
  .main { overflow-y: auto; }
  ::-webkit-scrollbar { width: 6px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
  ::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
}
