/* ============================================================
   ROOT VARIABLES
   ============================================================ */
:root {
    --bg-main: #0F172A;
    --bg-card: #1E293B;
    --bg-hover: #273449;
    --text-primary: #F8FAFC;
    --text-secondary: #94A3B8;
    --border-color: #2D3F55;
    --primary-color: #10A37F;
    --primary-hover: #0d8a6b;
    --primary-glow: rgba(16, 163, 127, 0.25);
    --sidebar-width: 280px;
    --danger: #EF4444;
    --radius: 0.75rem;
}

[data-bs-theme="light"] {
    --bg-main: #F1F5F9;
    --bg-card: #FFFFFF;
    --bg-hover: #E2E8F0;
    --text-primary: #0F172A;
    --text-secondary: #64748B;
    --border-color: #CBD5E1;
    --primary-glow: rgba(16, 163, 127, 0.15);
}

/* ============================================================
   BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ============================================================
   GLASS PANEL
   ============================================================ */
.glass-panel {
    background: rgba(30, 41, 59, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.06);
}
[data-bs-theme="light"] .glass-panel {
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid rgba(0, 0, 0, 0.06);
}

/* ============================================================
   LAYOUT
   ============================================================ */
#wrapper {
    height: 100vh;
    overflow: hidden;
    display: flex;
}

/* Auth pages don't have a sidebar — override the wrapper styles */
body.auth-page #wrapper {
    height: auto;
    overflow: visible;
    min-height: 100vh;
}

#sidebar-wrapper {
    min-width: var(--sidebar-width);
    max-width: var(--sidebar-width);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: margin 0.25s ease-out;
    height: 100vh;
    overflow: hidden;
}

#page-content-wrapper {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-main);
    height: 100vh;
    overflow: hidden;
}

#wrapper.toggled #sidebar-wrapper {
    margin-left: calc(var(--sidebar-width) * -1);
}

/* ============================================================
   SIDEBAR INTERNALS
   ============================================================ */
.sidebar-heading {
    font-size: 1rem;
    letter-spacing: 0.05em;
    border-color: var(--border-color) !important;
}

.letter-spacing { letter-spacing: 0.06em; }

.chat-list {
    overflow-y: auto;
    flex: 1;
}

.sidebar-search-group .form-control,
.sidebar-search-group .input-group-text {
    background-color: rgba(255,255,255,0.05);
    border-color: var(--border-color);
    color: var(--text-secondary);
    font-size: 0.875rem;
}
[data-bs-theme="light"] .sidebar-search-group .form-control,
[data-bs-theme="light"] .sidebar-search-group .input-group-text {
    background-color: var(--bg-main);
    color: var(--text-secondary);
}
.sidebar-search-group .form-control:focus {
    background-color: rgba(255,255,255,0.08);
    border-color: var(--primary-color);
    color: var(--text-primary);
    box-shadow: none;
}

/* ============================================================
   LIST GROUP / SIDEBAR ITEMS
   ============================================================ */
.list-group-item {
    background-color: transparent;
    color: var(--text-secondary);
    border: none;
    padding: 0.65rem 1rem;
    margin: 0.1rem 0.5rem;
    border-radius: 0.5rem !important;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}
.list-group-item:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}
.list-group-item.active {
    background-color: rgba(16, 163, 127, 0.12) !important;
    color: var(--primary-color) !important;
    font-weight: 600;
}
.list-group-flush > .list-group-item { border-radius: 0.5rem !important; }

/* Chat items with delete button */
.chat-item {
    position: relative;
    gap: 0.5rem;
}
.chat-item-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.delete-chat-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 0.15rem 0.3rem;
    border-radius: 0.3rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, color 0.2s;
    flex-shrink: 0;
    font-size: 0.75rem;
    cursor: pointer;
}
.chat-item:hover .delete-chat-btn {
    opacity: 1;
    pointer-events: all;
}
.delete-chat-btn:hover { color: var(--danger); }

/* ============================================================
   SIDEBAR FOOTER / USER MENU
   ============================================================ */
.sidebar-footer { flex-shrink: 0; }

.user-menu-btn { padding: 0.5rem; border-radius: 0.5rem; transition: background 0.2s; }
.user-menu-btn:hover { background: var(--bg-hover); }

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    font-size: 0.95rem;
}

/* ============================================================
   CUSTOM SCROLLBAR
   ============================================================ */
