/* ============================================================
   Esqon Guide — Общие стили многостраничной документации
   Перенесены из guide.html + добавлены sidebar, page-nav, mobile
   ============================================================ */

/* === CSS Custom Properties === */
:root {
  --color-accent: #F59E0B;
  --color-accent-hover: #D97706;
  --color-bg-warm: #FFFBEB;
  --color-bg-white: #FFFFFF;
  --color-bg-dark: #1F2937;
  --color-text-primary: #111827;
  --color-text-secondary: #6B7280;
  --color-text-on-dark: #FFFFFF;
  --radius: 12px;
  --header-height: 64px;
  --sidebar-width: 260px;
}

/* === Reset / Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: var(--header-height);
}

body {
  font-family: 'Inter', sans-serif;
  color: var(--color-text-primary);
  background: var(--color-bg-white);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--color-accent); text-decoration: none; }
a:hover { color: var(--color-accent-hover); }

/* === Buttons === */
.btn {
  display: inline-block;
  padding: 12px 28px;
  border-radius: var(--radius);
  font-family: 'Inter', sans-serif;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
  text-align: center;
}

.btn-primary {
  background: var(--color-accent);
  color: var(--color-bg-white);
}

.btn-primary:hover {
  background: var(--color-accent-hover);
  color: var(--color-bg-white);
}

/* === Header === */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  z-index: 100;
  background: var(--color-bg-white);
  transition: background 0.3s, border-color 0.3s;
  border-bottom: 1px solid transparent;
}

.header.scrolled {
  border-bottom-color: #E5E7EB;
}

.header .container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 1.25rem;
  color: var(--color-accent);
  text-decoration: none;
}

.logo:hover { color: var(--color-accent); }

.nav {
  display: flex;
  align-items: center;
  gap: 32px;
}

.nav a {
  color: var(--color-text-primary);
  font-size: 0.9375rem;
  font-weight: 500;
  text-decoration: none;
}

.nav a:hover { color: var(--color-accent); }

.header-cta { display: none; }

.burger {
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}

.burger span {
  display: block;
  width: 24px;
  height: 2px;
  background: var(--color-text-primary);
  border-radius: 2px;
  transition: transform 0.3s, opacity 0.3s;
}

/* Header mobile nav */
@media (max-width: 767px) {
  .nav {
    display: none;
    position: absolute;
    top: var(--header-height);
    left: 0;
    right: 0;
    background: var(--color-bg-white);
    flex-direction: column;
    padding: 20px;
    gap: 16px;
    border-bottom: 1px solid #E5E7EB;
  }

  .nav.open { display: flex; }
  .header-cta { display: none; }
}

@media (min-width: 768px) {
  .burger { display: none; }
  .nav { display: flex; }
  .header-cta { display: inline-block; }
}

/* === Sidebar === */
.sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--color-bg-white);
  border-right: 1px solid #E5E7EB;
  overflow-y: auto;
  padding: 20px 0;
  z-index: 50;
  transition: transform 0.3s ease;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
}

/* === Sidebar Links === */
.sidebar-link {
  display: block;
  padding: 8px 20px;
  color: var(--color-text-primary);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.sidebar-link:hover {
  background: var(--color-bg-warm);
  color: var(--color-accent-hover);
}

.sidebar-link.active {
  background: var(--color-bg-warm);
  color: var(--color-accent);
  border-left-color: var(--color-accent);
  font-weight: 600;
}

/* === Sidebar Groups (collapsible) === */
.sidebar-group {
  display: flex;
  flex-direction: column;
}

.sidebar-group-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 8px 20px;
  background: none;
  border: none;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text-primary);
  text-align: left;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s;
}

.sidebar-group-toggle:hover {
  background: #F9FAFB;
  color: var(--color-accent-hover);
}

/* Chevron icon — rotates when group is open */
.sidebar-chevron {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  transition: transform 0.2s ease;
  transform: rotate(0deg);
}

.sidebar-group.open > .sidebar-group-toggle .sidebar-chevron {
  transform: rotate(90deg);
  transition: transform 0.2s ease;
}

.sidebar-group-toggle .sidebar-chevron {
  transition: transform 0.2s ease;
}

/* Group items — hidden by default when JS is enabled */
.sidebar-group-items {
  display: none;
  flex-direction: column;
}

.sidebar-group.open > .sidebar-group-items {
  display: flex;
}

.sidebar-group-items .sidebar-link {
  padding-left: 40px;
  font-weight: 400;
}

/* === Graceful degradation: без JS все группы развёрнуты === */
/* Отключено: вызывало мерцание при загрузке страницы.
   Группы управляются через класс open в HTML. */

html:not(.js-enabled) .sidebar-chevron {
  transform: rotate(90deg);
}

html:not(.js-enabled) .sidebar-group-toggle {
  cursor: default;
}

/* === Sidebar Toggle (mobile hamburger button) === */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: calc(var(--header-height) + 12px);
  left: 12px;
  z-index: 60;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--color-bg-white);
  border: 1px solid #E5E7EB;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  transition: background 0.15s;
}

.sidebar-toggle:hover {
  background: #F9FAFB;
}

.sidebar-toggle svg {
  width: 20px;
  height: 20px;
  color: var(--color-text-primary);
}

