:root {
    color-scheme: dark;

    /* === Design System Tokens === */

    /* Backgrounds */
    --bg-base: #0f1117;
    --bg-surface: #1a1d27;
    --bg-panel: #1e2235;
    --bg-raised: #252840;

    /* Borders */
    --border-subtle: #2a2d3e;
    --border-default: #363a52;
    --border-active: #4a4f72;

    /* Brand / accent */
    --accent-primary: #5b6bff;
    --accent-primary-muted: rgba(91, 107, 255, 0.15);
    --accent-success: #2ecc71;
    --accent-success-muted: rgba(46, 204, 113, 0.15);
    --accent-warning: #f39c12;
    --accent-warning-muted: rgba(243, 156, 18, 0.15);
    --accent-danger: #e74c3c;
    --accent-danger-muted: rgba(231, 76, 60, 0.15);

    /* Entity type colours */
    --entity-person: #5b6bff;
    --entity-organisation: #2ecc71;
    --entity-place: #e67e22;
    --entity-event: #e74c3c;
    --entity-concept: #9b59b6;
    --entity-policy: #1abc9c;
    --entity-country: #e67e22;
    --entity-region: #d35400;
    --entity-commodity: #f1c40f;

    /* Text */
    --text-primary: #e8eaf0;
    --text-secondary: #8b90a8;
    --text-muted: #555870;
    --text-inverse: #0f1117;

    /* Confidence */
    --confidence-high: #2ecc71;
    --confidence-medium: #f39c12;
    --confidence-low: #e74c3c;

    /* Shadows */
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    --shadow-soft: 0 4px 12px rgba(0, 0, 0, 0.2);

    /* Radii */
    --radius-xl: 12px;
    --radius-lg: 8px;
    --radius-md: 6px;
    --radius-sm: 4px;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Layout */
    --content-max-width: 1280px;
    --assistant-max-width: 1120px;
    --user-max-width: min(820px, 72%);

    /* === Legacy Aliases (map old names to new tokens) === */
    --bg: var(--bg-base);
    --bg-strong: #0b1120;
    --sidebar-bg: var(--bg-surface);
    --surface: var(--bg-surface);
    --surface-strong: var(--bg-panel);
    --surface-subtle: var(--bg-panel);
    --surface-muted: var(--bg-raised);
    --surface-highlight: var(--bg-raised);
    --border: var(--border-subtle);
    --border-strong: var(--border-default);
    --ink: var(--text-primary);
    --ink-soft: var(--text-secondary);
    --muted: var(--text-muted);
    --accent: var(--accent-primary);
    --accent-strong: var(--accent-primary);
    --accent-soft: var(--accent-primary-muted);
    --success: var(--accent-success);
    --warning: var(--accent-warning);
    --danger: var(--accent-danger);
}

/* === Reset & Base === */

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
    min-height: 100%;
    background: var(--bg-base);
    color: var(--text-primary);
    font-family: "SF Pro Text", "SF Pro Display", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
    line-height: 1.5;
    overflow: hidden;
}

a {
    color: inherit;
}

#app {
    height: 100vh;
    min-height: 100vh;
}

/* === Layout & Shell === */

.workspace-shell {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: 332px minmax(0, 1fr);
    height: 100vh;
    min-height: 100vh;
    overflow: hidden;
    background: var(--bg);
}

.workspace-shell.mode-rail-shell {
    grid-template-columns: 78px minmax(0, 1fr);
}

.app-sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-height: 100vh;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
}

.app-sidebar.rail-only-sidebar {
    align-items: center;
    padding-top: 8px;
}

.mode-rail {
    display: flex;
    gap: 10px;
    padding: 18px 18px 0;
}

.rail-only-sidebar .mode-rail {
    flex-direction: column;
    padding: 10px 8px;
}

.mode-icon {
    position: relative;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.5);
    color: var(--muted);
    font: inherit;
    font-weight: 700;
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: border-color 140ms ease, background 140ms ease, color 140ms ease;
}

.mode-icon:hover {
    color: var(--ink);
    border-color: var(--border-strong);
}

.mode-icon.active {
    color: var(--accent);
    border-color: var(--accent-soft);
    background: var(--accent-soft);
}

.mode-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 16px;
    padding: 1px 4px;
    border-radius: 999px;
    background: var(--accent-strong);
    color: #04101e;
    font-size: 0.65rem;
    font-weight: 700;
}

.workspace-main.chat-workspace {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100vh;
    min-width: 0;
    min-height: 0;
    background: transparent;
}

.chat-hero-bar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 32px 10px;
    width: calc(100% - 40px);
    margin-left: auto;
    margin-right: auto;
}

.chat-hero-copy h2 {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 640;
    letter-spacing: -0.02em;
}

.chat-hero-copy p {
    margin: 2px 0 0;
    font-size: 0.82rem;
    color: var(--muted);
    line-height: 1.4;
}

.chat-hero-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    flex-shrink: 0;
}


.workspace-main.graph-workspace {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    height: 100vh;
    min-width: 0;
    min-height: 0;
    background: transparent;
}

.workspace-main.ops-workspace {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    height: 100vh;
    min-width: 0;
    min-height: 0;
    background: transparent;
}

.sidebar-header.minimal,
.project-header.minimal {
    padding: var(--space-lg) var(--space-lg) var(--space-md);
}

.eyebrow {
    margin: 0;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--muted);
}

.brand.minimal,
.project-title.minimal {
    margin: 8px 0 0;
    font-size: clamp(1.28rem, 1.1rem + 0.6vw, 1.7rem);
    font-weight: 640;
    letter-spacing: -0.03em;
}

.brand.minimal {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand.minimal::before {
    content: "";
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--accent), #34d399);
    box-shadow: 0 0 0 6px rgba(96, 165, 250, 0.12);
}

.subtle-copy {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 0.95rem;
    max-width: 70ch;
}

.sidebar-actions.minimal,
.project-toolbar.minimal,
.composer-actions,
.form-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.sidebar-actions.minimal {
    padding: 0 24px 16px;
}

.project-toolbar.minimal {
    padding: 0 32px 22px;
}

.workspace-toolbar-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
    width: min(var(--content-max-width), 100%);
    margin: 0 auto;
}

.workspace-status-stack {
    display: grid;
    gap: 10px;
}

.workspace-status-row,
.workspace-metrics {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.workspace-status-row {
    justify-content: flex-end;
}

.workspace-action-btn,
.ops-action-btn,
.graph-action-btn,
.queue-action-btn {
    min-height: 32px;
    font-size: 0.8rem;
    line-height: 1.2;
}

.workspace-metric,
.section-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    padding: 5px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(30, 41, 59, 0.45);
    color: var(--ink-soft);
    font-size: 0.76rem;
    font-weight: 700;
}

.section-count {
    min-width: 24px;
    padding: 4px 9px;
    color: var(--muted);
    background: rgba(15, 23, 42, 0.55);
}

.status-hint {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.72);
    color: var(--ink-soft);
    font-size: 0.78rem;
    font-weight: 700;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02);
}

.status-hint.success {
    color: var(--success);
    background: rgba(22, 101, 52, 0.14);
    border-color: rgba(74, 222, 128, 0.18);
}

.status-hint.warning {
    color: var(--warning);
    background: rgba(146, 64, 14, 0.16);
    border-color: rgba(245, 158, 11, 0.18);
}

.status-hint.danger {
    color: var(--danger);
    background: rgba(127, 29, 29, 0.18);
    border-color: rgba(248, 113, 113, 0.18);
}

.status-hint.neutral {
    color: var(--muted);
}

.pressure-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.58);
    color: var(--ink-soft);
    font-size: 0.76rem;
    font-weight: 700;
}

.pressure-chip.success {
    color: var(--success);
    border-color: rgba(74, 222, 128, 0.16);
    background: rgba(10, 36, 24, 0.46);
}

.pressure-chip.warning {
    color: var(--warning);
    border-color: rgba(245, 158, 11, 0.16);
    background: rgba(54, 31, 8, 0.46);
}

.pressure-chip.danger {
    color: var(--danger);
    border-color: rgba(248, 113, 113, 0.16);
    background: rgba(59, 16, 16, 0.48);
}

.sidebar-scroll {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 0 14px 24px;
}

.sidebar-scroll,
.message-scroller,
.document-modal-body,
.document-text-block {
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.28) transparent;
}

.sidebar-scroll::-webkit-scrollbar,
.message-scroller::-webkit-scrollbar,
.document-modal-body::-webkit-scrollbar,
.document-text-block::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.sidebar-scroll::-webkit-scrollbar-thumb,
.message-scroller::-webkit-scrollbar-thumb,
.document-modal-body::-webkit-scrollbar-thumb,
.document-text-block::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.22);
    border-radius: 999px;
}

