/* ============================================================
   GrimFolio Docs — styles.css
   Dark mode default. Light mode via [data-theme="light"].
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Custom Properties ─────────────────────────────────────── */

:root {
  --bg:              #0f0f1a;
  --surface:         #16162a;
  --surface-2:       #1e1e35;
  --text:            #e2e8f0;
  --text-heading:    #f8fafc;
  --text-muted:      #94a3b8;
  --accent:          #7C3AED;
  --accent-light:    #a78bfa;
  --border:          #2d2d4e;
  --callout-bg:      #1e1535;
  --callout-border:  #7C3AED;
  --table-header:    #7C3AED;
  --table-row-alt:   #1a1a2e;
  --overlay:         rgba(0, 0, 0, 0.85);

  --sidebar-width:   240px;
  --topnav-height:   56px;
  --toc-width:       220px;
  --content-max:     720px;
}

[data-theme="light"] {
  --bg:              #f8f7ff;
  --surface:         #f0eeff;
  --surface-2:       #ffffff;
  --text:            #1e1b4b;
  --text-heading:    #0f0a2a;
  --text-muted:      #6b7280;
  --accent:          #7C3AED;
  --accent-light:    #6d28d9;
  --border:          #ddd6fe;
  --callout-bg:      #ede9fe;
  --callout-border:  #7C3AED;
  --table-header:    #7C3AED;
  --table-row-alt:   #f5f3ff;
  --overlay:         rgba(0, 0, 0, 0.75);
}

/* ── Reset & Base ──────────────────────────────────────────── */

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

html {
  scroll-behavior: smooth;
  font-size: 17px;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.75;
  min-height: 100vh;
}

/* ── Layout Shell ──────────────────────────────────────────── */

.layout {
  display: grid;
  grid-template-areas:
    "topnav topnav topnav"
    "sidebar main toc";
  grid-template-columns: var(--sidebar-width) 1fr var(--toc-width);
  grid-template-rows: var(--topnav-height) 1fr;
  min-height: 100vh;
}

/* ── Top Nav ───────────────────────────────────────────────── */

.topnav {
  grid-area: topnav;
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topnav-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
}

.topnav-wordmark {
  font-weight: 700;
  font-size: 18px;
  color: var(--text-heading);
  text-decoration: none;
  white-space: nowrap;
  letter-spacing: -0.02em;
}

.topnav-wordmark span {
  color: var(--accent-light);
}

.topnav-search {
  flex: 1;
  max-width: 400px;
  margin: 0 auto;
  position: relative;
}

.topnav-search input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.topnav-search input::placeholder {
  color: var(--text-muted);
}

.topnav-search input:focus {
  border-color: var(--accent);
}

.topnav-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color 0.15s, background 0.15s;
  font-size: 18px;
  line-height: 1;
}

.theme-toggle:hover {
  color: var(--text);
  background: var(--surface-2);
}

.topnav-site-link {
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.15s;
}

.topnav-site-link:hover {
  color: var(--accent-light);
}

.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 6px;
  border-radius: 6px;
  font-size: 22px;
  line-height: 1;
}

/* ── Left Sidebar ──────────────────────────────────────────── */

