/* layout.css — topbar, sidebar, content area, TOC, prev/next */

/* ── TOPBAR ── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-height);
  background: rgba(250, 250, 247, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
}

.topbar-inner {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  justify-content: space-between;
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  text-decoration: none;
  flex-shrink: 0;
}
.topbar-logo:hover { text-decoration: none; }

.topbar-logo-icon {
  width: 34px;
  height: 34px;
  background: linear-gradient(135deg, #E8511A 0%, #D0430D 100%);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 18px;
  flex-shrink: 0;
}

.topbar-logo-img {
  width: 80px;
  height: 80px;
  object-fit: contain;
  flex-shrink: 0;
}

.topbar-logo-title {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--color-text);
  display: block;
  line-height: 1.2;
}

.topbar-logo-subtitle {
  font-size: 0.7rem;
  color: var(--color-text-muted);
  display: block;
  line-height: 1;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.topbar-nav a {
  color: var(--color-text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.375rem 0.625rem;
  border-radius: var(--radius);
  text-decoration: none;
  transition: color 0.15s, background 0.15s;
}
.topbar-nav a:hover {
  color: var(--color-text);
  background: var(--color-bg-hover);
}

.topbar-nav-cv {
  margin-left: 0.375rem;
  padding: 0.375rem 0.75rem !important;
  background: rgba(232, 81, 26, 0.1) !important;
  border: 1px solid rgba(232, 81, 26, 0.28);
  border-radius: var(--radius);
  color: #C94A10 !important;
  font-weight: 600 !important;
}
.topbar-nav-cv:hover {
  background: rgba(232, 81, 26, 0.18) !important;
  border-color: rgba(232, 81, 26, 0.45);
  color: #A83A08 !important;
}

.topbar-cta {
  background: var(--color-brand);
  color: #fff !important;
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 0.4375rem 0.875rem;
  border-radius: var(--radius);
  text-decoration: none !important;
  white-space: nowrap;
  transition: background 0.15s;
  flex-shrink: 0;
}
.topbar-cta:hover { background: var(--color-brand-hover); }

.topbar-hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.375rem;
  color: var(--color-text);
  border-radius: var(--radius);
}
.topbar-hamburger:hover { background: var(--color-bg-hover); }

.topbar-mobile-nav {
  display: none;
}

/* ── PAGE WRAPPER ── */

.page-wrapper {
  display: flex;
  min-height: calc(100vh - var(--topbar-height));
}

.page-wrapper.layout-landing {
  display: block;
}

/* ── SIDEBAR ── */

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  position: sticky;
  top: var(--topbar-height);
  height: calc(100vh - var(--topbar-height));
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--color-bg-secondary);
  border-right: 1px solid var(--color-border);
  padding: 0.75rem 0 2rem;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

.sidebar-home {
  padding: 0 0.75rem 0.5rem;
  border-bottom: 1px solid var(--color-border-subtle);
  margin-bottom: 0.5rem;
}

.sidebar-home-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.625rem;
  border-radius: var(--radius);
  color: var(--color-text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.sidebar-home-link:hover,
.sidebar-home-link.active {
  background: var(--color-bg-hover);
  color: var(--color-text);
  text-decoration: none;
}

.sidebar-group {
  margin: 0 0.75rem 0.125rem;
}

.sidebar-group-header {
  display: flex;
  align-items: center;
  border-radius: var(--radius);
}

.sidebar-group-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4375rem 0.5rem 0.4375rem 0.625rem;
  flex: 1;
  min-width: 0;
  border-radius: var(--radius) 0 0 var(--radius);
  color: var(--color-text);
  text-decoration: none;
  transition: background 0.15s;
}
.sidebar-group-link:hover { background: var(--color-bg-hover); text-decoration: none; }
.sidebar-group-link.active { background: var(--color-brand-light); }

.sidebar-group-toggle {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  border-radius: 0 var(--radius) var(--radius) 0;
  transition: background 0.15s;
}
.sidebar-group-toggle:hover { background: var(--color-bg-hover); color: var(--color-text); }
.sidebar-group-toggle svg { transition: transform 0.2s; }
.sidebar-group.open .sidebar-group-toggle svg { transform: rotate(180deg); }

.sidebar-group-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sidebar-group-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.3;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-group-items {
  display: none;
  padding: 0.25rem 0 0.25rem 1.25rem;
}
.sidebar-group.open .sidebar-group-items { display: block; }

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3125rem 0.625rem;
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
  border-radius: var(--radius);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
  border-left: 2px solid transparent;
  line-height: 1.4;
}
.sidebar-item:hover {
  background: var(--color-bg-hover);
  color: var(--color-text);
  text-decoration: none;
}
.sidebar-item.active {
  color: var(--color-brand);
  background: var(--color-brand-light);
  border-left-color: var(--color-brand);
  font-weight: 500;
}

.sidebar-item--draft {
  color: var(--color-text-muted);
}
.sidebar-item--draft:hover {
  color: var(--color-text-secondary);
}

.sidebar-draft-icon {
  flex-shrink: 0;
  opacity: 0.45;
  color: var(--color-text-muted);
}

