:root {
    --primary-color: #2563eb;
    --primary-gradient: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    --bg-color: #f0f4f8;
    --chat-bg: #ffffff;
    --text-color: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --user-msg-bg: #eff6ff;
    --bot-msg-bg: #f1f5f9;
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.06);
    --shadow-md: 0 4px 20px rgba(0,0,0,.08);
    --shadow-lg: 0 12px 40px rgba(0,0,0,.12);
}

body {
    font-family: var(--font-family);
    line-height: 1.6;
    margin: 0;
    padding: 0;
    background: linear-gradient(135deg, #eef2f7 0%, #f8fafc 50%, #eef2f7 100%);
    color: var(--text-color);
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 920px;
    width: 95%;
    margin: 1.5rem auto;
    padding: 0;
    background: var(--chat-bg);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    height: 92vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: #fff;
    flex-shrink: 0;
}

header h1 {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: none;
    -webkit-text-fill-color: initial;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-new-chat {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-family: var(--font-family);
}

.btn-new-chat:hover {
    background: var(--bot-msg-bg);
    color: var(--text-color);
}

/* Navigation */
.nav a {
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.88rem;
    padding: 0.4rem 0.85rem;
    border-radius: 8px;
    transition: all 0.2s;
}

.nav a:hover,
.nav a.active {
    color: var(--primary-color);
    background: rgba(37, 99, 235, 0.06);
}

/* Chat Area */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 1.5rem 0.5rem;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.chat-container:empty {
    justify-content: center;
    align-items: center;
}

.message {
    margin-bottom: 0.5rem;
    animation: msgFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    display: flex;
    gap: 0.75rem;
    max-width: 100%;
    position: relative;
}

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

/* Message Avatars */
.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
    margin-top: 4px;
}

.user .msg-avatar {
    background: var(--primary-gradient);
    color: #fff;
    order: 1;
}

.bot .msg-avatar {
    background: var(--secondary-color);
    color: #fff;
}

.msg-body {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    max-width: 72%;
    min-width: 0;
}

.user .msg-body {
    align-items: flex-end;
}

.bot .msg-body {
    align-items: flex-start;
}

.msg-sender {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0 0.25rem;
}

.bot .msg-sender {
    color: var(--primary-color);
}

.user {
    flex-direction: row-reverse;
}

.message-content {
    padding: 0.9rem 1.25rem;
    border-radius: 16px;
    word-wrap: break-word;
    font-size: 0.95rem;
    line-height: 1.65;
    position: relative;
}

/* User Message */
.user .message-content {
    background: var(--primary-gradient);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15);
}

.user .message-content p {
    color: white;
}

/* Bot Message */
.bot .message-content {
    background: var(--bot-msg-bg);
    color: var(--text-color);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border-color);
}

.bot .message-content p {
    color: var(--text-color);
}

.message-content p {
    margin: 0 0 0.6rem 0;
}

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

.message-content ul,
.message-content ol {
    padding-left: 1.25rem;
    margin: 0.6rem 0;
}

.message-content li {
    margin-bottom: 0.25rem;
}

/* Streaming raw text */
.stream-text {
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    font-size: 0.95rem;
    line-height: 1.65;
}

/* Markdown Styles inside Bot Messages */
.bot .message-content pre {
    background: #0f172a;
    color: #e2e8f0;
    padding: 1rem 1.25rem;
    border-radius: 10px;
    overflow-x: auto;
    margin: 0.75rem 0;
    border: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.85rem;
}

.bot .message-content code {
    font-family: 'Fira Code', monospace;
    font-size: 0.88em;
    background: rgba(0, 0, 0, 0.05);
    padding: 0.15em 0.35em;
    border-radius: 4px;
}

.bot .message-content pre code {
    background: transparent;
    padding: 0;
}

.bot .message-content blockquote {
    border-left: 3px solid var(--primary-color);
    padding-left: 0.75rem;
    margin: 0.6rem 0;
    color: var(--text-muted);
}

.bot .message-content a {
    color: var(--primary-color);
    text-decoration: none;
}

.bot .message-content a:hover {
    text-decoration: underline;
}

.bot .message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.75rem 0;
    font-size: 0.88rem;
}

.bot .message-content th,
.bot .message-content td {
    border: 1px solid var(--border-color);
    padding: 0.5rem 0.75rem;
    text-align: left;
}

.bot .message-content th {
    background: var(--bot-msg-bg);
    font-weight: 600;
}

