/* ── Light theme (default) ── */
:root {
  color-scheme: light;
  --bg: #f0f4f8;
  --surface: #ffffff;
  --text: #1a1a2e;
  --text-muted: #5c6370;
  --accent: #0078d4;
  --accent-light: #e8f4fd;
  --accent-dark: #005a9e;
  --success: #107c10;
  --success-bg: #e8f5e9;
  --success-border: #a5d6a7;
  --warning-bg: #fff8e1;
  --warning-border: #ffd54f;
  --danger: #d13438;
  --danger-bg: #fdecea;
  --border: #dde3ea;
  --table-stripe: #f8fafc;
  --code-bg: #eef2f7;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
  --header-text: #ffffff;
  --toggle-bg: rgba(255, 255, 255, 0.15);
  --toggle-border: rgba(255, 255, 255, 0.35);
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: Consolas, "Courier New", monospace;
  --sidebar-width: 260px;
  --content-max: 780px;
  --top-bar-height: 3.25rem;
  --sticky-offset: 1rem;
  --header-sticky-height: 3.25rem;
}

/* ── Dark theme ── */
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1419;
  --surface: #1a2332;
  --text: #e8ecf1;
  --text-muted: #9aa5b4;
  --accent: #4da3ff;
  --accent-light: #1e3a5f;
  --accent-dark: #7bb8ff;
  --success: #6fcf97;
  --success-bg: #1a2e22;
  --success-border: #2d5a3d;
  --warning-bg: #2a2518;
  --warning-border: #6b5a20;
  --danger: #ff6b6b;
  --danger-bg: #2e1a1a;
  --border: #2d3a4d;
  --table-stripe: #151e2b;
  --code-bg: #0d1117;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  --header-text: #ffffff;
  --toggle-bg: rgba(255, 255, 255, 0.1);
  --toggle-border: rgba(255, 255, 255, 0.25);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--sticky-offset) + 0.5rem);
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  transition: background 0.2s ease, color 0.2s ease;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

