/* Documentation-specific styles. Scoped under .doc-page / .doc-main
   so global site rules in screen.css are unaffected. */

:root {
    --doc-text: #1f2937;
    --doc-muted: #667085;
    --doc-border: #e4e7ec;
    --doc-border-strong: #d0d5dd;
    --doc-bg-alt: #f7f8fa;
    --doc-accent: #4182e4;
    --doc-accent-soft: #e8f0fe;
    --doc-link: #00a4ca;
    --doc-note-bg: #eef6fb;
    --doc-note-border: #8ecae6;
    --doc-tip-bg: #f1faf1;
    --doc-tip-border: #7cc98a;
    --doc-warn-bg: #fff7e8;
    --doc-warn-border: #f2b84b;
}

.doc-page {
    padding: 56px 0 100px 0;
    background: #fff;
}

.doc-shell {
    max-width: 1240px;
    margin: 0 auto;
    padding: 0 24px;
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 56px;
    color: var(--doc-text);
}

/* ---------- Sidebar ---------- */

.doc-sidebar-inner {
    position: sticky;
    top: 24px;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    padding: 4px 14px 24px 0;
    border-right: 1px solid var(--doc-border);
}

.doc-sidebar-eyebrow {
    text-transform: uppercase;
    letter-spacing: .08em;
    font-size: .72rem;
    font-weight: 700;
    color: var(--doc-accent);
    margin: 0 0 8px 0;
}

.doc-sidebar-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0 0 20px 0;
    color: var(--doc-text);
}

/* Reset site-wide <nav> styles from screen.css that assume a site header nav:
   - nav { position: absolute; top: 13px; right: 0; text-align: right; ... }
   - nav a { display: none; color: rgba(255,255,255,.8); padding: 20px 10px; ... }
   All defensively neutralized inside the documentation sidebar. */
.doc-sidebar nav {
    position: static;
    top: auto;
    right: auto;
    padding: 0;
    width: auto;
    text-align: left;
    text-transform: none;
    font-size: 1rem;
}

.doc-sidebar nav a {
    margin: 0;
    border-bottom: none;
}

.doc-sidebar nav a:hover {
    border-bottom: none;
    color: var(--doc-text);
}

.doc-sidebar nav ol {
    list-style: none;
    margin: 0;
    padding: 0;
    counter-reset: doc-section;
}

.doc-sidebar nav li {
    counter-increment: doc-section;
    margin: 0 0 2px 0;
}

.doc-sidebar nav a {
    display: flex;
    gap: 10px;
    align-items: baseline;
    padding: 7px 10px;
    border-radius: 6px;
    color: var(--doc-muted);
    font-size: .92rem;
    line-height: 1.4;
    border-left: 2px solid transparent;
    transition: background .15s, color .15s, border-color .15s;
}

.doc-sidebar nav a::before {
    content: counter(doc-section, decimal-leading-zero);
    color: #aab0ba;
    font-variant-numeric: tabular-nums;
    font-size: .78rem;
    min-width: 1.6em;
}

.doc-sidebar nav a:hover {
    text-decoration: none;
    color: var(--doc-text);
    background: var(--doc-bg-alt);
}

.doc-sidebar nav a.is-active {
    color: var(--doc-accent);
    background: var(--doc-accent-soft);
    border-left-color: var(--doc-accent);
    font-weight: 600;
}

.doc-sidebar-aside {
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid var(--doc-border);
    font-size: .82rem;
    color: var(--doc-muted);
    line-height: 1.55;
}

.doc-sidebar-aside p { font-size: inherit; color: inherit; margin: 0 0 8px 0; }
.doc-sidebar-aside a { color: var(--doc-link); }

/* ---------- Main column ---------- */

.doc-main {
    min-width: 0;
    font-size: 1rem;
    line-height: 1.65;
    color: var(--doc-text);
}

.doc-main p,
.doc-main li {
    font-size: 1rem;
    color: var(--doc-text);
    font-weight: 400;
    line-height: 1.65;
    margin: 0 0 14px 0;
}

.doc-main li { margin-bottom: 6px; }

.doc-main a { color: var(--doc-link); }

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

.doc-eyebrow {
    text-transform: uppercase;
    letter-spacing: .1em;
    font-size: .75rem !important;
    font-weight: 700 !important;
    color: var(--doc-accent) !important;
    margin: 0 0 12px 0 !important;
}

