/* OCN Constitution Management System Styling */

:root {
    /* Light mode color palette - OCN inspired */
    --color-bg: #f5f7fa;
    --color-bg-elevated: #ffffff;
    --color-bg-hover: #e8ecf1;
    --color-surface: #ffffff;
    --color-border: #d1d9e6;
    --color-border-subtle: #e5eaf2;
    
    --color-text: #1a2b3c;
    --color-text-muted: #5a6b7c;
    --color-text-subtle: #8a99aa;
    
    /* Accent - OCN teal/blue */
    --color-accent: #0891b2;
    --color-accent-hover: #0e7490;
    --color-accent-muted: #67cfe0;
    --color-accent-light: #e0f7fa;
    
    /* Semantic colors */
    --color-success: #059669;
    --color-warning: #d97706;
    --color-danger: #dc2626;
    --color-danger-subtle: rgba(220, 38, 38, 0.1);
    
    /* Primary (alias for accent) */
    --color-primary: var(--color-accent);
    --color-primary-subtle: var(--color-accent-light);
    
    /* Additional backgrounds */
    --color-bg-secondary: #f8fafc;
    
    /* Typography - OCN uses DM Sans */
    --font-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-serif: 'Georgia', 'Times New Roman', Times, serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    
    /* Spacing */
    --space-2xs: 0.125rem;
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;

    /* Shared height for the three column headers (structure / document / assistant) */
    --column-header-height: 40px;

    /* Border radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

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

html, body {
    height: 100%;
}

body {
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.6;
    color: var(--color-text);
    background: var(--color-bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-xl);
    background: #1a2b3c;
    border-bottom: none;
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    color: #ffffff;
}

.logo img {
    height: 36px;
    width: auto;
}

.logo h1 {
    font-size: 1.1rem;
    font-weight: 500;
    letter-spacing: -0.01em;
    color: #ffffff;
}

.logo h1 span {
    color: var(--color-accent-muted);
    font-weight: 700;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

/* User Menu */
.user-menu {
    position: relative;
}

.user-menu-btn {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: auto !important;
    height: auto !important;
    padding: 6px 12px !important;
}

.user-menu-btn svg {
    flex-shrink: 0;
}

.user-display-name {
    font-size: 0.875rem;
    font-weight: 500;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-menu-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 300px;
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    overflow: hidden;
}

.user-menu-dropdown.hidden {
    display: none;
}

.user-menu-header {
    padding: var(--space-md);
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
}

.user-full-name {
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 2px;
}

.user-email {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.user-menu-mcp {
    padding: var(--space-md);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg);
}

.user-menu-mcp-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    margin-bottom: var(--space-xs);
}

.user-menu-mcp-hint {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    line-height: 1.4;
    margin: 0 0 var(--space-sm) 0;
}

.user-menu-mcp-loading {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.user-menu-mcp-body.hidden,
.user-menu-mcp-loading.hidden {
    display: none;
}

.user-menu-mcp-token-preview {
    margin-bottom: var(--space-sm);
}

.user-menu-mcp-token-preview code {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    word-break: break-all;
    color: var(--color-text);
    background: var(--color-bg-elevated);
    padding: 6px 8px;
    border-radius: 4px;
    border: 1px solid var(--color-border);
}

.user-menu-mcp-buttons {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    margin-bottom: var(--space-sm);
}

.user-menu-mcp-primary-btn {
    width: 100%;
    justify-content: center;
}

.user-menu-mcp-error {
    font-size: 0.75rem;
    color: var(--color-danger);
    margin: 0;
    line-height: 1.4;
}

.user-menu-mcp-error.hidden {
    display: none;
}

#mcpKeyHasBlock.hidden,
#mcpGenerateBtn.hidden {
    display: none !important;
}

.user-menu-divider {
    height: 1px;
    background: var(--color-border);
}

.user-menu-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    border: none;
    background: transparent;
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.user-menu-item:hover {
    background: var(--color-bg-hover);
}

.user-menu-item svg {
    color: var(--color-text-muted);
}

/* Version Badge in Header */
.version-badge {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 500;
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
    padding: 4px 10px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    margin-left: var(--space-sm);
}

/* Breadcrumb Navigation */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    color: #ffffff;
    font-size: 0.9rem;
    margin-right: auto;
    padding-left: var(--space-lg);
}

.breadcrumb-link {
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.breadcrumb-link:hover {
    color: #ffffff;
    text-decoration: underline;
}

.breadcrumb-separator {
    color: rgba(255, 255, 255, 0.4);
    margin: 0 var(--space-2xs);
}

.breadcrumb-current {
    color: #ffffff;
    font-weight: 500;
}

/* Static breadcrumb - plain text for single org users */
.breadcrumb-static {
    cursor: default;
}

/* Interactive breadcrumb - dropdown styling for multi-org users */
.breadcrumb-interactive {
    cursor: pointer;
    padding-right: 20px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='white' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right center;
    transition: opacity var(--transition-fast);
}

.breadcrumb-interactive:hover {
    opacity: 0.8;
}

.document-select:hover {
    background-color: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

.document-select:focus {
    outline: none;
    border-color: var(--color-accent-muted);
    box-shadow: 0 0 0 2px rgba(103, 207, 224, 0.3);
}

.document-select option {
    background: #1a2b3c;
    color: #ffffff;
    padding: 8px;
}

/* No Document Selected State */
.no-document-selected {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: var(--space-lg);
    color: var(--color-text-muted);
    text-align: center;
    padding: var(--space-2xl);
}

.no-document-selected svg {
    width: 64px;
    height: 64px;
    opacity: 0.4;
}

.no-document-selected h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--color-text);
    margin: 0;
}

.no-document-selected p {
    font-size: 0.95rem;
    max-width: 400px;
    margin: 0;
}

/* Document Picker View */
.document-picker-view {
    flex: 1;
    overflow: hidden;
    background: var(--color-bg);
}

.document-picker-view.hidden {
    display: none;
}

.document-picker {
    height: 100%;
    padding: var(--space-2xl);
    overflow-y: auto;
    max-width: 1200px;
    margin: 0 auto;
}

.document-picker-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-xl);
}

.document-picker-title {
    display: flex;
    align-items: baseline;
    gap: var(--space-md);
}

.document-picker-title h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
    color: var(--color-text);
}

.document-count {
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

/* Document Table */
.document-table-container {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.document-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.document-table thead {
    background: var(--color-bg-secondary);
    border-bottom: 1px solid var(--color-border);
}

.document-table th {
    text-align: left;
    padding: var(--space-md) var(--space-lg);
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.document-table td {
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--color-border-subtle);
    color: var(--color-text);
}

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

.document-row:hover {
    background: var(--color-bg-hover);
}

.document-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    color: var(--color-text);
    text-decoration: none;
    font-weight: 500;
    transition: color var(--transition-fast);
}

.document-link:hover {
    color: var(--color-primary);
}

.document-link svg {
    color: var(--color-text-muted);
    flex-shrink: 0;
}

.document-link:hover svg {
    color: var(--color-primary);
}

.col-name {
    width: 40%;
}

.col-type {
    width: 20%;
    text-transform: capitalize;
}

.col-updated {
    width: 25%;
    color: var(--color-text-muted);
}

.col-actions {
    width: 15%;
    text-align: right;
}

.col-actions .btn {
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.document-row:hover .col-actions .btn {
    opacity: 1;
}

.document-table-empty td {
    text-align: center;
    padding: var(--space-2xl);
    color: var(--color-text-muted);
}

/* Editor View */
.editor-view {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.editor-view.hidden {
    display: none;
}

.btn-icon {
    padding: var(--space-xs);
    min-width: 32px;
    height: 32px;
    justify-content: center;
}

.btn-danger-subtle {
    color: var(--color-danger);
}

.btn-danger-subtle:hover {
    background: var(--color-danger-subtle);
}

/* Form hint text */
.form-hint {
    display: block;
    margin-top: var(--space-xs);
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

/* Auto-save Indicator */
.autosave-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    font-size: 0.8rem;
    color: #6ee7b7;
    opacity: 0;
    transition: opacity var(--transition-normal);
    padding: var(--space-xs) var(--space-sm);
}

.autosave-indicator.visible {
    opacity: 1;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn:hover:not(:disabled) {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: #ffffff;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-accent-hover);
    border-color: var(--color-accent-hover);
    color: #ffffff;
}

.btn-secondary {
    background: var(--color-surface);
    border-color: var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-surface-hover, rgba(0, 0, 0, 0.04));
    border-color: var(--color-border);
}

.btn-sm {
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.8rem;
}

.btn-icon {
    padding: var(--space-xs);
    background: transparent;
    border: none;
}

.btn-danger {
    color: var(--color-danger);
}

.btn-danger:hover {
    background: rgba(184, 92, 92, 0.15);
}

/* Main Content Area - Always Split View */
.app-main {
    flex: 1;
    overflow: hidden;
    position: relative;
    display: flex;
}

/* Panels */
.panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.panel-left {
    flex: 0 0 380px;
    min-width: 280px;
    /* The resize handle's 1px line is the divider (avoids a doubled border). */
    background: var(--color-bg-elevated);
}

.panel-right {
    flex: 1;
    min-width: 400px;
    display: flex;
    flex-direction: column;
}

/* Panel Header */
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--column-header-height);
    box-sizing: border-box;
    flex-shrink: 0;
    padding: 0 var(--space-md);
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
}

.panel-header h2 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text);
}

.panel-toolbar {
    display: flex;
    gap: var(--space-sm);
}

/* Resize handle: a wide, easy-to-grab hit area that renders only a 1px line.
   Negative margins collapse the 9px box down to a ~1px layout footprint so the
   neighbouring panels butt up against the line while the grab zone stays wide;
   the line itself is drawn (and highlighted) by the ::before. */
.panel-resize-handle {
    width: 9px;
    margin: 0 -4px;
    background: transparent;
    cursor: col-resize;
    flex-shrink: 0;
    position: relative;
    z-index: 20;
}

.panel-resize-handle::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 1px;
    transform: translateX(-50%);
    background: var(--color-border);
    transition: background var(--transition-fast), width var(--transition-fast);
}

.panel-resize-handle:hover::before,
.panel-resize-handle.dragging::before {
    width: 3px;
    background: var(--color-accent);
}

/* Navigation Tabs (in right panel) */
.view-tabs {
    display: flex;
    justify-content: space-between;
    align-items: stretch;
    height: var(--column-header-height);
    box-sizing: border-box;
    padding: 0 var(--space-lg);
    background: var(--color-bg-elevated);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.tabs-left {
    display: flex;
    gap: 0;
}

.tab {
    display: flex;
    align-items: center;
    height: 100%;
    gap: var(--space-sm);
    padding: 0 var(--space-lg);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-muted);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.tab:hover {
    color: var(--color-text);
    background: var(--color-bg-hover);
}

.tab.active {
    color: var(--color-accent);
    border-bottom-color: var(--color-accent);
}

/* View Panels */
.view-panel {
    display: none;
    flex: 1;
    overflow: hidden;
}

.view-panel.active {
    display: flex;
    flex-direction: column;
}

/* Rendered Document View */
.document-container {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-lg);
    background: var(--color-bg);
}

/* Match the scrollbar track to the document area's own background (rather than
   the default elevated track), so the thumb's inset gap blends in. */
.document-container::-webkit-scrollbar-track {
    background: var(--color-bg);
}

.rendered-content {
    max-width: 800px;
    margin: 0 auto;
    padding: var(--space-2xl) var(--space-2xl) var(--space-2xl) var(--space-2xl);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 2px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    font-family: var(--font-serif);
    font-size: 1rem;
    line-height: 1.7;
    text-align: justify;
    hyphens: auto;
}

/* Document element styling - Legislative format */

/* Clickable document elements */
.doc-clickable {
    cursor: pointer;
}

.doc-hover {
    background: var(--color-accent-light);
    border-radius: 4px;
    outline: 1px solid var(--color-accent-muted);
}

