/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --primary-light: #3b82f6;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-tertiary: #94a3b8;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --topbar-height: 64px;
    --sidebar-width: 280px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Topbar */
.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    z-index: 1000;
    display: flex;
    align-items: center;
    padding: 0 24px;
    justify-content: space-between;
}

.topbar-inner {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand {
    font-weight: 700;
    font-size: 18px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand::before {
    content: "💬";
    font-size: 24px;
}

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

.admin-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    text-decoration: none;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(102, 126, 234, 0.2);
}

.admin-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

.admin-btn svg {
    flex-shrink: 0;
}

.topbar-logout {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
    transition: all 0.2s;
}

.topbar-logout:hover {
    background: var(--border);
}

/* Auth Container */
#authContainer {
    display: none;
    min-height: 100vh;
    padding-top: var(--topbar-height);
    background: linear-gradient(135deg, #3b82f6 0%, #1e40af 100%);
}

.auth-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - var(--topbar-height));
    padding: 24px;
}

.auth-card {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
}

.auth-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
    text-align: center;
}

.auth-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 32px;
}

.auth-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    background: var(--bg-tertiary);
    padding: 4px;
    border-radius: var(--radius-md);
}

.auth-tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.auth-tab.active {
    background: var(--bg-primary);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.auth-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.auth-field label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.auth-field input {
    padding: 12px 14px;
    border: none;
    border-bottom: 1.5px solid var(--border);
    border-radius: 0; /* remove inner rounded box to avoid nested edge */
    font-size: 15px;
    background: var(--bg-primary);
    transition: border-color 0.18s ease, background 0.25s ease;
}

.auth-field input:hover {
    background: var(--bg-secondary);
}

.auth-field input:focus {
    outline: none;
    border-bottom-color: var(--primary);
    box-shadow: none; /* remove outer glow to prevent double border look */
}

/* High contrast focus indicator for accessibility (keyboard navigation) */
.auth-field input:focus-visible {
    border-bottom: 2px solid var(--primary);
}

/* Input with icon wrapper */
.input-with-icon {
    position: relative;
    display: flex;
    align-items: center;
}

.input-with-icon input {
    flex: 1;
    padding-left: 40px;
    padding-right: 40px;
}

.input-icon {
    position: absolute;
    left: 12px;
    color: var(--text-secondary);
    pointer-events: none;
}

.password-toggle {
    position: absolute;
    right: 12px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: color 0.2s;
}

.password-toggle:hover {
    color: var(--text-primary);
}

.password-toggle .eye-icon {
    width: 18px;
    height: 18px;
}

.field-hint {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.auth-submit {
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 15px;
    transition: all 0.2s;
    margin-top: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.auth-submit:hover {
    background: var(--primary-dark);
}

.auth-error {
    padding: 12px;
    background: #fef2f2;
    color: #dc2626;
    font-size: 14px;
    border-radius: var(--radius-sm);
    border: 1px solid #fecaca;
}

.auth-instructions {
    font-size: 14px;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 16px;
}

.auth-instructions a {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
}

/* App Layout */
.app-layout {
    display: none;
    height: calc(100vh - var(--topbar-height));
    margin-top: var(--topbar-height);
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-primary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex-shrink: 0;
    position: relative;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.logo-image {
    max-width: 180px;
    height: auto;
}

.new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px;
    background: var(--primary);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s;
}

.new-chat-btn:hover {
    background: var(--primary-dark);
}

.sidebar-section {
    padding: 20px;
    border-bottom: 1px solid var(--border-light);
}

.section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.session-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.session-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.session-item:hover {
    background: var(--bg-tertiary);
}

.session-item.active {
    background: var(--bg-tertiary);
    font-weight: 500;
}

.session-select {
    flex: 1;
    text-align: left;
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 14px;
}

.session-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.session-menu-trigger {
    opacity: 0;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 18px;
    line-height: 1;
    transition: opacity 0.2s;
}

.session-item:hover .session-menu-trigger {
    opacity: 1;
}

.session-menu-trigger:hover {
    background: var(--border);
}

.session-menu {
    position: absolute;
    top: 100%;
    right: 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    z-index: 10;
    overflow: hidden;
    min-width: 140px;
    margin-top: 4px;
}

.session-menu button {
    width: 100%;
    background: transparent;
    border: none;
    text-align: left;
    padding: 10px 12px;
    font-size: 14px;
    color: var(--text-primary);
    cursor: pointer;
    font-weight: 500;
}

.session-menu button:hover {
    background: var(--bg-tertiary);
}

.session-rename-input {
    width: 100%;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    padding: 6px 8px;
    font-size: 14px;
}

.setting-item {
    margin-bottom: 12px;
}

.setting-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    color: var(--text-primary);
}

.setting-input {
    width: 60px;
    padding: 6px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    text-align: center;
    font-size: 14px;
    color: var(--text-primary);
}

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

/* Document Section */
.document-section {
    border-bottom: 1px solid var(--border-light);
}

.mode-selector {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.mode-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.mode-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--primary-light);
}

.mode-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.mode-btn svg {
    width: 14px;
    height: 14px;
}

.document-upload-area {
    margin-top: 12px;
}

.upload-dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    background: var(--bg-tertiary);
    border: 2px dashed var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 16px;
}

