/* Universal Cabinet Dashboard */
:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-2: #242836;
    --border: #2e3347;
    --text: #e4e6f0;
    --text-dim: #8b8fa3;
    --accent: #6c7cff;
    --accent-dim: #4a56b5;
    --green: #34d399;
    --red: #f87171;
    --orange: #fbbf24;
    --radius: 8px;
    --brand: #1976D2;
}

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

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

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.header-left {
    display: flex; align-items: center; gap: 12px;
}
.header-logo {
    width: 36px; height: 36px; border-radius: 6px;
    object-fit: contain; flex-shrink: 0;
}
.header-left h1 {
    font-size: 18px; font-weight: 700; letter-spacing: -0.5px;
    color: var(--brand);
}
.header-left .subtitle { font-size: 12px; color: var(--text-dim); margin-left: 4px; }
.header-right { display: flex; align-items: center; gap: 12px; }

.status-badge {
    display: flex; align-items: center; gap: 6px;
    padding: 4px 12px; border-radius: 20px; font-size: 12px;
    background: var(--surface-2);
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; }
.status-badge.online .status-dot { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-badge.offline .status-dot { background: var(--red); }

/* Main layout */
main { padding: 20px 24px; height: calc(100vh - 65px); }
.main-row {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 16px;
    height: 100%;
}

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.card-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.card-header h3 {
    font-size: 13px; font-weight: 600; color: var(--text-dim);
    text-transform: uppercase; letter-spacing: 0.5px;
}
.card-body { padding: 16px; }

/* Chat */
.chat-card { display: flex; flex-direction: column; }
.chat-messages {
    flex: 1; overflow-y: auto; padding: 16px;
    display: flex; flex-direction: column; gap: 12px;
}

.msg {
    max-width: 85%; padding: 10px 14px; border-radius: 8px;
    font-size: 14px; line-height: 1.6; white-space: pre-wrap; word-break: break-word;
}
.msg.user { align-self: flex-end; background: var(--accent-dim); color: #fff; }
.msg.agent { align-self: flex-start; background: var(--surface-2); }
.msg.system { align-self: center; color: var(--text-dim); font-size: 12px; font-style: italic; }
.msg.streaming { border-left: 2px solid var(--accent); }

.chat-input-row {
    display: flex; gap: 8px; padding: 12px 16px;
    border-top: 1px solid var(--border); align-items: flex-end;
}
#chat-input {
    flex: 1; background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
    border-radius: 6px; padding: 10px 14px; font-family: inherit; font-size: 14px; resize: none;
}
#chat-input:focus { outline: none; border-color: var(--accent); }
.btn-send {
    padding: 10px 24px; background: var(--brand); color: #fff; border: none;
    border-radius: 6px; font-family: inherit; font-weight: 600; cursor: pointer; font-size: 14px;
}
.btn-send:hover { opacity: 0.9; }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-small {
    font-size: 11px; padding: 2px 8px; background: transparent; color: var(--text-dim);
    border: 1px solid var(--border); border-radius: 4px; cursor: pointer; font-family: inherit;
}
.btn-small:hover { color: var(--text); border-color: var(--text-dim); }

/* Attach (paperclip) button */
.btn-attach {
    display: flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; background: var(--surface-2);
    border: 1px solid var(--border); border-radius: 6px;
    color: var(--text-dim); cursor: pointer; flex-shrink: 0;
}
.btn-attach:hover { color: var(--text); border-color: var(--accent); }

/* Mic button */
.btn-mic {
    display: flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; background: var(--surface-2);
    border: 1px solid var(--border); border-radius: 6px;
    color: var(--text-dim); cursor: pointer; flex-shrink: 0;
}
.btn-mic:hover { color: var(--text); border-color: var(--accent); }
.btn-mic.recording {
    color: var(--red); border-color: var(--red);
    animation: mic-pulse 1.5s infinite;
}
.btn-mic.unsupported { opacity: 0.3; cursor: not-allowed; }
@keyframes mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(248, 113, 113, 0); }
}

/* Attachment preview */
.attachment-preview {
    display: flex; flex-wrap: wrap; gap: 8px;
    padding: 8px 16px 0;
}
.attachment-card {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 10px; background: var(--surface-2);
    border: 1px solid var(--border); border-radius: 6px;
    font-size: 12px; color: var(--text);
}
.attachment-card .file-icon { font-size: 16px; }
.attachment-card .file-name {
    max-width: 160px; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap;
}
.attachment-card .file-size { color: var(--text-dim); font-size: 10px; }
.attachment-card .remove-btn {
    background: none; border: none; color: var(--text-dim);
    cursor: pointer; font-size: 14px; padding: 0 2px; line-height: 1;
}
.attachment-card .remove-btn:hover { color: var(--red); }

