/*
 * modules/wiki/assets/wiki.css
 *
 * Styling for the wiki: rendered page content, the reading layout, and the
 * admin editor. Every selector is prefixed `wiki-`; nothing here redefines a
 * shared structural class.
 *
 * Written against the design tokens rather than as Tailwind utilities on
 * purpose. WikiMarkdown emits many of these class names from PHP at render
 * time, and a page has to look right on an install where nobody has rebuilt
 * assets/css/app.css — which is a generated file this module does not own.
 *
 * Light only, per AGENTS.md rule 5. Do not add a prefers-color-scheme block.
 */

/* ═══ Reading layout ═════════════════════════════════════════════════════ */

/*
 * Three columns at full width: the space's contents, the page, its headings.
 * Both rails are navigation aids, so they are the parts that collapse away —
 * the page itself is the only column that is ever essential.
 */
.wiki-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 2.5rem;
    align-items: start;
}

@media (min-width: 60rem) {
    .wiki-layout.has-outline {
        grid-template-columns: 15rem minmax(0, 1fr);
    }
}

@media (min-width: 80rem) {
    .wiki-layout.has-outline.has-toc {
        grid-template-columns: 15rem minmax(0, 1fr) 17rem;
    }

    .wiki-layout.has-toc:not(.has-outline) {
        grid-template-columns: minmax(0, 1fr) 17rem;
    }
}

/* The index, a space and the missing-page notice are single-column pages. */
.wiki-index {
    max-width: 60rem;
    margin: 0 auto;
}

/*
 * The wiki front page spans the window (WikiModule::renderIndex sets
 * $pageWidth = 'full'). What lives there is grids — spaces, what changed,
 * what is unfiled — and a cap on those only costs cards per row.
 *
 * Width is given to the grids, not to the text. Everything below re-imposes a
 * measure on the parts that are actually sentences, because a search snippet
 * running the full width of a 1700px monitor is exactly the unreadable line
 * the cap exists to prevent.
 */
.wiki-index-wide {
    max-width: none;
}

.wiki-index-wide .wiki-search {
    max-width: 46rem;
}

.wiki-index-wide .wiki-card-summary,
.wiki-index-wide .wiki-panel-text,
.wiki-index-wide .wiki-tree-summary {
    max-width: 74ch;
}

/* Results are a reading list, so they stay in a column rather than becoming
   a row of very wide cards. */
.wiki-index-wide .wiki-card-list {
    max-width: 80rem;
}

@media (min-width: 90rem) {
    .wiki-index-wide .wiki-index-columns:has(> section + section) {
        gap: 3.5rem;
    }
}

.wiki-main {
    min-width: 0;   /* lets a wide table scroll instead of stretching the grid */
}

/* ── Sidebar: the contents of a space ───────────────────────────────────── */

.wiki-sidebar {
    display: none;
}

@media (min-width: 60rem) {
    .wiki-sidebar {
        display: block;
    }
}

.wiki-sidebar-inner {
    position: sticky;
    top: 5.5rem;            /* clears the site's sticky header */
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 7rem);
    overflow-y: auto;
    padding: 1rem 0.75rem;
    border: 1px solid hsl(var(--border));
    border-radius: calc(var(--radius) + 2px);
    background: hsl(var(--card));
}

.wiki-sidebar-space {
    display: block;
    margin: 0 0 0.75rem;
    padding: 0.125rem 0.5rem 0.75rem;
    border-bottom: 1px solid hsl(var(--border));
    color: hsl(var(--foreground));
    font-size: 0.9375rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    text-decoration: none;
}

.wiki-sidebar-foot {
    display: grid;
    gap: 0.125rem;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid hsl(var(--border));
}

.wiki-sidebar-action {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.45rem 0.5rem;
    border-radius: 6px;
    color: hsl(var(--muted-foreground));
    font-size: 0.8125rem;
    text-decoration: none;
}

.wiki-sidebar-action svg {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
}

.wiki-sidebar-action:hover {
    background: hsl(var(--accent));
    color: hsl(var(--foreground));
}

.wiki-sidebar-action.is-primary {
    color: hsl(var(--primary));
    font-weight: 500;
}

.wiki-sidebar-space:hover {
    color: hsl(var(--primary));
}

/* ── Right rail: this page's headings ───────────────────────────────────── */

.wiki-rail {
    display: block;
    min-width: 0;
}

.wiki-rail-inner {
    display: grid;
    gap: 1rem;
}

/* Below the three-column width the rail sits under the page, where the
   inline contents list has already done its job. */
.wiki-rail-toc {
    display: none;
}

@media (min-width: 60rem) and (max-width: 79.99rem) {
    .wiki-layout.has-outline .wiki-rail {
        grid-column: 2;
    }
}

@media (min-width: 80rem) {
    .wiki-rail-inner {
        position: sticky;
        top: 5.5rem;
        max-height: calc(100vh - 7rem);
        overflow-y: auto;
    }

    .wiki-rail-toc {
        display: block;
    }

    /* The rail replaces the inline copy rather than duplicating it. */
    .wiki-toc-inline {
        display: none;
    }
}

.wiki-rail-card {
    padding: 1rem 1.125rem;
    border: 1px solid hsl(var(--border));
    border-radius: calc(var(--radius) + 2px);
    background: hsl(var(--card));
}

.wiki-rail-title {
    margin: 0 0 0.75rem;
    color: hsl(var(--foreground));
    font-size: 0.875rem;
    font-weight: 600;
}

.wiki-details {
    display: grid;
    gap: 0.875rem;
    margin: 0;
}

.wiki-detail {
    display: grid;
    grid-template-columns: 1.125rem minmax(0, 1fr);
    column-gap: 0.75rem;
    align-items: start;
}

.wiki-detail > svg {
    grid-row: span 2;
    width: 1.125rem;
    height: 1.125rem;
    margin-top: 0.1rem;
    color: hsl(var(--muted-foreground));
}

