:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-tertiary: #1a2332;
    --bg-card: #151d2e;
    --bg-hover: #1e2a3f;
    --border: #2a3548;
    --border-light: #374151;
    --text-primary: #e5e7eb;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-glow: rgba(59, 130, 246, 0.15);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --purple: #8b5cf6;
    --sidebar-width: 300px;
    --detail-width: 340px;
    --toolbar-height: 68px;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    --transition: 0.2s ease;
}

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

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
}

#app {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 10;
}

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

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon { font-size: 28px; }

.logo h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.sidebar-section {
    padding: 16px;
    flex: 1;
    overflow-y: auto;
    border-bottom: 1px solid var(--border);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.section-header h2 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    font-weight: 600;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
}

.stats {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    gap: 16px;
}

/* Investigation list */
.investigation-list { display: flex; flex-direction: column; gap: 16px; }

.inv-empty-msg {
    color: var(--text-muted);
    font-size: 13px;
    padding: 8px;
}

.investigation-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.investigation-group-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: var(--radius);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.investigation-group.status-active .investigation-group-header {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
    border-left: 3px solid var(--success);
}

.investigation-group.status-closed .investigation-group-header {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border-left: 3px solid var(--danger);
}

.investigation-group.status-archived .investigation-group-header {
    background: rgba(107, 114, 128, 0.12);
    color: var(--text-muted);
    border-left: 3px solid var(--text-muted);
}

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

.investigation-group.status-active .group-status-dot {
    background: var(--success);
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
    animation: pulse-active 2s ease-in-out infinite;
}

.investigation-group.status-closed .group-status-dot {
    background: var(--danger);
    border-radius: 2px;
}

.investigation-group.status-archived .group-status-dot {
    background: var(--text-muted);
    transform: rotate(45deg);
    border-radius: 1px;
}

@keyframes pulse-active {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(0.85); }
}

.group-title { flex: 1; }

.group-count {
    font-size: 10px;
    padding: 2px 7px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.25);
    font-weight: 600;
}

.investigation-group-items {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.investigation-item {
    padding: 10px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
    border-left-width: 3px;
}

.investigation-item.status-active { border-left-color: rgba(16, 185, 129, 0.5); }
.investigation-item.status-closed { border-left-color: rgba(239, 68, 68, 0.5); }
.investigation-item.status-archived { border-left-color: rgba(107, 114, 128, 0.5); }

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

.investigation-item.active {
    background: var(--accent-glow);
    border-color: var(--accent);
    border-left-color: var(--accent);
}

.investigation-item.status-closed.active {
    background: rgba(239, 68, 68, 0.08);
    border-color: var(--danger);
    border-left-color: var(--danger);
}

.investigation-item.status-archived.active {
    background: rgba(107, 114, 128, 0.1);
    border-color: var(--text-muted);
    border-left-color: var(--text-muted);
}

.inv-header {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 4px;
}

.inv-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 5px;
}

.investigation-item.status-active .inv-status-dot {
    background: var(--success);
    box-shadow: 0 0 6px rgba(16, 185, 129, 0.5);
}

.investigation-item.status-closed .inv-status-dot {
    background: var(--danger);
    border-radius: 2px;
}

.investigation-item.status-archived .inv-status-dot {
    background: var(--text-muted);
    transform: rotate(45deg);
    border-radius: 1px;
}

.inv-title-row {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.investigation-item .inv-title {
    font-size: 14px;
    font-weight: 500;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.inv-status-badge {
    flex-shrink: 0;
    font-size: 9px !important;
    padding: 2px 7px !important;
}

.investigation-item .inv-meta {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-left: 16px;
}

/* Entity list */
.search-box { margin-bottom: 12px; }

.search-box input {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
    transition: var(--transition);
}

.search-box input:focus { border-color: var(--accent); }

.entity-filters-wrap {
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-tertiary);
    overflow: hidden;
}

.entity-filters-wrap.collapsed .entity-filters {
    display: none;
}

.entity-filters-wrap.collapsed .entity-filters-chevron {
    transform: rotate(-90deg);
}

.entity-filters-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: var(--transition);
}

.entity-filters-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.entity-filters-toggle-label {
    flex: 1;
    text-align: left;
}

