/* Solution Optimal Portal — Layout & Components */

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

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ══════════════════════════════════════ */
/* HEADER                                 */
/* ══════════════════════════════════════ */

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--header-bg);
    height: 56px;
    flex-shrink: 0;
}
.header-left {
    display: flex; align-items: center; gap: 12px;
}
.header-logo {
    height: 32px; width: auto; border-radius: 6px;
    object-fit: contain; flex-shrink: 0;
}
.header-titles { display: flex; align-items: baseline; gap: 10px; }
.header-left h1 {
    font-family: var(--font-heading);
    font-size: 16px; font-weight: 700; letter-spacing: -0.3px;
    color: var(--text);
}
.subtitle {
    font-family: var(--font-data);
    font-size: 11px; color: var(--accent);
    text-transform: uppercase; letter-spacing: 0.06em;
    font-weight: 600;
}
.header-right { display: flex; align-items: center; gap: 12px; }

/* Status Badge */
.status-badge {
    display: flex; align-items: center; gap: 6px;
    padding: 4px 12px; border-radius: 20px;
    font-family: var(--font-data);
    font-size: 11px; font-weight: 500;
    background: var(--surface-2);
    border: 1px solid var(--border);
}
.status-dot { width: 7px; height: 7px; 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); }
.status-badge.online .status-text { color: var(--green); }
.status-badge.offline .status-text { color: var(--text-dim); }

/* User Badge */
.user-badge {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 10px; border-radius: 20px;
    background: var(--surface-2); border: 1px solid var(--border);
    font-size: 12px;
}
.user-avatar {
    width: 24px; height: 24px; border-radius: 50%;
    background: var(--accent); color: #000;
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-heading);
    font-weight: 700; font-size: 11px; flex-shrink: 0;
}
.user-name { color: var(--text); font-weight: 500; }
.user-logout {
    background: none; border: none; color: var(--text-dim);
    cursor: pointer; font-size: 16px; line-height: 1;
    padding: 0 2px; transition: color 0.15s;
}
.user-logout:hover { color: var(--red); }

/* ══════════════════════════════════════ */
/* LAYOUT                                 */
/* ══════════════════════════════════════ */

main {
    display: flex;
    height: calc(100vh - 56px);
    overflow: hidden;
}

/* ══════════════════════════════════════ */
/* SIDEBAR                                */
/* ══════════════════════════════════════ */

.sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-section {
    padding: 16px;
}
.sidebar-section + .sidebar-section {
    border-top: 1px solid var(--border);
}
.sidebar-kb {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.sidebar-label {
    font-size: 10px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--text-secondary); margin-bottom: 10px;
}

/* Cabinet Navigation */
.cabinet-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.cabinet-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: var(--radius-md);
    cursor: pointer; transition: all 0.15s;
    border: 1px solid transparent;
}
.cabinet-item:hover {
    background: var(--glass);
}
.cabinet-item.active {
    background: var(--accent-glow);
    border-color: rgba(245, 180, 85, 0.25);
}
.cabinet-icon {
    width: 32px; height: 32px; border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; background: var(--surface-2);
    border: 1px solid var(--border);
    flex-shrink: 0;
}
.cabinet-item.active .cabinet-icon {
    background: var(--accent);
    border-color: var(--accent);
}
.cabinet-info { overflow: hidden; }
.cabinet-name {
    font-size: 13px; font-weight: 600; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cabinet-desc {
    font-size: 11px; color: var(--text-dim);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cabinet-item.active .cabinet-name { color: var(--accent); }

/* Knowledge Base */
.kb-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 10px;
}
.kb-header .sidebar-label { margin-bottom: 0; }
.source-count {
    font-family: var(--font-data); font-size: 11px;
    color: var(--text-dim); font-weight: 500;
}
.sources-list {
    flex: 1; overflow-y: auto;
    font-size: 12px;
}
.source-item {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 8px; border-radius: 4px;
    transition: background 0.1s;
}
.source-item:hover { background: var(--glass); }
.source-icon { font-size: 14px; flex-shrink: 0; }
.source-name {
    flex: 1; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; color: var(--text);
}
.source-chunks {
    font-family: var(--font-data); font-size: 10px;
    color: var(--text-dim); flex-shrink: 0;
}
.empty-state {
    text-align: center; color: var(--text-secondary);
    padding: 20px 0; font-size: 12px;
}

/* Category folders */
.cat-folder { margin-bottom: 2px; }
.cat-summary {
    display: flex; align-items: center; gap: 6px;
    padding: 5px 8px; border-radius: 4px; cursor: pointer;
    list-style: none; font-size: 12px; font-weight: 500;
    color: var(--text); transition: background 0.1s;
}
.cat-summary:hover { background: var(--glass); }
.cat-summary::-webkit-details-marker { display: none; }
.cat-icon { font-size: 14px; }
.cat-name { flex: 1; }
.cat-count { font-family: var(--font-data); font-size: 10px; color: var(--text-dim); }
.cat-children { padding-left: 12px; }

/* ══════════════════════════════════════ */
/* CHAT AREA                              */
/* ══════════════════════════════════════ */

.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--header-bg);
    flex-shrink: 0;
}
.chat-cabinet-name {
    font-weight: 600; font-size: 14px; color: var(--text);
}
.chat-cabinet-desc {
    font-size: 12px; color: var(--text-dim); flex: 1;
}
.btn-small {
    padding: 4px 12px; border-radius: 4px;
    background: var(--surface-2); border: 1px solid var(--border);
    color: var(--text-dim); font-size: 11px; font-weight: 500;
    cursor: pointer; transition: all 0.15s;
    font-family: var(--font-data);
}
.btn-small:hover { border-color: var(--text-secondary); color: var(--text); }

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

