:root {
    /* ─── Color Palette (Sober & Elegant) ─── */
    --bg-primary: #f5f6fa;
    --bg-secondary: #ffffff;
    --bg-sidebar: #1a1a2e;
    --bg-sidebar-hover: #16213e;
    --bg-sidebar-active: #0f3460;
    --bg-card: #ffffff;
    --bg-input: #f0f1f5;
    --bg-chat-user: #e8f0fe;
    --bg-chat-ai: #f8f9fa;
    --bg-tool-call: #fff8e1;
    
    --text-primary: #1e1e2e;
    --text-secondary: #6c6c80;
    --text-sidebar: #a0a0b8;
    --text-sidebar-active: #ffffff;
    --text-on-accent: #ffffff;
    
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-light: #dbeafe;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    
    --border: #e2e4e9;
    --border-light: #f0f1f5;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    
    --sidebar-width: 260px;
    --header-height: 64px;
    
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* ─── Reset & Base ─── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: var(--font-family);
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Login Page ─── */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
}

.login-card {
    background: var(--bg-secondary);
    padding: 48px 40px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
    animation: fadeInUp 0.4s ease;
}

.login-card .logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-card .logo h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.login-card .logo p {
    color: var(--text-secondary);
    font-size: 13px;
}

.login-card .error-msg {
    background: #fef2f2;
    color: var(--danger);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 16px;
    border: 1px solid #fecaca;
}

/* ─── Forms ─── */
.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: var(--font-family);
    background: var(--bg-input);
    color: var(--text-primary);
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}

.form-control:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
    background: var(--bg-secondary);
}

select.form-control {
    cursor: pointer;
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    font-family: var(--font-family);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    color: var(--text-on-accent);
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: var(--shadow-md);
    text-decoration: none;
}

.btn-danger {
    background: var(--danger);
    color: var(--text-on-accent);
}

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

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-outline:hover {
    background: var(--bg-input);
    color: var(--text-primary);
    text-decoration: none;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-block {
    display: flex;
    width: 100%;
}

/* ─── Dashboard Layout ─── */
.dashboard {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
}

.sidebar-brand {
    padding: 20px 24px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-brand h2 {
    color: var(--text-sidebar-active);
    font-size: 18px;
    font-weight: 700;
}

.sidebar-brand small {
    color: var(--text-sidebar);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    list-style: none;
}

.sidebar-nav li {
    margin-bottom: 2px;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    color: var(--text-sidebar);
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s;
    text-decoration: none;
}

.sidebar-nav a:hover {
    background: var(--bg-sidebar-hover);
    color: var(--text-sidebar-active);
    text-decoration: none;
}

.sidebar-nav a.active {
    background: var(--bg-sidebar-active);
    color: var(--text-sidebar-active);
}

.sidebar-nav .nav-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.sidebar-nav .nav-divider {
    height: 1px;
    background: rgba(255,255,255,0.06);
    margin: 12px 0;
}

.sidebar-user {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.06);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-user .user-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: var(--accent);
    color: var(--text-on-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.sidebar-user .user-info {
    flex: 1;
    min-width: 0;
}

.sidebar-user .user-name {
    color: var(--text-sidebar-active);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user .user-role {
    color: var(--text-sidebar);
    font-size: 11px;
    text-transform: capitalize;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.main-header {
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 28px;
    flex-shrink: 0;
}

.main-header h1 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.main-header .header-actions {
    margin-left: auto;
    display: flex;
    gap: 12px;
    align-items: center;
}

.main-body {
    flex: 1;
    overflow-y: auto;
    padding: 28px;
}

/* ─── Cards ─── */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    font-size: 15px;
    font-weight: 600;
}

.card-body {
    padding: 24px;
}

/* ─── Tables ─── */
.table-wrapper {
    overflow-x: auto;
}

table.data-table {
    width: 100%;
    border-collapse: collapse;
}

table.data-table th {
    text-align: left;
    padding: 10px 16px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
}

table.data-table td {
    padding: 12px 16px;
    font-size: 13px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
}

table.data-table tbody tr:hover {
    background: var(--bg-input);
}

/* ─── Badges ─── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    text-transform: capitalize;
}

.badge-admin { background: #ede9fe; color: #7c3aed; }
.badge-analyst { background: #dbeafe; color: #2563eb; }
.badge-viewer { background: #d1fae5; color: #059669; }
.badge-active { background: #d1fae5; color: #059669; }
.badge-inactive { background: #fee2e2; color: #dc2626; }

/* ─── Chat Area ─── */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--header-height));
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 28px;
}

.chat-message {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    animation: fadeInUp 0.3s ease;
}

.chat-message .msg-avatar {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    font-weight: 600;
}

.chat-message.user .msg-avatar {
    background: var(--accent);
    color: var(--text-on-accent);
}

.chat-message.assistant .msg-avatar {
    background: #e2e8f0;
    color: #475569;
}

.chat-message .msg-content {
    flex: 1;
    min-width: 0;
}

.chat-message .msg-bubble {
    padding: 14px 18px;
    border-radius: var(--radius-md);
    font-size: 14px;
    line-height: 1.6;
    max-width: 85%;
}

.chat-message.user .msg-bubble {
    background: var(--bg-chat-user);
    color: var(--text-primary);
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.chat-message.assistant .msg-bubble {
    background: var(--bg-chat-ai);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.chat-message .msg-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 13px;
}

.chat-message .msg-bubble table th,
.chat-message .msg-bubble table td {
    padding: 8px 12px;
    border: 1px solid var(--border);
    text-align: left;
}

.chat-message .msg-bubble table th {
    background: var(--bg-input);
    font-weight: 600;
    font-size: 12px;
}

.chat-message .msg-bubble code {
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 12px;
}

.chat-message .msg-bubble pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 14px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 10px 0;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.5;
}

.chat-message .msg-bubble pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.tool-call-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    background: var(--bg-tool-call);
    border: 1px solid #fde68a;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 500;
    color: #92400e;
    margin-bottom: 10px;
}

