/* Tokeny 1:1 z GRIT stats panel — dark jest domyślny, przełącznik dodaje
   klasę .light-mode na <body> (bez media query, tak jak w panelu). */
:root {
  --bg: #0b0d11;
  --bg2: #0e1116;
  --card: #101319;
  --card2: #171b23;
  --border: #21262f;
  --border2: #2c323d;
  --sidebar-bg: #0a0c12;
  --text: #e7eaf0;
  --text2: #99a3b2;
  --text3: #5e6a79;
  --accent: #8177ff;
  --accent2: #a29bff;
  --accent-weak: rgba(129, 119, 255, 0.13);
  --good: #3fb984;
  --warn: #d6a441;
  --bad: #e5615f;

  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, Consolas, monospace;

  --r-sm: 4px;
  --r: 6px;
  --r-lg: 8px;
  --r-pill: 999px;

  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.12);
  --shadow-pop: 0 6px 20px rgba(0, 0, 0, 0.18);

  --sidebar-w: 280px;
  --content-w: 760px;
  font-synthesis: none;
}

:root.light-mode {
  --bg: #fbfcfd;
  --bg2: #f3f5f9;
  --card: #ffffff;
  --card2: #f3f5f9;
  --border: #e6e9ee;
  --border2: #d3d8e0;
  --sidebar-bg: #ffffff;
  --text: #191e27;
  --text2: #58616f;
  --text3: #8a94a2;
  --accent: #5b52e0;
  --accent2: #4a41c8;
  --accent-weak: rgba(91, 82, 224, 0.1);
  --good: #1f9d6b;
  --warn: #b7801f;
  --bad: #d1504e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent2); text-decoration: underline; }

.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 20px 16px 24px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.sidebar-nav {
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 8px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border2); border-radius: var(--r-pill); }
.sidebar-nav::-webkit-scrollbar-thumb:hover { background: var(--text3); }

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 20px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
}
.sidebar-brand:hover { text-decoration: none; opacity: 0.85; }
.sidebar-brand .dot {
  width: 8px;
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--accent);
  flex-shrink: 0;
}

.theme-toggle {
  appearance: none;
  border: 1px solid var(--border2);
  background: var(--card);
  color: var(--text2);
  border-radius: var(--r);
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  flex-shrink: 0;
}
.theme-toggle:hover { color: var(--text); border-color: var(--accent); }

.sidebar-search { margin-bottom: 14px; flex-shrink: 0; }
.search-input {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border2);
  color: var(--text);
  border-radius: var(--r);
  padding: 7px 10px;
  font-size: 12.5px;
  font-family: var(--font-ui);
}
.search-input:focus { outline: none; border-color: var(--accent); }
.search-input::placeholder { color: var(--text3); }

.sidebar-nav { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }

.search-results { list-style: none; margin: 0; padding: 0; }
.search-results li { margin: 1px 0; }
.search-results a {
  display: block;
  padding: 7px 9px;
  border-radius: var(--r);
  text-decoration: none;
}
.search-results a:hover { background: var(--card2); text-decoration: none; }
.search-results .sr-title { font-size: 12.5px; font-weight: 600; color: var(--text); display: block; }
.search-results .sr-snippet {
  font-size: 11.5px;
  color: var(--text3);
  display: block;
  margin-top: 2px;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.search-empty { padding: 8px 9px; font-size: 12px; color: var(--text3); }

.top-actions {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 30;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 4px 9px;
  border-radius: 6px;
  border: 1.5px solid var(--border2);
  background: var(--card2);
  color: var(--text2);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent2); text-decoration: none; }
.icon-btn.danger:hover { border-color: var(--bad); color: var(--bad); }

@media (max-width: 860px) {
  .top-actions { top: 10px; right: 10px; }
}

.sidebar-resizer {
  position: absolute;
  top: 0;
  right: -4px;
  width: 7px;
  height: 100%;
  cursor: col-resize;
  z-index: 5;
}
.sidebar-resizer:hover, .sidebar-resizer.dragging { background: var(--accent-weak); }

.nav-tree, .nav-tree ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.nav-tree ul {
  margin-left: 11px;
  padding-left: 9px;
  border-left: 1px solid var(--border);
}
.nav-tree li { margin: 0; }