.entity-filters-badge {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: rgba(59, 130, 246, 0.25);
    color: #93c5fd;
    font-size: 10px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.entity-filters-chevron {
    font-size: 12px;
    transition: transform 0.2s ease;
    color: var(--text-muted);
}

.entity-filters {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0 10px 10px;
}

.entity-filters-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.entity-filters-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    font-weight: 600;
}

.entity-filters-clear {
    border: none;
    background: transparent;
    color: var(--accent);
    font-size: 11px;
    cursor: pointer;
    padding: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.entity-filters-clear.visible {
    opacity: 1;
    pointer-events: auto;
}

.entity-filters-clear:hover {
    text-decoration: underline;
}

.entity-filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.entity-filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 9px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
    transition: var(--transition);
    line-height: 1;
}

.entity-filter-chip:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.entity-filter-chip.active {
    background: rgba(59, 130, 246, 0.2);
    border-color: var(--accent);
    color: #fff;
}

.entity-filter-chip .chip-icon {
    font-size: 13px;
}

.entity-filter-chip .chip-count {
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.25);
    font-size: 10px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.entity-filter-chip.active .chip-count {
    background: rgba(59, 130, 246, 0.45);
}

.entity-list { display: flex; flex-direction: column; gap: 2px; }

.entity-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    font-size: 13px;
}

.entity-item:hover { background: var(--bg-hover); }
.entity-item.selected {
    background: rgba(59, 130, 246, 0.24);
    border-left: 3px solid var(--accent);
    box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.45);
    padding-left: 7px;
}
.entity-item.selected .entity-label {
    color: #fff;
    font-weight: 600;
}
.entity-item.selected .entity-type {
    color: #93c5fd;
}

.entity-item .entity-icon { font-size: 16px; }
.entity-item .entity-thumb {
    width: 22px;
    height: 22px;
    border-radius: 4px;
    object-fit: cover;
    flex-shrink: 0;
}
.entity-item .entity-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entity-item .entity-type { font-size: 10px; color: var(--text-muted); text-transform: uppercase; }

/* Main content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    min-height: 0;
    min-width: 0;
}

.toolbar {
    height: var(--toolbar-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    flex-shrink: 0;
}

.toolbar-left { display: flex; align-items: center; gap: 12px; }
.toolbar-left h2 { font-size: 16px; font-weight: 600; }

.toolbar-title-group {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.toolbar-title-group h2 {
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-edit-investigation {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px 8px 14px;
    border: 1px solid var(--border-light);
    border-radius: 22px;
    background: linear-gradient(180deg, rgba(59, 130, 246, 0.08) 0%, rgba(59, 130, 246, 0.02) 100%);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
    min-height: 40px;
}

.btn-edit-investigation:hover {
    color: var(--accent);
    border-color: rgba(59, 130, 246, 0.45);
    background: linear-gradient(180deg, rgba(59, 130, 246, 0.16) 0%, rgba(59, 130, 246, 0.06) 100%);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn-edit-investigation:active {
    transform: scale(0.97);
}

.btn-edit-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.85;
}

.btn-edit-investigation:hover .btn-edit-icon {
    opacity: 1;
}

.toolbar-right { display: flex; gap: 10px; align-items: center; }

.toolbar-history {
    display: flex;
    gap: 6px;
}

.btn-history {
    padding: 11px 14px;
    white-space: nowrap;
}

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

.badge {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
}

.badge.archived { background: rgba(107, 114, 128, 0.15); color: var(--text-muted); }
.badge.closed { background: rgba(239, 68, 68, 0.15); color: var(--danger); }

/* Investigation summary */
.investigation-summary {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.investigation-summary.collapsed .summary-body { display: none; }
.investigation-summary.collapsed .btn-summary-toggle { transform: rotate(-90deg); }

.summary-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px 0;
}

.summary-header h3 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    font-weight: 600;
}

.summary-body { padding: 12px 20px 16px; }

.summary-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

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

.summary-table th {
    width: 160px;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 12px;
}

.summary-table td { color: var(--text-primary); }

.summary-table tr:last-child th,
.summary-table tr:last-child td { border-bottom: none; }

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