.upload-dropzone:hover {
    border-color: var(--primary-light);
    background: var(--bg-secondary);
}

.upload-dropzone.dragover {
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.05);
}

.upload-dropzone svg {
    color: var(--text-tertiary);
    margin-bottom: 8px;
}

.upload-text {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.upload-link {
    color: var(--primary);
    text-decoration: underline;
    cursor: pointer;
}

.upload-link:hover {
    color: var(--primary-dark);
}

.upload-hint {
    font-size: 12px;
    color: var(--text-tertiary);
}

.upload-progress {
    margin-bottom: 16px;
}

.upload-progress-bar {
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}

.upload-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    border-radius: 3px;
    transition: width 0.3s;
}

.upload-status {
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
}

.document-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.no-documents {
    font-size: 13px;
    color: var(--text-tertiary);
    text-align: center;
    padding: 16px;
}

.document-item {
    position: relative;
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 10px;
    padding: 10px 44px 10px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.document-item:hover {
    background: var(--bg-primary);
    border-color: var(--primary-light);
}

.document-item.selected {
    background: rgba(37, 99, 235, 0.08);
    border-color: var(--primary);
}

.document-info {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    flex: 1;
    min-width: 0;
    cursor: pointer;
}

.document-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.document-details {
    flex: 1;
    min-width: 0;
}

.document-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: normal;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    line-height: 1.3;
    word-break: break-word;
    margin-bottom: 2px;
}

.document-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    row-gap: 4px;
    font-size: 11px;
}

