/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --sidebar-w: 280px;
    --bg-dark: #1a1a2e;
    --bg-sidebar: #16213e;
    --bg-main: #f7f7f8;
    --bg-user: #e3f2fd;
    --bg-assistant: #ffffff;
    --accent: #4a90d9;
    --accent-hover: #357abd;
    --text-light: #e0e0e0;
    --text-dark: #1a1a1a;
    --border: #e0e0e0;
    --danger: #e74c3c;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    color: var(--text-dark);
    background: var(--bg-main);
}

/* ── Layout ──────────────────────────────────────────────── */
.app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--bg-sidebar);
    color: var(--text-light);
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s ease;
}

.sidebar.hidden {
    margin-left: calc(-1 * var(--sidebar-w));
}

.sidebar-header {
    padding: 20px 16px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h1 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 12px;
    color: #fff;
}

.btn-new-chat {
    width: 100%;
    padding: 10px;
    border: 1px dashed rgba(255,255,255,0.3);
    border-radius: 8px;
    background: transparent;
    color: var(--text-light);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-new-chat:hover {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.5);
}

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

.session-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 2px;
    transition: background 0.15s;
    gap: 8px;
}

.session-item:hover {
    background: rgba(255,255,255,0.08);
}

.session-item.active {
    background: rgba(255,255,255,0.15);
}

.session-item .title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
}

.session-item .btn-delete {
    opacity: 0;
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 16px;
    padding: 2px 6px;
    border-radius: 4px;
    transition: opacity 0.15s;
}

.session-item:hover .btn-delete {
    opacity: 0.7;
}

.session-item .btn-delete:hover {
    opacity: 1;
    background: rgba(231,76,60,0.15);
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid rgba(255,255,255,0.1);
    text-align: center;
}

.sidebar-footer .brand {
    font-size: 11px;
    opacity: 0.5;
    text-transform: uppercase;
    letter-spacing: 1px;
}

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

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

.btn-toggle-sidebar {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-dark);
    padding: 4px 8px;
    border-radius: 6px;
}

.btn-toggle-sidebar:hover {
    background: #f0f0f0;
}

.chat-title {
    font-weight: 600;
    font-size: 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Messages ────────────────────────────────────────────── */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 0;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #888;
    text-align: center;
    padding: 20px;
}

.empty-state h2 {
    font-size: 28px;
    color: var(--accent);
    margin-bottom: 12px;
}

.empty-state .hint {
    font-size: 13px;
    margin-top: 8px;
    opacity: 0.6;
}

.message {
    padding: 16px 20px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.message.user {
    background: var(--bg-user);
}

.message.assistant {
    background: var(--bg-assistant);
}

.message .role {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    color: #666;
}

.message.user .role { color: var(--accent); }
.message.assistant .role { color: #27ae60; }

.message .content {
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.message .pdf-download {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding: 8px 16px;
    background: var(--accent);
    color: #fff;
    border-radius: 6px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.2s;
}

.message .pdf-download:hover {
    background: var(--accent-hover);
}

/* ── Typing indicator ────────────────────────────────────── */
.typing-indicator {
    padding: 16px 20px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.typing-dots {
    display: inline-flex;
    gap: 4px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: #aaa;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* ── Input area ──────────────────────────────────────────── */
.input-area {
    padding: 12px 20px 20px;
    background: var(--bg-main);
    border-top: 1px solid var(--border);
}

.input-wrapper {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 2px 12px rgba(74,144,217,0.15);
}

#message-input {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.5;
    max-height: 150px;
    padding: 4px 0;
    background: transparent;
}

.btn-send {
    background: var(--accent);
    border: none;
    border-radius: 8px;
    color: #fff;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}

.btn-send:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        z-index: 100;
        height: 100vh;
    }
    .sidebar.hidden {
        margin-left: calc(-1 * var(--sidebar-w));
    }
}

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