/* ── Layout ────────────────────────────────────────────────────── */

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

:root {
    --bg: #f5f6fa;
    --sidebar-bg: #1e2a3a;
    --sidebar-text: #c8d6e5;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --danger: #ef4444;
    --success: #22c55e;
    --text: #1e293b;
    --text-muted: #64748b;
    --card-bg: #fff;
    --border: #e2e8f0;
    --msg-user-bg: #3b82f6;
    --msg-user-text: #fff;
    --msg-system-bg: #f1f5f9;
    --code-bg: #f8fafc;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────────── */

.sidebar {
    width: 250px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
}

.sidebar-header {
    padding: 1.5rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,.1);
}

.sidebar-header h2 {
    font-size: 1.2rem;
    color: #fff;
    margin-bottom: .25rem;
}

.sidebar-subtitle {
    font-size: .8rem;
    opacity: .7;
}

.sidebar-nav {
    list-style: none;
    padding: 1rem 0;
    flex: 1;
}

.sidebar-nav li a {
    display: block;
    padding: .75rem 1.25rem;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: background .15s;
}

.sidebar-nav li a:hover,
.sidebar-nav li a.active {
    background: rgba(255,255,255,.1);
    color: #fff;
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    font-size: .75rem;
    opacity: .5;
    border-top: 1px solid rgba(255,255,255,.1);
}

/* ── Main content ─────────────────────────────────────────────── */

.main-content {
    flex: 1;
    margin-left: 250px;
    padding: 2rem;
    max-width: calc(100vw - 250px);
}

.page-container {
    max-width: 1100px;
}

.page-container h1 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}

/* ── Chat ─────────────────────────────────────────────────────── */

.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 4rem);
    max-width: 900px;
}

.chat-header h1 {
    margin-bottom: .5rem;
}

.mode-toggle {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1rem;
    font-size: .9rem;
}

.mode-toggle label {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: .35rem;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    max-width: 80%;
    padding: .75rem 1rem;
    border-radius: 12px;
    font-size: .95rem;
    line-height: 1.6;
}

.message.user {
    background: var(--msg-user-bg);
    color: var(--msg-user-text);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.message.assistant {
    background: var(--card-bg);
    border: 1px solid var(--border);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.message.system {
    background: var(--msg-system-bg);
    align-self: center;
    max-width: 90%;
    font-size: .85rem;
    color: var(--text-muted);
    text-align: center;
}

.msg-content {
    white-space: pre-wrap;
}

.chat-input-area {
    display: flex;
    gap: .5rem;
    padding: 1rem 0;
    border-top: 1px solid var(--border);
}

.chat-input-area textarea {
    flex: 1;
    padding: .75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    resize: none;
    font-size: .95rem;
    font-family: inherit;
}

.chat-input-area textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.source-panel {
    margin-top: .5rem;
    padding: 1rem;
    background: var(--code-bg);
    border-radius: 8px;
    font-size: .8rem;
    max-height: 200px;
    overflow-y: auto;
}

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

.source-panel h3 {
    font-size: .85rem;
    margin-bottom: .5rem;
    color: var(--text-muted);
}

.source-item {
    padding: .25rem 0;
    border-bottom: 1px solid var(--border);
}

/* ── Buttons & toolbar ────────────────────────────────────────── */

.btn {
    padding: .5rem 1rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--card-bg);
    color: var(--text);
    cursor: pointer;
    font-size: .9rem;
    transition: all .15s;
}

.btn:hover { background: #f1f5f9; }

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

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

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}

.btn-secondary {
    background: #6366f1;
    color: #fff;
    border-color: #6366f1;
}

.toolbar {
    display: flex;
    gap: .5rem;
    margin-bottom: 1rem;
}

/* ── Tables ───────────────────────────────────────────────────── */

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.data-table th {
    background: #f8fafc;
    padding: .75rem 1rem;
    text-align: left;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
}

.data-table td {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: .9rem;
}

.data-table tr:hover td { background: #f8fafc; }

/* ── Cards / grid ─────────────────────────────────────────────── */

.results-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin: 1.5rem 0;
}

.card {
    background: var(--card-bg);
    padding: 1.25rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.card h3 {
    font-size: .85rem;
    color: var(--text-muted);
    margin-bottom: .5rem;
}

.card div {
    font-size: 1.5rem;
    font-weight: 700;
}

/* ── Benchmark actions ────────────────────────────────────────── */

.benchmark-actions {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.benchmark-actions .btn {
    flex-shrink: 0;
}

#benchmark-status {
    margin-bottom: 1rem;
    font-size: .9rem;
    color: var(--text-muted);
}

/* ── Graph explorer ───────────────────────────────────────────── */

.search-bar {
    display: flex;
    gap: .5rem;
    margin-bottom: 1.5rem;
}

.search-bar input {
    flex: 1;
    padding: .75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .95rem;
}

.search-results {
    margin-bottom: 1.5rem;
}

.search-results .hint {
    color: var(--text-muted);
    font-style: italic;
}

.search-result-item {
    padding: .75rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: .5rem;
    cursor: pointer;
    transition: border-color .15s;
}

.search-result-item:hover {
    border-color: var(--primary);
}

.entity-detail {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.entity-detail.hidden { display: none; }

.entity-props {
    margin: 1rem 0;
    font-size: .9rem;
}

.entity-props pre {
    background: var(--code-bg);
    padding: 1rem;
    border-radius: 6px;
    overflow-x: auto;
    font-size: .8rem;
}

.connections {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-top: 1rem;
}

.connections h3 {
    font-size: .9rem;
    margin-bottom: .5rem;
}

.connections ul {
    list-style: none;
}

.connections li {
    padding: .4rem .75rem;
    background: var(--code-bg);
    border-radius: 4px;
    margin-bottom: .25rem;
    font-size: .85rem;
}

.connections li .rel-tag {
    display: inline-block;
    background: var(--primary);
    color: #fff;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: .7rem;
    margin-right: .5rem;
}