/* Welcome Message */
.welcome-message {
    text-align: center;
    padding: 3rem 2rem 2rem;
    max-width: 100% !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

.welcome-message .welcome-icon {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background: var(--primary-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.25rem;
    color: white;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.welcome-message h2 {
    margin: 0 0 0.5rem;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-color);
    background: none;
    -webkit-text-fill-color: initial;
}

.welcome-message p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.92rem;
    line-height: 1.6;
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
}

.welcome-message .welcome-features {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.welcome-message .welcome-feature {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.welcome-message .welcome-feature svg {
    width: 16px;
    height: 16px;
    color: var(--primary-color);
    flex-shrink: 0;
}

/* Model Selector Bar */
.model-bar {
    display: flex;
    gap: 0.4rem;
    padding: 0.6rem 1.5rem;
    align-items: center;
    flex-shrink: 0;
}

.model-select {
    font-family: var(--font-family);
    font-size: 0.78rem;
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: #fff;
    color: var(--text-muted);
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
    max-width: 180px;
}

.model-select:focus {
    border-color: var(--primary-color);
    color: var(--text-color);
}

.model-select:hover {
    color: var(--text-color);
}

.provider-select {
    font-weight: 500;
}

/* Attachment Bar */
.attachment-bar {
    display: none;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0 0 0.6rem 0;
}

.attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: var(--bot-msg-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.2rem;
    position: relative;
    transition: border-color 0.2s;
}

.attachment-chip:hover {
    border-color: var(--text-muted);
}

.chip-thumb {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 6px;
}

.chip-remove {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: none;
    background: #ef4444;
    color: white;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    opacity: 0;
    transition: opacity 0.2s;
}

.attachment-chip:hover .chip-remove {
    opacity: 1;
}

.chip-remove:hover {
    background: #dc2626;
}

/* Input Area */
.input-area {
    padding: 0.75rem 1.5rem 1.25rem;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.compose-box {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    background: #fff;
    border: 1.5px solid var(--border-color);
    border-radius: 14px;
    padding: 0.4rem 0.4rem 0.4rem 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.compose-box:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.compose-box textarea {
    flex: 1;
    border: none;
    outline: none;
    font-family: var(--font-family);
    font-size: 0.95rem;
    line-height: 1.5;
    padding: 0.5rem 0;
    resize: none;
    background: transparent;
    color: var(--text-color);
    max-height: 150px;
    overflow-y: auto;
    box-shadow: none;
}

.compose-box textarea::placeholder {
    color: var(--text-muted);
}

.btn-attach {
    background: none;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    padding: 0.5rem;
    line-height: 1;
    color: var(--text-muted);
    transition: all 0.2s;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-attach:hover {
    color: var(--text-color);
    background: var(--bot-msg-bg);
}

.btn-send {
    background: var(--primary-color);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    padding: 0.5rem;
    line-height: 1;
    color: #fff;
    transition: all 0.2s;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
}

.btn-send:hover {
    background: var(--secondary-color);
    transform: scale(1.05);
}

.btn-send:active {
    transform: scale(0.95);
}

.btn-send:disabled {
    opacity: 0.35;
    cursor: default;
    transform: none;
}

/* Message Images */
.message-images {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.6rem;
}

.msg-image {
    max-width: 180px;
    max-height: 180px;
    border-radius: 10px;
    object-fit: cover;
    border: 1px solid var(--border-color);
}

.user .msg-image {
    border-color: rgba(255, 255, 255, 0.25);
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1.25rem;
    margin-bottom: 0.5rem;
    animation: msgFadeIn 0.3s ease forwards;
}

.typing-dots {
    display: flex;
    gap: 4px;
    padding: 0.75rem 1rem;
    background: var(--bot-msg-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typingBounce 1.4s infinite ease-in-out both;
}

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

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

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

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Error Message */
.message-error {
    background: #fef2f2 !important;
    border: 1px solid #fecaca !important;
    color: #991b1b !important;
}

.message-error p {
    color: #991b1b !important;
}

/* Global Button Styles (shared with admin pages) */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.95rem;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s ease;
    text-decoration: none;
    background-color: var(--primary-color);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn:hover {
    background-color: var(--secondary-color);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.btn:active {
    transform: translateY(0);
}

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

.btn-secondary:hover {
    background-color: #f8fafc;
    border-color: #cbd5e1;
}

.btn-danger {
    background-color: #ef4444;
    color: white;
}

.btn-danger:hover {
    background-color: #dc2626;
}

/* Global Form Styles */
input[type="text"],
input[type="password"],
input[type="email"] {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    padding: 0.75rem 1rem;
    outline: none;
    background: #fff;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
    box-sizing: border-box;
}

input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Login / auth pages shared styles */
.auth-page body {
    background: linear-gradient(135deg, #eef2f7, #f8fafc);
}

/* Responsive */
@media (max-width: 640px) {
    .container {
        width: 100%;
        height: 100vh;
        margin: 0;
        border-radius: 0;
    }
    header {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .header-actions {
        flex-wrap: wrap;
        gap: 0.3rem;
    }
    .header-actions .nav a {
        font-size: 0.78rem;
        padding: 0.3rem 0.5rem;
    }
    .btn-new-chat {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }
    .msg-body {
        max-width: 85%;
    }
    .message-content {
        font-size: 0.9rem;
        padding: 0.75rem 1rem;
    }
    .chat-container {
        padding: 1rem 0.75rem 0.25rem;
    }
    .input-area {
        padding: 0.5rem 0.75rem 0.75rem;
    }
    .welcome-message {
        padding: 2rem 1rem;
    }
    .welcome-features {
        gap: 1rem;
    }
    .model-bar {
        padding: 0.4rem 0.75rem;
    }
    .compose-box {
        padding: 0.3rem 0.3rem 0.3rem 0.75rem;
    }
    .compose-box textarea {
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1rem;
    }
    .header-actions .nav a {
        font-size: 0.72rem;
        padding: 0.25rem 0.4rem;
    }
    .btn-new-chat {
        font-size: 0.7rem;
        padding: 0.2rem 0.4rem;
    }
    .msg-body {
        max-width: 92%;
    }
    .model-bar {
        flex-wrap: wrap;
    }
    .model-select {
        max-width: 100%;
        flex: 1;
    }
    .welcome-message h2 {
        font-size: 1.1rem;
    }
    .welcome-features {
        flex-direction: column;
        align-items: center;
    }
}
