/* ================================================= */
/* GitBook-style (dark) — SAFE for Material + iOS   */
/* ================================================= */

/* ============================= */
/* BASE                          */
/* ============================= */

:root {
  --gb-bg: #0b0b0f;
  --gb-fg: #e6e6eb;
  --gb-muted: #9a9aa3;
  --gb-border: rgba(255,255,255,0.08);
  --gb-accent: #a855f7;
  --gb-code-bg: #111118;
}

/* ============================= */
/* PAGE BACKGROUND               */
/* ============================= */

html,
body {
  min-height: 100%;
  background:
    radial-gradient(
      900px circle at 15% -10%,
      rgba(168, 85, 247, 0.18),
      transparent 40%
    ),
    var(--gb-bg) !important;
}

.md-main {
  background: transparent !important;
  padding-top: 0 !important;
}

.md-footer {
  display: none !important;
}

/* ============================= */
/* REMOVE VISUAL NOISE           */
/* ============================= */

.md-tabs,
.md-sidebar--secondary,
.md-hero {
  display: none !important;
}

/* ============================= */
/* HEADER — SAFE                 */
/* ============================= */

.md-header,
.md-header__inner {
  background: transparent !important;
  box-shadow: none !important;
  border: none !important;
}

.md-header--shadow {
  box-shadow: none !important;
}

.md-header__title {
  color: rgba(255,255,255,0.72);
  font-weight: 500;
}

.md-header__title:hover {
  color: rgba(255,255,255,0.9);
}

