/* ---------------------------------------------------------------------------
   GT Intelligence — Custom UI Styles
   Modern, smooth, production-ready design
   --------------------------------------------------------------------------- */

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

:root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --accent: #059669;
    --danger: #dc2626;
    --warning: #d97706;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: all 0.2s ease;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
    overflow-x: hidden;
}

/* --- Header --- */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    z-index: 10;
    height: 60px;
}

.header-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
}

.header-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-left: 8px;
}

.header-right { display: flex; gap: 8px; align-items: center; }

/* --- Buttons --- */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 1px 2px rgba(37,99,235,0.3);
}

.btn-primary:hover { background: var(--primary-hover); box-shadow: var(--shadow-md); }
.btn-small { padding: 6px 10px; font-size: 0.8rem; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; }
.btn-small:hover { background: var(--border); }

/* --- Main Layout --- */
.main-layout {
    display: flex;
    height: calc(100vh - 60px);
    overflow: hidden;
}

/* --- Dashboard Panel --- */
.dashboard-panel {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px;
    transition: var(--transition);
}

.dashboard-panel::-webkit-scrollbar { width: 6px; }
.dashboard-panel::-webkit-scrollbar-track { background: transparent; }
.dashboard-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* --- Filters --- */
.filters-bar {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    padding: 14px 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 180px;
}

.filter-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.filter-select {
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    background: var(--bg);
    cursor: pointer;
    outline: none;
    transition: var(--transition);
}

.filter-select:focus { border-color: var(--primary); }

.multiselect {
    position: relative;
}

.multiselect-btn {
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    background: var(--bg);
    cursor: pointer;
    text-align: left;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: var(--transition);
}

.multiselect-btn:focus { border-color: var(--primary); }

.multiselect-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    z-index: 20;
    max-height: 200px;
    overflow-y: auto;
    margin-top: 4px;
}

.multiselect-dropdown.open { display: block; }

.multiselect-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: var(--transition);
}

.multiselect-option:hover { background: var(--primary-light); }

.multiselect-option input[type="checkbox"] {
    accent-color: var(--primary);
    width: 14px;
    height: 14px;
}

/* --- Metric Cards --- */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.metric-card {
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    transition: var(--transition);
}

.metric-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.metric-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.metric-value { font-size: 1.8rem; font-weight: 700; color: var(--text); margin-top: 4px; }
.metric-delta { font-size: 0.8rem; color: var(--accent); margin-top: 2px; }

/* --- Charts --- */
.charts-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
    overflow: hidden;
}

.chart-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    min-width: 0;
}

.chart-card.full-width { grid-column: 1 / -1; }
.chart-title { font-size: 0.95rem; font-weight: 600; color: var(--text); margin-bottom: 12px; }
.chart-container { width: 100%; height: 300px; }
.chart-container .js-plotly-plot { width: 100% !important; }

/* Quadrant overlay labels */
.quad-labels {
    position: absolute;
    top: 50px;
    left: 60px;
    right: 30px;
    bottom: 40px;
    pointer-events: none;
    z-index: 10;
}
.ql {
    position: absolute;
    font-size: 0.78rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
}
.ql-tl { top: 5%; left: 5%; }   /* top-left */
.ql-tr { top: 5%; right: 5%; }  /* top-right */
.ql-bl { bottom: 5%; left: 5%; } /* bottom-left */
.ql-br { bottom: 5%; right: 5%; } /* bottom-right */

/* --- Chat Panel --- */
.chat-panel {
    width: 420px;
    min-width: 420px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100%;
    transition: width 0.3s ease, min-width 0.3s ease;
}

.chat-panel.collapsed { width: 0; min-width: 0; padding: 0; border: none; overflow: hidden; }

.chat-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-title { font-size: 1rem; font-weight: 600; }
.chat-header-actions { display: flex; gap: 6px; align-items: center; }

.session-select {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    background: var(--bg);
    cursor: pointer;
    max-width: 160px;
}

/* --- Quick Actions --- */
.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
}

.quick-btn {
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg);
    font-size: 0.75rem;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.quick-btn:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }

/* --- Chat Messages --- */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 20px;
    font-size: 0.9rem;
}

.text-muted { color: var(--text-muted); font-size: 0.8rem; margin-top: 4px; }

/* Message bubbles */
.msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.875rem;
    line-height: 1.5;
    animation: fadeIn 0.2s ease;
}

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

.msg-assistant {
    align-self: flex-start;
    background: var(--bg);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.msg-error {
    align-self: flex-start;
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: var(--danger);
    border-radius: var(--radius-sm);
}

.msg-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    font-weight: 600;
}

/* SQL block */
.sql-block {
    background: #1e293b;
    color: #e2e8f0;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.78rem;
    overflow-x: auto;
    margin: 8px 0;
    cursor: pointer;
    position: relative;
}

.sql-block::after {
    content: '🔍';
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 0.7rem;
}

.sql-block.collapsed { max-height: 32px; overflow: hidden; }
.sql-block.expanded { max-height: 200px; overflow-y: auto; }

/* Data table */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
    margin: 8px 0;
    max-height: 180px;
    overflow-y: auto;
    display: block;
}

.data-table th {
    background: var(--bg);
    padding: 6px 10px;
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 0;
}

.data-table td {
    padding: 5px 10px;
    border-bottom: 1px solid var(--border);
}

.data-table tr:hover td { background: var(--primary-light); }

/* Insight box */
.insight-box {
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    border-left: 3px solid var(--primary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    padding: 10px 14px;
    margin: 8px 0;
    font-size: 0.85rem;
}

/* Follow-up chips */
.followups { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.followup-btn {
    padding: 4px 12px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg);
    font-size: 0.75rem;
    cursor: pointer;
    transition: var(--transition);
}
.followup-btn:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }

/* Chart in chat */
.chart-expand-btn {
    margin-top: 8px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    font-size: 0.8rem;
    cursor: pointer;
    transition: var(--transition);
}
.chart-expand-btn:hover { background: var(--primary-light); }

.chat-chart-container {
    margin: 8px 0;
    max-width: 100%;
    overflow: hidden;
}

.chart-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 100;
    justify-content: center;
    align-items: center;
    padding: 40px;
}
.chart-modal.active { display: flex; }
.chart-modal-content {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 900px;
    max-height: 80vh;
    overflow: auto;
    box-shadow: var(--shadow-lg);
}
.chart-modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.chat-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

.chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    outline: none;
    transition: var(--transition);
    background: var(--bg);
}

.chat-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }

.btn-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

/* --- Loading / Spinner --- */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 300px;
    color: var(--text-muted);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}

.spinner-small {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* --- Responsive --- */
@media (max-width: 1024px) {
    .metrics-grid { grid-template-columns: repeat(2, 1fr); }
    .charts-row { grid-template-columns: 1fr; }
    .chat-panel { width: 350px; min-width: 350px; }
}

@media (max-width: 768px) {
    .main-layout { flex-direction: column; }
    .chat-panel { width: 100%; min-width: 100%; height: 50vh; border-left: none; border-top: 1px solid var(--border); }
}
