/**
 * Tech documentation layout — scoped under .tech-docs
 * Small type, sidebar TOC, callouts, tables (Stripe/Vercel-style reference pages)
 */

.tech-docs {
  --td-bg: #fafafa;
  --td-surface: #ffffff;
  --td-border: #e5e7eb;
  --td-border-strong: #d1d5db;
  --td-text: #111827;
  --td-muted: #6b7280;
  --td-faint: #9ca3af;
  --td-accent: #059669;
  --td-accent-soft: rgba(5, 150, 105, 0.08);
  --td-code-bg: #f3f4f6;
  --td-code-border: #e5e7eb;
  --td-fs: 0.95rem;
  --td-fs-xs: 0.8rem;
  --td-fs-sm: 0.875rem;
  --td-leading: 1.7;
  --td-radius: 6px;
  --td-sidebar-w: 16rem;
  --td-max-prose: 46rem;
  font-family: "Montserrat", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: var(--td-fs);
  line-height: var(--td-leading);
  color: var(--td-text);
  background: var(--td-bg);
  /* body is flex column + overflow-x:hidden (header.css); min-width:0 lets this shrink so wide TOC does not clip text */
  min-width: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.tech-docs a.td-link {
  color: var(--td-accent);
  text-decoration: none;
  font-weight: 500;
}
.tech-docs a.td-link:hover {
  text-decoration: underline;
}

.tech-docs .td-shell {
  max-width: 72rem;
  margin: 0 auto;
  padding: 0 1.25rem 3rem;
  display: grid;
  /* minmax(0,1fr) — plain 1fr uses min=auto and grows with horizontal TOC intrinsic width → right-edge clip on mobile */
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

@media (min-width: 1024px) {
  .tech-docs .td-shell {
    grid-template-columns: var(--td-sidebar-w) minmax(0, 1fr);
    gap: 2.5rem;
    align-items: start;
    padding: 0 2rem 4rem;
  }
}

.tech-docs .td-sidebar {
  position: sticky;
  top: 4.5rem;
  max-height: calc(100vh - 5rem);
  overflow-y: auto;
  padding: 0.75rem 0 1rem;
  border-bottom: 1px solid var(--td-border);
  margin-bottom: 1.25rem;
}

@media (min-width: 1024px) {
  .tech-docs .td-sidebar {
    border-bottom: none;
    padding: 0.5rem 0;
    margin-bottom: 0;
  }
}

/* Mobile / tablet: TOC as horizontal chips — avoids tall sidebar + scroll trap */
@media (max-width: 1023px) {
  .tech-docs .td-shell {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }

  .tech-docs .td-sidebar {
    position: relative;
    top: auto;
    max-height: none;
    overflow: visible;
    padding: 0.35rem 0 0.75rem;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--td-border);
    min-width: 0;
    max-width: 100%;
  }

  .tech-docs .td-sidebar-meta {
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
  }

  .tech-docs .td-sidebar-label {
    margin-bottom: 0.35rem;
  }

  .tech-docs .td-toc {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 0.4rem;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    padding: 0.2rem 0 0.45rem;
    margin-left: -0.35rem;
    margin-right: -0.35rem;
    padding-left: 0.35rem;
    padding-right: 0.35rem;
    scrollbar-width: thin;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .tech-docs .td-toc::-webkit-scrollbar {
    height: 5px;
  }
  .tech-docs .td-toc::-webkit-scrollbar-thumb {
    background: var(--td-border-strong);
    border-radius: 999px;
  }

  .tech-docs .td-toc li {
    flex: 0 0 auto;
  }

  .tech-docs .td-toc a {
    display: inline-flex;
    align-items: center;
    min-height: 2.5rem;
    margin-left: 0;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--td-border);
    background: var(--td-surface);
    font-size: var(--td-fs-xs);
    font-weight: 500;
    white-space: nowrap;
    border-left-width: 1px;
    border-left-style: solid;
    border-left-color: var(--td-border);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  }

  .tech-docs .td-toc a:hover {
    background: #f9fafb;
  }

  .tech-docs .td-toc a.active {
    border-color: var(--td-accent);
    background: var(--td-accent-soft);
    color: var(--td-accent);
    font-weight: 600;
    border-left-color: var(--td-accent);
  }

  .tech-docs .td-toc-sub {
    display: none;
  }

  .tech-docs.tech-docs--dense .td-sidebar {
    margin-bottom: 0.65rem;
    padding-bottom: 0.5rem;
  }
}

/* Sidebar metadata (product, date) — above TOC like Stripe/Vercel docs */
.tech-docs .td-sidebar-meta {
  margin-bottom: 1rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--td-border);
}
.tech-docs .td-sidebar-meta-primary {
  margin: 0 0 0.35rem;
  font-size: var(--td-fs-xs);
  font-weight: 600;
  color: var(--td-muted);
  letter-spacing: 0.01em;
  line-height: 1.35;
}
.tech-docs .td-sidebar-meta-secondary {
  margin: 0;
  font-size: var(--td-fs-xs);
  font-family: "Montserrat", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--td-faint);
  letter-spacing: 0.02em;
}
.tech-docs .td-sidebar-meta-line {
  display: block;
}

