/* DeepAgent Chat - Custom Styles */
:root {
    --sidebar-width: 280px;
    --header-height: 56px;
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --bg-dark: #1a1a2e;
    --bg-sidebar: #16213e;
    --bg-chat: #0f3460;
    --text-light: #e2e8f0;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --user-bubble: #6366f1;
    --ai-bubble: #1e293b;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
}

* { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #0f172a;
    color: #e2e8f0;
    margin: 0;
    height: 100vh;
    overflow: hidden;
}

/* ============== Auth Pages ============== */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    padding: 20px;
}
.auth-card {
    background: rgba(30, 41, 59, 0.95);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5);
}
.auth-card .logo {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
    text-align: center;
    margin-bottom: 8px;
}
.auth-card .subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 24px;
    font-size: 0.9rem;
}
.auth-card .text-muted { color: var(--text-muted); }
.auth-card .form-label { color: var(--text-light); font-size: 0.85rem; }
.auth-card .form-control {
    background: #1e293b;
    border: 1px solid var(--border-color);
    color: var(--text-light);
    border-radius: 8px;
    padding: 10px 14px;
}
.auth-card .form-control:focus {
    background: #334155;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.2);
}
.auth-card .btn-primary {
    background: var(--primary);
    border: none;
    padding: 10px;
    border-radius: 8px;
    font-weight: 600;
    width: 100%;
}
.auth-card .btn-primary:hover { background: var(--primary-dark); }
.auth-link { color: var(--primary); text-decoration: none; }
.auth-link:hover { text-decoration: underline; }

/* ============== Landing Page ============== */
.landing-wrapper {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    text-align: center;
    padding: 20px;
}
.landing-wrapper h1 { font-size: 3rem; font-weight: 800; color: #fff; margin-bottom: 12px; }
.landing-wrapper h1 span { color: var(--primary); }
.landing-wrapper p { color: var(--text-muted); font-size: 1.1rem; max-width: 600px; margin-bottom: 32px; }
.landing-wrapper .btn {
    padding: 12px 32px;
    border-radius: 10px;
    font-weight: 600;
    margin: 0 6px;
}
.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 20px;
    max-width: 1000px;
    margin-top: 48px;
}
.feature-card {
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
    text-align: left;
}
.feature-card i { font-size: 1.5rem; color: var(--primary); margin-bottom: 12px; }
.feature-card h5 { color: #fff; font-size: 1rem; }
.feature-card p { color: var(--text-muted); font-size: 0.85rem; margin: 0; }

/* ============== Chat Layout ============== */
.chat-container {
    display: flex;
    height: 100vh;
}
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}
.sidebar-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.sidebar-header .brand { font-weight: 700; font-size: 1rem; color: var(--primary); }
.sidebar-header .btn { padding: 4px 10px; font-size: 0.8rem; }
.conv-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.conv-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background 0.15s;
    font-size: 0.85rem;
}
.conv-item:hover { background: rgba(99,102,241,0.1); }
.conv-item.active { background: rgba(99,102,241,0.2); }
.conv-item .conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .conv-actions { display: none; margin-left: 8px; }
.conv-item:hover .conv-actions { display: flex; gap: 4px; }
.conv-item .conv-actions .btn { padding: 2px 6px; font-size: 0.7rem; }
.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
}
.sidebar-footer .user-info { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }

.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.chat-header {
    height: var(--header-height);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 12px;
    background: var(--bg-dark);
}
.chat-header select { background: #1e293b; border: 1px solid var(--border-color); color: var(--text-light); border-radius: 8px; padding: 6px 12px; font-size: 0.85rem; }
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--bg-chat);
}
.message-row { display: flex; margin-bottom: 20px; }
.message-row.user { justify-content: flex-end; }
.message-row.assistant { justify-content: flex-start; }
.message-bubble {
    max-width: 75%;
    padding: 12px 18px;
    border-radius: 14px;
    line-height: 1.6;
    font-size: 0.9rem;
    word-break: break-word;
}
.message-row.user .message-bubble { background: var(--user-bubble); border-bottom-right-radius: 4px; }
.message-row.assistant .message-bubble { background: var(--ai-bubble); border: 1px solid var(--border-color); border-bottom-left-radius: 4px; }
.message-bubble pre {
    background: #0f172a;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 0.8rem;
}
.message-bubble code { font-size: 0.8rem; }
.message-time { font-size: 0.7rem; color: var(--text-muted); }
.message-meta { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; gap: 8px; }
.message-meta .msg-usage { font-size: 0.68rem; color: var(--text-muted); }
.btn-copy { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 2px 4px; font-size: 0.75rem; opacity: 0; transition: opacity 0.15s; }
.message-bubble:hover .btn-copy { opacity: 1; }
.btn-copy:hover { color: var(--primary); }