/* Tool Call Messages */
.msg.tool-call {
    align-self: flex-start;
    background: #1a2332;
    border: 1px solid #2a3a5a;
    border-left: 3px solid var(--accent);
    padding: 8px 12px; font-size: 12px;
    display: flex; align-items: center; gap: 8px; max-width: 90%;
}
.msg.tool-call.tool-ok { border-left-color: var(--green); }
.msg.tool-call.tool-err { border-left-color: var(--red); }

.tool-icon { font-size: 16px; flex-shrink: 0; }
.tool-name { color: var(--accent); font-weight: 600; white-space: nowrap; }
.tool-args {
    color: var(--text-dim); font-size: 11px; margin-left: 4px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 300px;
}
.tool-args::before { content: '('; }
.tool-args::after { content: ')'; }

.tool-spinner {
    width: 12px; height: 12px; border: 2px solid var(--border);
    border-top-color: var(--accent); border-radius: 50%;
    animation: tool-spin 0.8s linear infinite; flex-shrink: 0;
}
@keyframes tool-spin { to { transform: rotate(360deg); } }

.tool-badge {
    font-size: 10px; padding: 1px 8px; border-radius: 3px;
    font-weight: 600; white-space: nowrap; margin-left: auto;
}
.tool-badge.ok { background: #1e4d3a; color: var(--green); }
.tool-badge.err { background: #5f1e1e; color: var(--red); }

/* Thinking indicator */
.msg.thinking {
    align-self: flex-start; background: var(--surface-2);
    border-left: 2px solid var(--accent);
    display: flex; align-items: center; gap: 8px;
    padding: 10px 14px; border-radius: 8px;
}
.thinking-dots { display: flex; gap: 4px; }
.thinking-dots span {
    width: 6px; height: 6px; background: var(--accent);
    border-radius: 50%; animation: thinking-bounce 1.4s infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes thinking-bounce {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
}
.thinking-label { font-size: 12px; color: var(--text-dim); font-style: italic; }

/* Sidebar */
.sidebar { display: flex; flex-direction: column; gap: 16px; }

.sources-card { flex: 1; display: flex; flex-direction: column; }
.sources-list { flex: 1; overflow-y: auto; padding: 8px; }
.source-count { font-size: 11px; color: var(--text-dim); }

.source-item {
    display: flex; align-items: center; gap: 8px;
    padding: 8px; border-radius: 4px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
}
.source-item:hover { background: var(--surface-2); }
.source-icon { font-size: 16px; flex-shrink: 0; }
.source-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-chunks { color: var(--text-dim); font-size: 10px; }

.empty-state {
    color: var(--text-dim); font-size: 13px; text-align: center; padding: 24px;
}

/* KB Toolbar */
.kb-toolbar { display: flex; align-items: center; gap: 8px; }

/* Category tree */
.cat-folder { margin: 0; }
.cat-folder > .cat-children { padding-left: 16px; }
.cat-summary {
    display: flex; align-items: center; gap: 6px;
    padding: 5px 8px; border-radius: 4px;
    font-size: 12px; cursor: pointer;
    list-style: none; user-select: none;
}
.cat-summary::-webkit-details-marker { display: none; }
.cat-summary::before {
    content: '\25B6'; font-size: 8px; color: var(--text-dim);
    transition: transform 0.15s; flex-shrink: 0;
}
details[open] > .cat-summary::before { transform: rotate(90deg); }
.cat-summary:hover { background: var(--surface-2); }
.cat-icon { font-size: 13px; flex-shrink: 0; }
.cat-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.cat-count {
    font-size: 9px; color: var(--text-dim);
    background: var(--surface-2); padding: 1px 6px; border-radius: 8px;
}

/* Tag chips */
.tag-chip {
    font-size: 9px; padding: 1px 5px; border-radius: 3px;
    background: color-mix(in srgb, var(--tag-color, var(--accent)) 20%, transparent);
    color: var(--tag-color, var(--accent));
    white-space: nowrap; flex-shrink: 0;
}

/* Upload */
.upload-card .card-body { padding: 12px 16px; }
.upload-select {
    width: 100%; padding: 6px 10px; margin-bottom: 8px;
    background: var(--surface-2); border: 1px solid var(--border);
    color: var(--text); border-radius: 4px; font-size: 12px;
    font-family: inherit;
}
.upload-select:focus { outline: none; border-color: var(--accent); }
.upload-status { font-size: 12px; color: var(--text-dim); margin-bottom: 8px; }
.progress-bar {
    height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden;
}
.progress-fill {
    height: 100%; background: var(--brand); border-radius: 2px;
    width: 0%; transition: width 0.3s ease;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* Responsive */
@media (max-width: 768px) {
    .main-row { grid-template-columns: 1fr; }
    .sidebar { display: none; }
}
