/* ──────────────────────────────────────────────────────────────
   CodeAppJS Docs  —  Microsoft Learn-inspired theme
   Light / Dark mode with Outfit font
   ────────────────────────────────────────────────────────────── */

/* ── Reset ── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; scroll-behavior: smooth; }

/* ── CSS Custom Properties ── */
:root {
  --bg: #fcfcfc;
  --bg-alt: #f5f5f5;
  --panel: #ffffff;
  --panel-soft: #f9f9f9;
  --text: #0f0f0f;
  --text-muted: #555555;
  --text-ghost: #6a6a6a;
  --text-faint: #e2e2e2;
  --line: #ebebeb;
  --line-light: #f5f5f5;
  --accent: #A0418D;
  --accent-soft: rgba(160,65,141,0.08);
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --success: #107c10;
  --font: 'Outfit', 'Segoe UI Variable Text', 'Segoe UI', system-ui, sans-serif;
  --pad-x: 2rem;
  --code-bg: #1e1e1e;
  --code-text: #d4d4d4;
  --radius: 8px;
}

[data-theme="dark"] {
  --bg: #0a0a0a;
  --bg-alt: #141414;
  --panel: #1a1a1a;
  --panel-soft: #1f1f1f;
  --text: #f0f0f0;
  --text-muted: #999;
  --text-ghost: #555;
  --text-faint: #222;
  --line: #2a2a2a;
  --line-light: #1f1f1f;
  --accent: #c76db5;
  --accent-soft: rgba(199,109,181,0.12);
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --code-bg: #0d0d0d;
  --code-text: #d4d4d4;
}

a { color: inherit; text-decoration: none; }
a, button, input, table, td, th, div, article, section, aside, header, main, span, pre {
  border-radius: 0;
}

html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s, color 0.3s;
}

/* ── Shell ── */
.shell { min-height: 100vh; }

/* ── App Bar ── */
.appBar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 100;
  transition: background 0.3s, border-color 0.3s;
}

.appBarLeft, .appBarRight {
  display: flex;
  gap: 12px;
  align-items: center;
}