.tool-call-badge::before {
    content: '⚡';
}

/* Chat Input */
.chat-input-area {
    padding: 16px 28px 20px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
}

.chat-input-wrapper {
    display: flex;
    gap: 10px;
    max-width: 900px;
    margin: 0 auto;
}

.chat-input-wrapper input {
    flex: 1;
    padding: 12px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    font-size: 14px;
    font-family: var(--font-family);
    background: var(--bg-input);
    color: var(--text-primary);
    outline: none;
    transition: all 0.2s;
}

.chat-input-wrapper input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
    background: var(--bg-secondary);
}

.chat-input-wrapper button {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-full);
    background: var(--accent);
    color: var(--text-on-accent);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 18px;
}

.chat-input-wrapper button:hover {
    background: var(--accent-hover);
    box-shadow: var(--shadow-md);
}

.chat-input-wrapper button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ─── Loading ─── */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px;
}

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

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

/* ─── Toggle switches ─── */
.toggle {
    position: relative;
    width: 40px;
    height: 22px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle .slider {
    position: absolute;
    inset: 0;
    background: #cbd5e1;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: 0.3s;
}

.toggle .slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
}

.toggle input:checked + .slider {
    background: var(--accent);
}

.toggle input:checked + .slider::before {
    transform: translateX(18px);
}

/* ─── Utility ─── */
.text-secondary { color: var(--text-secondary); }
.text-sm { font-size: 12px; }
.text-center { text-align: center; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.mb-2 { margin-bottom: 8px; }
.gap-2 { gap: 8px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }

/* ─── Animations ─── */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

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

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -260px;
        top: 0;
        height: 100vh;
        z-index: 100;
        transition: left 0.3s;
    }
    .sidebar.open { left: 0; }
    .main-content { width: 100%; }
}
