/* ===========================================
   Design tokens — dark (default)
   =========================================== */
:root {
  --heading-font: 'Lato', 'Open Sans', system-ui, sans-serif;
  --body-font:    'Open Sans', 'Lato', system-ui, sans-serif;
  --mono-font:    ui-monospace, 'SFMono-Regular', 'Cascadia Code', monospace;
  --sidebar-w:    268px;
  --header-h:     58px;
  --radius:       8px;
  --radius-sm:    5px;

  --bg:           #0d1117;
  --bg-subtle:    #161b22;
  --panel:        #161b22;
  --panel-2:      #1c2433;
  --panel-3:      #21293d;
  --text:         #e2e8f0;
  --text-muted:   #fff;
  --link:         #4ecba8;
  --accent:       #14c58a;
  --accent-dim:   rgba(20, 197, 138, 0.14);
  --border:       #1e2d3d;
  --border-2:     #28384d;
  --shadow-sm:    0 1px 2px rgba(0,0,0,.25);
  --shadow:       0 2px 8px rgba(0,0,0,.35);
  --code-bg:      #161b22;
  color-scheme: dark;
}

/* ===========================================
   Auto light mode — follows OS preference
   (overrides :root when no data-theme is set)
   =========================================== */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:         #ffffff;
    --bg-subtle:  #f6f8fa;
    --panel:      #ffffff;
    --panel-2:    #f6f8fa;
    --panel-3:    #eaecf0;
    --text:       #1c2128;
    --text-muted: #000;
    --link:       #0b7554;
    --accent:     #0d9e6a;
    --accent-dim: rgba(13, 158, 106, 0.1);
    --border:     #d0d7de;
    --border-2:   #b0b7bf;
    --shadow-sm:  0 1px 2px rgba(31,35,40,.08);
    --shadow:     0 2px 8px rgba(31,35,40,.12);
    --code-bg:    #1a2233;
    color-scheme: light;
  }
}

/* Manual dark override (beats media query) */
[data-theme="dark"] {
  --bg:         #0d1117;
  --bg-subtle:  #161b22;
  --panel:      #161b22;
  --panel-2:    #1c2433;
  --panel-3:    #21293d;
  --text:       #e2e8f0;
  --text-muted: #fff;
  --link:       #4ecba8;
  --accent:     #14c58a;
  --accent-dim: rgba(20, 197, 138, 0.14);
  --border:     #1e2d3d;
  --border-2:   #28384d;
  --shadow-sm:  0 1px 2px rgba(0,0,0,.25);
  --shadow:     0 2px 8px rgba(0,0,0,.35);
  --code-bg:    #161b22;
  color-scheme: dark;
}

/* Manual light override */
[data-theme="light"] {
  --bg:         #ffffff;
  --bg-subtle:  #f6f8fa;
  --panel:      #ffffff;
  --panel-2:    #f6f8fa;
  --panel-3:    #eaecf0;
  --text:       #1c2128;
  --text-muted: #000;
  --link:       #0b7554;
  --accent:     #0d9e6a;
  --accent-dim: rgba(13, 158, 106, 0.1);
  --border:     #d0d7de;
  --border-2:   #b0b7bf;
  --shadow-sm:  0 1px 2px rgba(31,35,40,.08);
  --shadow:     0 2px 8px rgba(31,35,40,.12);
  --code-bg:    #1a2233;
  color-scheme: light;
}

/* ===========================================
   Base
   =========================================== */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--body-font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background 0.2s, color 0.2s;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--heading-font);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.25px;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--accent); }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }

/* ===========================================
   Accessibility
   =========================================== */
.skip-link {
  position: absolute; top: -48px; left: 8px;
  background: var(--accent); color: #fff;
  padding: 10px 18px; font-weight: 700;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  z-index: 200; text-decoration: none;
  transition: top 0.15s;
}
.skip-link:focus { top: 0; }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border-width: 0;
}

/* ===========================================
   Header
   =========================================== */
.site-header {
  position: sticky; top: 0; z-index: 50;
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  /* Thin accent stripe at the very top */
  background-image: linear-gradient(to bottom, var(--accent) 2px, var(--panel) 2px);
}

/* Brand block — lines up flush with the sidebar */
.brand {
  display: flex; align-items: center;
  height: 100%;
  padding: 0 20px;
  min-width: var(--sidebar-w);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}

.brand a {
  font-family: var(--heading-font);
  font-weight: 900;
  font-size: 15px;
  letter-spacing: -0.3px;
  color: var(--text);
  display: flex; align-items: center; gap: 10px;
}
/* Logo image in brand */
.brand-logo {
  width: 26px; height: 26px;
  display: block; flex-shrink: 0;
  border-radius: 50%;
  transition: transform 0.2s cubic-bezier(0.34,1.56,0.64,1);
}
.brand a:hover .brand-logo { transform: rotate(-8deg) scale(1.08); }
.brand a:hover { text-decoration: none; color: var(--accent); }

