/* === 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);
}

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

.site-header h1 {
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.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;
}

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

.version-link {
    color: inherit;
    text-decoration: none;
    opacity: 0.85;
}

.version-link:hover {
    text-decoration: underline;
    opacity: 1;
}

/* 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 input {
    background: var(--color-bg-alt);
    color: var(--color-text);
}

/* Hamburger */
.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;
}

/* === 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);
}

/* === Beta Banner === */
.beta-banner {
    background: var(--color-accent-light);
    color: var(--color-text);
    text-align: center;
    padding: 0.4rem 1rem;
    font-size: 0.8rem;
    font-family: var(--font-ui);
    border-bottom: 1px solid var(--color-border);
}

.beta-banner a {
    color: var(--color-accent);
    font-weight: 600;
    text-decoration: underline;
}

/* === 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;
}

/* Expand button - shown when sidebar is collapsed */
.sidebar-expand-btn {
    position: fixed;
    left: 0;
    top: 80px;
    z-index: 9999;
    width: 20px;
    height: 100px;
    background: var(--color-accent-light);
    border: 1px solid var(--color-accent);
    border-left: none;
    border-radius: 0 4px 4px 0;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    color: var(--color-accent);
    transition: background 0.15s, color 0.15s;
}

.sidebar-expand-btn:hover {
    background: var(--color-accent);
    color: #fff;
}

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

.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: var(--color-accent-light);
    border: 1px solid var(--color-accent);
    cursor: pointer;
    color: var(--color-accent);
    padding: 4px 6px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: color 0.15s, background 0.15s;
}

.sidebar-collapse-btn:hover {
    color: #fff;
    background: var(--color-accent);
}

.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);
}

.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;
}

@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.35rem 0.6rem;
    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.75rem;
}

.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.35rem 0.6rem;
    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.75rem;
}

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

/* === 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 === */
.welcome-page {
    max-width: 900px;
}

.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;
}

.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.75rem 0 0;
    margin: -0.75rem 0 0;
}

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

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

.chapter-sticky-header .chapter-nav-bar.nav-top {
    margin-top: 0.5rem;
    margin-bottom: 0;
    padding-bottom: 0.5rem;
}

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

.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;
}

.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;
    transition: transform 0.2s, background 0.2s;
    z-index: 150;
}

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