.tech-docs .td-sidebar-label {
  font-size: var(--td-fs-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--td-muted);
  margin-bottom: 0.65rem;
}

.tech-docs .td-toc {
  list-style: none;
  margin: 0;
  padding: 0;
}
.tech-docs .td-toc li {
  margin: 0;
}
.tech-docs .td-toc a {
  display: block;
  padding: 0.28rem 0.5rem;
  margin-left: -0.5rem;
  border-radius: 4px;
  font-size: var(--td-fs-sm);
  color: var(--td-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
}
.tech-docs .td-toc a:hover {
  color: var(--td-text);
  background: rgba(0, 0, 0, 0.03);
}
.tech-docs .td-toc a.active {
  color: var(--td-accent);
  border-left-color: var(--td-accent);
  font-weight: 600;
}
.tech-docs .td-toc-sub {
  list-style: none;
  margin: 0 0 0.35rem 0.65rem;
  padding: 0;
}
.tech-docs .td-toc-sub a {
  font-size: var(--td-fs-xs);
  padding: 0.2rem 0.45rem;
}

.tech-docs .td-main {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.tech-docs .td-hero {
  padding: 1.75rem 0 1.5rem;
  border-bottom: 1px solid var(--td-border);
  margin-bottom: 1.75rem;
}

.tech-docs .td-breadcrumb {
  font-size: var(--td-fs-xs);
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  color: var(--td-faint);
  letter-spacing: 0.02em;
  margin-bottom: 0.5rem;
}

.tech-docs .td-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--td-text);
  margin: 0 0 0.5rem;
  line-height: 1.25;
}

.tech-docs .td-lead {
  font-size: var(--td-fs);
  color: var(--td-muted);
  margin: 0;
  max-width: var(--td-max-prose);
}

.tech-docs .td-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  margin-top: 1rem;
  font-size: var(--td-fs-xs);
  color: var(--td-muted);
}
.tech-docs .td-meta span {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

.tech-docs .td-section {
  scroll-margin-top: 5rem;
  margin-bottom: 2.25rem;
  min-width: 0;
  max-width: 100%;
}

.tech-docs .td-section:last-child {
  margin-bottom: 0;
}

.tech-docs .td-h2 {
  font-size: 1.06rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--td-text);
  margin: 0 0 0.5rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--td-border);
}

.tech-docs .td-h3 {
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--td-text);
  margin: 0.95rem 0 0.4rem;
}

.tech-docs .td-h3:first-child {
  margin-top: 0;
}

.tech-docs .td-p {
  margin: 0 0 0.75rem;
  color: var(--td-text);
  max-width: var(--td-max-prose);
}

.tech-docs .td-p:last-child {
  margin-bottom: 0;
}

