/* =============================================
   IRIS — Incident Research & Investigation System
   Dark theme, data-dense, monospace data display
   ============================================= */

/* Hide app until auth completes to prevent flash of content */
body.auth-pending #sidebar,
body.auth-pending #main-content,
body.auth-pending #detail-panel,
body.auth-pending #panel-overlay { visibility: hidden; }

:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #1c2128;
    --bg-elevated: #21262d;
    --border: #30363d;
    --border-light: #21262d;

    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #484f58;
    --text-link: #58a6ff;

    /* Source badges */
    --color-itsm: #f0a020;
    --color-slack: #36c5f0;
    --color-experiment: #3fb950;
    --color-commit: #a371f7;
    --color-drive: #f778a0;
    --color-jira: #2684ff;
    --color-pagerduty: #06ac38;

    /* Conclusion badges */
    --color-include: #3fb950;
    --color-exclude: #f85149;
    --color-question: #d29922;
    --color-neutral: #8b949e;

    /* Relevance */
    --color-direct: #3fb950;
    --color-supporting: #58a6ff;
    --color-contextual: #8b949e;

    /* Claim sections */
    --color-h: #f0a020;
    --color-u: #a371f7;
    --color-e: #3fb950;
    --color-w: #58a6ff;
    --color-c: #f778a0;
    --color-r: #36c5f0;

    --font-ui: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;

    --sidebar-width: 240px;
    --detail-width: 480px;
    --header-height: 0px;

    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;

    --transition: 150ms ease;
}

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

html, body {
    height: 100%;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 13px;
    line-height: 1.5;
    overflow: hidden;
}

/* ---- Layout ---- */
body {
    display: flex;
}

#sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 20;
}

#main-content {
    flex: 1;
    height: 100vh;
    overflow-y: auto;
    padding: 20px 24px;
}

#detail-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--detail-width);
    height: 100vh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    z-index: 30;
    transform: translateX(100%);
    transition: transform 250ms ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#detail-panel.open {
    transform: translateX(0);
}

#panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 25;
    opacity: 0;
    pointer-events: none;
    transition: opacity 250ms ease;
}

#panel-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

/* Hidden utility */
.hidden { display: none !important; }

/* ---- Sidebar ---- */
.sidebar-header {
    padding: 20px 16px 16px;
    border-bottom: 1px solid var(--border);
}

.logo {
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--text-primary);
}

.logo-accent {
    color: var(--color-experiment);
}

.logo-sub {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.nav-links {
    flex: 1;
    padding: 8px 0;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all var(--transition);
    border-left: 2px solid transparent;
}

.nav-link:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.nav-link.active {
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border-left-color: var(--color-experiment);
}

.nav-link svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.nav-link.active svg {
    opacity: 1;
}

.nav-divider {
    height: 1px;
    background: var(--border);
    margin: 8px 16px;
}

.nav-section-label {
    padding: 6px 16px 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
}

.source-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dot-itsm { background: var(--color-itsm); }
.dot-slack { background: var(--color-slack); }
.dot-experiment { background: var(--color-experiment); }
.dot-commit { background: var(--color-commit); }
.dot-jira { background: var(--color-jira); }
.dot-drive { background: var(--color-drive); }
.dot-pagerduty { background: var(--color-pagerduty); }
.dot-neutral { background: var(--color-neutral); }

.sidebar-stats {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.8;
}

.sidebar-stats .stat-value {
    color: var(--text-primary);
    font-weight: 600;
}

/* ---- View Container ---- */
#view-container {
    max-width: 1400px;
}

.view-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 16px;
}

.view-title {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.view-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* ---- Filter Bar ---- */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 16px;
    align-items: center;
}

.filter-bar input,
.filter-bar select {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 12px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color var(--transition);
}

.filter-bar input:focus,
.filter-bar select:focus {
    border-color: var(--color-experiment);
}

.filter-bar input[type="text"],
.filter-bar input[type="search"] {
    min-width: 200px;
    flex: 1;
}

.filter-bar select {
    min-width: 120px;
}

.filter-bar input[type="date"] {
    width: 140px;
}