.appBarLeft p {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.appLogo { height: 42px; }

.barButton {
  border: 1px solid var(--line);
  padding: 8px 14px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  border-radius: var(--radius);
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.barButton:hover { border-color: var(--text-muted); color: var(--text); }

.primaryBarButton {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}
.primaryBarButton:hover { opacity: 0.9; }

/* ── Theme Toggle ── */
.theme-toggle {
  background: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 10px;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text-muted);
  transition: border-color 0.2s, color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.theme-toggle:hover { border-color: var(--text); color: var(--text); }

/* ── App Body Grid ── */
.appBody {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: calc(100vh - 60px);
}

/* ── Sidebar ── */
.siteMap {
  padding: 20px 16px;
  border-right: 1px solid var(--line);
  background: var(--bg-alt);
  transition: background 0.3s, border-color 0.3s;
  overflow-y: auto;
  max-height: calc(100vh - 60px);
  position: sticky;
  top: 60px;
}

.groupLabel, .sectionLabel {
  margin: 0;
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.siteMap nav, .entityList {
  display: grid;
  gap: 2px;
  margin-top: 10px;
}

.sectionNavButton, .entityButton {
  border: 0;
  padding: 9px 12px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}

.sectionNavButton.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.sectionNavButton:hover { background: var(--accent-soft); }

.entityButton.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.entityButton:hover { background: var(--accent-soft); }

.siteMapGroup.is-hidden { display: none; }
.secondLabel { margin-top: 20px; }

/* ── Work Area ── */
.workArea {
  padding: 24px 32px;
  max-width: 1200px;
}

.workArea > .docSection {
  display: none;
  min-height: calc(100vh - 150px);
}
.workArea > .docSection.is-active { display: block; }
.workArea > .workspaceHero.docSection.is-active { display: grid; }

/* ── Breadcrumb ── */
.breadcrumbRow {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--text-muted);
  font-size: 0.82rem;
  margin-bottom: 4px;
}

/* ── Hero ── */
.workspaceHero {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 20px;
  margin-top: 14px;
}

.workspaceHero article,
.recordShell,
.gridSection,
.fieldCard,
.heroStats > div {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  min-width: 0;
  border-radius: var(--radius);
  transition: background 0.3s, border-color 0.3s;
}

.workspaceHero article:first-child,
.recordShell,
.gridSection { padding: 24px; }

.workspaceHero h1 {
  margin: 10px 0;
  font-size: clamp(1.8rem, 3.5vw, 2.6rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.workspaceHero p:last-child,
.heroStats span,
.fieldRow span,
.fieldCard p,
.fieldCard li,
.dataGrid td {
  color: var(--text-muted);
  line-height: 1.7;
}

.heroStats { display: grid; gap: 12px; }
.heroStats > div { display: grid; gap: 10px; padding: 18px; }
.heroStatRows { display: grid; border-top: 1px solid var(--line); }
.heroStatRow { padding: 10px 0; color: var(--text-muted); }
.heroStatRow + .heroStatRow { border-top: 1px solid var(--line); }
.heroStatRow a { transition: color 0.2s; }
.heroStatRow a:hover { color: var(--accent); }

.heroStats .fieldRow {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

/* ── Records & Sections ── */
.recordShell { margin-top: 20px; }
.docSection.recordShell, .docSection.gridSection { margin-top: 14px; }

.recordHeader, .gridHeader {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.recordHeader h2, .gridHeader h3 {
  margin: 8px 0 0;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.recordActions, .recordTabs { display: flex; gap: 8px; flex-wrap: wrap; }
.pageActions { align-items: center; }

.recordTabs {
  margin-top: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.recordTab {
  border: 1px solid var(--line);
  padding: 8px 14px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.recordTab:hover { border-color: var(--accent); color: var(--accent); }
.recordTab.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

.recordView { display: none; margin-top: 16px; }
.recordView.is-active { display: block; }

/* ── Field Grid / Columns ── */
.fieldGrid { display: grid; gap: 14px; grid-template-columns: 1fr 0.8fr; }
.twoByOne { grid-template-columns: 1.2fr 0.8fr; }

.entityPanel { display: none; }
.entityPanel.is-active { display: block; }

.fieldCard { padding: 20px; }

.fieldRow {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.fieldRow:last-child { border-bottom: 0; }

.helperCard { background: var(--panel-soft); }

.detailColumns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

/* ── Code Blocks ── */
.commandCard pre {
  overflow-x: auto;
  margin: 12px 0 0;
  padding: 16px;
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: 6px;
  font-size: 0.88rem;
  line-height: 1.6;
}

.jsonSnippet {
  overflow-x: auto;
  margin-top: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  background: var(--code-bg);
  color: var(--code-text);
  font-family: Consolas, 'Courier New', monospace;
  font-size: 0.88rem;
  line-height: 1.6;
  white-space: pre-wrap;
  border-radius: 6px;
}

code {
  font-family: Consolas, 'Courier New', monospace;
  font-size: 0.9em;
}

/* Inline code in text */
td code, li code, p code {
  background: var(--bg-alt);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  border: 1px solid var(--line);
}

/* ── Data Grid ── */
.gridSection { margin-top: 16px; }

.dataGrid {
  width: 100%;
  border-collapse: collapse;
  margin-top: 14px;
}

.compactGrid, .fieldCard, .gridSection, .recordShell,
.detailColumns, .fieldGrid, .tipGrid { min-width: 0; }

.dataGrid th, .dataGrid td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}
.dataGrid th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ── Chips & Tags ── */
.statusChip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  background: var(--bg-alt);
  color: var(--text);
  font-size: 0.85rem;
  border-radius: 4px;
}
.successChip { background: #e7f6e7; color: var(--success); }

.metaTag {
  border: 1px solid var(--line);
  padding: 6px 12px;
  background: var(--panel);
  color: var(--text-muted);
  font-size: 0.78rem;
  border-radius: 4px;
  font-weight: 500;
}

/* ── Nested sections ── */
.compactGrid { margin-top: 10px; }
.nestedSection { margin-top: 16px; }
.nestedColumns { margin-top: 14px; }

.actionList { margin: 10px 0 0; padding-left: 18px; }
.denseList { columns: 2; column-gap: 22px; }
.connectorTabs { margin-bottom: 0; }
.connectionEntity { margin-top: 16px; }

.publicFunctionsSection .sectionLabel {
  margin-bottom: 0;
}

.functionSearchBar {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.functionSearchInput {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  border-radius: 6px;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.functionSearchInput:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.functionCatalog {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.functionCard {
  border: 1px solid var(--line);
  background: var(--panel-soft);
  padding: 16px;
  border-radius: var(--radius);
  display: grid;
  gap: 12px;
}

.functionCard.is-hidden {
  display: none;
}

.functionSignature {
  margin: 0;
}

.functionSignature code {
  display: inline-block;
  background: var(--accent-soft);
  border: 1px solid transparent;
  color: var(--accent);
  padding: 8px 10px;
  font-size: 0.86rem;
}

.functionExampleBlock {
  overflow-x: auto;
  margin: 0;
  padding: 16px;
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: 6px;
  font-size: 0.88rem;
  line-height: 1.6;
}

.functionNoResults {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.functionNoResults.is-hidden {
  display: none;
}

/* ── Tip Grid ── */
.tipGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.tipCard {
  position: relative;
  padding-left: 16px;
}
.tipCard::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent);
  border-radius: 3px;
}

.fieldCard ul { margin: 10px 0 0; padding-left: 18px; }

.fieldCard li, .fieldCard td, .fieldCard p, .fieldCard ul, .fieldCard code,
.workspaceHero p, .heroStats span, .dataGrid td {
  overflow-wrap: anywhere;
}

/* ── Image Placeholders ── */
.img-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--bg-alt);
  color: var(--text-ghost);
  font-size: 0.82rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 16px 0;
  transition: background 0.3s, border-color 0.3s;
}

.screenshot {
  max-width: 100%;
  border-radius: var(--radius);
}


/* ── Blog Section ── */
.blogGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.blogGrid.is-hidden,
.blogArticleShell.is-hidden {
  display: none;
}

.blogCard {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 24px;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.blogCard:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}
.blogCard-meta {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-ghost);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}
.blogCard-tag {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
}
.blogCard h4 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.3;
}
.blogCard p {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.6;
  flex: 1;
}
.blogCard-link {
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: gap 0.2s;
}
.blogCard:hover .blogCard-link { gap: 8px; }
.markdownTrigger { cursor: pointer; }

.blogArticleShell {
  margin-top: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 28px;
}

.blogArticleHeader {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.blogArticleStatus {
  margin: 0 0 18px;
  color: var(--text-muted);
  line-height: 1.6;
}

.blogArticleStatus.is-error {
  color: #b42318;
}

.blogArticleBody {
  color: var(--text);
  line-height: 1.75;
}

.blogArticleBody > :first-child {
  margin-top: 0;
}

.blogArticleBody h1,
.blogArticleBody h2,
.blogArticleBody h3,
.blogArticleBody h4 {
  margin: 1.8rem 0 0.8rem;
  line-height: 1.2;
}

.blogArticleBody p,
.blogArticleBody ul,
.blogArticleBody ol,
.blogArticleBody table,
.blogArticleBody pre,
.blogArticleBody hr {
  margin: 1rem 0;
}

.blogArticleBody ul,
.blogArticleBody ol {
  padding-left: 1.4rem;
}

.blogArticleBody li + li {
  margin-top: 0.45rem;
}

.blogArticleBody a {
  color: var(--accent);
}

.blogArticleBody img {
  display: block;
  max-width: 100%;
  border-radius: 14px;
}

.blogArticleBody pre {
  overflow-x: auto;
  padding: 18px;
  border-radius: 18px;
  background: var(--bg-alt);
  border: 1px solid var(--line);
}

.blogArticleBody code {
  font-family: Consolas, 'Courier New', monospace;
  font-size: 0.95em;
}

.blogArticleBody :not(pre) > code {
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
}

.blogArticleBody table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--line);
}

.blogArticleBody th,
.blogArticleBody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.blogArticleBody th {
  background: var(--bg-alt);
}

.blogArticleBody hr {
  border: 0;
  border-top: 1px solid var(--line);
}

/* ── Function Signature Styling ── */
.fnSig {
  font-family: Consolas, 'Courier New', monospace;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
}

/* ── Connector Section Header ── */
.connectorSection h4 {
  font-size: 1rem;
  font-weight: 700;
  margin: 20px 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-ghost);
  font-size: 0.78rem;
}

/* ── Footer ── */
.footer-bottom {
  padding: 2rem 32px;
  font-size: 0.75rem;
  color: var(--text-ghost);
  text-align: right;
  width: 100%;
  border-top: 1px solid var(--line);
  transition: color 0.3s, border-color 0.3s;
}

/* ── Responsive ── */
@media (max-width: 1080px) {
  .appBody, .workspaceHero, .fieldGrid, .detailColumns, .tipGrid, .twoByOne, .blogGrid {
    grid-template-columns: 1fr;
  }
  .denseList { columns: 1; }
}

@media (max-width: 760px) {
  .appBar, .appBarLeft, .appBarRight, .recordHeader, .gridHeader, .blogArticleHeader {
    flex-direction: column;
    align-items: flex-start;
  }

  .appBody { grid-template-columns: 1fr; }

  .siteMap {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    position: static;
    max-height: none;
  }

  .workArea { padding: 16px; }

  .recordShell, .gridSection, .fieldCard, .workspaceHero article, .heroStats > div {
    padding-left: 14px;
    padding-right: 14px;
  }

  .recordActions, .recordTabs, .pageActions, .appBarRight { width: 100%; }
  .barButton, .recordTab { width: 100%; }

  .dataGrid, .dataGrid thead, .dataGrid tbody, .dataGrid tr, .dataGrid th, .dataGrid td {
    display: block;
    width: 100%;
  }
  .dataGrid { margin-top: 12px; }
  .dataGrid thead {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
  }
  .dataGrid tr {
    margin-bottom: 12px;
    border: 1px solid var(--line);
    background: var(--panel-soft);
    border-radius: var(--radius);
  }
  .dataGrid tr:last-child { margin-bottom: 0; }
  .dataGrid td, .dataGrid th {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
  }
  .dataGrid td:first-child { font-weight: 600; color: var(--text); }
  .dataGrid td:last-child { border-bottom: 0; }

  .commandCard pre, .jsonSnippet { max-width: 100%; }
}