/* === 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;
}

.chat-model-badge {
    font-size: 0.65rem;
    font-weight: 500;
    background: rgba(255,255,255,0.2);
    padding: 0.15rem 0.45rem;
    border-radius: 100px;
    vertical-align: middle;
    margin-left: 0.25rem;
    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-footer-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.75rem 0.5rem;
    font-size: 0.68rem;
}

.chat-model-label {
    color: var(--color-text-light);
    opacity: 0.6;
}

.chat-clear-link {
    background: none;
    border: 1px solid var(--color-border);
    border-radius: 100px;
    color: var(--color-text-light);
    font-size: 0.78rem;
    font-family: var(--font-sans);
    cursor: pointer;
    padding: 0.4rem 1rem;
    transition: color 0.15s, border-color 0.15s;
}

.chat-clear-link:hover {
    color: var(--color-accent);
    border-color: var(--color-accent);
}

.chat-clear-standalone {
    padding: 0.5rem;
    background: none;
    color: var(--color-text-light);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, border-color 0.15s;
}

.chat-clear-standalone:hover {
    color: var(--color-accent);
    border-color: var(--color-accent);
}

.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;
}

.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-size: 0.84rem;
    font-weight: 600;
    color: var(--color-text);
    margin: 0.6em 0 0.2em;
    line-height: 1.3;
}

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

/* Links */
.chat-message .so-ref,
.chat-message .hp-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 {
    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 {
    display: flex;
    padding: 0.625rem;
    gap: 0.375rem;
}

.chat-input input {
    flex: 1;
    padding: 0.5rem 0.625rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.82rem;
    font-family: var(--font-sans);
    outline: none;
    transition: border-color 0.15s;
}

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

.chat-input button {
    padding: 0.5rem;
    background: var(--color-accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.chat-input button:hover {
    background: var(--color-primary-light);
}

/* === 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 .chat-model-badge {
    font-size: 0.7rem;
    background: var(--color-accent-light);
    color: var(--color-accent);
    padding: 0.2rem 0.55rem;
}

.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-heading {
    font-size: 0.9rem;
}

.chat-standalone-panel .chat-footer-meta {
    padding: 0 1rem 0.625rem;
}

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

.chat-standalone-panel .chat-input input {
    font-size: 0.9rem;
    padding: 0.625rem 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 Source Toggles === */
.chat-source-toggles {
    display: flex;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem 0.25rem;
    flex-wrap: wrap;
    align-items: center;
}

.chat-source-toggles-label {
    font-size: 0.72rem;
    font-family: var(--font-sans);
    color: var(--color-text-light);
    font-weight: 500;
}

.chat-source-toggle {
    display: inline-block;
    padding: 0.3rem 0.7rem;
    font-size: 0.72rem;
    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;
    line-height: 1.4;
}

.chat-source-toggle.active {
    background: var(--color-accent);
    color: #fff;
    border-color: var(--color-accent);
}

.chat-source-toggle:hover:not(.active) {
    border-color: var(--color-accent);
    color: var(--color-accent);
}

.chat-source-guidance {
    display: block;
    padding: 0 0.75rem 0.25rem;
    font-size: 0.65rem;
    color: var(--color-text-light);
    font-family: var(--font-sans);
}

.chat-standalone-panel .chat-source-toggles,
.chat-page-panel .chat-source-toggles {
    padding: 0.5rem 1rem 0.25rem;
}

.chat-standalone-panel .chat-source-toggle,
.chat-page-panel .chat-source-toggle {
    font-size: 0.78rem;
    padding: 0.35rem 0.8rem;
}

.chat-standalone-panel .chat-source-toggles-label,
.chat-page-panel .chat-source-toggles-label {
    font-size: 0.78rem;
}

.chat-standalone-panel .chat-source-guidance,
.chat-page-panel .chat-source-guidance {
    padding: 0 1rem 0.25rem;
    font-size: 0.7rem;
}

/* === 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 Copy Button === */
.chat-copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin-top: 0.4rem;
    padding: 0.25rem 0.6rem;
    font-size: 0.72rem;
    font-family: var(--font-sans);
    color: var(--color-text-light);
    background: none;
    border: 1px solid var(--color-border);
    border-radius: 100px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

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

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

/* === Chat Feedback Buttons === */
.chat-feedback {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.6rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--color-border);
}

.chat-feedback-label {
    font-size: 0.78rem;
    color: var(--color-text-light);
    margin-right: 0.2rem;
}

.chat-feedback-btn {
    background: none;
    border: 1px solid var(--color-border);
    border-radius: 100px;
    padding: 0.35rem 0.6rem;
    cursor: pointer;
    color: var(--color-text-light);
    font-size: 0.78rem;
    font-family: var(--font-sans);
    display: inline-flex;
    align-items: center;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

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

.chat-feedback-btn.active {
    color: var(--color-accent);
    border-color: var(--color-accent);
    background: var(--color-accent-light);
}

.chat-feedback-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

.chat-feedback-btn:disabled:hover {
    background: none;
    border-color: var(--color-border);
    color: var(--color-text-light);
}

.chat-feedback-btn.active:disabled {
    opacity: 1;
}

.chat-feedback-thanks {
    font-size: 0.78rem;
    color: var(--color-text-light);
    margin-left: 0.2rem;
    align-self: center;
}

.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);
}

/* === 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: 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-toggle {
        display: flex;
    }

    .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: wrap;
        padding: 0.75rem 1rem;
        gap: 0.5rem;
    }

    .header-content {
        min-width: 0;
    }

    .header-actions {
        width: 100%;
        order: 3;
    }

    .header-search-col {
        flex: 1;
        min-width: 0;
    }

    .search-container {
        flex: 1;
        width: auto;
        min-width: 0;
    }

    /* Hide header extras on mobile */
    .header-btn-stack,
    .header-search-filters,
    .theme-label-dark,
    .theme-label-light {
        display: none !important;
    }

    .mobile-chat-btn {
        display: flex;
    }

    .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%;
    }
}

@media (max-width: 600px) {
    .site-header {
        padding: 0.625rem 0.75rem;
    }

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

    .subtitle {
        display: none;
    }

    .content {
        padding: 1rem 0.875rem;
    }

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

    .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;
    }
}

/* === 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;
}

/* === 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-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;
}