.filter-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.filter-btn {
    padding: 6px 14px;
    background: var(--color-experiment);
    color: #000;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity var(--transition);
}

.filter-btn:hover { opacity: 0.85; }

.quarter-btn {
    padding: 4px 10px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}
.quarter-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--text-secondary);
}
.quarter-btn.active {
    background: var(--color-experiment);
    color: #000;
    border-color: var(--color-experiment);
}

.filter-btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

/* ---- Badges ---- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 10px;
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.badge-itsm { background: rgba(240,160,32,0.15); color: var(--color-itsm); }
.badge-slack { background: rgba(54,197,240,0.15); color: var(--color-slack); }
.badge-experiment { background: rgba(63,185,80,0.15); color: var(--color-experiment); }
.badge-commit { background: rgba(163,113,247,0.15); color: var(--color-commit); }
.badge-drive { background: rgba(247,120,160,0.15); color: var(--color-drive); }
.badge-jira { background: rgba(38,132,255,0.15); color: var(--color-jira); }
.badge-pagerduty { background: rgba(6,172,56,0.15); color: var(--color-pagerduty); }

.badge-direct { background: rgba(63,185,80,0.15); color: var(--color-direct); }
.badge-supporting { background: rgba(88,166,255,0.15); color: var(--color-supporting); }
.badge-contextual { background: rgba(139,148,158,0.15); color: var(--color-contextual); }

.badge-include { background: rgba(63,185,80,0.15); color: var(--color-include); }
.badge-exclude { background: rgba(248,81,73,0.15); color: var(--color-exclude); }
.badge-question { background: rgba(210,153,34,0.15); color: var(--color-question); }
.badge-neutral { background: rgba(139,148,158,0.15); color: var(--color-neutral); }

.badge-verified { background: rgba(63,185,80,0.15); color: var(--color-include); }
.badge-unverified { background: rgba(248,81,73,0.15); color: var(--color-exclude); }

/* Claim section badges */
.badge-H { background: rgba(240,160,32,0.15); color: var(--color-h); }
.badge-U { background: rgba(163,113,247,0.15); color: var(--color-u); }
.badge-E { background: rgba(63,185,80,0.15); color: var(--color-e); }
.badge-I { background: rgba(210,153,34,0.15); color: #d29922; }
.badge-W { background: rgba(88,166,255,0.15); color: var(--color-w); }
.badge-C { background: rgba(247,120,160,0.15); color: var(--color-c); }
.badge-R { background: rgba(54,197,240,0.15); color: var(--color-r); }
.badge-K { background: rgba(139,148,158,0.15); color: #8b949e; }

/* ---- Cards ---- */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 12px;
    align-items: start;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.card-title {
    font-size: 14px;
    font-weight: 600;
}

.card-meta {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.card-body {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
}

.card:hover {
    border-color: var(--text-muted);
    cursor: pointer;
}

/* ---- Stat Cards ---- */
.stats-row {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    min-width: 130px;
}

.stat-card .stat-number {
    font-family: var(--font-mono);
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-card .stat-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ---- Detail Panel ---- */
.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-tertiary);
}

.detail-header h2 {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.4;
    flex: 1;
    padding-right: 12px;
}

.icon-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    transition: all var(--transition);
    flex-shrink: 0;
}

.icon-btn:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
}

#detail-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.detail-section {
    margin-bottom: 20px;
}

.detail-section-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border-light);
}

.detail-meta-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 12px;
    font-size: 12px;
}

.detail-meta-grid dt {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 11px;
}

.detail-meta-grid dd {
    color: var(--text-primary);
}

.detail-description {
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.7;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 300px;
    overflow-y: auto;
    padding: 10px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
}

.detail-summary-text {
    font-size: 12px;
    line-height: 1.7;
    color: var(--text-secondary);
    padding: 10px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--color-experiment);
}

/* ---- Annotations ---- */
.annotation-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.annotation-form textarea {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 12px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    resize: vertical;
    min-height: 60px;
    outline: none;
}

.annotation-form textarea:focus {
    border-color: var(--color-experiment);
}

