:root {
    --bg-color: #ffffff;
    --sidebar-bg: #f8fafc;
    --chat-user-bg: #f1f5f9;
    --chat-ai-bg: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --accent-color: #1565C0; /* Modern Enterprise Blue */
    --accent-hover: #0d47a1;
    --danger: #ef4444;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
}

.sidebar-header {
    padding: 1.25rem 1rem;
}

.new-chat-btn {
    width: 100%;
    padding: 12px 16px;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.new-chat-btn:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
    box-shadow: var(--shadow-md);
}

.new-chat-btn svg {
    width: 18px;
    height: 18px;
    color: var(--accent-color);
}

.search-container {
    padding: 0 1rem 1rem 1rem;
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 12px;
    width: 16px;
    height: 16px;
    color: var(--text-secondary);
}

.search-input {
    width: 100%;
    padding: 10px 12px 10px 36px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background-color: var(--bg-color);
    color: var(--text-primary);
    outline: none;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.search-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.1);
}

.chat-history-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 1rem;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.history-item {
    padding: 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: all 0.2s ease;
    font-weight: 500;
}

.history-item:hover {
    background-color: #e2e8f0;
    color: var(--text-primary);
}

.history-item.active {
    background-color: #e0f2fe;
    color: var(--accent-color);
}

.history-item .actions {
    display: none;
    gap: 8px;
}

.history-item:hover .actions {
    display: flex;
}

.history-item .actions button {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    padding: 2px;
    transition: all 0.2s ease;
}

.history-item .actions button:hover {
    color: var(--danger);
    background-color: #fee2e2;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
}

.danger-btn {
    width: 100%;
    padding: 12px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.danger-btn svg {
    width: 16px;
    height: 16px;
}

.danger-btn:hover {
    background: #fee2e2;
    color: var(--danger);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    width: calc(100% - 280px);
    background-color: var(--bg-color);
}

.mobile-menu-btn {
    display: none;
    position: absolute;
    top: 16px;
    left: 16px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 8px;
    color: var(--text-primary);
    cursor: pointer;
    z-index: 101;
    box-shadow: var(--shadow-sm);
}

.mobile-menu-btn svg {
    width: 20px;
    height: 20px;
}

.chat-window {
    flex: 1;
    overflow-y: auto;
    padding: 0 0 2rem 0;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
}

.welcome-screen {
    margin: auto;
    text-align: center;
    color: var(--text-primary);
    max-width: 600px;
    padding: 2rem;
    animation: fadeIn 0.5s ease-out;
}

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

.welcome-logo {
    width: 64px;
    height: 64px;
    background-color: #e0f2fe;
    color: var(--accent-color);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.5rem auto;
}

.welcome-logo svg {
    width: 32px;
    height: 32px;
}

.welcome-screen h1 {
    font-size: 2.25rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    letter-spacing: -0.025em;
}

.welcome-subtitle {
    font-size: 1.1rem;
    color: var(--text-secondary);
}

/* Chat Messages */
.message-row {
    padding: 2rem 0;
    width: 100%;
    display: flex;
    justify-content: center;
}

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

.message-row.ai {
    background-color: var(--sidebar-bg);
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

.message-content {
    width: 100%;
    max-width: 850px;
    display: flex;
    gap: 1.5rem;
    padding: 0 1.5rem;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    flex-shrink: 0;
    color: #ffffff;
    box-shadow: var(--shadow-sm);
}

.avatar.user-avatar {
    background-color: #0f172a;
}

.avatar.ai-avatar {
    background-color: var(--accent-color);
}

.message-body {
    flex: 1;
    min-width: 0;
    line-height: 1.6;
    color: var(--text-primary);
    font-size: 1rem;
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.msg-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-secondary);
    font-weight: 400;
    font-size: 0.8rem;
}

.msg-actions button {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.msg-actions button:hover {
    color: var(--accent-color);
    background-color: #e0f2fe;
}

/* Result Cards (structured DB rows rendered as cards instead of plain text) */
.result-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
    margin-top: 1rem;
}
.result-card {
    background: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s, transform 0.2s;
}
.result-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}
.result-card-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
    margin-bottom: 8px;
    line-height: 1.4;
}
.result-card-toggle {
    background: none;
    border: 1px solid var(--accent-color);
    color: var(--accent-color);
    font-size: 0.78rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
}
.result-card-toggle:hover {
    background-color: var(--accent-color);
    color: #ffffff;
}
.result-card-line {
    display: flex;
    gap: 6px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-top: 4px;
    line-height: 1.4;
}
.result-card-label {
    font-weight: 500;
    color: var(--text-secondary);
    flex-shrink: 0;
}
.result-card-value {
    color: var(--text-primary);
}

/* Markdown Styles */
.message-text {
    word-wrap: break-word;
}
.message-text p { margin-bottom: 1rem; }
.message-text p:last-child { margin-bottom: 0; }
.message-text h1, .message-text h2, .message-text h3 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    font-weight: 600;
}
.message-text ul, .message-text ol {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}
.message-text li {
    margin-bottom: 0.5rem;
}
.message-text pre {
    background-color: #0f172a; /* Dark background for code blocks for better contrast */
    border-radius: var(--radius-md);
    padding: 1.25rem;
    margin: 1.25rem 0;
    overflow-x: auto;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}
.message-text code {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.85em;
    background-color: #f1f5f9;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    color: #db2777;
}
.message-text pre code {
    background: none;
    padding: 0;
    color: #f8fafc;
}
.message-text table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.25rem 0;
    font-size: 0.9rem;
}
.message-text th, .message-text td {
    border: 1px solid var(--border-color);
    padding: 0.75rem;
    text-align: left;
}
.message-text th {
    background-color: var(--sidebar-bg);
    font-weight: 600;
}

