/* === Base Reset & Variables === */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Global focus styles for keyboard accessibility */
*:focus-visible {
    outline: 2px solid var(--color-accent, #4a9e6b);
    outline-offset: 2px;
}

:root {
    --color-primary: #1a4d2e;
    --color-primary-light: #2a6e42;
    --color-accent: #4a9e6b;
    --color-accent-light: #e0f2e9;
    --color-amended: #d97706;
    --color-amended-bg: #fffbeb;
    --color-amended-border: #f59e0b;
    --color-added: #059669;
    --color-added-bg: #ecfdf5;
    --color-added-border: #10b981;
    --color-text: #1e293b;
    --color-text-light: #64748b;
    --color-bg: #ffffff;
    --color-bg-alt: #f8fafc;
    --color-border: #e2e8f0;
    --color-link: #1d6b3f;
    --sidebar-width: 420px;
    --header-height: auto;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-reading: 'Source Serif 4', Georgia, serif;
    --radius: 8px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
}

[data-theme="dark"] {
    --color-primary: #1b3a2a;
    --color-primary-light: #3d7a55;
    --color-accent: #6dcea0;
    --color-accent-light: #1c2e25;
    --color-amended: #f0b040;
    --color-amended-bg: #2a2211;
    --color-amended-border: #d4960e;
    --color-added: #4ade96;
    --color-added-bg: #0f2920;
    --color-added-border: #34d399;
    --color-text: #e2e8f0;
    --color-text-light: #94a3b8;
    --color-bg: #0f172a;
    --color-bg-alt: #1e293b;
    --color-border: #334155;
    --color-link: #6dcea0;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
}

html {
    /* scroll-behavior: smooth removed — it made window.scrollTo(0,0) on chapter
       changes animate through old content. Section navigation uses explicit
       scrollIntoView({ behavior: 'smooth' }) instead. */
}

body {
    font-family: var(--font-sans);
    color: var(--color-text);
    background: var(--color-bg-alt);
    line-height: 1.6;
    min-height: 100vh;
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* === Header === */
.site-header {
    background: var(--color-primary);
    color: #fff;
    padding: 0.875rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* iOS Safari / iPadOS has a long-standing bug where position: sticky
   elements detach during URL-bar show/hide transitions, leaving a
   transparent gap that reveals the content behind. GPU layer hints
   only mask the flicker — switching to position: fixed is the only
   thing that truly freezes the header at the top of the viewport.
   Scoped to touch devices so desktop layout is unchanged. The chat
   page (body.chat-fullheight) already has its own scroll-lock layout
   that keeps the header in flex flow, so we exclude it. */
@media (pointer: coarse) {
    body:not(.chat-fullheight) .site-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
    }
    body:not(.chat-fullheight) .app-layout {
        padding-top: var(--header-height, 60px);
    }
}

.header-content {
    flex: 1;
    min-width: 200px;
}

.site-header h1 {
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
}

.site-header h1 a {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.header-icon {
    flex-shrink: 0;
}

.home-link {
    color: inherit;
    text-decoration: none;
}

.home-link:hover {
    opacity: 0.85;
}

.header-beta-group {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}

.header-beta-badge {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    background: #e67e22;
    color: #fff;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    line-height: 1;
}

.header-feedback-link {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.65);
    text-decoration: none;
    font-weight: 400;
}

.header-feedback-link:hover {
    color: #fff;
    text-decoration: underline;
}

.subtitle {
    font-size: 0.75rem;
    opacity: 0.7;
    font-weight: 400;
}

.version-link {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.65);
    text-decoration: none;
    font-weight: 400;
}

.version-link:hover {
    color: #fff;
    text-decoration: underline;
}

/* Theme Toggle */
.theme-toggle {
    background: none;
    border: 1px solid rgba(255,255,255,0.2);
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    transition: color 0.15s, background 0.15s;
    font-family: var(--font-sans);
    font-size: 0.75rem;
    white-space: nowrap;
    flex-shrink: 0;
}
.theme-toggle:hover { color: #fff; background: rgba(255,255,255,0.1); }
.theme-toggle .icon-moon { display: none; }
.theme-label-light { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-label-dark { display: none; }
[data-theme="dark"] .theme-label-light { display: inline; }

/* Dark mode: elements that use --color-primary need brighter variants */
[data-theme="dark"] .so-table thead th {
    background: var(--color-primary-light);
}

[data-theme="dark"] .so-table-category td {
    color: var(--color-accent);
}

/* Dark mode: headings need a lighter green to be readable */
[data-theme="dark"] .chapter-heading,
[data-theme="dark"] .welcome-title,
[data-theme="dark"] .welcome h2,
[data-theme="dark"] .section-heading,
[data-theme="dark"] .so-definitions dt,
[data-theme="dark"] .resolution-title {
    color: var(--color-accent);
}

[data-theme="dark"] .search-result-snippet mark,
[data-theme="dark"] .search-page-item-snippet mark {
    background: #854d0e;
    color: #fef08a;
}

/* Dark mode: hamburger bars */
[data-theme="dark"] .sidebar-toggle span {
    background: #e2e8f0;
}

/* Dark mode: chat input field */
[data-theme="dark"] .chat-input-wrap {
    background: var(--color-bg-alt);
}

[data-theme="dark"] .chat-input-wrap textarea {
    background: transparent;
    color: var(--color-text);
}

/* Hamburger menu toggle */
.nav-menu-toggle {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    flex-shrink: 0;
}

.nav-menu-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: #fff;
    border-radius: 1px;
    transition: transform 0.2s;
}

/* Navigation dropdown menu */
.nav-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    height: 100dvh;
    background: var(--color-bg);
    z-index: 300;
    overflow-y: auto;
    box-shadow: 2px 0 12px rgba(0,0,0,0.15);
    padding: 1rem 0;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
}

.nav-menu[hidden] {
    display: block;
    transform: translateX(-100%);
}

.nav-menu.open {
    transform: translateX(0);
}

.nav-menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    color: var(--color-text);
    text-decoration: none;
    font-family: var(--font-ui);
    font-size: 0.88rem;
    font-weight: 500;
    transition: background 0.15s;
}

.nav-menu-item:hover {
    background: var(--color-accent-light);
    color: var(--color-accent);
}

.nav-menu-item svg {
    flex-shrink: 0;
    color: var(--color-text-light);
}

.nav-menu-item:hover svg {
    color: var(--color-accent);
}

.nav-menu-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 250;
}

.nav-menu-overlay.visible {
    display: block;
}

/* Legacy sidebar toggle — keep for sidebar-only pages */
.sidebar-toggle {
    display: none;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
}

.sidebar-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: #fff;
    border-radius: 1px;
    transition: transform 0.2s;
}

/* Search */
.search-container {
    position: relative;
    width: 320px;
    flex-shrink: 1;
    flex-grow: 1;
}

#searchInput {
    width: 100%;
    padding: 0.5rem 3.75rem 0.5rem 0.75rem;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: var(--radius);
    background: rgba(255,255,255,0.1);
    color: #fff;
    font-size: 0.875rem;
    font-family: var(--font-sans);
    outline: none;
    transition: all 0.2s;
}

.search-tips-btn {
    position: absolute;
    top: 50%;
    right: 30px;
    transform: translateY(-50%);
    background: none;
    border: 1px solid rgba(255,255,255,0.3);
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: 700;
    font-family: var(--font-sans);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    z-index: 1;
    padding: 0;
    line-height: 1;
}

.search-tips-btn:hover {
    color: #fff;
    border-color: rgba(255,255,255,0.6);
}

.search-submit-btn {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s;
    z-index: 1;
}

.search-submit-btn:hover {
    color: #fff;
}

.search-tips-popover {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    width: 340px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 0.875rem 1rem;
    z-index: 200;
}

.search-tips-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text);
    margin-bottom: 0.5rem;
}

.search-tips-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 0.625rem;
}

.search-tips-table td {
    padding: 0.25rem 0;
    font-size: 0.8rem;
    color: var(--color-text);
    vertical-align: top;
}

.search-tips-table td:first-child {
    width: 130px;
    padding-right: 0.75rem;
}

.search-tips-table code {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--color-accent);
    background: var(--color-bg-alt);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
}

.search-tips-hint {
    font-size: 0.75rem;
    color: var(--color-text-light);
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

.search-tips-advanced {
    display: inline-block;
    font-size: 0.78rem;
    color: var(--color-link);
    text-decoration: none;
    font-weight: 500;
}

.search-tips-advanced:hover {
    text-decoration: underline;
}

#searchInput::placeholder {
    color: rgba(255,255,255,0.5);
}

#searchInput:focus {
    background: rgba(255,255,255,0.15);
    border-color: rgba(255,255,255,0.4);
    box-shadow: 0 0 0 3px rgba(74,158,107,0.3);
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: var(--shadow-lg);
    max-height: 400px;
    overflow-y: auto;
    z-index: 200;
}

.search-result-item {
    padding: 0.625rem 0.875rem;
    border-bottom: 1px solid var(--color-border);
    cursor: pointer;
    color: var(--color-text);
    transition: background 0.15s;
}

.search-result-item:hover {
    background: var(--color-accent-light);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-number {
    font-weight: 600;
    color: var(--color-accent);
    font-size: 0.8rem;
}

.search-result-title {
    font-size: 0.85rem;
    margin-left: 0.25rem;
}

.search-result-chapter {
    font-size: 0.72rem;
    color: var(--color-text-light);
    margin-top: 2px;
}

.search-result-snippet {
    font-size: 0.78rem;
    color: var(--color-text-light);
    margin-top: 4px;
    line-height: 1.4;
}

.search-result-snippet mark {
    background: #fef08a;
    color: var(--color-text);
    padding: 0 2px;
    border-radius: 2px;
}

.search-no-results {
    padding: 1rem;
    color: var(--color-text-light);
    font-size: 0.875rem;
    text-align: center;
}

.search-fuzzy-note {
    padding: 0.5rem 1rem;
    color: var(--color-text-light);
    font-size: 0.78rem;
    font-style: italic;
}

/* === Full Search Results Page === */
.search-page {
    max-width: 800px;
}

.search-page-bar {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
    position: sticky;
    top: -1.5rem;
    z-index: 5;
    background: var(--color-bg-alt);
    margin: -1.5rem -1.5rem 1rem -1.5rem;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--color-border);
}

.search-page-input-wrap {
    position: relative;
    display: flex;
}

.search-page-input-wrap .search-page-input {
    padding-right: 2.5rem;
}

.search-page-submit {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 2.5rem;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-light);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s;
}

.search-page-submit:hover {
    color: var(--color-accent);
}

.search-page-input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 0.925rem;
    font-family: var(--font-sans);
}

.search-page-input:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 2px rgba(22, 101, 52, 0.15);
}

.search-page-doc-toggle {
    display: flex;
    gap: 1px;
}

.search-page-doc-toggle .header-doc-btn {
    background: var(--color-bg-alt);
    color: var(--color-text-light);
    border-color: var(--color-border);
}

.search-page-doc-toggle .header-doc-btn.active {
    background: var(--color-accent);
    color: #fff;
    border-color: var(--color-accent);
}

.search-page-doc-toggle .header-doc-btn:hover:not(.active) {
    background: var(--color-accent-light);
    color: var(--color-accent);
}

.search-page-count {
    color: var(--color-text-light);
    font-size: 0.875rem;
    margin-bottom: 1.5rem;
}

.search-page-empty {
    color: var(--color-text-light);
    font-size: 0.95rem;
    padding: 2rem 0;
}

