/* style.css - Premium Glassmorphism Theme for Livestream Analyzer */

:root {
    --bg-dark: #0f1016;
    --primary: #6366f1; /* Indigo */
    --primary-light: #818cf8;
    --primary-glow: rgba(99, 102, 241, 0.15);
    
    --success: #10b981; /* Emerald */
    --warning: #f59e0b; /* Amber */
    --danger: #ef4444;  /* Rose */
    
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --text-dim: #6b7280;
    
    --glass-bg: rgba(17, 18, 27, 0.65);
    --glass-bg-hover: rgba(25, 27, 40, 0.8);
    --glass-border: rgba(255, 255, 255, 0.07);
    --glass-border-focus: rgba(99, 102, 241, 0.4);
    
    --sidebar-width: 320px;
    --font-outfit: 'Outfit', 'Noto Sans SC', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-outfit);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* Mesh Gradient background behind application */
.mesh-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background: 
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(244, 63, 94, 0.08) 0px, transparent 50%),
        radial-gradient(at 100% 0%, rgba(16, 185, 129, 0.08) 0px, transparent 40%),
        radial-gradient(at 0% 100%, rgba(124, 58, 237, 0.12) 0px, transparent 50%);
    opacity: 0.85;
}

/* App Layout Grid */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    padding: 16px;
    gap: 16px;
}

/* Glass Panel Utility */
.glass-panel {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

/* Sidebar Styling */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
    gap: 16px;
    overflow-y: hidden; /* Main sidebar handles no scroll, content handles it */
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

.logo .icon {
    font-size: 28px;
}

.logo-text h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.5px;
    background: linear-gradient(135deg, #fff 30%, var(--primary-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-text p {
    font-size: 11px;
    color: var(--text-muted);
}

/* Sidebar Navigation Tabs */
.sidebar-tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    padding: 3px;
    flex-shrink: 0;
}

.s-tab-btn {
    flex-grow: 1;
    padding: 8px 0;
    background: transparent;
    border: none;
    border-radius: 8px;
    font-family: var(--font-outfit);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.s-tab-btn.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 12px var(--primary-glow);
}

.s-tab-btn:hover:not(.active) {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.03);
}

/* Sidebar Tab Contents */
.s-tab-content {
    display: none;
    flex-grow: 1;
    overflow-y: auto;
    flex-direction: column;
}

.s-tab-content.active {
    display: flex;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sidebar-section h2 {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Schema Browser styling */
.schema-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.schema-table {
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.04);
    overflow: hidden;
}

.schema-table-header {
    padding: 10px 12px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
    transition: background 0.2s ease;
}

.schema-table-header:hover {
    background: rgba(255, 255, 255, 0.05);
}

.schema-table-header .table-name {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.schema-table-header .arrow {
    font-size: 10px;
    transition: transform 0.2s ease;
    color: var(--text-muted);
}

.schema-table.expanded .arrow {
    transform: rotate(90deg);
}

.schema-table-columns {
    display: none;
    padding: 6px 12px 10px 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.03);
    font-family: var(--font-mono);
    font-size: 11px;
    background: rgba(0, 0, 0, 0.15);
}

.schema-table.expanded .schema-table-columns {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.column-item {
    display: flex;
    justify-content: space-between;
    cursor: pointer;
    padding: 3px 6px;
    border-radius: 4px;
    transition: background 0.15s ease, color 0.15s ease;
}

.column-item:hover {
    background: rgba(99, 102, 241, 0.15);
    color: #fff;
}

.column-item .col-type {
    color: var(--text-dim);
}

/* Preset Cards */
.presets-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.preset-card {
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    width: 100%;
}

.preset-card:hover {
    background: rgba(99, 102, 241, 0.08);
    border-color: rgba(99, 102, 241, 0.3);
    transform: translateY(-1px);
}

.preset-card h4 {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-main);
    margin-bottom: 4px;
}

.preset-card p {
    font-size: 10px;
    color: var(--text-muted);
    line-height: 1.3;
}

/* --- AI Chat UI Styling --- */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.chat-header {
    padding: 8px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.status-indicator {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.text-success {
    color: var(--success);
    font-size: 8px;
}

.chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-bubble {
    max-width: 88%;
    padding: 10px 12px;
    font-size: 12px;
    line-height: 1.5;
    border-radius: 12px;
    position: relative;
    word-wrap: break-word;
}

.chat-bubble p {
    margin-bottom: 6px;
}

.chat-bubble p:last-child {
    margin-bottom: 0;
}

.chat-bubble.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--primary) 0%, rgba(99, 102, 241, 0.8) 100%);
    color: #fff;
    border-bottom-right-radius: 0;
}