.sidebar-header.compact {
    padding: 12px 24px 4px;
}

.brand-compact {
    font-size: 0.88rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--muted);
}

.project-selector {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 24px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 120ms ease;
}

.project-selector:hover {
    background: rgba(30, 41, 59, 0.3);
}

.project-selector-label {
    font-size: 0.92rem;
    font-weight: 620;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.project-selector-chevron {
    font-size: 0.7rem;
    color: var(--muted);
    flex-shrink: 0;
}

.project-selector-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 24px 8px;
    border-bottom: 1px solid var(--border);
}

.project-selector-row .project-selector {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    border-bottom: none;
    border-radius: 8px;
}

.project-picker-dropdown {
    position: relative;
    z-index: 50;
    max-height: 260px;
    overflow-y: auto;
    margin: 0 14px;
    background: rgba(7, 11, 18, 0.96);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

.project-picker-item {
    padding: 9px 14px;
    cursor: pointer;
    font-size: 0.88rem;
    color: var(--ink-soft);
    transition: background 80ms ease;
}

.project-picker-item:hover {
    background: rgba(30, 41, 59, 0.4);
}

.project-picker-item.active {
    color: var(--accent);
    font-weight: 600;
}

.icon-btn {
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    font-size: 0.95rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 80ms ease, color 80ms ease;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--ink);
}

.section-chevron {
    font-size: 0.6rem;
    color: var(--muted);
    transition: transform 150ms ease;
}

.section-chevron.collapsed {
    transform: rotate(-90deg);
}

.show-all-link {
    display: block;
    padding: 6px 16px;
    font-size: 0.74rem;
    color: var(--accent);
    cursor: pointer;
    text-align: center;
    border: none;
    background: none;
    width: 100%;
}

.show-all-link:hover {
    text-decoration: underline;
}

.overflow-trigger {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    font-size: 1.1rem;
    font-weight: 900;
    letter-spacing: 1px;
    cursor: pointer;
}

.overflow-trigger:hover {
    border-color: var(--border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--ink);
}

.overflow-menu-wrap {
    position: relative;
}

.overflow-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    min-width: 170px;
    z-index: 60;
    padding: 6px 0;
    background: rgba(12, 16, 26, 0.96);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.overflow-menu-item {
    display: block;
    width: 100%;
    padding: 8px 14px;
    text-align: left;
    font-size: 0.82rem;
    border: none;
    background: none;
    color: var(--ink-soft);
    cursor: pointer;
}

.overflow-menu-item:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--ink);
}

.overflow-backdrop {
    position: fixed;
    inset: 0;
    z-index: 55;
}

.sidebar-section {
    padding: 0 8px 18px;
}

.sidebar-section.nested {
    padding-top: 8px;
}

.sidebar-section-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 0 8px 10px;
}

.sidebar-section-label-row.compact {
    padding: 0;
}

.sidebar-section-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--muted);
}

.sidebar-section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 0 8px 10px;
}

.sidebar-section-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.catalog-control input,
.catalog-control select {
    width: 100%;
    padding: 11px 13px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: rgba(7, 11, 18, 0.78);
    color: var(--ink);
    font: inherit;
}

.catalog-control input:focus,
.catalog-control select:focus {
    outline: none;
    border-color: rgba(125, 211, 252, 0.35);
    box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.08);
}

.graph-page-scroller {
    padding-top: 6px;
}

.graph-page {
    width: calc(100% - 24px);
    max-width: none;
    margin: 0 12px 28px;
    display: grid;
    gap: 18px;
}

.graph-page-layout {
    display: grid;
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.graph-query-sidebar,
.graph-page-content {
    min-width: 0;
}

.graph-hero-bar {
    display: grid;
    gap: 10px;
    padding: 16px 24px 8px;
}

.graph-hero-copy {
    display: grid;
    gap: 6px;
}

.graph-hero-copy h2 {
    margin: 0;
    font-size: clamp(1.16rem, 1.02rem + 0.46vw, 1.55rem);
    font-weight: 640;
    letter-spacing: -0.03em;
}

.graph-hero-copy p {
    margin: 0;
    color: var(--ink-soft);
    max-width: 92ch;
}

.graph-hero-meta {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    flex-wrap: wrap;
}

.ops-page-scroller {
    padding-top: 6px;
}

.ops-page {
    width: calc(100% - 24px);
    max-width: none;
    margin: 0 12px 28px;
    display: grid;
    gap: 18px;
}

.ops-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    align-items: start;
}

.ops-card {
    display: grid;
    gap: 14px;
    padding: 18px;
    border-radius: 24px;
    border: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(18, 24, 38, 0.9), rgba(12, 18, 30, 0.95));
    box-shadow: var(--shadow-soft);
}

.ops-card h3,
.ops-card p {
    margin: 0;
}

.ops-card p {
    color: var(--ink-soft);
}

.ops-stat-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.ops-inline-actions,
.ops-inline-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.ops-action-btn {
    justify-content: center;
}

.ops-systems-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

.ops-system-card {
    display: grid;
    gap: 8px;
    padding: 14px;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: rgba(10, 15, 25, 0.62);
}

.ops-table-wrap {
    overflow: auto;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: rgba(7, 11, 19, 0.68);
}

.ops-table {
    width: 100%;
    min-width: 720px;
    border-collapse: collapse;
}

.ops-table th,
.ops-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

.ops-table th {
    font-size: 0.76rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    background: rgba(13, 19, 31, 0.9);
}

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

.compact-table {
    min-width: 0;
}

.compact-table th {
    width: 220px;
}

.ops-cell-copy {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.ops-cell-copy strong,
.ops-table td,
.ops-table th {
    overflow-wrap: anywhere;
}

.graph-page-controls {
    margin-bottom: 0;
}

.graph-summary-panel {
    display: grid;
    gap: 14px;
    padding: 18px;
    border-radius: 24px;
    border: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(18, 24, 38, 0.88), rgba(12, 18, 30, 0.94));
    box-shadow: var(--shadow-soft);
}

.graph-summary-actions,
.graph-panel-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.graph-summary-actions {
    align-items: center;
}

.graph-panel-actions {
    justify-content: flex-end;
}

.graph-summary-copy p {
    margin: 8px 0 0;
    max-width: 80ch;
}

.dataset-upload-modal {
    width: min(640px, 100%);
}

.dataset-upload-modal .form-panel {
    margin: 0;
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
}

.metadata-modal .form-panel {
    margin: 0;
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
}

.members-section {
    margin-top: 8px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.members-invite-form {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 12px;
}

.members-invite-form input,
.members-invite-form select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(7, 11, 18, 0.78);
    color: var(--ink);
    font: inherit;
    font-size: 0.85rem;
}

.members-invite-form input {
    flex: 1;
    min-width: 0;
}

.members-invite-form input:focus,
.members-invite-form select:focus {
    outline: none;
    border-color: rgba(125, 211, 252, 0.35);
}

.members-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 0;
}

.members-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid rgba(30, 41, 59, 0.4);
}

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

.members-item-copy {
    flex: 1;
    min-width: 0;
    display: grid;
    gap: 2px;
}

.members-item-copy strong {
    font-size: 0.88rem;
    color: var(--ink);
}

.members-item-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.members-item-actions select {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.52);
    color: var(--ink-soft);
    font: inherit;
    font-size: 0.78rem;
}

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

.danger-text:hover {
    color: var(--danger);
    opacity: 0.8;
}

.graph-summary-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.graph-tool-panel,
.graph-tool-result,
.graph-tool-section {
    min-width: 0;
}

.graph-tool-panel {
    display: grid;
    gap: 12px;
    padding-top: 4px;
    border-top: 1px solid var(--border);
}

.graph-tool-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.graph-tool-temporal {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr));
    align-items: end;
    min-width: 0;
}

.graph-tool-temporal-help {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.graph-help-tip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    padding: 0;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.62);
    color: var(--muted);
    font-size: 0.74rem;
    font-weight: 700;
    line-height: 1;
    cursor: help;
}

.graph-tool-temporal-field {
    min-width: 0;
    overflow: hidden;
}

.graph-field-label {
    display: inline-flex;
    align-items: center;
    min-width: 0;
}

.graph-tool-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    padding: 0 2px;
    color: var(--ink-soft);
    font-size: 0.84rem;
}

.graph-tool-checkbox input {
    width: 15px;
    height: 15px;
}

.graph-tool-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: end;
}

.graph-tool-form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
}