.tech-docs .td-ul,
.tech-docs .td-ol {
  margin: 0 0 0.85rem;
  padding-left: 1.25rem;
  max-width: var(--td-max-prose);
}
.tech-docs .td-ul li,
.tech-docs .td-ol li {
  margin-bottom: 0.35rem;
}
.tech-docs .td-ul.td-tight li,
.tech-docs .td-ol.td-tight li {
  margin-bottom: 0.2rem;
}

.tech-docs .td-kbd {
  display: inline-block;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: var(--td-fs-xs);
  padding: 0.1rem 0.35rem;
  background: var(--td-code-bg);
  border: 1px solid var(--td-code-border);
  border-radius: 3px;
  color: var(--td-text);
}

.tech-docs .td-code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.76em;
  padding: 0.12em 0.35em;
  background: var(--td-code-bg);
  border: 1px solid var(--td-code-border);
  border-radius: 3px;
  color: #1f2937;
}

/* UI label / pill (e.g. display state “Anonymous”) — GitHub-style */
.tech-docs .td-badge {
  display: inline-flex;
  align-items: center;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: var(--td-fs-xs);
  font-weight: 600;
  padding: 0.12rem 0.4rem;
  border-radius: 9999px;
  background: #f3f4f6;
  border: 1px solid var(--td-code-border);
  color: #4b5563;
  vertical-align: middle;
  white-space: nowrap;
}

/* Denser reference layout — more words per screen, docs-site feel */
.tech-docs.tech-docs--dense {
  --td-fs: 0.95rem;
  --td-fs-sm: 0.875rem;
  --td-fs-xs: 0.8rem;
  --td-leading: 1.68;
  --td-max-prose: 50rem;
}

.tech-docs.tech-docs--dense .td-hero {
  padding: 0.65rem 0 0.85rem;
  margin-bottom: 0.85rem;
}

.tech-docs.tech-docs--dense .td-title {
  font-size: 1.1875rem;
  margin-bottom: 0.35rem;
}

.tech-docs.tech-docs--dense .td-lead {
  font-size: 0.8125rem;
  line-height: 1.58;
}

.tech-docs.tech-docs--dense .td-doc-actions {
  margin-bottom: 0.65rem;
}

.tech-docs.tech-docs--dense .td-section {
  margin-bottom: 1.35rem;
  scroll-margin-top: 4.5rem;
}

.tech-docs.tech-docs--dense .td-h2 {
  font-size: 1.03rem;
  margin-bottom: 0.4rem;
  padding-bottom: 0.25rem;
}

.tech-docs.tech-docs--dense .td-h3 {
  font-size: 0.95rem;
  margin-top: 0.75rem;
  margin-bottom: 0.28rem;
}

.tech-docs.tech-docs--dense .td-p {
  margin-bottom: 0.6rem;
  color: #374151;
}

.tech-docs.tech-docs--dense .td-ul li,
.tech-docs.tech-docs--dense .td-ol li {
  margin-bottom: 0.2rem;
}

.tech-docs.tech-docs--dense .td-table {
  font-size: 0.75rem;
}

.tech-docs.tech-docs--dense .td-table th,
.tech-docs.tech-docs--dense .td-table td {
  padding: 0.35rem 0.5rem;
}

.tech-docs.tech-docs--dense .td-dl dd {
  font-size: 0.75rem;
}

.tech-docs.tech-docs--dense .td-footer {
  margin-top: 1.75rem;
  padding-top: 0.85rem;
}

.tech-docs.tech-docs--dense .td-callout p {
  font-size: 0.75rem;
}

.tech-docs .td-doc-actions {
  font-size: var(--td-fs-sm);
  margin-bottom: 0.75rem;
}

.tech-docs .td-doc-actions a {
  font-weight: 600;
}

.tech-docs .td-pre {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: var(--td-fs-xs);
  line-height: 1.55;
  background: #1e293b;
  color: #e2e8f0;
  padding: 0.85rem 1rem;
  border-radius: var(--td-radius);
  overflow-x: auto;
  margin: 0 0 0.85rem;
  max-width: 100%;
}

