/* ─── CSS Variables ──────────────────────────────────────────────── */
:root {
    --primary: #1a2744;
    --primary-hover: #0f1a2e;
    --primary-light: #e8edf4;
    --secondary: #5f6368;
    --secondary-hover: #4a4e52;
    --danger: #dc3545;
    --danger-hover: #c82333;
    --success: #28a745;
    --warning: #ffc107;
    --bg: #f8f9fa;
    --bg-white: #ffffff;
    --bg-dark: #1a2744;
    --text: #202124;
    --text-light: #5f6368;
    --text-white: #ffffff;
    --border: #dadce0;
    --border-light: #e8eaed;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.15);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: all 0.2s ease;
}

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

html, body {
    height: 100%;
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
    font-size: 16px;
    color: var(--text);
    background: var(--bg);
    overflow: hidden;
}

/* ─── Header ────────────────────────────────────────────────────── */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    z-index: 100;
    position: relative;
}

.header-left {
    display: flex;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    height: 40px;
    width: auto;
    object-fit: contain;
}

.logo-title {
    font-size: 20px;
    font-weight: 600;
    line-height: 1.2;
}

.logo-title-dark {
    color: #000000;
}

.logo-title-light {
    color: #b0b0b0;
    font-weight: 400;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ─── Buttons ───────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    gap: 6px;
    white-space: nowrap;
}

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

.btn-primary {
    background: var(--primary);
    color: var(--text-white);
}

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

.btn-secondary {
    background: var(--secondary);
    color: var(--text-white);
}

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

.btn-danger {
    background: var(--danger);
    color: var(--text-white);
}

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

.btn-ghost {
    background: transparent;
    color: var(--text-light);
    border: 1px solid var(--border);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--bg);
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    font-size: 20px;
    background: transparent;
    border-radius: 50%;
    color: var(--text-light);
}

.btn-icon:hover {
    background: var(--bg);
}

/* ─── Main Container ────────────────────────────────────────────── */
.main-container {
    display: flex;
    height: calc(100vh - 65px);
}

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

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

.message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    overflow: hidden;
}

.message-avatar .avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.message.user .message-avatar {
    background: #e3f2fd;
}

.message.assistant .message-avatar {
    background: var(--primary-light);
}

.message.system-message .message-avatar {
    background: #fff3e0;
}

.message-content {
    padding: 12px 16px;
    border-radius: var(--radius);
    line-height: 1.6;
    word-wrap: break-word;
}

.message.user .message-content {
    background: #e3f2fd;
    color: #1565c0;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.message.system-message {
    align-self: center;
    max-width: 90%;
}

.message.system-message .message-content {
    background: #fff8e1;
    border: 1px solid #ffecb3;
    border-radius: var(--radius);
    text-align: left;
    width: 100%;
}

.message.system-message .message-content ol {
    padding-left: 20px;
    margin-top: 8px;
}

.message.system-message .message-content li {
    margin-bottom: 4px;
}

.message-content p {
    margin-bottom: 8px;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-sources {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-light);
    font-size: 12px;
    color: var(--text-light);
}

/* ─── Clickable Links in Messages ─────────────────────────────── */
.message-content a {
    color: #1565c0;
    text-decoration: none;
    font-weight: 500;
    border-bottom: 1px solid #90caf9;
    transition: var(--transition);
}

.message-content a:hover {
    color: #0d47a1;
    border-bottom-color: #1565c0;
    text-decoration: none;
}

.message-content a:visited {
    color: #6a1b9a;
    border-bottom-color: #ce93d8;
}

/* ─── Input Area ────────────────────────────────────────────────── */
.input-area {
    padding: 16px 24px;
    background: var(--bg-white);
    border-top: 1px solid var(--border-light);
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

#messageInput {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px;
    font-family: inherit;
    resize: none;
    min-height: 48px;
    max-height: 150px;
    transition: var(--transition);
    outline: none;
    line-height: 1.5;
}

#messageInput:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

#btnSend {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    font-size: 20px;
    flex-shrink: 0;
}

/* ─── Loading Overlay ───────────────────────────────────────────── */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    gap: 16px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ─── 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(--secondary);
}

/* ─── Responsive ────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .docs-panel {
        width: 100%;
        position: fixed;
        top: 65px;
        right: 0;
        bottom: 0;
        z-index: 50;
    }

    .message {
        max-width: 95%;
    }

    .modal {
        width: 95%;
    }
}

/* ─── Typing Indicator ──────────────────────────────────────────── */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-light);
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}
