/* Soul Book Demo — Styles */
:root {
    --bg: #0a0a0a;
    --fg: #e5e5e5;
    --muted: #737373;
    --border: #262626;
    --accent: #60a5fa;
    --accent-dim: rgba(96, 165, 250, 0.1);
    --success: #4ade80;
    --danger: #f87171;
    --rag: #60a5fa;
    --rlm: #c084fc;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--fg);
    line-height: 1.6;
    min-height: 100vh;
}

/* Top Navigation Bar */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 2rem;
    background: rgba(255,255,255,0.03);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.nav-brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--accent);
}

.nav-links {
    display: flex;
    gap: 1.5rem;
}

.nav-links a {
    color: var(--muted);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.nav-links a:hover {
    color: var(--fg);
}

@media (max-width: 600px) {
    .top-bar {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.5rem 1rem;
    }
    .nav-links {
        gap: 1rem;
        font-size: 0.8rem;
    }
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
}

header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--muted);
}

/* Grid Layout - Chat left, Router+Memory stacked right */
.main-grid {
    display: grid;
    grid-template-columns: 1fr 350px;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.right-column {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

@media (max-width: 900px) {
    .main-grid {
        grid-template-columns: 1fr;
    }
}

/* Panels */
.panel {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 1rem;
    overflow: hidden;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    background: rgba(255,255,255,0.02);
}

.panel-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

/* Chat Panel */
.chat-panel {
    display: flex;
    flex-direction: column;
    min-height: 500px;
}

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

.message {
    max-width: 85%;
    padding: 0.75rem 1rem;
    border-radius: 1rem;
}

.message.user {
    align-self: flex-end;
    background: var(--accent);
    color: white;
    border-bottom-right-radius: 0.25rem;
}

.message.assistant {
    align-self: flex-start;
    background: var(--border);
    border-bottom-left-radius: 0.25rem;
}

.message.error {
    align-self: center;
    background: rgba(248, 113, 113, 0.2);
    color: var(--danger);
    font-size: 0.9rem;
}

.message .meta {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    font-size: 0.75rem;
}

.message .route {
    padding: 0.125rem 0.5rem;
    border-radius: 1rem;
    font-weight: 600;
    text-transform: uppercase;
}

.message .route.rag {
    background: rgba(96, 165, 250, 0.2);
    color: var(--rag);
}

.message .route.rlm {
    background: rgba(192, 132, 252, 0.2);
    color: var(--rlm);
}

.message .timing {
    color: var(--muted);
}

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

.input-area input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    background: var(--bg);
    color: var(--fg);
    font-size: 1rem;
}

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

.input-area button {
    padding: 0.75rem 1.5rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

.input-area button:hover {
    opacity: 0.9;
}

/* Mode Selector */
.mode-selector {
    display: flex;
    gap: 0.5rem;
}

.mode-selector label {
    cursor: pointer;
}

.mode-selector input {
    display: none;
}

.mode-selector span {
    display: block;
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.8rem;
    font-weight: 500;
    background: var(--border);
    transition: all 0.2s;
}

.mode-selector input:checked + span {
    background: var(--accent);
    color: white;
}

/* Router Panel */
.router-info {
    padding: 1rem;
}

.router-info .hint {
    color: var(--muted);
    font-size: 0.9rem;
    text-align: center;
    padding: 2rem 1rem;
}

.route-display {
    text-align: center;
    margin-bottom: 1.5rem;
}

.route-badge {
    display: inline-block;
    padding: 0.5rem 1.5rem;
    border-radius: 2rem;
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.route-badge.rag {
    background: rgba(96, 165, 250, 0.2);
    color: var(--rag);
}

.route-badge.rlm {
    background: rgba(192, 132, 252, 0.2);
    color: var(--rlm);
}

.route-desc {
    color: var(--muted);
    font-size: 0.85rem;
}

/* Router Steps */
.router-steps {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.step {
    display: flex;
    gap: 0.75rem;
    padding: 0.5rem;
    background: rgba(255,255,255,0.02);
    border-radius: 0.5rem;
    border-left: 3px solid var(--border);
}

.step.done {
    border-left-color: var(--success);
}

.step-num {
    width: 1.5rem;
    height: 1.5rem;
    background: var(--border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
}

.step.done .step-num {
    background: var(--success);
    color: black;
}

.step-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.step-content strong {
    font-size: 0.85rem;
}

.step-detail {
    font-size: 0.75rem;
    color: var(--muted);
}

.step-time {
    font-size: 0.7rem;
    color: var(--accent);
    font-family: monospace;
}

.route-badge-small {
    margin-top: 0.75rem;
    padding: 0.5rem;
    text-align: center;
    border-radius: 0.5rem;
    font-weight: 600;
    font-size: 0.85rem;
}

.route-badge-small.rag {
    background: rgba(96, 165, 250, 0.15);
    color: var(--rag);
}

.route-badge-small.rlm {
    background: rgba(192, 132, 252, 0.15);
    color: var(--rlm);
}

.timing-breakdown {
    background: rgba(255,255,255,0.02);
    border-radius: 0.5rem;
    padding: 0.75rem;
}

.timing-row {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0;
    font-size: 0.85rem;
    color: var(--muted);
}

.timing-row.total {
    border-top: 1px solid var(--border);
    margin-top: 0.25rem;
    padding-top: 0.5rem;
    color: var(--fg);
    font-weight: 600;
}

/* Latency Chart */
.latency-chart {
    padding: 1rem;
    border-top: 1px solid var(--border);
}

.bar-chart {
    display: flex;
    height: 1.5rem;
    border-radius: 0.25rem;
    overflow: hidden;
    background: var(--border);
}

.bar {
    height: 100%;
    transition: width 0.3s;
}

.bar.router { background: var(--accent); }
.bar.retrieval { background: var(--rlm); }
.bar.generation { background: var(--success); }

.bar-legend {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--muted);
}

.dot {
    display: inline-block;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    margin-right: 0.25rem;
}

.dot.router { background: var(--accent); }
.dot.retrieval { background: var(--rlm); }
.dot.generation { background: var(--success); }

/* Memory Panel */
.memory-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
}

.memory-tabs .tab {
    flex: 1;
    padding: 0.5rem;
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.memory-tabs .tab:hover {
    color: var(--fg);
}

.memory-tabs .tab.active {
    color: var(--accent);
    border-bottom: 2px solid var(--accent);
    margin-bottom: -1px;
}

.memory-content {
    padding: 1rem;
    max-height: 250px;
    overflow-y: auto;
}

.memory-stats {
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: 0.5rem;
}

.memory-preview {
    font-family: monospace;
    font-size: 0.75rem;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--muted);
    background: rgba(255,255,255,0.02);
    padding: 0.75rem;
    border-radius: 0.5rem;
    max-height: 200px;
    overflow-y: auto;
}

.memory-actions {
    padding: 1rem;
    border-top: 1px solid var(--border);
}

/* Buttons */
.btn-small {
    padding: 0.25rem 0.75rem;
    font-size: 0.8rem;
    background: var(--border);
    color: var(--fg);
    border: none;
    border-radius: 0.25rem;
    cursor: pointer;
}

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

.btn-secondary {
    width: 100%;
    padding: 0.5rem;
    background: var(--border);
    color: var(--fg);
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.85rem;
}

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

.btn-danger {
    width: 100%;
    padding: 0.5rem;
    background: rgba(248, 113, 113, 0.1);
    color: var(--danger);
    border: 1px solid var(--danger);
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.85rem;
}

.btn-danger:hover {
    background: rgba(248, 113, 113, 0.2);
}

/* Footer */
footer {
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
}

footer a {
    color: var(--accent);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* Error */
.error {
    color: var(--danger);
}

/* Session Controls */
.session-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.session-controls select {
    padding: 0.25rem 0.5rem;
    background: var(--bg);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    font-size: 0.8rem;
    cursor: pointer;
    max-width: 140px;
}

.session-controls select:focus {
    outline: none;
    border-color: var(--accent);
}

.session-controls .btn-small {
    background: var(--accent);
    color: white;
}

.session-controls .btn-small:hover {
    opacity: 0.9;
}

/* Panel Header Flex Wrap for Mobile */
@media (max-width: 600px) {
    .panel-header {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .session-controls {
        order: 3;
        width: 100%;
        justify-content: flex-start;
    }
    
    .mode-selector {
        order: 2;
    }
}