/* While the attach modifier (Ctrl/Cmd) is held, show that elements are
   click-to-attach: a crosshair cursor and an accent outline on hover. */
#rendered-content.attach-armed [data-xml-id] {
    cursor: crosshair;
}

#rendered-content.attach-armed [data-xml-id]:hover {
    outline: 1px dashed var(--color-accent);
    outline-offset: 1px;
    border-radius: 3px;
}

.doc-highlight {
    background: var(--color-accent-light) !important;
    outline: 2px solid var(--color-accent) !important;
    border-radius: 4px;
    transition: background 0.3s ease, outline 0.3s ease;
}

.doc-part {
    margin-bottom: var(--space-2xl);
    page-break-before: always;
}

.doc-part:first-child {
    page-break-before: avoid;
}

.doc-part > .element-header {
    font-family: var(--font-sans);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--color-text);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    text-align: center;
    margin-bottom: var(--space-lg);
    padding: var(--space-sm) 0;
}

.doc-chapter {
    margin-bottom: var(--space-xl);
}

.doc-chapter > .element-header {
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    text-align: center;
    margin-bottom: var(--space-md);
}

.doc-section {
    margin-bottom: var(--space-lg);
}

.doc-section > .element-header {
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 600;
    font-style: italic;
    color: var(--color-text);
    text-align: center;
    margin-bottom: var(--space-md);
}

.doc-subsection {
    margin-bottom: var(--space-md);
}

.doc-subsection > .element-header {
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text-muted);
    margin-bottom: var(--space-sm);
}

.doc-subsection > .element-header .subsection-heading {
    margin-left: var(--space-xs);
}

.doc-paragraph {
    margin-bottom: var(--space-md);
}

.doc-para-num {
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: var(--space-xs);
    text-indent: 0;
    display: block;
}

.doc-paragraph p {
    text-indent: 2em;
}

.doc-paragraph:first-child p:first-child {
    text-indent: 0;
}

.doc-paragraph .para-num {
    font-weight: 600;
    color: var(--color-text);
    margin-right: var(--space-xs);
    text-indent: 0;
    display: inline;
}

/* In-document ref links (link to element) */
.rendered-content a.internal-ref {
    color: var(--color-accent);
    text-decoration: underline;
    cursor: pointer;
}

.rendered-content a.internal-ref:hover {
    color: var(--color-accent-hover);
}

.authorial-note-marker {
    position: relative;
    display: inline-block;
    vertical-align: super;
    font-size: 0.72em;
    line-height: 1;
    text-indent: 0;
    padding: 0 0.2em;
    margin: 0 0.05em;
    border-radius: 999px;
    background: var(--color-accent-light);
    color: var(--color-accent-hover);
    border: 1px solid rgba(8, 145, 178, 0.18);
    cursor: pointer;
    white-space: nowrap;
}

.authorial-note-marker::after {
    content: attr(data-note-tooltip);
    position: absolute;
    left: 50%;
    bottom: calc(100% + 8px);
    transform: translateX(-50%);
    min-width: 180px;
    max-width: 320px;
    padding: 0.55rem 0.7rem;
    border-radius: var(--radius-md);
    background: #123046;
    color: #fff;
    font-size: 0.85rem;
    line-height: 1.45;
    white-space: normal;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    transition: opacity var(--transition-fast), visibility var(--transition-fast);
    z-index: 20;
}

.authorial-note-marker:hover::after,
.authorial-note-marker:focus-visible::after {
    opacity: 1;
    visibility: visible;
}

.rendered-content .authorial-note-marker:hover,
.rich-text-editor .authorial-note-marker:hover {
    background: #c9f0f5;
}

/* List wrapper for closing text after lists */
.doc-list-wrapper {
    margin-bottom: var(--space-md);
    text-indent: 0;
}

/* Standard list styling - UL and OL */
.doc-list {
    margin-left: 2.5em;
    margin-bottom: var(--space-md);
    padding-left: 0;
    text-indent: 0;
}

/* Unordered list styling */
ul.doc-list {
    list-style-type: none;
}

ul.doc-list > li {
    position: relative;
    padding-left: 1.5em;
}

ul.doc-list > li::before {
    content: "—";
    position: absolute;
    left: 0;
    color: var(--color-text);
}

/* Ordered list base styling */
ol.doc-list {
    list-style-type: none;
    counter-reset: list-counter;
}

ol.doc-list > li {
    counter-increment: list-counter;
    position: relative;
    padding-left: 2em;
}

ol.doc-list > li::before {
    position: absolute;
    left: 0;
    font-weight: 400;
    color: var(--color-text);
}

/* Alphabetic lower: (a), (b), (c) */
ol.doc-list.list-alpha-lower > li::before {
    content: "(" counter(list-counter, lower-alpha) ")";
}

/* Alphabetic upper: (A), (B), (C) */
ol.doc-list.list-alpha-upper > li::before {
    content: "(" counter(list-counter, upper-alpha) ")";
}

/* Roman lower: (i), (ii), (iii) */
ol.doc-list.list-roman-lower > li::before {
    content: "(" counter(list-counter, lower-roman) ")";
}

/* Roman upper: (I), (II), (III) */
ol.doc-list.list-roman-upper > li::before {
    content: "(" counter(list-counter, upper-roman) ")";
}

/* Decimal with parentheses: (1), (2), (3) */
ol.doc-list.list-decimal-paren > li::before {
    content: "(" counter(list-counter) ")";
}

/* Decimal with dot: 1., 2., 3. */
ol.doc-list.list-decimal > li::before {
    content: counter(list-counter) ".";
}

/* Dash/indent style */
ol.doc-list.list-dash > li::before {
    content: "—";
}

/* List item (point) styling */
.doc-point {
    margin-bottom: var(--space-xs);
    line-height: 1.7;
    text-align: justify;
}

.doc-point-content {
    display: inline;
}

/* Nested lists get different styling */
.doc-list .doc-list {
    margin-top: var(--space-xs);
    margin-left: 1.5em;
}

/* Second level: Roman numerals */
ol.doc-list ol.doc-list {
    counter-reset: list-counter-2;
}

ol.doc-list ol.doc-list > li {
    counter-increment: list-counter-2;
}

ol.doc-list ol.doc-list > li::before {
    content: "(" counter(list-counter-2, lower-roman) ")";
}

/* Third level: Numbers */
ol.doc-list ol.doc-list ol.doc-list {
    counter-reset: list-counter-3;
}

ol.doc-list ol.doc-list ol.doc-list > li {
    counter-increment: list-counter-3;
}

ol.doc-list ol.doc-list ol.doc-list > li::before {
    content: "(" counter(list-counter-3) ")";
}

/* Fourth level: Dash */
ol.doc-list ol.doc-list ol.doc-list ol.doc-list > li::before {
    content: "—";
}

/* Legacy point-num support for backward compatibility */
.doc-point .point-num {
    color: var(--color-text);
    margin-right: var(--space-xs);
    font-weight: 400;
}

.doc-subparagraph {
    margin-bottom: var(--space-sm);
}

/* Content wrapper */
.doc-content {
    display: block;
}

.doc-content p {
    margin: 0;
    line-height: 1.7;
    text-align: justify;
}

.doc-content p + p {
    margin-top: var(--space-sm);
    text-indent: 2em;
}

/* Tables */
.doc-table-wrapper {
    margin: var(--space-md) 0;
    overflow-x: auto;
}

.doc-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    background: var(--color-bg-elevated);
}

.doc-table th,
.doc-table td {
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--color-border);
    text-align: left;
    vertical-align: top;
}

.doc-table th {
    background: var(--color-bg);
    font-weight: 600;
    color: var(--color-text);
}

.doc-table tr:nth-child(even) td {
    background: var(--color-bg);
}

.doc-table tr:hover td {
    background: var(--color-bg-hover);
}

.doc-table td p,
.doc-table th p {
    text-indent: 0;
    margin-bottom: 1rem;
}

/* Images */
.doc-image-wrapper {
    margin: var(--space-md) 0;
    text-align: center;
}

.doc-image {
    max-width: 100%;
    height: auto;
    border: 1px solid var(--color-border);
    border-radius: 4px;
}

.doc-image-caption {
    margin-top: var(--space-xs);
    font-size: 0.85rem;
    color: var(--color-text-muted);
    font-style: italic;
}

/* Tree View */
.tree-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md);
}

.tree-node {
    user-select: none;
}

.tree-node-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
    border-radius: 4px;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.tree-node-header:hover {
    background: var(--color-bg-hover);
}

.tree-node-header.selected {
    background: var(--color-accent-muted);
}

.tree-toggle {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
    transition: transform var(--transition-fast);
    font-size: 0.7rem;
}

.tree-toggle.collapsed {
    transform: rotate(-90deg);
}

.tree-toggle.empty {
    visibility: hidden;
}

.tree-toggle.non-collapsible {
    display: none;
    cursor: default;
}

.tree-icon {
    color: var(--color-accent);
    font-size: 0.85rem;
}

.tree-label {
    flex: 1;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-type {
    font-size: 0.7rem;
    color: var(--color-text-muted);
    background: var(--color-bg);
    padding: 2px 6px;
    border-radius: 3px;
    border: 1px solid var(--color-border-subtle);
    flex-shrink: 0;
}

.tree-actions {
    display: none;
    gap: var(--space-xs);
    flex-shrink: 0;
    max-height: 18px;
}

.tree-node-header:hover .tree-actions {
    display: flex;
}

.tree-node-header .tree-actions .btn-icon {
    margin-top: -0.5em;
    max-height: 31px;
}

/* Move mode styles */
.tree-node.move-source > .tree-node-header {
    background: var(--color-warning-muted, #fff3cd);
    border: 2px dashed var(--color-warning, #ffc107);
}

.tree-node.move-source > .tree-node-header .tree-actions {
    display: flex;
}

.move-actions {
    display: flex;
    gap: 2px;
}

.btn-move-cancel {
    background: var(--color-warning, #ffc107);
    color: var(--color-text);
    border: none;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 3px;
    cursor: pointer;
}

.btn-move-cancel:hover {
    background: var(--color-warning-hover, #e0a800);
}

.btn-move-placement {
    background: var(--color-accent-light);
    color: var(--color-accent);
    border: 1px solid var(--color-accent-muted);
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 3px;
    min-width: 24px;
    cursor: pointer;
}

.btn-move-placement:hover {
    background: var(--color-accent);
    color: white;
    border-color: var(--color-accent);
}

.btn-move-inside {
    background: var(--color-accent-light);
    color: var(--color-success);
    border: 1px solid var(--color-accent-muted);
    cursor: pointer;
}

.btn-move-inside:hover {
    background: var(--color-success);
    color: white;
    border-color: var(--color-success);
}

.btn-move {
    cursor: pointer;
}

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

.tree-children {
    margin-left: var(--space-md);
    border-left: 1px solid var(--color-border-subtle);
    padding-left: var(--space-sm);
}

.tree-children.collapsed {
    display: none;
}

/* Content element nodes (tables, images) */
.tree-content-element .tree-node-header {
    background: var(--color-accent-light);
    border-radius: 4px;
}

.tree-content-icon {
    font-size: 0.9rem;
    margin-right: var(--space-xs);
}

.tree-type-content {
    background: var(--color-accent-light);
    color: var(--color-accent);
    border-color: var(--color-accent-muted);
}

/* XML Editor */
.xml-container {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.xml-editor {
    flex: 1;
    padding: var(--space-md);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-bg);
    border: none;
    resize: none;
    outline: none;
    white-space: pre;
    overflow: auto;
    tab-size: 2;
}

/* Version Panel Resize Handle */
/* Horizontal (row-resize) dividers: same wide-grab / 1px-line treatment as the
   column handle, applied to the version panel splitter and the assistant
   agents-vs-conversation splitter. */
.version-resize-handle,
.assistant-vertical-resize {
    height: 9px;
    margin: -4px 0;
    background: transparent;
    cursor: row-resize;
    flex-shrink: 0;
    position: relative;
    z-index: 20;
}

.version-resize-handle::before,
.assistant-vertical-resize::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 1px;
    transform: translateY(-50%);
    background: var(--color-border);
    transition: background var(--transition-fast), height var(--transition-fast);
}

.version-resize-handle:hover::before,
.version-resize-handle.dragging::before,
.assistant-vertical-resize:hover::before,
.assistant-vertical-resize.dragging::before {
    height: 3px;
    background: var(--color-accent);
}

.assistant-vertical-resize:focus-visible {
    outline: 2px solid var(--color-accent-muted);
    outline-offset: -2px;
}

/* Version Panel */
.version-panel {
    flex-shrink: 0;
    background: var(--color-bg-elevated);
    height: 200px;
    min-height: 100px;
    max-height: 50vh;
    display: flex;
    flex-direction: column;
}

.version-panel-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--color-border-subtle);
    background: var(--color-bg);
}

.version-panel-header h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text);
    margin: 0;
}

