/* ============================================================
   AI Brain — Stylesheet
   Clean, modern, dark theme
   ============================================================ */

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --bg-surface: #1e2a4a;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0b8;
    --text-muted: #6c6c80;
    --accent: #4fc3f7;
    --accent-hover: #29b6f6;
    --accent-dim: #1a3a5c;
    --success: #66bb6a;
    --warning: #ffa726;
    --error: #ef5350;
    --border: #2a2a4a;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

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

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

.hidden { display: none !important; }
.error { color: var(--error); font-size: 0.85rem; margin-top: 0.5rem; }

/* ============================================================
   Login Screen
   ============================================================ */
#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
}

.login-box {
    background: var(--bg-secondary);
    padding: 2.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: 360px;
    text-align: center;
}

.login-box h1 {
    color: var(--accent);
    margin-bottom: 0.25rem;
    font-size: 1.8rem;
}

.login-box p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.login-box input {
    width: 100%;
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.95rem;
}

.login-box button {
    width: 100%;
    padding: 0.75rem;
    background: var(--accent);
    color: var(--bg-primary);
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.login-box button:hover {
    background: var(--accent-hover);
}

/* ============================================================
   Header
   ============================================================ */
#header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    height: 52px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.header-left h1 {
    font-size: 1.1rem;
    color: var(--accent);
}

.header-center {
    display: flex;
    gap: 0;
}

.view-tab {
    padding: 0.5rem 1.25rem;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.view-tab:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.view-tab:last-child { border-radius: 0 var(--radius) var(--radius) 0; }

.view-tab.active {
    background: var(--accent);
    color: var(--bg-primary);
    border-color: var(--accent);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-right select {
    padding: 0.35rem 0.5rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.8rem;
}

.btn-icon {
    padding: 0.35rem 0.75rem;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.8rem;
}

.btn-icon:hover { color: var(--error); border-color: var(--error); }

/* ============================================================
   Chat View
   ============================================================ */
#chat-view {
    display: flex;
    height: calc(100vh - 52px);
}

#chat-sidebar {
    width: 260px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 0.75rem;
    overflow-y: auto;
}

.btn-primary {
    width: 100%;
    padding: 0.6rem;
    background: var(--accent);
    color: var(--bg-primary);
    border: none;
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 0.75rem;
}

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

#conversation-list {
    flex: 1;
    overflow-y: auto;
}

.conv-item {
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius);
    cursor: pointer;
    margin-bottom: 2px;
    transition: background 0.15s;
}

.conv-item:hover { background: var(--bg-surface); }
.conv-item.active { background: var(--accent-dim); }

.conv-item-title {
    font-size: 0.85rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-item-date {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Chat main area */
#chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
}

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

.message {
    max-width: 75%;
    padding: 0.85rem 1rem;
    border-radius: var(--radius);
    line-height: 1.5;
    font-size: 0.92rem;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message.user {
    align-self: flex-end;
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.message.assistant {
    align-self: flex-start;
    background: var(--bg-surface);
    color: var(--text-primary);
}

.message.assistant .msg-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

#chat-status {
    padding: 0.25rem 1.25rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

#chat-form {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

#chat-input {
    flex: 1;
    padding: 0.65rem 0.85rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.92rem;
    font-family: inherit;
    resize: none;
    max-height: 120px;
}

#chat-input:focus { outline: none; border-color: var(--accent); }

#btn-send {
    padding: 0.65rem 1.25rem;
    background: var(--accent);
    color: var(--bg-primary);
    border: none;
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

#btn-send:hover { background: var(--accent-hover); }
#btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============================================================
   Dashboard View
   ============================================================ */
#dashboard-view {
    height: calc(100vh - 52px);
    overflow-y: auto;
    padding: 1.25rem;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    max-width: 1200px;
    margin: 0 auto;
}

.panel {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

.panel h2 {
    font-size: 1rem;
    color: var(--accent);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.panel-wide { grid-column: 1 / -1; }

/* Stats */
#stats-content {
    display: flex;
    gap: 2rem;
}

.stat { text-align: center; }

.stat-value {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Profile */
.profile-field {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border);
}

.profile-field-key {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.profile-field-value {
    font-size: 0.85rem;
    color: var(--text-primary);
}

.profile-add {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.profile-add input {
    flex: 1;
    padding: 0.4rem 0.6rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.8rem;
}

.profile-add button,
.memory-add button {
    padding: 0.4rem 0.75rem;
    background: var(--accent);
    color: var(--bg-primary);
    border: none;
    border-radius: var(--radius);
    font-size: 0.8rem;
    cursor: pointer;
}

/* Memory browser */
.memory-toolbar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.memory-toolbar input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.85rem;
}

.memory-toolbar select {
    padding: 0.5rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.85rem;
}

.memory-toolbar button {
    padding: 0.5rem 1rem;
    background: var(--accent);
    color: var(--bg-primary);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
}

#memory-list {
    max-height: 400px;
    overflow-y: auto;
}

.memory-item {
    padding: 0.65rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
}

.memory-item-content {
    flex: 1;
    font-size: 0.85rem;
    line-height: 1.4;
}

.memory-item-meta {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-shrink: 0;
}

.memory-badge {
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    border-radius: 12px;
    background: var(--accent-dim);
    color: var(--accent);
}

.memory-score {
    font-size: 0.7rem;
    color: var(--success);
    font-weight: 600;
}

.memory-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 0.2rem 0.4rem;
}

.memory-delete:hover { color: var(--error); }

.memory-add {
    margin-top: 0.75rem;
}

.memory-add textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: inherit;
    resize: vertical;
    margin-bottom: 0.5rem;
}

.memory-add-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.memory-add-row select,
.memory-add-row input {
    padding: 0.4rem 0.5rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.8rem;
}

.memory-add-row input[type="number"] { width: 50px; }

/* Conversation history in dashboard */
.history-item {
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border);
}

.history-item-title {
    font-size: 0.85rem;
    color: var(--text-primary);
    font-weight: 500;
}

.history-item-summary {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
    line-height: 1.4;
}

.history-item-date {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

/* Loading spinner */
.loading::after {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--text-muted);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-left: 0.5rem;
    vertical-align: middle;
}

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

/* Responsive */
@media (max-width: 768px) {
    #chat-sidebar { display: none; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .message { max-width: 90%; }
}