.search-page-item {
    padding: 1rem 1.25rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.search-page-item:hover {
    border-color: var(--color-accent);
    box-shadow: var(--shadow-sm);
}

.search-page-item-header {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.search-page-item-number {
    font-weight: 600;
    color: var(--color-accent);
    font-size: 0.875rem;
    white-space: nowrap;
}

.search-page-item-title {
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--color-text);
}

.search-page-item-chapter {
    font-size: 0.78rem;
    color: var(--color-text-light);
    margin-bottom: 0.375rem;
}

.search-page-item-snippet {
    font-size: 0.85rem;
    color: var(--color-text-light);
    line-height: 1.5;
}

.search-page-item-snippet mark {
    background: #fef08a;
    color: var(--color-text);
    padding: 0 2px;
    border-radius: 2px;
}

/* === Search Split Layout === */
.content.search-mode {
    padding: 0;
    overflow: hidden;
}

.search-split-layout {
    display: flex;
    gap: 0;
    height: calc(100vh - var(--header-actual-height, 60px));
}

.search-results-pane {
    width: 38%;
    min-width: 380px;
    max-width: 600px;
    flex-shrink: 0;
    overflow-y: auto;
    padding: 1.5rem;
    border-right: 1px solid var(--color-border);
    background: var(--color-bg-alt);
}

.search-results-pane .search-page {
    max-width: none;
}

.search-results-pane .chapter-heading {
    font-size: 1.1rem;
}

.search-results-pane .search-page-item {
    padding: 0.625rem 0.875rem;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
}

.search-results-pane .search-page-item.active {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 2px var(--color-accent);
    background: var(--color-accent-light);
}

.search-results-pane .search-page-item-number {
    font-size: 0.8rem;
}

.search-results-pane .search-page-item-title {
    font-size: 0.85rem;
}

.search-results-pane .search-page-item-snippet {
    font-size: 0.78rem;
}

.search-preview-pane {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 2rem;
    min-width: 0;
}

.search-preview-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 300px;
    color: var(--color-text-light);
    opacity: 0.5;
    gap: 0.75rem;
    text-align: center;
    font-size: 0.9rem;
}

.search-preview-content {
    max-width: 800px;
}

.search-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--color-border);
    gap: 1rem;
}

.search-preview-chapter {
    font-size: 0.82rem;
    color: var(--color-text-light);
    font-weight: 500;
}

.search-preview-open {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.65rem;
    font-size: 0.75rem;
    font-family: var(--font-sans);
    color: var(--color-link);
    background: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    white-space: nowrap;
    transition: border-color 0.15s, background 0.15s;
}

.search-preview-open:hover {
    border-color: var(--color-accent);
    background: var(--color-accent-light);
}

/* === Search Sort Bar === */
.search-sort-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.search-sort-bar .sort-label {
    font-size: 0.78rem;
    color: var(--color-text-light);
    font-weight: 500;
    margin-right: 0.25rem;
}

.search-sort-btn {
    display: inline-block;
    padding: 0.3rem 0.75rem;
    font-size: 0.78rem;
    font-family: var(--font-sans);
    color: var(--color-text-light);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 100px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.search-sort-btn:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
}

.search-sort-btn.active {
    background: var(--color-accent);
    color: #fff;
    border-color: var(--color-accent);
}

.search-advanced-link {
    margin-left: auto;
    font-size: 0.78rem;
    color: var(--color-link);
    background: none;
    border: none;
    cursor: pointer;
    font-family: var(--font-sans);
    text-decoration: underline;
    padding: 0.3rem 0;
}

.search-advanced-link:hover {
    color: var(--color-accent);
}

/* === Advanced Search === */
.advanced-search-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.advanced-search-bar .advanced-search-input {
    flex: 1;
    margin-bottom: 0;
}

.advanced-search-bar .advanced-search-btn {
    margin-bottom: 0;
    white-space: nowrap;
}

.advanced-search-details {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 1rem;
    background: var(--color-bg-alt);
}

.advanced-search-summary {
    padding: 0.625rem 1rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--color-text);
    cursor: pointer;
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.advanced-search-summary::-webkit-details-marker {
    display: none;
}

.advanced-search-summary::before {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 5px solid var(--color-text-light);
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    transition: transform 0.15s;
}

.advanced-search-details[open] > .advanced-search-summary::before {
    transform: rotate(90deg);
}

.advanced-search-details > .advanced-search-operators {
    padding: 0 1rem;
    margin-bottom: 0.5rem;
}

.advanced-search-details > .advanced-search-filter-group {
    margin: 0 1rem 1rem;
}

.advanced-search {
    max-width: 900px;
}

.advanced-search-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    font-family: var(--font-sans);
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
    color: var(--color-text);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    margin-bottom: 1.25rem;
}

.advanced-search-input:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(74,158,107,0.15);
}

.advanced-search-operators {
    margin-bottom: 1.5rem;
}

.advanced-search-operators h4 {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text);
    margin-bottom: 0.75rem;
}

.operator-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.operator-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.operator-syntax {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--color-accent);
    background: none;
    padding: 0;
}

.operator-desc {
    font-size: 0.82rem;
    color: var(--color-text-light);
    line-height: 1.4;
}

.operator-example {
    font-size: 0.78rem;
    color: var(--color-text-light);
}

.operator-try {
    background: none;
    border: none;
    color: var(--color-link);
    font-family: monospace;
    font-size: 0.78rem;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
    text-decoration-style: dashed;
}

.operator-try:hover {
    color: var(--color-accent);
}

.operator-combine {
    font-size: 0.82rem;
    color: var(--color-text-light);
}

.advanced-search-filters {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.advanced-search-filter-group {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1rem;
}

.advanced-search-filter-group h4 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.advanced-search-filter-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.82rem;
    color: var(--color-text);
    padding: 0.2rem 0;
    cursor: pointer;
}

.advanced-search-filter-group label:hover {
    color: var(--color-accent);
}

.advanced-search-filter-group input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--color-accent);
    cursor: pointer;
    flex-shrink: 0;
}

.advanced-search-chapters {
    max-height: 200px;
    overflow-y: auto;
    padding-right: 0.25rem;
}

.advanced-search-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1.25rem;
    font-size: 0.85rem;
    font-family: var(--font-sans);
    font-weight: 600;
    color: #fff;
    background: var(--color-accent);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 2rem;
}

.advanced-search-btn:hover {
    background: var(--color-primary-light);
}

@media (max-width: 900px) {
    .operator-grid {
        grid-template-columns: 1fr;
    }
}

/* === Layout === */
.app-layout {
    display: flex;
    min-height: calc(100vh - 60px);
}

/* === Sidebar === */
.sidebar {
    width: var(--sidebar-width);
    background: var(--color-bg);
    border-right: 1px solid var(--color-border);
    overflow-y: auto;
    position: sticky;
    top: var(--header-height, 60px);
    height: calc(100vh - var(--header-height, 60px));
    flex-shrink: 0;
    transition: width 0.25s ease, min-width 0.25s ease;
    overscroll-behavior: contain;
}

.sidebar.collapsed {
    width: 0;
    min-width: 0;
    overflow: hidden;
    border-right: none;
}

.sidebar.collapsed ~ .content {
    padding-left: 2rem;
}

.sidebar-hidden {
    display: none !important;
}

.sidebar-hidden ~ .content {
    padding-left: 2rem;
}

/* Expand "hover strip" — shown when sidebar is collapsed.
   The button itself is a wide invisible hover/click target running down the
   left edge; a small chevron handle reveals on hover so the affordance stays
   quiet until the user reaches for it. */
.sidebar-expand-btn {
    position: fixed;
    left: 0;
    top: var(--header-height, 60px);
    z-index: 9999;
    width: 18px;
    height: calc(100vh - var(--header-height, 60px));
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
    display: none;
    color: var(--color-text-light);
}

.sidebar-expand-btn.visible {
    display: block;
}

.sidebar-expand-handle {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.4rem;
    padding: 0 0.65rem 0 0.45rem;
    height: 36px;
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-left: none;
    border-radius: 0 8px 8px 0;
    color: var(--color-text);
    box-shadow: 1px 1px 3px rgba(15, 23, 42, 0.06);
    transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
    pointer-events: auto;
}

.sidebar-expand-handle svg {
    flex-shrink: 0;
}

.sidebar-expand-label {
    font-family: var(--font-ui);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-light);
    max-width: 0;
    overflow: hidden;
    white-space: nowrap;
    transition: max-width 0.2s ease, color 0.15s;
}

.sidebar-expand-btn:hover .sidebar-expand-handle,
.sidebar-expand-btn:focus-visible .sidebar-expand-handle {
    background: var(--color-bg);
    border-color: var(--color-text-light);
    color: var(--color-text);
    box-shadow: 2px 2px 6px rgba(15, 23, 42, 0.1);
}

.sidebar-expand-btn:hover .sidebar-expand-label,
.sidebar-expand-btn:focus-visible .sidebar-expand-label {
    max-width: 80px;
    color: var(--color-text);
}

.sidebar-expand-btn:focus-visible {
    outline: none;
}

.nav-header {
    padding: 0.75rem 1rem 0.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-header h2 {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-light);
    font-weight: 600;
}

.sidebar-collapse-btn {
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    color: var(--color-text-light);
    padding: 4px 6px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.sidebar-collapse-btn:hover {
    color: var(--color-text);
    background: var(--color-bg-alt);
    border-color: var(--color-border);
}

.sidebar-home-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: calc(100% - 1rem);
    margin: 0.25rem 0.5rem;
    padding: 0.5rem 0.75rem;
    background: none;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--color-text-light);
    transition: background 0.15s, color 0.15s;
}

.sidebar-home-btn:hover {
    background: var(--color-accent-light);
    color: var(--color-accent);
}

.sidebar-home-btn svg {
    flex-shrink: 0;
}

.chapter-list {
    list-style: none;
    padding: 0 0 1rem;
}

.chapter-item {
    border-bottom: 1px solid var(--color-border);
}

.chapter-btn {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    width: 100%;
    padding: 0.6rem 1rem;
    background: var(--color-bg-alt);
    border: none;
    cursor: pointer;
    text-align: left;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: var(--font-sans);
    color: var(--color-text);
    transition: all 0.15s;
    line-height: 1.4;
}

.chapter-label {
    flex: 1;
}

.chapter-btn:hover {
    background: var(--color-bg-alt);
    color: var(--color-accent);
}

.chapter-btn.active {
    background: var(--color-accent);
    color: #fff;
}

.chapter-num {
    font-weight: 600;
    color: var(--color-accent);
    white-space: nowrap;
    min-width: 1.5em;
}

.chapter-btn.active .chapter-num {
    color: rgba(255,255,255,0.8);
}

.nav-range {
    display: block;
    font-size: 0.75rem;
    color: var(--color-text-light);
    font-weight: 400;
    margin-top: 1px;
    opacity: 0.7;
}

.chapter-btn.active .nav-range {
    color: rgba(255,255,255,0.55);
}

.section-list {
    list-style: none;
    display: none;
    padding: 0.25rem 0 0.5rem;
    margin-left: 0;
    border-left: none;
    background: var(--color-bg);
}

.chapter-item.expanded .section-list {
    display: block;
}

.section-btn {
    display: block;
    width: 100%;
    padding: 0.35rem 1rem 0.35rem 2.25rem;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    font-size: 0.84rem;
    font-family: var(--font-sans);
    color: var(--color-text-light);
    transition: all 0.15s;
    line-height: 1.4;
    font-weight: 400;
}

.section-btn:hover {
    background: var(--color-bg-alt);
    color: var(--color-text);
}

.section-btn.active-section {
    background: var(--color-accent-light);
    color: var(--color-primary-light);
    font-weight: 500;
    border-left: 2px solid var(--color-accent);
    padding-left: calc(2.25rem - 2px);
}

/* Constitution section leaves — individual sections nested under a Part
   heading (or directly under a chapter). Smaller, slightly more indented
   so they read as leaves rather than peers of the Part heading. */
.section-btn.const-section-leaf {
    padding: 0.25rem 1rem 0.25rem 3rem;
    font-size: 0.78rem;
    color: var(--color-text-light);
    display: flex;
    gap: 0.35rem;
}

.section-btn.const-section-leaf .const-leaf-num {
    flex: 0 0 auto;
    min-width: 2.5rem;
    font-variant-numeric: tabular-nums;
    color: var(--color-text);
}