/* Input Area */
.input-area {
    padding: 0 1.5rem 2rem 1.5rem;
    width: 100%;
    display: flex;
    justify-content: center;
    background: linear-gradient(180deg, transparent, var(--bg-color) 30%);
}

.input-wrapper {
    width: 100%;
    max-width: 850px;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.controls-top {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 8px;
    min-height: 32px;
}

.hidden {
    display: none !important;
}

.action-pill-btn {
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 6px 16px;
    border-radius: var(--radius-full);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
}
.action-pill-btn:hover {
    background-color: #f8fafc;
    box-shadow: var(--shadow-md);
}
.action-pill-btn svg { width: 14px; height: 14px; }
#stop-btn:hover { color: var(--danger); border-color: var(--danger); }
#regenerate-btn:hover { color: var(--accent-color); border-color: var(--accent-color); }

.input-box {
    display: flex;
    align-items: flex-end;
    background-color: #f8fafc;
    border-radius: var(--radius-lg);
    padding: 8px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
}

.input-box:focus-within {
    border-color: var(--accent-color);
    background-color: var(--bg-color);
    box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.1);
}

.upload-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    margin-bottom: 2px;
}

.upload-btn:hover {
    background-color: #e2e8f0;
    color: var(--text-primary);
}

.upload-btn svg {
    width: 20px;
    height: 20px;
}

.textarea-container {
    flex: 1;
    padding: 0 12px;
}

textarea {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    padding: 10px 0;
    resize: none;
    outline: none;
    max-height: 200px;
    font-size: 1rem;
    line-height: 1.5;
}

textarea::placeholder {
    color: #94a3b8;
}

.send-btn {
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    margin-bottom: 2px;
}

.send-btn:hover:not(:disabled) {
    background-color: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.send-btn:active:not(:disabled) {
    transform: translateY(0);
}

.send-btn:disabled {
    background-color: #e2e8f0;
    color: #94a3b8;
    cursor: not-allowed;
}

.send-btn svg {
    width: 18px;
    height: 18px;
    position: relative;
    left: -1px;
}

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 12px;
    font-size: 0.75rem;
    color: #94a3b8;
}

.footer-note {
    text-align: center;
    flex: 1;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toast {
    background-color: #0f172a;
    color: white;
    padding: 14px 24px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 0.95rem;
    font-weight: 500;
    animation: slideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1), fadeOut 0.3s ease 4.7s forwards;
}

@keyframes slideIn {
    from { transform: translateX(100%) scale(0.95); opacity: 0; }
    to { transform: translateX(0) scale(1); opacity: 1; }
}

@keyframes fadeOut {
    to { opacity: 0; transform: translateY(-10px); }
}

/* Typing indicator */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background-color: #f1f5f9;
    border-radius: 12px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background-color: var(--accent-color);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0s; }

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

/* Responsive Design */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
    }

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

    .main-content {
        width: 100%;
    }

    .mobile-menu-btn {
        display: block;
    }

    .message-content {
        padding: 0 1rem;
        gap: 1rem;
    }
    
    .input-area {
        padding: 0 1rem 1rem 1rem;
    }
    
    .footer-note {
        display: none;
    }
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(15, 23, 42, 0.5); /* semi-transparent dark */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 1;
    transition: opacity 0.2s ease;
}

.modal.hidden {
    display: none !important;
    opacity: 0;
}

.modal-content {
    background-color: var(--bg-color);
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 400px;
    text-align: center;
    animation: slideUp 0.3s ease-out;
}

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

.modal-content h3 {
    margin-bottom: 12px;
    color: var(--text-primary);
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 24px;
    font-size: 0.95rem;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
}

.modal-btn {
    padding: 10px 24px;
    border-radius: var(--radius-md);
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    font-size: 0.95rem;
}

.secondary-btn {
    background-color: #f1f5f9;
    color: var(--text-primary);
}

.secondary-btn:hover {
    background-color: #e2e8f0;
}

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

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

/* Record Full-Details Popup */
.record-modal-content {
    max-width: 640px;
    max-height: 80vh;
    overflow-y: auto;
    text-align: left;
    position: relative;
    padding-top: 36px;
}
.record-modal-close {
    position: absolute;
    top: 12px;
    right: 14px;
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
}
.record-modal-close:hover {
    color: var(--text-primary);
}
.record-modal-loading {
    color: var(--text-secondary);
    padding: 20px 0;
    text-align: center;
}
#record-modal-body .result-card-line {
    padding: 6px 0;
    border-bottom: 1px solid var(--border-color);
}
#record-modal-body .result-card-line:last-child {
    border-bottom: none;
}
#record-modal-body .result-card-label {
    min-width: 140px;
}

/* ── Model Selector ─────────────────────────── */
.model-selector {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 4px 2px 4px;
    flex-wrap: wrap;
}

.model-selector-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.03em;
    margin-right: 2px;
}

.model-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 12px;
    border-radius: var(--radius-full);
    border: 1.5px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.18s ease;
    white-space: nowrap;
}

.model-pill:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
    background: rgba(21, 101, 192, 0.05);
}

.model-pill.active {
    border-color: var(--accent-color);
    background: var(--accent-color);
    color: #ffffff;
}

.model-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.groq-dot  { background: #a78bfa; }   /* purple – Llama/Groq */
.gemini-dot{ background: #4ade80; }   /* green – Gemini */
.claude-dot{ background: #fb923c; }   /* orange – Claude */