.version-panel-header .version-badge {
    font-size: 0.7rem;
    padding: 2px 6px;
    background: var(--color-primary-subtle);
    color: var(--color-primary);
    border-radius: var(--radius-sm);
}

.version-panel-header .btn {
    margin-left: auto;
}

.version-list-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-sm);
}

/* Version Release Groups */
.version-release-group {
    margin-bottom: var(--space-sm);
    border: 1px solid var(--color-border-subtle);
    border-radius: 6px;
    overflow: hidden;
}

.version-release-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--color-bg);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.version-release-header:hover {
    background: var(--color-bg-hover);
}

.release-toggle {
    color: var(--color-text-muted);
    font-size: 0.7rem;
    transition: transform var(--transition-fast);
}

.release-toggle.collapsed {
    transform: rotate(-90deg);
}

.release-name {
    flex: 1;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text);
}

.release-badge {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--color-accent);
    background: var(--color-accent-light);
    padding: 2px 8px;
    border-radius: 4px;
}

.release-name-unreleased {
    font-weight: 400;
    font-style: italic;
    color: var(--color-text-muted);
}

.release-badge-draft {
    color: var(--color-text-muted);
    background: var(--color-bg-hover);
}

.version-list-empty {
    padding: var(--space-sm) var(--space-lg);
    color: var(--color-text-subtle);
    font-size: 0.78rem;
    font-style: italic;
}

.release-details-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-subtle);
    font-size: 0.85rem;
    line-height: 1;
    padding: 2px 4px;
    border-radius: 3px;
    flex-shrink: 0;
}

.release-details-btn:hover {
    color: var(--color-accent);
    background: var(--color-accent-light);
}

/* Version List Items */
.version-list-items {
    background: var(--color-bg-elevated);
}

.version-list-items.collapsed {
    display: none;
}

.version-list-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    color: var(--color-text-muted);
    font-size: 0.8rem;
}

.version-list-loading .spinner {
    flex-shrink: 0;
    animation: spin 1s linear infinite;
}

.version-item {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: var(--space-sm) var(--space-md);
    padding-left: calc(var(--space-md) + var(--space-lg));
    border-bottom: 1px solid var(--color-border-subtle);
    transition: background var(--transition-fast);
    cursor: pointer;
}

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

.version-item:hover {
    background: var(--color-bg-hover);
}

.version-item:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: -2px;
}

.version-item.current {
    background: var(--color-accent-light);
    box-shadow: inset 3px 0 0 var(--color-accent);
}

.version-item-top {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.version-item-meta {
    margin-left: auto;
    font-size: 0.7rem;
    color: var(--color-text-subtle);
    white-space: nowrap;
}

.version-item-summary {
    font-size: 0.8rem;
    color: var(--color-text);
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.version-item-summary.summary-muted {
    color: var(--color-text-subtle);
    font-style: italic;
}

.version-item-summary-text {
    min-width: 0;
}

/* Added/removed line-count badge */
.diff-stats {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 400;
    flex-shrink: 0;
}

.diff-stat-add { color: var(--color-success); }
.diff-stat-del { color: var(--color-danger); }

.version-info {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.version-number {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-text);
}

.version-number.major {
    color: var(--color-accent);
    font-weight: 600;
}

.version-number.minor {
    color: var(--color-text-muted);
}

.version-time {
    font-size: 0.7rem;
    color: var(--color-text-subtle);
}

.version-creator {
    font-size: 0.7rem;
    color: var(--color-text-muted);
    font-style: italic;
}

.release-creator {
    font-size: 0.65rem;
    color: var(--color-text-muted);
    font-style: italic;
    margin-left: var(--space-xs);
}

.version-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.current-badge {
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--color-success);
    background: rgba(61, 122, 74, 0.1);
    padding: 2px 8px;
    border-radius: 3px;
}

.version-load-btn {
    font-size: 0.7rem;
    padding: 2px 8px;
}

/* Clickable version timestamp */
.version-time-clickable {
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.version-time-clickable:hover {
    background: var(--color-accent-light);
    color: var(--color-accent);
}

/* Timestamp editor popup */
.timestamp-editor-popup {
    z-index: 2000;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: var(--space-sm);
    min-width: 200px;
}

.timestamp-editor-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.timestamp-editor-content label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-text-muted);
}

.timestamp-editor-content input[type="datetime-local"] {
    padding: var(--space-xs);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    width: 100%;
}

.timestamp-editor-content input[type="datetime-local"]:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 2px var(--color-accent-light);
}

.timestamp-editor-buttons {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-xs);
    margin-top: var(--space-xs);
}

/* Form hint text */
.form-hint {
    display: block;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-top: var(--space-xs);
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden {
    display: none;
}

/* Link picker can be opened from another modal (e.g. table editor), so keep it above base modals. */
#ref-link-picker-modal {
    z-index: 1100;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
}

.modal-content {
    position: relative;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--color-border);
}

.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--color-text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: 4px;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--color-bg-hover);
    color: var(--color-text);
}

.modal-body {
    flex: 1;
    padding: var(--space-lg);
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    gap: var(--space-md);
    justify-content: flex-end;
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--color-border);
}

/* Modal Description */
.modal-description {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    margin-bottom: var(--space-lg);
    line-height: 1.5;
}

/* Form fields */
.form-field {
    margin-bottom: var(--space-md);
}

.form-field label {
    display: block;
    margin-bottom: var(--space-xs);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-text-muted);
}

.form-field input,
.form-field textarea {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    font-family: var(--font-sans);
    font-size: 1rem;
    color: var(--color-text);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    outline: none;
    transition: border-color var(--transition-fast);
}

.form-field input:focus,
.form-field textarea:focus {
    border-color: var(--color-accent);
}

.form-field textarea {
    min-height: 100px;
    resize: vertical;
}

#word-import-modal .hidden {
    display: none;
}

.word-import-mode-tabs {
    display: flex;
    gap: 0;
    margin-bottom: var(--space-md);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.word-import-mode-tab {
    flex: 1;
    padding: var(--space-sm) var(--space-md);
    border: 0;
    background: var(--color-bg-secondary);
    color: var(--color-text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.word-import-mode-tab:not(:last-child) {
    border-right: 1px solid var(--color-border);
}

.word-import-mode-tab:hover {
    background: var(--color-bg-hover);
    color: var(--color-text);
}

.word-import-mode-tab.active {
    background: var(--color-bg);
    color: var(--color-text);
}

.word-import-tab-panel {
    margin-top: var(--space-sm);
}

#word-import-clipboard-html,
#word-import-clipboard-text {
    min-height: 120px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
}

#word-transform-prompt {
    min-height: 140px;
}

#word-import-summary {
    padding: var(--space-xs) var(--space-sm);
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-sm);
}

#word-import-warnings {
    padding: var(--space-xs) var(--space-sm);
    border-left: 3px solid var(--color-warning);
    background: rgba(217, 119, 6, 0.08);
}

.form-field input:disabled {
    background: var(--color-bg);
    color: var(--color-text-muted);
    cursor: not-allowed;
}

/* Ref link picker: type toggle and panels */
.ref-link-type-row {
    margin-bottom: var(--space-md);
}

.ref-link-type-label {
    display: block;
    font-weight: 500;
    margin-bottom: var(--space-xs);
}

.ref-link-type-selector {
    display: inline-flex;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--color-border-subtle);
}

.ref-link-type-segment {
    display: flex;
    align-items: center;
    cursor: pointer;
    margin: 0 !important;
}

.ref-link-type-segment input {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    pointer-events: none;
}

.ref-link-type-segment-label {
    display: block;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--color-text-muted);
    transition: background-color 0.15s ease, color 0.15s ease;
}

.ref-link-type-segment:not(:last-child) .ref-link-type-segment-label {
    border-right: 1px solid var(--color-border);
}

.ref-link-type-segment:hover .ref-link-type-segment-label {
    background: var(--color-bg-hover);
    color: var(--color-text);
}

.ref-link-type-segment input:checked + .ref-link-type-segment-label {
    background: var(--color-bg);
    color: var(--color-accent);
    font-weight: 600;
}

.ref-link-url-hint.is-error {
    color: var(--color-danger);
    font-weight: 500;
}

.ref-link-panel.hidden {
    display: none;
}

.ref-link-panel {
    margin-bottom: var(--space-sm);
}

/* Ref link picker target list */
.ref-link-target-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    margin-top: var(--space-xs);
    background: var(--color-bg);
}

.ref-link-target-item {
    padding: var(--space-sm) var(--space-md);
    cursor: pointer;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--color-border-subtle);
}

.ref-link-target-item:last-child {
    border-bottom: none;
}

.ref-link-target-breadcrumb {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-bottom: var(--space-2xs);
}

.ref-link-target-main {
    font-weight: 500;
    margin-bottom: var(--space-2xs);
}

.ref-link-target-type {
    display: inline-block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-accent);
    margin-right: var(--space-xs);
}

.ref-link-target-id {
    font-size: 0.75rem;
    font-family: var(--font-mono);
    color: var(--color-text-subtle);
    word-break: break-all;
}

.ref-link-target-empty,
.ref-link-target-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 3rem;
    padding: var(--space-sm) var(--space-md);
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.ref-link-target-empty {
    font-style: italic;
}

.ref-link-target-loading {
    gap: var(--space-sm);
    font-weight: 500;
}

.ref-link-target-loading::before {
    content: "";
    width: 0.9rem;
    height: 0.9rem;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-accent);
    border-radius: 999px;
    animation: spin 0.8s linear infinite;
}

.ref-link-version-block {
    margin-top: var(--space-sm);
}

.ref-link-version-block-label {
    display: block;
    font-weight: 500;
    margin-bottom: var(--space-xs);
}

.ref-link-version-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-md);
}

.ref-link-version-checkbox-label {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    cursor: pointer;
    font-weight: 400;
}

.ref-link-version-checkbox-label input {
    width: auto;
}

.ref-link-version-select-wrap {
    display: inline-flex;
    align-items: center;
    min-width: 0;
}

.ref-link-version-select-wrap.hidden {
    display: none;
}

.ref-link-version-select-wrap select {
    width: 100%;
    min-width: 12rem;
    max-width: 20rem;
}

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

.ref-link-target-item:hover,
.ref-link-target-item.selected {
    background: var(--color-bg-hover);
}

.ref-link-target-item.selected {
    border-left: 3px solid var(--color-accent);
}

.form-field-num-override-row {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-xs);
}

.form-field-num-override-row input[type="checkbox"] {
    width: auto;
}

.form-field-num-override-row label {
    margin-bottom: 0;
    font-weight: 400;
}

.form-field-eid-override-row {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-xs);
}

.form-field-eid-override-row input[type="checkbox"] {
    width: auto;
}

.form-field-eid-override-row label {
    margin-bottom: 0;
    font-weight: 400;
}

/* Rich Text Editor */
.rich-text-editor-wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.rich-text-toolbar {
    display: flex;
    gap: var(--space-xs);
    padding: var(--space-xs);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-bottom: none;
    border-radius: 6px 6px 0 0;
}

.rich-text-toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-xs) var(--space-sm);
    min-width: 32px;
    height: 32px;
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text);
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.rich-text-toolbar-btn:hover {
    background: var(--color-bg-hover);
    border-color: var(--color-accent);
}