/* Welcome screen */
.welcome-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at center, var(--bg-tertiary) 0%, var(--bg-primary) 70%);
}

.welcome-content { text-align: center; max-width: 500px; padding: 40px; }

.welcome-icon { font-size: 64px; margin-bottom: 24px; }
.welcome-content h2 { font-size: 28px; margin-bottom: 12px; font-weight: 700; }
.welcome-content p { color: var(--text-secondary); margin-bottom: 32px; line-height: 1.6; }

.welcome-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
    margin-bottom: 32px;
}

.features {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 40px;
}

.feature {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    padding: 12px;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.feature-icon { font-size: 20px; }

/* Graph */
.graph-container.hidden { display: none !important; }

.graph-container {
    flex: 1 1 0;
    position: relative;
    background:
        radial-gradient(circle at center, rgba(59, 130, 246, 0.03) 0%, transparent 70%),
        repeating-linear-gradient(0deg, transparent, transparent 49px, rgba(42, 53, 72, 0.4) 49px, rgba(42, 53, 72, 0.4) 50px),
        repeating-linear-gradient(90deg, transparent, transparent 49px, rgba(42, 53, 72, 0.4) 49px, rgba(42, 53, 72, 0.4) 50px),
        var(--bg-primary);
    min-height: 0;
    overflow: hidden;
}

#network-graph {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.graph-empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 1;
}

.graph-empty-content {
    text-align: center;
    color: var(--text-muted);
    padding: 24px;
}

.graph-empty-content .empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }
.graph-empty-content p { font-size: 14px; line-height: 1.6; }

.link-mode-active .btn-accent {
    box-shadow: 0 0 0 2px var(--purple), 0 0 16px rgba(139, 92, 246, 0.4);
    animation: pulse-link 1.5s infinite;
}

@keyframes pulse-link {
    0%, 100% { box-shadow: 0 0 0 2px var(--purple), 0 0 8px rgba(139, 92, 246, 0.3); }
    50% { box-shadow: 0 0 0 2px var(--purple), 0 0 20px rgba(139, 92, 246, 0.6); }
}

.link-mode-hint {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--purple);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    z-index: 5;
    display: none;
    box-shadow: var(--shadow);
}

.link-mode-hint.visible { display: block; }

.graph-legend {
    position: absolute;
    bottom: 16px;
    left: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    font-size: 11px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 420px;
}

.legend-section {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.legend-divider {
    height: 1px;
    background: var(--border);
}

.legend-confidence .legend-item { font-size: 10px; }

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--text-secondary);
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

/* Detail panel */
.detail-panel {
    width: var(--detail-width);
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 10;
}

.detail-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.detail-header h3 { font-size: 15px; font-weight: 600; }

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

.detail-actions {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
}

.detail-field { margin-bottom: 16px; }

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

.detail-field .value {
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.detail-field .value.mono {
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    font-size: 13px;
    background: var(--bg-tertiary);
    padding: 8px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.confidence-badge {
    display: inline-block;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

.confidence-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1.5px solid rgba(0, 0, 0, 0.4);
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
}

.confidence-value {
    display: flex;
    align-items: center;
    gap: 8px;
}

.field-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 6px;
}

.field-label-row label {
    margin-bottom: 0;
}

.field-with-confidence > input,
.field-with-confidence > select,
.field-with-confidence > textarea {
    width: 100%;
}

.field-confidence-picker {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
}

.fc-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid transparent;
    padding: 0;
    cursor: pointer;
    opacity: 0.45;
    transition: opacity 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}

.fc-dot:hover {
    opacity: 0.85;
    transform: scale(1.08);
}

.fc-dot.active {
    opacity: 1;
    border-color: #fff;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.confidence-preview {
    padding: 8px 0;
}

.confidence-badge.low { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.confidence-badge.medium { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.confidence-badge.high { background: rgba(59, 130, 246, 0.15); color: var(--accent); }
.confidence-badge.confirmed { background: rgba(16, 185, 129, 0.15); color: var(--success); }

.tag-list { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }

.tag {
    font-size: 11px;
    padding: 2px 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-secondary);
}

.relation-list { margin-top: 8px; }

.relation-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    margin-bottom: 4px;
    font-size: 12px;
    transition: var(--transition);
    border-left: 3px solid transparent;
}