.section-btn.const-section-leaf .const-leaf-title {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.section-btn .nav-range {
    display: inline;
    margin-top: 0;
    margin-left: 0.25rem;
    opacity: 0.5;
    font-size: 0.73rem;
}

/* HP subsection nav (desktop only) */
.section-btn.has-subsections {
    position: relative;
    padding-right: 1.5rem;
}

.section-btn.has-subsections::after {
    content: '';
    position: absolute;
    right: 0.6rem;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid currentColor;
    opacity: 0.4;
    transition: transform 0.2s;
}

.section-item.expanded > .section-btn.has-subsections::after {
    transform: translateY(-50%) rotate(180deg);
}

.subsection-list {
    display: none;
    list-style: none;
    margin: 0;
    padding: 0;
}

.section-item.expanded > .subsection-list {
    display: block;
}

.subsection-btn {
    display: block;
    width: 100%;
    padding: 0.25rem 1rem 0.25rem 3.25rem;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    font-size: 0.78rem;
    font-family: var(--font-sans);
    color: var(--color-text-light);
    transition: all 0.15s;
    line-height: 1.35;
    font-weight: 400;
}

.subsection-btn:hover {
    background: var(--color-bg-alt);
    color: var(--color-text);
}

.subsection-btn.active-section {
    background: var(--color-accent-light);
    color: var(--color-primary-light);
    font-weight: 500;
    border-left: 2px solid var(--color-accent);
    padding-left: calc(3.25rem - 2px);
}

@media (max-width: 900px) {
    .subsection-list {
        display: none !important;
    }
    .section-btn.has-subsections::after {
        display: none;
    }
}

.nav-section {
    border-top: 1px solid var(--color-border);
    padding: 0.5rem 0;
}

.resolutions-link {
    display: block;
    width: 100%;
    padding: 0.5rem 1rem;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    font-size: 0.8rem;
    font-family: var(--font-sans);
    color: var(--color-text);
    font-weight: 600;
    transition: all 0.15s;
}

.resolutions-link:hover {
    background: var(--color-bg-alt);
    color: var(--color-accent);
}

/* === Main Content === */
.content {
    flex: 1;
    padding: 2rem 3rem;
    min-width: 0;
}

/* === Breadcrumbs === */
.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.78rem;
    color: var(--color-text-light);
    margin-bottom: 1rem;
    flex-wrap: wrap;
    scroll-margin-top: calc(var(--header-height, 60px) + 16px);
}

.breadcrumbs a {
    color: var(--color-link);
    text-decoration: none;
    transition: color 0.15s;
}

.breadcrumbs a:hover {
    text-decoration: underline;
}

.breadcrumbs .breadcrumb-sep {
    color: var(--color-text-light);
    opacity: 0.5;
    user-select: none;
}

.breadcrumbs .breadcrumb-current {
    color: var(--color-text);
    font-weight: 500;
}

/* === Content Transitions === */
#contentArea {
    animation: contentFadeIn 0.2s ease-out;
}

/* Hide the whole app body AND the site-header until app.js hydrates and
   renders the right view. Hiding the header too prevents the home-page
   header-padding transition (body:has(.welcome-page) .site-header)
   from flashing the wordmark from full width to centred. visibility
   (not display) so the layout doesn't shift. */
.app-layout[data-hydrating],
body[data-hydrating] .site-header,
body[data-hydrating] .app-layout {
    visibility: hidden;
}

/* Two-tone wordmark. Split "House" (soft) from "Procedure" (strong)
   so the jammed compound reads as an intentional mark. */
.home-link .brand-soft,
.welcome-title .brand-soft {
    font-weight: 400;
    letter-spacing: -0.01em;
}
.home-link .brand-strong,
.welcome-title .brand-strong {
    font-weight: 700;
    letter-spacing: -0.01em;
}
.home-link .brand-strong {
    margin-left: -0.22em;
}
.welcome-title .brand-strong {
    margin-left: 0.1em;
}
.home-link .brand-soft {
    opacity: 0.68;
}
.welcome-title .brand-soft {
    color: var(--color-text-light);
}
.welcome-title .brand-strong {
    color: var(--color-primary);
}

@keyframes contentFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* === Chapter Navigation === */
.chapter-nav-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.chapter-nav-bar.nav-bottom {
    margin-top: 2.5rem;
    padding-top: 1.5rem;
    border-top: 2px solid var(--color-border);
}

.chapter-nav-bar.nav-top {
    margin-top: 1rem;
    margin-bottom: 1.5rem;
}

.chapter-nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 0.82rem;
    color: var(--color-text);
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
    max-width: 45%;
    min-width: 0;
}

.chapter-nav-btn:hover {
    border-color: var(--color-accent);
    box-shadow: var(--shadow-md);
    background: var(--color-accent-light);
}

.chapter-nav-btn:disabled {
    opacity: 0.35;
    cursor: default;
    pointer-events: none;
}

.chapter-nav-btn svg {
    flex-shrink: 0;
    color: var(--color-accent);
}

.chapter-nav-btn-content {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    align-items: flex-start;
}

.chapter-nav-direction {
    font-size: 0.9rem;
    color: var(--color-text);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.chapter-nav-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 400;
    font-size: 0.78rem;
    color: var(--color-text-light);
}

.chapter-nav-btn.nav-prev {
    margin-right: auto;
    text-align: left;
}

.chapter-nav-btn.nav-prev .chapter-nav-btn-content {
    align-items: flex-start;
}

.chapter-nav-btn.nav-next {
    margin-left: auto;
    text-align: right;
}

.chapter-nav-btn.nav-next .chapter-nav-btn-content {
    align-items: flex-end;
}

.chapter-nav-spacer {
    flex: 1;
}

/* Copy chapter link button */
.copy-chapter-link-btn {
    background: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--color-text-light);
    padding: 0.3rem;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    font-family: var(--font-sans);
    transition: color 0.15s, border-color 0.15s;
    vertical-align: middle;
    margin-left: 0;
}

.copy-chapter-link-btn span {
    display: none;
}

.copy-chapter-link-btn:hover {
    color: var(--color-accent);
    border-color: var(--color-accent);
}

.copy-chapter-link-btn.copied {
    color: var(--color-accent);
    border-color: var(--color-accent);
}

/* Print chapter button */
.print-chapter-btn {
    background: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--color-text-light);
    padding: 0.3rem;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    font-family: var(--font-sans);
    transition: color 0.15s, border-color 0.15s;
    vertical-align: middle;
    margin-left: 0;
}

.print-chapter-btn span {
    display: none;
}

.print-chapter-btn:hover {
    color: var(--color-accent);
    border-color: var(--color-accent);
}

/* Find-in-chapter toggle button (matches copy/print buttons) */
.chapter-find-toggle {
    background: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--color-text-light);
    padding: 0.3rem;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}
.chapter-find-toggle span { display: none; }
.chapter-find-toggle:hover,
.chapter-find-toggle.active {
    color: var(--color-accent);
    border-color: var(--color-accent);
}

/* In-chapter find bar (lives in the chapter sticky header) */
.chapter-find {
    display: none;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.5rem;
    margin: 0 0 0.4rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}
.chapter-find.open { display: flex; }
.chapter-find-icon { color: var(--color-text-light); flex: 0 0 auto; }
.chapter-find-input {
    flex: 1 1 auto;
    min-width: 0;
    border: none;
    background: none;
    color: var(--color-text);
    font-size: 0.9rem;
    padding: 0.15rem 0.25rem;
    outline: none;
}
.chapter-find-counter {
    flex: 0 0 auto;
    font-size: 0.8rem;
    color: var(--color-text-light);
    min-width: 2.75rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.chapter-find-prev,
.chapter-find-next,
.chapter-find-close {
    flex: 0 0 auto;
    background: none;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--color-text-light);
    font-size: 1.1rem;
    line-height: 1;
    padding: 0.1rem 0.4rem;
}
.chapter-find-prev:hover:not(:disabled),
.chapter-find-next:hover:not(:disabled),
.chapter-find-close:hover {
    color: var(--color-accent);
    border-color: var(--color-border);
}
.chapter-find-prev:disabled,
.chapter-find-next:disabled {
    opacity: 0.4;
    cursor: default;
}

/* In-chapter find highlights */
mark.chapter-find-mark {
    background: #fef08a;
    color: var(--color-text);
    padding: 0 1px;
    border-radius: 2px;
}
mark.chapter-find-mark.current {
    background: #f97316;
    color: #fff;
    outline: 2px solid #f97316;
    outline-offset: 1px;
}
[data-theme="dark"] mark.chapter-find-mark {
    background: #854d0e;
    color: #fef08a;
}
[data-theme="dark"] mark.chapter-find-mark.current {
    background: #f97316;
    color: #fff;
}

/* === Cross-reference Tooltip === */
.so-tooltip {
    position: fixed;
    z-index: 500;
    max-width: 320px;
    padding: 0.75rem 1rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--color-text);
    pointer-events: none;
}

.so-tooltip strong {
    display: block;
    color: var(--color-accent);
    margin-bottom: 0.3rem;
    font-size: 0.82rem;
}

.so-tooltip p {
    margin: 0;
    color: var(--color-text-light);
    font-size: 0.78rem;
}

/* === Welcome / Home Page === */
body:has(.welcome-page) .site-header,
html.is-home-initial .site-header {
    padding-inline: max(1.5rem, calc((100vw - 900px) / 2));
}

.welcome-page {
    max-width: 900px;
    margin: 0 auto;
}

.welcome-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
}

.welcome-subtitle {
    font-size: 1rem;
    color: var(--color-text-light);
    margin-bottom: 2rem;
    line-height: 1.6;
}

.doc-home-hero {
    display: flex;
    align-items: flex-start;
    gap: 2rem;
    margin-bottom: 2rem;
}

.doc-home-cover {
    width: 140px;
    height: auto;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    flex-shrink: 0;
}

.doc-home-intro {
    flex: 1;
}

.doc-home-intro .welcome-title {
    margin-bottom: 0.5rem;
}

.doc-home-intro .welcome-subtitle {
    margin-bottom: 0.75rem;
}

.doc-home-stat {
    font-size: 0.85rem;
    color: var(--color-text-light);
    font-family: var(--font-sans);
}

.welcome-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.welcome-cards-lg {
    grid-template-columns: repeat(3, 1fr);
}

.welcome-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    padding: 2rem 2rem 2.25rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    font-family: var(--font-sans);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.welcome-card:hover {
    border-color: var(--color-accent);
    box-shadow: var(--shadow-md);
}

.welcome-card-icon {
    width: 52px;
    height: 52px;
    border-radius: 10px;
    background: var(--color-accent-light);
    color: var(--color-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.25rem;
}

.welcome-card h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 0.5rem;
}

.welcome-card p {
    font-size: 0.85rem;
    color: var(--color-text-light);
    line-height: 1.6;
    margin: 0;
}

.welcome-card-note {
    display: block;
    margin-top: 0.75rem;
    font-size: 0.72rem;
    color: var(--color-text-light);
    opacity: 0.75;
    font-style: italic;
    line-height: 1.4;
}

.welcome-card-split {
    padding: 0;
    cursor: default;
    overflow: hidden;
}

.welcome-card-split:hover {
    border-color: var(--color-border);
    box-shadow: none;
}

.welcome-card-option {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    padding: 2rem 2rem 1.5rem;
    background: none;
    border: none;
    cursor: pointer;
    font-family: var(--font-sans);
    width: 100%;
    transition: background 0.15s;
}

.welcome-card-option:hover {
    background: var(--color-accent-light);
}

.welcome-card-option-alt {
    padding: 1rem 2rem;
    border-top: 1px solid var(--color-border);
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
}

.welcome-card-option-alt h3 {
    font-size: 0.95rem;
}

.welcome-card-option-alt p {
    font-size: 0.78rem;
}

.welcome {
    max-width: 700px;
}

.welcome h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 0.75rem;
    letter-spacing: -0.02em;
}

/* === Unified Browse panel on the home page === */
.browse-box {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.5rem 1.5rem 1.75rem;
    margin-bottom: 1.5rem;
}

.browse-box-title {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-light);
    margin: 0 0 1rem;
}

.browse-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

.browse-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 0.75rem 1.1rem;
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    color: inherit;
    font-family: var(--font-sans);
    transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.browse-card:hover {
    border-color: var(--color-accent);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.browse-card-cover {
    width: 78px;
    height: 110px;
    object-fit: cover;
    border-radius: 4px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.12);
    background: var(--color-bg);
}

