/* Base theme variables */
:root {
  --bg: #ffffff;
  --text: #111318;
  --muted: #667085;
  --card: #f6f7f9;
  --brand: #1463ff;
  --brand-2: #0b57d0;
  --border: #e6e8eb;
  --success: #1a936f;
  --badge: #eef2ff;

  --radius-s: 10px;
  --radius-m: 14px;
  --radius-l: 16px;

  --shadow-1: 0 1px 2px rgba(0,0,0,.04);
  --hdr-h: 60px; /* вычисляем в JS тоже */
  --gap-s: 12px; --gap-m: 14px; --gap-l: 18px;

  /* Мобильная высота окна: задаётся в JS, fallback — 1dvh */
  --vh: 1dvh;
}

[data-theme="dark"] {
  --bg: #0f1115;
  --text: #f1f5f9;
  --muted: #9aa4b2;
  --card: #171a21;
  --brand: #6ea8ff;
  --brand-2: #8bb7ff;
  --border: #262a33;
  --success: #3bd39b;
  --badge: #1d263a;
}

/* Global */
html { color-scheme: light dark; }
html, body { margin: 0; padding: 0; }
html, body { overflow-x: hidden; }
body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.6;
  text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; box-sizing: border-box; }

/* Header — фиксирован сверху всегда */
header.hdr {
  position: fixed; top: 0; left: 0; right: 0; z-index: 2000;
  background: var(--bg); border-bottom: 1px solid var(--border);
  padding-top: constant(safe-area-inset-top); /* старые iOS */
  padding-top: env(safe-area-inset-top);
  backdrop-filter: saturate(1.2) blur(4px);
}
body.with-fixed-header {
  padding-top: calc(var(--hdr-h) + env(safe-area-inset-top));
}
.nav { display: flex; align-items: center; gap: 12px; height: var(--hdr-h); }
.logo { font-weight: 800; letter-spacing: .2px; white-space: nowrap; }

.theme-switch { display: flex; gap: 6px; align-items: center; }
.theme-switch button {
  padding: 8px 12px; min-height: 44px;
  border-radius: var(--radius-s); border: 1px solid var(--border);
  background: var(--card); color: var(--text); cursor: pointer;
}

.nav-spacer { flex: 1; }

/* Hamburger */
.nav-toggle {
  display: none; align-items: center; gap: 8px;
  padding: 8px 12px; min-height: 44px;
  border: 1px solid var(--border); background: var(--card);
  border-radius: var(--radius-s); cursor: pointer; white-space: nowrap;
}
.nav-toggle .burger {
  width: 18px; height: 2px; background: var(--text); position: relative; display: inline-block;
}
.nav-toggle .burger::before, .nav-toggle .burger::after {
  content: ""; position: absolute; left: 0; width: 18px; height: 2px; background: var(--text);
}
.nav-toggle .burger::before { top: -6px; }
.nav-toggle .burger::after { top: 6px; }

/* Menu */
.menu { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 12px; min-height: 44px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  border-radius: var(--radius-s); box-shadow: var(--shadow-1);
}
.btn:hover { text-decoration: none; filter: brightness(1.02); }
.btn.primary { background: var(--brand); color: #fff; border-color: transparent; }
.btn.active { outline: 2px solid var(--brand); outline-offset: 1px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 8px; border-radius: 999px;
  background: var(--badge); border: 1px solid var(--border); font-size: 12px;
}

/* Dropdown (Направления) — по клику/hover, класс .open */
.dropdown { position: relative; }
.dropdown > button {
  padding: 10px 12px; min-height: 44px;
  border: 1px solid var(--border); background: var(--card);
  color: var(--text); border-radius: var(--radius-s); cursor: pointer;
}
.dropdown ul {
  display: none; position: absolute; top: calc(100% + 8px); left: 0;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-m);
  min-width: 280px; padding: 8px; list-style: none; margin: 0; max-height: 60vh; overflow: auto;
  box-shadow: 0 10px 24px rgba(0,0,0,.12);
  will-change: transform; transform: translateZ(0);
}
.dropdown.open ul { display: block; }
.dropdown ul li a { display: block; padding: 8px 10px; border-radius: 8px; }
.dropdown ul li a:hover { background: var(--card); text-decoration: none; }

/* Page hero + breadcrumbs */
.page-hero { padding: 22px 0 8px; }
.page-hero h1 { margin: 0 0 8px; font-size: clamp(24px, 3.4vw, 36px); line-height: 1.2; }
.muted { color: var(--muted); }
.breadcrumbs { padding: 10px 0 0; font-size: 14px; color: var(--muted); }
.breadcrumbs a { color: var(--muted); }

/* Layout helpers */
.grid { display: grid; gap: var(--gap-m); }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--gap-m); }
.tags { display: flex; flex-wrap: wrap; gap: 8px; }
.tag {
  display: inline-flex; align-items: center;
  padding: 6px 10px; border: 1px solid var(--border);
  border-radius: 999px; background: var(--card); color: var(--text);
}

/* Cards */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-m); padding: 14px; box-shadow: var(--shadow-1);
}
.card h2 { margin: 0 0 8px; font-size: 20px; }
.card p { margin: 6px 0 10px; }

/* Lists */
ul.list { padding-left: 18px; }
ul.list li { margin: 6px 0; }

/* CTA row */
.cta { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }

/* Footer */
footer.ftr { border-top: 1px solid var(--border); margin-top: 24px; padding: 18px 0; }

/* Единые вертикальные отступы между основными секциями */
main.wrap > nav.breadcrumbs { margin-top: 8px; margin-bottom: 12px; }
main.wrap > header.page-hero { margin-bottom: 16px; }
main.wrap > section { margin-bottom: 16px; }
@media (min-width: 741px) {
  main.wrap > header.page-hero { margin-bottom: 20px; }
  main.wrap > section { margin-bottom: 20px; }
}

/* Mobile */
@media (max-width: 900px) {
  .menu { display: none; }
  .nav-toggle { display: inline-flex; }
  .theme-switch { order: 2; }
  .logo { order: 1; }
  .nav-toggle { order: 3; }

  /* Панель меню — фиксирована под шапкой, с собственной прокруткой */
  .menu.panel {
    display: none;
    position: fixed; top: calc(var(--hdr-h) + env(safe-area-inset-top)); left: 0; right: 0;
    background: var(--bg); border-top: 1px solid var(--border);
    box-shadow: 0 10px 24px rgba(0,0,0,.12);
    padding: 10px 12px;
    max-height: calc((var(--vh) * 100) - var(--hdr-h) - env(safe-area-inset-top));
    overflow: auto; -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    z-index: 1999;
  }
  .menu.panel.open { display: block; }

  .menu.panel .btn,
  .menu.panel .dropdown > button { width: 100%; justify-content: flex-start; margin-bottom: 8px; }

  .dropdown { width: 100%; }
  .dropdown ul {
    position: static; display: none; border-radius: var(--radius-s);
    border: 1px solid var(--border); margin-top: 6px; max-height: none; box-shadow: none;
  }
  .dropdown.open ul { display: block; }

  /* Блокировка скролла страницы при открытом меню */
  body.nav-open { overflow: hidden; height: 100vh; touch-action: none; }
}

/* Предохранитель от «выпираний» */
* { box-sizing: border-box; }