.nav-tree .nav-link {
  display: block;
  padding: 5px 8px;
  border-radius: var(--r);
  color: var(--text2);
  font-size: 12.5px;
  line-height: 1.4;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-tree .nav-link:hover {
  background: var(--card2);
  color: var(--text);
  text-decoration: none;
}
.nav-tree .nav-link.active {
  background: var(--accent-weak);
  color: var(--accent2);
  font-weight: 600;
}

.nav-tree details > summary {
  display: flex;
  align-items: center;
  list-style: none;
  cursor: pointer;
  border-radius: var(--r);
}
.nav-tree details > summary::-webkit-details-marker { display: none; }
.nav-tree details > summary::marker { content: ''; }
.nav-tree details > summary .nav-link { flex: 1; min-width: 0; }

.nav-caret {
  flex-shrink: 0;
  width: 20px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text3);
  transition: transform 0.15s ease;
}
.nav-caret::before { content: '\203A'; font-size: 12px; }
.nav-tree details[open] > summary .nav-caret { transform: rotate(90deg); }

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: center;
  padding: 56px 32px 100px;
  background: var(--bg);
}

.content {
  width: 100%;
  max-width: var(--content-w);
}

.content .doc-title {
  font-size: 25px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
  color: var(--text);
}

.doc-meta {
  color: var(--text3);
  font-size: 12px;
  margin-bottom: 32px;
}

.content h1 { font-size: 19px; margin-top: 38px; }
.content h2 { font-size: 16px; margin-top: 32px; }
.content h3 { font-size: 14px; margin-top: 26px; }
.content h1, .content h2, .content h3, .content h4 {
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.3;
  color: var(--text);
}

.content p, .content li { line-height: 1.65; font-size: 14px; color: var(--text); }
.content p { margin: 12px 0; }

.content ul, .content ol { padding-left: 22px; }

.content blockquote {
  margin: 20px 0;
  padding: 4px 18px;
  border-left: 3px solid var(--accent);
  background: var(--accent-weak);
  border-radius: 0 var(--r) var(--r) 0;
  color: var(--text);
}

.callout {
  margin: 20px 0;
  padding: 14px 18px;
  border-radius: var(--r-lg);
  border: 1px solid var(--border2);
  border-left: 3px solid var(--text2);
  background: var(--card);
  box-shadow: var(--shadow-card);
}
.callout p:first-child { margin-top: 0; }
.callout p:last-child { margin-bottom: 0; }
.callout-info { border-left-color: var(--accent); background: var(--accent-weak); }
.callout-tip, .callout-success { border-left-color: var(--good); background: color-mix(in srgb, var(--good) 12%, var(--card)); }
.callout-warning { border-left-color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, var(--card)); }
.callout-danger { border-left-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, var(--card)); }
.callout-note { border-left-color: var(--text2); }

.embed-video {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  margin: 20px 0;
  border-radius: var(--r-lg);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--card2);
  box-shadow: var(--shadow-card);
}
.embed-video iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.content code {
  font-family: var(--font-mono);
  background: var(--card2);
  padding: 2px 6px;
  border-radius: var(--r-sm);
  font-size: 0.88em;
  color: var(--text);
}

.content pre {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px 18px;
  overflow-x: auto;
  box-shadow: var(--shadow-card);
}
.content pre code { background: none; padding: 0; }

.content table {
  border-collapse: collapse;
  width: 100%;
  margin: 20px 0;
  font-size: 14px;
  background: var(--card);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}
.content th, .content td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.content th { background: var(--card2); font-weight: 600; color: var(--text); }

.content img {
  max-width: 100%;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
}

.content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 36px 0;
}

.task-list-item { list-style: none; margin-left: -22px; }
.task-list-item input { margin-right: 8px; }

.doc-children {
  margin-top: 48px;
  padding: 20px 20px 6px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--card);
  box-shadow: var(--shadow-card);
}
.doc-children h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text3);
  margin: 0 0 12px;
  font-weight: 700;
}
.doc-children ul { list-style: none; padding: 0; margin: 0 0 14px; }
.doc-children li { margin: 2px 0; }
.doc-children a {
  display: block;
  font-size: 14.5px;
  padding: 6px 10px;
  margin: 0 -10px;
  border-radius: var(--r);
  color: var(--text);
}
.doc-children a:hover { background: var(--card2); text-decoration: none; color: var(--accent2); }

.footer-note {
  margin-top: 60px;
  color: var(--text3);
  font-size: 12px;
}

.menu-toggle { display: none; }

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 20;
    box-shadow: var(--shadow-pop);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    position: sticky;
    top: 12px;
    margin: 12px 0 0 16px;
    background: var(--card);
    border: 1px solid var(--border2);
    color: var(--text);
    border-radius: var(--r);
    padding: 8px 12px;
    font-size: 13px;
    cursor: pointer;
    z-index: 21;
    box-shadow: var(--shadow-card);
  }
  .main { padding: 8px 20px 80px; }
  .content .doc-title { font-size: 26px; }
}