.browse-card-cover-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-accent);
    background: var(--color-accent-light);
    box-shadow: none;
}

.browse-card-body h4 {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--color-text);
    margin: 0 0 0.25rem;
    line-height: 1.3;
}

.browse-card-body p {
    font-size: 0.75rem;
    color: var(--color-text-light);
    margin: 0;
    line-height: 1.4;
}

@media (max-width: 1100px) {
    .browse-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
    .browse-grid { grid-template-columns: 1fr; }
    .browse-card { flex-direction: row; text-align: left; padding: 0.75rem; }
    .browse-card-cover { width: 56px; height: 78px; }
}

/* === Constitution subsections === */
.const-subsections {
    list-style: none;
    padding: 0;
    margin: 0.6rem 0 0;
}

.const-subsection {
    display: flex;
    gap: 0.5rem;
    padding: 0.35rem 0;
    font-family: var(--font-serif);
    font-size: 0.92rem;
    line-height: 1.55;
}

.const-subsection-id {
    flex: 0 0 auto;
    min-width: 2.5rem;
    color: var(--color-text-light);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
}

.const-subsection-text {
    flex: 1 1 auto;
}

/* === Sidebar doc label (now that the doc-switcher tabs are gone) === */
.sidebar-doc-label {
    padding: 0.75rem 1rem 0.4rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-light);
}

.welcome p {
    margin-bottom: 1rem;
    color: var(--color-text-light);
    line-height: 1.7;
}

.insert-notice {
    background: var(--color-amended-bg);
    border-left: 4px solid var(--color-amended-border);
    padding: 1rem 1.25rem;
    border-radius: 0 var(--radius) var(--radius) 0;
    margin-top: 1.5rem;
}

.insert-notice h3 {
    font-size: 0.9rem;
    color: var(--color-amended);
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.insert-notice p {
    font-size: 0.875rem;
    color: var(--color-text);
    margin: 0;
}

.insert-notice p + p {
    margin-top: 0.6rem;
}

/* Chapter sticky header (breadcrumbs + heading) */
.chapter-sticky-header {
    position: sticky;
    top: var(--header-height, 60px);
    background: var(--color-bg-alt);
    z-index: 10;
    padding: 0.5rem 0 0;
    margin: -0.5rem 0 0;
}

.chapter-sticky-header .breadcrumbs {
    margin-bottom: 0.25rem;
}

.chapter-sticky-header .chapter-heading {
    margin-bottom: 0;
    padding-bottom: 0.4rem;
}

/* Inline prev/next arrow buttons in chapter heading */
.chapter-nav-inline {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--color-text-light);
    transition: border-color 0.15s, color 0.15s, background 0.15s;
    flex-shrink: 0;
}

.chapter-nav-inline:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
    background: var(--color-accent-light);
}

.chapter-nav-inline:disabled {
    opacity: 0.3;
    cursor: default;
    pointer-events: none;
}

.chapter-nav-inline.nav-next {
    margin-left: auto;
}

.chapter-heading-text {
    flex: 1;
    min-width: 0;
}

/* Chapter rendering */
.chapter-heading {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--color-accent);
    letter-spacing: -0.02em;
    scroll-margin-top: calc(var(--header-height, 60px) + 16px);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chapter-outline {
    color: var(--color-text-light);
    font-size: 0.9rem;
    margin-bottom: 2rem;
    font-style: italic;
}

.section-heading {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--color-primary-light);
    margin: 2.5rem 0 1.25rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--color-border);
    scroll-margin-top: calc(var(--header-height, 60px) + var(--sticky-header-height, 120px) + 16px);
}

/* Standing order rendering */
.standing-order {
    margin-bottom: 1.5rem;
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    position: relative;
    transition: box-shadow 0.2s;
    scroll-margin-top: calc(var(--header-height, 60px) + var(--sticky-header-height, 120px) + 16px);
}

.standing-order:target {
    box-shadow: 0 0 0 2px var(--color-accent);
}

.standing-order.amended {
    border-left: 4px solid var(--color-amended-border);
    background: var(--color-amended-bg);
}

.standing-order.added {
    border-left: 4px solid var(--color-added-border);
    background: var(--color-added-bg);
}

.so-header {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 0.875rem;
    flex-wrap: wrap;
}

.so-number {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--color-accent);
    white-space: nowrap;
}

.so-number a {
    color: inherit;
    text-decoration: none;
}

.so-number a:hover {
    text-decoration: underline;
}

.so-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
    flex: 1;
}

.badge {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
    vertical-align: middle;
    letter-spacing: 0.01em;
}

.badge-amended {
    background: var(--color-amended);
    color: #fff;
}

.badge-added {
    background: var(--color-added);
    color: #fff;
}

.badge-sessional {
    background: var(--color-primary-light);
    color: #fff;
}

.so-text {
    font-family: var(--font-reading);
    font-size: 0.9rem;
    line-height: 1.8;
}

.so-text p {
    margin: 0 0 0.75rem;
}

.so-text p:last-child {
    margin-bottom: 0;
}

.so-list-a {
    padding-left: 2rem;
    margin: 0.5rem 0;
    text-indent: -1.5rem;
}

.so-list-i {
    padding-left: 4rem;
    margin: 0.35rem 0;
    text-indent: -1.75rem;
}

.so-list-n {
    padding-left: 2rem;
    margin: 0.5rem 0;
    text-indent: -1.5rem;
}

.so-text a {
    color: var(--color-link);
}

/* Original text toggle */
.original-toggle {
    display: inline-block;
    margin-top: 0.75rem;
    padding: 4px 10px;
    font-size: 0.78rem;
    color: var(--color-amended);
    background: none;
    border: 1px solid var(--color-amended-border);
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--font-sans);
    transition: background 0.15s;
}

.original-toggle:hover {
    background: rgba(217, 119, 6, 0.1);
}

.original-text {
    display: none;
    margin-top: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--color-bg-alt);
    border-radius: var(--radius);
    font-family: var(--font-reading);
    font-size: 0.85rem;
    color: var(--color-text-light);
    line-height: 1.7;
    border: 1px dashed var(--color-border);
}

.original-text.visible {
    display: block;
}

.original-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--color-text-light);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.5rem;
}

/* SO 1 Table */
.so-table-wrapper {
    overflow-x: auto;
    margin-top: 0.75rem;
}

.so-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.so-table thead th {
    background: var(--color-primary);
    color: #fff;
    padding: 0.5rem 0.75rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.so-table thead th {
    white-space: nowrap;
}

.so-table td {
    padding: 0.35rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
    vertical-align: top;
    line-height: 1.5;
}

.so-table-category td {
    background: var(--color-bg-alt);
    font-weight: 600;
    color: var(--color-primary-light);
    padding-top: 0.6rem;
    padding-bottom: 0.4rem;
    border-bottom: 2px solid var(--color-border);
    font-size: 0.82rem;
}

.so-table-ref td {
    font-size: 0.75rem;
    color: var(--color-text-light);
    padding-top: 0.1rem;
    padding-bottom: 0.5rem;
    border-bottom: none;
}

.so-table tbody tr:hover:not(.so-table-category):not(.so-table-ref) {
    background: var(--color-accent-light);
}

/* SO 2 Definitions */
.so-definitions {
    margin-top: 0.75rem;
    display: grid;
    gap: 0;
}

.so-definitions dt {
    font-weight: 600;
    color: var(--color-primary);
    font-size: 0.88rem;
    padding: 0.75rem 0 0.15rem;
    border-top: 1px solid var(--color-border);
}

.so-definitions dt:first-child {
    border-top: none;
}

.so-definitions dd {
    font-family: var(--font-reading);
    font-size: 0.88rem;
    line-height: 1.7;
    padding-bottom: 0.5rem;
    color: var(--color-text);
}

/* Omitted orders */
.standing-order.omitted {
    opacity: 0.45;
    padding: 0.5rem 1.25rem;
    min-height: auto;
    border-style: dashed;
}

.omitted-title {
    font-style: italic;
    color: var(--color-text-light) !important;
    font-weight: 400 !important;
}

/* Flowchart (SO 139 - bill stages) */
.so-figure {
    margin: 1.25rem 0 0.5rem;
    text-align: center;
}

.so-figure img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
}

.so-figure figcaption {
    margin-top: 0.5rem;
    font-size: 0.82rem;
    color: var(--color-text-light);
    font-style: italic;
}

/* Resolution rendering */
.resolution {
    margin-bottom: 1.5rem;
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    scroll-margin-top: calc(var(--header-height, 60px) + var(--sticky-header-height, 120px) + 16px);
}

.resolution.added {
    border-left: 4px solid var(--color-added-border);
    background: var(--color-added-bg);
}

.resolution-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-primary);
    margin-bottom: 0.25rem;
}

.resolution-date {
    font-size: 0.78rem;
    color: var(--color-text-light);
    margin-bottom: 0.75rem;
}

.resolution-text {
    font-family: var(--font-reading);
    font-size: 0.9rem;
    line-height: 1.8;
}

/* === Header Actions === */
.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.header-search-col {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    flex: 1;
    max-width: 320px;
    min-width: 0;
}

.header-search-col .search-container {
    width: 100%;
}

.header-search-filters {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-filter-label {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.5);
    white-space: nowrap;
}

.header-btn-stack {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    flex-shrink: 0;
    width: 160px;
    align-self: stretch;
}

.header-btn-stack .header-ask-btn,
.header-btn-stack .header-advanced-btn {
    flex: 1;
    box-sizing: border-box;
    line-height: 1.2;
}

.header-ask-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.875rem;
    background: rgba(255,255,255,0.15);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: var(--radius);
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 0.825rem;
    font-weight: 500;
    white-space: nowrap;
    transition: background 0.15s;
    justify-content: center;
}

.header-ask-btn:hover {
    background: rgba(255,255,255,0.25);
}

/* === Mobile Chat Button (header icon, visible only on mobile) === */
.mobile-chat-btn {
    display: none;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,0.85);
    padding: 0.35rem;
    border-radius: 4px;
    text-decoration: none;
}

.mobile-chat-btn:hover {
    color: #fff;
    background: rgba(255,255,255,0.15);
}

/* === Header Doc Toggle === */
.header-doc-toggle {
    display: flex;
    gap: 1px;
    flex-shrink: 0;
}

.header-doc-btn {
    padding: 0.35rem 0.55rem;
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.65);
    border: 1px solid rgba(255,255,255,0.15);
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 0.75rem;
    font-weight: 600;
    transition: all 0.15s;
}

.header-doc-btn:first-child {
    border-radius: 4px 0 0 4px;
}

.header-doc-btn:last-child {
    border-radius: 0 4px 4px 0;
}

.header-doc-btn.active {
    background: rgba(255,255,255,0.25);
    color: #fff;
    border-color: rgba(255,255,255,0.35);
}

.header-doc-btn:hover:not(.active) {
    background: rgba(255,255,255,0.15);
    color: rgba(255,255,255,0.85);
}

.header-advanced-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.875rem;
    background: rgba(255,255,255,0.15);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: var(--radius);
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 0.825rem;
    font-weight: 500;
    white-space: nowrap;
    transition: background 0.15s;
    text-decoration: none;
    justify-content: center;
}

.header-advanced-btn:hover {
    background: rgba(255,255,255,0.25);
}

/* === Floating Chat Button === */
.chat-fab {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
    z-index: 150;
}

.chat-fab:hover {
    transform: scale(1.08);
    background: var(--color-primary-light);
}

/* Inline label hidden on mobile, shown alongside the icon on wide screens */
.chat-fab-label {
    display: none;
    font-family: var(--font-ui);
    font-size: 0.92rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    padding-right: 0.25rem;
}

/* Wider, pill-shaped FAB on desktop with a subtle attention pulse so users
   notice the AI option without it dominating the page. The pulse uses a soft
   ring shadow and pauses on hover so it's not distracting once engaged. */
@media (min-width: 1024px) {
    .chat-fab {
        width: auto;
        height: 60px;
        min-width: 60px;
        padding: 0 1.25rem 0 1.1rem;
        border-radius: 30px;
        bottom: 2rem;
        right: 2rem;
        animation: chat-fab-pulse 3s ease-in-out infinite;
    }
    .chat-fab-label {
        display: inline;
    }
    .chat-fab:hover {
        animation: none;
    }
}