/* ── MAIN CONTENT ── */

.main-content {
  flex: 1;
  min-width: 0;
  padding: 2rem 2.5rem;
}

.layout-landing .main-content {
  padding: 0;
}

/* ── TOC (RIGHT SIDEBAR) ── */

.toc-sidebar {
  width: var(--toc-width);
  flex-shrink: 0;
  position: sticky;
  top: var(--topbar-height);
  height: calc(100vh - var(--topbar-height));
  overflow-y: auto;
  padding: 1.5rem 1.25rem 2rem 0.75rem;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

.toc-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin-bottom: 0.75rem;
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc-item {
  margin-bottom: 0.125rem;
}
.toc-item.depth-3 { padding-left: 0.875rem; }

.toc-link {
  display: block;
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
  padding: 0.2rem 0;
  text-decoration: none;
  line-height: 1.4;
  border-left: 2px solid transparent;
  padding-left: 0.5rem;
  transition: color 0.15s, border-color 0.15s;
}
.toc-link:hover {
  color: var(--color-text);
  text-decoration: none;
}
.toc-link.active {
  color: var(--color-brand);
  border-left-color: var(--color-brand);
  font-weight: 500;
}

/* ── BREADCRUMB ── */

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.breadcrumb a {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  text-decoration: none;
}
.breadcrumb a:hover { color: var(--color-brand); }

.breadcrumb-sep {
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

.breadcrumb [aria-current="page"] {
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
  font-weight: 500;
}

/* ── LESSON TAGS ── */

.tag {
  display: inline-flex;
  align-items: center;
  padding: 0.2em 0.65em;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 4px;
  border: 1px solid transparent;
  background: var(--color-bg-secondary);
  color: var(--color-text-secondary);
  border-color: var(--color-border);
}

/* Семантические цвета по ключевым тегам */
.tag[data-tag="core"]         { background: var(--color-brand-soft);  color: var(--color-brand);   border-color: rgba(232,81,26,0.25); }
.tag[data-tag="optimization"] { background: #FFFBEB;                  color: #D97706;               border-color: rgba(217,119,6,0.25); }
.tag[data-tag="streaming"]    { background: var(--color-blue-soft);   color: var(--color-blue);     border-color: rgba(43,108,176,0.25); }
.tag[data-tag="platform"]     { background: #F5F3FF;                  color: #7C3AED;               border-color: rgba(124,58,237,0.25); }

@media (prefers-color-scheme: dark) {
  .tag                           { background: var(--color-bg-secondary); color: var(--color-text-muted); border-color: var(--color-border); }
  .tag[data-tag="core"]          { background: rgba(232,81,26,0.15);  color: #F97316; border-color: rgba(232,81,26,0.3); }
  .tag[data-tag="optimization"]  { background: rgba(217,119,6,0.15);  color: #FBB824; border-color: rgba(217,119,6,0.3); }
  .tag[data-tag="streaming"]     { background: rgba(43,108,176,0.15); color: #60A5FA; border-color: rgba(43,108,176,0.3); }
  .tag[data-tag="platform"]      { background: rgba(124,58,237,0.15); color: #A78BFA; border-color: rgba(124,58,237,0.3); }
}

/* ── PREV/NEXT NAV ── */

.lesson-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
}

.lesson-nav-card {
  display: block;
  padding: 0.875rem 1rem;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}
.lesson-nav-card:hover {
  border-color: var(--color-brand);
  background: var(--color-brand-light);
  text-decoration: none;
}

.lesson-nav-card.prev { text-align: left; }
.lesson-nav-card.next { text-align: right; }

.lesson-nav-dir {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  display: block;
  margin-bottom: 0.25rem;
}

.lesson-nav-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
  display: block;
  line-height: 1.35;
}

/* ── FOOTER ── */

.site-footer {
  background: var(--color-bg-secondary);
  border-top: 1px solid var(--color-border);
  padding: 2rem 0;
}

.footer-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 2rem;
  flex-wrap: wrap;
}

.footer-brand {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.footer-brand > span:first-child {
  font-weight: 700;
  font-size: 0.9375rem;
}
.footer-note {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  max-width: 400px;
  line-height: 1.5;
}

.footer-links {
  display: flex;
  gap: 1.25rem;
}
.footer-links a {
  font-size: 0.875rem;
  color: var(--color-text-secondary);
  text-decoration: none;
}
.footer-links a:hover { color: var(--color-brand); }

/* ── MOBILE SIDEBAR OVERLAY ── */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.sidebar-overlay.visible { opacity: 1; pointer-events: auto; }

/* ── RESPONSIVE ── */

@media (max-width: 1280px) {
  .toc-sidebar { display: none; }
  .main-content { padding: 1.75rem 2rem; }
}

@media (max-width: 1024px) {
  :root { --sidebar-width: 248px; }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 95;
    transform: translateX(-100%);
    transition: transform 0.28s ease;
    padding-top: calc(var(--topbar-height) + 0.75rem);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay { display: block; }

  .topbar-hamburger { display: flex; align-items: center; }
  .topbar-nav { display: none; }
  .topbar-cta { display: none; }

  .main-content { padding: 1.25rem 1rem; }

  .topbar-mobile-nav {
    display: block;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: rgba(250, 250, 247, 0.97);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--color-border);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    z-index: 99;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.28s ease;
  }
  .topbar-mobile-nav.open {
    max-height: 360px;
  }
  .topbar-mobile-nav a {
    display: block;
    padding: 0.8125rem 1.5rem;
    color: var(--color-text-secondary);
    font-size: 0.9375rem;
    font-weight: 500;
    text-decoration: none;
    border-bottom: 1px solid var(--color-border-subtle);
    transition: background 0.15s, color 0.15s;
  }
  .topbar-mobile-nav a:last-child { border-bottom: none; }
  .topbar-mobile-nav a:hover {
    background: var(--color-bg-hover);
    color: var(--color-text);
  }
}

/* ══════════════════════════════════════════════
   MERMAID DIAGRAM VIEWER
   ══════════════════════════════════════════════ */

.mermaid-wrap {
  position: relative;
  margin: 2rem 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-bg-secondary);
  overflow: hidden;
  cursor: grab;
  user-select: none;
  touch-action: none;
  min-height: 160px;
  display: flex;
  align-items: stretch;
}
.mermaid-wrap:active { cursor: grabbing; }

/* Mermaid renders inside <pre class="mermaid"> — reset pre styles, fill wrap */
.mermaid-wrap pre.mermaid {
  all: unset;
  display: block;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}

/* SVG dimensions are controlled entirely by JS (viewBox aspect ratio) */
.mermaid-wrap pre.mermaid svg {
  display: block;
}

/* Toolbar (top-right) */
.mermaid-toolbar {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  display: flex;
  gap: 0.2rem;
  z-index: 20;
  background: rgba(250, 250, 247, 0.92);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 0.25rem;
  box-shadow: 0 1px 6px rgba(0,0,0,0.08);
  backdrop-filter: blur(4px);
}

.mermaid-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  color: var(--color-text-secondary);
  transition: background 0.12s, color 0.12s;
}
.mermaid-btn:hover {
  background: var(--color-brand);
  color: #fff;
}
.mermaid-btn-fs svg { display: block; }

/* Hint label */
.mermaid-wrap::after {
  content: 'колесо — зум · тащи — пан · двойной клик — сброс';
  position: absolute;
  bottom: 0.4rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
.mermaid-wrap:hover::after { opacity: 1; }

/* ── Fullscreen overlay ── */
.mermaid-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 14, 13, 0.80);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
  backdrop-filter: blur(3px);
  touch-action: none;
}
.mermaid-overlay.visible { opacity: 1; }

.mermaid-overlay-box {
  position: relative;
  width: min(96vw, 1400px);
  height: 90vh;
  background: var(--color-bg-secondary);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0,0,0,0.35);
  display: flex;
  flex-direction: column;
}

.mermaid-overlay-wrap {
  flex: 1;
  overflow: hidden;
  cursor: grab;
  user-select: none;
  touch-action: none;
  position: relative;
}
.mermaid-overlay-wrap:active { cursor: grabbing; }

/* SVG placed directly in overlay wrap, fills it for viewBox pan/zoom */
.mermaid-overlay-wrap svg {
  display: block;
  width: 100%;
  height: 100%;
}

.mermaid-overlay-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 10;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 50%;
  cursor: pointer;
  font-size: 13px;
  color: var(--color-text);
  transition: background 0.12s, color 0.12s;
}
.mermaid-overlay-close:hover {
  background: var(--color-brand);
  color: #fff;
  border-color: var(--color-brand);
}

