/* ═══════════════════════════════════════════════════════════════════════════════
   BIST Predictor — Premium Dark Theme Dashboard
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ─── CSS Variables ───────────────────────────────────────────────────────────── */
:root {
    /* Background & Surface */
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.7);
    --bg-card-hover: rgba(17, 24, 39, 0.9);
    --bg-glass: rgba(255, 255, 255, 0.03);
    --bg-glass-border: rgba(255, 255, 255, 0.06);
    
    /* Text */
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    /* Accent Colors */
    --accent-green: #00e676;
    --accent-green-dim: rgba(0, 230, 118, 0.15);
    --accent-red: #ff5252;
    --accent-red-dim: rgba(255, 82, 82, 0.15);
    --accent-cyan: #00bcd4;
    --accent-cyan-dim: rgba(0, 188, 212, 0.15);
    --accent-yellow: #ffd740;
    --accent-yellow-dim: rgba(255, 215, 64, 0.15);
    --accent-orange: #ff9800;
    --accent-purple: #b388ff;
    
    /* Gradients */
    --gradient-main: linear-gradient(135deg, #00e676 0%, #00bcd4 100%);
    --gradient-red: linear-gradient(135deg, #ff5252 0%, #ff1744 100%);
    --gradient-bg: radial-gradient(ellipse at top left, rgba(0, 230, 118, 0.05) 0%, transparent 50%),
                   radial-gradient(ellipse at bottom right, rgba(0, 188, 212, 0.05) 0%, transparent 50%);
    
    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
    --shadow-glow-green: 0 0 20px rgba(0, 230, 118, 0.2);
    --shadow-glow-red: 0 0 20px rgba(255, 82, 82, 0.2);
    
    /* Spacing */
    --sidebar-width: 300px;
    --header-height: 60px;
    
    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    
    /* Transition */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;
}

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

html {
    font-size: 14px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--gradient-bg);
    pointer-events: none;
    z-index: 0;
}

/* ─── Scrollbar ───────────────────────────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ─── Header ──────────────────────────────────────────────────────────────────── */
#app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: rgba(10, 14, 23, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--bg-glass-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

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

.logo-icon {
    display: flex;
    align-items: center;
    animation: logoGlow 3s ease-in-out infinite alternate;
}

@keyframes logoGlow {
    0% { filter: drop-shadow(0 0 4px rgba(0, 230, 118, 0.3)); }
    100% { filter: drop-shadow(0 0 12px rgba(0, 230, 118, 0.6)); }
}

.logo-text h1 {
    font-size: 1.25rem;
    font-weight: 700;
    background: var(--gradient-main);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.logo-subtitle {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.header-center {
    display: flex;
    align-items: center;
}

.horizon-tabs {
    display: flex;
    background: rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-md);
    padding: 3px;
    gap: 2px;
}

.horizon-tab {
    padding: 6px 18px;
    border: none;
    background: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    border-radius: 7px;
    cursor: pointer;
    transition: var(--transition-fast);
}

.horizon-tab:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.horizon-tab.active {
    background: var(--gradient-main);
    color: #0a0e17;
    font-weight: 600;
}

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

.system-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-yellow);
    animation: pulse 2s ease-in-out infinite;
}

.status-dot.online {
    background: var(--accent-green);
}

.status-dot.offline {
    background: var(--accent-red);
    animation: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
}

.header-date {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
}

/* ─── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
    padding: 8px 16px;
    border: 1px solid var(--bg-glass-border);
    background: var(--bg-glass);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition-fast);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.12);
}

.btn.active {
    background: var(--accent-cyan-dim);
    color: var(--accent-cyan);
    border-color: rgba(0, 188, 212, 0.3);
}

.btn-sm {
    padding: 4px 12px;
    font-size: 0.75rem;
}

.btn-icon {
    padding: 8px;
    border-radius: 8px;
}

.btn-icon:hover {
    background: var(--accent-cyan-dim);
    color: var(--accent-cyan);
}

.btn-icon svg {
    display: block;
}

/* ─── Main Layout ─────────────────────────────────────────────────────────────── */
#app-main {
    display: flex;
    margin-top: var(--header-height);
    height: calc(100vh - var(--header-height));
    position: relative;
    z-index: 1;
}