@keyframes chat-fab-pulse {
    0%, 100% {
        box-shadow: var(--shadow-lg), 0 0 0 0 rgba(26, 77, 46, 0.45);
    }
    50% {
        box-shadow: var(--shadow-lg), 0 0 0 14px rgba(26, 77, 46, 0);
    }
}

/* Respect the user's reduced-motion preference across the whole app:
   near-eliminate animations/transitions and instant scroll. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* === Floating Chat Panel === */
.chat-panel {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 440px;
    height: 600px;
    max-height: calc(100vh - 100px);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    display: none;
    flex-direction: column;
    z-index: 200;
}

.chat-panel.open {
    display: flex;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--color-primary);
    color: #fff;
    border-radius: var(--radius) var(--radius) 0 0;
}

.chat-header h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: #fff;
    margin: 0;
    line-height: 1.1;
}

.chat-header-text {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}

.chat-header-note {
    font-size: 0.65rem;
    color: rgba(255,255,255,0.75);
    letter-spacing: 0.01em;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.chat-expand-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    display: flex;
    align-items: center;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}

.chat-expand-btn:hover {
    color: #fff;
    background: rgba(255,255,255,0.15);
}

.chat-close {
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.chat-close:hover {
    color: #fff;
}

.chat-footer {
    border-top: 1px solid var(--color-border);
}

.chat-standalone-panel .chat-footer,
.chat-page-panel .chat-footer {
    position: sticky;
    bottom: 0;
    background: var(--color-bg);
    z-index: 2;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.875rem;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

/* Message row: avatar + bubble */
.chat-message-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
    align-self: flex-start;
    max-width: 95%;
}

.chat-avatar {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--color-accent-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    line-height: 1;
    margin-top: 0.2rem;
}

.chat-message-row .chat-message {
    max-width: 100%;
}

.chat-message {
    max-width: 90%;
    padding: 0.625rem 0.875rem;
    border-radius: 12px;
    font-size: 0.82rem;
    line-height: 1.65;
    /* Long URLs / unbroken tokens (citations, identifiers) shouldn't push
       the bubble — and the whole chat layout — wider than the viewport
       on mobile. */
    overflow-wrap: anywhere;
    word-break: break-word;
    min-width: 0;
}

.chat-message p {
    margin: 0;
}

.chat-message p + p {
    margin-top: 0.5em;
}

.chat-message.user {
    align-self: flex-end;
    background: var(--color-accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-message.assistant {
    align-self: flex-start;
    background: var(--color-bg);
    color: var(--color-text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--color-border);
    max-width: 95%;
}

/* Headings inside messages */
.chat-heading {
    font-weight: 700;
    color: var(--color-text);
    margin: 0.85em 0 0.3em;
    line-height: 1.3;
}
/* Sized in em so headings are always larger than the surrounding body text,
   whether in the small floating panel or the larger chat page. */
h3.chat-heading { font-size: 1.25em; }
h4.chat-heading { font-size: 1.1em; }

.chat-heading:first-child {
    margin-top: 0;
}

/* Links */
.chat-message .so-ref,
.chat-message .hp-ref,
.chat-message .cs-ref {
    color: var(--color-link);
    cursor: pointer;
    text-decoration: none;
    font-weight: 500;
    border-bottom: 1px dotted var(--color-link);
}

.chat-message .so-ref:hover,
.chat-message .hp-ref:hover,
.chat-message .cs-ref:hover {
    border-bottom-style: solid;
}

/* Lists */
.chat-message ul,
.chat-message ol {
    margin: 0.4em 0;
    padding-left: 1.5em;
}

.chat-message .chat-blockquote {
    margin: 0.5em 0;
    padding: 0.5em 0.75em;
    border-left: 3px solid var(--color-accent);
    background: var(--color-accent-light);
    border-radius: 0 var(--radius) var(--radius) 0;
    font-style: italic;
}

.chat-message .chat-ol {
    counter-reset: chat-ol;
    list-style: none;
    padding-left: 1.6em;
}

.chat-message .chat-ol li {
    counter-increment: chat-ol;
    position: relative;
}

.chat-message .chat-ol li::before {
    content: counter(chat-ol) ".";
    position: absolute;
    left: -1.6em;
    width: 1.4em;
    text-align: right;
    font-weight: 600;
    color: var(--color-accent);
}

.chat-message li {
    margin-bottom: 0.35em;
    padding-left: 0.15em;
}

.chat-message li:last-child {
    margin-bottom: 0;
}

.chat-message strong {
    font-weight: 600;
}

.chat-message .chat-source-cards {
    margin-top: 0.6rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--color-border);
    max-width: 100%;
}

.chat-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--color-text-light);
    animation: blink 0.8s step-end infinite;
    vertical-align: text-bottom;
    margin-left: 1px;
}

@keyframes blink {
    50% { opacity: 0; }
}

.chat-loading {
    align-self: flex-start;
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    color: var(--color-text-light);
}

.chat-loading::after {
    content: '';
    animation: dots 1.2s steps(3, end) infinite;
}

@keyframes dots {
    0% { content: ''; }
    33% { content: '.'; }
    66% { content: '..'; }
    100% { content: '...'; }
}

.chat-input {
    padding: 0.5rem 0.75rem 0.625rem;
}

.chat-input-wrap {
    position: relative;
    display: flex;
    align-items: end;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.chat-input-wrap:focus-within {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 2px rgba(74,158,107,0.15);
}

.chat-input-wrap textarea {
    flex: 1;
    /* min-width: 0 is critical — without it the textarea's intrinsic
       size (from the default cols=20) refuses to shrink, forcing the
       whole chat-page-panel wider than the viewport on narrow mobile. */
    min-width: 0;
    width: 100%;
    border: 0;
    outline: none;
    resize: none;
    padding: 0.6rem 2.75rem 0.6rem 0.875rem;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    line-height: 1.5;
    background: transparent;
    color: var(--color-text);
    min-height: 2.5rem;
    max-height: 8rem;
    overflow-y: auto;
    box-sizing: border-box;
}

.chat-send-btn {
    position: absolute;
    right: 0.3rem;
    bottom: 0.3rem;
    width: 2rem;
    height: 2rem;
    border: 0;
    border-radius: 50%;
    background: var(--color-accent);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}

.chat-send-btn:hover {
    background: var(--color-primary-light);
}

.chat-send-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.chat-page-panel .chat-input-wrap textarea,
.chat-standalone-panel .chat-input-wrap textarea {
    font-size: 0.9rem;
    padding: 0.7rem 2.75rem 0.7rem 0.875rem;
}

/* === Amendment History === */
.amendment-history {
    max-width: 800px;
}

.amendment-history-copyright {
    font-size: 0.82rem;
    color: var(--color-text-light);
    margin-bottom: 1.25rem;
}

.amendment-history-desc {
    font-size: 0.9rem;
    line-height: 1.7;
    margin-bottom: 1rem;
    color: var(--color-text);
}

.amendment-history-dates {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-bottom: 2rem;
}

.amendment-date {
    display: inline-block;
    font-size: 0.8rem;
    padding: 0.3rem 0.65rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text);
    white-space: nowrap;
}

.amendment-history-inserts {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.amendment-insert-item {
    display: flex;
    gap: 1rem;
    align-items: baseline;
    padding: 0.75rem 1rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-left: 3px solid var(--color-accent);
    border-radius: var(--radius);
}

.amendment-insert-date {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--color-accent);
    white-space: nowrap;
}

.amendment-insert-desc {
    font-size: 0.88rem;
    color: var(--color-text);
}

/* === How it works (floating chat panel) === */
.chat-how-it-works {
    margin: 0.25rem 0.75rem 0.5rem;
    font-size: 0.8rem;
    color: var(--color-text-light);
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    line-height: 1.5;
}

.chat-how-it-works summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--color-text);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.chat-how-it-works summary::-webkit-details-marker {
    display: none;
}

.chat-how-it-works summary::before {
    content: '▶';
    font-size: 0.6rem;
    transition: transform 0.15s ease;
    color: var(--color-text-light);
}

.chat-how-it-works[open] summary::before {
    transform: rotate(90deg);
}

.chat-how-it-works p {
    margin: 0.4rem 0 0;
    font-size: 0.78rem;
}

.chat-how-it-works p + p {
    margin-top: 0.3rem;
}

.chat-ai-disclaimer {
    margin-top: 0.5rem;
    font-size: 0.78rem;
    color: var(--color-text-light);
    opacity: 0.85;
}

/* === Standalone Chat View === */
.chat-standalone {
    max-width: 900px;
}

.sidebar.collapsed ~ .content .chat-standalone {
    max-width: 1200px;
}

.chat-standalone-header {
    margin-bottom: 0.5rem;
}

.chat-standalone-header .chapter-heading {
    margin: 0 0 0.15rem;
}

.chat-standalone-header .chat-page-disclaimer {
    font-size: 0.75rem;
    color: var(--color-text-light);
    margin: 0;
}

.chat-standalone .insert-notice {
    margin-bottom: 1.5rem;
    margin-top: 0;
    line-height: 1.5;
}

.chat-standalone .insert-notice summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.chat-standalone .insert-notice summary::-webkit-details-marker {
    display: none;
}

.chat-standalone .insert-notice summary::before {
    content: '▶';
    font-size: 1rem;
    transition: transform 0.15s ease;
    color: var(--color-amended);
}

.chat-standalone .insert-notice[open] summary::before {
    transform: rotate(90deg);
}

.chat-standalone .insert-notice summary h3 {
    margin: 0;
}

.chat-standalone-intro {
    color: var(--color-text-light);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
    line-height: 1.6;
}

.chat-standalone-panel {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    height: 60vh;
    min-height: 400px;
}

.chat-standalone-panel .chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.chat-standalone-panel .chat-message {
    max-width: 80%;
    font-size: 0.88rem;
    line-height: 1.7;
}

.chat-standalone-panel .chat-message-row {
    max-width: 90%;
}

.chat-standalone-panel .chat-message.assistant {
    max-width: 100%;
}

.chat-standalone-panel .chat-avatar {
    width: 30px;
    height: 30px;
    font-size: 0.85rem;
}


.chat-standalone-panel .chat-input {
    padding: 0.5rem 1rem 0.875rem;
}

/* === Chat Suggested Questions === */
.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    padding: 0.25rem 0;
    align-self: flex-start;
}

.chat-suggestion-chip {
    display: inline-block;
    padding: 0.35rem 0.75rem;
    font-size: 0.78rem;
    font-family: var(--font-sans);
    color: var(--color-accent);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 100px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    line-height: 1.4;
    text-align: left;
}

.chat-suggestion-chip:hover {
    background: var(--color-accent-light);
    border-color: var(--color-accent);
}

/* === Chat bottom row: Sources pill + whole-chat actions on one row ===
   Wraps the source-control and chat-chat-actions, with the source pill
   left-aligned and the actions pushed to the right via margin-left:auto. */
.chat-bottom-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem 0;
}

.chat-bottom-row .chat-chat-actions {
    margin-left: auto;
    padding: 0;
}

.chat-page-panel .chat-bottom-row,
.chat-standalone-panel .chat-bottom-row {
    padding: 0.5rem 0 0;
}

/* === Chat Source Control (popover button) === */
.chat-source-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0;
    position: relative;
}

.chat-sources-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.78rem;
    font-weight: 500;
    font-family: var(--font-sans);
    color: var(--color-accent);
    padding: 0.35rem 0.7rem;
    min-height: 32px;
    max-width: 100%;
    border: 1px solid var(--color-accent);
    border-radius: 999px;
    background: var(--color-accent-light);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.chat-sources-btn:hover,
.chat-sources-btn[aria-expanded="true"] {
    background: var(--color-accent);
    color: #fff;
    border-color: var(--color-accent);
}

.chat-sources-btn:hover .chat-sources-prefix,
.chat-sources-btn[aria-expanded="true"] .chat-sources-prefix {
    color: rgba(255,255,255,0.85);
}

.chat-sources-prefix {
    color: var(--color-text-light);
    font-weight: 400;
}

