/* ==================== reset / base ==================== */

*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: 'SF Pro Text', 'SF Pro Icons', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
  margin: 0;
  padding: 0;
  color: #1a1a1a;
  line-height: 1.65;
  background: #ffffff;
}

a { color: #2563a8; text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4, h5, h6 {
  color: #62b8db !important;
  line-height: 1.3;
  margin: 1.6em 0 0.6em;
}
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; margin-top: 2em; }
h3 { font-size: 1.2rem; }
h4 { font-size: 1.05rem; }

#article p { margin: 1em 0; }
#article ul, #article ol { margin: 1em 0; padding-left: 1.6em; }
#article li { margin: 0.3em 0; }
#article blockquote {
  margin: 1em 0;
  padding: 0.2em 1em;
  border-left: 3px solid #62b8db;
  background: #f7fbfd;
  color: #333;
}
#article code {
  background: #f0f0f0;
  padding: 0.15em 0.4em;
  border-radius: 3px;
  font-size: 0.9em;
}
#article img {
  max-width: 100%;
  border: 1px solid #e2e2e2;
  border-radius: 4px;
  cursor: zoom-in;
  display: block;
  margin: 1em 0;
}
#article table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
  font-size: 0.92em;
}
#article th, #article td {
  border: 1px solid #ddd;
  padding: 0.5em 0.7em;
  text-align: left;
  vertical-align: top;
}
#article th {
  background: #f0f7fa;
}
#article tr:nth-child(even) td {
  background: #fafafa;
}

/* ==================== navbar ==================== */

#navbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 4rem;
  background: #ffffff;
  border-bottom: 1px solid #eaeaea;
}
.navbar-inner {
  height: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 2rem;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1.5rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: #1a1a1a;
  font-weight: 600;
  white-space: nowrap;
  justify-self: start;
}
.brand:hover { text-decoration: none; }
.brand img { display: block; height: 36px; width: auto; border-radius: 4px; }

.search-box {
  position: relative;
  width: 420px;
  max-width: 100%;
  justify-self: center;
}
.search-box input {
  width: 100%;
  padding: 0.5rem 0.8rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 0.95rem;
}
.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 60vh;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  z-index: 30;
}
.search-result {
  display: block;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid #f0f0f0;
  color: #1a1a1a;
}
.search-result:hover { background: #f7fbfd; text-decoration: none; }
.search-result:last-child { border-bottom: none; }
.result-title { font-weight: 600; font-size: 0.95rem; }
.result-section { font-size: 0.78rem; color: #62b8db; margin-top: 0.1em; }
.result-excerpt { font-size: 0.85rem; color: #555; margin-top: 0.2em; }
.result-excerpt mark { background: #fdf1a8; }
.search-empty { padding: 0.8rem; color: #777; font-size: 0.9rem; }

.locale-switch {
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #1a1a1a;
  white-space: nowrap;
  justify-self: end;
}
.locale-switch:hover { background: #f0f7fa; text-decoration: none; }

#sidebar-toggle {
  display: none;
  position: fixed;
  top: 0.85rem;
  left: 0.75rem;
  z-index: 25;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  width: 2.2rem;
  height: 2.2rem;
  font-size: 1.1rem;
  cursor: pointer;
}

/* ==================== layout ==================== */

#layout {
  display: grid;
  grid-template-columns: 16rem minmax(0, 1fr) 16rem;
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 2rem;
  align-items: start;
}

#sidebar {
  position: sticky;
  top: 4rem;
  height: calc(100vh - 4rem);
  overflow-y: auto;
  padding: 1.5rem 1rem;
  border-right: 1px solid #eee;
  font-size: 0.9rem;
}

#content {
  min-width: 0;
  padding: 1.75rem 2.5rem;
}

#article { max-width: 80ch; }

#toc {
  position: sticky;
  top: 4rem;
  height: calc(100vh - 4rem);
  overflow-y: auto;
  padding: 1.5rem 1rem;
  border-left: 1px solid #eee;
  font-size: 0.85rem;
}

/* ==================== sidebar tree ==================== */

.nav-tree, .sub-tree { list-style: none; margin: 0; padding: 0; }
.nav-tree > li { margin: 0.15rem 0; }
.section-row { display: flex; align-items: center; justify-content: space-between; gap: 0.3rem; }
.nav-tree a {
  display: block;
  padding: 0.35rem 0.5rem;
  border-radius: 5px;
  color: #333;
  flex: 1;
  min-width: 0;
}
.nav-tree a:hover { background: #f5f5f5; text-decoration: none; }
.nav-tree a.active {
  background: #eaf6fb;
  color: #2563a8;
  font-weight: 600;
  border-left: 3px solid #62b8db;
  padding-left: calc(0.5rem - 3px);
}
.section.current > .section-row > a:not(.active) {
  color: #1a1a1a;
  font-weight: 600;
}
.sub-tree {
  max-height: 0;
  overflow: hidden;
  padding-left: 1.5rem;
  border-left: 1px solid #eee;
  margin-left: 0.6rem;
}
.section.expanded .sub-tree { max-height: none; }
.toggle {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  cursor: pointer;
  width: 1.6rem;
  height: 1.6rem;
  color: #777;
  border-radius: 4px;
}
.toggle:hover { background: #f0f0f0; color: #333; }
.toggle svg {
  width: 12px;
  height: 12px;
  transition: transform 0.15s ease;
}
.section.expanded .toggle svg { transform: rotate(90deg); }

/* ==================== toc ==================== */

.toc-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #999;
  margin-bottom: 0.6rem;
  font-weight: 600;
}
#toc ul { list-style: none; margin: 0; padding: 0; }
#toc li { margin: 0.1rem 0; }
#toc a {
  display: block;
  padding: 0.25rem 0;
  color: #555;
  border-left: 2px solid transparent;
  padding-left: 0.6rem;
}
#toc a:hover { color: #2563a8; text-decoration: none; }
#toc a.active {
  color: #2563a8;
  font-weight: 600;
  border-left-color: #62b8db;
}
.toc-level-3 { padding-left: 0.8rem; }