.chat-input-area {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-dark);
}
.chat-input-area form { display: flex; gap: 10px; align-items: flex-end; }
.chat-input-area textarea {
    flex: 1;
    background: #1e293b;
    border: 1px solid var(--border-color);
    color: var(--text-light);
    border-radius: 12px;
    padding: 10px 14px;
    resize: none;
    min-height: 44px;
    max-height: 150px;
    font-size: 0.9rem;
}
.chat-input-area textarea:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px rgba(99,102,241,0.15); }
.chat-input-area .btn-send {
    background: var(--primary);
    border: none;
    border-radius: 12px;
    padding: 10px 20px;
    font-weight: 600;
    white-space: nowrap;
}
.chat-input-area .btn-send:hover { background: var(--primary-dark); }
.chat-input-area .btn-file {
    background: #1e293b;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 10px 14px;
    cursor: pointer;
    color: var(--text-light);
}
.file-attachment {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(99,102,241,0.2);
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 0.8rem;
    margin-right: 8px;
}

/* Dark-themed card-body (profile, admin cards) */
.card-body { color: var(--text-light); }
.card-body h5 { color: #fff; }
.card-body strong { color: #fff; }

/* Profile / user-facing settings — same dark theme as admin */
.main-area .form-label { color: var(--text-light); font-size: 0.85rem; }
.main-area .form-control {
    background: #0f172a;
    border: 1px solid var(--border-color);
    color: var(--text-light);
    border-radius: 8px;
}
.main-area .form-control:focus {
    background: #1e293b;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}
.main-area .text-muted { color: var(--text-muted) !important; }

/* ============== Admin Layout ============== */
.admin-wrapper {
    display: flex;
    height: 100vh;
}
.admin-sidebar {
    width: 240px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}
.admin-sidebar .brand { padding: 16px 20px; font-weight: 700; color: var(--primary); border-bottom: 1px solid var(--border-color); font-size: 1rem; }
.admin-nav { flex: 1; overflow-y: auto; padding: 12px; }
.admin-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    color: var(--text-light);
    text-decoration: none;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 2px;
    transition: background 0.15s;
}
.admin-nav a:hover, .admin-nav a.active { background: rgba(99,102,241,0.2); color: #fff; }
.admin-nav a i { width: 18px; text-align: center; }
.admin-nav .nav-section { font-size: 0.7rem; color: var(--text-muted); padding: 12px 14px 6px; text-transform: uppercase; letter-spacing: 0.05em; }
.admin-main {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background: var(--bg-dark);
}
.admin-main h4 { margin-bottom: 20px; color: #fff; }
.admin-main .form-label { color: var(--text-light); font-size: 0.85rem; }
.admin-main .form-control, .admin-main .form-select {
    background: #1e293b;
    border: 1px solid var(--border-color);
    color: var(--text-light);
    border-radius: 8px;
}
.admin-main .form-control:focus, .admin-main .form-select:focus {
    background: #334155;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}
.admin-main .text-muted { color: var(--text-muted) !important; }
.stat-card {
    background: rgba(30,41,59,0.6);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
}
.stat-card .stat-num { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-card .stat-label { color: var(--text-muted); font-size: 0.8rem; }
.admin-table {
    background: #1e293b;
    border-radius: 12px;
    overflow: hidden;
}
.admin-table th {
    background: #0f172a;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-color);
    padding: 12px 16px;
}
.admin-table td { padding: 12px 16px; border-bottom: 1px solid rgba(51,65,85,0.5); font-size: 0.85rem; vertical-align: middle; }
.admin-table tr:hover td { background: rgba(99,102,241,0.05); }
.admin-table .btn-outline-light {
    color: var(--text-muted);
    border-color: var(--text-muted);
}
.admin-table .btn-outline-light:hover {
    color: #fff;
    background: rgba(99,102,241,0.2);
    border-color: var(--primary);
}
.badge-role { font-size: 0.75rem; padding: 4px 10px; border-radius: 20px; }
.badge-role.admin { background: rgba(239,68,68,0.2); color: #ef4444; }
.badge-role.vip { background: rgba(245,158,11,0.2); color: #f59e0b; }
.badge-role.user { background: rgba(99,102,241,0.2); color: #6366f1; }
.modal-content { background: #1e293b; color: var(--text-light); border: 1px solid var(--border-color); }
.modal-header { border-bottom: 1px solid var(--border-color); }
.modal-footer { border-top: 1px solid var(--border-color); }
.modal .form-control, .modal .form-select {
    background: #0f172a;
    border: 1px solid var(--border-color);
    color: var(--text-light);
}
.modal .form-control:focus, .modal .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}
.modal .btn-close { filter: invert(1); }

/* ============== Profile ============== */
.profile-wrapper {
    max-width: 600px;
    margin: 40px auto;
    padding: 0 20px;
}

/* ============== Mobile Responsive ============== */
@media (max-width: 768px) {
    .sidebar { position: fixed; left: -100%; z-index: 1000; width: 85%; max-width: 300px; transition: left 0.3s; height: 100vh; }
    .sidebar.open { left: 0; }
    .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 999; }
    .sidebar-overlay.open { display: block; }
    .chat-header { padding: 0 12px; }
    .chat-header select { font-size: 0.75rem; padding: 4px 8px; }
    .chat-messages { padding: 12px; }
    .chat-input-area { padding: 12px; }
    .chat-input-area form { gap: 6px; }
    .chat-input-area textarea { font-size: 0.85rem; }
    .message-bubble { max-width: 90%; }
    .admin-sidebar { position: fixed; left: -100%; z-index: 1000; width: 260px; transition: left 0.3s; height: 100vh; }
    .admin-sidebar.open { left: 0; }
    .landing-wrapper h1 { font-size: 2rem; }
    .features-grid { grid-template-columns: 1fr; }
    .auth-card { padding: 24px; }
}

/* ============== Scrollbar ============== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #475569; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #64748b; }

/* ============== Markdown in messages ============== */
.markdown-body { line-height: 1.7; }
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 { margin: 12px 0 6px; }
.markdown-body h1 { font-size: 1.3rem; border-bottom: 1px solid var(--border-color); padding-bottom: 4px; }
.markdown-body h2 { font-size: 1.15rem; }
.markdown-body h3 { font-size: 1.05rem; }
.markdown-body p { margin: 4px 0 8px; }
.markdown-body ul, .markdown-body ol { padding-left: 22px; margin: 4px 0 8px; }
.markdown-body li { margin: 2px 0; }
.markdown-body blockquote { border-left: 3px solid var(--primary); padding: 4px 14px; margin: 8px 0; color: var(--text-muted); background: rgba(99,102,241,0.05); border-radius: 0 6px 6px 0; }
.markdown-body table { font-size: 0.8rem; border-collapse: collapse; margin: 8px 0; width: 100%; }
.markdown-body table th, .markdown-body table td { padding: 6px 10px; border: 1px solid var(--border-color); text-align: left; }
.markdown-body table th { background: rgba(99,102,241,0.15); font-weight: 600; }
.markdown-body table tr:nth-child(even) { background: rgba(255,255,255,0.02); }
.markdown-body code { background: rgba(99,102,241,0.15); padding: 2px 6px; border-radius: 4px; font-size: 0.82rem; font-family: 'Consolas', 'Monaco', monospace; }
.markdown-body pre { background: #0f172a; padding: 12px 16px; border-radius: 8px; overflow-x: auto; margin: 8px 0; border: 1px solid var(--border-color); }
.markdown-body pre code { background: none; padding: 0; font-size: 0.8rem; color: #e2e8f0; }
.markdown-body hr { border: none; border-top: 1px solid var(--border-color); margin: 12px 0; }
.markdown-body a { color: var(--primary); text-decoration: underline; }
.markdown-body img { max-width: 100%; border-radius: 8px; }
.markdown-body strong { color: #fff; }

/* ============== Light theme ============== */
.light-theme {
    --bg-dark: #ffffff;
    --bg-sidebar: #f8fafc;
    --bg-chat: #f1f5f9;
    --text-light: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --user-bubble: #6366f1;
    --ai-bubble: #ffffff;
    --primary: #6366f1;
    --primary-dark: #4f46e5;
}
.light-theme body { background: #f1f5f9; color: #1e293b; }
.light-theme .auth-wrapper { background: linear-gradient(135deg, #e0e7ff 0%, #f0f0ff 50%, #e8f0fe 100%); }
.light-theme .auth-card { background: rgba(255,255,255,0.95); border-color: #e2e8f0; }
.light-theme .auth-card .form-control { background: #f1f5f9; color: #1e293b; border-color: #e2e8f0; }
.light-theme .auth-card .form-control:focus { background: #fff; }
.light-theme .landing-wrapper { background: linear-gradient(135deg, #e0e7ff 0%, #f0f0ff 50%, #e8f0fe 100%); }
.light-theme .landing-wrapper h1 { color: #1e293b; }
.light-theme .feature-card { background: rgba(255,255,255,0.9); }
.light-theme .feature-card h5 { color: #1e293b; }
.light-theme .chat-header select { background: #ffffff; color: #1e293b; border-color: #e2e8f0; }
.light-theme .chat-input-area textarea { background: #ffffff; color: #1e293b; border-color: #e2e8f0; }
.light-theme .chat-input-area textarea:focus { border-color: var(--primary); }
.light-theme .chat-input-area .btn-file { background: #ffffff; color: #1e293b; border-color: #e2e8f0; }
.light-theme .admin-sidebar { background: #f8fafc; }
.light-theme .admin-sidebar .brand { color: var(--primary); }
.light-theme .admin-sidebar .admin-nav a { color: #475569; }
.light-theme .admin-sidebar .admin-nav a:hover { background: rgba(99,102,241,0.08); color: var(--primary); }
.light-theme .admin-sidebar .admin-nav a.active { background: rgba(99,102,241,0.12); color: var(--primary); }
.light-theme .admin-sidebar .admin-nav .nav-section { color: #94a3b8; }
.light-theme .admin-main { background: #ffffff; }
.light-theme .admin-main .form-control, .light-theme .admin-main .form-select { background: #ffffff; color: #1e293b; border-color: #e2e8f0; }
.light-theme .admin-table { background: #ffffff; }
.light-theme .admin-table th { background: #f8fafc; color: #64748b; }
.light-theme .admin-table td { border-color: #f1f5f9; }
.light-theme .admin-main .form-label { color: #1e293b; }
.light-theme .admin-main .nav-tabs .nav-link.active { background: #ffffff; color: #1e293b; border-color: #e2e8f0; }
.light-theme .admin-main .nav-tabs .nav-link:not(.active) { color: #64748b; }
.light-theme .admin-main .form-text.text-muted { color: #64748b !important; }
.light-theme .admin-main .form-check-label { color: #1e293b; }
.light-theme .modal-content { background: #ffffff; color: #1e293b; }
.light-theme .modal .form-control, .light-theme .modal .form-select { background: #f1f5f9; color: #1e293b; border-color: #e2e8f0; }
.light-theme .stat-card { background: rgba(248,250,252,0.8); }
.light-theme .message-row.user .message-bubble,
.light-theme .message-row.assistant .message-bubble { background: #ffffff; }
.light-theme .markdown-body strong { color: #1e293b; }
.light-theme .markdown-body pre { background: #f8fafc; }
.light-theme .markdown-body pre code { color: #1e293b; }
.light-theme .sidebar-header .brand { color: var(--primary); }
.light-theme .card-body strong { color: #1e293b; }
.light-theme .card-body h5 { color: #1e293b; }
.light-theme .markdown-body table th { background: rgba(99,102,241,0.08); }
.light-theme ::-webkit-scrollbar-thumb { background: #cbd5e1; }
.light-theme .btn-theme-toggle { color: #1e293b; border-color: #e2e8f0; }
.light-theme .btn-theme-toggle:hover { background: #f1f5f9; }
.light-theme .main-area .card,
.light-theme .profile-wrapper .card {
    background: #ffffff !important;
    border-color: #e2e8f0 !important;
}
.light-theme .main-area .card-body h5 { color: #1e293b; }
.light-theme .main-area .card-body strong { color: #1e293b; }
.light-theme .main-area .card-body .text-muted { color: #64748b !important; }
.light-theme .main-area .form-control {
    background: #ffffff;
    color: #1e293b;
    border-color: #d1d5db;
}
.light-theme .main-area .form-control:focus {
    background: #ffffff;
    border-color: var(--primary);
}

.light-theme .main-area .btn-outline-light,
.light-theme .conv-list .btn-outline-light,
.light-theme .chat-header .btn-outline-light,
.light-theme .sidebar-footer .btn-outline-light,
.light-theme .conv-item .btn-outline-light,
.light-theme .admin-main .btn-outline-light {
    color: #64748b; border-color: #cbd5e1;
}
.light-theme .main-area .btn-outline-light:hover,
.light-theme .conv-list .btn-outline-light:hover,
.light-theme .chat-header .btn-outline-light:hover,
.light-theme .sidebar-footer .btn-outline-light:hover,
.light-theme .conv-item .btn-outline-light:hover,
.light-theme .admin-main .btn-outline-light:hover {
    color: #1e293b; background: #f1f5f9; border-color: #94a3b8;
}

/* ============== Theme toggle button ============== */
.btn-theme-toggle {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-light);
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.15s;
}
.btn-theme-toggle:hover { background: rgba(99,102,241,0.1); }

/* ============== Toast ============== */
.toast-container { position: fixed; top: 16px; right: 16px; z-index: 9999; }

/* ============== Tool call group (collapsible, all tools in one) ============== */
.tool-wrapper { flex-direction: column; align-items: flex-start; margin-bottom: 8px; }
.tool-toggle-bubble {
    background: rgba(245,158,11,0.12) !important;
    border: 1px solid rgba(245,158,11,0.25) !important;
    font-size: 0.8rem; padding: 6px 12px !important;
    cursor: pointer; user-select: none;
    display: flex; align-items: center; gap: 8px;
}
.tool-toggle-bubble:hover { background: rgba(245,158,11,0.2) !important; }
.tool-toggle-bubble i.fa-cog { color: var(--warning); }
.tool-toggle-bubble i.fa-check-circle { color: var(--success); }
.tool-chevron { margin-left: auto; transition: transform 0.2s; color: var(--text-muted); font-size: 0.7rem; }
.tool-details { width: 100%; margin-top: 4px; }
.tool-call-entry {
    background: rgba(30,41,59,0.6) !important;
    border: 1px solid var(--border-color) !important;
    font-size: 0.75rem; padding: 5px 10px !important;
    margin-bottom: 3px;
}
.tool-call-entry i.fa-cog { color: var(--warning); }
.tool-call-entry i.fa-check-circle { color: var(--success); }
.tool-pending { color: var(--text-muted); font-style: italic; }
.tool-result-pre {
    background: rgba(0,0,0,0.3); margin: 3px 0 0; padding: 5px 8px;
    border-radius: 4px; font-size: 0.68rem; max-height: 100px; overflow-y: auto;
    white-space: pre-wrap; word-break: break-all; color: var(--text-muted);
}

/* ============== Cursor blink for streaming ============== */
.cursor-blink { animation: blink 1s step-end infinite; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