/* ── Header ── */
.header-hero,
.header-bar {
  background: linear-gradient(135deg, #0078d4 0%, #005a9e 100%);
  color: var(--header-text);
}
[data-theme="dark"] .header-hero,
[data-theme="dark"] .header-bar {
  background: linear-gradient(135deg, #1a3a5c 0%, #0d2137 100%);
}

.header-hero {
  padding: 1.75rem 1.25rem;
}

.header-bar {
  display: none;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}
.header-text { flex: 1; min-width: 0; }

.header-hero h1 {
  margin: 0 0 0.4rem;
  font-size: clamp(1.35rem, 4vw, 2rem);
  font-weight: 700;
  line-height: 1.25;
}
.header-hero .subtitle {
  margin: 0;
  font-size: clamp(0.82rem, 2.5vw, 0.95rem);
  opacity: 0.9;
  line-height: 1.4;
}

.header-bar-title {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Animated theme switch ── */
.theme-switch {
  flex-shrink: 0;
  margin: 0;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.theme-switch--bar { margin-left: auto; }
.theme-switch:focus-visible .theme-switch-track {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.theme-switch-track {
  position: relative;
  display: block;
  width: 4.5rem;
  height: 2.25rem;
  border-radius: 999px;
  background: linear-gradient(160deg, #5eb8ff 0%, #3d8fd9 100%);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.12), 0 1px 3px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  transition: background 0.55s cubic-bezier(0.4, 0, 0.2, 1);
}
[data-theme="dark"] .theme-switch-track {
  background: linear-gradient(160deg, #1e2d4a 0%, #0a1020 100%);
}

.theme-switch-sky {
  position: absolute;
  inset: 0;
  pointer-events: none;
  transition: opacity 0.45s ease;
}
.theme-switch-sky--day { opacity: 1; }
.theme-switch-sky--night { opacity: 0; }
[data-theme="dark"] .theme-switch-sky--day { opacity: 0; }
[data-theme="dark"] .theme-switch-sky--night { opacity: 1; }

.theme-switch-cloud {
  position: absolute;
  right: 0.35rem;
  top: 0.55rem;
  animation: cloud-drift 6s ease-in-out infinite;
}
@keyframes cloud-drift {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(-3px); }
}

.theme-switch-stars { display: block; }
.theme-star {
  fill: #fff;
  opacity: 0.45;
  animation: star-twinkle 2.4s ease-in-out infinite;
}
.theme-star--2 { animation-delay: 0.5s; }
.theme-star--3 { animation-delay: 1s; }
.theme-star--4 { animation-delay: 1.6s; }
@keyframes star-twinkle {
  0%, 100% { opacity: 0.35; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.25); }
}

.theme-switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc(2.25rem - 6px);
  height: calc(2.25rem - 6px);
  border-radius: 50%;
  background: linear-gradient(145deg, #ffe066 0%, #ffb020 100%);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.55s cubic-bezier(0.34, 1.35, 0.64, 1), background 0.45s ease;
}
[data-theme="dark"] .theme-switch-thumb {
  transform: translateX(calc(4.5rem - 2.25rem));
  background: linear-gradient(145deg, #f0f2f8 0%, #c8cdd8 100%);
}

.theme-switch-face {
  position: absolute;
  transition: opacity 0.35s ease, transform 0.55s cubic-bezier(0.34, 1.35, 0.64, 1);
}
.theme-switch-face--sun {
  opacity: 1;
  transform: rotate(0deg);
  animation: sun-spin 12s linear infinite;
}
.theme-switch-face--moon {
  opacity: 0;
  transform: scale(0.5) rotate(-30deg);
}
[data-theme="dark"] .theme-switch-face--sun {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
  animation: none;
}
[data-theme="dark"] .theme-switch-face--moon {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}
@keyframes sun-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .theme-switch-track,
  .theme-switch-thumb,
  .theme-switch-face,
  .theme-switch-sky { transition: none; }
  .theme-switch-face--sun,
  .theme-switch-cloud,
  .theme-star { animation: none; }
}

/* ── Layout ── */
.page-layout {
  display: flex;
  max-width: 1200px;
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2rem) clamp(0.75rem, 2vw, 1.25rem);
  gap: clamp(1.25rem, 3vw, 2.5rem);
  align-items: flex-start;
}

/* ── Sidebar / TOC ── */
.sidebar {
  position: sticky;
  top: var(--sticky-offset);
  flex: 0 0 var(--sidebar-width);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  box-shadow: var(--shadow);
  max-height: calc(100vh - var(--sticky-offset) - 1rem);
  overflow: hidden;
  transition: background 0.2s, border-color 0.2s;
}


.nav-drawer-head {
  display: none;
}

.toc-body {
  padding: 1.25rem;
  overflow-y: auto;
  max-height: calc(100vh - var(--sticky-offset) - 1rem);
}

/* ── Sticky top bar (mobile nav only) ── */
.top-bar {
  display: none;
  z-index: 120;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.top-bar-placeholder {
  display: none;
  height: 0;
  pointer-events: none;
}

.top-bar-inner {
  max-width: 1200px;
  margin: 0 auto;
  height: var(--top-bar-height);
  padding: 0  clamp(0.75rem, 2vw, 1.25rem);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.top-bar-current {
  display: none;
  flex: 1;
  min-width: 0;
  height: 1.25rem;
  line-height: 1.25rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: right;
}

.nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
}
[data-theme="dark"] .nav-overlay {
  background: rgba(0, 0, 0, 0.6);
}
body.nav-open .nav-overlay {
  display: block;
}

.burger-btn {
  display: none;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.burger-btn:hover { background: var(--accent-light); border-color: var(--accent); }

.burger-lines {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 18px;
  height: 14px;
}
.burger-lines span {
  display: block;
  height: 2px;
  width: 100%;
  background: currentColor;
  border-radius: 1px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.burger-btn[aria-expanded="true"] .burger-lines span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.burger-btn[aria-expanded="true"] .burger-lines span:nth-child(2) {
  opacity: 0;
}
.burger-btn[aria-expanded="true"] .burger-lines span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.sidebar-title {
  margin: 0 0 0.75rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.toc { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0; }
.toc a {
  display: block;
  padding: 0.35rem 0;
  font-size: 0.875rem;
  color: var(--text);
  text-decoration: none;
  border-left: 2px solid transparent;
  padding-left: 0.75rem;
  margin-left: -0.75rem;
  transition: color 0.15s;
}
.toc a:hover { color: var(--accent); }
.toc a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

.toc-appendix {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

/* ── Article ── */
.article {
  flex: 1;
  min-width: 0;
  max-width: var(--content-max);
}

.intro {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(1rem, 3vw, 1.5rem);
  margin-bottom: clamp(1rem, 3vw, 2rem);
  box-shadow: var(--shadow);
  transition: background 0.2s, border-color 0.2s;
}

section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(1.15rem, 3vw, 1.75rem);
  margin-bottom: clamp(1rem, 2.5vw, 1.5rem);
  box-shadow: var(--shadow);
  transition: background 0.2s, border-color 0.2s;
}
section.appendix { border-top: 3px solid var(--accent); }

h2 {
  margin: 0 0 1rem;
  font-size: clamp(1.15rem, 3vw, 1.35rem);
  color: var(--accent);
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--accent);
  line-height: 1.3;
}
h3 {
  margin: 1.25rem 0 0.5rem;
  font-size: clamp(0.95rem, 2.5vw, 1.05rem);
}
h3:first-child { margin-top: 0; }

p { margin: 0 0 1rem; }
p:last-child { margin-bottom: 0; }

.note {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-style: italic;
}

/* ── Cards & callouts ── */
.card {
  background: var(--accent-light);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  transition: background 0.2s;
}
.card:last-child { margin-bottom: 0; }
.card-title {
  margin: 0 0 0.35rem;
  font-weight: 700;
  color: var(--accent);
}

.callout {
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin: 1rem 0;
  transition: background 0.2s;
}
.callout-title { margin: 0 0 0.35rem; font-weight: 700; }
.callout-success {
  background: var(--success-bg);
  border-color: var(--success-border);
}

/* ── Lists ── */
ul.bullets {
  margin: 0 0 1rem;
  padding-left: 1.25rem;
}
ul.bullets li { margin-bottom: 0.35rem; }
ol.steps {
  margin: 0;
  padding-left: 1.25rem;
}
ol.steps li { margin-bottom: 0.5rem; }

/* ── Tables ── */
.table-wrap {
  overflow-x: auto;
  margin: 1rem 0;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.table-scroll-hint {
  display: none;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  padding: 0.35rem;
  border-top: 1px solid var(--border);
  background: var(--table-stripe);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: clamp(0.82rem, 2vw, 0.9rem);
}
th, td {
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
th {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  white-space: nowrap;
}
tr:nth-child(even) td { background: var(--table-stripe); }
.table-success th { background: var(--success); }
.table-danger th { background: var(--danger); }

td .hint {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* HTTP method cell — action + tag on separate lines */
.action-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.4rem;
}
.action-cell strong {
  display: block;
  line-height: 1.3;
}
.method-tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: 0.03em;
  color: var(--accent);
  background: var(--code-bg);
  padding: 0.2em 0.55em;
  border-radius: 4px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

/* ── Code ── */
code, .code-block {
  font-family: var(--font-mono);
}
code {
  font-size: 0.85em;
  background: var(--code-bg);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  border: 1px solid var(--border);
  word-break: break-word;
}
.code-block {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(0.85rem, 2vw, 1.25rem);
  overflow-x: auto;
  line-height: 1.75;
  margin: 1rem 0;
  font-size: clamp(0.75rem, 2vw, 0.82rem);
  white-space: pre-wrap;
  word-break: break-word;
}
.code-block strong { color: var(--accent); }

/* ── Footer ── */
.site-footer {
  text-align: center;
  padding: 1.5rem 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
}

/* ── Desktop ── */
@media (min-width: 901px) {
  html {
    scroll-padding-top: calc(var(--header-sticky-height) + 0.5rem);
  }

  html:not(.header-bar-visible) {
    scroll-padding-top: 1.5rem;
  }

  .header-hero h1 {
    font-size: 2rem;
  }

  .header-bar {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 110;
    height: var(--header-sticky-height);
    padding: 0 1.25rem;
    box-shadow: none;
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s ease, opacity 0.3s ease, box-shadow 0.3s ease;
  }

  .header-bar .header-inner {
    height: 100%;
    align-items: center;
  }

  .header-bar.is-visible {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
    box-shadow: 0 2px 14px rgba(0, 0, 0, 0.18);
  }
  [data-theme="dark"] .header-bar.is-visible {
    box-shadow: 0 2px 14px rgba(0, 0, 0, 0.45);
  }

  html.header-bar-visible {
    --sticky-offset: calc(var(--header-sticky-height) + 0.5rem);
  }

  html.header-bar-visible .sidebar {
    top: var(--sticky-offset);
    max-height: calc(100vh - var(--sticky-offset) - 1rem);
  }

  html.header-bar-visible .toc-body {
    max-height: calc(100vh - var(--sticky-offset) - 1rem);
  }

  .theme-switch--header { align-self: center; }
  .theme-switch--header-bar { transform: scale(0.88); transform-origin: center right; }
  .theme-switch--bar { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .header-bar { transition: none !important; }
  .header-hero h1,
  .header-inner,
  .sidebar,
  .toc-body,
  .theme-switch--header {
    transition: none !important;
  }
}

/* ── Tablet (768–1024) ── */
@media (max-width: 1024px) {
  :root { --sidebar-width: 220px; }
  .page-layout { gap: 1.5rem; }
}

/* ── Mobile / narrow tablet ── */
@media (max-width: 900px) {
  html { scroll-padding-top: calc(var(--top-bar-height) + 0.5rem); }

  .theme-switch--header { display: none; }
  .top-bar,
  .top-bar-placeholder { display: block; }

  .top-bar.is-pinned {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    transform: translateZ(0);
    backface-visibility: hidden;
  }

  .burger-btn { display: inline-flex; }
  .top-bar-current { display: block; }

  .page-layout {
    flex-direction: column;
    padding-top: 0.5rem;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    flex: none;
    width: min(300px, 88vw);
    max-height: 100vh;
    z-index: 200;
    border-radius: 0;
    border-left: none;
    border-top: none;
    border-bottom: none;
    transform: translateX(-105%);
    transition: transform 0.28s ease;
    overflow: hidden;
  }
  body.nav-open .sidebar {
    transform: translateX(0);
  }

  .nav-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--accent-light);
  }
  .nav-drawer-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--accent);
  }
  .nav-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
  }
  .nav-close:hover {
    background: var(--border);
    color: var(--text);
  }

  .toc-body {
    max-height: calc(100vh - 3.5rem);
  }

  .article { max-width: none; }

  /* Horizontal scroll for wide tables */
  .table-wrap table { min-width: 540px; }
  .table-scroll-hint { display: block; }
}

/* ── Phone ── */
@media (max-width: 600px) {
  section, .intro { padding: 1rem; }

  th, td { padding: 0.5rem 0.65rem; }

  /* Card-style tables on small screens */
  .table-wrap.table-cards {
    overflow-x: visible;
    border: none;
    background: transparent;
  }
  .table-wrap.table-cards .table-scroll-hint { display: none; }

  .table-wrap.table-cards table {
    min-width: 0;
    border: none;
  }
  .table-wrap.table-cards thead { display: none; }
  .table-wrap.table-cards tbody tr {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
    padding: 0.25rem 0;
    box-shadow: var(--shadow);
  }
  .table-wrap.table-cards tbody tr:nth-child(even) td { background: transparent; }
  .table-wrap.table-cards td {
    display: block;
    border: none;
    border-bottom: 1px solid var(--border);
    padding: 0.55rem 0.85rem;
  }
  .table-wrap.table-cards td:last-child { border-bottom: none; }
  .table-wrap.table-cards td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
  }
  .table-wrap.table-cards td.action-cell::before { content: "Действие"; }
  .table-wrap.table-cards td:first-child:not([data-label])::before { content: "Поле"; }
}

@media (max-width: 380px) {
  body { font-size: 15px; }
  .header-hero { padding: 1.25rem 1rem; }
}
