*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    background: #1e1e1e;
    color: #d4d4d4;
    font-family: 'Segoe UI', Roboto, sans-serif;
}

/* ── Layout ──────────────────────────────────────────────── */
.chat-layout {
    display: flex;
    height: calc(100vh - 48px);
    overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.chat-sidebar {
    width: 240px;
    min-width: 180px;
    background: #252526;
    border-right: 1px solid #3c3c3c;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 10px 8px;
    border-bottom: 1px solid #3c3c3c;
}

.session-list {
    flex: 1;
    overflow-y: auto;
}

.session-item {
    display: flex;
    align-items: center;
    padding: 8px 8px 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid #2d2d2d;
    user-select: none;
    transition: background 0.15s;
}

.session-item:hover { background: #2a2d2e; }
.session-item.active { background: #094771; border-left: 3px solid #0078d4; }

.session-item-body {
    flex: 1;
    min-width: 0;
}

.session-title {
    font-size: 13px;
    color: #d4d4d4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-date {
    font-size: 11px;
    color: #6a6a6a;
    margin-top: 2px;
}

.session-delete-btn {
    flex-shrink: 0;
    opacity: 0;
    background: transparent;
    border: none;
    color: #888;
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 3px;
    cursor: pointer;
    line-height: 1;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.session-item:hover .session-delete-btn { opacity: 1; }
.session-delete-btn:hover { background: #5a1d1d; color: #f48771; }

/* ── Main ────────────────────────────────────────────────── */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #1e1e1e;
}

/* ── Toolbar ─────────────────────────────────────────────── */
.chat-toolbar {
    display: flex;
    align-items: center;
    padding: 6px 16px;
    background: #252526;
    border-bottom: 1px solid #3c3c3c;
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.status-dot.connected    { background: #4caf50; }
.status-dot.disconnected { background: #f44336; }

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

.message-wrapper { display: flex; }
.message-wrapper.user      { justify-content: flex-end; }
.message-wrapper.assistant,
.message-wrapper.system    { justify-content: flex-start; }

.message-bubble {
    max-width: 72%;
    border-radius: 8px;
    padding: 10px 14px;
    word-break: break-word;
}

.message-wrapper.user      .message-bubble { background: #1a4a82; }
.message-wrapper.assistant .message-bubble { background: #2a2b30; }
.message-wrapper.system    .message-bubble { background: #321840; }
.message-bubble.streaming  { border: 1px solid #0078d4; }

.message-role {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.message-wrapper.user      .message-role { color: #8cb4ff; }
.message-wrapper.assistant .message-role { color: #50d7aa; }
.message-wrapper.system    .message-role { color: #c896f0; }

.message-time {
    font-weight: 400;
    color: #6a6a6a;
    font-size: 10px;
}

.message-body {
    font-size: 14px;
    line-height: 1.6;
    color: #dcdcdc;
}

.typing-indicator {
    animation: blink 1s step-end infinite;
    color: #0078d4;
}

@keyframes blink { 50% { opacity: 0; } }

/* ── Code blocks ─────────────────────────────────────────── */
.message-body pre.code-block {
    background: #141414;
    border-radius: 6px;
    padding: 12px 14px;
    margin: 8px 0;
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.5;
}

.message-body code {
    font-family: 'Cascadia Code', Consolas, 'Courier New', monospace;
    color: #d7d7d7;
}

/* ── Input area ──────────────────────────────────────────── */
.chat-input-area {
    padding: 12px 16px;
    background: #252526;
    border-top: 1px solid #3c3c3c;
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-input { flex: 1; }

.input-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-bottom: 4px;
}

/* ── Attached files bar ──────────────────────────────────── */
.attached-files {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 16px 0;
    background: #252526;
    border-top: 1px solid #3c3c3c;
}

.attached-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    background: #1a3a5c;
    border: 1px solid #0078d4;
    border-radius: 12px;
    padding: 3px 8px 3px 6px;
    font-size: 12px;
    color: #8cb4ff;
}

.chip-remove {
    background: transparent;
    border: none;
    color: #6a8cb4;
    font-size: 11px;
    cursor: pointer;
    padding: 0 0 0 2px;
    line-height: 1;
}
.chip-remove:hover { color: #f48771; }

/* ── Context menu ────────────────────────────────────────── */
.ctx-menu {
    position: fixed;
    z-index: 9999;
    background: #2d2d30;
    border: 1px solid #3c3c3c;
    border-radius: 4px;
    min-width: 160px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    padding: 4px 0;
}

.ctx-item {
    padding: 8px 14px;
    cursor: pointer;
    font-size: 13px;
    color: #d4d4d4;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: background 0.1s;
}

.ctx-item:hover        { background: #094771; }
.ctx-item.danger       { color: #f48771; }
.ctx-item.danger:hover { background: #5a1d1d; }

/* ── Login page ──────────────────────────────────────────── */
.login-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: #1e1e1e;
}

.login-card {
    background: #252526;
    border: 1px solid #3c3c3c;
    border-radius: 8px;
    padding: 40px 36px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.login-title {
    font-size: 22px;
    font-weight: 600;
    color: #d4d4d4;
    text-align: center;
    margin-bottom: 28px;
}

.login-error {
    background: #5a1d1d;
    color: #f48771;
    border: 1px solid #8b2020;
    border-radius: 4px;
    padding: 10px 14px;
    font-size: 13px;
    margin-bottom: 16px;
}

.login-field {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.login-field label {
    font-size: 12px;
    color: #9a9a9a;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.login-field input {
    background: #1e1e1e;
    border: 1px solid #3c3c3c;
    border-radius: 4px;
    color: #d4d4d4;
    font-size: 14px;
    padding: 9px 12px;
    outline: none;
    transition: border-color 0.15s;
}

.login-field input:focus {
    border-color: #0078d4;
}

.login-btn {
    width: 100%;
    margin-top: 8px;
    padding: 10px;
    background: #0078d4;
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.login-btn:hover { background: #006cbf; }
.login-btn:active { background: #005fa8; }

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #555; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #777; }