.custom-scrollbar, .chat-container, .chat-list { overflow-y: auto; }
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background-color: var(--border-color); border-radius: 20px; }
::-webkit-scrollbar-thumb:hover { background-color: var(--text-secondary); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn-primary {
    background-color: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
    font-weight: 500;
    transition: all 0.2s ease;
}
.btn-primary:hover {
    background-color: var(--primary-hover) !important;
    border-color: var(--primary-hover) !important;
    box-shadow: 0 4px 12px var(--primary-glow);
    transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }

/* ============================================================
   TOP NAVBAR
   ============================================================ */
.page-navbar {
    height: 60px;
    border-bottom: 1px solid var(--border-color) !important;
    flex-shrink: 0;
}

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

.message-wrapper {
    display: flex;
    gap: 1rem;
    padding: 0.5rem 1rem;
    max-width: 820px;
    width: 100%;
    margin: 0 auto;
    transition: background 0.15s;
    border-radius: 0.75rem;
    animation: fadeSlideIn 0.3s ease;
}
.message-wrapper:hover { background: rgba(255,255,255,0.02); }

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

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.9rem;
}
.ai-message .message-avatar {
    background-color: var(--primary-color);
    color: white;
    border: none;
}

.message-content {
    padding: 0.85rem 1.25rem;
    border-radius: 0.75rem;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    max-width: calc(100% - 52px);
    line-height: 1.7;
    font-size: 0.95rem;
    word-break: break-word;
}
.user-message .message-content {
    background-color: var(--bg-hover);
    border-color: transparent;
}

/* Message Action Buttons (copy, like, dislike) */
.message-actions {
    display: flex;
    gap: 0.5rem;
    border-top: 1px solid var(--border-color);
    padding-top: 0.5rem;
    opacity: 0;
    transition: opacity 0.2s;
}
.message-wrapper:hover .message-actions { opacity: 1; }

.msg-action-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 0.2rem 0.4rem;
    border-radius: 0.3rem;
    transition: color 0.2s, background 0.2s;
}
.msg-action-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.msg-action-btn.active { color: var(--primary-color); }

/* ============================================================
   MARKDOWN / CODE BLOCKS
   ============================================================ */
.message-content h1, .message-content h2, .message-content h3 {
    margin-top: 1rem; margin-bottom: 0.5rem; font-weight: 600;
}
.message-content p { margin-bottom: 0.75rem; }
.message-content p:last-child { margin-bottom: 0; }
.message-content ul, .message-content ol { padding-left: 1.5rem; margin-bottom: 0.75rem; }
.message-content li { margin-bottom: 0.25rem; }
.message-content blockquote {
    border-left: 3px solid var(--primary-color);
    padding-left: 1rem;
    color: var(--text-secondary);
    margin: 0.75rem 0;
}
.message-content a { color: var(--primary-color); }
.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0;
    font-size: 0.875rem;
}
.message-content th, .message-content td {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    text-align: left;
}
.message-content th { background: var(--bg-hover); font-weight: 600; }

/* Code block wrapper */
.message-content pre {
    background-color: #1a1e2e;
    border-radius: 0.6rem;
    overflow: hidden;
    margin: 0.75rem 0;
    border: 1px solid rgba(255,255,255,0.05);
    position: relative;
}
[data-bs-theme="light"] .message-content pre { background-color: #1e1e2e; }

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0.85rem;
    background: rgba(255,255,255,0.04);
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.code-lang {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #6b7fa3;
    font-family: 'Courier New', monospace;
}

.message-content pre code {
    display: block;
    padding: 0.9rem 1rem;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.85rem;
    overflow-x: auto;
    background: none !important;
    color: inherit;
}

/* Inline code */
.message-content code:not(pre code) {
    background: rgba(16, 163, 127, 0.12);
    color: #10CFA0;
    padding: 0.15rem 0.4rem;
    border-radius: 0.25rem;
    font-size: 0.875em;
    font-family: 'Courier New', monospace;
}

.copy-btn {
    background: rgba(255,255,255,0.08);
    border: none;
    color: #8899bb;
    padding: 0.15rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.72rem;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.copy-btn:hover { background: rgba(255,255,255,0.15); color: white; }

/* ============================================================
   INPUT AREA
   ============================================================ */
.input-area-wrapper {
    padding: 1rem 1.5rem 1.25rem;
    background: linear-gradient(0deg, var(--bg-main) 70%, transparent 100%);
    flex-shrink: 0;
}

.input-container {
    max-width: 820px;
    margin: 0 auto;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    display: flex;
    align-items: flex-end;
    padding: 0.5rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    transition: border-color 0.2s, box-shadow 0.2s;
}
.input-container:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-primary);
    resize: none;
    padding: 0.5rem 0.75rem;
    max-height: 180px;
    min-height: 24px;
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    line-height: 1.5;
}
.chat-input:focus { outline: none; box-shadow: none; }
.chat-input::placeholder { color: var(--text-secondary); }