.relation-item.selected {
    background: rgba(59, 130, 246, 0.24);
    border-left-color: var(--accent);
    box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.45);
}

.relation-item.selected .relation-label {
    color: #fff;
    font-weight: 600;
}

.relation-item.selected .relation-arrow {
    color: #93c5fd;
    font-size: 14px;
}

.relation-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    min-width: 0;
}

.relation-info:hover { color: var(--accent); }

.relation-label { font-weight: 500; }

.relation-target {
    color: var(--text-muted);
    cursor: pointer;
    text-decoration: underline;
    text-decoration-color: transparent;
    transition: var(--transition);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.relation-target:hover {
    color: var(--accent);
    text-decoration-color: var(--accent);
}

.relation-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.btn-icon-sm {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

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

.btn-icon-danger:hover {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.entity-link {
    cursor: pointer;
    color: var(--accent);
}

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

.relation-arrow { color: var(--accent); font-weight: bold; flex-shrink: 0; }

.detail-field-highlight {
    padding: 12px;
    border-radius: var(--radius);
    background: rgba(59, 130, 246, 0.14);
    border: 1px solid rgba(59, 130, 246, 0.35);
}

.relation-selected-summary {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    font-weight: 600;
    color: #fff;
}

.relation-selected-node {
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(59, 130, 246, 0.25);
    border: 1px solid rgba(96, 165, 250, 0.5);
}

.relation-selected-arrow {
    color: #93c5fd;
    font-size: 18px;
    font-weight: 700;
}

.graph-container.edge-bend-active {
    cursor: grabbing;
}

.graph-container.edge-bend-active #network-graph canvas {
    cursor: grabbing;
}

/* Buttons */
.btn {
    padding: 11px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    min-height: 42px;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-accent { background: var(--purple); color: white; }
.btn-accent:hover { background: #7c3aed; }

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

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }

.btn-lg { padding: 16px 40px; font-size: 18px; min-height: 52px; }

.btn-icon {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}

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

.btn-sm { padding: 8px 14px; font-size: 14px; min-height: 36px; }

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

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 520px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
}

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

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

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Forms */
.form-group { margin-bottom: 16px; }

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

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

.form-group textarea { resize: vertical; min-height: 80px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.person-fields-section,
.type-fields-section {
    margin: 4px 0 12px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-secondary);
}
.person-fields-title,
.type-fields-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}
.person-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 16px;
}
.person-detail-item { display: flex; flex-direction: column; gap: 2px; }
.person-detail-label { font-size: 11px; color: var(--text-muted); }
.person-detail-value { font-size: 13px; color: var(--text-primary); display: flex; align-items: center; gap: 6px; }

.input-readonly {
    background: var(--bg-primary);
    color: var(--text-secondary);
    cursor: default;
}

.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

.file-input {
    margin-top: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.image-preview {
    position: relative;
    background: var(--bg-tertiary);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 12px;
    text-align: center;
    margin-bottom: 8px;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-preview.empty .preview-placeholder {
    color: var(--text-muted);
    font-size: 13px;
}

.image-preview img {
    max-width: 100%;
    max-height: 160px;
    border-radius: 6px;
    object-fit: contain;
}

.photo-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 8px;
    margin-bottom: 10px;
    min-height: 60px;
}

.photo-gallery.empty {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.photo-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--radius);
    overflow: hidden;
    border: 2px solid var(--border);
    background: var(--bg-tertiary);
}

.photo-item.is-primary {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.photo-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
}

.file-preview-trigger {
    border: none;
    padding: 0;
    margin: 0;
    background: transparent;
    cursor: zoom-in;
    width: 100%;
    height: 100%;
    display: block;
}

.file-image-trigger {
    position: absolute;
    inset: 0;
}

.file-preview-overlay {
    position: fixed;
    inset: 0;
    z-index: 11000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.file-preview-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.82);
    backdrop-filter: blur(4px);
}

.file-preview-panel {
    position: relative;
    z-index: 1;
    width: min(1100px, 96vw);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
    overflow: hidden;
}

.file-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

.file-preview-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin: 0;
}

.file-preview-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.file-preview-body {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0a0e17;
    padding: 16px;
}

