/* ===== Enhanced Market Dashboard V2 — Styles ===== */
:root {
    --bg-deep: #0a0e1a;
    --bg-card: rgba(18, 24, 42, 0.85);
    --bg-panel: #0f1628;
    --border: rgba(79, 195, 247, 0.12);
    --border-glow: rgba(79, 195, 247, 0.3);
    --accent: #4fc3f7;
    --accent2: #7c4dff;
    --green: #00e676;
    --red: #ff5252;
    --yellow: #ffd740;
    --orange: #ff9100;
    --text: #e0e6f0;
    --text-dim: #7a8ba8;
    --glass-blur: 16px;
    --radius: 14px;
    --radius-sm: 10px;
}

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

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg-deep);
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(79,195,247,0.04) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(124,77,255,0.04) 0%, transparent 50%);
    color: var(--text);
    padding: 20px;
    min-height: 100vh;
}

.dashboard { max-width: 1440px; margin: 0 auto; }

/* ===== ACTION BANNER ===== */
.action-banner {
    display: flex; align-items: center; gap: 16px;
    padding: 18px 24px; border-radius: var(--radius);
    background: linear-gradient(135deg, rgba(18,24,42,0.95), rgba(30,40,60,0.95));
    border: 1px solid var(--border);
    backdrop-filter: blur(var(--glass-blur));
    margin-bottom: 20px;
    animation: fadeSlideIn 0.6s ease;
    position: relative; overflow: hidden;
}
.action-banner::before {
    content: ''; position: absolute; inset: 0;
    border-radius: var(--radius);
    padding: 2px;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor; mask-composite: exclude;
    opacity: 0.5;
}
.action-banner.pulse::before { animation: borderPulse 2s ease-in-out infinite; }
.banner-icon { font-size: 32px; flex-shrink: 0; }
.banner-text { flex: 1; }
.banner-zone { font-size: 20px; font-weight: 700; letter-spacing: 0.5px; }
.banner-detail { font-size: 13px; color: var(--text-dim); margin-top: 4px; }
.banner-alloc {
    font-size: 36px; font-weight: 900; color: var(--accent);
    text-shadow: 0 0 20px rgba(79,195,247,0.3);
    flex-shrink: 0;
}

/* ===== TITLE ===== */
.title {
    text-align: center; font-size: 28px; font-weight: 800;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text; margin-bottom: 4px;
}
.version-badge {
    font-size: 11px; font-weight: 600;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
    vertical-align: super;
}
.subtitle { text-align: center; color: var(--text-dim); font-size: 13px; margin-bottom: 18px; }

/* ===== STATUS BAR ===== */
.status-bar {
    padding: 10px 16px; border-radius: var(--radius-sm);
    margin-bottom: 20px; text-align: center;
    background: var(--bg-card); border: 1px solid var(--border);
    font-weight: 600; font-size: 13px;
    backdrop-filter: blur(var(--glass-blur));
}
.status-bar.success { background: rgba(0,230,118,0.08); border-color: rgba(0,230,118,0.3); color: var(--green); }
.status-bar.error { background: rgba(255,82,82,0.08); border-color: rgba(255,82,82,0.3); color: var(--red); }

/* ===== CONVERGENCE ALERT ===== */
.convergence-alert {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 20px; border-radius: var(--radius-sm);
    background: rgba(255,82,82,0.08); border: 1px solid rgba(255,82,82,0.4);
    margin-bottom: 18px; animation: alertSlideIn 0.5s ease;
}
.convergence-alert.hidden { display: none; }
.conv-icon { font-size: 24px; animation: alertPulse 1.5s ease-in-out infinite; }
.conv-text { font-size: 13px; font-weight: 500; color: var(--red); }

