/* =========================================
   1. CORE VARIABLES & BASE STYLES
   ========================================= */
:root {
    --bg-color: #f3f4f6;
    --card-bg: #ffffff;
    --primary: #2563eb;
    --primary-light: #eff6ff;
    --nav-bg: #1e293b;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --accent-green: #10b981;
    --accent-green-bg: #d1fae5;
    --accent-red: #ef4444;
    --accent-red-bg: #fee2e2;
    --accent-gold: #fef3c7;
    --accent-blue-light: #dbeafe;
    --accent-blue-strong: #1e40af;
    --success: #10b981;
}

body { 
    font-family: 'Inter', -apple-system, sans-serif; 
    background-color: var(--bg-color); 
    color: var(--text-main); 
    margin: 0; 
    line-height: 1.5; 
}

/* =========================================
   2. NAVIGATION & HEADER
   ========================================= */
.sub-nav {
    background-color: var(--nav-bg);
    padding: 0.75rem 2rem;
    display: flex;
    gap: 1.5rem;
    justify-content: flex-start; /* Adaptive for scrolling */
    overflow-x: auto;
    white-space: nowrap;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sub-nav a { 
    color: #cbd5e1; 
    text-decoration: none; 
    font-size: 0.85rem; 
    font-weight: 500; 
    display: flex; 
    align-items: center; 
    gap: 6px; 
    transition: all 0.2s; 
}

.sub-nav a:hover { color: #fff; }

.sub-nav .active { 
    color: #fff; 
    border-bottom: 2px solid var(--primary); 
}

header {
    background: var(--card-bg); 
    border-bottom: 1px solid var(--border);
    padding: 1.2rem 2rem; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    position: sticky; 
    top: 0; 
    z-index: 100;
}

h1 { 
    margin: 0; 
    font-size: 1.25rem; 
    font-weight: 700; 
    display: flex; 
    align-items: center; 
    gap: 10px; 
}

/* =========================================
   3. LAYOUT & CONTAINERS
   ========================================= */
.container { 
    max-width: 1400px; 
    margin: 1.5rem auto; 
    padding: 0 1.5rem; 
}

.section-title { 
    font-size: 0.75rem; 
    text-transform: uppercase; 
    letter-spacing: 0.05em; 
    color: var(--text-muted); 
    margin: 2rem 0 1rem; 
    font-weight: 700; 
}

.card { 
    background: var(--card-bg); 
    border-radius: 12px; 
    border: 1px solid var(--border); 
    overflow: hidden; 
    margin-bottom: 30px; 
}

.card-header-inner { 
    padding: 12px 20px; 
    border-bottom: 1px solid var(--border); 
    background: #fdfdfd; 
}

/* =========================================
   4. FILTERS & CONTROLS
   ========================================= */
.filter-bar, .filter-card {
    background: var(--card-bg);
    padding: 1rem 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    margin-bottom: 1.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    align-items: flex-end;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.filter-group { display: flex; flex-direction: column; gap: 0.4rem; }

.filter-group label { 
    font-size: 0.7rem; 
    font-weight: 700; 
    color: var(--text-muted); 
    text-transform: uppercase; 
}

select, input[type="date"], .filter-select { 
    padding: 0.6rem; 
    border: 1px solid var(--border); 
    border-radius: 6px; 
    background: #f9fafb; 
    font-family: inherit;
    min-width: 150px;
}

.btn {
    background: var(--primary);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}

/* =========================================
   5. TABLES & DATA GRIDS
   ========================================= */
.table-container, .heatmap-container, .table-responsive, .pivot-wrapper { 
    background: var(--card-bg); 
    border-radius: 12px; 
    border: 1px solid var(--border); 
    overflow: auto; 
    max-height: 75vh;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
    position: relative;
}

.pivot-table, .modern-table { 
    width: 100%; 
    border-collapse: separate; 
    border-spacing: 0; 
    font-size: 0.8rem; 
}

.pivot-table th, .modern-table th { 
    background: #f8fafc; 
    padding: 12px 8px; 
    border-bottom: 2px solid var(--border); 
    color: var(--text-muted); 
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 20;
}

.pivot-table td, .modern-table td { 
    padding: 10px 12px; 
    border-bottom: 1px solid #f1f5f9; 
    background: #fff;
}

/* Pivot/Heatmap Specific Cells */
.heatmap-cell { 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    text-decoration: none; 
    height: 100%; 
    width: 100%; 
    color: inherit; 
}

.date-label { 
    writing-mode: vertical-rl; 
    transform: rotate(180deg); 
    font-size: 9px; 
    padding: 6px 0; 
}

/* Sticky Columns */
.ticker-col, .sector-name, .sticky-col { 
    position: sticky; 
    left: 0; 
    background: #fff !important; 
    z-index: 10; 
    border-right: 2px solid var(--border) !important;
}

.first-col { left: 0; width: 85px; font-weight: 700; color: var(--primary); }
.second-col { left: 85px; width: 140px; }

/* Table Row Hovers */
.pivot-table tbody tr:hover td, .modern-table tbody tr:hover td {
    background-color: #f8fafc !important;
}

/* =========================================
   6. METRICS, CARDS & BADGES
   ========================================= */
.grid-metrics, .sector-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); 
    gap: 1.25rem; 
}

.stat-card, .sector-card { 
    background: var(--card-bg); 
    border-radius: 12px; 
    padding: 1.25rem; 
    border: 1px solid var(--border); 
    transition: all 0.2s ease; 
    text-decoration: none;
    color: inherit;
}

.stat-card:hover, .sector-card:hover { 
    transform: translateY(-2px); 
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); 
    border-color: var(--primary);
}