.wiki-detail dt {
    color: hsl(var(--muted-foreground));
    font-size: 0.75rem;
}

.wiki-detail dd {
    margin: 0;
    color: hsl(var(--foreground));
    font-size: 0.8125rem;
    overflow-wrap: anywhere;
}

.wiki-detail dd a {
    color: inherit;
    text-decoration: none;
}

.wiki-detail dd a:hover {
    color: hsl(var(--primary));
    text-decoration: underline;
}

.wiki-status {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.wiki-status::before {
    content: "";
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 999px;
    background: hsl(var(--muted-foreground));
}

.wiki-status.is-published::before {
    background: #16a34a;
}

.wiki-status.is-published {
    color: #15803d;
}

.wiki-related {
    display: grid;
    gap: 0.125rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.wiki-related a {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.35rem 0.25rem;
    border-radius: 6px;
    color: hsl(var(--foreground));
    font-size: 0.8125rem;
    line-height: 1.35;
    text-decoration: none;
}

.wiki-related a:hover {
    background: hsl(var(--accent));
    color: hsl(var(--primary));
}

.wiki-related svg {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
    margin-top: 0.05rem;
    color: hsl(var(--muted-foreground));
}

/* ═══ Page furniture ═════════════════════════════════════════════════════ */

.wiki-crumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 1.25rem;
    color: hsl(var(--muted-foreground));
    font-size: 0.8125rem;
}

.wiki-crumb-home {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.wiki-crumbs a {
    color: hsl(var(--muted-foreground));
    text-decoration: none;
}

.wiki-crumbs a:hover {
    color: hsl(var(--primary));
    text-decoration: underline;
}

.wiki-crumb-sep {
    width: 0.8rem;
    height: 0.8rem;
    flex-shrink: 0;
    opacity: 0.6;
}

.wiki-crumb-current {
    color: hsl(var(--foreground));
    font-weight: 500;
}

.wiki-page-header {
    margin-bottom: 2rem;
}

.wiki-page-title-row,
.wiki-hero {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.wiki-hero {
    position: relative;
    align-items: flex-end;
    margin: -1rem 0 1.5rem;
    padding: 1.5rem 0 0.5rem;
}

/* A faint wash behind the heading, drawn rather than imaged. */
.wiki-hero::before {
    content: "";
    position: absolute;
    inset: -1.5rem -2rem -1rem 35%;
    z-index: -1;
    background:
        radial-gradient(ellipse at 85% 10%, hsl(var(--primary) / 0.07), transparent 60%),
        radial-gradient(ellipse at 60% 90%, hsl(var(--primary) / 0.04), transparent 55%);
    pointer-events: none;
}

.wiki-hero-text {
    min-width: 0;
}

.wiki-hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.wiki-eyebrow {
    margin: 0 0 0.5rem;
    color: hsl(var(--muted-foreground));
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.wiki-hero-title {
    font-size: clamp(2.25rem, 4vw, 3rem);
    font-weight: 800;
    letter-spacing: -0.035em;
    line-height: 1.05;
}

.wiki-page-title {
    margin: 0;
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    line-height: 1.2;
}

.wiki-page-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

/* ── Byline: who wrote it, how fresh, how long ──────────────────────────── */

.wiki-byline {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

.wiki-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    flex-shrink: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, hsl(var(--primary)), #6366f1);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
}

.wiki-byline-text {
    display: grid;
    gap: 0.1rem;
    min-width: 0;
}

.wiki-byline-author {
    color: hsl(var(--muted-foreground));
    font-size: 0.8125rem;
}

.wiki-byline-author strong {
    color: hsl(var(--foreground));
    font-weight: 600;
}

.wiki-byline .wiki-page-meta {
    margin: 0;
    font-size: 0.75rem;
}

.wiki-meta-item {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.wiki-lede {
    max-width: 74ch;
    margin: 0.75rem 0 0;
    color: hsl(var(--muted-foreground));
    font-size: 1.0625rem;
    line-height: 1.6;
}

.wiki-page-meta,
.wiki-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin: 0.75rem 0 0;
    color: hsl(var(--muted-foreground));
    font-size: 0.8125rem;
}

.wiki-card-meta a {
    color: inherit;
}

.wiki-meta-sep {
    opacity: 0.5;
}

.wiki-draft-note {
    margin: 0.75rem 0 0;
    color: hsl(var(--muted-foreground));
    font-size: 0.8125rem;
}

.wiki-section-title {
    margin: 0 0 1rem;
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.wiki-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.wiki-section-head .wiki-section-title {
    margin: 0;
}

.wiki-children,
.wiki-index > section + section,
.wiki-index-columns > section {
    margin-top: 2.5rem;
}

.wiki-empty-body {
    color: hsl(var(--muted-foreground));
    font-size: 0.875rem;
}

.wiki-page-footer {
    margin-top: 3rem;
    padding-top: 1rem;
    border-top: 1px solid hsl(var(--border));
    color: hsl(var(--muted-foreground));
    font-size: 0.8125rem;
}

/* ═══ Buttons ════════════════════════════════════════════════════════════ */

.wiki-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    min-height: 2.5rem;
    padding: 0.5rem 1rem;
    border: 1px solid hsl(var(--border));
    border-radius: calc(var(--radius) - 2px);
    background: hsl(var(--card));
    color: hsl(var(--foreground));
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.wiki-btn:hover {
    background: hsl(var(--accent));
    color: hsl(var(--accent-foreground));
}

.wiki-btn:focus-visible {
    outline: 2px solid hsl(var(--ring));
    outline-offset: 2px;
}

.wiki-btn-primary {
    border-color: transparent;
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
}

.wiki-btn-primary:hover {
    background: hsl(var(--primary) / 0.9);
    color: hsl(var(--primary-foreground));
}

.wiki-btn-quiet {
    border-color: transparent;
    background: transparent;
    color: hsl(var(--muted-foreground));
}

.wiki-btn svg {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
}

.wiki-btn-sm {
    min-height: 2.25rem;
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.wiki-btn-lg {
    min-height: 3rem;
    padding: 0.75rem 1.4rem;
    font-size: 0.9375rem;
    font-weight: 600;
    box-shadow: 0 1px 2px rgb(15 23 42 / 0.04);
}

.wiki-btn-icon {
    padding-inline: 0.55rem;
}

.wiki-btn-primary {
    box-shadow: 0 1px 2px rgb(37 99 235 / 0.25);
}

/* ── Small <details> menus: row actions and "more" ──────────────────────── */

.wiki-menu {
    position: relative;
}

.wiki-menu > summary {
    list-style: none;
    cursor: pointer;
}

.wiki-menu > summary::-webkit-details-marker {
    display: none;
}

.wiki-menu-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 6px;
    color: hsl(var(--muted-foreground));
}

.wiki-menu-button svg {
    width: 1.1rem;
    height: 1.1rem;
}

.wiki-menu-button:hover,
.wiki-menu[open] > .wiki-menu-button {
    background: hsl(var(--accent));
    color: hsl(var(--foreground));
}

.wiki-menu-panel {
    position: absolute;
    top: calc(100% + 0.25rem);
    right: 0;
    z-index: 30;
    display: grid;
    min-width: 10rem;
    padding: 0.3rem;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    background: hsl(var(--card));
    box-shadow: 0 10px 30px -10px rgb(15 23 42 / 0.25);
}

.wiki-menu-panel a {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.45rem 0.6rem;
    border-radius: 6px;
    color: hsl(var(--foreground));
    font-size: 0.8125rem;
    text-decoration: none;
}

.wiki-menu-panel a:hover {
    background: hsl(var(--accent));
}

.wiki-menu-panel svg {
    width: 0.95rem;
    height: 0.95rem;
    color: hsl(var(--muted-foreground));
}

/* ── Icons ──────────────────────────────────────────────────────────────── */

.wiki-icon {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
}

.wiki-icon-sm {
    width: 0.875rem;
    height: 0.875rem;
}

/* ═══ Search ═════════════════════════════════════════════════════════════ */

.wiki-search {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 2rem;
}

.wiki-search-field {
    position: relative;
    flex: 1 1 20rem;
    min-width: 0;
}

.wiki-search-icon {
    position: absolute;
    top: 50%;
    left: 0.75rem;
    width: 1rem;
    height: 1rem;
    color: hsl(var(--muted-foreground));
    transform: translateY(-50%);
    pointer-events: none;
}

.wiki-search-input {
    width: 100%;
    min-height: 2.5rem;
    padding: 0.5rem 0.75rem 0.5rem 2.25rem;
    border: 1px solid hsl(var(--input));
    border-radius: calc(var(--radius) - 2px);
    background: hsl(var(--card));
    color: hsl(var(--foreground));
    font-size: 0.9375rem;
}

.wiki-search-input::placeholder {
    color: hsl(var(--muted-foreground));
}

.wiki-search-input:focus-visible {
    outline: 2px solid hsl(var(--ring));
    outline-offset: -1px;
}

.wiki-index-wide .wiki-search-hero {
    max-width: none;
}

.wiki-search-hero {
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 2.5rem;
    padding: 0.375rem 0.375rem 0.375rem 0;
    border: 1px solid hsl(var(--border));
    border-radius: calc(var(--radius) + 4px);
    background: hsl(var(--card));
    box-shadow: 0 1px 3px rgb(15 23 42 / 0.05), 0 6px 18px -12px rgb(15 23 42 / 0.12);
}

.wiki-search-hero:focus-within {
    border-color: hsl(var(--primary) / 0.5);
    box-shadow: 0 0 0 3px hsl(var(--primary) / 0.12);
}

.wiki-search-hero .wiki-search-field {
    flex: 1 1 auto;
}

.wiki-search-hero .wiki-search-icon {
    left: 1.25rem;
    width: 1.2rem;
    height: 1.2rem;
}

.wiki-search-hero .wiki-search-input {
    min-height: 3rem;
    padding-left: 3.25rem;
    border: 0;
    background: transparent;
    font-size: 1rem;
}

.wiki-search-hero .wiki-search-input:focus-visible {
    outline: none;
}

.wiki-search-hero .wiki-btn-primary {
    min-height: 2.75rem;
    padding-inline: 1.75rem;
    font-weight: 600;
}

.wiki-mark {
    padding: 0 0.1em;
    border-radius: 2px;
    background: hsl(var(--primary) / 0.16);
    color: inherit;
    font-weight: 600;
}

/* ═══ Wiki results on the paper search page ══════════════════════════════ */

/*
 * Rendered into the search module's results column through the
 * `search_after_results` action. It is deliberately a *separate*, labelled
 * block rather than rows in the paper grid: a wiki page answers a different
 * kind of question than a paper does, and the two should not be mistaken for
 * each other at a glance. The rule above it is what makes that switch legible.
 */
.wiki-search-block {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid hsl(var(--border));
}

.wiki-search-block-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.wiki-search-block-title {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.wiki-search-toggle {
    color: hsl(var(--muted-foreground));
    font-size: 0.8125rem;
    text-decoration: underline;
    text-underline-offset: 2px;
    white-space: nowrap;
}

.wiki-search-toggle:hover {
    color: hsl(var(--primary));
}

.wiki-search-block-note {
    margin: 0.75rem 0 0;
    color: hsl(var(--muted-foreground));
    font-size: 0.8125rem;
}

.wiki-search-block-note a {
    color: hsl(var(--primary));
    text-decoration: underline;
    text-underline-offset: 2px;
}

.wiki-search-hits {
    max-width: 74ch;
}

/* ═══ Panels, cards and lists ════════════════════════════════════════════ */

.wiki-panel {
    padding: 1.25rem;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    background: hsl(var(--card));
}

.wiki-panel-empty {
    padding: 2.5rem 1.5rem;
    text-align: center;
}

.wiki-panel-empty .wiki-page-title {
    font-size: 1.5rem;
}

.wiki-panel-text {
    max-width: 60ch;
    margin: 0.75rem auto 1rem;
    color: hsl(var(--muted-foreground));
    font-size: 0.9375rem;
    line-height: 1.6;
}

.wiki-panel-empty p:last-child {
    margin-bottom: 0;
}

.wiki-card-list {
    display: grid;
    gap: 0.75rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.wiki-card {
    padding: 1rem 1.25rem;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    background: hsl(var(--card));
    transition: border-color 0.12s ease;
}

.wiki-card:hover {
    border-color: hsl(var(--primary) / 0.4);
}

.wiki-card-title {
    color: hsl(var(--foreground));
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
}

.wiki-card-title:hover {
    color: hsl(var(--primary));
    text-decoration: underline;
}

.wiki-card-summary {
    margin: 0.5rem 0 0;
    color: hsl(var(--muted-foreground));
    font-size: 0.875rem;
    line-height: 1.6;
}

/* ── Spaces ─────────────────────────────────────────────────────────────── */

.wiki-space-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 24rem), 1fr));
    gap: 1rem;
}

@media (min-width: 64rem) {
    .wiki-space-grid {
        grid-template-columns: repeat(auto-fill, minmax(26rem, calc(50% - 0.5rem)));
    }
}

.wiki-space-card {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 1.5rem;
    border: 1px solid hsl(var(--border));
    border-radius: calc(var(--radius) + 4px);
    background: hsl(var(--card));
    text-decoration: none;
    box-shadow: 0 1px 2px rgb(15 23 42 / 0.04);
    transition: border-color 0.12s ease, box-shadow 0.12s ease, transform 0.12s ease;
}

.wiki-space-card:hover {
    border-color: hsl(var(--primary) / 0.35);
    box-shadow: 0 8px 24px -14px rgb(37 99 235 / 0.35);
}

.wiki-space-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 4.5rem;
    height: 4.5rem;
    flex-shrink: 0;
    border-radius: calc(var(--radius) + 2px);
    background: hsl(var(--primary) / 0.08);
    color: hsl(var(--primary));
}

.wiki-space-icon svg {
    width: 2rem;
    height: 2rem;
    stroke-width: 1.6;
}

.wiki-space-body {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 0.35rem;
    min-width: 0;
}

.wiki-space-go {
    flex-shrink: 0;
    color: hsl(var(--foreground));
}

.wiki-space-go svg {
    width: 1.25rem;
    height: 1.25rem;
}

.wiki-space-name {
    color: hsl(var(--foreground));
    font-size: 1.125rem;
    font-weight: 600;
}

.wiki-space-description {
    color: hsl(var(--muted-foreground));
    font-size: 0.875rem;
    line-height: 1.5;
}

.wiki-space-count {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.5rem;
    color: hsl(var(--muted-foreground));
    font-size: 0.8125rem;
}

/* ── Recently updated ───────────────────────────────────────────────────── */

.wiki-index-columns {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1.5rem;
    margin-top: 2.5rem;
}

@media (min-width: 48rem) {
    .wiki-index-columns:has(> section + section) {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.wiki-index-columns > .wiki-list-card {
    margin-top: 0;
}

.wiki-list-card {
    align-self: start;
    padding: 1.25rem 1.25rem 1.125rem;
    border: 1px solid hsl(var(--border));
    border-radius: calc(var(--radius) + 4px);
    background: hsl(var(--card));
    box-shadow: 0 1px 2px rgb(15 23 42 / 0.04);
}

.wiki-rows {
    margin: 0;
    padding: 0;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    list-style: none;
}

.wiki-row {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 0.75rem 0.5rem 0.75rem 1rem;
}

.wiki-row + .wiki-row {
    border-top: 1px solid hsl(var(--border));
}

.wiki-row:hover {
    background: hsl(var(--accent) / 0.5);
}

.wiki-row-icon {
    display: inline-flex;
    flex-shrink: 0;
    color: hsl(var(--muted-foreground));
}

.wiki-row-icon svg {
    width: 1.25rem;
    height: 1.25rem;
    stroke-width: 1.75;
}

.wiki-row-main {
    flex: 1 1 auto;
    min-width: 0;
}

.wiki-row-line {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 0.5rem;
}

.wiki-row-line .wiki-chip {
    margin-left: 0;
}

.wiki-row-title {
    color: hsl(var(--foreground));
    font-size: 0.9375rem;
    font-weight: 500;
    text-decoration: none;
}

.wiki-row-title:hover {
    color: hsl(var(--primary));
    text-decoration: underline;
}

.wiki-row-summary {
    margin: 0.2rem 0 0;
    overflow: hidden;
    color: hsl(var(--muted-foreground));
    font-size: 0.8125rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.wiki-row-meta {
    flex-shrink: 0;
    color: hsl(var(--muted-foreground));
    font-size: 0.8125rem;
    white-space: nowrap;
}

@media (max-width: 40rem) {
    .wiki-row {
        flex-wrap: wrap;
    }

    .wiki-row-meta {
        order: 3;
        width: 100%;
        padding-left: 2.125rem;
    }
}

.wiki-recent {
    margin: 0;
    padding: 0;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    background: hsl(var(--card));
    list-style: none;
}

.wiki-recent-item {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
}

.wiki-recent-item + .wiki-recent-item {
    border-top: 1px solid hsl(var(--border));
}

.wiki-recent-title {
    color: hsl(var(--foreground));
    font-size: 0.9375rem;
    font-weight: 500;
    text-decoration: none;
}

.wiki-recent-title:hover {
    color: hsl(var(--primary));
    text-decoration: underline;
}

.wiki-recent-meta {
    margin-left: auto;
    color: hsl(var(--muted-foreground));
    font-size: 0.75rem;
    white-space: nowrap;
}

/* ── Previous / next ────────────────────────────────────────────────────── */

.wiki-pager {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    margin-top: 3rem;
}

.wiki-pager-link {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.875rem 1rem;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    background: hsl(var(--card));
    text-decoration: none;
    transition: border-color 0.12s ease;
}

.wiki-pager-link:hover {
    border-color: hsl(var(--primary) / 0.4);
}

.wiki-pager-next {
    text-align: right;
}

.wiki-pager-label {
    color: hsl(var(--muted-foreground));
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.wiki-pager-title {
    color: hsl(var(--foreground));
    font-size: 0.9375rem;
    font-weight: 500;
}

/* ═══ Rendered page content ══════════════════════════════════════════════ */

.wiki-prose {
    /* A measure, not a width: long lines of body copy are hard to read, and
       the page's column is sized to fit the rails beside it. */
    max-width: 74ch;
    color: hsl(var(--foreground));
    font-size: 1rem;
    line-height: 1.7;
}

.wiki-prose > *:first-child {
    margin-top: 0;
}

/*
 * Each top-level section gets a numbered badge, the way a runbook reads.
 * Counted in CSS so the Markdown stays plain and the anchors keep working.
 */
.wiki-prose {
    counter-reset: wiki-section;
}

.wiki-prose > .wiki-h2 {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    counter-increment: wiki-section;
}

.wiki-prose > .wiki-h2::before {
    content: counter(wiki-section);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    flex-shrink: 0;
    margin-right: 0.75rem;
    border-radius: 8px;
    background: hsl(var(--primary) / 0.1);
    color: hsl(var(--primary));
    font-size: 0.875rem;
    font-weight: 700;
}

.wiki-p {
    margin: 0 0 1rem;
}

.wiki-heading {
    position: relative;
    margin: 2rem 0 0.75rem;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -0.01em;
    scroll-margin-top: 5rem;   /* clears the sticky site header on an anchor jump */
}

.wiki-h1 { font-size: 1.75rem; }
.wiki-h2 { font-size: 1.4rem; }
.wiki-h3 { font-size: 1.2rem; }
.wiki-h4,
.wiki-h5,
.wiki-h6 { font-size: 1.05rem; }

.wiki-h2 {
    padding-bottom: 0.35rem;
    border-bottom: 1px solid hsl(var(--border));
}

/*
 * The permalink beside a heading. Hidden until the heading is hovered or the
 * link itself is focused — always visible it is clutter, never available it is
 * a feature nobody finds. Keyboard users get it on focus, which is why it is
 * transparent rather than display:none.
 */
.wiki-anchor {
    position: absolute;
    margin-left: 0.35rem;
    color: hsl(var(--muted-foreground));
    font-weight: 400;
    text-decoration: none;
    opacity: 0;
    transition: opacity 0.12s ease;
}

.wiki-heading:hover .wiki-anchor,
.wiki-anchor:focus-visible {
    opacity: 1;
}

.wiki-anchor:hover {
    color: hsl(var(--primary));
}

.wiki-list {
    margin: 0 0 1rem;
    padding-left: 1.5rem;
    list-style: disc;
}

.wiki-list-ordered {
    list-style: decimal;
}

.wiki-list .wiki-list {
    margin-bottom: 0;
    list-style: circle;
}

.wiki-list .wiki-list .wiki-list {
    list-style: square;
}

.wiki-list-item {
    margin: 0.25rem 0;
}

.wiki-quote {
    margin: 0 0 1.25rem;
    padding: 0.875rem 1.125rem;
    border: 1px solid hsl(var(--primary) / 0.18);
    border-left: 3px solid hsl(var(--primary) / 0.6);
    border-radius: var(--radius);
    background: hsl(var(--primary) / 0.05);
    color: hsl(var(--foreground));
    font-size: 0.9375rem;
}

.wiki-quote > *:last-child {
    margin-bottom: 0;
}

.wiki-rule {
    margin: 2rem 0;
    border: 0;
    border-top: 1px solid hsl(var(--border));
}

/* ── Code ───────────────────────────────────────────────────────────────── */

.wiki-code {
    padding: 0.125em 0.35em;
    border-radius: 4px;
    background: hsl(var(--muted));
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
    font-size: 0.875em;
}

.wiki-pre {
    margin: 0 0 1rem;
    padding: 0.875rem 1rem;
    /* Code is the one thing that must not be reflowed to fit, so it scrolls
       inside its own box rather than widening the page. */
    overflow-x: auto;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    background: hsl(var(--muted));
    line-height: 1.5;
}

.wiki-pre code {
    padding: 0;
    background: none;
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
    font-size: 0.8125rem;
    white-space: pre;
}

.wiki-pre[data-lang]::before {
    content: attr(data-lang);
    display: block;
    margin-bottom: 0.5rem;
    color: hsl(var(--muted-foreground));
    font-size: 0.6875rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

/*
 * The copy button is wrapped around <pre> by wiki.js rather than positioned
 * inside it: <pre> scrolls horizontally, and a button inside would slide out
 * of view with the code.
 */
.wiki-pre-wrap {
    position: relative;
}

.wiki-pre-wrap .wiki-pre {
    margin-bottom: 0;
}

.wiki-pre-wrap + * {
    margin-top: 1rem;
}

.wiki-copy {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: 0.25rem 0.5rem;
    border: 1px solid hsl(var(--border));
    border-radius: 4px;
    background: hsl(var(--card));
    color: hsl(var(--muted-foreground));
    font-size: 0.6875rem;
    font-weight: 600;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.12s ease;
}

.wiki-pre-wrap:hover .wiki-copy,
.wiki-copy:focus-visible {
    opacity: 1;
}

.wiki-copy:hover {
    color: hsl(var(--foreground));
}

.wiki-copy.is-done {
    opacity: 1;
    border-color: hsl(var(--success) / 0.5);
    color: hsl(var(--success));
}

/* ── Images ─────────────────────────────────────────────────────────────── */

.wiki-image {
    max-width: 100%;
    height: auto;              /* never distort: the pair is what preserves ratio */
    border-radius: calc(var(--radius) - 2px);
    vertical-align: middle;
}

/* A standalone image is a figure; one inside a sentence stays in the line. */
.wiki-figure {
    margin: 1.5rem 0;
}

.wiki-figure .wiki-image {
    display: block;
    border: 1px solid hsl(var(--border));
    background: hsl(var(--muted));   /* shows the frame while it loads */
}

.wiki-figcaption {
    margin-top: 0.5rem;
    color: hsl(var(--muted-foreground));
    font-size: 0.8125rem;
    line-height: 1.5;
}

/* An image we will not load from a third party — see WikiMarkdown::figure(). */
.wiki-image-blocked {
    color: hsl(var(--muted-foreground));
    font-size: 0.8125rem;
    font-style: italic;
}

/* ── Tables ─────────────────────────────────────────────────────────────── */

.wiki-table-wrap {
    margin: 0 0 1rem;
    overflow-x: auto;   /* wide tables scroll; the page body never does */
}

.wiki-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9375rem;
}

.wiki-table th,
.wiki-table td {
    padding: 0.5rem 0.75rem;
    border: 1px solid hsl(var(--border));
    text-align: left;
    vertical-align: top;
}

.wiki-table th {
    background: hsl(var(--muted));
    font-weight: 600;
}

.wiki-cell-center { text-align: center; }
.wiki-cell-right  { text-align: right; }

/* ── Links ──────────────────────────────────────────────────────────────── */

.wiki-link {
    color: hsl(var(--primary));
    text-decoration: underline;
    text-underline-offset: 2px;
}

.wiki-link:hover {
    text-decoration-thickness: 2px;
}

/*
 * A link to a page nobody has written. Deliberately loud: an unwritten page is
 * a gap in the handbook someone should fill, and the red-link convention is
 * how wikis have surfaced that for twenty years.
 */
.wiki-link-missing {
    color: hsl(var(--destructive));
    text-decoration-style: dashed;
}

/* ═══ Table of contents ══════════════════════════════════════════════════ */

.wiki-toc-inline {
    max-width: 74ch;
    margin: 0 0 2rem;
    padding: 1rem 1.25rem;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    background: hsl(var(--card));
}

.wiki-toc-title {
    margin: 0 0 0.5rem;
    color: hsl(var(--muted-foreground));
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.wiki-toc-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.wiki-toc-item {
    margin: 0;
    font-size: 0.8125rem;
    line-height: 1.4;
}

.wiki-toc-item a {
    display: block;
    padding: 0.3rem 0 0.3rem 0.6rem;
    border-left: 2px solid transparent;
    color: hsl(var(--muted-foreground));
    text-decoration: none;
}

.wiki-toc-item a:hover {
    color: hsl(var(--foreground));
}

.wiki-toc-level-3 a {
    padding-left: 1.4rem;
}

/* Set by wiki.js as the reader scrolls. */
.wiki-toc-item a.is-active {
    border-left-color: hsl(var(--primary));
    color: hsl(var(--primary));
    font-weight: 500;
}

/* ═══ Page tree ══════════════════════════════════════════════════════════ */

.wiki-tree {
    margin: 0;
    padding: 0;
    list-style: none;
}

.wiki-tree-item {
    padding: 0.35rem 0;
}

.wiki-tree-item + .wiki-tree-item {
    border-top: 1px solid hsl(var(--border));
}

.wiki-tree-link {
    color: hsl(var(--foreground));
    font-weight: 500;
    text-decoration: none;
}

.wiki-tree-link:hover {
    color: hsl(var(--primary));
    text-decoration: underline;
}

.wiki-tree-summary {
    display: block;
    color: hsl(var(--muted-foreground));
    font-size: 0.8125rem;
}

/* Four fixed steps rather than a computed margin, so a deeply nested page
   cannot indent itself off the right-hand edge. */
.wiki-tree-depth-1 { padding-left: 1rem; }
.wiki-tree-depth-2 { padding-left: 2rem; }
.wiki-tree-depth-3 { padding-left: 3rem; }

.wiki-tree .wiki-tree {
    margin-top: 0.35rem;
    border-top: 1px solid hsl(var(--border));
}

/* ── Compact variant, for the sidebar ───────────────────────────────────── */

.wiki-tree-compact,
.wiki-tree-compact .wiki-tree {
    border: 0;
}

.wiki-tree-compact .wiki-tree-item,
.wiki-tree-compact .wiki-tree-item + .wiki-tree-item {
    padding: 0;
    border-top: 0;
}

.wiki-tree-compact .wiki-tree-link {
    display: block;
    padding: 0.3rem 0.5rem;
    border-left: 2px solid transparent;
    border-radius: 0 4px 4px 0;
    color: hsl(var(--muted-foreground));
    font-size: 0.8125rem;
    font-weight: 400;
    line-height: 1.4;
}

.wiki-tree-compact .wiki-tree-link:hover {
    background: hsl(var(--accent));
    color: hsl(var(--foreground));
    text-decoration: none;
}

.wiki-tree-compact .wiki-tree-link.is-current {
    border-left-color: hsl(var(--primary));
    background: hsl(var(--primary) / 0.08);
    color: hsl(var(--primary));
    font-weight: 600;
}

.wiki-tree-compact.wiki-tree-depth-1 { padding-left: 0.75rem; }
.wiki-tree-compact.wiki-tree-depth-2 { padding-left: 1.5rem; }
.wiki-tree-compact.wiki-tree-depth-3 { padding-left: 2.25rem; }

/* ═══ Small pieces ═══════════════════════════════════════════════════════ */

.wiki-chip {
    display: inline-block;
    margin-left: 0.35rem;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    vertical-align: middle;
}

.wiki-chip-draft {
    border: 1px solid hsl(var(--border));
    background: hsl(var(--muted));
    color: hsl(var(--muted-foreground));
    font-weight: 500;
}

.wiki-chip-dept {
    background: hsl(var(--primary) / 0.1);
    color: hsl(var(--primary));
    border: 1px solid hsl(var(--primary) / 0.2);
}

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

/* ═══ Admin editor ═══════════════════════════════════════════════════════ */

.wiki-editor-shell {
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    background: hsl(var(--card));
    overflow: hidden;
}

.wiki-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.15rem;
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid hsl(var(--border));
    background: hsl(var(--muted) / 0.5);
}

.wiki-tool {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    height: 2rem;
    padding: 0 0.45rem;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: hsl(var(--muted-foreground));
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.12s ease, color 0.12s ease;
}

.wiki-tool:hover {
    background: hsl(var(--card));
    border-color: hsl(var(--border));
    color: hsl(var(--foreground));
}

.wiki-tool:focus-visible {
    outline: 2px solid hsl(var(--ring));
    outline-offset: 1px;
}

.wiki-tool svg {
    width: 1rem;
    height: 1rem;
}

.wiki-tool-sep {
    width: 1px;
    height: 1.25rem;
    margin: 0 0.3rem;
    background: hsl(var(--border));
}

.wiki-tool-spacer {
    margin-left: auto;
}

/* ── Write / preview tabs ───────────────────────────────────────────────── */

.wiki-tabs {
    display: inline-flex;
    gap: 0.15rem;
    padding: 0.15rem;
    border-radius: 6px;
    background: hsl(var(--muted));
}

.wiki-tab {
    padding: 0.3rem 0.7rem;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: hsl(var(--muted-foreground));
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
}

.wiki-tab.is-active {
    background: hsl(var(--card));
    color: hsl(var(--foreground));
    box-shadow: 0 1px 2px hsl(0 0% 0% / 0.06);
}

.wiki-tab:focus-visible {
    outline: 2px solid hsl(var(--ring));
    outline-offset: 1px;
}

.wiki-editor {
    display: block;
    width: 100%;
    min-height: 30rem;
    padding: 1rem 1.125rem;
    border: 0;
    background: transparent;
    color: hsl(var(--foreground));
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
    font-size: 0.875rem;
    line-height: 1.7;
    tab-size: 4;
    resize: vertical;
}

.wiki-editor:focus-visible {
    outline: 0;
}

.wiki-preview {
    min-height: 30rem;
    padding: 1rem 1.125rem;
}

.wiki-preview-placeholder {
    color: hsl(var(--muted-foreground));
    font-size: 0.875rem;
}

/*
 * Side by side above the breakpoint, one pane at a time below it. The JS
 * toggles [hidden] on the panes; this only decides how many can be on screen
 * at once.
 */
.wiki-editor-panes {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
}

/* Below the breakpoint the two panes stack, so the divider between them has
   to be a top border rather than a left one. */
.wiki-editor-panes.is-split .wiki-preview {
    border-top: 1px solid hsl(var(--border));
}

@media (min-width: 64rem) {
    .wiki-editor-panes.is-split {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .wiki-editor-panes.is-split .wiki-preview {
        border-top: 0;
        border-left: 1px solid hsl(var(--border));
    }
}

.wiki-editor-status {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    padding: 0.4rem 0.75rem;
    border-top: 1px solid hsl(var(--border));
    background: hsl(var(--muted) / 0.5);
    color: hsl(var(--muted-foreground));
    font-size: 0.75rem;
}

.wiki-editor-dirty {
    margin-left: auto;
    color: hsl(var(--destructive));
    font-weight: 600;
}

/* Drop target feedback while an image is dragged over the textarea. */
.wiki-editor.is-dropping {
    outline: 2px dashed hsl(var(--primary));
    outline-offset: -4px;
    background: hsl(var(--primary) / 0.04);
}

.wiki-upload-status:not(:empty) {
    color: hsl(var(--muted-foreground));
}

.wiki-upload-status.is-error {
    color: hsl(var(--destructive));
    font-weight: 600;
}

/* ── Image library ──────────────────────────────────────────────────────── */

.wiki-image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
    gap: 1rem;
}

.wiki-image-tile {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 0;
    padding: 0.75rem;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    background: hsl(var(--card));
}

.wiki-image-thumb {
    display: block;
    width: 100%;
    /* Uniform tiles from images of wildly different shapes, without letting a
       tall screenshot stretch one row to the height of the page. */
    height: 9rem;
    object-fit: contain;
    border-radius: calc(var(--radius) - 4px);
    background: hsl(var(--muted));
}

.wiki-image-meta {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    color: hsl(var(--muted-foreground));
    font-size: 0.75rem;
}

.wiki-image-name {
    overflow: hidden;
    color: hsl(var(--foreground));
    font-weight: 500;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.wiki-image-markdown {
    min-height: 2rem;
    padding: 0.3rem 0.5rem;
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
    font-size: 0.6875rem;
}

.wiki-upload-form .wiki-field {
    margin-bottom: 0.75rem;
}

.wiki-slug-preview {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
}

/* ── Markdown reference ─────────────────────────────────────────────────── */

.wiki-cheatsheet {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    gap: 0.35rem 1rem;
    margin: 0;
    font-size: 0.8125rem;
    line-height: 1.5;
}

.wiki-cheatsheet dt {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
    color: hsl(var(--foreground));
    white-space: nowrap;
}

.wiki-cheatsheet dd {
    margin: 0;
    color: hsl(var(--muted-foreground));
}

/* ═══ Admin form layout ══════════════════════════════════════════════════ */

.wiki-form-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.wiki-form-context {
    margin: 0;
    color: hsl(var(--muted-foreground));
    font-size: 0.8125rem;
}

.wiki-form-context a {
    color: hsl(var(--primary));
}

.wiki-server-preview {
    margin-bottom: 1rem;
}

/*
 * Writing on the left, filing on the right. The settings are real but they
 * are not what anyone opened this screen to do, and a stack of selects above
 * the editor pushes the actual work below the fold.
 */
.wiki-form-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1.25rem;
    align-items: start;
}

@media (min-width: 64rem) {
    .wiki-form-grid {
        grid-template-columns: minmax(0, 1fr) 19rem;
    }

    .wiki-form-side {
        position: sticky;
        top: 1rem;
    }
}

.wiki-form-main {
    min-width: 0;
}

.wiki-form-side {
    display: grid;
    gap: 1rem;
}

.wiki-form-card {
    padding: 1.125rem;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    background: hsl(var(--card));
}

.wiki-form-danger {
    border-color: hsl(var(--destructive) / 0.35);
}

.wiki-form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}

.wiki-field {
    margin-bottom: 1rem;
}

.wiki-form-card .wiki-field:last-of-type,
.wiki-form-main .wiki-field:last-child {
    margin-bottom: 0;
}

.wiki-label {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.8125rem;
    font-weight: 500;
}

.wiki-input {
    display: block;
    width: 100%;
    min-height: 2.5rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid hsl(var(--input));
    border-radius: calc(var(--radius) - 2px);
    background: hsl(var(--background));
    color: hsl(var(--foreground));
    font-family: inherit;
    font-size: 0.875rem;
}

.wiki-input::placeholder {
    color: hsl(var(--muted-foreground));
}

.wiki-input:focus-visible {
    outline: 2px solid hsl(var(--ring));
    outline-offset: -1px;
}

.wiki-input-title {
    min-height: 3rem;
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.wiki-help {
    display: block;
    margin: 0.35rem 0 0;
    color: hsl(var(--muted-foreground));
    font-size: 0.75rem;
    line-height: 1.5;
}

.wiki-help a {
    color: hsl(var(--primary));
    text-decoration: underline;
}

.wiki-check {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    cursor: pointer;
}

.wiki-check input {
    margin-top: 0.15rem;
    flex: none;
}

.wiki-check-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
}

.wiki-reference {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    background: hsl(var(--card));
}

.wiki-reference > summary {
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
}

.wiki-reference[open] > summary {
    margin-bottom: 0.75rem;
}

/* ═══ Revision history ═══════════════════════════════════════════════════ */

.wiki-revision-body {
    max-height: 28rem;
    overflow: auto;
    padding: 0.875rem 1rem;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    background: hsl(var(--muted));
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
    font-size: 0.8125rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ═══ References picker ════════════════════════════════════ */

/* Prefixed wiki-*, and defined here rather than as Tailwind utilities,
   because references.js builds chips at runtime and the scanner cannot see a
   class name that only exists inside a JavaScript string. */

.wiki-ref-list {
    list-style: none;
    margin: 0 0 0.5rem;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.wiki-ref-chip {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.375rem 0.5rem;
    border: 1px solid hsl(var(--border));
    border-radius: calc(var(--radius) - 2px);
    background: hsl(var(--muted) / 0.4);
    font-size: 0.8125rem;
}

.wiki-ref-kind {
    flex: none;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: hsl(var(--muted-foreground));
}

.wiki-ref-title {
    flex: 1 1 auto;
    min-width: 0;
    word-break: break-word;
}

.wiki-ref-remove {
    flex: none;
    border: 0;
    background: none;
    cursor: pointer;
    padding: 0 0.25rem;
    font-size: 1rem;
    line-height: 1;
    color: hsl(var(--muted-foreground));
}

.wiki-ref-remove:hover,
.wiki-ref-remove:focus-visible {
    color: hsl(var(--destructive));
}

.wiki-ref-empty,
.wiki-ref-status {
    margin: 0 0 0.5rem;
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}

.wiki-ref-picker {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.wiki-ref-results {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 15rem;
    overflow-y: auto;
    border: 1px solid hsl(var(--border));
    border-radius: calc(var(--radius) - 2px);
}

.wiki-ref-result {
    display: block;
    width: 100%;
    text-align: left;
    border: 0;
    border-bottom: 1px solid hsl(var(--border));
    background: none;
    cursor: pointer;
    padding: 0.5rem 0.625rem;
    font: inherit;
    color: inherit;
}

.wiki-ref-results li:last-child .wiki-ref-result {
    border-bottom: 0;
}

.wiki-ref-result:hover,
.wiki-ref-result:focus-visible {
    background: hsl(var(--muted) / 0.6);
}

.wiki-ref-result-title {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
}

.wiki-ref-result-meta {
    display: block;
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}

/* ═══ Motion ═════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
    .wiki-btn,
    .wiki-card,
    .wiki-space-card,
    .wiki-pager-link,
    .wiki-anchor,
    .wiki-copy,
    .wiki-tool {
        transition: none;
    }
}

/* ── Sidebar tree: a page icon per entry, chips tucked under the title ──── */

.wiki-sidebar .wiki-tree-compact .wiki-tree-link {
    position: relative;
    padding: 0.45rem 0.5rem 0.45rem 2rem;
    border-left: 0;
    border-radius: 6px;
}

.wiki-sidebar .wiki-tree-compact .wiki-tree-link::before {
    content: "";
    position: absolute;
    top: 0.55rem;
    left: 0.6rem;
    width: 0.95rem;
    height: 0.95rem;
    background: currentColor;
    opacity: 0.8;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z'/%3E%3Cpath d='M14 2v4a2 2 0 0 0 2 2h4'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z'/%3E%3Cpath d='M14 2v4a2 2 0 0 0 2 2h4'/%3E%3C/svg%3E") center / contain no-repeat;
}

.wiki-sidebar .wiki-tree-compact .wiki-tree-link.is-current {
    box-shadow: inset 2px 0 0 hsl(var(--primary));
}

.wiki-sidebar .wiki-tree-compact .wiki-chip {
    margin: 0 0.25rem 0.3rem 2rem;
}

.wiki-sidebar .wiki-tree-compact .wiki-chip + .wiki-chip {
    margin-left: 0;
}

@media (max-width: 40rem) {
    .wiki-space-card {
        gap: 1rem;
        padding: 1rem;
    }

    .wiki-space-icon {
        width: 3rem;
        height: 3rem;
    }

    .wiki-space-icon svg {
        width: 1.5rem;
        height: 1.5rem;
    }

    .wiki-hero-title {
        font-size: 2.25rem;
    }
}