/* ─── Sidebar ─────────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: rgba(10, 14, 23, 0.6);
    backdrop-filter: blur(10px);
    border-right: 1px solid var(--bg-glass-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--bg-glass-border);
}

.sidebar-header h2 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 12px;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--bg-glass-border);
    border-radius: var(--radius-sm);
    transition: var(--transition-fast);
}

.search-box:focus-within {
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px rgba(0, 188, 212, 0.1);
}

.search-box svg {
    color: var(--text-muted);
    flex-shrink: 0;
}

.search-box input {
    flex: 1;
    border: none;
    background: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    outline: none;
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.stock-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.stock-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition-fast);
    margin-bottom: 2px;
    border: 1px solid transparent;
}

.stock-item:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: var(--bg-glass-border);
}

.stock-item.active {
    background: var(--accent-cyan-dim);
    border-color: rgba(0, 188, 212, 0.2);
}

.stock-item-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stock-symbol {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
}

.stock-price {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
}

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

.stock-score {
    font-size: 0.8rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
}

.score-high { background: var(--accent-green-dim); color: var(--accent-green); }
.score-mid { background: var(--accent-yellow-dim); color: var(--accent-yellow); }
.score-low-mid { background: rgba(255, 152, 0, 0.15); color: var(--accent-orange); }
.score-low { background: var(--accent-red-dim); color: var(--accent-red); }
.score-none { background: rgba(255,255,255,0.05); color: var(--text-muted); }

/* ─── Main Panel ──────────────────────────────────────────────────────────────── */
.main-panel {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ─── Glass Card ──────────────────────────────────────────────────────────────── */
.glass-card {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border: 1px solid var(--bg-glass-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

/* ─── Stats Row ───────────────────────────────────────────────────────────────── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--bg-glass-border);
    border-radius: var(--radius-lg);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: var(--transition-normal);
}

.stat-card:hover {
    border-color: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-primary);
}

.stat-change {
    font-size: 0.8rem;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
}

.stat-change.positive { color: var(--accent-green); }
.stat-change.negative { color: var(--accent-red); }

.stat-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ─── Confidence Gauge ────────────────────────────────────────────────────────── */
.confidence-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.confidence-gauge {
    position: relative;
    width: 90px;
    height: 90px;
    margin: 4px 0;
}

.gauge-svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.gauge-bg {
    fill: none;
    stroke: rgba(255, 255, 255, 0.06);
    stroke-width: 6;
}

.gauge-fill {
    fill: none;
    stroke: var(--accent-green);
    stroke-width: 6;
    stroke-linecap: round;
    transition: stroke-dashoffset 1s ease-out, stroke 0.5s ease;
}

.gauge-value {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.3rem;
    font-weight: 800;
    font-family: 'JetBrains Mono', monospace;
}

.confidence-label {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 2px 10px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ─── Chart Container ─────────────────────────────────────────────────────────── */
.chart-container {
    flex: 1;
    min-height: 320px;
    display: flex;
    flex-direction: column;
}

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

.chart-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

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

.chart-wrapper {
    flex: 1;
    padding: 16px;
    position: relative;
    min-height: 280px;
}

/* ─── Bottom Row ──────────────────────────────────────────────────────────────── */
.bottom-row {
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    gap: 16px;
}

.detail-card {
    padding: 20px;
}

.detail-card h3 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ─── Confidence Metrics ──────────────────────────────────────────────────────── */
.confidence-metrics {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.metric-bar {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.metric-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.metric-name {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.metric-weight {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
}

.bar-track {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 3px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    background: var(--gradient-main);
    border-radius: 3px;
    transition: width 1s ease-out;
}

.metric-value {
    font-size: 0.8rem;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-primary);
    align-self: flex-end;
}

/* ─── Data Table ──────────────────────────────────────────────────────────────── */
.table-wrapper {
    overflow-x: auto;
    max-height: 300px;
    overflow-y: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.data-table th {
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--bg-glass-border);
    position: sticky;
    top: 0;
    background: var(--bg-card);
}

.data-table td {
    padding: 8px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-secondary);
    font-size: 0.78rem;
}

.data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.data-table .positive { color: var(--accent-green); }
.data-table .negative { color: var(--accent-red); }

.empty-state {
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
    font-family: 'Inter', sans-serif;
    padding: 32px !important;
}

.in-band {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-green);
}

.out-band {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-red);
}

/* ─── Toast ───────────────────────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    border: 1px solid var(--bg-glass-border);
    color: var(--text-primary);
    font-size: 0.85rem;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease-out;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 400px;
}

.toast.success { border-left: 3px solid var(--accent-green); }
.toast.error { border-left: 3px solid var(--accent-red); }
.toast.info { border-left: 3px solid var(--accent-cyan); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(100px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(100px); }
}

/* ─── Loading ─────────────────────────────────────────────────────────────────── */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 14, 23, 0.85);
    backdrop-filter: blur(8px);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.loading-content h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.loading-content p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--accent-cyan);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner.large {
    width: 48px;
    height: 48px;
    border-width: 4px;
}

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

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.progress-bar {
    width: 240px;
    height: 4px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--gradient-main);
    border-radius: 2px;
    transition: width 0.3s ease;
    width: 0%;
}

/* ─── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 1200px) {
    .stats-row {
        grid-template-columns: repeat(2, 1fr);
    }
    .bottom-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    :root {
        --sidebar-width: 240px;
    }
    .header-center {
        display: none;
    }
}

@media (max-width: 700px) {
    .sidebar {
        display: none;
    }
    .stats-row {
        grid-template-columns: 1fr 1fr;
    }
}