.file-preview-image {
    max-width: 100%;
    max-height: calc(92vh - 90px);
    object-fit: contain;
    border-radius: 6px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
}

.file-preview-pdf {
    width: 100%;
    height: calc(92vh - 90px);
    min-height: 420px;
    border: none;
    border-radius: 6px;
    background: #fff;
}

.photo-actions {
    position: absolute;
    top: 4px;
    right: 4px;
    display: flex;
    gap: 2px;
}

.photo-actions button {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.photo-actions button:hover { background: rgba(0, 0, 0, 0.9); }

.btn-photo-primary { color: #fbbf24 !important; }

.photo-badge {
    position: absolute;
    bottom: 4px;
    left: 4px;
    background: var(--accent);
    color: white;
    font-size: 9px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
}

.file-item-pdf {
    min-height: 88px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
}

.file-pdf-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    height: 100%;
    min-height: 88px;
    padding: 10px 8px 22px;
    color: var(--text-primary);
    text-align: center;
    cursor: zoom-in;
}

.file-pdf-icon {
    font-size: 28px;
    line-height: 1;
}

.file-pdf-name {
    font-size: 10px;
    text-align: center;
    word-break: break-all;
    line-height: 1.3;
    max-width: 100%;
}

.file-badge-pdf {
    background: #ef4444;
}

.detail-photos .photo-gallery {
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
}

.pending-preview { margin-top: 6px; }

.frame-preview {
    margin-top: 8px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 12px;
    color: var(--text-secondary);
}

.frame-preview-label {
    color: var(--text-muted);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-right: 6px;
}

.frame-fields-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin: 8px 0;
    padding: 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.frame-field-check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 2px;
}

.frame-field-check input {
    accent-color: var(--accent);
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.frame-field-check:hover { color: var(--text-primary); }

.btn-remove-image {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(239, 68, 68, 0.9);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    min-height: 32px;
}

.btn-remove-image:hover { background: var(--danger); }

.detail-photo {
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
}

.detail-photo img {
    width: 100%;
    max-height: 200px;
    object-fit: contain;
    display: block;
}

/* Toast */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    box-shadow: var(--shadow);
    animation: slideIn 0.3s ease;
    max-width: 360px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }

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

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* Graph tooltips (custom HTML, replaces vis.js default) */
div.vis-tooltip {
    display: none !important;
    visibility: hidden !important;
}

.graph-tooltip {
    position: fixed;
    z-index: 10000;
    pointer-events: none;
    opacity: 0;
    transform: translateY(6px) scale(0.98);
    transition: opacity 0.15s ease, transform 0.15s ease;
    max-width: min(320px, calc(100vw - 24px));
}

.graph-tooltip.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.graph-tooltip-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.04);
    overflow: hidden;
    font-size: 12px;
    backdrop-filter: blur(8px);
}

.graph-tooltip-accent {
    height: 3px;
}

.graph-tooltip-header {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px 10px;
}

.graph-tooltip-icon {
    font-size: 22px;
    line-height: 1;
    flex-shrink: 0;
}

.graph-tooltip-head-text {
    min-width: 0;
    flex: 1;
}

.graph-tooltip-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.3;
    word-break: break-word;
}

.graph-tooltip-type {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 3px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.graph-tooltip-body {
    padding: 8px 14px 10px;
    border-top: 1px solid var(--border);
}

.graph-tooltip-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
    padding: 4px 0;
    line-height: 1.35;
}

.graph-tooltip-row + .graph-tooltip-row {
    border-top: 1px solid rgba(42, 53, 72, 0.5);
}

.graph-tooltip-label {
    color: var(--text-muted);
    flex-shrink: 0;
    font-size: 11px;
}

.graph-tooltip-value {
    color: var(--text-primary);
    text-align: right;
    word-break: break-word;
    font-size: 12px;
}

.graph-tooltip-footer {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 8px 14px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-secondary);
}

.graph-tooltip-confidence-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 6px currentColor;
}

/* Responsive */
@media (max-width: 1024px) {
    .detail-panel { display: none !important; }
    .sidebar { width: 260px; }
}