.tech-docs .td-callout {
  border: 1px solid var(--td-border);
  border-radius: var(--td-radius);
  padding: 0.75rem 0.9rem;
  margin: 0 0 0.75rem;
  background: var(--td-surface);
  max-width: var(--td-max-prose);
}
.tech-docs .td-callout:last-child {
  margin-bottom: 0;
}

.tech-docs .td-callout-label {
  font-size: var(--td-fs-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.tech-docs .td-callout--note {
  border-left: 3px solid #3b82f6;
  background: #eff6ff;
}
.tech-docs .td-callout--note .td-callout-label {
  color: #1d4ed8;
}

.tech-docs .td-callout--tip {
  border-left: 3px solid var(--td-accent);
  background: var(--td-accent-soft);
}
.tech-docs .td-callout--tip .td-callout-label {
  color: #047857;
}

.tech-docs .td-callout--warn {
  border-left: 3px solid #f59e0b;
  background: #fffbeb;
}
.tech-docs .td-callout--warn .td-callout-label {
  color: #b45309;
}

.tech-docs .td-callout--danger {
  border-left: 3px solid #dc2626;
  background: #fef2f2;
}
.tech-docs .td-callout--danger .td-callout-label {
  color: #b91c1c;
}

.tech-docs .td-callout p {
  margin: 0;
  font-size: var(--td-fs-sm);
  color: #374151;
  line-height: 1.6;
}

.tech-docs .td-callout p.td-callout-body {
  margin: 0;
}

.tech-docs .td-table-wrap {
  overflow-x: auto;
  margin: 0 0 0.85rem;
  border: 1px solid var(--td-border);
  border-radius: var(--td-radius);
  max-width: 100%;
}

.tech-docs .td-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--td-fs-sm);
}
.tech-docs .td-table th,
.tech-docs .td-table td {
  text-align: left;
  padding: 0.45rem 0.65rem;
  border-bottom: 1px solid var(--td-border);
  vertical-align: top;
}
.tech-docs .td-table th {
  font-size: var(--td-fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--td-muted);
  background: #f9fafb;
}
.tech-docs .td-table tr:last-child td {
  border-bottom: none;
}

.tech-docs .td-dl {
  margin: 0 0 0.85rem;
  max-width: var(--td-max-prose);
}
.tech-docs .td-dl dt {
  font-size: var(--td-fs-xs);
  font-weight: 600;
  color: var(--td-muted);
  margin-top: 0.65rem;
}
.tech-docs .td-dl dt:first-child {
  margin-top: 0;
}
.tech-docs .td-dl dd {
  margin: 0.15rem 0 0;
  font-size: var(--td-fs-sm);
  color: var(--td-text);
}

.tech-docs .td-footer {
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--td-border);
  font-size: var(--td-fs-xs);
  color: var(--td-faint);
}

.tech-docs .td-grid-2 {
  display: grid;
  gap: 0.75rem;
}
@media (min-width: 640px) {
  .tech-docs .td-grid-2 {
    grid-template-columns: 1fr 1fr;
  }
}

/* Flush under fixed site header (body normally has padding-top from includes/header.php) */
body.td-docs-flush-header {
  padding-top: 0 !important;
}
body.td-docs-flush-header .tech-docs.td-docs-header-clear {
  padding-top: 80px;
  box-sizing: border-box;
}
@media (max-width: 768px) {
  body.td-docs-flush-header .tech-docs.td-docs-header-clear {
    padding-top: 70px;
  }
}

/* Bottom inset so fixed customer-care FAB does not cover last lines on mobile */
@media (max-width: 1023px) {
  .tech-docs.tech-docs--fab-safe {
    padding-bottom: max(5.5rem, calc(4.5rem + env(safe-area-inset-bottom, 0px)));
  }
}

/* Anchor targets clear fixed header a bit more reliably on small screens */
@media (max-width: 768px) {
  .tech-docs.tech-docs--dense .td-section {
    scroll-margin-top: 5.75rem;
  }
}
