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

:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: #1a2035;
    --bg-card-hover: #1f2a40;
    --bg-input: #0f1629;
    --border: #1e2a45;
    --border-hover: #2a3a5c;
    --text-primary: #e8edf5;
    --text-secondary: #8892a8;
    --text-muted: #5a6478;
    --accent: #00d4aa;
    --accent-dim: #009e7e;
    --blue: #3b82f6;
    --purple: #8b5cf6;
    --red: #ef4444;
    --orange: #f59e0b;
    --green: #10b981;
    --verified: #10b981;
    --corroborated: #f59e0b;
    --unverified: #ef4444;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 4px;
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.4);
}

html { font-size: 15px; }
body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: #00ffd0; }

/* ── Layout ──────────────────────────────────────────────────────────── */
.layout {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────────────────── */
.sidebar {
    width: 260px;
    flex-shrink: 0;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 8px 24px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}
.brand-icon { font-size: 28px; }
.brand-text { display: flex; flex-direction: column; }
.brand-title {
    font-weight: 800;
    font-size: 1.1rem;
    letter-spacing: 3px;
    color: var(--text-primary);
}
.brand-sub {
    font-size: 0.7rem;
    color: var(--text-muted);
    letter-spacing: 1px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 24px;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.15s;
}
.nav-item:hover {
    background: var(--bg-card);
    color: var(--text-primary);
}
.nav-item.active {
    background: rgba(0, 212, 170, 0.1);
    color: var(--accent);
}
.nav-icon { font-size: 1.1rem; }

.sidebar-search {
    margin-top: auto;
    padding: 16px 0;
    border-top: 1px solid var(--border);
}
.search-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    outline: none;
    transition: border 0.2s;
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { border-color: var(--accent-dim); }

.sidebar-footer {
    padding-top: 12px;
    border-top: 1px solid var(--border);
}
.footer-text {
    font-size: 0.7rem;
    color: var(--text-muted);
    letter-spacing: 1px;
}
.footer-admin {
    display: block;
    margin-top: 4px;
    font-size: 0.65rem;
    color: var(--orange);
    letter-spacing: 1px;
}

/* ── Main Content ────────────────────────────────────────────────────── */
.main-content {
    flex: 1;
    padding: 32px 40px;
    max-width: 1200px;
}

/* ── Dashboard Stats ─────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 40px;
}
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    transition: border 0.2s;
}
.stat-card:hover { border-color: var(--border-hover); }
.stat-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--accent);
    font-family: var(--font-mono);
}
.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-top: 4px;
}

/* ── Page Header ─────────────────────────────────────────────────────── */
.page-header {
    margin-bottom: 32px;
}
.page-title {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 4px;
}
.page-sub {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* ── Operations List ─────────────────────────────────────────────────── */
.section-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-secondary);
}

.ops-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.op-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.15s;
    cursor: pointer;
}
.op-card:hover {
    border-color: var(--accent-dim);
    background: var(--bg-card-hover);
    transform: translateX(4px);
}
.op-card-left {
    display: flex;
    align-items: center;
    gap: 16px;
}
.op-card-icon {
    width: 40px;
    height: 40px;
    background: rgba(0, 212, 170, 0.1);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}
.op-card-name {
    font-weight: 600;
    font-size: 1rem;
}
.op-card-meta {
    display: flex;
    gap: 12px;
    margin-top: 3px;
}
.op-card-date {
    font-size: 0.8rem;
    color: var(--text-muted);
}
.op-card-tag {
    font-size: 0.7rem;
    padding: 1px 8px;
    border-radius: 99px;
    background: rgba(139, 92, 246, 0.15);
    color: var(--purple);
}
.op-card-right {
    display: flex;
    align-items: center;
    gap: 12px;
}
.op-card-badge {
    font-size: 0.75rem;
    padding: 3px 10px;
    border-radius: 99px;
    background: rgba(16, 185, 129, 0.15);
    color: var(--green);
    font-weight: 500;
    text-transform: capitalize;
}
.status-completed { background: rgba(16, 185, 129, 0.15); color: var(--green); }
.status-pending { background: rgba(245, 158, 11, 0.15); color: var(--orange); }
.status-in_progress { background: rgba(59, 130, 246, 0.15); color: var(--blue); }
.op-card-arrow {
    color: var(--text-muted);
    font-size: 1.2rem;
}

/* ── Operation Detail ────────────────────────────────────────────────── */
.op-header {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 32px;
    margin-bottom: 28px;
}
.op-header-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
}
.op-header-name {
    font-size: 1.8rem;
    font-weight: 700;
}
.op-header-context {
    margin-top: 6px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}
.op-header-meta {
    text-align: right;
    flex-shrink: 0;
}
.op-header-date {
    font-size: 0.85rem;
    color: var(--text-muted);
}
.op-header-tags {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.tag {
    font-size: 0.7rem;
    padding: 3px 10px;
    border-radius: 99px;
    background: rgba(139, 92, 246, 0.15);
    color: var(--purple);
    font-weight: 500;
}

/* ── Trait Sections ──────────────────────────────────────────────────── */
.trait-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 20px;
    overflow: hidden;
}
.trait-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}
.trait-icon {
    font-size: 1.2rem;
}
.trait-name {
    font-weight: 600;
    font-size: 1.05rem;
}
.trait-count {
    margin-left: auto;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}