@media (max-width: 768px) {
    .sidebar { width: 100%; position: absolute; z-index: 20; }
    .features { grid-template-columns: 1fr; }
}

/* History page */
body.history-page {
    overflow: auto;
    height: auto;
    min-height: 100vh;
    background: var(--bg-primary);
}

#history-app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.history-header {
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
    border-bottom: 1px solid var(--border);
    padding: 20px 32px 28px;
    flex-shrink: 0;
}

.history-header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.history-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--accent);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    padding: 8px 14px;
    border-radius: var(--radius);
    background: var(--accent-glow);
    border: 1px solid rgba(59, 130, 246, 0.2);
    transition: all var(--transition);
}

.history-back:hover {
    background: rgba(59, 130, 246, 0.22);
    transform: translateX(-2px);
}

.history-back-icon { font-size: 16px; }

.history-count {
    font-size: 13px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.history-hero {
    display: flex;
    align-items: center;
    gap: 18px;
    margin-bottom: 24px;
}

.history-hero-icon {
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    flex-shrink: 0;
}

.history-hero h1 {
    font-size: 26px;
    font-weight: 700;
    margin-bottom: 4px;
    letter-spacing: -0.3px;
}

.history-hero p {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.history-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    max-width: 520px;
}

.history-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 14px 16px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: var(--bg-card);
}

.history-stat-value {
    font-size: 28px;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

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

.history-stat-add .history-stat-value { color: var(--success); }
.history-stat-edit .history-stat-value { color: var(--accent); }
.history-stat-remove .history-stat-value { color: var(--danger); }

.history-stat-add { border-color: rgba(16, 185, 129, 0.25); background: rgba(16, 185, 129, 0.06); }
.history-stat-edit { border-color: rgba(59, 130, 246, 0.25); background: rgba(59, 130, 246, 0.06); }
.history-stat-remove { border-color: rgba(239, 68, 68, 0.25); background: rgba(239, 68, 68, 0.06); }

.history-toolbar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px 32px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.history-search { width: 100%; max-width: none; }

.history-chip-filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.history-chip {
    padding: 7px 14px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.history-chip:hover {
    border-color: var(--border-light);
    color: var(--text-primary);
}

.history-chip.active {
    color: var(--text-primary);
    border-color: var(--accent);
    background: var(--accent-glow);
}

.history-chip-add.active { border-color: var(--success); background: rgba(16, 185, 129, 0.12); color: var(--success); }
.history-chip-edit.active { border-color: var(--accent); background: rgba(59, 130, 246, 0.12); color: var(--accent); }
.history-chip-remove.active { border-color: var(--danger); background: rgba(239, 68, 68, 0.12); color: var(--danger); }

.history-toolbar-row {
    display: flex;
    gap: 10px;
    align-items: center;
}

.history-select {
    flex: 1;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 9px 12px;
    font-size: 13px;
    min-width: 0;
}

.btn-sm { padding: 9px 14px; font-size: 14px; }

.history-main {
    flex: 1;
    padding: 28px 32px 48px;
    max-width: 860px;
    width: 100%;
    margin: 0 auto;
}

.history-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 80px 20px;
    color: var(--text-secondary);
    font-size: 14px;
}

.history-loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: history-spin 0.8s linear infinite;
}

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

.history-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 80px 24px;
    color: var(--text-secondary);
}

.history-empty-icon { font-size: 52px; margin-bottom: 16px; opacity: 0.7; }
.history-empty h2 { font-size: 20px; margin-bottom: 10px; color: var(--text-primary); font-weight: 600; }
.history-empty p { max-width: 380px; line-height: 1.6; font-size: 14px; }

.history-date-group { margin-bottom: 36px; }

.history-date-sticky {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border);
}

.history-date-label {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    text-transform: capitalize;
}

.history-date-count {
    font-size: 12px;
    color: var(--text-muted);
}

.history-date-entries {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.history-entry {
    display: grid;
    grid-template-columns: 20px 72px 1fr;
    gap: 0 16px;
    position: relative;
    padding-bottom: 20px;
}

.history-entry-rail {
    display: flex;
    justify-content: center;
    position: relative;
}

.history-entry-rail::after {
    content: '';
    position: absolute;
    top: 14px;
    bottom: -6px;
    left: 50%;
    width: 2px;
    transform: translateX(-50%);
    background: var(--border);
}

.history-entry-last .history-entry-rail::after { display: none; }

.history-entry-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-top: 6px;
    z-index: 1;
    border: 2px solid var(--bg-primary);
    flex-shrink: 0;
}