.graph-tool-form .catalog-control {
    min-width: 0;
}

.graph-tool-form input {
    min-width: 0;
}

.graph-tool-temporal input {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    padding: 10px 11px;
    font-size: 0.8rem;
}

.graph-tool-entity-picker {
    margin-top: -2px;
}

.graph-tool-result {
    display: grid;
    gap: 12px;
    padding: 14px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: rgba(11, 17, 28, 0.72);
}

.graph-tool-result-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.graph-tool-section {
    display: grid;
    gap: 8px;
}

.graph-tool-two-column {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.graph-tool-list,
.graph-path-result-list {
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.graph-tool-list-item,
.graph-path-result {
    display: grid;
    gap: 4px;
    min-width: 0;
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.52);
}

.graph-tool-list-item strong,
.graph-path-result strong,
.graph-tool-list-item span,
.graph-path-result span {
    overflow-wrap: anywhere;
}

.graph-tool-metric-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.graph-warning-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.graph-workspace-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(340px, 430px);
    gap: 18px;
    align-items: start;
}

.graph-canvas-panel,
.graph-detail-card {
    min-width: 0;
    border-radius: 24px;
    border: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(17, 24, 39, 0.92), rgba(10, 15, 26, 0.96));
    box-shadow: var(--shadow-soft);
}

.graph-canvas-panel {
    padding: 18px;
    align-self: start;
}

.graph-filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
    align-items: center;
}

.graph-canvas-hint {
    margin-left: auto;
    padding-left: 8px;
    font-size: 0.76rem;
    line-height: 1.35;
    color: var(--muted);
}

.graph-control-status,
.graph-control-btn,
.graph-filter-chip {
    min-height: 32px;
    padding: 6px 11px;
    border-radius: 999px;
    font-size: 0.77rem;
    font-weight: 700;
    line-height: 1.2;
}

.graph-control-status,
.graph-filter-chip {
    border: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.62);
    color: var(--muted);
}

.graph-control-status {
    display: inline-flex;
    align-items: center;
}

.graph-control-btn {
    padding-inline: 11px;
}

.graph-control-btn-icon {
    min-width: 32px;
    padding-inline: 0;
}

.graph-filter-chip {
    font: inherit;
    cursor: pointer;
    transition: border-color 140ms ease, background 140ms ease, color 140ms ease, transform 140ms ease;
}

.graph-filter-chip:hover {
    transform: translateY(-1px);
    color: var(--ink);
}

.graph-filter-chip.active {
    border-color: rgba(125, 211, 252, 0.22);
    background: rgba(11, 29, 49, 0.56);
    color: var(--accent);
}

.graph-panel-header,
.graph-detail-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.graph-panel-header > *,
.graph-detail-header > * {
    min-width: 0;
}

.graph-panel-header h3,
.graph-detail-header h3 {
    margin: 8px 0 0;
    font-size: 1.05rem;
    font-weight: 620;
}

.graph-canvas {
    position: relative;
    height: clamp(620px, 72vh, 960px);
    min-height: 620px;
    margin-top: 14px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: rgba(5, 8, 16, 0.9);
    overflow: hidden;
    cursor: grab;
}

.graph-canvas.panning {
    cursor: grabbing;
}

.graph-canvas.dragging-node {
    cursor: default;
}

.graph-canvas.panning,
.graph-canvas.panning *,
.graph-canvas.dragging-node,
.graph-canvas.dragging-node * {
    user-select: none;
}

.graph-canvas::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(rgba(148, 163, 184, 0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(148, 163, 184, 0.04) 1px, transparent 1px);
    background-size: 36px 36px;
    opacity: 0.6;
}

.graph-stage {
    position: absolute;
    left: 0;
    top: 0;
    transform-origin: 0 0;
    will-change: transform;
}

