/* ===== Variables ===== */
:root {
    --primary: #4F46E5;
    --primary-hover: #4338CA;
    --sidebar-width: 250px;
    --sidebar-bg: #1E1B4B;
    --sidebar-text: #C7D2FE;
    --sidebar-active: #4F46E5;
    --topbar-height: 60px;
    --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ===== Global ===== */
body {
    font-family: var(--font-stack);
    background-color: #F5F7FA;
    min-height: 100vh;
}

/* ===== Override Bootstrap primary ===== */
.btn-primary {
    background-color: var(--primary);
    border-color: var(--primary);
}
.btn-primary:hover, .btn-primary:focus {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
}
.btn-outline-primary {
    color: var(--primary);
    border-color: var(--primary);
}
.btn-outline-primary:hover {
    background-color: var(--primary);
    border-color: var(--primary);
}
.text-primary { color: var(--primary) !important; }
.bg-primary { background-color: var(--primary) !important; }
a { color: var(--primary); }
a:hover { color: var(--primary-hover); }

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--sidebar-bg);
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1040;
    flex-direction: column;
}

.sidebar-brand {
    padding: 20px 24px;
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
}

.sidebar-nav {
    padding: 16px 0;
    flex: 1;
}

.sidebar-nav .nav-link {
    color: var(--sidebar-text);
    padding: 10px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.sidebar-nav .nav-link:hover {
    background: rgba(255,255,255,0.08);
    color: white;
}

.sidebar-nav .nav-link.active {
    background: rgba(79,70,229,0.2);
    color: white;
    border-left-color: var(--primary);
    font-weight: 600;
}

.sidebar-nav .nav-link i {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
}

.sidebar-divider {
    border-top: 1px solid rgba(255,255,255,0.1);
    margin: 8px 24px;
}

.sidebar-section-title {
    color: rgba(255,255,255,0.4);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 8px 24px 4px;
    font-weight: 600;
}

/* ===== Mobile Sidebar ===== */
.mobile-topbar {
    background: var(--sidebar-bg);
    z-index: 1050;
}

.sidebar-offcanvas {
    background: var(--sidebar-bg);
    width: var(--sidebar-width);
}

/* ===== Main Content ===== */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Topbar ===== */
.topbar {
    height: var(--topbar-height);
    background: white;
    border-bottom: 1px solid #E5E7EB;
    padding: 0 24px;
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1020;
}

/* ===== Page Content ===== */
.page-content {
    padding: 24px;
    flex: 1;
}

/* ===== Footer ===== */
.page-footer {
    padding: 16px 24px;
    border-top: 1px solid #E5E7EB;
    background: white;
    text-align: center;
    font-size: 0.8rem;
    color: #9CA3AF;
}

/* ===== Stat Cards ===== */
.stat-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    padding: 20px;
    transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.stat-card-body {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.stat-label {
    color: #6B7280;
    font-size: 0.85rem;
    margin-bottom: 4px;
}
.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: #111827;
}
.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

/* ===== Upload Area ===== */
.upload-area {
    border: 2px dashed #D1D5DB;
    border-radius: 12px;
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}
.upload-area:hover, .upload-area.drag-over {
    border-color: var(--primary);
    background: rgba(79,70,229,0.04);
}

/* ===== Widget Preview ===== */
.widget-preview {
    position: relative;
    min-height: 460px;
    background: #F3F4F6;
    border-radius: 12px;
    padding: 16px;
}
.widget-window {
    width: 100%;
    max-width: 320px;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
}
.widget-header {
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.widget-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}
.widget-avatar-default {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.1rem;
}
.widget-messages {
    padding: 16px;
    min-height: 200px;
    max-height: 260px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.widget-msg {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.85rem;
    max-width: 85%;
    line-height: 1.4;
}
.widget-msg.bot {
    background: #F3F4F6;
    color: #374151;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.widget-msg.user {
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}
.widget-input-area {
    padding: 12px 16px;
    border-top: 1px solid #E5E7EB;
    display: flex;
    gap: 8px;
    align-items: center;
}
.widget-fab {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    bottom: 16px;
    right: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* Mini preview (Details page) */
.widget-preview-mini {
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.widget-header-preview {
    padding: 10px 14px;
}
.widget-avatar-mini {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}
.widget-avatar-mini-default {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.8rem;
}
.widget-body-preview {
    padding: 12px 14px;
    background: white;
}
.widget-message-preview {
    background: #F3F4F6;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 0.8rem;
    color: #374151;
}
.widget-input-preview {
    padding: 10px 14px;
    border-top: 1px solid #E5E7EB;
    background: white;
}

/* ===== Chat Bubbles ===== */
.chat-container {
    max-height: 600px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.chat-bubble {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 16px;
}
.chat-user {
    align-self: flex-end;
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}
.chat-bot {
    align-self: flex-start;
    background: #F3F4F6;
    color: #374151;
    border-bottom-left-radius: 4px;
}
.chat-bubble-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 4px;
}
.chat-user .chat-bubble-header span {
    color: rgba(255,255,255,0.8);
}
.chat-bubble-content {
    line-height: 1.5;
    white-space: pre-wrap;
}
.chat-bubble-meta {
    margin-top: 4px;
    text-align: right;
}
.chat-user .chat-bubble-meta span {
    color: rgba(255,255,255,0.6) !important;
}

/* ===== Spin animation ===== */
.spin {
    animation: spin 1s linear infinite;
}
@@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ===== API Key display ===== */
.api-key-display {
    font-family: "SF Mono", "Fira Code", "Fira Mono", monospace;
}

/* ===== Login Page ===== */
.login-body {
    background: linear-gradient(135deg, #1E1B4B 0%, #4F46E5 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-container {
    width: 100%;
    max-width: 420px;
    padding: 20px;
}
.login-card {
    background: white;
    border-radius: 16px;
    padding: 40px 32px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.login-logo {
    width: 64px;
    height: 64px;
    background: var(--primary);
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.75rem;
}

/* ===== Responsive ===== */
@@media (max-width: 991.98px) {
    .sidebar { display: none !important; }
    .main-content {
        margin-left: 0;
        padding-top: 56px;
    }
    .topbar {
        position: relative;
    }
}

/* ===== Misc ===== */
.breadcrumb {
    margin-bottom: 0;
    font-size: 0.875rem;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.2rem rgba(79,70,229,0.15);
}
.form-check-input:checked {
    background-color: var(--primary);
    border-color: var(--primary);
}
.badge.bg-primary-subtle {
    background-color: rgba(79,70,229,0.1) !important;
}
.text-primary {
    color: var(--primary) !important;
}