/* === Sidebar Overlay (mobile dark backdrop) === */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
  display: block;
  opacity: 1;
}

/* === Content Area === */
.content {
  margin-left: var(--sidebar-width);
  padding: calc(var(--header-height) + 32px) 40px 60px;
  min-height: calc(100vh - var(--header-height));
}

.content-body {
  max-width: 800px;
  line-height: 1.7;
}

/* === Content Typography (from guide.html) === */
.content-body h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.content-body h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-top: 32px;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid #E5E7EB;
}

.content-body h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 24px;
  margin-bottom: 10px;
}

.content-body p {
  margin: 10px 0;
  text-align: justify;
}

.content-body .meta {
  text-align: center;
  color: var(--color-text-secondary);
  margin-bottom: 24px;
}

.content-body ul, .content-body ol {
  padding-left: 24px;
}

.content-body li {
  margin-bottom: 6px;
}

/* === Code blocks === */
.content-body pre {
  background: #F3F4F6;
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  font-family: 'Courier New', monospace;
  font-size: 0.875rem;
  line-height: 1.5;
  margin: 12px 0;
}

.content-body code {
  background: #F3F4F6;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.875rem;
}

.content-body pre code {
  background: none;
  padding: 0;
}

/* === Tables === */
.content-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 0.9375rem;
}

.content-body th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  border-bottom: 2px solid #E5E7EB;
}

.content-body td {
  padding: 10px 12px;
  border-bottom: 1px solid #E5E7EB;
}

/* === Tip & Warning boxes === */
.tip-box {
  background: #FFFBEB;
  border-left: 4px solid #F59E0B;
  padding: 12px 16px;
  border-radius: 0 8px 8px 0;
  margin: 16px 0;
}

.warning-box {
  background: #FEF2F2;
  border-left: 4px solid #EF4444;
  padding: 12px 16px;
  border-radius: 0 8px 8px 0;
  margin: 16px 0;
}

.tip-box strong, .warning-box strong {
  display: block;
  margin-bottom: 4px;
}

/* === Page Navigation (prev/next) === */
.page-nav {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: 16px;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid #E5E7EB;
}

.page-nav-btn {
  display: inline-flex;
  align-items: center;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--color-text-primary);
  background: #F9FAFB;
  border: 1px solid #E5E7EB;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  max-width: 48%;
}

.page-nav-btn:hover {
  background: var(--color-bg-warm);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.page-nav-prev {
  margin-right: auto;
}

.page-nav-next {
  margin-left: auto;
  text-align: right;
}

/* === Footer === */
.footer {
  background: var(--color-bg-dark);
  color: var(--color-text-on-dark);
  padding: 40px 0;
  margin-left: var(--sidebar-width);
}

.footer-content {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  text-align: center;
}

.footer .logo { color: var(--color-accent); }

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
}

.footer-links a {
  color: #9CA3AF;
  font-size: 0.875rem;
}

.footer-links a:hover { color: var(--color-text-on-dark); }

.footer-copy {
  color: #9CA3AF;
  font-size: 0.8125rem;
}

.footer-ip {
  color: #6B7280;
  font-size: 0.75rem;
}

/* === Mobile Styles (< 768px) === */
@media (max-width: 767px) {
  /* Show sidebar toggle button */
  .sidebar-toggle {
    display: flex;
  }

  /* Hide sidebar off-screen by default */
  .sidebar {
    transform: translateX(-100%);
    width: 280px;
    z-index: 55;
    box-shadow: none;
  }

  /* Sidebar slides in when open */
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.15);
  }

  /* Content takes full width */
  .content {
    margin-left: 0;
    padding: calc(var(--header-height) + 24px) 16px 40px;
  }

  /* Footer takes full width */
  .footer {
    margin-left: 0;
  }

  /* Page nav stacks on small screens */
  .page-nav {
    flex-direction: column;
    gap: 12px;
  }

  .page-nav-btn {
    max-width: 100%;
  }

  .page-nav-next {
    text-align: left;
  }

  /* Content typography adjustments */
  .content-body h1 {
    font-size: 1.5rem;
  }

  .content-body h2 {
    font-size: 1.125rem;
  }

  /* Tables scroll horizontally on mobile */
  .content-body table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

/* === Desktop (>= 768px) — ensure sidebar is visible === */
@media (min-width: 768px) {
  .sidebar {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: none;
  }

  .sidebar-overlay {
    display: none !important;
  }
}


/* === Sidebar Search === */
.sidebar-search {
  padding: 12px 16px 8px;
  border-bottom: 1px solid #E5E7EB;
}

.sidebar-search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #D1D5DB;
  border-radius: 8px;
  font-size: 0.875rem;
  font-family: 'Inter', sans-serif;
  background: #F9FAFB;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.sidebar-search input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.1);
  background: #fff;
}

.sidebar-search input::placeholder {
  color: #9CA3AF;
}

.sidebar-link.search-hidden,
.sidebar-group.search-hidden {
  display: none;
}

/* === Warning Box (for scanner docs) === */
.warning-box {
  background: #FEF3C7;
  border-left: 4px solid #F59E0B;
  padding: 16px 20px;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 16px 0;
  font-size: 0.9375rem;
  line-height: 1.6;
}

.warning-box strong {
  display: block;
  margin-bottom: 4px;
  color: #92400E;
}