.chat-sources-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.chat-sources-caret {
    flex-shrink: 0;
    opacity: 0.7;
}

.chat-sources-icon {
    flex-shrink: 0;
}

.chat-sources-popover {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0.75rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,0.14);
    padding: 0.4rem 0.75rem;
    z-index: 20;
    min-width: 220px;
    font-family: var(--font-sans);
}

.chat-sources-popover label {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.4rem 0;
    min-height: 36px;
    font-size: 0.85rem;
    color: var(--color-text);
    cursor: pointer;
}

.chat-sources-popover input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--color-accent);
    cursor: pointer;
}

/* Whole-chat actions: Copy / Export / Clear, right-aligned within
   the chat-bottom-row. Icon + label on desktop, icon-only Copy /
   Export on tight mobile (Clear keeps its text since it has no icon). */
.chat-chat-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.1rem;
}

.chat-chat-action {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.72rem;
    font-family: var(--font-sans);
    color: var(--color-text-light);
    background: none;
    border: 0;
    border-radius: 4px;
    padding: 0.35rem 0.55rem;
    min-height: 32px;
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
}

.chat-chat-action:hover {
    color: var(--color-accent);
    background: var(--color-accent-light);
}

.chat-chat-action-clear {
    text-decoration: underline;
    text-underline-offset: 2px;
}

.chat-chat-action-clear:hover {
    background: none;
}

@media (max-width: 600px) {
    .chat-chat-action:not(.chat-chat-action-clear) span {
        display: none;
    }
    .chat-chat-action {
        padding: 0.35rem 0.4rem;
    }
}

/* === Chat Source Cards === */
.chat-source-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 0.325rem;
    padding: 0.125rem 0 0.25rem;
    align-self: flex-start;
    max-width: 90%;
}

.chat-source-card {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.6rem;
    font-size: 0.72rem;
    font-family: var(--font-sans);
    color: var(--color-text);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 100px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    line-height: 1.4;
    text-align: left;
    max-width: 100%;
}

.chat-source-card:hover {
    background: var(--color-accent-light);
    border-color: var(--color-accent);
}

.chat-source-card-num {
    font-weight: 600;
    color: var(--color-accent);
    white-space: nowrap;
}

.chat-source-card-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-text-light);
}

.chat-standalone-panel .chat-source-cards {
    max-width: 75%;
}

.chat-standalone-panel .chat-suggestion-chip {
    font-size: 0.85rem;
    padding: 0.4rem 0.875rem;
}

.chat-standalone-panel .chat-source-card {
    font-size: 0.78rem;
    padding: 0.3rem 0.7rem;
}

/* === Chat per-message overflow menu === */
.chat-msg-actions {
    position: absolute;
    bottom: 0.25rem;
    right: 0.25rem;
}

.chat-message.assistant {
    position: relative;
}

.chat-msg-actions-btn {
    background: none;
    border: 0;
    padding: 0.2rem 0.3rem;
    border-radius: 4px;
    color: var(--color-text-light);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0.5;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.chat-message.assistant:hover .chat-msg-actions-btn,
.chat-msg-actions-btn[aria-expanded="true"] {
    opacity: 1;
}

.chat-msg-actions-btn:hover {
    color: var(--color-accent);
    background: var(--color-accent-light);
}

.chat-msg-actions-menu {
    position: absolute;
    bottom: calc(100% + 4px);
    right: 0;
    min-width: 140px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,0.14);
    padding: 0.3rem;
    z-index: 15;
    font-family: var(--font-sans);
}

.chat-msg-actions-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.4rem 0.6rem;
    font-size: 0.82rem;
    color: var(--color-text);
    background: none;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s, color 0.15s;
}

.chat-msg-actions-item:hover {
    background: var(--color-accent-light);
    color: var(--color-accent);
}

.chat-msg-actions-item.active {
    color: var(--color-accent);
}

.chat-msg-actions-item svg {
    flex-shrink: 0;
    color: var(--color-text-light);
}

.chat-msg-actions-item:hover svg,
.chat-msg-actions-item.active svg {
    color: var(--color-accent);
}

/* Desktop / tablet: expand the per-message actions into an inline row
   at the bottom of each answer. The ⋮ overflow collapse is only used
   on tight mobile viewports (≤600px) where the buttons would crowd the
   bubble. */
@media (min-width: 601px) {
    .chat-msg-actions {
        position: static;
        margin-top: 0.5rem;
        display: flex;
    }
    .chat-message.assistant .chat-msg-actions-btn {
        display: none;
    }
    .chat-msg-actions-menu {
        display: flex !important;
        position: static;
        flex-direction: row;
        background: transparent;
        border: 0;
        box-shadow: none;
        padding: 0;
        gap: 0.25rem;
        min-width: 0;
        z-index: auto;
    }
    .chat-msg-actions-item {
        width: auto;
        padding: 0.3rem 0.55rem;
        font-size: 0.74rem;
        color: var(--color-text-light);
        opacity: 0.8;
        gap: 0.35rem;
    }
    .chat-msg-actions-item:hover {
        opacity: 1;
    }
}

.chat-feedback-thanks {
    display: block;
    font-size: 0.78rem;
    color: var(--color-text-light);
    margin-top: 0.4rem;
}

.chat-correction-form {
    margin-top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.chat-correction-form textarea {
    width: 100%;
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
    font-family: var(--font-sans);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg-alt);
    color: var(--color-text);
    resize: vertical;
    outline: none;
    transition: border-color 0.15s;
}

.chat-correction-form textarea:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 2px rgba(74,158,107,0.15);
}

.chat-correction-submit {
    align-self: flex-end;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    font-family: var(--font-sans);
    font-weight: 600;
    color: #fff;
    background: var(--color-accent);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s;
}

.chat-correction-submit:hover {
    background: var(--color-primary-light);
}

/* === Copy Link Button === */
.so-copy-link {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-light);
    padding: 2px 4px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    opacity: 0.4;
    transition: opacity 0.15s, color 0.15s;
    vertical-align: middle;
    flex-shrink: 0;
}

.so-copy-link:hover,
.so-copy-link:focus {
    opacity: 1;
}

.so-copy-link:hover {
    color: var(--color-accent);
}

.so-copy-link.copied {
    opacity: 1;
    color: var(--color-accent);
    position: relative;
}

.so-copy-link.copied::after {
    content: 'Copied!';
    position: absolute;
    bottom: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.68rem;
    font-family: var(--font-sans);
    font-weight: 600;
    color: #fff;
    background: var(--color-accent);
    padding: 2px 8px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
}

/* === Search Highlight in Preview === */
.search-preview-content .so-text mark,
.search-preview-content .hp-content mark {
    background: #fef08a;
    color: var(--color-text);
    padding: 0 2px;
    border-radius: 2px;
}

[data-theme="dark"] .search-preview-content .so-text mark,
[data-theme="dark"] .search-preview-content .hp-content mark {
    background: #854d0e;
    color: #fef08a;
}

/* === Match Navigation Bar === */
.match-nav-bar {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.5rem;
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.78rem;
    margin-bottom: 0.75rem;
    position: sticky;
    top: 0;
    z-index: 10;
}

.match-nav-bar button {
    background: none;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 0.15rem 0.4rem;
    cursor: pointer;
    color: var(--color-text);
    font-size: 0.78rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
}

.match-nav-bar button:hover:not(:disabled) {
    background: var(--color-border);
}

.match-nav-bar button:disabled {
    opacity: 0.35;
    cursor: default;
}

.match-nav-counter {
    color: var(--color-text-light);
    min-width: 5em;
    text-align: center;
}

mark.current-match {
    background: #f97316 !important;
    color: #fff !important;
    outline: 2px solid #f97316;
    outline-offset: 1px;
    border-radius: 2px;
}

[data-theme="dark"] mark.current-match {
    background: #ea580c !important;
    color: #fff !important;
    outline-color: #ea580c;
}

/* === Recently Viewed === */
.recently-viewed {
    margin-bottom: 2rem;
}

.recently-viewed h3 {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-light);
    margin-bottom: 0.625rem;
}

.recently-viewed-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

.recently-viewed-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.75rem;
    font-size: 0.78rem;
    font-family: var(--font-sans);
    color: var(--color-text);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 100px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    max-width: 250px;
    white-space: nowrap;
}

.recently-viewed-chip:hover {
    background: var(--color-accent-light);
    border-color: var(--color-accent);
}

.recently-viewed-chip .rv-so {
    font-weight: 600;
    color: var(--color-accent);
    flex-shrink: 0;
}

.recently-viewed-chip .rv-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-text-light);
}

/* === Quiz Highlight === */
.quiz-highlight-row td {
    background: rgba(59, 130, 246, 0.12) !important;
    position: relative;
}
[data-theme="dark"] .quiz-highlight-row td {
    background: rgba(96, 165, 250, 0.15) !important;
}
.quiz-highlight-row td::after {
    content: '';
    position: absolute;
    left: 0; right: 0; top: 0; bottom: 0;
    border-top: 2px solid rgba(59, 130, 246, 0.4);
    border-bottom: 2px solid rgba(59, 130, 246, 0.4);
    pointer-events: none;
}
.quiz-highlight-row td:first-child::after {
    border-left: 2px solid rgba(59, 130, 246, 0.4);
}
.quiz-highlight-row td:last-child::after {
    border-right: 2px solid rgba(59, 130, 246, 0.4);
}

dt.quiz-highlight-def,
dd.quiz-highlight-def {
    background: rgba(59, 130, 246, 0.12);
    border-left: 3px solid rgba(59, 130, 246, 0.5);
    padding-left: 8px;
    border-radius: 0 4px 4px 0;
}
[data-theme="dark"] dt.quiz-highlight-def,
[data-theme="dark"] dd.quiz-highlight-def {
    background: rgba(96, 165, 250, 0.15);
    border-left-color: rgba(96, 165, 250, 0.5);
}

#quizRightPane mark.quiz-mark {
    background: rgba(59, 130, 246, 0.15);
    color: var(--color-text);
    padding: 1px 2px;
    border-radius: 2px;
    border-bottom: 2px solid rgba(59, 130, 246, 0.5);
}
[data-theme="dark"] #quizRightPane mark.quiz-mark {
    background: rgba(96, 165, 250, 0.15);
    border-bottom-color: rgba(96, 165, 250, 0.5);
}

/* === Deep-link arrival highlight === */
/* Phrase highlighted when arriving via a chatbot House Practice deep-link
   that carried a ~q= quote hint. Pulses amber, then settles to a soft mark. */
mark.nav-quote-mark {
    background: #fde68a;
    color: var(--color-text);
    padding: 1px 2px;
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.5);
    animation: nav-quote-pulse 2.4s ease-out;
}
[data-theme="dark"] mark.nav-quote-mark {
    background: #854d0e;
    color: #fef08a;
    box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.6);
}
@keyframes nav-quote-pulse {
    0%, 25% { background: #f59e0b; }
    100% { background: #fde68a; }
}

/* Section/subsection heading flash when a deep-link lands on it. */
.hp-arrival-flash {
    animation: hp-arrival-flash 2.4s ease-out;
    border-radius: 4px;
}
@keyframes hp-arrival-flash {
    0% { background: rgba(245, 158, 11, 0.35); }
    100% { background: transparent; }
}

/* Print-edition page badge on HP section/subsection headings */
.hp-page-ref {
    margin-left: 0.5rem;
    padding: 0.05em 0.45em;
    font-size: 0.7em;
    font-weight: 400;
    color: var(--color-text-light);
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    vertical-align: middle;
    white-space: nowrap;
    cursor: default;
}

/* === Quiz === */
.quiz-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 3rem 1rem;
    color: var(--color-text-secondary);
}
.quiz-loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

.quiz-setup {
    max-width: 600px;
    margin: 0 auto;
    padding: 2rem 0;
}

.quiz-setup-desc {
    color: var(--color-text-light);
    font-size: 0.9rem;
    line-height: 1.6;
    margin-bottom: 2rem;
}

.quiz-setup-options h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 0.75rem;
}

.quiz-setup-counts {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
}

