:root {
    --bg-dark: #0f172a;
    --bg-card: rgba(30, 41, 59, 0.7);
    --primary: #3b82f6;
    --primary-glow: rgba(59, 130, 246, 0.5);
    --secondary: #8b5cf6;
    --accent: #10b981;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.1);
    --radius: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    background-image: 
        radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(139, 92, 246, 0.15) 0px, transparent 50%);
}

/* Typography */
h1, h2, h3 { font-family: 'Outfit', sans-serif; }
.highlight { color: var(--primary); }
.text-muted { color: var(--text-muted); }

/* Topbar */
.topbar {
    height: 64px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.icon {
    font-size: 24px;
    filter: drop-shadow(0 0 8px var(--primary-glow));
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: grid;
    place-items: center;
    font-weight: 600;
}

/* Layout */
.app-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 300px;
    background: rgba(30, 41, 59, 0.4);
    border-right: 1px solid var(--border);
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.section-title {
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
}

/* Upload Zone */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 32px 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: rgba(255,255,255,0.02);
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.05);
}

.upload-zone svg {
    margin-bottom: 12px;
    color: var(--primary);
}

.upload-zone p { font-size: 14px; margin-bottom: 4px; }
.upload-zone .browse { color: var(--primary); font-weight: 600; }
.upload-zone small { font-size: 12px; color: var(--text-muted); }

/* Connectors */
.source-connectors {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.connector-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 12px 16px;
    border-radius: 8px;
    color: var(--text-main);
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
    transition: all 0.2s ease;
}

.connector-btn:hover {
    transform: translateY(-2px);
    border-color: rgba(255,255,255,0.2);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
}
.badge.sql { background: rgba(59, 130, 246, 0.2); color: #60a5fa; }
.badge.api { background: rgba(139, 92, 246, 0.2); color: #a78bfa; }
.badge.sage { background: rgba(16, 185, 129, 0.2); color: #34d399; }
.badge.qbo { background: rgba(245, 158, 11, 0.2); color: #fbbf24; }

/* Dataset List */
.datasets-list { flex: 1; }
.dataset-item {
    padding: 12px;
    border-radius: 8px;
    background: rgba(255,255,255,0.03);
    margin-bottom: 8px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s ease;
}
.dataset-item:hover, .dataset-item.active {
    background: rgba(59,130,246,0.1);
    border-color: rgba(59,130,246,0.3);
}
.dataset-item .d-name { font-weight: 500; font-size: 14px; margin-bottom: 4px; }
.dataset-item .d-meta { font-size: 12px; color: var(--text-muted); }

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 32px;
    overflow-y: auto;
    position: relative;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1px;
}

.tab-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 12px 24px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
}

.tab-btn:hover { color: var(--text-main); }
.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-pane { display: none; }
.tab-pane.active { display: block; animation: fadeIn 0.3s ease; }

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

/* Panels & Cards */
.panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    backdrop-filter: blur(16px);
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    margin-bottom: 24px;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

/* Table */
.table-container {
    overflow-x: auto;
    max-height: 500px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    text-align: left;
}

th {
    background: rgba(0,0,0,0.4);
    position: sticky;
    top: 0;
    padding: 12px 16px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

td {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

tbody tr:hover { background: rgba(255,255,255,0.02); }

/* Analytics Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: linear-gradient(145deg, rgba(30,41,59,0.8), rgba(15,23,42,0.8));
    border: 1px solid var(--border);
    padding: 20px;
    border-radius: 12px;
    position: relative;
    overflow: hidden;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; height: 2px;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    opacity: 0.5;
}

.kpi-value { font-size: 28px; font-family: 'Outfit'; font-weight: 700; margin: 8px 0; }
.kpi-label { font-size: 13px; color: var(--text-muted); }

.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.chart-panel h3 { margin-bottom: 16px; font-size: 16px; }

/* Insights Tab */
.ai-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border: none;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(59,130,246,0.3);
    transition: all 0.2s;
}
.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(59,130,246,0.4);
}

.insights-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.insights-list li {
    padding: 16px;
    background: rgba(255,255,255,0.03);
    border-left: 3px solid var(--secondary);
    border-radius: 4px;
    line-height: 1.6;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 100;
    place-items: center;
}
.modal.active { display: grid; }

.modal-content {
    background: #1e293b;
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    padding: 24px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.4);
    animation: scaleIn 0.2s ease;
}

@keyframes scaleIn {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 24px;
}

.close-btn {
    background: none; border: none;
    color: var(--text-muted);
    font-size: 24px; cursor: pointer;
}

.form-group { margin-bottom: 16px; display: flex; flex-direction: column; gap: 8px; }
.form-group label { font-size: 13px; color: var(--text-muted); }
.form-group input {
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border);
    padding: 12px;
    border-radius: 8px;
    color: white;
    font-family: inherit;
}
.form-group input:focus { border-color: var(--primary); outline: none; }

.btn-submit {
    width: 100%;
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-weight: 600;
    margin-top: 16px;
    cursor: pointer;
}

/* Chat Widget */
.chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 350px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    backdrop-filter: blur(16px);
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 60px; /* Collapsed */
    transition: height 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 50;
}

.chat-widget.expanded { height: 500px; }

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: rgba(255,255,255,0.05);
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}

.ai-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--secondary);
    display: grid; place-items: center;
    font-size: 12px;
}

.chat-header span { font-weight: 600; flex: 1; }
.chat-header .close-btn { font-size: 20px; transition: transform 0.3s; }
.chat-widget.expanded .close-btn { transform: rotate(45deg); }