.doc-main h1 {
    font-size: 2.25rem;
    font-weight: 600;
    line-height: 1.2;
    margin: 0 0 14px 0;
    text-align: left;
}

.doc-lead {
    font-size: 1.1rem !important;
    color: var(--doc-muted) !important;
    max-width: 52rem;
    margin: 0 0 18px 0 !important;
    line-height: 1.55 !important;
}

.doc-meta {
    font-size: .85rem !important;
    color: var(--doc-muted) !important;
    margin: 0 !important;
}

.doc-main section {
    padding: 0;
    margin: 0 0 56px 0;
}

.doc-main section + section { padding-top: 0; }

.doc-main h2 {
    font-size: 1.6rem;
    font-weight: 600;
    margin: 0 0 16px 0;
    scroll-margin-top: 24px;
    text-align: left;
    color: var(--doc-text);
    padding-bottom: 10px;
    border-bottom: 1px solid var(--doc-border);
}

.doc-main h3 {
    font-size: 1.12rem;
    font-weight: 600;
    margin: 28px 0 10px 0;
    scroll-margin-top: 24px;
    color: var(--doc-text);
}

.doc-main h4 {
    font-size: .88rem;
    font-weight: 700;
    margin: 20px 0 8px 0;
    color: var(--doc-muted);
    text-transform: uppercase;
    letter-spacing: .06em;
}

.doc-main ul,
.doc-main ol {
    padding-left: 22px;
    margin: 0 0 14px 0;
}

.doc-main code {
    font-family: ui-monospace, "SF Mono", "Menlo", "Consolas", monospace;
    font-size: .88em;
    background: var(--doc-bg-alt);
    border: 1px solid var(--doc-border);
    border-radius: 4px;
    padding: 1px 6px;
    color: #344054;
}

.doc-main kbd {
    font-family: ui-monospace, "SF Mono", "Menlo", "Consolas", monospace;
    font-size: .82em;
    font-weight: 600;
    background: #fff;
    color: var(--doc-text);
    border: 1px solid var(--doc-border-strong);
    border-bottom-width: 2px;
    border-radius: 5px;
    padding: 2px 7px;
    box-shadow: inset 0 -1px 0 rgba(16, 24, 40, 0.06);
    white-space: nowrap;
    display: inline-block;
    line-height: 1.3;
    vertical-align: baseline;
}

.doc-kbd-combo {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.doc-kbd-combo .plus {
    color: var(--doc-muted);
    font-size: .8rem;
}

/* ---------- Tables ---------- */

.doc-main table.doc-table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid var(--doc-border);
    border-radius: 6px;
    overflow: hidden;
    font-size: .95rem;
    margin: 14px 0 22px 0;
    background: #fff;
}

.doc-main table.doc-table th,
.doc-main table.doc-table td {
    padding: 10px 14px;
    border: none;
    border-bottom: 1px solid var(--doc-border);
    text-align: left;
    vertical-align: top;
}

.doc-main table.doc-table thead th {
    background: var(--doc-bg-alt);
    color: var(--doc-text);
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 700;
    border-bottom: 1px solid var(--doc-border-strong);
}

.doc-main table.doc-table tbody tr:last-child td { border-bottom: none; }

.doc-main table.doc-table tbody tr:hover { background: #fafbfc; }

.doc-main table.doc-table td.doc-cell-key { width: 22%; white-space: nowrap; }

.doc-main table.doc-table td.doc-cell-cat {
    width: 20%;
    color: var(--doc-muted);
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    font-weight: 600;
}

/* ---------- Callouts ---------- */

.doc-note,
.doc-tip,
.doc-warn {
    border-left: 3px solid var(--doc-note-border);
    background: var(--doc-note-bg);
    padding: 14px 18px;
    border-radius: 4px;
    margin: 18px 0;
}

.doc-note p:last-child,
.doc-tip p:last-child,
.doc-warn p:last-child { margin-bottom: 0; }

.doc-tip {
    border-left-color: var(--doc-tip-border);
    background: var(--doc-tip-bg);
}

.doc-warn {
    border-left-color: var(--doc-warn-border);
    background: var(--doc-warn-bg);
}

.doc-note-title {
    font-weight: 700;
    font-size: .72rem !important;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--doc-muted) !important;
    margin: 0 0 6px 0 !important;
}

/* ---------- Quick-start block ---------- */