.graph-links {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.graph-link {
    stroke: rgba(125, 211, 252, 0.18);
    stroke-width: 2.2;
}

.graph-link.active {
    stroke: rgba(74, 222, 128, 0.72);
    stroke-width: 3;
}

.graph-link.path {
    stroke: rgba(125, 211, 252, 0.78);
    stroke-width: 3.2;
    stroke-dasharray: 10 8;
}

.graph-link-asserted-relation {
    stroke: rgba(251, 191, 36, 0.56);
    stroke-width: 3.2;
}

.graph-link-published-by,
.graph-link-authored-by,
.graph-link-hosted-by {
    stroke: rgba(148, 163, 184, 0.38);
    stroke-width: 2.4;
    stroke-dasharray: 7 7;
}

.graph-link-query-entity {
    stroke: rgba(52, 211, 153, 0.4);
    stroke-width: 2.6;
    stroke-dasharray: 8 7;
}

.graph-edge-label {
    fill: rgba(226, 232, 240, 0.92);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.02em;
    pointer-events: none;
    paint-order: stroke fill;
    stroke: rgba(7, 11, 18, 0.92);
    stroke-width: 5px;
    stroke-linejoin: round;
}

.graph-edge-label.active {
    fill: rgba(134, 239, 172, 0.98);
}

.graph-edge-label.path {
    fill: rgba(186, 230, 253, 0.98);
}

.graph-node {
    position: absolute;
    transform: translate(-50%, -50%);
    display: grid;
    gap: 4px;
    padding: 12px 14px;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.92);
    color: var(--ink);
    text-align: left;
    cursor: pointer;
    z-index: 1;
    transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.graph-node:hover {
    transform: translate(-50%, -50%) translateY(-2px);
    border-color: rgba(125, 211, 252, 0.24);
}

.graph-node.active {
    border-color: rgba(74, 222, 128, 0.34);
    box-shadow: 0 0 0 1px rgba(74, 222, 128, 0.16), 0 12px 32px rgba(15, 118, 110, 0.22);
    background: rgba(16, 27, 46, 0.96);
}

.graph-node.path {
    border-color: rgba(125, 211, 252, 0.24);
    box-shadow: 0 0 0 1px rgba(125, 211, 252, 0.12), 0 10px 28px rgba(37, 99, 235, 0.16);
}

.graph-node.seed {
    box-shadow: inset 0 0 0 1px rgba(125, 211, 252, 0.08);
}

.graph-node.pinned {
    border-color: rgba(250, 204, 21, 0.42);
    box-shadow: 0 0 0 1px rgba(250, 204, 21, 0.18), 0 16px 34px rgba(2, 6, 23, 0.42);
}

.graph-node-cluster,
.graph-node-pin {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1.2;
}

.graph-node-cluster {
    color: var(--ink);
    background: color-mix(in srgb, var(--graph-cluster-color, #60a5fa) 22%, rgba(15, 23, 42, 0.95));
    border-color: color-mix(in srgb, var(--graph-cluster-color, #60a5fa) 58%, rgba(148, 163, 184, 0.18));
}

.graph-node-pin {
    justify-self: start;
    color: #fde68a;
    background: rgba(113, 63, 18, 0.28);
    border-color: rgba(250, 204, 21, 0.24);
}

.graph-node-query {
    width: 220px;
    background: linear-gradient(135deg, rgba(96, 165, 250, 0.16), rgba(45, 212, 191, 0.08)), rgba(12, 18, 30, 0.96);
}

.graph-node-project {
    width: 180px;
}

.graph-node-document {
    width: 240px;
    min-height: 92px;
}

.graph-node-entity {
    width: 210px;
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.12), rgba(15, 23, 42, 0.94));
}

.graph-node-agent {
    width: 210px;
    background: linear-gradient(135deg, rgba(148, 163, 184, 0.14), rgba(15, 23, 42, 0.94));
}

.graph-node-keyword {
    width: 170px;
}

.graph-node-kind {
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}

.graph-node-secondary {
    font-size: 0.77rem;
    color: var(--muted);
}

.graph-side-panel {
    display: grid;
    gap: 14px;
    min-width: 0;
    align-self: start;
}

.graph-workspace-grid.panel-collapsed {
    grid-template-columns: minmax(0, 1fr);
}

.graph-detail-card {
    padding: 18px;
    min-width: 0;
    overflow: hidden;
}

.graph-detail-header.compact {
    align-items: flex-start;
    flex-wrap: wrap;
}

.graph-score-row,
.graph-detail-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.graph-score-row {
    margin-top: 12px;
}

.graph-detail-actions {
    margin-top: 14px;
    align-items: center;
    justify-content: flex-start;
}

.graph-action-btn {
    justify-content: center;
}

.queue-action-btn {
    justify-content: center;
}

.graph-detail-actions.inline {
    margin-top: 0;
    width: 100%;
}

.graph-inline-form {
    display: grid;
    gap: 10px;
    margin-top: 12px;
}

.graph-inline-form textarea {
    min-height: 82px;
    resize: vertical;
}

.graph-inline-form-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 110px;
    gap: 10px;
}

.graph-color-control input[type="color"] {
    width: 100%;
    min-height: 38px;
    padding: 0;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: transparent;
}

.graph-workspace-summary {
    gap: 12px;
}

.graph-workspace-list-section {
    display: grid;
    gap: 8px;
}

.graph-workspace-list {
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.graph-workspace-list-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: rgba(9, 14, 24, 0.56);
}

.graph-workspace-list-copy {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.graph-workspace-list-copy strong,
.graph-workspace-list-copy span {
    overflow-wrap: anywhere;
}

.graph-relationship-toolbar {
    margin-top: 6px;
}

.graph-evidence-list .retry-item.active {
    border-color: rgba(74, 222, 128, 0.2);
    background: rgba(12, 24, 24, 0.48);
}

.graph-evidence-list {
    margin-top: 12px;
}

.graph-evidence-list .retry-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 12px;
    min-width: 0;
    padding: 14px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: rgba(9, 14, 24, 0.54);
    overflow: hidden;
}

.graph-evidence-copy,
.graph-evidence-list .retry-item-copy,
.graph-evidence-list .retry-item-actions {
    min-width: 0;
}

.graph-evidence-copy {
    gap: 5px;
}

.graph-evidence-title {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--ink);
    font: inherit;
    font-weight: 620;
    text-align: left;
    cursor: pointer;
    overflow: hidden;
}

.graph-evidence-title:hover {
    color: var(--accent);
}

.graph-evidence-meta,
.graph-evidence-snippet {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-width: 0;
    color: var(--ink-soft);
}

.graph-evidence-meta {
    -webkit-line-clamp: 1;
}

.graph-evidence-snippet {
    -webkit-line-clamp: 3;
}

.graph-panel-reopen {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 3;
}

.graph-detail-card p,
.graph-relationship-copy strong,
.graph-relationship-copy p,
.graph-link-explanation-copy strong,
.graph-link-explanation-copy p,
.graph-evidence-title,
.graph-node strong,
.graph-node-secondary {
    overflow-wrap: anywhere;
}

.graph-relationship-list {
    display: grid;
    gap: 10px;
    margin: 12px 0 0;
    padding: 0;
    list-style: none;
    min-width: 0;
}

.graph-relationship-item {
    display: grid;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: rgba(9, 14, 24, 0.72);
    min-width: 0;
    overflow: hidden;
}

.graph-relationship-copy {
    display: grid;
    gap: 8px;
    min-width: 0;
}

.graph-relationship-copy p {
    margin: 0;
}

.graph-relationship-copy strong {
    font-size: 0.95rem;
    line-height: 1.35;
}

.graph-relationship-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.graph-relationship-evidence-block {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.graph-relationship-evidence-heading {
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.graph-relationship-evidence-table {
    display: grid;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: rgba(15, 23, 42, 0.44);
}

.graph-relationship-evidence-row {
    display: grid;
    grid-template-columns: 54px minmax(0, 1fr);
}

.graph-relationship-evidence-row + .graph-relationship-evidence-row {
    border-top: 1px solid var(--border);
}

.graph-relationship-evidence-label {
    padding: 8px 10px;
    border-right: 1px solid var(--border);
    background: rgba(30, 41, 59, 0.42);
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.graph-relationship-evidence-value,
.graph-relationship-evidence-link {
    display: block;
    min-width: 0;
    padding: 8px 10px;
    font-size: 0.78rem;
    line-height: 1.35;
    color: var(--ink-soft);
    overflow-wrap: anywhere;
}

.graph-relationship-evidence-link {
    text-decoration: none;
}

.graph-relationship-evidence-link:hover {
    color: var(--accent);
    text-decoration: underline;
}

.graph-relationship-actions {
    margin-top: 2px;
}

.graph-link-explanation-list {
    display: grid;
    gap: 8px;
    margin: 12px 0 0;
    padding: 0;
    list-style: none;
    min-width: 0;
}

.graph-link-explanation-item {
    display: grid;
    gap: 6px;
    padding: 11px 12px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(9, 14, 24, 0.62);
    min-width: 0;
    overflow: hidden;
}

.graph-link-explanation-copy {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.graph-link-explanation-copy strong {
    font-size: 0.89rem;
    line-height: 1.35;
}

.graph-link-explanation-copy p {
    margin: 0;
    font-size: 0.8rem;
    line-height: 1.45;
    color: var(--ink-soft);
}

.graph-link-explanation-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.graph-checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.84rem;
    color: var(--ink-soft);
}

.graph-checkbox-row input {
    width: auto;
    margin: 0;
}

.graph-target-picker {
    display: grid;
    gap: 10px;
    padding: 12px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(11, 17, 28, 0.7);
}

.graph-target-picker-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.graph-target-selection,
.graph-target-create-panel {
    display: grid;
    gap: 10px;
    padding: 12px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.42);
}

.graph-entity-search-results {
    gap: 8px;
    min-width: 0;
}

.graph-entity-search-results .retry-item {
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(9, 14, 24, 0.54);
    min-width: 0;
    overflow: hidden;
}

.graph-target-selection .retry-item-actions,
.graph-entity-search-results .retry-item-actions {
    justify-content: flex-start;
}

.graph-entity-modal .form-panel,
.graph-relationship-modal .form-panel {
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
}

.graph-entity-modal,
.graph-relationship-modal {
    width: min(760px, calc(100vw - 40px));
    max-width: min(760px, calc(100vw - 40px));
}

.graph-review-list .retry-item {
    align-items: flex-start;
}

.graph-chat-callout {
    width: min(var(--content-max-width), calc(100% - 40px));
    margin: 0 auto 16px;
    display: flex;
    justify-content: space-between;
    gap: 14px;
    padding: 16px 18px;
    border-radius: 20px;
    border: 1px solid rgba(125, 211, 252, 0.16);
    background: linear-gradient(135deg, rgba(96, 165, 250, 0.1), rgba(45, 212, 191, 0.06)), rgba(11, 18, 30, 0.86);
    box-shadow: var(--shadow-soft);
}

.graph-chat-copy {
    display: grid;
    gap: 6px;
}

.graph-chat-copy p,
.graph-chat-copy strong {
    margin: 0;
}

.graph-chat-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: flex-start;
    justify-content: flex-end;
}

.graph-modal-summary {
    display: grid;
    gap: 10px;
    margin-top: 12px;
}

.graph-predicate-picker {
    display: grid;
    gap: 12px;
    padding: 14px;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.36);
}

.graph-predicate-current {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
}

.graph-predicate-current-copy {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.graph-predicate-current-copy p,
.graph-predicate-current-copy strong {
    margin: 0;
}

.graph-predicate-current-label-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.graph-predicate-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
}

.graph-predicate-custom {
    margin-top: -2px;
}

.graph-predicate-helper {
    display: grid;
    gap: 12px;
}

.graph-predicate-category-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.graph-predicate-category-row .graph-action-btn.active {
    border-color: rgba(96, 165, 250, 0.42);
    background: rgba(20, 32, 54, 0.9);
    color: var(--ink);
}

.graph-predicate-category-copy {
    margin: 0;
}

.graph-predicate-option-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 10px;
}

.graph-predicate-option {
    display: grid;
    gap: 8px;
    padding: 12px 14px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: rgba(9, 14, 24, 0.72);
    color: var(--ink);
    text-align: left;
    cursor: pointer;
    transition: border-color 140ms ease, transform 140ms ease, background 140ms ease;
}

.graph-predicate-option:hover,
.graph-predicate-option:focus-visible {
    border-color: rgba(125, 211, 252, 0.35);
    background: rgba(12, 19, 31, 0.9);
    transform: translateY(-1px);
}

.graph-predicate-option.active {
    border-color: rgba(96, 165, 250, 0.44);
    background: linear-gradient(180deg, rgba(21, 39, 67, 0.92), rgba(10, 16, 28, 0.92));
    box-shadow: 0 14px 30px rgba(2, 6, 23, 0.28);
}

.graph-predicate-option-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.graph-predicate-option-head strong {
    font-size: 0.9rem;
}

.graph-predicate-option-code {
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 0.78rem;
    color: var(--accent);
    letter-spacing: 0.04em;
}

.graph-predicate-option-copy {
    font-size: 0.8rem;
    line-height: 1.45;
    color: var(--muted);
}

.catalog-control {
    display: grid;
    gap: 8px;
}