.trait-findings {
    padding: 8px 0;
}
.finding-item {
    padding: 12px 24px;
    border-bottom: 1px solid rgba(30, 42, 69, 0.4);
    display: flex;
    align-items: flex-start;
    gap: 12px;
}
.finding-item:last-child { border-bottom: none; }
.finding-cred {
    flex-shrink: 0;
    width: 24px;
    text-align: center;
    margin-top: 2px;
}
.finding-cred.verified { color: var(--verified); }
.finding-cred.corroborated { color: var(--corroborated); }
.finding-cred.unverified { color: var(--unverified); }
.finding-body {
    flex: 1;
    min-width: 0;
}
.finding-fact {
    font-size: 0.9rem;
    line-height: 1.5;
}
.finding-notes {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
    font-style: italic;
}
.finding-sources {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}
.source-link {
    font-size: 0.75rem;
    padding: 2px 10px;
    border-radius: 99px;
    background: rgba(59, 130, 246, 0.1);
    color: var(--blue);
    border: 1px solid rgba(59, 130, 246, 0.2);
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.source-link:hover {
    background: rgba(59, 130, 246, 0.2);
    border-color: var(--blue);
}

/* ── Contradictions ──────────────────────────────────────────────────── */
.contradiction-block {
    background: rgba(239, 68, 68, 0.05);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: var(--radius);
    padding: 20px 24px;
    margin-bottom: 20px;
}
.contradiction-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: var(--red);
    margin-bottom: 12px;
}
.contradiction-item {
    padding: 8px 0;
    border-bottom: 1px solid rgba(239, 68, 68, 0.1);
}
.contradiction-item:last-child { border-bottom: none; }
.contradiction-desc { font-size: 0.9rem; }
.contradiction-sides {
    display: flex;
    gap: 16px;
    margin-top: 6px;
    font-size: 0.8rem;
}
.contradiction-sides span {
    padding: 3px 10px;
    border-radius: var(--radius-xs);
    background: rgba(255,255,255,0.04);
}

/* ── Queries ─────────────────────────────────────────────────────────── */
.queries-block {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    margin-bottom: 20px;
}
.queries-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-secondary);
}
.query-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 8px;
}
.query-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-family: var(--font-mono);
    color: var(--text-secondary);
}
.query-trait {
    font-size: 0.65rem;
    padding: 1px 6px;
    border-radius: 3px;
    background: rgba(0, 212, 170, 0.15);
    color: var(--accent);
    text-transform: uppercase;
    flex-shrink: 0;
}

/* ── Search Page ─────────────────────────────────────────────────────── */
.search-hero {
    text-align: center;
    padding: 60px 20px 40px;
}
.search-hero h1 { font-size: 2.2rem; font-weight: 700; }
.search-hero p { color: var(--text-secondary); margin-top: 6px; }

.search-box-wrap {
    max-width: 600px;
    margin: 24px auto;
}
.search-box {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    color: var(--text-primary);
    font-size: 1.05rem;
    font-family: var(--font-sans);
    outline: none;
    transition: border 0.2s;
}
.search-box:focus { border-color: var(--accent); }