/* Welcome Screen */
.welcome-screen {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    flex: 1; gap: 12px; padding: 40px;
}
.welcome-icon { opacity: 0.5; }
.welcome-title {
    font-size: 20px; font-weight: 600; color: var(--text);
    letter-spacing: -0.3px;
}
.welcome-text {
    font-size: 14px; color: var(--text-dim); text-align: center;
    max-width: 400px; line-height: 1.5;
}

/* Messages */
.msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.msg.user {
    align-self: flex-end;
    background: var(--accent);
    color: #000;
    border-bottom-right-radius: 2px;
}
.msg.agent {
    align-self: flex-start;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 2px;
}
.msg.system {
    align-self: center;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px; padding: 4px 12px;
    font-style: italic;
}
.msg.streaming::after {
    content: '';
    display: inline-block;
    width: 6px; height: 14px;
    background: var(--accent);
    margin-left: 2px;
    animation: blink 0.7s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* Tool calls */
.msg.tool-call {
    align-self: flex-start;
    background: rgba(245, 180, 85, 0.06);
    border: 1px solid rgba(245, 180, 85, 0.15);
    padding: 8px 12px;
    font-size: 12px; font-family: var(--font-data);
    display: flex; align-items: center; gap: 6px;
    max-width: 90%;
}
.tool-icon { font-size: 14px; }
.tool-name { font-weight: 600; color: var(--accent); }
.tool-args { color: var(--text-dim); margin-left: 4px; }
.tool-spinner {
    width: 12px; height: 12px; border: 2px solid var(--border);
    border-top-color: var(--accent); border-radius: 50%;
    animation: spin 0.8s linear infinite; margin-left: auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.tool-badge {
    font-size: 10px; padding: 1px 6px; border-radius: 3px;
    margin-left: auto; font-weight: 600;
}
.tool-badge.ok { background: rgba(52, 211, 153, 0.15); color: var(--green); }
.tool-badge.err { background: rgba(248, 113, 113, 0.15); color: var(--red); }

/* Thinking */
.msg.thinking {
    align-self: flex-start;
    background: var(--surface-2);
    border: 1px solid var(--border);
    display: flex; align-items: center; gap: 10px;
    padding: 10px 16px;
}
.thinking-dots { display: flex; gap: 4px; }
.thinking-dots span {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--accent); opacity: 0.3;
    animation: dot-pulse 1.4s ease-in-out infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot-pulse { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }
.thinking-label { font-size: 13px; color: var(--text-dim); }

/* Attachment preview */
.attachment-preview {
    padding: 8px 20px;
    border-top: 1px solid var(--border);
}
.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; max-width: 300px;
}
.file-icon { font-size: 16px; }
.file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { color: var(--text-dim); font-family: var(--font-data); }
.remove-btn {
    background: none; border: none; color: var(--text-dim);
    cursor: pointer; font-size: 16px; padding: 0 2px;
}
.remove-btn:hover { color: var(--red); }

/* Chat Input */
.chat-input-row {
    display: flex; align-items: flex-end; gap: 8px;
    padding: 12px 20px 16px;
    border-top: 1px solid var(--border);
    background: var(--header-bg);
    flex-shrink: 0;
}
.chat-input-row textarea {
    flex: 1; padding: 10px 14px;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius-md); color: var(--text);
    font-family: var(--font-body); font-size: 14px;
    resize: none; outline: none; min-height: 42px; max-height: 120px;
}
.chat-input-row textarea:focus { border-color: var(--accent); }
.chat-input-row textarea:disabled {
    opacity: 0.5; cursor: not-allowed;
}
.chat-input-row textarea::placeholder { color: var(--text-secondary); }
.btn-send {
    width: 42px; height: 42px;
    background: var(--accent); border: none; border-radius: var(--radius-md);
    color: #000; cursor: pointer; transition: background 0.15s;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.btn-send:hover { background: var(--accent-strong); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-attach {
    width: 42px; height: 42px;
    display: flex; align-items: center; justify-content: center;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius-md); color: var(--text-dim);
    cursor: pointer; transition: all 0.15s; flex-shrink: 0;
}
.btn-attach:hover { border-color: var(--accent); color: var(--accent); }

/* ══════════════════════════════════════ */
/* SCROLLBARS                             */
/* ══════════════════════════════════════ */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.25); }

/* ══════════════════════════════════════ */
/* RESPONSIVE                             */
/* ══════════════════════════════════════ */

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -280px;
        top: 56px;
        height: calc(100vh - 56px);
        z-index: 100;
        width: 280px;
        transition: left 0.25s ease;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
    }
    .sidebar.open { left: 0; }
    .sidebar-overlay {
        position: fixed; inset: 0; top: 56px;
        background: rgba(0, 0, 0, 0.5);
        z-index: 99; display: none;
    }
    .sidebar-overlay.visible { display: block; }
    .header-left { gap: 8px; }
    .header-logo { height: 28px; }
    .header-left h1 { font-size: 14px; }
    .hamburger {
        display: flex !important; align-items: center; justify-content: center;
        width: 36px; height: 36px; background: none; border: none;
        color: var(--text); cursor: pointer; font-size: 20px;
    }
    .chat-messages { padding: 12px; }
    .chat-input-row { padding: 8px 12px 12px; }
    .msg { max-width: 95%; }
}
@media (min-width: 769px) {
    .hamburger { display: none; }
    .sidebar-overlay { display: none !important; }
}