.sidebar-list,
.folder-list,
.catalog-list,
.message-list,
.entity-list,
.citation-list,
.retry-list {
    list-style: none;
    margin: 0;
    padding: 0;
}


.project-card.minimal,
.folder-item {
    position: relative;
    display: grid;
    gap: 4px;
    padding: 12px 13px;
    border-radius: 14px;
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    transition: transform 140ms ease, background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.project-card.minimal + .project-card.minimal,
.folder-item + .folder-item {
    margin-top: 6px;
}

.project-card.minimal h3,
.folder-item-title {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--ink);
}

.folder-item-copy {
    min-width: 0;
    display: grid;
    gap: 4px;
}

.folder-item-meta {
    display: block;
    min-width: 0;
    color: var(--muted);
    font-size: 0.74rem;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-artifact-item {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px 10px;
    align-items: start;
    padding: 10px 11px;
    border-radius: 10px;
}

.sidebar-artifact-item .folder-item-title {
    font-size: 0.88rem;
    line-height: 1.28;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}

.project-card.minimal:hover,
.folder-item:hover {
    background: rgba(30, 41, 59, 0.36);
    border-color: var(--border);
}

.project-card.minimal.active,
.folder-item.active {
    background: rgba(15, 23, 42, 0.6);
    border-color: var(--border);
    border-left: 2px solid var(--accent);
}

.project-card.minimal.active::before,
.folder-item.active::before {
    display: none;
}

.folder-item.appendix {
    cursor: pointer;
}

.folder-item.appendix:hover .folder-item-title {
    color: var(--accent);
}

.folder-item.appendix.sidebar-artifact-item .appendix-state {
    align-self: start;
}

.sidebar-artifact-item.excluded {
    opacity: 0.45;
}

.sidebar-artifact-item.excluded .folder-item-title {
    text-decoration: line-through;
}

.appendix-state {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    border: 1px solid var(--border);
}

.appendix-state.warning {
    color: var(--warning);
    border-color: rgba(245, 158, 11, 0.18);
    background: rgba(54, 31, 8, 0.42);
}

.appendix-state.danger {
    color: var(--danger);
    border-color: rgba(248, 113, 113, 0.2);
    background: rgba(59, 16, 16, 0.42);
}

.catalog-action-btn,
.catalog-action-status {
    min-height: 32px;
    font-size: 0.8rem;
    line-height: 1.2;
}

.catalog-action-btn {
    justify-content: center;
}

.catalog-action-status {
    display: inline-flex;
    align-items: center;
    padding: 6px 10px;
}


.tiny {
    font-size: 0.82rem;
    color: var(--muted);
}

.mono {
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 0.82rem;
}

.btn,
.secondary-btn,
.ghost-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    padding: 9px 14px;
    border: 1px solid transparent;
    font: inherit;
    line-height: 1.2;
    font-weight: 600;
    cursor: pointer;
    transition: transform 120ms ease, background 120ms ease, border-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
}

.btn:hover,
.secondary-btn:hover,
.ghost-btn:hover {
    transform: translateY(-1px);
}

.btn {
    color: #04101e;
    background: linear-gradient(135deg, #7dd3fc, #60a5fa);
    box-shadow: 0 10px 24px rgba(96, 165, 250, 0.22);
}

.btn:hover {
    background: linear-gradient(135deg, #93ddff, #78b6ff);
}

.secondary-btn {
    color: var(--ink-soft);
    background: rgba(15, 23, 42, 0.7);
    border-color: var(--border);
}

.secondary-btn:hover {
    background: rgba(30, 41, 59, 0.85);
    border-color: var(--border-strong);
}

.ghost-btn {
    color: var(--muted);
    background: transparent;
    border-color: var(--border);
}

.ghost-btn:hover {
    color: var(--ink);
    background: rgba(15, 23, 42, 0.5);
}

.btn:disabled,
.secondary-btn:disabled,
.ghost-btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
    transform: none;
}

.secondary-btn.compact,
.btn.compact,
.ghost-btn.compact {
    padding: 6px 10px;
    font-size: 0.8rem;
}

.form-panel {
    margin: 0 24px 16px;
    padding: 14px;
    display: grid;
    gap: 10px;
    border-radius: 18px;
    background: rgba(15, 23, 42, 0.56);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-soft);
}

.form-panel.hidden,
.hidden {
    display: none !important;
}

.form-panel input,
.form-panel textarea,
.composer textarea,
.upload-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    background: rgba(7, 11, 18, 0.82);
    color: var(--ink);
    font: inherit;
}

.form-panel input::placeholder,
.form-panel textarea::placeholder,
.composer textarea::placeholder {
    color: #6f7f96;
}

.form-panel textarea,
.composer textarea {
    resize: vertical;
}

.form-panel input:focus,
.form-panel textarea:focus,
.composer textarea:focus {
    outline: none;
    border-color: rgba(125, 211, 252, 0.4);
    box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.1);
}

.project-header.minimal,
.project-toolbar.minimal,
.message-list {
    width: calc(100% - 40px);
    margin-left: auto;
    margin-right: auto;
}

.composer {
    width: calc(100% - 80px);
    margin-left: auto;
    margin-right: auto;
}

.project-header.minimal {
    padding-bottom: 12px;
}

.message-scroller {
    min-height: 0;
    overflow: auto;
    padding: 10px 20px 24px;
}

.message-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
}

.message {
    display: grid;
    gap: 10px;
    width: 100%;
    min-width: 0;
    padding: 16px 18px;
    border-radius: 20px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-soft);
    box-sizing: border-box;
}

.message.user {
    align-self: flex-end;
    max-width: var(--user-max-width);
    background:
        linear-gradient(135deg, rgba(55, 116, 236, 0.94), rgba(49, 75, 167, 0.98)),
        rgba(18, 46, 102, 0.92);
    color: #ecf4ff;
    border-color: rgba(125, 211, 252, 0.14);
}

.message.assistant {
    align-self: flex-start;
    max-width: 100%;
    background: linear-gradient(180deg, rgba(18, 24, 38, 0.96), rgba(14, 20, 32, 0.94));
}

.message-header {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 0.73rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: inherit;
    opacity: 0.72;
}

.message-content {
    overflow-wrap: anywhere;
}

.message-content > :first-child {
    margin-top: 0;
}

.message-content > :last-child {
    margin-bottom: 0;
}

.message-content p,
.message-content ul,
.message-content ol,
.message-content pre,
.message-content blockquote,
.message-content table {
    margin: 0.75em 0;
}

.message-content ul,
.message-content ol {
    padding-left: 1.25rem;
}

.message-content li + li {
    margin-top: 0.32rem;
}

.message-content code {
    padding: 0.14em 0.38em;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 0.92em;
}

.message.user .message-content code {
    background: rgba(255, 255, 255, 0.16);
}

.message-content pre {
    overflow: auto;
    padding: 14px;
    border-radius: 14px;
    background: rgba(2, 6, 23, 0.92);
    color: #eff6ff;
    border: 1px solid rgba(148, 163, 184, 0.12);
}

.message-content pre code {
    padding: 0;
    background: transparent;
}

.message-content blockquote {
    margin-left: 0;
    padding-left: 12px;
    border-left: 3px solid rgba(125, 211, 252, 0.34);
    color: var(--ink-soft);
}

.message-content table {
    width: 100%;
    display: block;
    overflow-x: auto;
    border-collapse: collapse;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: auto;
}

.message-content th,
.message-content td {
    min-width: 140px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.message-content th {
    background: rgba(148, 163, 184, 0.08);
}

.message-metrics {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.message-runtime {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.processing-message {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 24px;
}

.processing-text {
    font-weight: 600;
}

.processing-elapsed {
    color: var(--muted);
    font-size: 0.82rem;
}

.typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: rgba(125, 211, 252, 0.82);
    animation: typing-pulse 1s ease-in-out infinite;
}

.typing-dots span:nth-child(2) {
    animation-delay: 120ms;
}

.typing-dots span:nth-child(3) {
    animation-delay: 240ms;
}

.disclosure {
    border: 1px solid var(--border);
    border-radius: 16px;
    background: rgba(10, 15, 25, 0.42);
    overflow: hidden;
}

.disclosure.compact {
    margin-top: 4px;
}

.disclosure.success {
    border-color: rgba(74, 222, 128, 0.14);
    background: rgba(10, 36, 24, 0.28);
}

.disclosure.warning {
    border-color: rgba(245, 158, 11, 0.14);
    background: rgba(54, 31, 8, 0.28);
}

.disclosure.danger {
    border-color: rgba(248, 113, 113, 0.16);
    background: rgba(59, 16, 16, 0.3);
}

.disclosure-summary {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 14px;
    cursor: pointer;
    list-style: none;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--ink-soft);
}

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

.disclosure-summary::after {
    content: "▾";
    color: var(--muted);
    transition: transform 140ms ease;
}

.disclosure[open] .disclosure-summary::after {
    transform: rotate(180deg);
}

.disclosure-summary:hover {
    background: rgba(255, 255, 255, 0.02);
}

.disclosure-title {
    letter-spacing: 0.01em;
}

.disclosure-content {
    display: grid;
    gap: 10px;
    padding: 0 14px 14px;
}

.tool-activity-strip {
    display: grid;
    gap: 8px;
}

.tool-activity {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.52);
    font-size: 0.82rem;
}

