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

:root {
    --bg: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a26;
    --border: #2a2a3a;
    --text: #e0e0e8;
    --text-dim: #8888a0;
    --accent: #6366f1;
    --accent-dim: #4f46e5;
    --user-msg: #1e1e3a;
    --mind-msg: #1a1a26;
    --online: #22c55e;
    --offline: #6b7280;
}

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

/* Login */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-box {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 40px;
    width: 360px;
    text-align: center;
}

.login-box h1 {
    font-size: 1.8em;
    letter-spacing: 3px;
    margin-bottom: 4px;
}

.subtitle {
    color: var(--text-dim);
    font-size: 0.75em;
    margin-bottom: 24px;
}

.flash {
    background: #3b1a1a;
    border: 1px solid #5a2a2a;
    color: #f87171;
    padding: 8px 12px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 0.85em;
}

.login-box input {
    width: 100%;
    padding: 10px 14px;
    margin-bottom: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.95em;
}

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

.login-box button {
    width: 100%;
    padding: 10px;
    background: var(--accent);
    border: none;
    border-radius: 6px;
    color: white;
    font-size: 0.95em;
    cursor: pointer;
    margin-top: 4px;
}

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

/* Dashboard layout */
.container {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 220px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

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

.sidebar-header h2 {
    font-size: 1.1em;
    letter-spacing: 2px;
}

.user-info {
    font-size: 0.75em;
    color: var(--text-dim);
}

.mind-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.mind-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: none;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    font-size: 0.9em;
    text-align: left;
}

.mind-btn:hover { background: var(--bg-tertiary); }
.mind-btn.active {
    background: var(--bg-tertiary);
    border-color: var(--border);
}

.mind-name { text-transform: capitalize; }

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--offline);
    flex-shrink: 0;
}

.status-dot.online { background: var(--online); }

.logout-btn {
    display: block;
    padding: 12px 16px;
    color: var(--text-dim);
    text-decoration: none;
    font-size: 0.8em;
    border-top: 1px solid var(--border);
    text-align: center;
}

.logout-btn:hover { color: var(--text); }

/* Chat */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header h3 {
    font-size: 1.05em;
    text-transform: capitalize;
}

.chat-status {
    font-size: 0.75em;
    color: var(--text-dim);
}

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

.msg {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 0.9em;
    line-height: 1.5;
    word-wrap: break-word;
}

.msg.user {
    align-self: flex-end;
    background: var(--user-msg);
    border: 1px solid #2a2a4a;
}

.msg.mind {
    align-self: flex-start;
    background: var(--mind-msg);
    border: 1px solid var(--border);
}

.msg .meta {
    font-size: 0.7em;
    color: var(--text-dim);
    margin-top: 4px;
}

/* Markdown rendering inside mind messages */
.msg.mind .text p { margin: 0 0 8px; }
.msg.mind .text p:last-child { margin-bottom: 0; }
.msg.mind .text ul, .msg.mind .text ol { margin: 4px 0 8px 18px; padding: 0; }
.msg.mind .text li { margin-bottom: 2px; }
.msg.mind .text table { border-collapse: collapse; margin: 8px 0; font-size: 0.9em; }
.msg.mind .text th, .msg.mind .text td { border: 1px solid var(--border); padding: 4px 10px; text-align: left; }
.msg.mind .text th { background: var(--bg-secondary); }
.msg.mind .text code { background: var(--bg-secondary); padding: 1px 5px; border-radius: 3px; font-size: 0.9em; }
.msg.mind .text pre { background: var(--bg-secondary); padding: 10px; border-radius: 4px; overflow-x: auto; margin: 8px 0; }
.msg.mind .text pre code { background: none; padding: 0; }
.msg.mind .text h1, .msg.mind .text h2, .msg.mind .text h3 { margin: 8px 0 4px; font-size: 1em; font-weight: bold; }

.msg.relay {
    max-width: 70%;
    opacity: 0.75;
    border-style: dashed;
    font-size: 0.85em;
}

.msg.relay-out {
    align-self: flex-end;
    background: #1a1a2e;
    border-color: #3a3a5a;
}

.msg.relay-in {
    align-self: flex-start;
    background: #1a2a1a;
    border-color: #3a5a3a;
}

.relay-label {
    font-size: 0.7em;
    color: var(--text-dim);
    margin-bottom: 4px;
    font-style: italic;
}