.annotation-form .form-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.annotation-form select {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 12px;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    outline: none;
}

.annotation-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.annotation-item {
    padding: 8px 10px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
    font-size: 12px;
}

.annotation-item .ann-meta {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    font-size: 10px;
    color: var(--text-muted);
}

.annotation-item .ann-note {
    color: var(--text-secondary);
    line-height: 1.5;
}

.annotation-item .ann-delete {
    color: var(--color-exclude);
    cursor: pointer;
    font-size: 10px;
    opacity: 0;
    transition: opacity var(--transition);
}

.annotation-item:hover .ann-delete {
    opacity: 1;
}

/* ---- Related artifacts ---- */
.related-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.related-item {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 6px 8px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 11px;
    transition: background var(--transition);
}

.related-item:hover {
    background: var(--bg-elevated);
}

.related-item .related-date {
    font-family: var(--font-mono);
    color: var(--text-muted);
    white-space: nowrap;
    font-size: 10px;
}

.related-item .related-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- Claims View ---- */
.claim-section {
    margin-bottom: 24px;
}

.claim-section-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.claim-section-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.claim-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    margin-bottom: 8px;
}

.claim-card .claim-id {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 13px;
}

.claim-card .claim-text {
    font-size: 12px;
    color: var(--text-secondary);
    margin: 6px 0;
    line-height: 1.6;
}

.claim-evidence {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
}

.evd-marker {
    display: inline-flex;
    align-items: center;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 10px;
    cursor: pointer;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    transition: all var(--transition);
}

.evd-marker:hover {
    border-color: var(--color-experiment);
    color: var(--text-primary);
}

.evd-marker.verified {
    background: rgba(63,185,80,0.1);
    border-color: rgba(63,185,80,0.3);
    color: var(--color-include);
}

/* ---- Charts ---- */
.chart-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 16px;
}

.chart-container canvas {
    width: 100% !important;
}

/* ---- Collections ---- */
.collection-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.collection-item {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    font-size: 12px;
}

.collection-item .ci-num {
    font-family: var(--font-mono);
    color: var(--text-muted);
    font-size: 11px;
    min-width: 24px;
}

.collection-item .ci-remove {
    color: var(--text-muted);
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--transition);
    flex-shrink: 0;
}

.collection-item:hover .ci-remove {
    opacity: 1;
    color: var(--color-exclude);
}

/* ---- Tabulator overrides ---- */
.tabulator {
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-lg) !important;
    font-family: var(--font-mono) !important;
    font-size: 11px !important;
}

.tabulator .tabulator-header {
    background: var(--bg-tertiary) !important;
    border-bottom: 1px solid var(--border) !important;
}

.tabulator .tabulator-header .tabulator-col {
    background: transparent !important;
    border-right: 1px solid var(--border-light) !important;
}

.tabulator .tabulator-header .tabulator-col-content {
    padding: 8px 10px !important;
}

.tabulator .tabulator-header .tabulator-col .tabulator-col-title {
    font-family: var(--font-ui) !important;
    font-size: 10px !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    color: var(--text-muted) !important;
}

.tabulator .tabulator-tableholder .tabulator-table .tabulator-row {
    border-bottom: 1px solid var(--border-light) !important;
    background: transparent !important;
}

.tabulator .tabulator-tableholder .tabulator-table .tabulator-row:hover {
    background: var(--bg-tertiary) !important;
    cursor: pointer;
}

.tabulator .tabulator-tableholder .tabulator-table .tabulator-row .tabulator-cell {
    padding: 6px 10px !important;
    border-right: none !important;
    color: var(--text-primary) !important;
}

.tabulator .tabulator-footer {
    background: var(--bg-tertiary) !important;
    border-top: 1px solid var(--border) !important;
    padding: 6px 10px !important;
}

.tabulator .tabulator-footer .tabulator-page {
    background: var(--bg-elevated) !important;
    color: var(--text-secondary) !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-sm) !important;
    font-size: 11px !important;
    padding: 3px 8px !important;
    margin: 0 2px !important;
}

.tabulator .tabulator-footer .tabulator-page.active {
    background: var(--color-experiment) !important;
    color: #000 !important;
    border-color: var(--color-experiment) !important;
}