.doc-quickstart {
    background: var(--doc-accent-soft);
    border: 1px solid #cfe0f8;
    border-radius: 8px;
    padding: 22px 26px;
    margin: 0 0 40px 0;
}

.doc-quickstart h3 {
    margin-top: 0;
    color: var(--doc-accent);
}

.doc-quickstart ol { margin-bottom: 0; }

/* ---------- Anchor link on headings ---------- */

.doc-anchor {
    opacity: 0;
    margin-left: 8px;
    font-weight: 400;
    color: var(--doc-muted);
    text-decoration: none;
    font-size: .85em;
    transition: opacity .15s;
}

.doc-anchor:hover { text-decoration: none; color: var(--doc-accent); }

.doc-main h2:hover .doc-anchor,
.doc-main h3:hover .doc-anchor,
.doc-anchor:focus { opacity: 1; }

/* ---------- Footer ---------- */

.doc-footer {
    margin-top: 64px;
    padding-top: 24px;
    border-top: 1px solid var(--doc-border);
    color: var(--doc-muted);
    font-size: .95rem;
}

.doc-footer p { color: inherit; font-size: inherit; margin: 0 0 6px 0; }

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
    .doc-shell {
        grid-template-columns: 1fr;
        gap: 24px;
    }
    .doc-sidebar-inner {
        position: static;
        max-height: none;
        border-right: none;
        border-bottom: 1px solid var(--doc-border);
        padding: 0 0 18px 0;
    }
    .doc-sidebar-aside { display: none; }
    .doc-main h1 { font-size: 1.8rem; }
    .doc-main table.doc-table { font-size: .88rem; }
    .doc-main table.doc-table td.doc-cell-cat { width: auto; }
}

/* ═══════════════════════════════════════════════════
   Inline animated demos
   (lightweight CSS-only, no JS, no video assets)
   ═══════════════════════════════════════════════════ */