.tool-activity.success {
    border-color: rgba(74, 222, 128, 0.14);
    background: rgba(10, 36, 24, 0.5);
}

.tool-activity.warning {
    border-color: rgba(245, 158, 11, 0.14);
    background: rgba(54, 31, 8, 0.5);
}

.tool-activity.danger {
    border-color: rgba(248, 113, 113, 0.14);
    background: rgba(59, 16, 16, 0.52);
}

.tool-activity-label,
.tool-activity-status {
    font-weight: 700;
}

.tool-activity-provider,
.tool-activity-summary {
    color: var(--muted);
}

.citation-block {
    display: grid;
}

.citation-list {
    display: grid;
    gap: 8px;
}

.citation-item {
    display: grid;
    gap: 4px;
    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(7, 11, 18, 0.56);
    border: 1px solid var(--border);
}

.citation-item a {
    font-weight: 600;
    text-decoration: none;
    overflow-wrap: anywhere;
}

.citation-item a:hover {
    color: var(--accent);
    text-decoration: underline;
}

.citation-url {
    font-size: 0.8rem;
    color: var(--muted);
    overflow-wrap: anywhere;
}

.composer {
    margin-top: 4px;
    margin-bottom: 28px;
    padding: 12px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    background: var(--surface-strong);
    box-shadow: var(--shadow-soft);
}

.composer:hover {
    border-color: rgba(125, 211, 252, 0.18);
    box-shadow: 0 24px 60px rgba(2, 6, 23, 0.4);
}

.composer textarea {
    min-height: 38px;
    max-height: 200px;
    border: none;
    padding: 0;
    background: transparent;
    resize: none;
    overflow-y: auto;
    line-height: 1.5;
}

.composer textarea:focus {
    box-shadow: none;
}

.empty-state,
.loading-state {
    padding: 16px;
    border-radius: 16px;
    border: 1px dashed rgba(148, 163, 184, 0.22);
    background: rgba(15, 23, 42, 0.48);
    color: var(--muted);
}

.empty-state.compact {
    margin: 0 8px;
    padding: 12px;
}

.loading-state {
    box-shadow: inset 0 0 0 1px rgba(125, 211, 252, 0.04);
}

.app-banner {
    position: fixed;
    right: 22px;
    bottom: 22px;
    max-width: 360px;
    padding: 12px 14px;
    border-radius: 16px;
    background: rgba(10, 15, 25, 0.94);
    color: var(--ink);
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow);
    z-index: 20;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-lg);
    background: rgba(0, 0, 0, 0.6);
    z-index: 30;
}

.document-modal {
    width: min(900px, 100%);
    max-height: min(88vh, 940px);
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
    background: var(--surface-strong);
    border: 1px solid var(--border-strong);
    border-radius: 26px;
    box-shadow: 0 30px 90px rgba(2, 6, 23, 0.56);
    animation: modal-rise 180ms ease-out;
}

.failed-enrichment-modal {
    width: min(780px, 100%);
}

.appendix-modal {
    width: min(760px, 100%);
}

.catalog-chat-modal {
    width: min(760px, 100%);
}

.task-modal {
    width: min(920px, 100%);
}

.task-run-modal {
    width: min(840px, 100%);
}

.document-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    padding: 22px 24px 16px;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.01);
}

.document-modal-header > div {
    min-width: 0;
}

.document-modal-header h3 {
    margin: 6px 0 0;
    font-size: 1.18rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.document-modal-body {
    overflow: auto;
    padding: 22px 24px 26px;
    display: grid;
    gap: 14px;
}

.status-stack {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.document-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: rgba(15, 23, 42, 0.72);
    color: var(--muted);
    border: 1px solid var(--border);
}

.status-pill.success {
    color: var(--success);
    background: rgba(10, 36, 24, 0.58);
    border-color: rgba(74, 222, 128, 0.16);
}

.status-pill.warning {
    color: var(--warning);
    background: rgba(54, 31, 8, 0.58);
    border-color: rgba(245, 158, 11, 0.16);
}

.status-pill.danger {
    color: var(--danger);
    background: rgba(59, 16, 16, 0.58);
    border-color: rgba(248, 113, 113, 0.16);
}

.status-pill.neutral {
    color: var(--muted);
}

.document-meta-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.document-meta-card,
.document-analysis-section,
.retry-item {
    border: 1px solid var(--border);
    border-radius: 16px;
    background: rgba(15, 23, 42, 0.48);
}

.document-meta-card {
    display: grid;
    gap: 4px;
    padding: 12px;
}

.document-analysis {
    display: grid;
    gap: 12px;
}

.document-analysis-subsection {
    display: grid;
    gap: 8px;
    margin-top: 12px;
}

.graph-signal-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 8px;
}

.graph-signal-card {
    display: grid;
    gap: 8px;
    padding: 12px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(7, 11, 18, 0.54);
}

.document-analysis-section {
    padding: 13px 14px;
}

.task-weekday-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.task-weekday-option,
.task-enabled-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.46);
}

.task-weekday-option input,
.task-enabled-toggle input {
    width: auto;
    margin: 0;
}

.task-status-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.task-run-section {
    display: grid;
    gap: 10px;
}

.task-prompt-guide {
    display: grid;
    gap: 10px;
}

.task-template-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.task-template-btn {
    min-height: 34px;
}

.task-template-btn.active {
    border-color: rgba(96, 165, 250, 0.35);
    color: var(--ink);
    background: rgba(59, 130, 246, 0.12);
}

.task-template-summary {
    display: grid;
    gap: 4px;
}

.task-run-item .retry-item-actions {
    align-items: flex-start;
}

.task-url-list .retry-item {
    padding: 10px 12px;
}

.appendix-callout p {
    margin: 10px 0 0;
    color: var(--ink-soft);
    line-height: 1.55;
}

.appendix-error {
    display: grid;
    gap: 6px;
    margin-top: 12px;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.58);
}

.appendix-error.warning {
    color: var(--warning);
    border-color: rgba(245, 158, 11, 0.18);
    background: rgba(54, 31, 8, 0.42);
}

.appendix-error.danger {
    color: var(--danger);
    border-color: rgba(248, 113, 113, 0.18);
    background: rgba(59, 16, 16, 0.42);
}

.appendix-link {
    color: var(--accent);
    word-break: break-word;
    text-decoration: none;
}

.appendix-link:hover {
    text-decoration: underline;
}

.appendix-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
}

.document-analysis-section p {
    margin: 6px 0 0;
    color: var(--ink-soft);
}

.document-evidence-query-row {
    display: grid;
    gap: 8px;
    margin-top: 12px;
}

.document-evidence-query-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
}

.document-evidence-query-controls input {
    min-width: 0;
}

.document-evidence-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.document-evidence-mode {
    margin-top: 4px;
}

.document-evidence-chunk-list,
.document-evidence-hint-list {
    display: grid;
    gap: 10px;
    margin-top: 8px;
}

.document-evidence-chunk {
    display: grid;
    gap: 8px;
}

.document-evidence-chunk-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    color: var(--muted);
}

.error-list {
    display: grid;
    gap: 10px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.error-item {
    display: grid;
    gap: 4px;
    padding: 10px 12px;
    border-radius: 13px;
    border: 1px solid rgba(248, 113, 113, 0.14);
    background: rgba(48, 16, 16, 0.34);
    color: var(--ink-soft);
}

.tag-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.tag-chip,
.tag-chip-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-height: 32px;
    padding: 6px 11px;
    border-radius: 999px;
    background: rgba(96, 165, 250, 0.12);
    color: #bfdbfe;
    border: 1px solid rgba(125, 211, 252, 0.12);
    box-sizing: border-box;
    font-family: inherit;
    font-size: 0.77rem;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: top;
}