.top-nav { display: flex; align-items: center; gap: 2px; padding: 0 12px; flex: 1; }
.top-nav a {
  font-size: 13.5px; font-weight: 500;
  color: var(--text-muted);
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  transition: background 0.12s, color 0.12s;
}
.top-nav a:not(.cta):hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.top-nav a[aria-current="page"] { color: var(--text); font-weight: 600; }

.top-nav .cta {
  background: var(--accent); color: #fff;
  font-weight: 700; font-size: 13.5px;
  padding: 7px 15px; border-radius: var(--radius-sm);
  margin-left: 8px;
  transition: opacity 0.12s, transform 0.1s;
}
.top-nav .cta:hover { text-decoration: none; opacity: 0.88; transform: translateY(-1px); }

/* Theme toggle — icon-only button */
.theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 15px;
  margin-left: 4px;
  margin-right: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  flex-shrink: 0;
}
.theme-toggle:hover { background: var(--panel-2); border-color: var(--border-2); color: var(--text); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-toggle svg { display: block; pointer-events: none; }

/* ===========================================
   Layout grid
   =========================================== */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: calc(100vh - var(--header-h));
}

/* ===========================================
   Sidebar
   =========================================== */
.sidebar {
  background: var(--bg-subtle);
  border-right: 1px solid var(--border);
  padding: 12px 8px 40px;
  overflow-y: auto;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
}

.sidebar-group { margin-bottom: 2px; }

.sidebar h3 {
  margin: 22px 0 4px 10px;
  color: var(--text-muted);
  font-family: var(--heading-font);
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

.sidebar-group:first-child > h3 { margin-top: 6px; }

.sidebar ul { list-style: none; padding: 0; margin: 0; }
.sidebar li { margin: 1px 0; }
.sidebar a {
  display: block;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 400;
  color: var(--text-muted);
  transition: background 0.1s, color 0.1s;
}
.sidebar a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.sidebar a[aria-current="page"] {
  font-weight: 600;
  background: var(--accent-dim);
  color: var(--accent);
  border-left: 2px solid var(--accent);
  padding-left: 8px;
}

/* ===========================================
   Content
   =========================================== */
.content {
  padding: 40px 48px 72px;
  background: var(--bg);
  color: var(--text);
  min-width: 0;
}

.doc-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  margin-bottom: 36px;
}

#doc-title {
  margin: 0;
  font-family: var(--heading-font);
  font-size: 2em;
  font-weight: 900;
  letter-spacing: -0.6px;
  line-height: 1.15;
}

/* Decorative accent underline below the page title */
#doc-title::after {
  content: '';
  display: block;
  width: 36px; height: 3px;
  background: var(--accent);
  border-radius: 2px;
  margin-top: 12px;
}

.doc-controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

#page-search {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  min-width: 200px;
  font-size: 13.5px;
  font-family: var(--body-font);
  transition: border-color 0.15s, box-shadow 0.15s;
}
#page-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
#page-search::placeholder { color: var(--text-muted); }

/* Search highlighting */
.search-highlight, mark.search-highlight {
  background-color: rgba(250, 204, 21, 0.35);
  color: inherit; padding: 1px 0; border-radius: 2px;
}

/* ===========================================
   Animations
   =========================================== */
