/* ==========================================================================
   VIETRRO 2026 — layout.css
   Site chrome: topbar, sidebar (pinned / collapsed / mobile drawer),
   main content shell, back-to-top button.
   This chrome is new (the 19 source modules each had their own tiny local
   topbar+nav); it replaces those per-module topbars with one shared,
   sidebar-driven navigation system as required by the brief.
   ========================================================================== */

body { padding-top: var(--topbar-h); }

/* ---------- Topbar ---------- */
.site-topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 60;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  background: rgba(255,255,255,.97);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.hamburger-btn {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  border: 1px solid var(--line);
  background: var(--white);
  border-radius: 8px;
  display: grid;
  place-items: center;
  gap: 4px;
}
.hamburger-btn span {
  display: block;
  width: 18px; height: 2px;
  background: var(--blue);
  border-radius: 2px;
}

.site-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  flex: 0 0 auto;
}
.site-logo .mark {
  width: 36px; height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--blue);
  color: #fff;
  font-weight: 900;
  font-family: "Times New Roman", Times, serif;
}
.site-logo b { display: block; font-size: 14px; }
.site-logo small { display: block; color: var(--muted); font-size: 11px; margin-top: -2px; }

.breadcrumb {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.breadcrumb .crumb-sep { margin: 0 6px; color: #b7c1cb; }
.breadcrumb .crumb-current { color: var(--blue); font-weight: 700; }
.breadcrumb .crumb-link { color: var(--muted); text-decoration: none; }
.breadcrumb .crumb-link:hover { color: var(--blue); text-decoration: underline; }

.topbar-search-btn {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--white);
  border-radius: 8px;
  height: 40px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--blue);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* ---------- App shell ---------- */
.app-shell {
  display: flex;
  align-items: flex-start;
  min-height: calc(100vh - var(--topbar-h));
}

/* ---------- Sidebar ---------- */
.site-sidebar {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--white);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 50;
  transform: translateX(0);
  transition: transform .22s ease, width .22s ease;
  padding: 18px 0 90px;
}

.main-content {
  flex: 1 1 auto;
  min-width: 0;
  margin-left: var(--sidebar-w);
  transition: margin-left .22s ease;
  width: 100%;
}

/* Collapsed (desktop icon rail) state */
body.sidebar-collapsed .site-sidebar {
  width: var(--sidebar-rail-w);
}
body.sidebar-collapsed .main-content {
  margin-left: var(--sidebar-rail-w);
}
body.sidebar-collapsed .site-sidebar .nav-label,
body.sidebar-collapsed .site-sidebar .nav-group-title span,
body.sidebar-collapsed .site-sidebar .doc-toc,
body.sidebar-collapsed .site-sidebar .nav-doc-toggle,
body.sidebar-collapsed .site-sidebar .sidebar-pin-row .pin-label {
  display: none;
}
body.sidebar-collapsed .site-sidebar .nav-doc-link {
  justify-content: center;
}

/* Fully closed (desktop, not pinned, hamburger toggled shut) */
body.sidebar-closed .site-sidebar { transform: translateX(-100%); }
body.sidebar-closed .main-content { margin-left: 0; }

.sidebar-pin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}
.pin-label { font-size: 12px; color: var(--muted); font-weight: 700; }
.pin-btn {
  border: 1px solid var(--line);
  background: var(--white);
  border-radius: 6px;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  font-size: 14px;
}
.pin-btn[aria-pressed="true"] { background: var(--blue); color: #fff; border-color: var(--blue); }

.sidebar-close-btn {
  display: none;
  border: 0;
  background: none;
  font-size: 20px;
  color: var(--muted);
}

.nav-group { margin-bottom: 6px; }
.nav-group-title {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 0;
  background: none;
  text-align: left;
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .06em;
  color: var(--blue);
  text-transform: uppercase;
}
.nav-group-title .chev { transition: transform .18s ease; color: var(--muted); }
.nav-group[data-open="true"] .nav-group-title .chev { transform: rotate(90deg); }
.nav-group-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  background: var(--soft);
  border-radius: 999px;
  padding: 1px 8px;
}

.nav-group-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: none;
}
.nav-group[data-open="true"] .nav-group-list { display: block; }

.nav-doc-item { margin: 0; }
.nav-doc-row {
  display: flex;
  align-items: stretch;
}
.nav-doc-link {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: none;
  text-align: left;
  text-decoration: none;
  padding: 9px 16px 9px 26px;
  font-size: 13px;
  line-height: 1.4;
  color: #46566a;
  border-left: 3px solid transparent;
}
.nav-doc-link:hover { background: var(--soft); color: var(--blue); }
.nav-doc-link[aria-current="true"],
.nav-doc-item.is-active > .nav-doc-row > .nav-doc-link {
  color: var(--blue);
  font-weight: 800;
  border-left-color: var(--gold);
  background: var(--soft);
}
.nav-doc-link .doc-num {
  flex: 0 0 auto;
  color: var(--gold);
  font-weight: 900;
  font-size: 11px;
}

.nav-doc-toggle {
  flex: 0 0 auto;
  width: 30px;
  border: 0;
  background: none;
  display: grid;
  place-items: center;
  color: var(--muted);
}
.nav-doc-toggle .chev { transition: transform .18s ease; }
.nav-doc-toggle[aria-expanded="true"] .chev { transform: rotate(90deg); }
.nav-doc-toggle:hover { color: var(--blue); }

.doc-toc {
  list-style: none;
  margin: 2px 0 10px;
  padding: 0;
  display: none;
}
.doc-toc[data-open="true"] { display: block; }
.doc-toc a {
  display: block;
  padding: 6px 16px 6px 40px;
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
  border-left: 3px solid transparent;
}
.doc-toc a:hover { color: var(--blue); }
.doc-toc a[aria-current="true"] {
  color: var(--blue);
  font-weight: 700;
  border-left-color: var(--blue2);
  background: var(--soft);
}

/* ---------- Mobile drawer ---------- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 35, .45);
  z-index: 45;
}

@media (max-width: 1024px) {
  .site-sidebar {
    transform: translateX(-100%);
    width: min(340px, 86vw);
    box-shadow: 0 0 0 9999px transparent;
  }
  body.sidebar-open .site-sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-overlay { display: block; }
  body.sidebar-open { overflow: hidden; }

  .main-content,
  body.sidebar-collapsed .main-content,
  body.sidebar-closed .main-content {
    margin-left: 0 !important;
  }
  body.sidebar-collapsed .site-sidebar { width: min(340px, 86vw); }
  body.sidebar-collapsed .site-sidebar .nav-label,
  body.sidebar-collapsed .site-sidebar .nav-group-title span,
  body.sidebar-collapsed .site-sidebar .sidebar-pin-row .pin-label { display: inline; }

  .sidebar-pin-row { display: none; }
  .sidebar-close-btn { display: block; }
}

/* ---------- Back to top ---------- */
.back-to-top {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 40;
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--blue);
  color: #fff;
  font-size: 18px;
  display: grid;
  place-items: center;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  box-shadow: 0 10px 26px rgba(16,41,61,.22);
}
.back-to-top.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* ---------- Global site footer ---------- */
.site-footer {
  padding: 28px 5vw;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: var(--white);
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}
.site-footer b { color: var(--ink); display: block; }
.site-footer a { color: var(--blue); font-weight: 800; text-decoration: none; }