/* ===== KPI ROW ===== */
.kpi-row {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
    gap: 12px; margin-bottom: 22px;
}
.kpi-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 14px 12px;
    text-align: center; backdrop-filter: blur(var(--glass-blur));
    transition: transform 0.2s, border-color 0.3s;
    animation: fadeSlideIn 0.5s ease backwards;
    position: relative; overflow: hidden;
}
.kpi-card:hover { transform: translateY(-2px); border-color: var(--border-glow); }
.kpi-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 4px; font-weight: 600; }
.kpi-value { font-size: 22px; font-weight: 800; color: #fff; }
.kpi-status { font-size: 10px; margin-top: 4px; font-weight: 600; }
.kpi-delta {
    font-size: 11px; font-weight: 600; margin-top: 4px;
    padding: 2px 6px; border-radius: 4px; display: inline-block;
}
.kpi-delta.up { background: rgba(0,230,118,0.12); color: var(--green); }
.kpi-delta.down { background: rgba(255,82,82,0.12); color: var(--red); }
.kpi-delta.neutral-delta { background: rgba(255,215,64,0.12); color: var(--yellow); }
/* Distance to threshold */
.kpi-threshold {
    margin-top: 6px; font-size: 10px; color: var(--text-dim);
    display: flex; align-items: center; gap: 4px; justify-content: center;
}
.threshold-bar {
    width: 60px; height: 4px; background: rgba(255,255,255,0.1);
    border-radius: 2px; overflow: hidden; display: inline-block;
}
.threshold-fill { height: 100%; border-radius: 2px; transition: width 0.5s; }
/* Sparkline canvas */
.kpi-sparkline { margin-top: 6px; }
.kpi-sparkline canvas { width: 100% !important; height: 28px !important; }

/* ===== MAIN LAYOUT ===== */
.main-content { display: grid; grid-template-columns: 1fr 370px; gap: 20px; }
@media (max-width: 1100px) { .main-content { grid-template-columns: 1fr; } }

/* ===== CARD (GLASS) ===== */
.card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px; margin-bottom: 18px;
    backdrop-filter: blur(var(--glass-blur));
    animation: fadeSlideIn 0.5s ease backwards;
}
.card h3 {
    font-size: 16px; font-weight: 700; margin-bottom: 14px;
    background: linear-gradient(135deg, var(--accent), #80d8ff);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}
.calc-container { border: 2px solid rgba(79,195,247,0.25); }

/* ===== SCORING PANELS ===== */
.scoring-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.scoring-panel {
    background: var(--bg-panel); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 12px;
}
.panel-title { font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.trend-panel .panel-title { color: var(--accent); }
.emotion-panel .panel-title { color: var(--yellow); }
.panel-icon { font-size: 16px; }
.panel-sub { font-size: 11px; color: var(--text-dim); margin-bottom: 8px; }
.score-big { font-size: 20px; font-weight: 800; color: var(--red); }

/* K-box */
.k-box {
    margin-top: 12px; background: var(--bg-panel); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 12px;
    display: grid; grid-template-columns: 120px 1fr; gap: 12px;
}
.k-label { font-size: 11px; color: var(--text-dim); }
.k-val { font-size: 34px; font-weight: 900; color: var(--green); line-height: 1; }
.k-note { font-size: 13px; line-height: 1.6; color: var(--text); white-space: pre-line; }

/* ===== FORMULA BOX ===== */
.formula-box {
    margin-top: 14px; background: var(--bg-panel); padding: 14px;
    border-radius: var(--radius-sm); font-size: 12px; color: var(--text-dim);
    line-height: 1.7; border: 1px dashed var(--border);
}

/* ===== QUADRANT ===== */
.quadrant-legend { font-size: 12px; line-height: 1.8; margin-bottom: 10px; color: var(--text); }
.legend-dot { display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 2px; }
.chart-note { font-size: 12px; color: var(--text-dim); margin-top: 8px; }

/* ===== CHARTS ===== */
.chart-container { position: relative; height: 220px; }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 18px; }

/* ===== TABLES ===== */
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { text-align: left; color: var(--accent); padding: 8px; border-bottom: 2px solid var(--border); font-weight: 600; }
td { padding: 8px; border-bottom: 1px solid rgba(255,255,255,0.05); }
.highlight-row { background: rgba(79,195,247,0.06); }
.up { color: var(--green); } .down { color: var(--red); } .neutral { color: var(--orange); }

/* ===== FUND INPUT ===== */
.fund-input-group {
    background: var(--bg-panel); padding: 16px; border-radius: var(--radius-sm);
    margin-bottom: 18px; text-align: center; font-size: 14px;
}
.fund-input-group input {
    background: transparent; border: none; border-bottom: 2px solid var(--accent);
    color: var(--accent); font-size: 28px; font-weight: 800;
    width: 150px; text-align: center; outline: none; font-family: 'Inter';
}
.alloc-bar { display: flex; height: 36px; border-radius: 8px; overflow: hidden; margin: 14px 0; border: 1px solid rgba(0,0,0,0.3); }
.alloc-item { display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: #000; transition: width 0.5s; }

/* ===== PORTFOLIO GAP ===== */
.portfolio-input-group { margin-bottom: 14px; }
.portfolio-input-group label { font-size: 13px; color: var(--text-dim); display: block; margin-bottom: 8px; }
.slider-row { display: flex; align-items: center; gap: 12px; }
.slider-row input[type=range] { flex: 1; accent-color: var(--accent); }
.slider-val { font-size: 24px; font-weight: 800; color: var(--accent); min-width: 60px; text-align: right; }
.gap-result { font-size: 13px; line-height: 1.7; }
.gap-bar-container { margin-top: 10px; }
.gap-bar-track { height: 12px; background: rgba(255,255,255,0.06); border-radius: 6px; position: relative; overflow: hidden; }
.gap-bar-current { position: absolute; left: 0; top: 0; height: 100%; border-radius: 6px; transition: width 0.5s; }
.gap-bar-target { position: absolute; top: -4px; height: 20px; width: 3px; border-radius: 2px; transition: left 0.5s; }

/* ===== WHAT-IF SLIDERS ===== */
.collapsible .collapse-body { max-height: 600px; overflow: hidden; transition: max-height 0.3s ease; }
.collapsible.collapsed .collapse-body { max-height: 0; }
.collapsible h3 { cursor: pointer; user-select: none; }
.collapse-icon { float: right; font-size: 12px; transition: transform 0.3s; }
.collapsible.collapsed .collapse-icon { transform: rotate(-90deg); }
.whatif-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.whatif-item { font-size: 12px; }
.whatif-item label { display: block; color: var(--text-dim); margin-bottom: 4px; }
.whatif-item input[type=range] { width: 100%; accent-color: var(--accent2); }
.whatif-item .wi-val { font-weight: 700; color: var(--accent); }
.btn-reset {
    background: rgba(124,77,255,0.15); border: 1px solid rgba(124,77,255,0.3);
    color: var(--accent2); padding: 8px 16px; border-radius: 8px;
    font-weight: 600; font-size: 12px; cursor: pointer; margin-bottom: 12px;
    transition: all 0.2s;
}
.btn-reset:hover { background: rgba(124,77,255,0.25); }
.whatif-result { font-size: 13px; color: var(--text-dim); line-height: 1.6; }

/* ===== REGIME LOG ===== */
.regime-log { max-height: 220px; overflow-y: auto; font-size: 12px; }
.regime-log .entry { padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,0.04); display: grid; grid-template-columns: 80px 1fr; gap: 8px; }
.regime-log .entry-date { color: var(--text-dim); font-weight: 500; }
.regime-log .entry-event { color: var(--text); }
.empty-state { color: var(--text-dim); font-size: 12px; text-align: center; padding: 20px; }

/* ===== THRESHOLDS ===== */
.thresholds-box { font-size: 12px; line-height: 1.8; }

/* ===== MTD ===== */
.mtd-box { font-size: 13px; line-height: 1.8; }
.mtd-item { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,0.04); }

/* ===== BACKTEST ===== */
.backtest-disclaimer { font-size: 10px; color: var(--text-dim); text-align: center; margin-top: 8px; font-style: italic; }

/* ===== NOTIFICATION ===== */
.notif-box { display: flex; flex-direction: column; gap: 8px; }
.btn-notif, .btn-copy {
    padding: 10px 16px; border-radius: 8px; font-weight: 600;
    font-size: 12px; cursor: pointer; border: 1px solid var(--border);
    transition: all 0.2s; font-family: 'Inter';
}
.btn-notif { background: rgba(79,195,247,0.12); color: var(--accent); }
.btn-notif:hover { background: rgba(79,195,247,0.2); }
.btn-copy { background: rgba(255,255,255,0.04); color: var(--text); }
.btn-copy:hover { background: rgba(255,255,255,0.08); }

/* ===== TIMEFRAME TOGGLE ===== */
.timeframe-toggle {
    position: fixed; bottom: 24px; right: 24px;
    display: flex; gap: 4px; padding: 4px;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 12px; backdrop-filter: blur(var(--glass-blur));
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    z-index: 100;
}
.tf-btn {
    padding: 8px 16px; border: none; border-radius: 8px;
    background: transparent; color: var(--text-dim);
    font-weight: 600; font-size: 12px; cursor: pointer;
    transition: all 0.2s; font-family: 'Inter';
}
.tf-btn.active { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; }
.tf-btn:hover:not(.active) { color: var(--text); background: rgba(255,255,255,0.05); }

/* ===== ANIMATIONS ===== */
@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes borderPulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.8; }
}
@keyframes alertSlideIn {
    from { opacity: 0; transform: translateX(-20px); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes alertPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}
@keyframes shimmer {
    0% { background-position: -200px 0; }
    100% { background-position: 200px 0; }
}

/* Stagger KPI card animations */
.kpi-card:nth-child(1) { animation-delay: 0.05s; }
.kpi-card:nth-child(2) { animation-delay: 0.1s; }
.kpi-card:nth-child(3) { animation-delay: 0.15s; }
.kpi-card:nth-child(4) { animation-delay: 0.2s; }
.kpi-card:nth-child(5) { animation-delay: 0.25s; }
.kpi-card:nth-child(6) { animation-delay: 0.3s; }
.kpi-card:nth-child(7) { animation-delay: 0.35s; }
.kpi-card:nth-child(8) { animation-delay: 0.4s; }
.kpi-card:nth-child(9) { animation-delay: 0.45s; }
.kpi-card:nth-child(10) { animation-delay: 0.5s; }
.kpi-card:nth-child(11) { animation-delay: 0.55s; }
.kpi-card:nth-child(12) { animation-delay: 0.6s; }
.kpi-card:nth-child(13) { animation-delay: 0.65s; }
.kpi-card:nth-child(14) { animation-delay: 0.7s; }
.kpi-card:nth-child(15) { animation-delay: 0.75s; }
.kpi-card:nth-child(16) { animation-delay: 0.8s; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(79,195,247,0.2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(79,195,247,0.4); }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .kpi-row { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
    .scoring-grid { grid-template-columns: 1fr; }
    .chart-grid { grid-template-columns: 1fr; }
    .action-banner { flex-direction: column; text-align: center; }
    .banner-alloc { font-size: 28px; }
    .whatif-grid { grid-template-columns: 1fr; }
}