@keyframes ici-fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes ici-fadeLeft {
  from { opacity: 0; transform: translateX(-12px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes ici-barGrow {
  from { width: 0; opacity: 0; }
  to   { width: 36px; opacity: 1; }
}

@media (prefers-reduced-motion: no-preference) {
  .sidebar {
    animation: ici-fadeLeft 0.28s ease both;
  }
  .content {
    animation: ici-fadeUp 0.32s ease 0.06s both;
  }
  /* Stagger sidebar section groups */
  .sidebar-group:nth-child(1) { animation: ici-fadeLeft 0.24s ease 0.04s both; }
  .sidebar-group:nth-child(2) { animation: ici-fadeLeft 0.24s ease 0.10s both; }
  .sidebar-group:nth-child(3) { animation: ici-fadeLeft 0.24s ease 0.16s both; }
  .sidebar-group:nth-child(4) { animation: ici-fadeLeft 0.24s ease 0.22s both; }
  /* Title accent bar grows in */
  #doc-title::after {
    animation: ici-barGrow 0.5s cubic-bezier(0.4,0,0.2,1) 0.3s both;
  }
}

/* ===========================================
   Markdown body
   =========================================== */
.markdown-body { max-width: 720px; }

.markdown-body h2 {
  font-family: var(--heading-font);
  font-size: 1.3em; font-weight: 700;
  margin-top: 2.2em; margin-bottom: 0.6em;
  padding-bottom: 0.4em;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.markdown-body h3 {
  font-family: var(--heading-font);
  font-size: 1.05em; font-weight: 700;
  margin-top: 1.6em; margin-bottom: 0.4em;
  color: var(--text);
}

.markdown-body h4 {
  font-size: 0.9em; font-weight: 700;
  margin-top: 1.3em; margin-bottom: 0.3em;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.6px;
}

.markdown-body p { line-height: 1.8; margin: 0.8em 0; }
.markdown-body ul, .markdown-body ol { line-height: 1.8; padding-left: 1.6em; margin: 0.6em 0; }
.markdown-body li { margin: 0.2em 0; }

/* Inline code */
.markdown-body code {
  font-family: var(--mono-font);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--link);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.845em;
}

/* Code blocks — always use a dark bg even in light mode for readability */
.markdown-body pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  overflow-x: auto;
  margin: 1.2em 0;
  font-size: 0.875em;
  line-height: 1.6;
  box-shadow: var(--shadow-sm);
}
.markdown-body pre code {
  background: none; border: none; padding: 0;
  color: #cdd9e5; font-size: inherit;
}

/* Tables */
.markdown-body table {
  border-collapse: collapse; width: 100%;
  margin: 1.2em 0; font-size: 0.9em;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.markdown-body th {
  background: var(--panel-2); font-weight: 700;
  font-size: 0.82em; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-muted);
}
.markdown-body th, .markdown-body td {
  padding: 9px 14px; text-align: left;
  border-bottom: 1px solid var(--border);
}
.markdown-body tbody tr:last-child td { border-bottom: none; }

/* Blockquotes */
.markdown-body blockquote {
  border-left: 3px solid var(--accent);
  margin: 1.2em 0; padding: 12px 16px;
  background: var(--accent-dim);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.markdown-body blockquote p { margin: 0; }

.markdown-body a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ===========================================
   Footer
   =========================================== */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 18px 48px;
  background: var(--bg-subtle);
  font-size: 13px;
  color: var(--text-muted);
  display: flex; align-items: center;
  justify-content: space-between; flex-wrap: wrap; gap: 8px;
}
.site-footer a { color: var(--text-muted); }
.site-footer a:hover { color: var(--accent); text-decoration: none; }

/* ===========================================
   Tab system
   =========================================== */
.tabs-container { margin: 2rem 0; }

.tabs-nav {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
  overflow-x: auto; scrollbar-width: thin;
}

.tab-button {
  background: none; border: none;
  padding: 0.7rem 1.25rem;
  font-size: 0.9rem; font-weight: 500;
  font-family: var(--body-font);
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s; white-space: nowrap;
  position: relative; bottom: -1px;
}
.tab-button:hover { color: var(--text); background: var(--panel-2); }
.tab-button.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.tab-content { display: none; animation: fadeIn 0.2s ease; }
.tab-content.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.tab-badge {
  display: inline-block; margin-left: 0.4rem;
  padding: 0.1rem 0.45rem; font-size: 0.72rem; font-weight: 600;
  background: var(--accent); color: #fff; border-radius: 10px;
}

/* ===========================================
   Mobile navigation toggle button
   =========================================== */
.nav-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 15px;
  margin-right: 4px;
  align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.nav-toggle:hover { background: var(--panel-2); border-color: var(--border-2); color: var(--text); }
.nav-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.nav-toggle svg { display: block; pointer-events: none; }

/* Overlay shown behind the open sidebar drawer on mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 39;
}
.sidebar-overlay.open { display: block; }

/* ===========================================
   Print
   =========================================== */
@media print {
  .site-header, .sidebar, .doc-controls, .site-footer, .skip-link { display: none; }
  .layout { grid-template-columns: 1fr; }
  .content { padding: 0; }
  a { color: #000; text-decoration: underline; }
  .search-highlight { background-color: transparent; }
}

/* ===========================================
   Responsive
   =========================================== */
@media (max-width: 980px) {
  .nav-toggle { display: inline-flex; }
  .layout { grid-template-columns: 1fr; }
  .brand { min-width: auto; border-right: none; }
  /* Sidebar becomes a fixed off-canvas drawer on mobile */
  .sidebar {
    display: none;
    position: fixed;
    top: var(--header-h);
    left: 0;
    width: min(280px, 85vw);
    height: calc(100vh - var(--header-h));
    z-index: 40;
    overflow-y: auto;
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow);
    /* Reset the desktop sticky rules */
    max-height: none;
    border-bottom: none;
  }
  .sidebar.open {
    display: block;
    animation: ici-fadeLeft 0.2s ease both;
  }
  .top-nav { flex-wrap: nowrap; justify-content: flex-end; gap: 2px; }
  .top-nav .cta { display: none; } /* CTA moves into the sidebar drawer on mobile */
  .doc-header { flex-direction: column; align-items: flex-start; }
  #page-search { min-width: 160px; }
  .content { padding: 24px 20px 48px; }
  .site-footer { padding: 16px 20px; }

  .tab-button { padding: 0.6rem 1rem; font-size: 0.875rem; }
}

/* On very narrow screens hide text nav links to prevent overflow;
   the sidebar drawer serves as the navigation menu instead. */
@media (max-width: 600px) {
  .top-nav > a:not(.cta) { display: none; }
}