/* Status Badges */
.badge, .trend-up, .trend-down, .trend-neutral {
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success, .trend-up { background: var(--accent-green-bg); color: #166534; }
.badge-danger, .trend-down { background: var(--accent-red-bg); color: #991b1b; }
.badge-neutral, .trend-neutral { background: #f3f4f6; color: #6b7280; }

.top-rank-gold { background: var(--accent-gold); color: #92400e; font-weight: bold; }
.top-rank { background: var(--accent-blue-light); color: var(--accent-blue-strong); font-weight: 700; }
.mid-rank { background-color: #eff6ff; }

/* =========================================
   7. CHARTS & DATA VISUALIZATION (D3)
   ========================================= */
.chart-container { 
    width: 100%; 
    height: 600px; 
    background: radial-gradient(circle at center, #1b1f24 0%, #0b0c10 100%); 
    border: 1px solid #333; 
    overflow: hidden; 
    position: relative; 
    border-radius: 12px;
}

.line { fill: none; stroke-width: 2px; opacity: 0.6; transition: all 0.2s; }
.line:hover { stroke-width: 4px; opacity: 1 !important; filter: drop-shadow(0 0 5px #66fcf1); cursor: pointer; }

.axis line, .axis path { stroke: #45a29e; }
.axis text { fill: #888; font-size: 11px; }

#tooltip { 
    position: absolute; 
    background: rgba(11, 12, 16, 0.95); 
    border: 1px solid #66fcf1; 
    color: #fff; 
    padding: 10px; 
    opacity: 0; 
    pointer-events: none; 
    z-index: 1000; 
    font-size: 12px; 
    border-radius: 4px; 
}

/* =========================================
   8. UTILITIES & FOOTER
   ========================================= */
.font-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.num-cell { font-variant-numeric: tabular-nums; text-align: center; }

footer { background: var(--nav-bg); color: #cbd5e1; padding: 3rem 2rem; margin-top: 4rem; }
.footer-grid { max-width: 1300px; margin: 0 auto; display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 2.5rem; }
.footer-links { list-style: none; padding: 0; margin: 0; }
.footer-links a { color: #94a3b8; text-decoration: none; font-size: 0.85rem; }
.footer-links a:hover { color: var(--primary); }

.error-banner {
    background: var(--accent-red-bg);
    color: var(--accent-red);
    padding: 1rem 1.5rem;
    border-radius: 12px;
    margin-bottom: 2rem;
    border: 1px solid var(--accent-red);
}