.status-badge {
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-pending {
    background: #fef3c7;
    color: #92400e;
}

.status-processing {
    background: #dbeafe;
    color: #1e40af;
}

.status-completed {
    background: #d1fae5;
    color: #065f46;
}

.status-failed {
    background: #fee2e2;
    color: #991b1b;
}

.document-size {
    color: var(--text-tertiary);
}

.document-delete {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 6px;
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.document-delete:hover {
    background: #fee2e2;
    color: #dc2626;
}

.sidebar-resizer {
    position: absolute;
    top: 0;
    right: -4px;
    width: 8px;
    height: 100%;
    cursor: col-resize;
    z-index: 10;
}

.sidebar-resizer:hover::after {
    content: '';
    position: absolute;
    top: 0;
    left: 3px;
    width: 2px;
    height: 100%;
    background: var(--border);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    overflow: hidden;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 140px;
    scroll-behavior: smooth;
}

.chat-quick-prompts {
    max-width: 800px;
    margin: 0 auto;
    padding: 24px 24px 0;
    position: sticky;
    top: 0;
    z-index: 5;
    background: linear-gradient(var(--bg-secondary) 70%, rgba(248, 250, 252, 0));
}

.chat-quick-prompts:empty {
    display: none;
}

.chat-messages {
    max-width: 800px;
    margin: 0 auto;
    padding: 32px 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Messages */
.message-group {
    display: flex;
    gap: 12px;
    animation: slideIn 0.3s ease-out;
}

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

.user-group {
    flex-direction: row-reverse;
    margin-left: auto;
}

.assistant-group {
    flex-direction: row;
}

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

.user-group .message-avatar {
    background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
}

.assistant-group .message-avatar {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
}

.message-content {
    flex: 1;
    max-width: 85%;
}

.user-group .message-content {
    align-items: flex-end;
}

.assistant-group .message-content {
    align-items: flex-start;
}

.message-bubble {
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    font-size: 15px;
    line-height: 1.6;
}

.user-bubble {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.assistant-bubble {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.message-text p {
    margin-bottom: 12px;
}

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

.message-text ul, .message-text ol {
    margin: 12px 0;
    padding-left: 20px;
}

.message-text li {
    margin-bottom: 8px;
}

.message-text strong {
    font-weight: 600;
}

.message-text em {
    font-style: italic;
}

.quick-prompts-panel {
    padding: 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.quick-prompts-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 600;
}

.quick-prompts-header span:last-child {
    font-weight: 400;
    font-size: 12px;
    color: var(--text-tertiary);
}

.quick-prompts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
}

.quick-prompt {
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    text-align: left;
    box-shadow: var(--shadow-sm);
}

.quick-prompt-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(37, 99, 235, 0.12);
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.quick-prompt-text {
    flex: 1;
}

.quick-prompt:hover {
    border-color: var(--primary);
    color: var(--primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.quick-prompt:hover .quick-prompt-icon {
    background: var(--primary);
    color: #fff;
}

.quick-prompt:disabled,
.quick-prompt.disabled {
    opacity: 0.6;
    cursor: not-allowed;
    box-shadow: none;
    border-color: var(--border);
    color: var(--text-tertiary);
    transform: none;
}

.quick-prompt:disabled .quick-prompt-icon,
.quick-prompt.disabled .quick-prompt-icon {
    background: var(--bg-tertiary);
    color: var(--text-tertiary);
}

.message-text code {
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 13px;
}

.user-bubble .message-text code {
    background: rgba(255, 255, 255, 0.2);
}

.message-time {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 6px;
}

/* Feedback */
.feedback-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-light);
}

.feedback-buttons {
    display: flex;
    gap: 6px;
}

.feedback-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.feedback-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.feedback-like span,
.feedback-dislike span {
    display: block;
}

.feedback-add-comment {
    margin-left: auto;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 500;
    transition: all 0.2s;
}

.feedback-add-comment:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.feedback-comment-area {
    width: 100%;
    margin-top: 8px;
}

.feedback-comment-area textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    resize: vertical;
    font-family: inherit;
    line-height: 1.5;
}

.feedback-comment-area textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.feedback-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

.feedback-submit {
    padding: 8px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    transition: all 0.2s;
}

.feedback-submit:hover {
    background: var(--primary-dark);
}

.feedback-status {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-tertiary);
    font-weight: 500;
}

.feedback-error {
    font-size: 13px;
    color: #dc2626;
    background: #fef2f2;
    padding: 6px 10px;
    border-radius: 4px;
}

/* Typing Indicator */
.typing-indicator {
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.typing-bubble {
    padding: 14px 18px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    border-bottom-left-radius: 4px;
}

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

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

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

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

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

/* Input Container */
.input-container {
    /* border-top: 1px solid var(--border); */
    background: var(--bg-primary);
    padding: 20px 24px;
    position: sticky;
    bottom: 0;
}

.input-wrapper {
    max-width: 800px;
    margin: 0 auto;
}

.message-form {
    width: 100%;
}

.input-area {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: var(--bg-secondary);
    /* Use a single subtle shadow instead of a physical border to avoid double-edge visuals */
    box-shadow: 0 0 0 1px var(--border);
    border-radius: var(--radius-lg);
    padding: 12px 16px;
    transition: box-shadow 0.18s ease, transform 0.12s ease;
}

.input-area:focus-within {
    /* Highlight with a single warm outline on focus, avoid adding another inner border */
    box-shadow: 0 0 0 2px rgba(244,163,0,0.12);
}

.message-textarea {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    max-height: 120px;
    font-family: inherit;
    color: var(--text-primary);
}

.message-textarea::placeholder {
    color: var(--text-tertiary);
}

/* Prevent the global focus-visible outline from appearing on the inner textarea
   — we want the outer .input-area to show the focus state instead. */
.message-textarea:focus-visible {
    outline: none;
}

.send-button {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.send-button:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.send-button:active:not(:disabled) {
    transform: scale(0.95);
}

.send-button:disabled {
    background: var(--border);
    cursor: not-allowed;
}

.send-icon {
    color: white;
}

.send-button:disabled .send-icon {
    color: var(--text-tertiary);
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Welcome Message */
.welcome-message .message-bubble {
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    border-color: #bfdbfe;
}

/* Session Loading/Empty */
.session-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 20px;
    color: var(--text-secondary);
    font-size: 14px;
}

.session-loading .spinner {
    border: 2px solid var(--border);
    border-top: 2px solid var(--primary);
}

.session-empty {
    padding: 20px;
    text-align: center;
    color: var(--text-tertiary);
    font-size: 14px;
}

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

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

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/* Sidebar Toggle (Mobile) */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 72px;
    left: 16px;
    z-index: 1000;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px;
    cursor: pointer;
    box-shadow: var(--shadow-md);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -280px;
        top: var(--topbar-height);
        height: calc(100vh - var(--topbar-height));
        z-index: 999;
        transition: left 0.3s;
    }

    .sidebar.open {
        left: 0;
        box-shadow: var(--shadow-lg);
    }

    .sidebar-toggle {
        display: flex;
    }

    .chat-messages {
        padding: 20px 16px;
    }

    .message-content {
        max-width: 100%;
    }

    .brand::before {
        display: none;
    }

    .topbar {
        padding: 0 16px;
    }

    .brand {
        font-size: 16px;
    }

    .topbar-logout {
        padding: 8px 12px;
        font-size: 13px;
    }

    .topbar-logout span {
        display: none;
    }

    .input-container {
        padding: 16px;
    }

    .auth-card {
        padding: 28px;
    }
}

@media (max-width: 480px) {
    .auth-card {
        padding: 24px;
    }

    .auth-title {
        font-size: 24px;
    }
}

/* Focus visible for accessibility */
*:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Selection styling */
::selection {
    background: rgba(37, 99, 235, 0.2);
    color: var(--text-primary);
}