/* ============================================================================
   TechLapse NOVA Docs — layout & chrome only (components from techlapse-nova.css)
   ============================================================================ */

html.tl-dark,
body.tl-dark {
  background: var(--tl-cream);
  color: var(--tl-ink);
}

html {
  overflow-x: clip;
}

body.doc-nav-open {
  overflow: hidden;
}

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

.doc-app {
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  min-height: 100vh;
  min-height: 100dvh;
}

/* — Top bar — */
.doc-topbar {
  grid-area: topbar;
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "start search end";
  align-items: center;
  gap: var(--tl-space-3) var(--tl-space-4);
  padding: var(--tl-space-3) var(--tl-space-5);
  padding-left: max(var(--tl-space-5), env(safe-area-inset-left));
  padding-right: max(var(--tl-space-5), env(safe-area-inset-right));
  background: var(--tl-cream);
  border-bottom: var(--tl-border-bold);
}

.doc-topbar__start { grid-area: start; min-width: 0; }

.doc-topbar__search {
  grid-area: search;
  position: relative;
  min-width: 0;
  max-width: 360px;
  justify-self: center;
  width: 100%;
}

.doc-topbar__end {
  grid-area: end;
  display: flex;
  align-items: center;
  gap: var(--tl-space-2);
  flex-shrink: 0;
}

.doc-topbar__download-short { display: none; }

.doc-topbar__theme { white-space: nowrap; }

.doc-topbar__brand {
  display: inline-flex;
  align-items: center;
  gap: var(--tl-space-2);
  text-decoration: none;
  color: var(--tl-ink);
  font-family: var(--tl-font-display);
  font-weight: var(--tl-weight-bold);
  font-size: var(--tl-text-lg);
  letter-spacing: -0.01em;
}

.doc-topbar__brand:hover { color: var(--tl-primary-500); }

.doc-topbar__mark {
  width: 26px;
  height: 26px;
  background: var(--tl-primary-400);
  border: var(--tl-border);
  border-radius: var(--tl-radius-sm);
  flex: none;
}

/* .tl a overrides .tl-btn color on <a> tags — restore button foreground */
.tl a.tl-btn {
  text-decoration: none;
  color: var(--_fg);
}

.tl a.tl-btn:hover {
  color: var(--_fg);
}

.doc-search {
  width: 100%;
  font-family: var(--tl-font-body);
  font-size: var(--tl-text-sm);
  padding: 0.55rem 0.85rem;
  border: var(--tl-border);
  border-radius: var(--tl-radius-md);
  background: var(--tl-white);
  color: var(--tl-ink);
}

.doc-search:focus {
  outline: none;
  box-shadow: var(--tl-shadow-sm);
}

.doc-search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--tl-white);
  border: var(--tl-border-bold);
  border-radius: var(--tl-radius-md);
  box-shadow: var(--tl-shadow-md);
  max-height: 320px;
  overflow-y: auto;
  display: none;
  z-index: 50;
}

.doc-search-results.is-open { display: block; }

.doc-search-results a {
  display: block;
  padding: 0.55rem 0.85rem;
  text-decoration: none;
  color: var(--tl-ink);
  font-size: var(--tl-text-sm);
  border-bottom: var(--tl-bw) solid var(--tl-line);
}

.doc-search-results a:last-child { border-bottom: none; }

.doc-search-results a:hover,
.doc-search-results a:focus-visible {
  background: var(--tl-cream-2);
  outline: none;
}

.doc-search-results__meta {
  display: block;
  font-family: var(--tl-font-mono);
  font-size: var(--tl-text-xs);
  color: var(--tl-muted);
  margin-top: 2px;
}

.doc-search-results__empty {
  padding: var(--tl-space-4);
  font-size: var(--tl-text-sm);
  color: var(--tl-muted);
}

/* — Sidebar — */
.doc-sidebar {
  grid-area: sidebar;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--tl-cream-2);
  border-right: var(--tl-border-bold);
  padding: var(--tl-space-5);
  padding-left: max(var(--tl-space-5), env(safe-area-inset-left));
  -webkit-overflow-scrolling: touch;
}

.doc-sidebar__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--tl-space-2);
  margin-bottom: var(--tl-space-2);
}

.doc-sidebar__close { display: none; }

.doc-sidebar__version {
  margin: 0;
}

.doc-sidebar__group {
  font-family: var(--tl-font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--tl-muted);
  margin: var(--tl-space-5) 0 var(--tl-space-2);
}

.doc-sidebar__group:first-of-type { margin-top: var(--tl-space-4); }