.quiz-count-btn {
    padding: 0.625rem 1.5rem;
    font-size: 1rem;
    font-family: var(--font-sans);
    font-weight: 600;
    background: var(--color-bg);
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--color-text);
    transition: border-color 0.15s, background 0.15s;
}

.quiz-count-btn:hover {
    border-color: var(--color-accent);
}

.quiz-count-btn.selected {
    border-color: var(--color-accent);
    background: var(--color-accent-light);
    color: var(--color-accent);
}

.quiz-start-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.75rem;
    font-size: 0.9rem;
    font-family: var(--font-sans);
    font-weight: 600;
    color: #fff;
    background: var(--color-accent);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s;
}

.quiz-start-btn:hover {
    background: var(--color-primary-light);
}

.quiz-container {
    padding: 0.5rem;
}

.quiz-progress {
    height: 4px;
    background: var(--color-border);
    border-radius: 2px;
    margin-bottom: 1rem;
    overflow: hidden;
}

.quiz-progress-bar {
    height: 100%;
    background: var(--color-accent);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.quiz-status {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    color: var(--color-text-light);
    font-weight: 500;
    margin-bottom: 1.25rem;
}

.quiz-score {
    font-weight: 600;
    color: var(--color-accent);
}

.quiz-question {
    margin-bottom: 1.25rem;
}

.quiz-chapter-hint {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}
.quiz-question-text {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--color-text);
    line-height: 1.5;
    margin-bottom: 0.25rem;
}

.quiz-question-context {
    font-size: 0.85rem;
    color: var(--color-text-light);
    line-height: 1.6;
    font-family: var(--font-reading);
    background: var(--color-bg-alt);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    border-left: 3px solid var(--color-accent);
    margin-top: 0.5rem;
}

.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.quiz-option {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--color-bg);
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: var(--color-text);
    text-align: left;
    transition: border-color 0.15s, background 0.15s;
    line-height: 1.5;
}

.quiz-option:hover:not(.disabled) {
    border-color: var(--color-accent);
    background: var(--color-accent-light);
}

.quiz-option.disabled {
    cursor: default;
    opacity: 0.65;
}

.quiz-option.correct {
    border-color: #10b981;
    background: #ecfdf5;
    opacity: 1;
}

.quiz-option.incorrect {
    border-color: #ef4444;
    background: #fef2f2;
    opacity: 1;
}

[data-theme="dark"] .quiz-option.correct {
    border-color: #34d399;
    background: #0f2920;
}

[data-theme="dark"] .quiz-option.incorrect {
    border-color: #f87171;
    background: #2a1111;
}

.quiz-option-letter {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--color-bg-alt);
    color: var(--color-text-light);
    font-weight: 600;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.quiz-option.correct .quiz-option-letter {
    background: #10b981;
    color: #fff;
}

.quiz-option.incorrect .quiz-option-letter {
    background: #ef4444;
    color: #fff;
}

.quiz-option-text {
    flex: 1;
    padding-top: 2px;
}

.quiz-feedback {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    line-height: 1.5;
    margin-bottom: 1rem;
}

.quiz-feedback.correct {
    background: #ecfdf5;
    border: 1px solid #10b981;
    color: #065f46;
}

.quiz-feedback.incorrect {
    background: #fef2f2;
    border: 1px solid #ef4444;
    color: #991b1b;
}

[data-theme="dark"] .quiz-feedback.correct {
    background: #0f2920;
    border-color: #34d399;
    color: #6ee7b7;
}

[data-theme="dark"] .quiz-feedback.incorrect {
    background: #2a1111;
    border-color: #f87171;
    color: #fca5a5;
}

.quiz-next-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 1.25rem;
    font-size: 0.85rem;
    font-family: var(--font-sans);
    font-weight: 600;
    color: #fff;
    background: var(--color-accent);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s;
}

.quiz-next-btn:hover {
    background: var(--color-primary-light);
}

/* Quiz Results */
.quiz-results {
    text-align: center;
    padding: 2rem 0;
}

.quiz-results-grade {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.quiz-results-grade.outstanding { color: #10b981; }
.quiz-results-grade.good { color: var(--color-accent); }
.quiz-results-grade.ok { color: var(--color-amended); }
.quiz-results-grade.needs-work { color: #ef4444; }

.quiz-results-score {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 0.25rem;
}

.quiz-results-pct {
    font-size: 0.9rem;
    color: var(--color-text-light);
    margin-bottom: 2rem;
}

.quiz-results-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

.quiz-home-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 1.25rem;
    font-size: 0.85rem;
    font-family: var(--font-sans);
    font-weight: 500;
    color: var(--color-text);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.quiz-home-btn:hover {
    border-color: var(--color-accent);
    background: var(--color-accent-light);
}

/* Quiz Review */
.quiz-review {
    padding: 1rem;
}

.quiz-review-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--color-border);
}

.quiz-review-item {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--color-border);
}

.quiz-review-num {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    font-size: 0.72rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}

.quiz-review-item.correct .quiz-review-num {
    background: #10b981;
}

.quiz-review-item.incorrect .quiz-review-num {
    background: #ef4444;
}

.quiz-review-q {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--color-text);
    margin-bottom: 0.2rem;
}

.quiz-review-a {
    font-size: 0.78rem;
    color: var(--color-text-light);
    line-height: 1.5;
}

/* === Responsive === */
@media (max-width: 1100px) {
    .header-feedback-link {
        display: none;
    }
}

@media (max-width: 900px) {
    html, body {
        overflow-x: clip;
    }

    .content.search-mode {
        padding: 0;
    }

    .search-split-layout {
        flex-direction: column;
        height: auto;
    }

    .search-results-pane {
        width: 100%;
        min-width: 0;
        height: auto;
        max-height: 50vh;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
    }

    .search-preview-pane {
        height: auto;
        padding: 1.25rem;
    }

    .doc-home-hero {
        gap: 1.25rem;
    }

    .doc-home-cover {
        width: 110px;
    }

    .welcome-cards {
        grid-template-columns: 1fr;
    }

    .welcome-cards-lg {
        grid-template-columns: repeat(2, 1fr);
    }

    .sidebar-collapse-btn {
        display: none;
    }

    .sidebar-expand-btn {
        display: none !important;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 300;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        width: 280px;
        height: 100vh;
        height: 100dvh;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 250;
    }

    .sidebar-overlay.visible {
        display: block;
    }

    .content {
        padding: 1.5rem 1.25rem;
    }

    .site-header {
        flex-wrap: nowrap;
        padding: 0.625rem 0.75rem;
        gap: 0.5rem;
    }

    .header-content {
        min-width: 0;
        flex: 0 1 auto;
    }

    .site-header h1 {
        font-size: 0.95rem;
    }

    .header-icon {
        display: none;
    }

    .header-beta-group {
        gap: 0.25rem;
    }

    .header-feedback-link,
    .version-link {
        display: none;
    }

    .header-search-col {
        flex: 0 0 auto;
        max-width: none;
    }

    /* Collapsed search: icon-only trigger */
    .header-search-col .search-container {
        width: 36px;
        height: 36px;
        transition: width 0.25s ease;
        overflow: hidden;
        border-radius: var(--radius);
        background: rgba(255,255,255,0.1);
        border: 1px solid rgba(255,255,255,0.2);
    }

    .header-search-col .search-container #searchInput {
        opacity: 0;
        pointer-events: none;
        padding-left: 2.25rem;
        border: none;
        background: transparent;
    }

    .header-search-col .search-container .search-submit-btn {
        right: auto;
        left: 6px;
        color: rgba(255,255,255,0.7);
        pointer-events: auto;
    }

    .header-search-col .search-container .search-tips-btn {
        opacity: 0;
        pointer-events: none;
    }

    /* Expanded state */
    .header-search-col .search-container.search-expanded {
        width: calc(100vw - 5.5rem);
        position: absolute;
        right: 0.75rem;
        top: 50%;
        transform: translateY(-50%);
        z-index: 10;
        overflow: visible;
        background: rgba(255,255,255,0.15);
        backdrop-filter: blur(8px);
    }

    .header-search-col .search-container.search-expanded #searchInput {
        opacity: 1;
        pointer-events: auto;
    }

    .header-search-col .search-container.search-expanded .search-tips-btn {
        opacity: 1;
        pointer-events: auto;
    }

    .header-search-col .search-container.search-expanded .search-submit-btn {
        right: 6px;
        left: auto;
    }

    /* Hide header extras on mobile */
    .header-search-filters,
    .subtitle {
        display: none !important;
    }

    .theme-toggle {
        display: none;
    }

    .chat-fab,
    .chat-panel {
        display: none !important;
    }

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

    /* Prevent tables from causing horizontal overflow */
    .so-table-wrapper {
        max-width: calc(100vw - 2.5rem);
    }

    .search-sort-bar {
        flex-wrap: wrap;
        gap: 0.375rem;
    }

    .search-advanced-link {
        margin-left: 0;
        width: 100%;
    }

    /* Compact chapter sticky header on laptop and below */
    .chapter-sticky-header {
        padding: 0.5rem 0 0;
        margin: -0.5rem 0 0;
    }

    .chapter-sticky-header .breadcrumbs {
        margin-bottom: 0.25rem;
    }

    .chapter-heading {
        font-size: 1rem;
        padding-bottom: 0.25rem;
        margin-bottom: 0.25rem;
    }

    .chapter-nav-bar.nav-bottom {
        margin-top: 1.25rem;
        padding-top: 0.75rem;
    }

    .chapter-nav-btn {
        padding: 0.35rem 0.65rem;
    }

    .chapter-nav-direction {
        font-size: 0.75rem;
        margin-bottom: 0.1rem;
    }

    .chapter-nav-label {
        font-size: 0.72rem;
    }

    .copy-chapter-link-btn,
    .print-chapter-btn {
        padding: 0.25rem 0.45rem;
        font-size: 0.7rem;
    }

    .section-heading {
        margin: 1.75rem 0 1rem;
    }
}

@media (max-width: 600px) {
    .content {
        padding: 1rem 0.875rem;
    }

    .chapter-heading {
        font-size: 0.95rem;
    }

    .chapter-sticky-header .breadcrumbs {
        display: none;
    }

    .standing-order {
        padding: 1rem;
    }

    .so-text {
        font-size: 0.85rem;
    }

    .chapter-nav-btn {
        padding: 0.5rem;
    }

    .chapter-nav-label {
        display: none;
    }

    .search-tips-popover {
        width: calc(100vw - 2rem);
        right: -0.5rem;
    }

    .doc-home-hero {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .doc-home-cover {
        width: 120px;
    }

    .welcome-cards-lg {
        grid-template-columns: 1fr;
    }

    /* === Chat: mobile space wins === */
    .chat-message-row .chat-avatar {
        display: none;
    }

    .chat-message-row.assistant {
        gap: 0;
    }

    .chat-message-row.assistant .chat-message.assistant {
        max-width: 100%;
    }

    .chat-standalone-panel .chat-messages {
        padding: 0.75rem;
    }

    .chat-standalone-panel .chat-message {
        max-width: 95%;
    }

    .chat-standalone-panel .chat-message-row {
        max-width: 100%;
    }

    .chat-standalone-panel .chat-input {
        padding: 0.4rem 0.75rem 0.6rem;
    }

    .chat-bottom-row {
        padding: 0.4rem 0.5rem 0;
        gap: 0.35rem;
    }

    .chat-standalone-panel .chat-bottom-row,
    .chat-page-panel .chat-bottom-row {
        padding: 0.4rem 0 0;
    }

    .chat-sources-popover {
        left: 0;
        right: 0;
        min-width: 0;
    }

    .chat-sources-prefix {
        display: none;
    }

    .chat-sources-btn {
        font-size: 0.75rem;
        padding: 0.3rem 0.6rem;
    }
}

/* === Short viewport: un-stick header to reclaim vertical space ===
   Keep the sidebar in the flex flow (still position: sticky from the
   base rule) so .content doesn't expand under it. Just stretch the
   sidebar to the full viewport so it stays useful once the header
   scrolls away. */
@media (max-height: 700px) {
    .site-header {
        position: relative;
    }

    .sidebar {
        top: 0;
        height: 100vh;
        height: 100dvh;
    }
}

/* === Print === */
@media print {
    .site-header,
    .sidebar,
    .chat-fab,
    .chat-panel,
    .sidebar-toggle,
    .search-container,
    .original-toggle,
    .breadcrumbs,
    .chapter-nav-bar,
    .print-chapter-btn,
    .sidebar-expand-btn,
    .section-mini-nav {
        display: none !important;
    }

    .content {
        max-width: 100%;
        padding: 0;
    }

    body {
        background: #fff;
    }

    .standing-order {
        border: none;
        break-inside: avoid;
        page-break-inside: avoid;
        padding: 0.5rem 0;
    }

    .standing-order.amended,
    .standing-order.added {
        border-left: 2px solid #999;
    }

    .original-text.visible {
        display: block;
    }
}

/* === Document Switcher === */
.doc-switcher {
    display: flex;
    gap: 2px;
    padding: 0.5rem 1rem;
    background: var(--color-bg-alt);
    border-bottom: 1px solid var(--color-border);
}

.doc-tab {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    color: var(--color-text-light);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius);
    transition: all 0.15s;
    font-family: var(--font-sans);
}

