/* =============================================================================
   SHARED STYLES FOR WEB-COMMANDPALETTE EXAMPLES
   (copied from web-editor — keep the nav/copy-link/controls contract in sync)
   ============================================================================= */

/* Base reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Prevent FOUC (Flash of Unstyled Content) before the element upgrades. */
web-command-palette:not(:defined) {
    display: none;
}

/* Body and layout */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    padding: 2rem;
    background: #f7fafc;
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

/* Header styling */
header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 2rem;
    border-radius: 12px;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.subtitle {
    opacity: 0.9;
    font-size: 1.1rem;
}

.back-link {
    display: inline-block;
    color: white;
    text-decoration: none;
    margin-bottom: 1rem;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.back-link:hover {
    opacity: 1;
}

/* Card/Section styles */
.card,
.example-section {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.card h2,
.example-section h2 {
    margin-bottom: 1rem;
    color: #2d3748;
    font-size: 1.5rem;
    /* Flex so an inline `.badge` sits centered next to the heading text.
       Single-child headings (the common case) render identically. `flex-wrap`
       keeps longer headings that mix text with inline `<code>` chips flowing
       onto new lines instead of squishing each flex item to one word per line. */
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.card h3,
.example-section h3 {
    margin-bottom: 0.75rem;
    color: #4a5568;
    font-size: 1.25rem;
}

/* Accent sub-heading within a card/section (a step below its h2). */
.card h3.subsection,
.example-section h3.subsection {
    margin: 2rem 0 1rem;
    font-size: 1.2rem;
    color: #667eea;
}

.card p,
.example-section p {
    margin-bottom: 1rem;
    color: #666;
}

/* Demo card — a padded box framing a single demo/instance (smaller and lighter
   than `.card`). The surface is tunable via `--demo-card-bg` / `--demo-card-border`
   (e.g. a gray fill or a shadow-only look); the inner heading/paragraph/code are
   standardized so cards read consistently across every example page. */
.demo-card {
    background: var(--demo-card-bg, #fff);
    border: var(--demo-card-border, 1px solid #e5e7eb);
    border-radius: 8px;
    padding: 1.5rem;
}

.demo-card h3,
.demo-card h4 {
    margin: 0 0 0.5rem 0;
    font-size: 1rem;
    color: #374151;
    border: none;
    padding: 0;
}

.demo-card p {
    margin: 0 0 1rem 0;
    font-size: 0.8125rem;
    color: #6b7280;
}

.demo-card code {
    background: #f3f4f6;
    padding: 0.125rem 0.375rem;
    border-radius: 3px;
    font-size: 0.7rem;
}

/* Description text */
.description {
    color: #718096;
    margin-bottom: 1.5rem;
}

/* Form styling */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.form-text {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.875rem;
    color: #666;
}

/* Demo form panel — a soft card wrapping a live `<form>` (the form-integration
   examples). The `.form-actions` footer holds the submit/inspect buttons, set off
   from the field above by a top rule + spacing so the buttons never sit flush
   against the component. */
form {
    background: #edf2f7;
    padding: 1.5rem;
    border-radius: 8px;
    margin-top: 1rem;
}

.form-actions {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #cbd5e0;
}

/* Controls */
.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    align-items: center;
}

/* Inline control label — a clickable row of checkbox/radio + text. Used for
   each label inside `.controls`, and standalone as `.toggle-label` (a single
   switch that also carries its own bottom spacing). */
.controls label,
.toggle-label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.toggle-label {
    margin-bottom: 0.75rem;
}

.controls input[type="checkbox"] {
    width: 16px;
    height: 16px;
}

/* Demo areas — a soft panel wrapping a live component demo, optionally
   introduced by a `.demo-label`. */
.demo-area {
    background: #f7fafc;
    padding: 1.5rem;
    border-radius: 8px;
    margin: 1rem 0;
}

.demo-label {
    display: block;
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 0.5rem;
}

/* Trailing action buttons in a demo panel (e.g. "Show Selected Data") sit as
   direct children after the component / `.output` box. Give them top spacing so
   they don't butt up against the content above. Scoped to DIRECT children so it
   never touches buttons nested in a `.controls` row (which lays out its own way).
   Adjacent buttons on the same line share the margin, so they stay aligned. */
.demo-area > button {
    margin-top: 1rem;
}
.demo-area > button + button {
    margin-inline-start: 0.5rem;
}

/* Output display */
.output {
    margin-top: 1rem;
}

.output-label {
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: #4a5568;
}

.output pre,
pre {
    background: #f7fafc;
    padding: 1rem;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 0.875rem;
    border: 1px solid #e2e8f0;
}

/* Dark output theme — opt in per page with `class="dark-output"` on <body>.
   Turns the light `.output` panels above into a dark console look. */
.dark-output .output {
    background: #2d3748;
    color: #a0aec0;
    padding: 1rem;
    border-radius: 8px;
    margin-top: 1rem;
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
    overflow-x: auto;
    border: none;
}

.dark-output .output-label {
    color: #667eea;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.dark-output .output pre {
    margin: 0;
    padding: 0;
    border: none;
    background: transparent;
    color: inherit;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Section-header badge pill (e.g. a "NEW" tag beside an `.example-section h2`).
   Landing/templating pages override `.badge` locally for their own look. */
.badge {
    display: inline-block;
    background: #667eea;
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge.new {
    background: #f56565;
}

/* Log / console panel — a monospace, scrollable box for streaming demo output
   (event logs, request activity, registry dumps, live values). Light by
   default; add `.log-panel--dark` for the console look. Height caps via
   `--log-max-height`. Pages keep their own entry-color classes
   (`.entry--*`, `.tag-*`, …). */
.log-panel {
    font-family: ui-monospace, SFMono-Regular, Menlo, 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.5;
    padding: 1rem 1.25rem;
    border-radius: 8px;
    max-height: var(--log-max-height, 220px);
    overflow: auto;
    background: #f7fafc;
    color: #2d3748;
    border: 1px solid #e2e8f0;
}

.log-panel--dark {
    background: #0f172a;
    color: #e2e8f0;
    border-color: transparent;
}

/* Muted secondary text — used inside log panels and elsewhere. */
.muted {
    color: #6b7280;
}

/* Spacing utility — top margin to separate a follow-up block (a details
   disclosure, a secondary grid) from the demo above it. */
.mt-1 {
    margin-top: 1rem;
}

/* Code blocks */
.code-block {
    margin: 1.5rem 0;
    position: relative;
}

.code-block pre {
    background: #2d3748;
    color: #e2e8f0;
    padding: 1.5rem;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 0.875rem;
    line-height: 1.6;
}

/* Code block copy button */
.code-block .copy-button {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    background: rgba(255, 255, 255, 0.1);
    color: #e2e8f0;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.code-block .copy-button:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
}

/* Inline code */
code {
    background: #edf2f7;
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-size: 0.9em;
    color: #667eea;
    font-family: 'Courier New', monospace;
}

/* Reset code styling inside pre and code blocks */
pre code,
.code-block code,
.code-block pre code {
    background: transparent;
    padding: 0;
    border-radius: 0;
    color: inherit;
    font-size: inherit;
}

/* Notes/Info boxes */
.note {
    background: #edf2f7;
    padding: 1rem;
    border-radius: 6px;
    border-left: 4px solid #667eea;
    margin: 1rem 0;
}

.note.warning {
    background: #fef3c7;
    border-left-color: #f59e0b;
}

.note-title {
    font-weight: 600;
    color: #667eea;
    margin-bottom: 0.5rem;
}

.note ul {
    margin-left: 1.5rem;
    margin-top: 0.5rem;
}

.note li {
    margin-bottom: 0.5rem;
}

/* Grid layouts — one auto-fit grid parameterized by `--grid-min` (min column
   width) and `--grid-gap`. Pages tune the min inline, e.g.
   `<div class="card-grid" style="--grid-min: 240px">`. `.grid`/`.grid-2` are
   kept as named presets. */
.grid,
.grid-2,
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(var(--grid-min, 300px), 1fr));
    gap: var(--grid-gap, 2rem);
}

.grid-2 {
    --grid-min: 400px;
}

/* Reference table — bordered spec/lookup table used on a few pages. Add
   `is-highlight` to a <tr> to emphasize a row (e.g. the default value). */
.reference-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    margin-bottom: 2rem;
}

.reference-table th,
.reference-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border: 1px solid #e5e7eb;
}

.reference-table th {
    background: #f3f4f6;
    font-weight: 600;
}

.reference-table tbody tr:hover {
    background: #f9fafb;
}

.reference-table tr.is-highlight {
    background: #eff6ff;
}

.reference-table code {
    background: #e5e7eb;
    padding: 0.125rem 0.375rem;
    border-radius: 3px;
    font-size: 0.75rem;
}

/* Typography */
h2 {
    color: #2d3748;
    margin-bottom: 1rem;
}

h3 {
    color: #4a5568;
    margin-bottom: 0.75rem;
}

ul {
    line-height: 1.8;
}

li {
    color: #4a5568;
}

/* Links */
a {
    color: #667eea;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Buttons */
/* Primary button (default) */
button,
button.btn-primary {
    cursor: pointer;
    background: #667eea;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.875rem;
    transition: background 0.2s;
}

button:hover,
button.btn-primary:hover {
    background: #5a67d8;
}

/* Secondary button (gray) */
button.secondary,
button.btn-secondary {
    background: #6b7280;
    color: white;
}

button.secondary:hover,
button.btn-secondary:hover {
    background: #4b5563;
}

/* Outline button (white bg, dark text) */
button.btn-outline {
    background: white;
    color: #374151;
    border: 1px solid #d1d5db;
}

button.btn-outline:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem;
    color: #718096;
    font-size: 0.875rem;
}

footer a {
    color: #667eea;
}

/* =============================================================================
   CHAPTER NAV — floating "on this page" jump navigator (built by
   examples-chapter-nav.js). A tab pinned to the right edge (~1/3 down the
   viewport) that expands into a scroll-spied list of the page's chapters.
   ============================================================================= */

/* Smooth hash-jumps + a little headroom so a jumped-to section isn't flush to the
   top edge. `scroll-margin-top` applies to the anchor targets the nav assigns ids to. */
html {
    scroll-behavior: smooth;
}
.card,
.example-section {
    scroll-margin-top: 1rem;
}

/* Copy-link button — a small chain-link icon appended inside every section <h2>
   (see examples-copy-link.js). Click copies a share-ready deep link to the section.
   The h2 is already a flex row, so this sits as the trailing inline item; it fades
   up on header hover to stay unobtrusive, and briefly flips to a check + "Copied!". */
.copy-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    /* Icon size tracks the heading. */
    font-size: 0.8rem;
    line-height: 1;
    padding: 0.25rem 0.4rem;
    margin-inline-start: 0.15rem;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: #a0aec0;
    cursor: pointer;
    /* Unobtrusive until you hover the header (or focus the button for keyboard users). */
    opacity: 0;
    transition: opacity 0.15s ease, color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}
.card h2:hover .copy-link,
.example-section h2:hover .copy-link,
.copy-link:focus-visible {
    opacity: 1;
}
.copy-link:hover {
    color: #667eea;
    background: #edf2ff;
    border-color: #c3cbf5;
}
.copy-link:focus-visible {
    outline: 2px solid #667eea;
    outline-offset: 1px;
}
.copy-link .copy-link__icon {
    width: 1.05em;
    height: 1.05em;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
/* Default: link icon shown, check + label hidden. */
.copy-link .copy-link__icon--check,
.copy-link .copy-link__label {
    display: none;
}
.copy-link .copy-link__label {
    font-weight: 600;
    font-size: 0.7rem;
}
/* Copied: swap to the green check + "Copied!" pill. */
.copy-link.is-copied {
    opacity: 1;
    color: #2f855a;
    background: #f0fff4;
    border-color: #9ae6b4;
}
.copy-link.is-copied .copy-link__icon--link {
    display: none;
}
.copy-link.is-copied .copy-link__icon--check,
.copy-link.is-copied .copy-link__label {
    display: inline-flex;
}
/* Copy failed (e.g. clipboard blocked): red hint; JS also updates the tooltip. */
.copy-link.is-failed {
    opacity: 1;
    color: #c53030;
    background: #fff5f5;
    border-color: #feb2b2;
}

/* The grab tab, pinned to the right edge ~1/3 down. The panel is positioned
   against it by Floating UI (see examples-chapter-nav.js), so it's out of flow
   here — only the toggle occupies this fixed box. */
.chapter-nav {
    position: fixed;
    top: 33vh;
    right: 0;
    z-index: 9000;
    /* Let clicks fall through to the page; children re-enable. */
    pointer-events: none;
}

.chapter-nav__panel,
.chapter-nav__toggle {
    pointer-events: auto;
}

/* The grab tab. Rounded on the left (it hugs the right edge). */
.chapter-nav__toggle {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 48px;
    padding: 0;
    background: #667eea;
    color: #fff;
    border: none;
    border-radius: 10px 0 0 10px;
    box-shadow: 0 6px 18px rgba(102, 126, 234, 0.35);
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s;
}

.chapter-nav__toggle:hover {
    background: #5a67d8;
}

.chapter-nav[data-open="true"] .chapter-nav__toggle {
    background: #4c51bf;
}

.chapter-nav__toggle svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
}

.chapter-nav__toggle svg circle {
    fill: currentColor;
    stroke: none;
}

/* The list panel — hidden (and non-interactive) until open. Positioned by
   Floating UI (left/top set inline), so it's taken out of flow with fixed. */
.chapter-nav__panel {
    position: fixed;
    z-index: 9000;
    width: 260px;
    max-width: 72vw;
    max-height: 60vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.12), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    padding: 0.5rem;
    opacity: 0;
    visibility: hidden;
    transform: translateX(8px);
    transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
}