.send-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.6rem;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0.15rem;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.15s;
    flex-shrink: 0;
}
.send-btn:hover:not(:disabled) {
    background-color: var(--primary-hover);
    transform: scale(1.05);
}
.send-btn:disabled {
    background-color: var(--bg-hover);
    color: var(--text-secondary);
    cursor: not-allowed;
    opacity: 0.6;
}

/* ============================================================
   TYPING INDICATOR
   ============================================================ */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 0.5rem 0.25rem;
    align-items: center;
    min-height: 28px;
}
.typing-dot {
    width: 7px;
    height: 7px;
    background-color: var(--text-secondary);
    border-radius: 50%;
    animation: bounce 1.4s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 100% { transform: translateY(0); opacity: 0.5; }
    50%       { transform: translateY(-5px); opacity: 1; }
}

/* ============================================================
   EMPTY STATE / SUGGESTIONS
   ============================================================ */
.empty-state { display: flex; flex-direction: column; align-items: center; margin: auto; }

.suggestion-chip {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Inter', sans-serif;
}
.suggestion-chip:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: rgba(16, 163, 127, 0.06);
}

/* ============================================================
   MODEL SELECTOR
   ============================================================ */
#model-selector {
    background: rgba(255,255,255,0.05);
    color: var(--text-primary);
    border-color: var(--border-color);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    border-radius: 0.5rem;
}
#model-selector:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--primary-glow);
}
[data-bs-theme="light"] #model-selector { background: var(--bg-card); }

/* ============================================================
   DASHBOARD CARDS
   ============================================================ */
.stat-card {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.5rem;
    transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 0.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ============================================================
   AUTH CARDS
   ============================================================ */
.auth-card {
    max-width: 420px;
    width: 100%;
    margin: 0 auto;
    padding: 2.5rem;
    border-radius: 1rem;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.form-control {
    background-color: rgba(255,255,255,0.04);
    border-color: var(--border-color);
    color: var(--text-primary);
    border-radius: 0.5rem;
    padding: 0.65rem 1rem;
    font-family: 'Inter', sans-serif;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.form-control:focus {
    background-color: rgba(255,255,255,0.06);
    color: var(--text-primary);
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-glow);
}
[data-bs-theme="light"] .form-control { background-color: var(--bg-main); }
[data-bs-theme="light"] .form-control:focus { background-color: var(--bg-card); }

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.app-toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--primary-color);
    color: var(--text-primary);
    padding: 0.85rem 1.25rem;
    border-radius: 0.6rem;
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.9rem;
    min-width: 240px;
    transform: translateX(120%);
    opacity: 0;
    transition: transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.35s ease;
}
.app-toast.show { transform: translateX(0); opacity: 1; }
.app-toast-error { border-left-color: var(--danger); }
.app-toast-error i { color: var(--danger); }
.app-toast i { color: var(--primary-color); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
    #sidebar-wrapper {
        position: fixed;
        z-index: 1000;
        height: 100vh;
        margin-left: calc(var(--sidebar-width) * -1);
    }
    #wrapper.toggled #sidebar-wrapper { margin-left: 0; }

    .message-wrapper { padding: 0.5rem 0; }
    .auth-card { padding: 1.75rem; }
    .input-area-wrapper { padding: 0.75rem 1rem 1rem; }
}

/* ============================================================
   BOOTSTRAP TABLE OVERRIDES
   ============================================================ */
.table {
    color: var(--text-primary);
    border-color: var(--border-color);
}
.table > :not(caption) > * > * {
    background-color: transparent;
    border-bottom-color: var(--border-color);
    color: var(--text-primary);
}
.table-hover > tbody > tr:hover > * {
    background-color: var(--bg-hover);
}
[data-bs-theme="dark"] .dropdown-menu {
    background-color: var(--bg-card);
    border-color: var(--border-color);
}
[data-bs-theme="dark"] .dropdown-item {
    color: var(--text-secondary);
}
[data-bs-theme="dark"] .dropdown-item:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}
.form-select {
    background-color: rgba(255,255,255,0.05);
    border-color: var(--border-color);
    color: var(--text-primary);
}
.form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-glow);
}
[data-bs-theme="light"] .form-select {
    background-color: var(--bg-card);
}