.tag-chip-button {
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    margin: 0;
    text-align: left;
    transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.tag-chip-button:hover {
    transform: translateY(-1px);
    border-color: rgba(125, 211, 252, 0.28);
    background: rgba(96, 165, 250, 0.18);
}

.graph-context-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 65;
}

.graph-context-menu {
    position: fixed;
    width: min(220px, calc(100vw - 24px));
    display: grid;
    gap: 10px;
    padding: 12px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: rgba(7, 11, 18, 0.96);
    box-shadow: 0 20px 48px rgba(2, 6, 23, 0.46);
}

.graph-context-menu-head {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.graph-context-menu-head strong,
.graph-context-menu-head span {
    overflow-wrap: anywhere;
}

.graph-context-menu-actions {
    display: grid;
    gap: 8px;
}

.entity-list {
    display: grid;
    gap: 8px;
    margin-top: 8px;
}

.entity-item {
    display: grid;
    gap: 2px;
    padding: 10px 12px;
    border-radius: 13px;
    border: 1px solid var(--border);
    background: rgba(7, 11, 18, 0.56);
}

.document-text-block {
    margin-top: 8px;
    max-height: 280px;
    overflow: auto;
    padding: 12px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(5, 8, 16, 0.8);
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.92rem;
    color: var(--ink-soft);
}

.retry-list {
    display: grid;
    gap: 12px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.retry-item {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 16px;
}

.retry-item-copy {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.retry-item-actions {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.sync-actions {
    min-width: 220px;
}

@keyframes modal-rise {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.99);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes typing-pulse {
    0%, 80%, 100% {
        opacity: 0.32;
        transform: translateY(0);
    }
    40% {
        opacity: 1;
        transform: translateY(-1px);
    }
}

/* === Login Screen === */

.login-shell {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: var(--space-lg);
}

.login-card {
    width: min(380px, 100%);
    padding: var(--space-xl) var(--space-lg);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
}

.login-brand {
    margin: 0 0 4px;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.login-tagline {
    margin: 0 0 var(--space-lg);
    font-size: 0.82rem;
    color: var(--text-muted);
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.login-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.login-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.login-field input {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-default);
    background: var(--bg-panel);
    color: var(--text-primary);
    font: inherit;
    font-size: 0.95rem;
}

.login-field input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-primary-muted);
}

.login-error {
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: var(--accent-danger-muted);
    color: var(--accent-danger);
    font-size: 0.82rem;
}

.login-submit {
    margin-top: var(--space-sm);
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--accent-primary);
    color: var(--text-inverse);
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.15s ease;
}

.login-submit:hover {
    filter: brightness(1.1);
}

/* === Workspace Tabs === */

.workspace-tab-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-height: 0;
}

.workspace-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border-subtle);
    padding: 0 var(--space-md);
    background: var(--bg-surface);
    flex-shrink: 0;
}

.workspace-tab {
    padding: 10px 18px;
    border: none;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
}

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

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

/* === Report Workspace === */

.report-workspace {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

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

.report-header-left .eyebrow {
    margin: 0;
}

.report-title {
    margin: 4px 0 0;
    font-size: 1.1rem;
    font-weight: 600;
}

.report-header-right {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.report-status-select {
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-default);
    background: var(--bg-panel);
    color: var(--text-secondary);
    font: inherit;
    font-size: 0.78rem;
    cursor: pointer;
}

.report-body-layout {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr 280px;
    overflow: hidden;
}

.report-editor-column {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.report-editor-container {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.report-bibliography-pane {
    border-left: 1px solid var(--border-subtle);
    padding: var(--space-md);
    overflow-y: auto;
    background: var(--bg-surface);
}

.bib-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.bib-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    padding: var(--space-sm);
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    line-height: 1.3;
}

.bib-item.cited {
    background: var(--accent-success-muted);
}

.bib-item.unused {
    background: var(--bg-panel);
}

.bib-number {
    font-weight: 700;
    color: var(--accent-primary);
    flex-shrink: 0;
}

.bib-label {
    flex: 1;
    min-width: 0;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.bib-status {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    flex-shrink: 0;
}

.bib-item.cited .bib-status {
    color: var(--accent-success);
}

.bib-item.unused .bib-status {
    color: var(--text-muted);
}

.bib-divider {
    height: 1px;
    background: var(--border-subtle);
    margin: var(--space-sm) 0;
}

.bib-actions {
    margin-top: var(--space-md);
}

.bib-item-actions {
    display: flex;
    gap: var(--space-xs);
    flex-shrink: 0;
}

.bib-action-btn {
    font-size: 0.72rem;
    padding: 2px 6px;
}

.entity-link-item {
    background: var(--bg-panel);
}

.entity-link-item .entity-badge {
    flex-shrink: 0;
}

.entity-search-row {
    display: flex;
    gap: var(--space-sm);
}

.entity-search-row input {
    flex: 1;
}

.entity-selected-card {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--accent-primary-muted);
    border-radius: var(--radius-sm);
    margin: var(--space-sm) 0;
}

.entity-search-results {
    max-height: 200px;
    overflow-y: auto;
}

#report-editor-container {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.tiptap-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.tiptap-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 6px 12px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.tiptap-btn {
    padding: 4px 10px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
}

.tiptap-btn:hover {
    background: var(--bg-raised);
    color: var(--text-primary);
}

.tiptap-btn.active {
    background: var(--accent-primary-muted);
    color: var(--accent-primary);
}

.tiptap-separator {
    width: 1px;
    height: 18px;
    background: var(--border-subtle);
    margin: 0 4px;
}

.tiptap-content {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

#report-editor-container .ProseMirror {
    min-height: 400px;
    padding: var(--space-lg);
    outline: none;
    color: var(--text-primary);
    font-size: 0.95rem;
    line-height: 1.7;
}

#report-editor-container .ProseMirror p.is-editor-empty:first-child::before {
    content: attr(data-placeholder);
    float: left;
    color: var(--text-muted);
    pointer-events: none;
    height: 0;
}

#report-editor-container .ProseMirror h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 1.2em 0 0.4em;
    color: var(--text-primary);
}

#report-editor-container .ProseMirror h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 1em 0 0.3em;
    color: var(--text-primary);
}

#report-editor-container .ProseMirror h3 {
    font-size: 1.05rem;
    font-weight: 600;
    margin: 0.8em 0 0.3em;
    color: var(--text-primary);
}

#report-editor-container .ProseMirror blockquote {
    border-left: 3px solid var(--border-active);
    padding-left: var(--space-md);
    color: var(--text-secondary);
    margin: 0.8em 0;
}

#report-editor-container .ProseMirror hr {
    border: none;
    border-top: 1px solid var(--border-subtle);
    margin: 1.2em 0;
}

#report-editor-container .ProseMirror ul,
#report-editor-container .ProseMirror ol {
    padding-left: 1.5em;
}

#report-editor-container .ProseMirror a,
#report-editor-container .ProseMirror a.report-link {
    color: var(--accent-primary);
    text-decoration: underline;
    text-decoration-color: rgba(91, 107, 255, 0.3);
    cursor: pointer;
}

#report-editor-container .ProseMirror a:hover {
    text-decoration-color: var(--accent-primary);
}

#report-editor-container .ProseMirror ::selection {
    background: var(--accent-primary-muted);
}

/* Report Ask Panel */

.report-ask-panel {
    border-top: 1px solid var(--border-subtle);
    padding: var(--space-sm) var(--space-md);
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: var(--space-sm);
    background: var(--surface-secondary);
    flex-shrink: 0;
}

.report-ask-form {
    display: flex;
    gap: var(--space-sm);
    flex: 1;
    min-width: 0;
}

.report-ask-input {
    flex: 1;
    min-width: 0;
    padding: 4px 8px;
    font-size: 0.8rem;
    background: var(--surface-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    color: var(--text-primary);
}

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

.report-ask-response {
    width: 100%;
    margin-top: var(--space-xs);
}

.report-ask-text {
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--text-secondary);
    background: var(--surface-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: var(--space-sm) var(--space-md);
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
    margin-bottom: var(--space-sm);
}

.report-ask-response-actions {
    display: flex;
    gap: var(--space-sm);
}

/* Bib picker dual buttons */

.bib-picker-actions {
    display: flex;
    gap: var(--space-xs);
    flex-shrink: 0;
}

.sidebar-delete-btn {
    opacity: 0;
    font-size: 0.7rem;
    padding: 2px 6px;
    flex-shrink: 0;
    color: var(--accent-danger);
}

.folder-item:hover .sidebar-delete-btn {
    opacity: 1;
}

/* === Message Actions === */

.message-actions {
    display: flex;
    gap: var(--space-sm);
    margin-top: var(--space-sm);
    opacity: 0;
    transition: opacity 0.15s ease;
}

.message:hover .message-actions {
    opacity: 1;
}

/* === Design System Components === */

/* Toggle Chip */
.toggle-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    border: 1px solid var(--border-default);
    background: transparent;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.03em;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
    font-family: inherit;
}