/* Column resize handle — visible feedback on hover */
.tabulator .tabulator-header .tabulator-col .tabulator-col-resize-handle {
    width: 6px !important;
    right: -3px !important;
    cursor: col-resize !important;
    position: absolute;
    top: 0;
    bottom: 0;
    z-index: 10;
}

.tabulator .tabulator-header .tabulator-col .tabulator-col-resize-handle:hover {
    background: var(--text-link) !important;
    opacity: 0.6;
    border-radius: 2px;
}

.tabulator .tabulator-header .tabulator-col .tabulator-col-resize-handle:active {
    background: var(--text-link) !important;
    opacity: 1;
}

/* ---- Form elements: ensure light text on dark background ---- */
select, input, textarea {
    color: var(--text-primary) !important;
}

/* ---- Toast ---- */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 10px 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 12px;
    color: var(--text-primary);
    animation: toast-in 250ms ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.toast.toast-success { border-left: 3px solid var(--color-include); }
.toast.toast-error { border-left: 3px solid var(--color-exclude); }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--transition);
}

.btn-primary {
    background: var(--color-experiment);
    color: #000;
}

.btn-primary:hover { opacity: 0.85; }

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-color: var(--border);
}

.btn-secondary:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 11px;
}

/* ---- Modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    min-width: 400px;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal h3 {
    margin-bottom: 16px;
    font-size: 16px;
}

.modal .form-group {
    margin-bottom: 12px;
}

.modal .form-group label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.modal .form-group input,
.modal .form-group select,
.modal .form-group textarea {
    width: 100%;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    outline: none;
}

.modal .form-group input:focus,
.modal .form-group select:focus,
.modal .form-group textarea:focus {
    border-color: var(--color-experiment);
}

.modal .form-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}

/* ---- Narrative Editor ---- */
.narratives-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.narrative-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.narrative-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    background: var(--bg-tertiary);
    transition: background var(--transition);
}

.narrative-header:hover {
    background: var(--bg-elevated);
}

.narrative-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.narrative-chevron {
    flex-shrink: 0;
    transition: transform 200ms ease;
}

.narrative-chevron.rotated {
    transform: rotate(-90deg);
}

.narrative-qid {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 13px;
    color: var(--color-experiment);
    flex-shrink: 0;
}

.narrative-title {
    font-size: 12px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.narrative-wc {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
    margin-left: 8px;
}

.narrative-body {
    padding: 16px;
    transition: max-height 300ms ease;
}

.narrative-body.collapsed {
    display: none;
}

.narrative-editor {
    width: 100%;
    min-height: 150px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.7;
    padding: 12px;
    border-radius: var(--radius-sm);
    resize: none;
    overflow: hidden;
    outline: none;
}

.narrative-editor:focus {
    border-color: var(--color-experiment);
}

.narrative-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
}

.narrative-wc-live {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
}

.narrative-wc-over { color: var(--color-exclude) !important; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ---- Empty state ---- */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}

.empty-state .empty-icon {
    font-size: 32px;
    margin-bottom: 12px;
    opacity: 0.3;
}

.empty-state p {
    font-size: 13px;
    line-height: 1.6;
}

/* ---- Loading ---- */
.loading-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px;
    color: var(--text-muted);
}

.loading-spinner::after {
    content: '';
    width: 24px;
    height: 24px;
    border: 2px solid var(--border);
    border-top-color: var(--color-experiment);
    border-radius: 50%;
    animation: spin 600ms linear infinite;
}

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

/* ---- Keyboard shortcut hints ---- */
.kbd {
    display: inline-block;
    padding: 1px 5px;
    font-family: var(--font-mono);
    font-size: 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text-muted);
}

/* ---- Add-to-collection dropdown ---- */
.add-to-collection {
    position: relative;
}

.collection-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 10;
    min-width: 200px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-top: 4px;
    padding: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.collection-dropdown .coll-option {
    padding: 6px 10px;
    font-size: 12px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}

.collection-dropdown .coll-option:hover {
    background: var(--bg-tertiary);
}