.chat-body {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-msg {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
}

.ai-msg {
    background: rgba(255,255,255,0.05);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.user-msg {
    background: var(--primary);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.chat-input-area {
    padding: 16px;
    display: flex;
    gap: 8px;
    background: rgba(0,0,0,0.2);
}

.chat-input-area input {
    flex: 1;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 10px 16px;
    color: white;
    font-family: inherit;
}
.chat-input-area input:focus { outline: none; border-color: var(--primary); }

.chat-input-area button {
    background: var(--primary);
    border: none;
    width: 40px; height: 40px;
    border-radius: 50%;
    display: grid; place-items: center;
    color: white;
    cursor: pointer;
}

.empty-state {
    color: var(--text-muted);
    font-style: italic;
    padding: 24px;
    text-align: center;
}

/* ======================== AUTH OVERLAY ======================== */
.auth-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-dark);
    background-image:
        radial-gradient(at 20% 20%, rgba(59, 130, 246, 0.2) 0px, transparent 50%),
        radial-gradient(at 80% 80%, rgba(139, 92, 246, 0.2) 0px, transparent 50%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.auth-card {
    background: rgba(30, 41, 59, 0.9);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(20px);
    animation: scaleIn 0.3s ease;
}

.auth-brand {
    text-align: center;
    margin-bottom: 32px;
}

.auth-brand .icon { font-size: 32px; filter: drop-shadow(0 0 12px var(--primary-glow)); }
.auth-brand h1 { font-size: 36px; font-family: 'Outfit', sans-serif; margin: 8px 0 4px; }
.auth-tagline { color: var(--text-muted); font-size: 14px; }

.auth-tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    padding: 4px;
    margin-bottom: 28px;
    gap: 4px;
}

.auth-tab {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 10px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.auth-tab.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.auth-error {
    color: #f87171;
    font-size: 13px;
    min-height: 18px;
    text-align: center;
}

/* ======================== TOPBAR USER PROFILE ======================== */
.username-display {
    font-size: 13px;
    color: var(--text-muted);
    margin-right: 4px;
}

.logout-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    cursor: pointer;
    margin-left: 8px;
    transition: all 0.2s;
}
.logout-btn:hover { color: #f87171; border-color: #f87171; }

/* ======================== PANEL HEADER ACTIONS ======================== */
.panel-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.meta-tag {
    font-size: 12px;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    padding: 3px 10px;
    border-radius: 20px;
    display: inline-block;
    margin-top: 4px;
}

.search-input {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    color: white;
    font-family: inherit;
    font-size: 13px;
    width: 180px;
    transition: border-color 0.2s;
}
.search-input:focus { border-color: var(--primary); outline: none; }

.btn-outline {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 8px 14px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

/* ======================== QUICK ANALYSIS ======================== */
.quick-analysis-panel { padding: 20px 24px; margin-bottom: 20px; }

.panel-section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 16px;
}

.quick-links-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

@media (max-width: 900px) {
    .quick-links-grid { grid-template-columns: 1fr; }
}

.quick-link-section {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
}

.ql-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.ql-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.ql-select {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 8px 10px;
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
    flex: 1;
    min-width: 120px;
}

.ql-select-sm {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 8px 10px;
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
}

.ql-select:focus, .ql-select-sm:focus { border-color: var(--primary); outline: none; }

.btn-sm {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-primary-sm {
    background: var(--primary);
    color: white;
}
.btn-primary-sm:hover { background: #2563eb; transform: translateY(-1px); }

.btn-ghost-sm {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
    border: 1px solid var(--border) !important;
}
.btn-ghost-sm:hover { color: var(--text-main); }

/* ======================== REPORT BUILDER ======================== */
.report-section {
    border-top: 1px solid var(--border);
    padding: 20px 0;
}
.report-section:first-child { border-top: none; }

.report-section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
}

.col-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.col-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}
.col-toggle:hover { border-color: rgba(255,255,255,0.2); }
.col-toggle input { accent-color: var(--primary); }

.filter-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.filter-val-input {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
    color: white;
    font-family: inherit;
    font-size: 13px;
    flex: 1;
    min-width: 120px;
}
.filter-val-input:focus { border-color: var(--primary); outline: none; }

.chart-builder-controls {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 20px;
}

.report-chart-container {
    max-height: 350px;
    position: relative;
}

/* ======================== FORM ADDITIONS ======================== */
.form-textarea {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    color: white;
    font-family: inherit;
    font-size: 13px;
    width: 100%;
    min-height: 80px;
    resize: vertical;
}
.form-textarea:focus { border-color: var(--primary); outline: none; }

.form-select {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    color: white;
    font-family: inherit;
    font-size: 14px;
    width: 100%;
}
.form-select:focus { border-color: var(--primary); outline: none; }

.form-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.field-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    line-height: 1.5;
}

.optional {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 400;
}

/* ======================== SAGE PASTEL SPECIAL ======================== */
.sage-btn { border-color: rgba(16, 185, 129, 0.3); }
.sage-btn:hover { border-color: rgba(16, 185, 129, 0.6) !important; background: rgba(16, 185, 129, 0.08) !important; }

.sage-note {
    background: rgba(16, 185, 129, 0.08);
    border: 1px solid rgba(16, 185, 129, 0.3);
    border-radius: 8px;
    padding: 12px 14px;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.6;
    margin-top: 8px;
}
.sage-note strong { color: #34d399; }

/* ======================== KPI SUB ======================== */
.kpi-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ======================== TYPING INDICATOR ======================== */
.typing-dots { display: inline-flex; gap: 4px; align-items: center; }
.typing-dots span {
    width: 6px; height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: blink 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
    0%, 80%, 100% { opacity: 0.2; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

.typing-inline {
    color: var(--text-muted);
    font-style: italic;
    font-size: 13px;
}

/* ======================== MODAL SCROLLABLE ======================== */
.modal-content {
    max-height: 90vh;
    overflow-y: auto;
}
.modal-body { padding-top: 4px; }