.search-results { margin-top: 32px; }
.search-result-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 22px;
    margin-bottom: 12px;
    transition: border 0.15s;
}
.search-result-item:hover { border-color: var(--border-hover); }
.search-result-type {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.search-result-title {
    font-weight: 600;
    font-size: 1rem;
}
.search-result-snippet {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.15s;
}
.btn-primary {
    background: var(--accent);
    color: #0a0e17;
}
.btn-primary:hover {
    background: #00ffd0;
    transform: translateY(-1px);
}

/* ── Dashboard Controls ─────────────────────────────────────────────── */
.dash-controls {
    margin-bottom: 20px;
}
.dash-filter-row {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}
.dash-search-input {
    flex: 1;
    min-width: 200px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    outline: none;
    transition: border 0.2s;
}
.dash-search-input::placeholder { color: var(--text-muted); }
.dash-search-input:focus { border-color: var(--accent-dim); }
.dash-select {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
}
.dash-select:focus { border-color: var(--accent-dim); }
.dash-badge-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    flex-wrap: wrap;
}
.dash-badge-label {
    font-size: 0.8rem;
    color: var(--text-muted);
}
.dash-badge {
    font-size: 0.75rem;
    padding: 4px 14px;
    border-radius: 99px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--font-sans);
}
.dash-badge:hover { border-color: var(--accent-dim); color: var(--accent); }
.dash-badge.active {
    background: rgba(0, 212, 170, 0.15);
    border-color: var(--accent);
    color: var(--accent);
}
.dash-footer-info {
    margin-top: 20px;
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 12px;
}
.btn-link {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    padding: 0;
}
.btn-link:hover { color: #00ffd0; }

/* ── Breadcrumb ──────────────────────────────────────────────────────── */
.breadcrumb {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    font-size: 0.85rem;
}

/* ── Admin Modal ─────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}
.modal-box {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 32px;
    width: 380px;
    max-width: 90vw;
    box-shadow: var(--shadow-lg);
}
.modal-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}
.modal-icon { font-size: 1.4rem; }
.modal-title {
    font-weight: 600;
    font-size: 1.1rem;
}
.modal-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
}
.modal-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 1rem;
    outline: none;
    margin-bottom: 16px;
    letter-spacing: 4px;
}
.modal-input:focus { border-color: var(--red); }
.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}
.modal-error {
    margin-top: 12px;
    font-size: 0.85rem;
    color: var(--red);
}
.btn-secondary {
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--border-hover); color: var(--text-primary); }
.btn-danger {
    background: var(--red);
    color: white;
}
.btn-danger:hover {
    background: #dc2626;
}
.btn-danger-outline {
    background: transparent;
    color: var(--red);
    border: 1px solid rgba(239, 68, 68, 0.3);
}
.btn-danger-outline:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--red);
}
.btn-sm {
    padding: 5px 14px;
    font-size: 0.8rem;
}

/* ── Trait Delete Button ────────────────────────────────────────────── */
.btn-trait-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 4px 8px;
    border-radius: var(--radius-xs);
    transition: all 0.15s;
    margin-left: auto;
}
.btn-trait-delete:hover {
    background: rgba(239, 68, 68, 0.15);
    color: var(--red);
}

.op-header-status {
    display: inline-block;
    font-size: 0.75rem;
    padding: 3px 10px;
    border-radius: 99px;
    font-weight: 500;
    margin-top: 4px;
    text-transform: capitalize;
}

.finding-empty {
    padding: 20px 24px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ── 404 ─────────────────────────────────────────────────────────────── */
.error-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    text-align: center;
}
.error-code { font-size: 5rem; font-weight: 800; font-family: var(--font-mono); color: var(--accent); }
.error-text { font-size: 1.1rem; color: var(--text-secondary); margin: 8px 0 24px; }

/* ── Search highlight ────────────────────────────────────────────────── */
mark {
    background: rgba(0, 212, 170, 0.2);
    color: var(--accent);
    padding: 0 3px;
    border-radius: 2px;
}

/* ── Target View ─────────────────────────────────────────────────────── */
.target-header {
    margin-bottom: 28px;
}
.target-name {
    font-size: 1.8rem;
    font-weight: 700;
}

/* ── Empty State ─────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state-text { font-size: 0.95rem; }

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
    .layout { flex-direction: column; }
    .sidebar {
        width: 100%;
        height: auto;
        position: static;
        padding: 16px;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 12px;
    }
    .sidebar-brand { border-bottom: none; margin-bottom: 0; padding: 0; }
    .sidebar-nav { flex-direction: row; margin-bottom: 0; }
    .sidebar-search { margin-top: 0; border-top: none; padding: 0; flex: 1; }
    .sidebar-footer { display: none; }
    .main-content { padding: 20px; }
}
@media (max-width: 600px) {
    .stats-grid { grid-template-columns: 1fr; }
    .op-card { flex-direction: column; align-items: flex-start; gap: 8px; }
    .op-card-right { margin-left: 56px; }
}

/* Regeneration status banner */
.regeneration-status {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 0.95rem;
}
.regeneration-status.pending {
    background: #fef3cd;
    border: 1px solid #ffc107;
    color: #856404;
}
.regeneration-status.in-progress {
    background: #cce5ff;
    border: 1px solid #0d6efd;
    color: #004085;
}
.regeneration-status.completed {
    background: #d4edda;
    border: 1px solid #28a745;
    color: #155724;
}
.regeneration-status.failed {
    background: #f8d7da;
    border: 1px solid #dc3545;
    color: #721c24;
}

/* Outline button variant */
.btn-outline {
    background: transparent;
    border: 1px solid #0d6efd;
    color: #0d6efd;
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.15s;
}
.btn-outline:hover {
    background: #0d6efd;
    color: #fff;
}

/* Per-finding regenerate button */
.finding-regenerate-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border: none;
    background: transparent;
    color: #dc3545;
    cursor: pointer;
    font-size: 0.7rem;
    border-radius: 3px;
    opacity: 0.3;
    transition: opacity 0.15s;
    vertical-align: middle;
    margin-left: 6px;
    padding: 0;
    line-height: 1;
}
.finding-regenerate-btn:hover {
    opacity: 1;
    background: #f8d7da;
}

/* Regeneration status badge on finding */
.finding-regen-badge {
    display: inline-block;
    font-size: 0.7rem;
    padding: 1px 6px;
    border-radius: 4px;
    background: #fff3cd;
    color: #856404;
    margin-left: 6px;
    font-family: sans-serif;
}