.rich-text-toolbar-btn.active {
    background: var(--color-accent-light);
    border-color: var(--color-accent);
    color: var(--color-accent);
}

.rich-text-toolbar-btn-ref {
    font-size: 0.8rem;
}

.rich-text-toolbar-btn-note {
    font-size: 0.8rem;
}

.rich-text-editor {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.6;
    color: var(--color-text);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 0 0 6px 6px;
    outline: none;
    transition: border-color var(--transition-fast);
    min-height: 100px;
}

.rich-text-editor:focus {
    border-color: var(--color-accent);
}

.rich-text-editor[data-placeholder]:empty:before {
    content: attr(data-placeholder);
    color: var(--color-text-subtle);
    pointer-events: none;
}

.rich-text-editor a.internal-ref {
    color: var(--color-accent);
    text-decoration: underline;
    cursor: pointer;
}

.rich-text-editor .authorial-note-marker {
    user-select: none;
}

.rich-text-field {
    width: 100%;
}

/* Table cell editor (with toolbar) */
.editable-cell {
    position: relative;
    padding: 0;
    min-height: 32px;
}

.editable-cell .table-cell-editor {
    width: 100%;
    height: 100%;
}

.editable-cell .rich-text-toolbar {
    padding: var(--space-xs);
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
}

.editable-cell .rich-text-toolbar-btn {
    min-width: 28px;
    height: 28px;
    padding: var(--space-xs);
    font-size: 0.75rem;
}

.editable-cell .rich-text-editor {
    min-height: auto;
    padding: var(--space-xs);
    border: 1px solid transparent;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    font-size: 0.875rem;
}

/* Restore normal block/list spacing inside table cell editors. */
.editable-cell .rich-text-editor p {
    margin: 0 0 var(--space-sm) 0;
    padding: 0;
    text-indent: 0;
}

.editable-cell .rich-text-editor p:last-child {
    margin-bottom: 0;
}

.editable-cell .rich-text-editor ul,
.editable-cell .rich-text-editor ol {
    margin: var(--space-xs) 0 var(--space-sm) var(--space-lg);
    padding-left: var(--space-md);
}

.editable-cell .rich-text-editor li {
    margin: 0 0 var(--space-2xs) 0;
    padding: 0;
}

.editable-cell .rich-text-editor:focus {
    border-color: var(--color-accent);
    background: var(--color-bg);
}

.editable-cell.focused .rich-text-editor,
.editable-cell.focused .rich-text-toolbar {
    border-color: var(--color-accent);
}

.editable-cell .rich-text-editor-wrapper {
    border: 1px solid var(--color-border);
    border-radius: 4px;
}

.editable-cell.focused .rich-text-editor-wrapper {
    border-color: var(--color-accent);
}

.field-hint {
    display: block;
    margin-top: var(--space-xs);
    font-size: 0.75rem;
    color: var(--color-text-subtle);
    font-style: italic;
}

.field-hint code {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    background: var(--color-bg);
    padding: 2px 6px;
    border-radius: 3px;
    font-style: normal;
}

.field-error {
    display: block;
    margin-top: var(--space-xs);
    font-size: 0.8rem;
    color: var(--color-error, #c00);
}

.field-error.hidden {
    display: none;
}

/* Element Path Display */
.element-path-field {
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--color-border-subtle);
}

.element-path {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
    background: var(--color-bg);
    border-radius: 6px;
    font-size: 0.85rem;
}

.path-segment {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.path-type {
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-text-subtle);
    background: var(--color-border-subtle);
    padding: 2px 6px;
    border-radius: 3px;
}

.path-id {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.path-segment-current .path-type {
    background: var(--color-accent-light);
    color: var(--color-accent);
}

.path-segment-current .path-id {
    color: var(--color-text);
    font-weight: 500;
}

.path-separator {
    color: var(--color-text-subtle);
    font-weight: 300;
    margin: 0 2px;
}

/* Merged Location / eId: path + editable current segment */
.form-field-location-eid .element-path-eid {
    flex-wrap: wrap;
    align-items: center;
}

.form-field-location-eid .path-segment-editable {
    display: inline-flex;
    align-items: center;
}

.form-field-location-eid .path-segment-input-row {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    margin-left: var(--space-xs);
}

.form-field-location-eid .path-segment-input {
    min-width: 120px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid var(--color-border);
}

.form-field-location-eid .path-segment-input:disabled {
    background: var(--color-bg);
    color: var(--color-text-muted);
    border-color: var(--color-border-subtle);
}

/* Context Menu */
.context-menu {
    position: fixed;
    z-index: 1001;
    min-width: 240px; /* enough for "Insert at: Top / Bottom" row without clipping */
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.context-menu.hidden {
    display: none;
}

.context-menu-header {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-subtle);
    background: var(--color-bg);
}

.context-menu-item {
    display: block;
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    color: var(--color-text);
    background: transparent;
    border: none;
    text-align: left;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.context-menu-item:hover {
    background: var(--color-bg-hover);
}

.context-menu-separator {
    height: 1px;
    background: var(--color-border-subtle);
    margin: var(--space-xs) 0;
}

.context-menu-subheader {
    padding: var(--space-xs) var(--space-md);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-subtle);
    background: var(--color-bg);
}

.context-menu-icon {
    margin-right: var(--space-xs);
}

.context-menu-insert-position {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
    background: var(--color-bg);
}

.context-menu-insert-position-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-subtle);
    margin-right: var(--space-xs);
    flex-shrink: 0;
}

.context-menu-position-btn {
}

.context-menu-position-btn.is-active {
    background: var(--color-accent-light);
    color: var(--color-accent);
    font-weight: 600;
}

/* Table Editor Modal */
.modal-large {
    max-width: 800px;
}

.table-editor-controls {
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--color-border-subtle);
}

.table-editor-help {
    margin-top: var(--space-xs);
    margin-bottom: 0;
    font-size: 0.8rem;
    color: var(--color-text-subtle);
}

.form-row {
    display: flex;
    align-items: flex-end;
    gap: var(--space-md);
    margin-bottom: var(--space-md);
}

.form-row .form-field {
    margin-bottom: 0;
    flex: 0 0 100px;
}

.table-preview-container {
    max-height: 400px;
    overflow: auto;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    padding: var(--space-md);
    background: var(--color-bg);
}

.table-add-row-below {
    display: block;
    width: 100%;
    margin-top: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
}

.table-editor-preview {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.table-editor-preview th,
.table-editor-preview td {
    padding: var(--space-sm);
    border: 1px solid var(--color-border);
    min-width: 80px;
}

.table-editor-preview th {
    background: var(--color-bg-elevated);
    font-weight: 600;
}

.table-editor-preview .editable-cell {
    outline: none;
    cursor: text;
}

.table-editor-preview .editable-cell:focus {
    background: var(--color-accent-light);
    outline: 2px solid var(--color-accent);
}

.table-editor-preview .editable-cell.focused {
    background: var(--color-accent-light);
}

.table-editor-preview .table-row-actions {
    width: 1%;
    white-space: nowrap;
    padding: var(--space-xs);
    vertical-align: middle;
    background: var(--color-bg-secondary);
    border-right: 1px solid var(--color-border);
}

.table-editor-preview .table-row-actions-wrap {
    display: flex;
    gap: var(--space-2xs);
    align-items: center;
}

.table-editor-preview .table-row-actions .btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: color var(--transition-fast), background var(--transition-fast);
}

.table-editor-preview .table-row-actions .btn-icon:hover {
    color: var(--color-accent);
    background: var(--color-bg-hover);
}

.table-editor-preview .table-row-actions .table-row-action-delete:hover:not(:disabled) {
    color: var(--color-danger);
    background: var(--color-danger-subtle);
}

.table-editor-preview .table-row-actions .table-row-action-delete:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Help Button in Header */
.btn-icon-header {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-icon-header:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
    color: #ffffff;
}

.btn-icon-header:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(103, 207, 224, 0.3);
}

/* Image Modal */
.image-preview-container {
    margin-bottom: var(--space-md);
    text-align: center;
    padding: var(--space-md);
    background: var(--color-bg-secondary);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}

.image-preview-container.hidden {
    display: none;
}

.image-preview-container img {
    max-width: 100%;
    max-height: 300px;
    border-radius: var(--radius-sm);
}

#image-file-input {
    width: 100%;
    padding: var(--space-sm);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
}

#image-file-input:hover {
    border-color: var(--color-accent);
}

#image-file-input::file-selector-button {
    padding: var(--space-xs) var(--space-md);
    margin-right: var(--space-md);
    background: var(--color-accent);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition-fast);
}

#image-file-input::file-selector-button:hover {
    background: var(--color-accent-hover);
}

/* Help Modal */
.modal-help {
    max-width: 700px;
    max-height: 85vh;
}

.hotkeys-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.hotkeys-category {
    border: 1px solid var(--color-border-subtle);
    border-radius: 8px;
    overflow: hidden;
}

.hotkeys-category-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border-subtle);
}

.hotkeys-category-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text);
}

.hotkeys-category-description {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.hotkeys-list {
    padding: var(--space-sm) 0;
}

.hotkey-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-xs) var(--space-md);
    transition: background var(--transition-fast);
}

.hotkey-item:hover {
    background: var(--color-bg-hover);
}

.hotkey-description {
    font-size: 0.875rem;
    color: var(--color-text);
}

.hotkey-keys {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 var(--space-sm);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-text);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

kbd.kbd-wide {
    min-width: auto;
    padding: 0 var(--space-sm);
}

.hotkey-separator {
    font-size: 0.75rem;
    color: var(--color-text-subtle);
    margin: 0 2px;
}

.help-footer-hint {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-right: auto;
}

.help-footer-hint kbd {
    margin: 0 2px;
}

/* Scrollbar styling. Gutter = thumb (6px) + an even ~4px gap on each side. */
::-webkit-scrollbar {
    width: 14px;
    height: 14px;
}

::-webkit-scrollbar-track {
    background: var(--color-bg-elevated);
}

/* Transparent border + padding-box clip insets the thumb evenly on all sides,
   so it reads as a rounded pill floating in the track with a ~4px gap. The gap
   has to be symmetric: a one-sided border subtracts from the radius on that
   side only (border-radius − border-width), squaring the far corners. */
::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 7px;
    border: 4px solid transparent;
    background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-muted);
    background-clip: padding-box;
}

/* Loading state */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-2xl);
    color: var(--color-text-muted);
}

/* Panel skeleton loading - shimmer sweeps left to right */
.skeleton {
    min-height: 0.75em;
    background: var(--color-border-subtle);
    border-radius: var(--radius-sm);
}

@media (prefers-reduced-motion: no-preference) {
    .skeleton {
        background: linear-gradient(
            90deg,
            var(--color-border-subtle) 0%,
            var(--color-border-subtle) 35%,
            #eef2f6 48%,
            #eef2f6 52%,
            var(--color-border-subtle) 65%,
            var(--color-border-subtle) 100%
        );
        background-size: 200% 100%;
        background-position: 100% 0;
        animation: skeleton-shimmer 1.5s linear infinite;
    }
}

@keyframes skeleton-shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

.panel-skeleton[data-panel="document-picker"] .skeleton-row { height: 20px; }
.panel-skeleton[data-panel="document-picker"] .skeleton-row.narrow { width: 40%; }
.panel-skeleton[data-panel="document-picker"] .skeleton-table-row { display: flex; gap: var(--space-md); padding: var(--space-md) var(--space-lg); align-items: center; border-bottom: 1px solid var(--color-border-subtle); }
.panel-skeleton[data-panel="document-picker"] .skeleton-table-row .skeleton { flex: 1; max-width: 280px; height: 16px; }
.panel-skeleton[data-panel="document-picker"] .skeleton-table-row .skeleton.short { flex: 0; width: 60px; max-width: none; }
.panel-skeleton[data-panel="document-picker"] .skeleton-table-row .skeleton.actions { flex: 0; width: 64px; max-width: none; }