.sidebar {
  grid-area: sidebar;
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: sticky;
  top: var(--topnav-height);
  height: calc(100vh - var(--topnav-height));
  overflow-y: auto;
  padding: 20px 0 40px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar::-webkit-scrollbar {
  width: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.nav-group {
  margin-bottom: 8px;
}

.nav-group-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 12px 20px 4px;
}

.nav-link {
  display: block;
  padding: 7px 20px;
  font-size: 14px;
  color: var(--text);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-link:hover {
  background: var(--surface-2);
  color: var(--accent-light);
}

.nav-link.active {
  border-left-color: var(--accent);
  background: var(--surface-2);
  color: var(--accent-light);
  font-weight: 500;
}

/* ── Main Content ──────────────────────────────────────────── */

.main-content {
  grid-area: main;
  padding: 48px 48px 80px;
  min-width: 0;
}

.content-body {
  max-width: var(--content-max);
  margin: 0 auto;
}

/* ── Right TOC ─────────────────────────────────────────────── */

.toc {
  grid-area: toc;
  width: var(--toc-width);
  padding: 32px 20px 40px 12px;
  position: sticky;
  top: var(--topnav-height);
  height: calc(100vh - var(--topnav-height));
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.toc-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.toc-list {
  list-style: none;
}

.toc-item {
  margin: 0;
}

.toc-item a {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  padding: 4px 8px;
  border-left: 2px solid transparent;
  border-radius: 0 4px 4px 0;
  transition: color 0.12s, border-color 0.12s;
  line-height: 1.4;
}

.toc-item a:hover {
  color: var(--text);
}

.toc-item.active a {
  color: var(--accent-light);
  border-left-color: var(--accent);
  font-weight: 500;
}

.toc-item.toc-h3 a {
  padding-left: 20px;
  font-size: 12px;
}

/* ── Typography ────────────────────────────────────────────── */

.content-body h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-heading);
  line-height: 1.3;
  margin-bottom: 8px;
}

.content-body .page-subtitle {
  font-size: 16px;
  color: var(--text-muted);
  margin-bottom: 40px;
}

.content-body h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent-light);
  line-height: 1.4;
  margin-top: 48px;
  margin-bottom: 16px;
  scroll-margin-top: calc(var(--topnav-height) + 16px);
}

.content-body h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-heading);
  line-height: 1.4;
  margin-top: 32px;
  margin-bottom: 12px;
  scroll-margin-top: calc(var(--topnav-height) + 16px);
}

.content-body p {
  margin-bottom: 16px;
  color: var(--text);
}

.content-body ul,
.content-body ol {
  padding-left: 24px;
  margin-bottom: 16px;
}

.content-body li {
  margin-bottom: 6px;
}

.content-body a {
  color: var(--accent-light);
  text-decoration: none;
}

.content-body a:hover {
  text-decoration: underline;
}

.content-body code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  color: var(--accent-light);
}

.content-body pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  overflow-x: auto;
  margin-bottom: 20px;
}

.content-body pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  color: var(--text);
}

/* ── Callout ───────────────────────────────────────────────── */

.callout {
  background: var(--callout-bg);
  border-left: 3px solid var(--callout-border);
  border-radius: 0 8px 8px 0;
  padding: 14px 18px;
  margin: 24px 0;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
}

.callout strong {
  color: var(--text-heading);
}

/* ── Tables ────────────────────────────────────────────────── */

.content-body table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 24px;
  font-size: 15px;
}

.content-body th {
  background: var(--table-header);
  color: #ffffff;
  font-weight: 600;
  padding: 10px 14px;
  text-align: left;
  font-size: 13px;
  letter-spacing: 0.03em;
}

.content-body td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.content-body tr:nth-child(even) td {
  background: var(--table-row-alt);
}

.content-body th:first-child {
  border-radius: 6px 0 0 0;
}

.content-body th:last-child {
  border-radius: 0 6px 0 0;
}

/* ── Images & Figures ──────────────────────────────────────── */

figure {
  margin: 32px 0;
}

figure img {
  display: block;
  border-radius: 8px;
  border: 1px solid var(--border);
  max-width: 100%;
  height: auto;
}

figcaption {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 8px;
  line-height: 1.5;
}

/* Lightbox-eligible images */
figure.lightbox-fig {
  position: relative;
  cursor: pointer;
}

figure.lightbox-fig img {
  transition: box-shadow 0.15s;
}

figure.lightbox-fig:hover img {
  box-shadow: 0 0 0 2px var(--accent);
}

/* Magnifier icon for full-page shots */
figure.lightbox-fig.full-page::after {
  content: '⊕';
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}

figure.lightbox-fig.full-page:hover::after {
  opacity: 1;
}