/* 🔑 КНОПКА МЕНЮ — ОБЯЗАТЕЛЬНО */
.md-header__button,
.md-header__button--menu {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* ============================= */
/* SIDEBAR (DESKTOP)             */
/* ============================= */

.md-sidebar--primary {
  width: 320px;
  background: transparent !important;
  border-right: 1px solid var(--gb-border);
}

.md-nav {
  background: transparent !important;
}

.md-nav__title {
  display: none !important;
}

.md-nav__item {
  margin: 0 !important;
  padding: 0 !important;
}

/* section */
.md-nav__item--section > .md-nav__link {
  margin-bottom: 0.4rem;
  font-size: 0.95rem;
  font-weight: 500;
  color: rgba(255,255,255,0.8) !important;
}

/* links */
.md-nav__link {
  padding: 0.28rem 0 !important;
  line-height: 1.25;
  font-size: 0.9rem;
  color: rgba(255,255,255,0.6) !important;
  transition: color 0.15s ease, transform 0.15s ease;
}

.md-nav__link:hover {
  color: rgba(255,255,255,0.85) !important;
  transform: translateX(2px);
}

.md-nav__link--active {
  color: var(--gb-accent) !important;
  font-weight: 500;
}

/* ============================= */
/* CONTENT                       */
/* ============================= */

.md-content {
  max-width: 900px;
  margin: 0 auto !important;
}

.md-typeset {
  line-height: 1.55;
  overflow-x: hidden;
}

/* headings */
.md-typeset h1 {
  font-size: 2.6rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: #f5f5f7;
  margin-bottom: 0.8rem;
}

.md-typeset h2 {
  font-size: 1.6rem;
  margin-top: 2rem;
  margin-bottom: 0.6rem;
  border-bottom: 1px solid var(--gb-border);
  padding-bottom: 0.25rem;
}

.md-typeset h3 {
  font-size: 1.25rem;
  margin-top: 1.4rem;
}

/* text */
.md-typeset p {
  color: rgba(230,230,235,0.88);
  margin: 0.6rem 0;
}

.md-typeset strong {
  color: #fff;
  font-weight: 600;
}

/* ============================= */
/* CODE / BLOCKS                 */
/* ============================= */

.md-typeset code {
  background: var(--gb-code-bg);
  border-radius: 6px;
  padding: 0.12em 0.35em;
  font-size: 0.9em;
}

.md-typeset pre {
  margin: 1.2rem 0;
  padding: 0.9rem 1.1rem;
  border-radius: 14px;
  background: rgba(20,20,30,0.85);
}

/* quote */
.md-typeset blockquote {
  margin: 0.8rem 0;
  padding: 0.75rem 1rem;
  background: rgba(255,255,255,0.03);
  border-left: 3px solid var(--gb-accent);
}

/* ============================= */
/* SEARCH                        */
/* ============================= */

.md-search__form {
  background: rgba(255,255,255,0.04) !important;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 999px;
}

.md-search__input {
  color: #e6e6eb !important;
}

/* ============================= */
/* REMOVE RIPPLE / FOCUS         */
/* ============================= */

.md-nav__link::before,
.md-nav__link::after {
  display: none !important;
}

.md-nav__link:focus,
.md-nav__link:focus-visible {
  outline: none !important;
  box-shadow: none !important;
}

/* ============================= */
/* MOBILE — SAFE (≤900px)        */
/* ============================= */

@media (max-width: 900px) {

  /* content */
  .md-content {
    max-width: 100% !important;
    padding: 0 1rem;
  }

  /* typography */
  .md-typeset {
    font-size: 0.95rem;
    line-height: 1.5;
  }

  .md-typeset h1 {
    font-size: 2rem;
  }

  .md-typeset h2 {
    font-size: 1.35rem;
  }

  .md-typeset h3 {
    font-size: 1.1rem;
  }

  /* sidebar — НЕ трогаем positioning */
  .md-sidebar--primary {
    background: var(--gb-bg) !important;
    border-right: 1px solid var(--gb-border);
  }

  /* overlay */
  .md-overlay {
    background: rgba(0,0,0,0.45) !important;
  }
}

/* ================================================= */
/* iOS SAFARI — FINAL FIX FOR MATERIAL DRAWER       */
/* ================================================= */

@media (max-width: 900px) {

  /* 🔥 КРИТИЧЕСКИ: ничего не должно обрезать drawer */
  html,
  body,
  .md-container,
  .md-main,
  .md-main__inner {
    overflow: visible !important;
  }

  /* sidebar — используем родной, но принудительно */
  .md-sidebar--primary {
    position: fixed !important;
    top: 0;
    left: 0;

    width: 85vw !important;
    max-width: 320px;
    height: 100vh;

    background: var(--gb-bg) !important;
    border-right: 1px solid var(--gb-border);

    z-index: 4000;

    /* ВАЖНО: Material сам управляет translate */
    transform: translateX(-100%);
  }

  /* когда меню открыто */
  [data-md-toggle="drawer"]:checked
  ~ .md-container
  .md-sidebar--primary {
    transform: translateX(0);
  }

  /* overlay */
  .md-overlay {
    background: rgba(0,0,0,0.45) !important;
    z-index: 3000;
  }
}

/* ========================================= */
/* NUCLEAR FIX — DISABLE MATERIAL DRAWER     */
/* ========================================= */

@media (max-width: 900px) {

  /* ❌ отключаем Material drawer */
  input#__drawer {
    display: none !important;
  }

  .md-overlay {
    display: none !important;
  }

  /* sidebar — ВСЕГДА нормальный */
  .md-sidebar--primary {
    position: fixed !important;
    inset: 0 !important;

    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;

    background: var(--gb-bg) !important;
    border-right: none !important;

    z-index: 5000 !important;

    transform: translateX(-100%) !important;
    transition: transform 0.25s ease !important;
  }

  /* открытие через кнопку меню */
  .md-header__button[for="__drawer"]:active
  ~ .md-container
  .md-sidebar--primary {
    transform: translateX(0) !important;
  }

  /* контент всегда виден */
  .md-content {
    margin-left: 0 !important;
    max-width: 100% !important;
    padding: 0 1rem;
  }
}

/* ========================================= */
/* MOBILE SIDEBAR — FINAL WORKING FIX        */
/* ========================================= */

@media (max-width: 900px) {

  /* ничего не обрезаем */
  html, body {
    overflow-x: hidden !important;
  }

  .md-container {
    overflow: visible !important;
  }

  /* sidebar = drawer */
  .md-sidebar--primary {
    position: fixed !important;
    top: 0;
    left: 0;

    width: 85vw !important;
    max-width: 320px;
    height: 100vh;

    background: var(--gb-bg) !important;
    border-right: 1px solid var(--gb-border);

    z-index: 3000;

    /* ❗ по умолчанию скрыт */
    transform: translateX(-100%) !important;
    transition: transform 0.25s ease !important;
  }

  /* ✅ ОТКРЫТИЕ */
  input#__drawer:checked
  ~ .md-container
  .md-sidebar--primary {
    transform: translateX(0) !important;
  }

  /* overlay затемнение */
  .md-overlay {
    background: rgba(0,0,0,0.5) !important;
    z-index: 2500;
  }

  /* контент всегда нормальный */
  .md-content {
    margin-left: 0 !important;
    max-width: 100% !important;
    padding: 0 1rem;
  }
}