.panel-skeleton[data-panel="tree"] .skeleton-node { display: flex; align-items: center; gap: var(--space-sm); padding: var(--space-xs) var(--space-sm); }
.panel-skeleton[data-panel="tree"] .skeleton-node .skeleton { height: 14px; }
.panel-skeleton[data-panel="tree"] .skeleton-node .skeleton.toggle { width: 18px; flex-shrink: 0; }
.panel-skeleton[data-panel="tree"] .skeleton-node .skeleton.label { flex: 1; max-width: 180px; }
.panel-skeleton[data-panel="tree"] .skeleton-node.indent { padding-left: calc(var(--space-sm) + 18px + var(--space-sm)); }

.panel-skeleton[data-panel="version-list"] .skeleton-release { padding: var(--space-sm) var(--space-md); border-bottom: 1px solid var(--color-border-subtle); }
.panel-skeleton[data-panel="version-list"] .skeleton-release .skeleton { height: 14px; margin-bottom: var(--space-xs); }
.panel-skeleton[data-panel="version-list"] .skeleton-release .skeleton.title { width: 70%; }
.panel-skeleton[data-panel="version-list"] .skeleton-item { display: flex; align-items: center; padding: var(--space-xs) var(--space-md); padding-left: calc(var(--space-md) + var(--space-lg)); border-bottom: 1px solid var(--color-border-subtle); gap: var(--space-md); }
.panel-skeleton[data-panel="version-list"] .skeleton-item .skeleton { height: 12px; }
.panel-skeleton[data-panel="version-list"] .skeleton-item .skeleton.version { width: 36px; }
.panel-skeleton[data-panel="version-list"] .skeleton-item .skeleton.time { flex: 1; max-width: 120px; }

.panel-skeleton[data-panel="rendered-document"] .skeleton-doc { max-width: 400px; margin: 0 auto var(--space-lg); }
.panel-skeleton[data-panel="rendered-document"] .skeleton-doc .skeleton { height: 1em; margin-bottom: var(--space-sm); }
.panel-skeleton[data-panel="rendered-document"] .skeleton-doc .skeleton.title { height: 1.4em; width: 80%; margin-bottom: var(--space-md); }
.panel-skeleton[data-panel="rendered-document"] .skeleton-doc .skeleton.line { width: 100%; }
.panel-skeleton[data-panel="rendered-document"] .skeleton-doc .skeleton.line.short { width: 85%; }
.panel-skeleton[data-panel="rendered-document"] .skeleton-doc .skeleton.line.medium { width: 92%; }
.panel-skeleton[data-panel="rendered-document"] .skeleton-doc .skeleton.line.last { width: 60%; margin-bottom: 0; }
.panel-skeleton[data-panel="rendered-document"] .skeleton-doc .skeleton + .skeleton { margin-top: var(--space-sm); }
.panel-skeleton[data-panel="rendered-document"] .skeleton-doc .skeleton.line + .skeleton.line { margin-top: 0.6em; }

.panel-skeleton[data-panel="tasks"] { padding: var(--space-sm); }
.panel-skeleton[data-panel="tasks"] .skeleton-task { display: flex; align-items: center; gap: var(--space-sm); padding: var(--space-sm); }
.panel-skeleton[data-panel="tasks"] .skeleton-task .skeleton { height: 12px; }
.panel-skeleton[data-panel="tasks"] .skeleton-task .skeleton.dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.panel-skeleton[data-panel="tasks"] .skeleton-task .skeleton.label { flex: 1; max-width: 200px; }

/* Saving button state */
.btn.saving {
    position: relative;
    cursor: wait;
}

.btn.saving .spinner {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Notifications */
@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

.notification {
    animation: slideInRight 0.3s ease;
}

/* Cover page styling */
.doc-coverpage {
    text-align: center;
    padding: calc(var(--space-2xl) * 1.5) var(--space-lg) var(--space-2xl);
    margin-bottom: var(--space-2xl);
    border-bottom: none;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.doc-coverpage .doc-title {
    font-family: var(--font-sans);
    font-size: 2.75rem;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: var(--space-lg);
    line-height: 1.15;
}

.doc-coverpage .doc-subtitle {
    font-size: 1.1rem;
    color: var(--color-text-muted);
    margin-bottom: var(--space-2xl);
}

.doc-cover-metadata {
    width: min(100%, 44rem);
    margin-bottom: var(--space-2xl);
}

.doc-cover-meta-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm) 0;
    border-top: 1px solid var(--color-border);
}

.doc-cover-meta-row:last-child {
    border-bottom: 1px solid var(--color-border);
}

.doc-cover-meta-label {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.doc-cover-meta-value {
    font-size: 0.95rem;
    color: var(--color-text);
}

.doc-cover-note {
    width: min(100%, 44rem);
    margin-top: var(--space-lg);
    color: var(--color-text-muted);
    line-height: 1.6;
}

.doc-cover-note p {
    margin: 0;
}

.doc-cover-actions {
    width: min(100%, 44rem);
    display: flex;
    justify-content: center;
    margin-top: var(--space-md);
}

.doc-preface {
    margin-bottom: var(--space-2xl);
    padding-bottom: var(--space-xl);
    text-align: justify;
}

.doc-preface > .element-header {
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    text-align: center;
    margin-bottom: var(--space-md);
}

/* Glossary/Definitions styling */
.doc-glossary {
    margin-top: var(--space-2xl);
    padding-top: var(--space-xl);
}

.doc-glossary > .element-header {
    font-family: var(--font-sans);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--color-text);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    text-align: center;
    margin-bottom: var(--space-lg);
}

.doc-definition {
    margin-bottom: var(--space-md);
    padding-left: var(--space-lg);
    text-indent: -var(--space-lg);
}

.doc-definition .def-term {
    font-weight: 700;
    color: var(--color-text);
}

.doc-definition .def-meaning {
    color: var(--color-text);
}

/* Schedule/Annex styling */
.doc-schedule {
    margin-top: var(--space-2xl);
    padding-top: var(--space-xl);
    page-break-before: always;
}

.doc-schedule > .element-header {
    font-family: var(--font-sans);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--color-text);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    text-align: center;
    margin-bottom: var(--space-lg);
}

/* =============================================================================
   Changelog: version summaries, diff viewer, undo conflict negotiation
   ========================================================================== */

/* Version + release detail modals */
#version-detail-modal .hidden,
#release-detail-modal .hidden { display: none !important; }

.version-detail {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.version-detail-title {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.vd-number {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--color-text);
}

.vd-number.major { color: var(--color-accent); }
.vd-number.minor { color: var(--color-text-muted); }

.vd-kind {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
    color: var(--color-text-muted);
    background: var(--color-bg-hover);
    border: 1px solid var(--color-border-subtle);
    padding: 2px 8px;
    border-radius: 999px;
}

.vd-current {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--color-success);
    background: rgba(61, 122, 74, 0.1);
    padding: 2px 8px;
    border-radius: 999px;
}

.version-detail-meta {
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.vd-meta-row {
    display: flex;
    align-items: baseline;
    gap: var(--space-md);
}

.vd-meta-row dt {
    flex: 0 0 60px;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-subtle);
}

.vd-meta-row dd {
    margin: 0;
    font-size: 0.85rem;
    color: var(--color-text);
}

.vd-time-dd {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

.vd-time { cursor: pointer; }
.vd-time:hover { color: var(--color-accent); }

.vd-time-rel {
    font-size: 0.75rem;
    color: var(--color-text-subtle);
}

.vd-inline-edit {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-subtle);
    font-size: 0.85rem;
    padding: 0 2px;
    line-height: 1;
}

.vd-inline-edit:hover { color: var(--color-accent); }

.vd-time-editor {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-basis: 100%;
    margin-top: var(--space-xs);
}

.vd-time-editor input {
    padding: var(--space-xs);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
}

.version-detail-summary {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.vd-summary-head {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.vd-summary-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-subtle);
}

.vd-summary-text {
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--color-text);
    white-space: pre-wrap;
}

.vd-summary-text.summary-muted {
    color: var(--color-text-subtle);
    font-style: italic;
}

.vd-summary-text.summary-user { color: var(--color-text); }

/* Rich context items (text rationale + conversation reference + future kinds). */
.vd-context-text { display: flex; flex-direction: column; gap: 8px; }
.vd-context-text-item { white-space: pre-wrap; }

.vd-context-conversation { display: flex; }
.vd-context-conversation-open {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font: inherit;
    font-size: 0.82rem;
    padding: 4px 10px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-bg-elevated);
    color: var(--color-accent);
    cursor: pointer;
}
.vd-context-conversation-open::before { content: '💬'; }
.vd-context-conversation-open:hover {
    background: var(--color-accent-light);
    border-color: var(--color-accent-muted);
}

.vd-summary-editor {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.vd-summary-editor textarea {
    width: 100%;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    padding: var(--space-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    resize: vertical;
}

.vd-editor-buttons {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-xs);
}

.version-summary-row {
    display: flex;
    align-items: flex-start;
    gap: var(--space-xs);
    width: 100%;
    margin-top: 2px;
}

.version-summary-text {
    flex: 1;
    font-size: 0.8rem;
    color: var(--color-text);
    line-height: 1.35;
}

.version-summary-text.summary-muted {
    color: var(--color-text-subtle);
    font-style: italic;
}

.version-summary-text.summary-user {
    color: var(--color-text);
}

.version-summary-edit {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-subtle);
    font-size: 0.8rem;
    padding: 0 2px;
    line-height: 1;
    flex-shrink: 0;
}

.version-summary-edit:hover {
    color: var(--color-accent);
}

.version-summary-editor {
    width: 100%;
    margin-top: var(--space-xs);
}

.version-summary-input {
    width: 100%;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    padding: var(--space-xs);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    resize: vertical;
}

.version-summary-buttons {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-xs);
    margin-top: var(--space-xs);
}

.version-diff-btn,
.version-undo-btn {
    margin-left: var(--space-xs);
}

/* Diff viewer */
.diff-view {
    font-family: var(--font-mono, monospace);
    font-size: 0.78rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: var(--space-sm);
    /* Scroll within the shared modal-body, not as a separate nested region. */
    overflow-x: auto;
    margin: 0;
}

/* Word-level diff (diff-match-patch JSON tuples) */
.diff-word-view { white-space: pre-wrap; word-break: break-word; font-family: var(--font-mono, ui-monospace, monospace); font-size: 0.85rem; line-height: 1.45; }
.diff-word-view ins.diff-add,
.diff-word-view del.diff-del { text-decoration: none; padding: 0 1px; border-radius: 2px; }
.diff-word-view ins.diff-add { background: rgba(5, 150, 105, 0.14); color: var(--color-success); }
.diff-word-view del.diff-del { background: rgba(220, 38, 38, 0.12); color: var(--color-danger); }
.diff-word-view .diff-gap { color: var(--color-text-muted); font-style: italic; }

.version-tool-badge {
    display: inline-block;
    font-size: 0.75rem;
    font-family: var(--font-mono, ui-monospace, monospace);
    padding: 0.1rem 0.45rem;
    border-radius: 4px;
    background: var(--color-bg-subtle, rgba(0, 0, 0, 0.06));
    color: var(--color-text-muted);
    letter-spacing: 0.02em;
}

.diff-modal-summary {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-bottom: var(--space-sm);
}

/* Diff modal tabs: redline ("Document changes") vs technical word-diff */
.diff-tabs {
    display: flex;
    gap: var(--space-xs);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--space-sm);
}

.diff-tab {
    appearance: none;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-text-muted);
    cursor: pointer;
}

.diff-tab:hover { color: var(--color-text); }

.diff-tab.active {
    color: var(--color-accent, var(--color-text));
    border-bottom-color: var(--color-accent, var(--color-text));
}

/* Inline redline ("Document changes") view */
.diff-redline {
    /* The modal-body is already the scroll container (max-height 80vh); giving
       this panel its own max-height + overflow produced a redundant nested
       scrollbar. Let it grow and scroll horizontally only if truly needed. */
    overflow-x: auto;
    padding: var(--space-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg);
}