.doc-tab:first-child {
    border-radius: var(--radius) 0 0 var(--radius);
}

.doc-tab:last-child {
    border-radius: 0 var(--radius) var(--radius) 0;
}

.doc-tab:hover {
    background: var(--color-accent-light);
}

.doc-tab.active {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

/* === House Practice Styles === */
.hp-section {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--color-border);
    scroll-margin-top: calc(var(--header-height, 60px) + var(--sticky-header-height, 120px) + 16px);
}

.hp-section:last-child {
    border-bottom: none;
}

.hp-section-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.hp-content {
    font-family: var(--font-reading);
    font-size: 1rem;
    line-height: 1.75;
    color: var(--color-text);
}

.hp-content p {
    margin-bottom: 0.75rem;
}

.hp-content ul {
    margin: 0.5rem 0 0.75rem 1.5rem;
}

.hp-content li {
    margin-bottom: 0.25rem;
}

.hp-content blockquote {
    border-left: 3px solid var(--color-accent);
    padding-left: 1rem;
    margin: 0.75rem 0;
    color: var(--color-text-light);
    font-style: italic;
}

.hp-term {
    display: block;
    font-style: normal;
    color: var(--color-text);
    margin-bottom: 0.25rem;
    font-size: 0.95em;
}

.hp-table-wrap {
    overflow-x: auto;
    margin: 0.75rem 0;
    -webkit-overflow-scrolling: touch;
}

.hp-content table.hp-table,
.hp-table-wrap table.hp-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    line-height: 1.5;
}

.hp-content table.hp-table td,
.hp-content table.hp-table th,
.hp-table-wrap table.hp-table td,
.hp-table-wrap table.hp-table th {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--color-border);
    vertical-align: top;
}

.hp-content table.hp-table th,
.hp-table-wrap table.hp-table th {
    background: var(--color-bg-alt);
    font-weight: 600;
    text-align: left;
    position: sticky;
    top: 0;
}

.hp-content table.hp-table thead,
.hp-table-wrap table.hp-table thead {
    background: var(--color-bg-alt);
}

.hp-content table.hp-table tbody tr:nth-child(even),
.hp-table-wrap table.hp-table tbody tr:nth-child(even) {
    background: color-mix(in srgb, var(--color-bg-alt) 50%, transparent);
}

.hp-subsection {
    margin-top: 1.25rem;
    scroll-margin-top: calc(var(--header-height, 60px) + var(--sticky-header-height, 120px) + 16px);
}

.hp-subsection-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-primary);
    margin-bottom: 0.5rem;
}

.hp-footnote-ref {
    font-size: 0.8em;
    color: var(--color-accent);
    text-decoration: none;
    cursor: pointer;
}

.hp-footnote-ref:hover {
    text-decoration: underline;
}

.hp-footnote-ref sup {
    font-size: inherit;
}

.hp-footnote-ref-plain {
    font-size: 0.75em;
    color: var(--color-accent);
}

/* Footnote popover */
.fn-popover {
    display: none;
    position: absolute;
    z-index: 200;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 0.75rem 1rem;
    font-family: var(--font-reading);
    font-size: 0.85rem;
    line-height: 1.55;
    color: var(--color-text);
    max-width: 360px;
}

.fn-popover-text {
    margin-bottom: 0.5rem;
}

.fn-popover-num {
    font-weight: 600;
    color: var(--color-accent);
}

.fn-popover-link {
    display: inline-block;
    font-family: var(--font-sans);
    font-size: 0.75rem;
    color: var(--color-link);
    text-decoration: none;
    padding-top: 0.35rem;
    border-top: 1px solid var(--color-border);
    width: 100%;
}

.fn-popover-link:hover {
    text-decoration: underline;
}

/* Chapter intro block */
.hp-intro {
    padding-bottom: 1.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--color-border);
}

/* Chapter-level footnotes at bottom */
.hp-chapter-footnotes {
    margin-top: 2.5rem;
    padding-top: 1.5rem;
    border-top: 2px solid var(--color-border);
    font-size: 0.85rem;
    color: var(--color-text-light);
    font-family: var(--font-reading);
    line-height: 1.6;
}

.hp-chapter-footnotes h4 {
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text);
}

.hp-chapter-footnotes ol {
    padding-left: 2.5rem;
}

.hp-chapter-footnotes li {
    margin-bottom: 0.35rem;
    scroll-margin-top: calc(var(--header-height, 60px) + var(--sticky-header-height, 120px) + 16px);
}

.hp-chapter-footnotes li:target {
    background: var(--color-accent-light);
    border-radius: 3px;
    padding: 0.1rem 0.3rem;
    margin-left: -0.3rem;
}

.fn-back {
    color: var(--color-accent);
    text-decoration: none;
    font-size: 0.85em;
    margin-right: 0.25rem;
}

.fn-back:hover {
    text-decoration: underline;
}

/* Figures/images */
.hp-figure {
    margin: 1.5rem 0;
    text-align: center;
}

.hp-figure img {
    max-width: 100%;
    height: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.hp-figure figcaption {
    font-size: 0.85rem;
    color: var(--color-text-light);
    margin-top: 0.5rem;
    font-style: italic;
}

/* Appendix styles */
.hp-appendix {
    margin-top: 1rem;
}

.hp-appendix .hp-subsection-title {
    margin-top: 1.5rem;
}

.hp-appendix-summary-card {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: 1.25rem 1.5rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
    font-family: var(--font-sans);
    margin-top: 1.5rem;
}

.hp-appendix-summary-card:hover {
    border-color: var(--color-accent);
    box-shadow: var(--shadow-sm);
}

.hp-appendix-summary-count {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--color-accent);
    line-height: 1;
}

.hp-appendix-summary-text {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.hp-appendix-summary-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
}

.hp-appendix-summary-desc {
    font-size: 0.85rem;
    color: var(--color-text-light);
}

.hp-appendix-summary-arrow {
    margin-left: auto;
    color: var(--color-text-light);
    font-size: 1.25rem;
}

/* Appendix nav in sidebar */
.appendix-nav-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-light);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    border-top: 1px solid var(--color-border);
    margin-top: 0.5rem;
}

.appendix-nav-header:hover {
    color: var(--color-text);
}

.appendix-nav-header .chevron {
    transition: transform 0.15s;
    font-size: 0.7em;
}

.appendix-nav-header.expanded .chevron {
    transform: rotate(90deg);
}

.hp-so-refs {
    margin-top: 1rem;
    padding: 0.5rem 0.75rem;
    background: var(--color-accent-light);
    border-radius: var(--radius);
    font-size: 0.85rem;
}

.hp-so-refs-label {
    font-weight: 600;
    color: var(--color-primary);
}

.hp-copy-link {
    margin-left: 0.25rem;
}

/* HP Chapter Grid (HP Home) */
.hp-chapter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}

.hp-chapter-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 1.25rem 1.5rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
    font-family: var(--font-sans);
}

.hp-chapter-card:hover {
    border-color: var(--color-accent);
    box-shadow: var(--shadow-sm);
}

.hp-chapter-card-num {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-accent);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.hp-chapter-card-title {
    font-size: 1rem;
    font-weight: 500;
    color: var(--color-text);
    margin-top: 0.35rem;
}

.hp-chapter-card-count {
    font-size: 0.8rem;
    color: var(--color-text-light);
    margin-top: 0.35rem;
}

/* === Document Badge === */
.doc-badge {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    vertical-align: middle;
    margin-right: 0.35rem;
}

.doc-badge-so {
    background: var(--color-accent-light);
    color: var(--color-primary);
}

.doc-badge-hp {
    background: #eff6ff;
    color: #1e40af;
}

[data-theme="dark"] .doc-badge-hp {
    background: #1e293b;
    color: #60a5fa;
}

.doc-badge-const {
    background: #fef3c7;
    color: #92400e;
}

[data-theme="dark"] .doc-badge-const {
    background: #3a2e10;
    color: #fbbf24;
}

/* === Advanced search doc filter === */
.advanced-search-doc-filter {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
}

.advanced-search-doc-filter label {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.85rem;
    cursor: pointer;
}

/* === Section Mini-Nav (mobile floating bar) === */
.section-mini-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 160;
    background: var(--color-bg);
    border-top: 1px solid var(--color-border);
    box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
    padding: 0.4rem 0.5rem;
    padding-bottom: calc(0.4rem + env(safe-area-inset-bottom, 0px));
    align-items: center;
    gap: 0.25rem;
}

@media (max-width: 900px) {
    .section-mini-nav.visible {
        display: flex;
    }
    /* Prevent content being hidden behind mini-nav */
    body:has(.section-mini-nav.visible) .content {
        padding-bottom: calc(4rem + env(safe-area-inset-bottom, 0px));
    }
    /* Lift chat FAB above mini-nav */
    .section-mini-nav.visible ~ .chat-fab,
    body:has(.section-mini-nav.visible) .chat-fab {
        bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
    }
}

.smn-btn {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    border: 1px solid var(--color-border);
    background: var(--color-bg-alt);
    color: var(--color-text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}

.smn-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

.smn-btn:not(:disabled):active {
    background: var(--color-primary);
    color: #fff;
}

.smn-chapters {
    margin-right: 0.15rem;
    border-right: 1px solid var(--color-border);
    border-radius: 8px 0 0 8px;
    padding-right: 0.35rem;
}

.smn-current {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    padding: 0.4rem 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--color-border);
    background: var(--color-bg-alt);
    color: var(--color-text);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    overflow: hidden;
}

.smn-current.active {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

.smn-current.active .smn-chevron {
    transform: rotate(180deg);
}

.smn-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.smn-counter {
    flex-shrink: 0;
    font-size: 0.7rem;
    opacity: 0.55;
    font-variant-numeric: tabular-nums;
}

.smn-current.active .smn-counter {
    opacity: 0.8;
}

.smn-chevron {
    flex-shrink: 0;
    transition: transform 0.2s;
}

.smn-popover {
    position: absolute;
    bottom: 100%;
    left: 0.5rem;
    right: 0.5rem;
    margin-bottom: 0.4rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.12);
    max-height: 50vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* The hidden attribute's UA display:none is overridden by display:flex above */
.smn-popover[hidden] {
    display: none;
}

.smn-popover-header {
    padding: 0.6rem 0.75rem 0.4rem;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-light);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.smn-list {
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0.4rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-height: 0;
}

.smn-list-btn {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.55rem 0.75rem;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--color-text);
    font-size: 0.83rem;
    cursor: pointer;
    transition: background 0.12s;
    line-height: 1.3;
}

.smn-list-btn:active {
    background: var(--color-bg-alt);
}

.smn-list-btn.active {
    background: var(--color-primary);
    color: #fff;
    font-weight: 500;
}

.smn-top-btn {
    font-style: italic;
    color: var(--color-text-light);
    font-size: 0.78rem;
    border-bottom: 1px solid var(--color-border);
    border-radius: 8px 8px 0 0;
}

.smn-top-btn.active {
    color: #fff;
}

.smn-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.25);
    z-index: 159;
    cursor: pointer;
}