/* ==================== prev/next ==================== */

#prevnext { margin-top: 2.5rem; max-width: 80ch; }
.prevnext-row {
  display: flex;
  gap: 1rem;
  border-top: 1px solid #eee;
  padding-top: 1.25rem;
}
.prevnext-link {
  flex: 1;
  border: 1px solid #e2e2e2;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  color: #1a1a1a;
}
.prevnext-link:hover { border-color: #62b8db; text-decoration: none; box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.prevnext-link.next { text-align: right; }
.prevnext-link .dir { display: block; font-size: 0.75rem; color: #999; margin-bottom: 0.25rem; }
.prevnext-link .title { font-weight: 600; }
.prevnext-spacer { flex: 1; }

/* ==================== footer ==================== */

#footer {
  text-align: center;
  padding: 0.75rem;
  background: #f0f0f0;
  color: #555;
  font-size: 0.85rem;
}
#footer a { color: #2563a8; }

/* ==================== lightbox ==================== */

#lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  cursor: zoom-out;
  padding: 2rem;
}
#lightbox-overlay[hidden] { display: none; }
#lightbox-image {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.4);
}

/* ==================== responsive ==================== */

@media (max-width: 1279px) {
  #layout { grid-template-columns: 16rem minmax(0, 1fr); }
  #toc { display: none; }
}

@media (max-width: 900px) {
  .navbar-inner { grid-template-columns: auto 1fr auto; padding: 0 1rem; }
  .search-box { width: 100%; justify-self: stretch; }
}

@media (max-width: 768px) {
  #layout { grid-template-columns: 1fr; padding: 0; }
  #sidebar-toggle { display: block; }
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 16rem;
    background: #fff;
    z-index: 24;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 2px 0 12px rgba(0,0,0,0.15);
    padding-top: 4rem;
  }
  #sidebar.open { transform: translateX(0); }
  #content { padding: 1.25rem; padding-top: 3.5rem; }
  .brand span { display: none; }
  .search-box { max-width: none; }
}