.history-dot-add { background: var(--success); box-shadow: 0 0 8px rgba(16, 185, 129, 0.5); }
.history-dot-edit { background: var(--accent); box-shadow: 0 0 8px rgba(59, 130, 246, 0.5); }
.history-dot-remove { background: var(--danger); box-shadow: 0 0 8px rgba(239, 68, 68, 0.5); }

.history-entry-timecol {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-top: 2px;
    text-align: right;
}

.history-entry-time {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.history-entry-relative {
    font-size: 11px;
    color: var(--text-muted);
}

.history-entry-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.history-entry-card:hover {
    border-color: var(--border-light);
    box-shadow: var(--shadow);
}

.history-entry-add .history-entry-card { border-left: 3px solid var(--success); }
.history-entry-edit .history-entry-card { border-left: 3px solid var(--accent); }
.history-entry-remove .history-entry-card { border-left: 3px solid var(--danger); }

.history-entry-card-header {
    display: flex;
    gap: 14px;
    align-items: flex-start;
}

.history-entry-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    font-size: 18px;
    flex-shrink: 0;
}

.history-icon-add { background: rgba(16, 185, 129, 0.12); }
.history-icon-edit { background: rgba(59, 130, 246, 0.12); }
.history-icon-remove { background: rgba(239, 68, 68, 0.12); }

.history-entry-titles { flex: 1; min-width: 0; }

.history-verb {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 3px 8px;
    border-radius: 4px;
    margin-bottom: 6px;
}

.history-verb-add { background: rgba(16, 185, 129, 0.15); color: var(--success); }
.history-verb-edit { background: rgba(59, 130, 246, 0.15); color: var(--accent); }
.history-verb-remove { background: rgba(239, 68, 68, 0.15); color: var(--danger); }

.history-entry-headline {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.45;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.history-entry-headline strong { color: #fff; font-weight: 700; }

.history-entry-subline {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.history-changes-details {
    margin-top: 12px;
    border-top: 1px solid var(--border);
    padding-top: 10px;
}

.history-changes-details summary {
    font-size: 12px;
    color: var(--accent);
    cursor: pointer;
    font-weight: 500;
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
}

.history-changes-details summary::before {
    content: '▸';
    font-size: 10px;
    transition: transform var(--transition);
}

.history-changes-details[open] summary::before { transform: rotate(90deg); }

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

.history-changes {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-change-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    font-size: 13px;
}

.history-change-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.history-change-diff {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.history-change-old {
    color: var(--danger);
    text-decoration: line-through;
    opacity: 0.85;
    word-break: break-word;
}

.history-change-arrow { color: var(--text-muted); font-size: 12px; }

.history-change-new {
    color: var(--success);
    font-weight: 500;
    word-break: break-word;
}

.history-change-added .history-change-value { color: var(--success); font-weight: 500; }
.history-change-removed .history-change-value { color: var(--danger); text-decoration: line-through; }

.history-change-hint {
    font-size: 11px;
    color: var(--text-muted);
    font-style: italic;
}

.history-entry-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-muted);
}

.history-footer-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.history-footer-icon { font-size: 13px; opacity: 0.8; }

.history-user-unknown { font-style: italic; }

.history-load-more {
    display: flex;
    justify-content: center;
    padding: 24px 0 8px;
}

@media (max-width: 768px) {
    .history-header,
    .history-toolbar,
    .history-main { padding-left: 16px; padding-right: 16px; }

    .history-stats { max-width: none; }

    .history-entry {
        grid-template-columns: 16px 1fr;
        grid-template-rows: auto auto;
    }

    .history-entry-timecol {
        grid-column: 2;
        flex-direction: row;
        gap: 8px;
        text-align: left;
        padding-bottom: 6px;
    }

    .history-entry-card { grid-column: 2; }

    .history-entry-rail { grid-row: 1 / 3; }

    .history-toolbar-row { flex-wrap: wrap; }
}