/* Image size variants */
.img-small {
  max-width: 300px;
}

.img-medium {
  max-width: 480px;
}

.img-modal {
  max-width: 560px;
}

.img-large {
  max-width: 680px;
}

/* Screenshot Placeholder */
.screenshot-placeholder {
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: 8px;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  margin: 32px 0;
  padding: 24px;
}

.screenshot-placeholder .placeholder-icon {
  font-size: 32px;
  color: var(--text-muted);
  opacity: 0.6;
}

.screenshot-placeholder .placeholder-caption {
  font-size: 14px;
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
}

/* ── Lightbox ──────────────────────────────────────────────── */

#lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--overlay);
  align-items: center;
  justify-content: center;
}

#lightbox.open {
  display: flex;
}

#lightbox img {
  max-width: 75vw;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
}

/* ── Search Dropdown ───────────────────────────────────────── */

.search-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  z-index: 200;
  overflow: hidden;
  max-height: 420px;
  overflow-y: auto;
}

.search-dropdown.open {
  display: block;
}

.search-result {
  display: block;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.1s;
}

.search-result:last-child {
  border-bottom: none;
}

.search-result:hover,
.search-result.focused {
  background: var(--surface-2);
}

.search-result-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-heading);
  margin-bottom: 2px;
}

.search-result-section {
  font-size: 12px;
  color: var(--accent-light);
  margin-bottom: 4px;
}

.search-result-excerpt {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.search-result-excerpt mark {
  background: none;
  color: var(--accent-light);
  font-weight: 600;
}

.search-empty {
  padding: 16px;
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
}

.search-empty a {
  color: var(--accent-light);
}

/* ── Horizontal Rule ───────────────────────────────────────── */

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

/* ── Page Header ───────────────────────────────────────────── */

.page-header {
  margin-bottom: 40px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.page-header .breadcrumb {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.page-header .breadcrumb a {
  color: var(--text-muted);
  text-decoration: none;
}

.page-header .breadcrumb a:hover {
  color: var(--accent-light);
}

/* ── Blog ──────────────────────────────────────────────────── */

.blog-post-list {
  list-style: none;
  padding: 0;
}

.blog-post-item {
  padding: 24px 0;
  border-bottom: 1px solid var(--border);
}

.blog-post-item:first-child {
  padding-top: 0;
}

.blog-post-item h2 {
  font-size: 20px;
  margin-top: 0;
  margin-bottom: 6px;
}

.blog-post-item h2 a {
  color: var(--text-heading);
  text-decoration: none;
  transition: color 0.12s;
}

.blog-post-item h2 a:hover {
  color: var(--accent-light);
}

.blog-post-meta {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.blog-post-desc {
  font-size: 15px;
  color: var(--text);
  margin: 0;
}

.coming-soon-badge {
  display: inline-block;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  padding: 3px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  vertical-align: middle;
  margin-left: 10px;
}

/* ── Sidebar overlay on mobile ─────────────────────────────── */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 49;
}

/* ── Responsive ────────────────────────────────────────────── */

@media (max-width: 1280px) {
  .layout {
    grid-template-areas:
      "topnav topnav"
      "sidebar main";
    grid-template-columns: var(--sidebar-width) 1fr;
  }

  .toc {
    display: none;
  }
}

@media (max-width: 768px) {
  .layout {
    grid-template-areas:
      "topnav"
      "main";
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: var(--topnav-height);
    height: calc(100vh - var(--topnav-height));
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.open {
    display: block;
  }

  .hamburger {
    display: flex;
    align-items: center;
  }

  .topnav-search {
    max-width: none;
  }

  .main-content {
    padding: 24px 20px 60px;
  }

  .topnav-wordmark span {
    display: none;
  }
}

@media (max-width: 480px) {
  .topnav {
    padding: 0 16px;
    gap: 10px;
  }

  .topnav-site-link {
    display: none;
  }
}