/* The tab switcher toggles `.hidden` on the inactive panel; there is no global
   .hidden utility, so scope the hide rule to the diff modal (cf. the version /
   release detail modals). Without this, both panels render at once. */
#diff-modal .hidden { display: none !important; }

.redline-document {
    font-size: 0.9rem;
    line-height: 1.5;
    /* Template paragraphs can contain long unbreakable runs (e.g. "______"
       fill-in lines or dotted leaders). In the narrow diff modal these can't
       wrap and force the whole view wide with a blank scroll gutter, so allow
       breaking inside such tokens. */
    overflow-wrap: anywhere;
    word-break: break-word;
}
/* Elements are clickable to jump to the same element in the main document. */
.redline-document [data-xml-id] { cursor: pointer; }

/* Collapsed stand-in for unchanged content that was pruned from the view. */
.redline-omitted {
    color: var(--color-text-subtle);
    text-align: center;
    padding: 2px 0;
    font-size: 1.1rem;
    letter-spacing: 3px;
    line-height: 1;
    user-select: none;
}

/* Inline word-level changes inside the rendered document */
.redline-document ins.diff-add,
.redline-document del.diff-del { text-decoration: none; padding: 0 1px; border-radius: 2px; }
.redline-document ins.diff-add { background: rgba(5, 150, 105, 0.16); color: var(--color-success); }
.redline-document del.diff-del { background: rgba(220, 38, 38, 0.14); color: var(--color-danger); }
.redline-document .diff-gap { color: var(--color-text-muted); font-style: italic; }

/* Block-level change markers */
.redline-block {
    position: relative;
    border-left: 3px solid transparent;
    padding-left: var(--space-sm);
    margin: var(--space-xs) 0;
}