.mermaid-overlay-toolbar {
  position: absolute;
  top: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
}

/* ── pymdownx.details: collapsible solution blocks ── */
details {
  margin: 1.25rem 0;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--color-surface);
}

details summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
  list-style: none;
  background: var(--color-bg-secondary);
  border-bottom: 1px solid transparent;
  transition: background 0.15s;
}

details summary::-webkit-details-marker { display: none; }

details summary::before {
  content: "▶";
  font-size: 0.65rem;
  color: var(--color-text-muted);
  transition: transform 0.2s;
  flex-shrink: 0;
}

details[open] summary {
  border-bottom-color: var(--color-border);
}

details[open] summary::before {
  transform: rotate(90deg);
}

details summary:hover {
  background: var(--color-bg-hover);
}

details > *:not(summary) {
  padding: 0 1.25rem;
}

details > p:first-of-type   { margin-top: 1rem; }
details > *:last-child       { margin-bottom: 1rem; }
details > .highlight         { margin: 0.75rem 0; border-radius: 6px; overflow: hidden; }

/* success / tip variant — green accent */
details.success,
details.tip {
  border-color: #16A34A40;
}
details.success summary,
details.tip summary {
  background: #F0FDF4;
  color: #14532D;
}
details.success summary::before,
details.tip summary::before {
  color: #16A34A;
}

/* note variant — blue accent */
details.note {
  border-color: #2B6CB040;
}
details.note summary {
  background: #EBF4FF;
  color: #1E3A5F;
}
details.note summary::before {
  color: #2B6CB0;
}