.doc-demo {
    margin: 22px 0 8px 0;
    border: 1px solid var(--doc-border-strong);
    border-radius: 10px;
    background: #fff;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.doc-demo-titlebar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: linear-gradient(180deg, #f9fafb 0%, #eef0f3 100%);
    border-bottom: 1px solid var(--doc-border);
    font-size: .78rem;
    color: var(--doc-muted);
}
.doc-demo-dots {
    display: inline-flex;
    gap: 5px;
    margin-right: 8px;
}
.doc-demo-dots span {
    width: 9px; height: 9px; border-radius: 50%;
    background: #d0d5dd;
}
.doc-demo-dots span:nth-child(1) { background: #ff6159; }
.doc-demo-dots span:nth-child(2) { background: #ffbd2e; }
.doc-demo-dots span:nth-child(3) { background: #27c93f; }

.doc-demo-file {
    font-family: "SF Mono", Menlo, Consolas, monospace;
    color: var(--doc-text);
    font-weight: 500;
}

.doc-demo-stage {
    position: relative;
    padding: 14px 14px 16px 14px;
    background: #fff;
}

/* Simulated data grid */
.doc-demo-grid {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: .82rem;
    font-family: "SF Mono", Menlo, Consolas, monospace;
    border: 1px solid var(--doc-border);
    border-radius: 6px;
    overflow: hidden;
}
.doc-demo-grid th,
.doc-demo-grid td {
    padding: 5px 10px;
    border-right: 1px solid var(--doc-border);
    border-bottom: 1px solid var(--doc-border);
    text-align: left;
    white-space: nowrap;
    color: var(--doc-text);
}
.doc-demo-grid th:last-child,
.doc-demo-grid td:last-child { border-right: none; }
.doc-demo-grid tr:last-child td { border-bottom: none; }
.doc-demo-grid th {
    background: #f7f8fa;
    color: var(--doc-muted);
    font-weight: 600;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .04em;
}

/* Filter/status bar */
.doc-demo-bar {
    margin-top: 8px;
    padding: 6px 10px;
    background: var(--doc-bg-alt);
    border: 1px solid var(--doc-border);
    border-radius: 5px;
    font-family: "SF Mono", Menlo, Consolas, monospace;
    font-size: .76rem;
    color: var(--doc-muted);
    min-height: 14px;
}
.doc-demo-bar .doc-demo-bar-label {
    color: #667085;
    margin-right: 6px;
}
.doc-demo-bar .doc-demo-bar-expr {
    color: var(--doc-accent);
    font-weight: 600;
}

/* Floating keypress indicator */
.doc-demo-key {
    position: absolute;
    right: 18px;
    top: 18px;
    width: 40px; height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-weight: 700;
    font-size: 1.02rem;
    color: #fff;
    background: #1f2937;
    border-radius: 8px;
    box-shadow:
        inset 0 -3px 0 rgba(0,0,0,.35),
        0 4px 10px rgba(16,24,40,.18);
    opacity: 0;
}
.doc-demo-key.combo { width: auto; padding: 0 10px; font-size: .82rem; letter-spacing: .02em; }

/* Caption */
.doc-demo-caption {
    font-size: .86rem;
    color: var(--doc-muted);
    padding: 8px 14px 12px 14px;
    border-top: 1px dashed var(--doc-border);
    background: #fbfcfd;
}
.doc-demo-caption strong { color: var(--doc-text); }

/* Highlight styling for cells */
.doc-demo-grid td.sel { outline: 2px solid var(--doc-accent); outline-offset: -2px; background: var(--doc-accent-soft); }
.doc-demo-grid td.match { background: #fff7e8; }
.doc-demo-grid td.diff-a { background: #ffe1e1; color: #b42318; }
.doc-demo-grid td.diff-b { background: #d9f4e0; color: #0b7a2c; }

/* Row hiding animation for filter */
.doc-demo-grid tr.row-anim { transform-origin: top; }

/* Keypress pop animation helper */
@keyframes keypop {
    0%   { opacity: 0; transform: scale(.7); }
    10%  { opacity: 1; transform: scale(1.08); }
    25%  { opacity: 1; transform: scale(1); }
    55%  { opacity: 1; transform: scale(1); }
    70%  { opacity: 0; transform: scale(.9); }
    100% { opacity: 0; transform: scale(.9); }
}

/* ── Demo 1: Dataset filter (D) ── 8s cycle ── */
.demo-filter .doc-demo-grid td.cell-sex { transition: background .15s; }
.demo-filter .row-m { animation: demo1-row-m 8s linear infinite; }
.demo-filter .cell-target { animation: demo1-target 8s linear infinite; }
.demo-filter .doc-demo-key { animation: demo1-key 8s linear infinite; animation-delay: 0s; }
.demo-filter .doc-demo-bar-expr { animation: demo1-expr 8s linear infinite; opacity: 0; }

@keyframes demo1-target {
    0%, 14% { outline-color: transparent; background: transparent; }
    15%, 100% { outline: 2px solid var(--doc-accent); outline-offset: -2px; background: var(--doc-accent-soft); }
}
@keyframes demo1-key {
    0%, 30% { opacity: 0; transform: scale(.7); }
    32%, 45% { opacity: 1; transform: scale(1); }
    55% { opacity: 0; transform: scale(.9); }
    100% { opacity: 0; transform: scale(.9); }
}
@keyframes demo1-row-m {
    0%, 45% { max-height: 28px; opacity: 1; transform: scaleY(1); }
    55%, 92% { max-height: 0; opacity: 0; transform: scaleY(0); padding-top: 0; padding-bottom: 0; }
    100% { max-height: 28px; opacity: 1; transform: scaleY(1); }
}
@keyframes demo1-expr {
    0%, 50% { opacity: 0; }
    55%, 92% { opacity: 1; }
    100% { opacity: 0; }
}

/* ── Demo 2: Library filter (L) ── 8s cycle ── */
.demo-library .library-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}
.demo-library .lib-card {
    border: 1px solid var(--doc-border);
    border-radius: 6px;
    padding: 6px;
    background: #fff;
    font-family: "SF Mono", Menlo, Consolas, monospace;
    font-size: .72rem;
    position: relative;
    overflow: hidden;
}
.demo-library .lib-card h4 {
    margin: 0 0 4px 0;
    font-size: .7rem;
    font-weight: 600;
    color: var(--doc-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    font-family: inherit;
}
.demo-library .lib-row {
    display: flex; justify-content: space-between;
    padding: 2px 4px;
    border-bottom: 1px solid #f0f1f3;
    color: var(--doc-text);
}
.demo-library .lib-row:last-child { border-bottom: none; }
.demo-library .lib-row.keep { background: var(--doc-accent-soft); }
.demo-library .lib-row.drop { animation: lib-drop 8s linear infinite; }
.demo-library .lib-card .lib-badge {
    position: absolute;
    top: 4px; right: 6px;
    font-size: .62rem;
    padding: 1px 6px;
    border-radius: 9px;
    background: var(--doc-accent);
    color: #fff;
    opacity: 0;
    animation: lib-badge 8s linear infinite;
}
.demo-library .doc-demo-key { animation: demo1-key 8s linear infinite; }
.demo-library .doc-demo-bar-expr { animation: demo1-expr 8s linear infinite; opacity: 0; }

@keyframes lib-drop {
    0%, 45% { max-height: 18px; opacity: 1; }
    55%, 92% { max-height: 0; opacity: 0; padding: 0 4px; border: none; }
    100% { max-height: 18px; opacity: 1; }
}
@keyframes lib-badge {
    0%, 52% { opacity: 0; transform: scale(.8); }
    58%, 92% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(.8); }
}

/* ── Demo 3: Frequency (F / N) ── 10s cycle ── */
.demo-freq .freq-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.demo-freq .freq-table { font-size: .8rem; }
.demo-freq .freq-table td { padding: 4px 8px; }
.demo-freq .freq-title {
    font-family: "SF Mono", Menlo, Consolas, monospace;
    font-size: .72rem;
    color: var(--doc-muted);
    margin: 0 0 4px 0;
    text-transform: uppercase;
    letter-spacing: .05em;
}
.demo-freq .freq-source { opacity: 1; }
.demo-freq .freq-out {
    opacity: 0;
    animation: freq-out 10s linear infinite;
}
.demo-freq .freq-n-col { animation: freq-n-col 10s linear infinite; opacity: 0; }
.demo-freq .key-f { animation: freq-key-f 10s linear infinite; }
.demo-freq .key-n { animation: freq-key-n 10s linear infinite; }

@keyframes freq-out {
    0%, 22% { opacity: 0; transform: translateY(4px); }
    28%, 96% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(4px); }
}
@keyframes freq-n-col {
    0%, 62% { opacity: 0; }
    68%, 96% { opacity: 1; }
    100% { opacity: 0; }
}
@keyframes freq-key-f {
    0%, 15% { opacity: 0; transform: scale(.7); }
    18%, 26% { opacity: 1; transform: scale(1); }
    32% { opacity: 0; transform: scale(.9); }
    100% { opacity: 0; transform: scale(.9); }
}
@keyframes freq-key-n {
    0%, 55% { opacity: 0; transform: scale(.7); }
    58%, 66% { opacity: 1; transform: scale(1); }
    72% { opacity: 0; transform: scale(.9); }
    100% { opacity: 0; transform: scale(.9); }
}

/* ── Demo 4: Compare ── static annotated frame ── */
.demo-compare .cmp-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.demo-compare h4 {
    margin: 0 0 4px 0;
    font-size: .72rem;
    color: var(--doc-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    font-family: "SF Mono", Menlo, Consolas, monospace;
}
.demo-compare .cmp-summary {
    margin-top: 8px;
    padding: 8px 10px;
    background: var(--doc-note-bg);
    border-left: 3px solid var(--doc-note-border);
    border-radius: 0 5px 5px 0;
    font-size: .8rem;
    color: var(--doc-text);
}
.demo-compare .cmp-summary strong { color: var(--doc-accent); }
.demo-compare .pulse {
    animation: cmp-pulse 3s ease-in-out infinite;
}
@keyframes cmp-pulse {
    0%, 100% { box-shadow: inset 0 0 0 0 rgba(180, 35, 24, 0); }
    50%      { box-shadow: inset 0 0 0 2px rgba(180, 35, 24, .35); }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
    .doc-demo *,
    .doc-demo *::before,
    .doc-demo *::after {
        animation-duration: 0s !important;
        animation-iteration-count: 1 !important;
        transition: none !important;
    }
    .demo-filter .doc-demo-bar-expr,
    .demo-library .doc-demo-bar-expr,
    .demo-library .lib-badge,
    .demo-freq .freq-out,
    .demo-freq .freq-n-col { opacity: 1 !important; }
    .demo-filter .cell-target { outline: 2px solid var(--doc-accent); outline-offset: -2px; background: var(--doc-accent-soft); }
}

@media (max-width: 700px) {
    .demo-library .library-grid { grid-template-columns: 1fr; }
    .demo-freq .freq-split,
    .demo-compare .cmp-split { grid-template-columns: 1fr; }
    .doc-demo-grid { font-size: .72rem; }
    .doc-demo-grid th, .doc-demo-grid td { padding: 4px 6px; }
}