.chat-bubble.ai {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border-bottom-left-radius: 0;
}

.chat-tip {
    font-size: 11px;
    color: var(--text-muted);
    border-left: 2px solid var(--primary-light);
    padding-left: 8px;
    margin-top: 8px;
}

/* Code layout inside chat assistant response */
.chat-sql-box {
    margin-top: 8px;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    padding: 8px;
    font-family: var(--font-mono);
    font-size: 10.5px;
    color: var(--primary-light);
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.chat-btn-group {
    display: flex;
    gap: 6px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.chat-action-btn {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 10.5px;
    cursor: pointer;
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.3);
    color: var(--primary-light);
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-action-btn:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.chat-input-wrapper {
    padding: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(0, 0, 0, 0.15);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
}

#chat-input {
    flex-grow: 1;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: var(--text-main);
    font-family: var(--font-outfit);
    font-size: 12px;
    padding: 8px 10px;
    outline: none;
    resize: none;
    max-height: 80px;
    line-height: 1.4;
    transition: border-color 0.25s ease;
}

#chat-input:focus {
    border-color: var(--glass-border-focus);
}

#btn-chat-send {
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    flex-shrink: 0;
}

/* Chat typing indicator bubble */
.typing-dots {
    display: flex;
    gap: 4px;
    padding: 4px 6px;
    align-items: center;
    height: 18px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.2s infinite ease-in-out;
}

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

@keyframes bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-5px); }
}

/* SQL Editor AI generated badge indicator */
.badge-ai {
    font-size: 9px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid rgba(16, 185, 129, 0.4);
    color: var(--success);
    margin-left: 8px;
    text-transform: uppercase;
}

/* Main Area Container */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Header summary stats */
.top-header {
    padding: 18px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
}

.header-title h2 {
    font-size: 18px;
    font-weight: 600;
}

.header-title p {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.quick-stats {
    display: flex;
    gap: 12px;
}

.stat-card {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.stat-label {
    font-size: 10px;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

.stat-val {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary-light);
}

/* SQL Editor panel */
.editor-section {
    padding: 18px 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.section-header h3 {
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.editor-actions {
    display: flex;
    gap: 8px;
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid transparent;
    transition: all 0.2s ease;
    font-family: var(--font-outfit);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-light);
    box-shadow: 0 0 16px var(--primary-glow);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.15);
}

/* SQL Textarea editor */
.sql-editor-wrapper {
    display: flex;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    overflow: hidden;
    height: 180px;
    position: relative;
}

.sql-editor-wrapper:focus-within {
    border-color: var(--glass-border-focus);
    box-shadow: 0 0 0 1px var(--primary-glow);
}

.line-numbers {
    width: 36px;
    padding: 12px 0;
    background: rgba(0, 0, 0, 0.15);
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 12px;
    text-align: center;
    line-height: 1.6;
    border-right: 1px solid rgba(255, 255, 255, 0.03);
    user-select: none;
    overflow: hidden;
}

#sql-editor {
    flex-grow: 1;
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    padding: 12px;
    font-family: var(--font-mono);
    font-size: 13px;
    color: #e4e4e7;
    line-height: 1.6;
    overflow-y: auto;
}

/* Results panel */
.results-section {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    min-height: 380px;
}

.results-tabs {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding: 0 24px;
    height: 52px;
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.1);
}

.tabs-header {
    display: flex;
    height: 100%;
}

.tab-btn {
    padding: 0 20px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 100%;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    color: var(--text-main);
}

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