.doc-sidebar nav a {
  display: block;
  padding: 0.55rem 0.65rem;
  margin-bottom: 2px;
  color: var(--tl-ink-2);
  text-decoration: none;
  font-weight: var(--tl-weight-medium);
  font-size: var(--tl-text-sm);
  border-radius: var(--tl-radius-sm);
  border: var(--tl-bw) solid transparent;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.doc-sidebar nav a:hover {
  background: var(--tl-white);
  border-color: var(--tl-ink);
}

.doc-sidebar nav a.is-active {
  background: var(--tl-primary-400);
  color: var(--tl-primary-ink);
  border-color: var(--tl-ink);
  box-shadow: var(--tl-shadow-sm);
}

/* — Main content — */
.doc-main {
  grid-area: main;
  padding: var(--tl-space-6) var(--tl-space-7) var(--tl-space-8);
  padding-right: max(var(--tl-space-7), env(safe-area-inset-right));
  max-width: 960px;
  min-width: 0;
  width: 100%;
}

.doc-page-header h1,
.doc-page-header .tl-display {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.doc-page-header p {
  max-width: 65ch;
}

.doc-footer {
  margin-top: var(--tl-space-7);
}

.doc-footer__text {
  margin: 0;
  text-align: center;
}

.doc-footer__heart {
  color: var(--tl-primary-500);
}

.doc-footer a {
  font-weight: var(--tl-weight-bold);
  color: var(--tl-ink);
  text-decoration: none;
  border-bottom: var(--tl-bw) solid var(--tl-primary-400);
}

.doc-footer a:hover {
  color: var(--tl-primary-500);
}

.doc-page-header { margin-bottom: var(--tl-space-6); }

.doc-section { margin-top: var(--tl-space-7); }

.doc-section h3 { margin-bottom: var(--tl-space-3); }

/* — Demo blocks — */
.demo {
  border: var(--tl-border);
  border-radius: var(--tl-radius-lg);
  background: var(--tl-white);
  overflow: hidden;
  margin-top: var(--tl-space-4);
}

.demo__stage {
  padding: var(--tl-space-6);
  display: flex;
  flex-wrap: wrap;
  gap: var(--tl-space-4);
  align-items: center;
}

.demo__stage--block { display: block; }

.demo__code {
  position: relative;
  border-top: var(--tl-border);
  background: var(--tl-ink);
}

.demo__code pre {
  margin: 0;
  padding: var(--tl-space-4) var(--tl-space-5);
  padding-top: 2.75rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.demo__code pre code {
  font-size: clamp(0.7rem, 2.5vw, 0.8125rem);
  white-space: pre;
  word-break: normal;
}

.demo__code pre[class*="language-"] { background: var(--tl-ink); }

.demo__copy {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
}

/* — Swatches — */
.swatch {
  width: 96px;
  min-width: 72px;
  flex: 1 1 72px;
  max-width: 120px;
  cursor: pointer;
}

.swatch__chip {
  height: 64px;
  border: var(--tl-border);
  border-radius: var(--tl-radius-md);
  transition: transform var(--tl-dur) var(--tl-ease);
}

.swatch:hover .swatch__chip { transform: translate(-2px, -2px); }

.swatch__label {
  font-family: var(--tl-font-mono);
  font-size: 11px;
  margin-top: 6px;
  color: var(--tl-muted);
}

.swatch__hex {
  font-family: var(--tl-font-mono);
  font-size: 10px;
  color: var(--tl-line);
}

/* — Type scale rows — */
.type-row {
  display: flex;
  align-items: baseline;
  gap: var(--tl-space-4);
  padding: var(--tl-space-3) 0;
  border-bottom: var(--tl-bw) solid var(--tl-line);
}

.type-row:last-child { border-bottom: none; }

/* — Props table wrapper — */
.doc-props {
  margin-top: var(--tl-space-5);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.doc-props .tl-table {
  font-size: var(--tl-text-sm);
  min-width: 480px;
}

.doc-props code {
  font-size: var(--tl-text-xs);
  word-break: break-word;
}

/* Scrollable demo tables & overflow components */
.demo__stage:has(.tl-table) {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  display: block;
}

.demo__stage .tl-table {
  min-width: 480px;
}

.demo__stage .tl-tabs,
.demo__stage .tl-btn-group,
.demo__stage .tl-nav {
  max-width: 100%;
}

.demo__stage .tl-tabs {
  display: flex;
  flex-wrap: wrap;
}

.demo__scroll-x {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

/* — A11y notes — */
.doc-a11y { margin-top: var(--tl-space-5); }

/* — Theme playground — */
.playground {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--tl-space-5);
  margin-top: var(--tl-space-5);
}

.playground__controls {
  padding: var(--tl-space-5);
  background: var(--tl-white);
  border: var(--tl-border);
  border-radius: var(--tl-radius-lg);
}

.playground__preview {
  padding: var(--tl-space-6);
  background: var(--tl-cream-2);
  border: var(--tl-border);
  border-radius: var(--tl-radius-lg);
  box-shadow: var(--tl-shadow-md);
  display: flex;
  flex-direction: column;
  gap: var(--tl-space-4);
  align-items: flex-start;
}

.playground__preview-inner {
  padding: var(--tl-space-5);
  background: var(--tl-white);
  border: var(--tl-border);
  border-radius: var(--tl-radius-lg);
  width: 100%;
}

.playground__output { margin-top: var(--tl-space-6); }

.playground-control {
  margin-bottom: var(--tl-space-4);
}

.playground-control label {
  display: flex;
  justify-content: space-between;
  font-size: var(--tl-text-sm);
  font-weight: var(--tl-weight-bold);
  margin-bottom: var(--tl-space-2);
}

.playground-control input[type="range"] {
  width: 100%;
  accent-color: var(--tl-primary-400);
}

.playground-control input[type="color"] {
  width: 100%;
  height: 40px;
  border: var(--tl-border);
  border-radius: var(--tl-radius-md);
  cursor: pointer;
  padding: 2px;
  background: var(--tl-white);
}

/* — Mobile overlay — */
.doc-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(26, 20, 16, 0.45);
  z-index: 35;
}

.doc-overlay.is-open { display: block; }

.doc-menu-btn { display: none; }

/* — Prism overrides for NOVA palette — */
.demo__code .token.tag,
.demo__code .token.selector { color: #ff9c86; }
.demo__code .token.attr-name { color: #ffc1b2; }
.demo__code .token.attr-value,
.demo__code .token.string { color: #d7f5e6; }
.demo__code .token.punctuation { color: #a9997f; }
.demo__code .token.property { color: #ffb300; }
.demo__code .token.comment { color: #7c7163; }

/* — Responsive — */

/* Tablet */
@media (max-width: 900px) {
  .doc-app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "main";
  }

  .doc-topbar {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "start end"
      "search search";
    gap: var(--tl-space-3);
    padding: var(--tl-space-3) var(--tl-space-4);
    padding-left: max(var(--tl-space-4), env(safe-area-inset-left));
    padding-right: max(var(--tl-space-4), env(safe-area-inset-right));
  }

  .doc-topbar__search {
    max-width: none;
    justify-self: stretch;
  }

  .doc-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(300px, 88vw);
    z-index: 40;
    transform: translateX(-105%);
    transition: transform 0.2s var(--tl-ease);
    box-shadow: var(--tl-shadow-lg);
  }

  .doc-sidebar.is-open { transform: none; }

  .doc-sidebar__close { display: inline-flex; }

  .doc-menu-btn { display: inline-flex; }

  .doc-main {
    padding: var(--tl-space-5) var(--tl-space-4) var(--tl-space-7);
    max-width: none;
  }

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

  .doc-section { margin-top: var(--tl-space-6); }

  .demo__stage { padding: var(--tl-space-4); }

  .type-row {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--tl-space-1);
  }
}

/* Phone */
@media (max-width: 540px) {
  .doc-topbar__download-full { display: none; }

  .doc-topbar__download-short { display: inline; }

  .doc-topbar__theme {
    padding-inline: 0.65rem;
    font-size: var(--tl-text-xs);
  }

  .doc-topbar__brand {
    font-size: var(--tl-text-md);
  }

  .doc-topbar__mark {
    width: 22px;
    height: 22px;
  }

  .doc-page-header .tl-display {
    font-size: var(--tl-text-3xl);
  }

  .doc-main {
    padding: var(--tl-space-4) var(--tl-space-3) var(--tl-space-6);
  }

  .demo__stage {
    padding: var(--tl-space-3);
    gap: var(--tl-space-3);
  }

  .demo__code pre {
    padding: var(--tl-space-3);
    padding-top: 2.5rem;
  }

  .demo__copy {
    top: 6px;
    right: 6px;
  }

  .swatch {
    flex: 1 1 calc(33% - var(--tl-space-3));
    max-width: none;
  }

  .playground__controls,
  .playground__preview {
    padding: var(--tl-space-4);
  }

  .playground-control label {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--tl-space-1);
  }

  /* Full-width CTA buttons on home */
  .doc-main .tl-flex .tl-btn {
    flex: 1 1 100%;
  }

  .doc-footer {
    margin-top: var(--tl-space-5);
  }

  .doc-footer__text {
    font-size: var(--tl-text-xs);
    padding-inline: var(--tl-space-2);
  }
}

/* Very small screens */
@media (max-width: 360px) {
  .doc-topbar__end {
    gap: 4px;
  }

  .doc-topbar__end .tl-btn--sm {
    padding: 0.45rem 0.6rem;
    font-size: var(--tl-text-xs);
  }
}

@media (prefers-reduced-motion: reduce) {
  .doc-sidebar { transition: none; }
  .swatch:hover .swatch__chip { transform: none; }
}