.chapter-nav[data-open="true"] .chapter-nav__panel {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

/* "Back to Examples" link at the top of the panel (example pages only). */
.chapter-nav__back {
    display: block;
    margin-bottom: 0.35rem;
    padding: 0.45rem 0.6rem;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 600;
    color: #4c51bf;
    text-decoration: none;
    background: #eef2ff;
    transition: background 0.15s, color 0.15s;
}

.chapter-nav__back:hover {
    background: #e0e7ff;
    color: #3730a3;
    text-decoration: none;
}

.chapter-nav__title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #9ca3af;
    padding: 0.25rem 0.5rem 0.4rem;
}

.chapter-nav__list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.chapter-nav__item {
    display: block;
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    border-left: 3px solid transparent;
    font-size: 0.85rem;
    line-height: 1.35;
    color: #4a5568;
    text-decoration: none;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.chapter-nav__item:hover {
    background: #f3f4f6;
    color: #2d3748;
    text-decoration: none;
}

.chapter-nav__item.is-active {
    background: #eef2ff;
    color: #4338ca;
    border-left-color: #667eea;
    font-weight: 600;
}

/* On small screens, go near-fullscreen (touch targets + readability) and bump the
   font so chapter titles are comfortable to tap. */
@media (max-width: 768px) {
    .chapter-nav__panel {
        width: 80vw;
        max-width: 80vw;
        max-height: 80vh;
    }
    .chapter-nav__title {
        font-size: 0.9rem;
    }
    .chapter-nav__item {
        font-size: 1.05rem;
        padding: 0.7rem 0.85rem;
    }
    .chapter-nav__toggle {
        width: 40px;
        height: 44px;
    }
}

/* Respect reduced-motion: no smooth scroll or slide. */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
    .chapter-nav__panel {
        transition: none;
    }
}

/* Responsive */
@media (max-width: 768px) {
    body {
        padding: 1rem;
    }

    h1 {
        font-size: 2rem;
    }

    .grid,
    .grid-2,
    .card-grid {
        grid-template-columns: 1fr;
    }

    .card,
    .example-section {
        padding: 1.5rem;
    }
}