.results-meta {
    font-size: 11px;
    color: var(--text-muted);
}

/* Tab contents */
.tab-content {
    display: none;
    flex-grow: 1;
    flex-direction: column;
    overflow: hidden;
    padding: 16px 24px 24px 24px;
}

.tab-content.active {
    display: flex;
}

/* Table Toolbar */
.table-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.search-box {
    position: relative;
    width: 280px;
}

.search-box i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-dim);
    font-size: 12px;
}

.search-box input {
    width: 100%;
    padding: 8px 12px 8px 32px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: var(--text-main);
    font-size: 12px;
    outline: none;
    transition: all 0.25s ease;
}

.search-box input:focus {
    border-color: var(--glass-border-focus);
    background: rgba(0, 0, 0, 0.35);
}

.pagination-info {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 12px;
}

.pagination-controls {
    display: flex;
    gap: 4px;
}

.page-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 11px;
}

.page-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.08);
}

.page-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* Interactive Data Table */
.table-wrapper {
    flex-grow: 1;
    overflow: auto;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.15);
}

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

.query-table th {
    position: sticky;
    top: 0;
    background: #151622;
    padding: 12px 16px;
    font-weight: 600;
    color: var(--text-main);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.query-table th:hover {
    background: #1b1c2b;
}

.query-table th i {
    margin-left: 6px;
    font-size: 10px;
    color: var(--text-dim);
}

.query-table td {
    padding: 10px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    color: var(--text-muted);
    white-space: nowrap;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.query-table tr:hover td {
    background: rgba(255, 255, 255, 0.02);
    color: var(--text-main);
}

/* Empty State / Loading State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%;
    color: var(--text-muted);
    gap: 12px;
    padding: 48px;
}

.empty-icon {
    font-size: 40px;
    opacity: 0.6;
}

.empty-state p {
    font-size: 13px;
}

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    height: 100%;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(99, 102, 241, 0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Chart visualization tab */
.chart-controls {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    margin-bottom: 16px;
    align-items: flex-end;
    flex-shrink: 0;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.control-group label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
}

.control-group select {
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: var(--text-main);
    font-size: 12px;
    outline: none;
    min-width: 150px;
}

.chart-wrapper {
    flex-grow: 1;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

#chart-container {
    width: 100%;
    height: 100%;
    min-height: 320px;
}

#chart-empty-state {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10;
    background: rgba(15, 16, 22, 0.95);
}

/* Summary metrics template cards in data table */
.summary-cards-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    padding: 16px 0;
    width: 100%;
}

.summary-card {
    padding: 20px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.03) 0%, rgba(255, 255, 255, 0.01) 100%);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.summary-card-val {
    font-size: 26px;
    font-weight: 700;
    color: #fff;
    margin-bottom: 6px;
    background: linear-gradient(135deg, #fff 50%, var(--primary-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.summary-card-label {
    font-size: 12px;
    color: var(--text-muted);
}

/* Toast alert notification */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    display: flex;
    align-items: flex-start;
    padding: 14px 18px;
    border-radius: 12px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
    max-width: 420px;
    transform: translateY(150%);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    backdrop-filter: blur(16px);
}

.toast.show {
    transform: translateY(0);
}

.error-toast {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.4);
    color: #fef2f2;
}

.toast-icon {
    font-size: 16px;
    margin-top: 3px;
    margin-right: 12px;
}

.toast-body {
    flex-grow: 1;
}

.toast-title {
    font-size: 13px;
    font-weight: 600;
    display: block;
    margin-bottom: 2px;
}

.toast-msg {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.8);
    font-family: var(--font-mono);
    line-height: 1.4;
    word-break: break-all;
}

.toast-close {
    background: transparent;
    border: none;
    color: inherit;
    font-size: 18px;
    cursor: pointer;
    margin-left: 12px;
    line-height: 1;
    opacity: 0.7;
}

.toast-close:hover {
    opacity: 1;
}

/* Small Loading State */
.loading-small {
    padding: 12px;
    font-size: 11px;
    color: var(--text-dim);
    text-align: center;
}