.redline-added { border-left-color: var(--color-success); background: rgba(5, 150, 105, 0.06); }
.redline-removed { border-left-color: var(--color-danger); background: rgba(220, 38, 38, 0.06); }
.redline-removed, .redline-removed * { color: var(--color-text-muted); }
.redline-removed .doc-body, .redline-removed [class^="doc-"] { text-decoration: none; }
.redline-moved { border-left-color: var(--color-warning, #d97706); background: rgba(217, 119, 6, 0.06); }
.redline-modified { border-left: 3px solid var(--color-border); padding-left: var(--space-sm); }

.redline-tag {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.05rem 0.4rem;
    border-radius: 4px;
    margin-right: var(--space-xs);
    vertical-align: middle;
    color: #fff;
}

.redline-tag-added { background: var(--color-success); }
.redline-tag-removed { background: var(--color-danger); }
.redline-tag-moved { background: var(--color-warning, #d97706); }
.redline-tag-modified { background: var(--color-info, #2563eb); }

.redline-inline-fallback { margin: var(--space-xs) 0; }

/* Author-pinned number change shown where the number has no standalone node
   (part/chapter/section headers) and is rendered as a leading marker instead. */
.redline-num-change { margin-right: var(--space-xs); }

/* Link-target change marked on the link text itself: a dotted underline cues a
   reviewer to hover, and a styled custom tooltip reveals the old → new URL. */
.redline-link-changed {
    position: relative;
    text-decoration: underline dotted var(--color-warning, #d97706) 2px;
    text-underline-offset: 2px;
    background: rgba(217, 119, 6, 0.12);
    border-radius: 2px;
    cursor: help;
}

/* Styled, instant custom tooltip (the native title can't colour the URLs).
   Same dark-bubble idiom as .authorial-note-marker. It is portaled to <body>
   and positioned with position:fixed by JS (see _positionLinkTooltip) so the
   diff modal's scroll containers cannot clip it. */
.redline-link-tooltip {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    min-width: 220px;
    max-width: min(460px, 90vw);
    padding: 0.55rem 0.7rem;
    border-radius: var(--radius-md);
    background: #123046;
    color: #fff;
    font-size: 0.82rem;
    line-height: 1.4;
    text-align: left;
    white-space: normal;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
    pointer-events: none;
}
.redline-link-tooltip-floating {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1200;  /* above the diff modal (.modal z-index: 1000) */
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-fast), visibility var(--transition-fast);
}
.redline-link-tooltip-visible {
    opacity: 1;
    visibility: visible;
}
.redline-link-tooltip-title { font-weight: 600; margin-bottom: 0.1rem; }
.redline-link-tooltip-row { display: block; word-break: break-all; }
.redline-link-tooltip-label { opacity: 0.75; }
.redline-link-tooltip-url { font-family: var(--font-mono, monospace); }
.redline-link-tooltip-old .redline-link-tooltip-url {
    color: #fca5a5; text-decoration: line-through;
}
.redline-link-tooltip-new .redline-link-tooltip-url { color: #6ee7b7; }

/* Fallback note for link changes with no anchor to hover (e.g. a removed link):
   spell out the old → new URL inline at the end of the element. */
.redline-link-changes {
    margin: var(--space-xs) 0 0;
    padding: var(--space-xs) var(--space-sm);
    border-left: 3px solid var(--color-border);
    background: var(--color-bg-subtle, rgba(0, 0, 0, 0.03));
    border-radius: 0 4px 4px 0;
    font-size: 0.85rem;
}
.redline-link-change { line-height: 1.5; }
.redline-link-change-label { color: var(--color-text-muted, #6b7280); }
.redline-link-url {
    text-decoration: none;
    padding: 0 2px;
    border-radius: 2px;
    word-break: break-all;
    font-family: var(--font-mono, monospace);
}
del.redline-link-url { background: rgba(220, 38, 38, 0.14); color: var(--color-danger); }
ins.redline-link-url { background: rgba(5, 150, 105, 0.16); color: var(--color-success); }

/* ============================================================
   Structure outline view (diff modal "Structure" tab)
   ============================================================ */

.diff-structure {
    overflow-x: auto;
    padding: var(--space-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg);
    font-size: 0.9rem;
}

.structure-summary {
    font-weight: 600;
    color: var(--color-text-muted);
    padding: var(--space-xs) var(--space-sm) var(--space-sm);
    border-bottom: 1px solid var(--color-border-subtle);
    margin-bottom: var(--space-sm);
}

.structure-block {
    margin-bottom: var(--space-md);
    border-left: 2px solid var(--color-border-subtle);
    padding-left: var(--space-sm);
}

.structure-block-head {
    font-size: 0.85rem;
    color: var(--color-text);
    padding: 2px var(--space-sm);
    margin-bottom: 2px;
}

/* Ancestor breadcrumb is quiet; the container itself stands out. */
.structure-path {
    font-weight: 400;
    color: var(--color-text-subtle);
    margin-right: 0.35em;
}
.structure-self { font-weight: 700; }
.structure-self-link { cursor: pointer; }
.structure-self-link:hover { text-decoration: underline; }

.structure-rows {
    list-style: none;
    margin: 0;
    padding: 0;
}

.structure-row {
    display: flex;
    align-items: baseline;
    gap: var(--space-sm);
    padding: 3px var(--space-sm);
    border-left: 3px solid transparent;
    border-radius: 2px;
    cursor: pointer;
}
.structure-row:hover { background: var(--color-bg-hover); }

.structure-label {
    flex-shrink: 0;
    min-width: 6.5em;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--color-text-muted);
}

.structure-heading {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Status accents mirror the redline: green add, red remove, amber move. */
.structure-added { border-left-color: var(--color-success); }
.structure-removed { border-left-color: var(--color-danger); }
.structure-removed .structure-label,
.structure-removed .structure-heading { text-decoration: line-through; color: var(--color-text-muted); }
.structure-moved { border-left-color: var(--color-warning, #d97706); }
.structure-modified { border-left-color: var(--color-accent-muted); }

/* Incidental renumbering: a quiet, non-clickable aside under the block. */
.structure-renumbered {
    padding: 2px var(--space-sm);
    margin-left: 3px;
    font-size: 0.78rem;
    font-style: italic;
    color: var(--color-text-subtle);
}

.structure-badge {
    flex-shrink: 0;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.05rem 0.4rem;
    border-radius: 4px;
    color: #fff;
    white-space: nowrap;
}
.structure-badge-added { background: var(--color-success); }
.structure-badge-removed { background: var(--color-danger); }
.structure-badge-moved { background: var(--color-warning, #d97706); }
.structure-badge-modified { background: var(--color-accent); }

.structure-was {
    flex-shrink: 0;
    font-size: 0.72rem;
    font-style: italic;
    color: var(--color-text-subtle);
    white-space: nowrap;
}

/* Undo conflict negotiation */
.undo-conflict-hunks {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    margin-bottom: var(--space-md);
}

.conflict-hunk {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-sm);
}

.conflict-hunk-heading {
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: var(--space-xs);
    color: var(--color-text-muted);
}

.conflict-hunk-cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-sm);
}

.conflict-col-label {
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 2px;
    color: var(--color-text-subtle);
}

.conflict-col-ours .conflict-col-label { color: var(--color-accent); }
.conflict-col-theirs .conflict-col-label { color: var(--color-warning); }

@media (max-width: 720px) {
    .conflict-hunk-cols { grid-template-columns: 1fr; }
}

/* ============================================================
   AI Assistant panel (static/js/mixins/assistant.js)
   ============================================================ */

/* Embedded right-hand column, laid out like .panel-left (see editor-view). */
.assistant-panel {
    flex: 0 0 420px;
    min-width: 320px;
    max-width: 60%;
    display: flex;
    flex-direction: column;
    background: var(--color-bg-elevated);
    /* Divider is drawn by the assistant resize handle's 1px line. */
    overflow: hidden;
}

.assistant-panel.hidden { display: none; }

/* Hidden collapsible columns and their resize handles drop out of the flex row. */
.panel-left.hidden { display: none; }
.panel-resize-handle.hidden { display: none; }

/* ---- Tasks panel (docked at the top of the agents column) ----------------- */

.tasks-section {
    flex: 0 0 auto;
    height: 220px;
    min-height: 80px;
    display: flex;
    flex-direction: column;
    background: var(--color-bg-elevated);
    overflow: hidden;
}

.tasks-header {
    display: flex;
    align-items: center;
    height: var(--column-header-height);
    box-sizing: border-box;
    flex-shrink: 0;
    gap: 6px;
    padding: 0 10px 0 16px;
    border-bottom: 1px solid var(--color-border-subtle);
}

.tasks-header h3 { margin: 0; font-size: 1rem; flex: 1; min-width: 0; }

.tasks-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.tasks-header-actions .btn-sm {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

.tasks-filter {
    font-size: 0.78rem;
    padding: 2px 4px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg);
    color: var(--color-text);
}

.tasks-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tasks-list:focus { outline: none; }

.tasks-empty {
    padding: 12px 10px;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.task-row {
    border-radius: 6px;
    border: 1px solid transparent;
}

.task-row-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    cursor: pointer;
    border-radius: 6px;
}

.task-row-header:hover { background: var(--color-bg-hover); }

.task-status-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--color-text-muted);
}

/* The inline dot doubles as a button that opens the status popover. */
button.task-status-dot {
    padding: 0;
    border: 2px solid transparent;
    box-sizing: border-box;
    cursor: pointer;
    transition: box-shadow var(--transition-fast);
}

button.task-status-dot:hover {
    box-shadow: 0 0 0 3px var(--color-bg-hover);
}

.task-status-dot.status-open { background: var(--color-accent); }
.task-status-dot.status-in-progress { background: var(--color-warning); }
.task-status-dot.status-blocked { background: var(--color-danger); }
.task-status-dot.status-done { background: var(--color-success); }
.task-status-dot.status-dismissed { background: var(--color-text-muted); }

.task-title {
    flex: 1;
    min-width: 0;
    font-size: 0.85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.task-title-muted { color: var(--color-text-muted); text-decoration: line-through; }

.task-chips {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

/* Clickable assignee cluster that opens the assignment popover. */
.task-assignees {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px;
    margin: -2px;
    border: none;
    background: none;
    border-radius: 6px;
    cursor: pointer;
}

.task-assignees:hover { background: var(--color-bg-hover); }

.task-assign-empty {
    font-size: 0.65rem;
    color: var(--color-text-muted);
    padding: 3px 6px;
    border: 1px dashed var(--color-border);
    border-radius: 999px;
}

.task-chip,
.task-badge {
    font-size: 0.65rem;
    line-height: 1;
    padding: 3px 6px;
    border-radius: 999px;
    white-space: nowrap;
}

.task-chip-user { background: var(--color-accent-light); color: var(--color-accent); }
.task-chip-agent { background: var(--color-bg-hover); color: var(--color-text-muted); border: 1px dashed var(--color-border); }
.task-chip-agent.linked { border-style: solid; color: var(--color-text); }

.task-badge-auto { background: var(--color-bg-hover); color: var(--color-text-muted); }
.task-badge-blocked { background: var(--color-danger-subtle); color: var(--color-danger); }
.task-badge-deps { background: var(--color-bg-hover); color: var(--color-text-muted); padding: 3px 5px; }

/* ---- quick-action popovers (status / assignment) ---- */
.task-popover {
    position: fixed;
    z-index: 1100;
    min-width: 160px;
    max-width: 260px;
    padding: 6px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.task-popover-heading {
    font-size: 0.66rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    padding: 6px 8px 2px;
}

.task-popover-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    text-align: left;
    font-size: 0.83rem;
    padding: 6px 8px;
    border: none;
    border-radius: 6px;
    background: none;
    color: var(--color-text);
    cursor: pointer;
}

.task-popover-item:hover { background: var(--color-bg-hover); }
.task-popover-item.primary { color: var(--color-accent); font-weight: 600; }
.task-popover-item.current { font-weight: 600; }

.task-popover-note {
    font-size: 0.72rem;
    color: var(--color-danger);
    padding: 4px 8px 2px;
    line-height: 1.35;
}

/* ---- detail modal sections ---- */
.task-detail-extra {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.task-detail-extra.hidden { display: none; }

.task-detail-hint {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin: 8px 0 0;
}

.task-detail-hint.hidden { display: none; }

.task-status-select {
    font-size: 0.85rem;
    padding: 4px 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg);
    color: var(--color-text);
}

.task-blocked-note {
    margin-left: 10px;
    font-size: 0.78rem;
    color: var(--color-danger);
}

.task-assign-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

/* In the detail modal the assignment controls render as a row of buttons. */
#task-detail-assign .task-popover-heading {
    width: 100%;
    padding: 0;
}

#task-detail-assign .task-popover-item {
    width: auto;
    border: 1px solid var(--color-border);
    padding: 5px 10px;
}

.task-pill-remove {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 0.95rem;
    line-height: 1;
    color: inherit;
    padding: 0 2px;
    opacity: 0.7;
}

.task-pill-remove:hover { opacity: 1; }

/* ---- dependency editor ---- */
.task-dep-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.task-dep-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
    padding: 3px 4px 3px 10px;
    border-radius: 999px;
    background: var(--color-bg-hover);
    color: var(--color-text);
}

.task-dep-pill.done { color: var(--color-text-muted); text-decoration: line-through; }
.task-dep-none { font-size: 0.8rem; color: var(--color-text-muted); }

.task-dep-add {
    font-size: 0.85rem;
    padding: 4px 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg);
    color: var(--color-text);
    max-width: 100%;
}

/* Delete sits on the left of the modal footer, away from Cancel/Save. */
.task-edit-delete { margin-right: auto; }
.task-edit-delete.hidden { display: none; }

.tasks-resize-handle {
    height: 9px;
    margin: -4px 0;
    background: transparent;
    cursor: row-resize;
    flex-shrink: 0;
    position: relative;
    z-index: 20;
}

.tasks-resize-handle::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 1px;
    transform: translateY(-50%);
    background: var(--color-border);
    transition: background var(--transition-fast), height var(--transition-fast);
}

.tasks-resize-handle:hover::before,
.tasks-resize-handle.dragging::before {
    height: 3px;
    background: var(--color-accent);
}

/* Tasks pop-out modal: a roomier copy of the docked list. */
.tasks-modal-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: var(--space-md);
}

.tasks-list-modal {
    max-height: 60vh;
    padding: 0;
}

.tasks-list-modal .task-title { font-size: 0.9rem; }

.assistant-header {
    display: flex;
    align-items: center;
    height: var(--column-header-height);
    box-sizing: border-box;
    flex-shrink: 0;
    gap: 8px;
    padding: 0 12px 0 16px;
    border-bottom: 1px solid var(--color-border-subtle);
}

/* Title flexes so the action buttons always hug the right edge. */
.assistant-header h3 { margin: 0; font-size: 1rem; flex: 1; min-width: 0; }

.assistant-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    margin-left: auto;
}

.assistant-header-actions .btn-sm {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

/* ---- Persistent agents list ---------------------------------------------- */

.assistant-agents {
    flex: 0 0 auto;
    height: 200px;
    min-height: 64px;
    display: flex;
    flex-direction: column;
    background: var(--color-bg);
}

.assistant-agents-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px 4px 16px;
    flex-shrink: 0;
}

.assistant-folder-tabs {
    display: flex;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.assistant-folder-tab {
    border: none;
    background: none;
    font: inherit;
    font-size: 0.78rem;
    color: var(--color-text-muted);
    padding: 3px 8px;
    border-radius: 6px;
    cursor: pointer;
}

.assistant-folder-tab:hover { background: var(--color-bg-hover); }

.assistant-folder-tab.active {
    background: var(--color-accent-light);
    color: var(--color-accent);
    font-weight: 600;
}

.assistant-agents-summary {
    font-size: 0.72rem;
    color: var(--color-text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.assistant-agents-list {
    flex: 1;
    overflow-y: auto;
    padding: 1px 8px 6px;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.assistant-agents-list:focus { outline: none; }

.assistant-agents-empty {
    padding: 12px 10px;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.assistant-agent-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
}

.assistant-agent-row:hover { background: var(--color-bg-hover); }
.assistant-agent-row.active { background: var(--color-accent-light); }
.assistant-agent-row:focus { outline: none; box-shadow: inset 0 0 0 2px var(--color-accent-muted); }
.assistant-agent-row.needs-attention .assistant-agent-title { font-weight: 600; }

/* Status indicator: idle = faint dot, attention = amber dot, working = dots. */
.assistant-agent-status {
    flex-shrink: 0;
    width: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.assistant-agent-status-idle::before,
.assistant-agent-status-attention::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.assistant-agent-status-idle::before { background: var(--color-border); }
.assistant-agent-status-attention::before { background: var(--color-warning, #d98324); }

.assistant-agent-status-working span {
    width: 4px;
    height: 4px;
    margin: 0 1px;
    border-radius: 50%;
    background: var(--color-accent);
    display: inline-block;
    animation: assistant-pulse 1.2s infinite ease-in-out;
}
.assistant-agent-status-working span:nth-child(2) { animation-delay: 0.2s; }
.assistant-agent-status-working span:nth-child(3) { animation-delay: 0.4s; }

.assistant-agent-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.assistant-agent-title {
    font-size: 0.84rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.assistant-agent-meta {
    font-size: 0.72rem;
    color: var(--color-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Conversation pane fills the rest of the panel below the agents list. */
.assistant-conversation {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header for the focused agent: title + always-visible lifecycle actions. */
.assistant-active-header {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    padding: 5px 8px 5px 16px;
    border-bottom: 1px solid var(--color-border-subtle);
    background: var(--color-bg-elevated);
}

.assistant-active-header.hidden { display: none; }

.assistant-active-title {
    flex: 1;
    min-width: 0;
    font-size: 0.82rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.assistant-active-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}

.assistant-active-action {
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    color: var(--color-text-muted);
    padding: 4px 6px;
    border-radius: 5px;
}

.assistant-active-action:hover {
    background: var(--color-bg-hover);
    color: var(--color-text);
}

.assistant-active-action:focus-visible {
    outline: 2px solid var(--color-accent-muted);
    outline-offset: 1px;
}

.assistant-empty-conversation {
    margin: auto;
    padding: 16px;
    text-align: center;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.assistant-messages {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Never let transcript items shrink to fit the panel — the container scrolls
   instead. Without this, items whose content is scrollable (the proposal
   card's diff) collapse to a sliver once the transcript overflows. */
.assistant-messages > * { flex-shrink: 0; }

.assistant-msg {
    max-width: 92%;
    padding: 6px 10px;
    border-radius: 10px;
    font-size: 0.9rem;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

.assistant-msg-user {
    align-self: flex-end;
    background: var(--color-accent-light);
    color: var(--color-text);
    position: relative;
}

/* Edit-and-resend affordance: a pencil revealed on hover/focus of a user msg. */
.assistant-msg-edit {
    position: absolute;
    top: 50%;
    left: -26px;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    padding: 0;
    border: none;
    border-radius: 5px;
    background: none;
    color: var(--color-text-subtle);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.1s ease;
}

.assistant-msg-user:hover .assistant-msg-edit,
.assistant-msg-edit:focus-visible {
    opacity: 1;
}

.assistant-msg-edit:hover {
    color: var(--color-accent);
    background: rgba(26, 43, 60, 0.06);
}

.assistant-msg-editing {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 92%;
}

.assistant-msg-edit-input {
    width: 100%;
    resize: vertical;
    border: 1px solid var(--color-accent-muted);
    border-radius: 8px;
    padding: 6px 8px;
    font: inherit;
    background: var(--color-surface, #fff);
    color: var(--color-text);
}

.assistant-msg-edit-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

/* Inline stop control, sitting beside the thinking spinner so it only shows
   while the agent is actually running. */
.assistant-thinking-stop {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    padding: 0;
    border: 1px solid var(--color-accent-muted);
    border-radius: 50%;
    background: none;
    color: var(--color-text-subtle);
    cursor: pointer;
    transition: color 0.12s ease, border-color 0.12s ease;
}

.assistant-thinking-stop:hover {
    color: var(--color-text);
    border-color: var(--color-accent);
}

/* Assistant replies are the primary content: render full-width as plain prose
   (no chat bubble) so long Markdown / redlines use the whole column. */
.assistant-msg-assistant {
    align-self: stretch;
    max-width: 100%;
    padding: 0;
    background: none;
    border: none;
    white-space: normal;
}

/* Markdown rendered inside assistant replies */
.assistant-msg-assistant > :first-child { margin-top: 0; }
.assistant-msg-assistant > :last-child { margin-bottom: 0; }
.assistant-msg-assistant p { margin: 0 0 0.6em; }
.assistant-msg-assistant ul,
.assistant-msg-assistant ol { margin: 0 0 0.6em; padding-left: 1.4em; }
.assistant-msg-assistant li { margin: 0.15em 0; }
.assistant-msg-assistant li > p { margin: 0; }
.assistant-msg-assistant h3,
.assistant-msg-assistant h4,
.assistant-msg-assistant h5,
.assistant-msg-assistant h6 { margin: 0.5em 0 0.3em; font-size: 0.95rem; font-weight: 600; }
.assistant-msg-assistant strong { font-weight: 600; }
.assistant-msg-assistant code {
    font-family: var(--font-mono);
    font-size: 0.85em;
    background: var(--color-bg-hover);
    padding: 0.1em 0.3em;
    border-radius: 4px;
}
.assistant-msg-assistant a:not(.assistant-eid-link) {
    color: var(--color-accent);
    text-decoration: underline;
}

/* Errors stay a boxed alert even though normal replies are unboxed. */
.assistant-msg-error {
    align-self: stretch;
    max-width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--color-danger);
    border-radius: 8px;
    background: var(--color-danger-subtle);
    white-space: pre-wrap;
}

.assistant-retry-link {
    margin-top: 6px;
    padding: 2px 0;
    border: none;
    background: none;
    color: var(--color-danger);
    font: inherit;
    font-weight: 600;
    text-decoration: underline;
    cursor: pointer;
}

.assistant-retry-link:disabled {
    color: var(--color-text-muted, #888);
    cursor: default;
    text-decoration: none;
}

.assistant-tool-note {
    align-self: flex-start;
    font-size: 0.78rem;
    color: var(--color-text-muted);
    font-style: italic;
    padding: 0 4px;
}

.assistant-thinking {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 4px;
}

.assistant-thinking-dots {
    display: flex;
    gap: 4px;
}

/* The model's streamed reasoning: deliberately understated, folded once the
   answer arrives. */
.assistant-thought {
    align-self: flex-start;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 4px;
}

.assistant-thought-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.72rem;
    font-style: italic;
    color: var(--color-text-subtle);
}

.assistant-thought-toggle:hover {
    color: var(--color-text-muted);
}

/* When open there is no header — the reasoning itself is the collapse target. */
.assistant-thought.expanded .assistant-thought-toggle {
    display: none;
}

.assistant-thought-body[hidden] {
    display: none;
}

.assistant-thought-body {
    margin-left: 12px;
    padding: 2px 0;
    font-size: 0.72rem;
    line-height: 1.5;
    font-style: italic;
    color: var(--color-text-subtle);
    cursor: pointer;
}

/* Compact Markdown inside reasoning, kept understated. */
.assistant-thought-body > :first-child { margin-top: 0; }
.assistant-thought-body > :last-child { margin-bottom: 0; }
.assistant-thought-body p { margin: 0 0 0.5em; }
.assistant-thought-body ul,
.assistant-thought-body ol { margin: 0 0 0.5em; padding-left: 1.3em; }
.assistant-thought-body li { margin: 0.1em 0; }
.assistant-thought-body h1,
.assistant-thought-body h2,
.assistant-thought-body h3,
.assistant-thought-body h4 { font-size: 0.72rem; font-weight: 600; margin: 0.4em 0 0.2em; }
.assistant-thought-body pre,
.assistant-thought-body code { font-style: normal; }

.assistant-thinking-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-text-subtle);
    animation: assistant-pulse 1.2s infinite ease-in-out;
}

.assistant-thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.assistant-thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes assistant-pulse {
    0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

.assistant-proposal {
    align-self: stretch;
    border: 1px solid var(--color-accent-muted);
    border-radius: 10px;
    background: var(--color-surface);
    overflow: hidden;
}

.assistant-proposal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
    background: var(--color-accent-light);
    font-size: 0.85rem;
    font-weight: 500;
}

.assistant-proposal-verdict {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}

/* While pending there is no verdict text; drop the slot so it doesn't add a
   flex gap that pushes the expand button off the top-right corner. */
.assistant-proposal-verdict:empty { display: none; }

.assistant-proposal-applied .assistant-proposal-verdict { color: var(--color-success); }
.assistant-proposal-rejected .assistant-proposal-verdict { color: var(--color-danger); }
.assistant-proposal-revised .assistant-proposal-verdict { color: var(--color-text-muted); }
.assistant-proposal-rejected .assistant-proposal-diff,
.assistant-proposal-revised .assistant-proposal-diff { opacity: 0.55; }

.assistant-proposal-diff {
    max-height: 260px;
    overflow-y: auto;
    padding: 8px 10px;
}

.assistant-proposal-args {
    max-height: 200px;
    overflow-y: auto;
    margin: 0;
    padding: 10px 12px;
    font-size: 0.78rem;
    font-family: var(--font-mono, ui-monospace, monospace);
    color: var(--color-text-muted);
}

.assistant-proposal-actions {
    display: flex;
    gap: 8px;
    padding: 6px 10px;
    border-top: 1px solid var(--color-border-subtle);
}

/* The proposal whose feedback the main input is currently capturing. */
.assistant-proposal-revising {
    box-shadow: 0 0 0 2px var(--color-primary);
}

/* Footer summarising a decided proposal's outcome (replaces the actions row),
   and the standalone compact card reload rebuilds for past decisions. */
.assistant-proposal-outcome {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    padding: 6px 10px;
    border-top: 1px solid var(--color-border-subtle);
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.assistant-outcome-label { font-weight: 600; }
.assistant-outcome-applied .assistant-outcome-label { color: var(--color-success); }
.assistant-outcome-rejected .assistant-outcome-label { color: var(--color-danger); }
.assistant-outcome-failed .assistant-outcome-label { color: var(--color-danger); }
.assistant-outcome-revised .assistant-outcome-label { color: var(--color-text-muted); }

.assistant-version-link {
    color: var(--color-primary);
    text-decoration: underline;
    cursor: pointer;
}
.assistant-version-link:hover { text-decoration: none; }

/* Admin-only model picker, sits just below the composer. */
.assistant-model-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 12px 6px;
    font-size: 0.72rem;
    color: var(--color-text-subtle);
}
.assistant-model-row.hidden { display: none; }
.assistant-model-row label { flex-shrink: 0; }
.assistant-model-picker {
    flex: 1;
    min-width: 0;
    padding: 3px 6px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font: inherit;
    font-size: 0.72rem;
    background: var(--color-surface);
    color: var(--color-text);
}
.assistant-model-picker:disabled { background: var(--color-bg); color: var(--color-text-subtle); }

/* The textarea and send button are joined into one control: shared border,
   no gap, only the outer corners rounded, button matches the textarea height. */
.assistant-input-row {
    display: flex;
    align-items: stretch;
    gap: 0;
    padding: 8px 12px;
    border-top: 1px solid var(--color-border-subtle);
}

.assistant-input {
    flex: 1;
    resize: none;
    padding: 8px 10px;
    border: 1px solid var(--color-border);
    border-right: none;
    border-radius: 8px 0 0 8px;
    font: inherit;
    font-size: 0.9rem;
    background: var(--color-surface);
    color: var(--color-text);
}

.assistant-input:focus {
    outline: none;
    border-color: var(--color-accent);
}

/* Keep the seam coloured with the textarea when it is focused. */
.assistant-input-row:focus-within .assistant-send:not(:disabled) {
    background: var(--color-accent-hover);
}

.assistant-input:disabled { background: var(--color-bg); color: var(--color-text-subtle); }

.assistant-send {
    padding: 0 12px;
    flex-shrink: 0;
    border-radius: 0 8px 8px 0;
    align-self: stretch;
}

.assistant-footnote {
    padding: 4px 12px 8px;
    font-size: 0.72rem;
    color: var(--color-text-subtle);
}

/* Shown only while a proposal is pending (toggled in setAssistantAwaitingDecision). */
.assistant-footnote.hidden { display: none; }

#assistantBtn.active { color: var(--color-accent); }
#structureToggleBtn.active { color: var(--color-accent); }

.assistant-eid-link {
    color: var(--color-accent);
    text-decoration: none;
    border-bottom: 1px dotted var(--color-accent-muted);
    cursor: pointer;
}

.assistant-eid-link:hover {
    color: var(--color-accent-hover);
    border-bottom-style: solid;
}

.assistant-eid-chip {
    display: inline-block;
    max-width: 230px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
    margin: 0 2px 0 8px;
    padding: 0 8px;
    background: var(--color-accent-light);
    border: 1px solid var(--color-accent-muted);
    border-radius: 999px;
    border-bottom-style: solid;
    font-size: 0.75rem;
    line-height: 1.7;
    font-style: normal;
}

.assistant-eid-chip:hover {
    border-color: var(--color-accent);
}

/* Pending click-attached elements: a compact "context row" that reads as the
   top of the composer. The divider sits above it (and the input-row's own
   top border is dropped) so header → pills → input form one connected block. */
.assistant-attachments {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 6px;
    padding: 7px 12px 0;
    border-top: 1px solid var(--color-border-subtle);
}

.assistant-attachments.hidden {
    display: none;
}

.assistant-attachments:not(.hidden) + .assistant-input-row {
    border-top: none;
    padding-top: 5px;
}

.assistant-attachments-label {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--color-text-subtle);
    margin-right: 1px;
    user-select: none;
}

.assistant-attachment-pill {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    gap: 2px;
    padding: 1px 3px 1px 8px;
    background: var(--color-accent-light);
    border: 1px solid var(--color-accent-muted);
    border-radius: 999px;
    font-size: 0.7rem;
    line-height: 1.5;
    cursor: pointer;
}

.assistant-attachment-pill:hover {
    border-color: var(--color-accent);
}

.assistant-attachment-label {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-accent);
}

.assistant-attachment-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    padding: 0;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: var(--color-text-muted);
    font-size: 0.85rem;
    line-height: 1;
    cursor: pointer;
}

.assistant-attachment-remove:hover {
    background: var(--color-accent-muted);
    color: var(--color-text);
}

/* Attached-element chips shown on a sent user message. */
.assistant-msg-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
}

/* Custom hover tooltip for element chips/pills: the ancestry breadcrumb,
   replacing the plain native title (which only showed the raw eId). */
.assistant-eid-tooltip {
    position: fixed;
    z-index: 2000;
    display: none;
    max-width: 340px;
    padding: 6px 9px;
    background: var(--color-text, #1f2937);
    color: var(--color-surface, #fff);
    border-radius: 6px;
    font-size: 0.72rem;
    line-height: 1.4;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    pointer-events: none;
}

.assistant-eid-tooltip-sep {
    opacity: 0.5;
    margin: 0 5px;
}

.assistant-tool-note {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    max-width: 100%;
}

.assistant-tool-note-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    max-width: 100%;
}

.assistant-tool-note-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: none;
    color: var(--color-text-subtle);
    cursor: pointer;
}

.assistant-tool-note-toggle:hover {
    background: rgba(26, 43, 60, 0.08);
    color: var(--color-text);
}

.assistant-tool-note-toggle svg {
    transition: transform 0.12s ease;
}

.assistant-tool-note.expanded .assistant-tool-note-toggle svg {
    transform: rotate(90deg);
}

.assistant-tool-note-clickable {
    cursor: pointer;
}

.assistant-tool-note-details[hidden] {
    display: none;
}

.assistant-tool-note-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
    /* Align under the summary text, past the disclosure caret. */
    margin-left: 20px;
    padding: 2px 0;
    font-style: normal;
    font-size: 0.75rem;
}

.assistant-tool-note-detail {
    color: var(--color-text-muted);
    word-break: break-word;
    overflow-wrap: anywhere;
}

.assistant-tool-note-detail a {
    color: var(--color-accent);
}

.assistant-proposal-title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    min-width: 0;
    /* Absorb the free space so the expand button hugs the right edge instead of
       drifting to the middle (header is justify-content: space-between). */
    flex: 1 1 auto;
}

.assistant-proposal-title .assistant-eid-chip { max-width: 190px; }

/* Shared "expand into a modal" button. One standard everywhere a compact panel
   pops out into a larger modal (assistant proposal preview, tasks panel, …).
   Always visible (muted at rest, darker on hover/focus). See docs/ui-conventions.md. */
.expand-modal-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: none;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.expand-modal-btn:hover {
    background: rgba(26, 43, 60, 0.08);
    color: var(--color-text);
}

.expand-modal-btn:focus-visible {
    outline: none;
    color: var(--color-text);
    box-shadow: 0 0 0 2px var(--color-accent-light);
}

/* ============================================================
   Version history scroll controls
   ============================================================ */

.version-scroll-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 20px;
    flex-shrink: 0;
    padding: 0;
    border: none;
    border-top: 1px solid var(--color-border-subtle);
    border-bottom: 1px solid var(--color-border-subtle);
    background: var(--color-bg-secondary, #f8fafc);
    color: var(--color-text-subtle);
    cursor: pointer;
}

.version-scroll-btn:hover {
    background: var(--color-bg-hover);
    color: var(--color-accent);
}

.version-scroll-btn.hidden { display: none; }

#version-list-content:focus-visible {
    outline: 2px solid var(--color-accent-muted);
    outline-offset: -2px;
}

/* Reverted-version links (version rows + detail modal) */
.version-item-undoes {
    margin-top: 2px;
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.version-undoes-link {
    color: var(--color-accent);
    text-decoration: none;
    border-bottom: 1px dotted var(--color-accent-muted);
}

.version-undoes-link:hover {
    color: var(--color-accent-hover);
    border-bottom-style: solid;
}