.toggle-chip:hover {
    border-color: var(--border-active);
    color: var(--text-secondary);
}

.toggle-chip.active {
    border-color: var(--accent-primary);
    background: var(--accent-primary-muted);
    color: var(--accent-primary);
}

.toggle-chip .toggle-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.6;
}

.toggle-chip.active .toggle-dot {
    opacity: 1;
}

.layer-toggle-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-subtle);
}

/* Entity Type Badge */
.entity-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.entity-badge.type-person       { background: rgba(91,107,255,0.15);  color: #5b6bff; }
.entity-badge.type-organisation { background: rgba(46,204,113,0.15);  color: #2ecc71; }
.entity-badge.type-place        { background: rgba(230,126,34,0.15);  color: #e67e22; }
.entity-badge.type-event        { background: rgba(231,76,60,0.15);   color: #e74c3c; }
.entity-badge.type-concept      { background: rgba(155,89,182,0.15);  color: #9b59b6; }
.entity-badge.type-policy       { background: rgba(26,188,156,0.15);  color: #1abc9c; }
.entity-badge.type-country      { background: rgba(230,126,34,0.15);  color: #e67e22; }
.entity-badge.type-region       { background: rgba(211,84,0,0.15);    color: #d35400; }
.entity-badge.type-commodity    { background: rgba(241,196,15,0.15);  color: #f1c40f; }
.entity-badge.type-default      { background: var(--bg-raised);       color: var(--text-secondary); }

/* Status Badge */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
}

.status-badge::before {
    content: '';
    display: block;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
}

.status-badge.trusted     { background: var(--accent-success-muted); color: var(--accent-success); }
.status-badge.suggested   { background: var(--accent-warning-muted); color: var(--accent-warning); }
.status-badge.rejected    { background: var(--accent-danger-muted);  color: var(--accent-danger); }
.status-badge.pending     { background: var(--bg-raised);            color: var(--text-muted); }
.status-badge.corpus      { background: rgba(155,89,182,0.15);       color: #9b59b6; }
.status-badge.catalog     { background: var(--accent-primary-muted); color: var(--accent-primary); }
.status-badge.provisional { background: var(--accent-warning-muted); color: var(--accent-warning); }

.status-badge.tiny { font-size: 9px; padding: 1px 5px; }
.status-badge.tiny::before { width: 4px; height: 4px; }

.sidebar-filter-row {
    display: flex;
    gap: 4px;
    padding: 4px 12px;
    flex-wrap: wrap;
}
.chip-btn {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-subtle);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, color 0.15s;
}
.chip-btn:hover { background: var(--bg-raised); color: var(--text-primary); }
.chip-btn.active { background: var(--accent-primary-muted); color: var(--accent-primary); border-color: var(--accent-primary); }

/* Relation Chip */
.relation-chip {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 4px;
    background: var(--bg-raised);
    border: 1px solid var(--border-default);
    font-size: 10px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.04em;
}

/* Confidence Meter */
.confidence-meter {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10px;
    color: var(--text-secondary);
}

.confidence-bar {
    width: 48px;
    height: 4px;
    border-radius: 2px;
    background: var(--bg-raised);
    overflow: hidden;
}

.confidence-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s ease;
}

.confidence-fill.high   { background: var(--confidence-high); }
.confidence-fill.medium { background: var(--confidence-medium); }
.confidence-fill.low    { background: var(--confidence-low); }

/* Panel Section */
.panel-section {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-subtle);
}

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

.panel-section-label {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 8px;
}

/* Inline Alert */
.inline-alert {
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 11px;
    line-height: 1.4;
    display: flex;
    gap: 7px;
    align-items: flex-start;
}

.inline-alert.info    { background: var(--accent-primary-muted); color: var(--text-secondary); }
.inline-alert.warning { background: var(--accent-warning-muted); color: var(--accent-warning); }
.inline-alert.empty   { background: var(--bg-raised); color: var(--text-muted); font-style: italic; }

/* Graph Node Entity Type Borders */
.graph-node.type-person       { border-left: 3px solid var(--entity-person); }
.graph-node.type-organisation { border-left: 3px solid var(--entity-organisation); }
.graph-node.type-place        { border-left: 3px solid var(--entity-place); }
.graph-node.type-event        { border-left: 3px solid var(--entity-event); }
.graph-node.type-concept      { border-left: 3px solid var(--entity-concept); }
.graph-node.type-policy       { border-left: 3px solid var(--entity-policy); }
.graph-node.type-country      { border-left: 3px solid var(--entity-country); }
.graph-node.type-region       { border-left: 3px solid var(--entity-region); }
.graph-node.type-commodity    { border-left: 3px solid var(--entity-commodity); }

.graph-node.provisional {
    opacity: 0.7;
    border-style: dashed;
}

.graph-node-type-label {
    font-size: 8px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.graph-node-name {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
}

/* Button Variants (new names alongside old) */
.btn-primary {
    background: var(--accent-primary);
    color: var(--text-inverse);
    border-color: var(--accent-primary);
}

.btn-primary:hover {
    filter: brightness(1.1);
}

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

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

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}

.btn-ghost:hover {
    background: var(--bg-raised);
    color: var(--text-primary);
}

.btn-danger {
    background: transparent;
    color: var(--accent-danger);
    border-color: var(--accent-danger);
}

.btn-danger:hover {
    background: var(--accent-danger-muted);
}

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

@media (max-width: 1120px) {
    .workspace-shell {
        grid-template-columns: 300px minmax(0, 1fr);
    }

    .workspace-toolbar-row {
        flex-direction: column;
        align-items: stretch;
    }

    .workspace-status-row {
        justify-content: flex-start;
    }

    .ops-grid,
    .ops-stat-grid,
    .graph-workspace-grid {
        grid-template-columns: 1fr;
    }

    .graph-summary-grid {
        grid-template-columns: 1fr;
    }

    .graph-tool-result-grid,
    .graph-tool-two-column,
    .graph-tool-form,
    .graph-tool-temporal {
        grid-template-columns: 1fr;
    }

}

@media (max-width: 960px) {
    body {
        overflow: auto;
    }

    #app {
        height: auto;
    }

    .workspace-shell {
        grid-template-columns: 1fr;
        height: auto;
        overflow: visible;
    }

    .app-sidebar {
        position: static;
        top: auto;
        height: auto;
        min-height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .workspace-main.chat-workspace,
    .workspace-main.graph-workspace,
    .workspace-main.ops-workspace,
    catalog-workspace {
        height: auto;
        min-height: auto;
    }

    .message-scroller {
        overflow: visible;
    }

    :root {
        --assistant-max-width: 100%;
        --user-max-width: 100%;
    }
}

@media (max-width: 720px) {
    .sidebar-header.minimal,
    .project-header.minimal {
        padding-left: 18px;
        padding-right: 18px;
    }

    .sidebar-actions.minimal,
    .project-toolbar.minimal {
        padding-left: 18px;
        padding-right: 18px;
    }

    .sidebar-scroll {
        padding-left: 10px;
        padding-right: 10px;
    }

    .project-header.minimal,
    .project-toolbar.minimal,
    .message-list,
    .composer,
    .graph-page,
    .ops-page {
        width: min(100%, calc(100% - 28px));
    }

    .graph-page-layout {
        grid-template-columns: 1fr;
    }

    .message-scroller {
        padding-left: 14px;
        padding-right: 14px;
    }

    .message {
        max-width: 100%;
    }

    .document-meta-grid {
        grid-template-columns: 1fr;
    }

    .graph-signal-grid {
        grid-template-columns: 1fr;
    }

    .graph-canvas {
        height: 620px;
        min-height: 620px;
    }

    .graph-node-document {
        width: 220px;
    }

    .graph-node-entity,
    .graph-node-agent,
    .graph-node-keyword,
    .graph-node-project {
        width: 160px;
    }

    .retry-item {
        flex-direction: column;
    }

    .retry-item-actions {
        justify-content: flex-start;
    }

    .mode-rail {
        padding-left: 18px;
        padding-right: 18px;
    }

    .workspace-shell.mode-rail-shell {
        grid-template-columns: 66px minmax(0, 1fr);
    }

    .rail-only-sidebar .mode-rail {
        padding-left: 8px;
        padding-right: 8px;
    }

    .modal-backdrop {
        padding: 12px;
    }
}