.msg .signed-badge {
    color: var(--online);
    font-size: 0.65em;
    margin-left: 6px;
}

.input-area {
    display: flex;
    gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

.input-area textarea {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.9em;
    font-family: inherit;
    resize: none;
    overflow-y: hidden;
    min-height: 38px;
    max-height: 150px;
    line-height: 1.4;
}

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

.input-area button {
    padding: 10px 20px;
    background: var(--accent);
    border: none;
    border-radius: 6px;
    color: white;
    cursor: pointer;
    font-size: 0.9em;
}

.input-area button:hover { background: var(--accent-dim); }

/* Thinking indicator */
.thinking {
    align-self: flex-start;
    color: var(--text-dim);
    font-size: 0.85em;
    padding: 8px 14px;
}

.thinking::after {
    content: '';
    animation: dots 1.5s infinite;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* Drone output panel */
.drone-panel {
    border-top: 1px solid var(--border);
    background: #0d0d14;
    display: flex;
    flex-direction: column;
    max-height: 250px;
    transition: max-height 0.3s ease;
}

.drone-panel.collapsed {
    max-height: 32px;
    overflow: hidden;
}

.drone-toggle {
    background: var(--bg-tertiary);
    border: none;
    color: var(--text-dim);
    padding: 6px 14px;
    cursor: pointer;
    font-size: 0.8em;
    text-align: left;
    flex-shrink: 0;
}

.drone-toggle:hover { color: var(--text); }

.drone-log {
    overflow-y: auto;
    padding: 8px 14px;
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.78em;
    line-height: 1.5;
    flex: 1;
    min-height: 0;
}

.drone-empty {
    color: var(--text-dim);
    font-style: italic;
}

.drone-event {
    display: flex;
    gap: 8px;
    padding: 2px 0;
    word-break: break-word;
}

.drone-icon {
    flex-shrink: 0;
    width: 16px;
    text-align: center;
}

.drone-ts {
    color: var(--text-dim);
    flex-shrink: 0;
    font-size: 0.9em;
}

.drone-content {
    color: var(--text);
    white-space: pre-wrap;
}

.drone-start .drone-content { color: var(--accent); }
.drone-tool_use .drone-content { color: #f59e0b; }
.drone-tool_result .drone-content { color: var(--text-dim); }
.drone-error .drone-content { color: #ef4444; }
.drone-result .drone-content { color: #22c55e; }
.drone-done .drone-content { color: var(--text-dim); }
.drone-tokens .drone-content { color: #a78bfa; }
.drone-escalation .drone-content { color: #fb923c; }

/* Sidebar links */
.sidebar-link {
    display: block;
    padding: 10px 16px;
    color: var(--text-dim);
    text-decoration: none;
    font-size: 0.85em;
}

.sidebar-link:hover { color: var(--text); background: var(--bg-tertiary); }

.config-link {
    border-top: 1px solid var(--border);
    margin-top: auto;
}

/* Config page */
.config-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow-y: auto;
}

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

.config-header h3 {
    font-size: 1.05em;
}

.config-content {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.config-error {
    background: #3b1a1a;
    border: 1px solid #5a2a2a;
    color: #f87171;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.85em;
}

.config-saved {
    background: #1a3b1a;
    border: 1px solid #2a5a2a;
    color: #4ade80;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.85em;
}

.config-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
}

.config-card-header {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 16px;
}

.config-card-header h4 {
    font-size: 1em;
}

.config-mind-id {
    font-size: 0.75em;
    color: var(--text-dim);
    font-family: monospace;
}

.config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}

.config-field label {
    display: block;
    font-size: 0.75em;
    color: var(--text-dim);
    margin-bottom: 4px;
}

.config-field input,
.config-field select {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.85em;
}

.config-field input:focus,
.config-field select:focus {
    outline: none;
    border-color: var(--accent);
}

.config-drones-header {
    font-size: 0.8em;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 8px 0 4px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.config-drone {
    margin-bottom: 8px;
}

.drone-label {
    font-size: 0.85em;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 4px;
    display: block;
}

.config-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.config-actions button {
    padding: 8px 18px;
    border: none;
    border-radius: 6px;
    color: white;
    cursor: pointer;
    font-size: 0.85em;
    background: var(--accent);
}

.config-actions button:hover { background: var(--accent-dim); }

.config-actions .btn-restart {
    background: #b45309;
}

.config-actions .btn-restart:hover { background: #92400e; }
