/* ═══════════════════════════════════════════════════════════════════════════
   Tesla Investment Dashboard - Professional Styling
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
    --bg-primary: #0a0a0a;
    --bg-secondary: #121212;
    --bg-tertiary: #1a1a1a;
    --bg-card: #141414;
    
    --border-primary: #2a2a2a;
    --border-secondary: #1a1a1a;
    
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --text-tertiary: #666666;
    
    --accent-red: #E31937;
    --accent-green: #00FF9C;
    --accent-blue: #00C9FF;
    --accent-purple: #A259FF;
    --accent-gold: #FFD700;
    --accent-orange: #FF6B35;
    
    --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Courier New', monospace;
    
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.6);
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

/* ─── Reset & Base ──────────────────────────────────────────────────────── */

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

body {
    font-family: var(--font-primary);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* ─── Header ──────────────────────────────────────────────────────────────── */

.header {
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
    border-bottom: 1px solid var(--border-primary);
    padding: 1.5rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(20px);
}

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

.brand {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.brand-icon {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--accent-red), #8B0000);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 900;
    box-shadow: 0 0 24px rgba(227, 25, 55, 0.4);
}

.brand-text h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.brand-subtitle {
    font-size: 0.875rem;
    color: var(--text-tertiary);
    font-family: var(--font-mono);
    margin-top: 0.25rem;
}

.header-portfolio {
    text-align: right;
    flex-shrink: 0;
}

.portfolio-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-tertiary);
    margin-bottom: 0.25rem;
}

.portfolio-value {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -1px;
    font-family: var(--font-mono);
}

.portfolio-change {
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

.refresh-btn {
    padding: 0.75rem 1.5rem;
    background: transparent;
    border: 1px solid rgba(227, 25, 55, 0.3);
    border-radius: var(--radius-sm);
    color: var(--accent-red);
    font-size: 0.875rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
    flex-shrink: 0;
}

.refresh-btn:hover {
    background: rgba(227, 25, 55, 0.1);
    border-color: var(--accent-red);
}

.refresh-btn svg {
    transition: transform 0.3s;
}

.refresh-btn:active svg {
    transform: rotate(180deg);
}

/* ─── Navigation Tabs ──────────────────────────────────────────────────────── */

.tabs {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-primary);
    position: sticky;
    top: 84px;
    z-index: 90;
}

.tabs-list {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding: 0.5rem 0;
}

.tabs-list::-webkit-scrollbar {
    height: 4px;
}

.tabs-list::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

.tabs-list::-webkit-scrollbar-thumb {
    background: var(--accent-red);
    border-radius: 4px;
}

.tab-btn {
    padding: 0.75rem 1.5rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
}

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

.tab-btn.active {
    color: var(--accent-red);
    border-bottom-color: var(--accent-red);
}

/* ─── Main Content ──────────────────────────────────────────────────────────── */

.main-content {
    padding: 2rem 0 4rem;
    min-height: calc(100vh - 200px);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.section-header {
    margin: 2rem 0 1.5rem;
}

.section-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.section-subtitle {
    color: var(--text-tertiary);
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* ─── Metrics Grid ──────────────────────────────────────────────────────────── */

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.metric-card {
    background: linear-gradient(135deg, var(--bg-card), var(--bg-tertiary));
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: 1.25rem 1.5rem;
    position: relative;
    overflow: hidden;
}

.metric-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent-blue), transparent);
    opacity: 0.6;
}

.metric-card.primary {
    grid-column: span 2;
}

.metric-card.primary::before {
    background: linear-gradient(90deg, transparent, var(--accent-red), transparent);
}

.metric-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-tertiary);
    margin-bottom: 0.5rem;
}

.metric-value {
    font-size: 1.75rem;
    font-weight: 700;
    font-family: var(--font-mono);
    letter-spacing: -0.5px;
}

.metric-card.primary .metric-value {
    font-size: 2.5rem;
}

.metric-change {
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

.metric-change.positive {
    color: var(--accent-green);
}

.metric-change.negative {
    color: var(--accent-red);
}

/* ─── Charts ──────────────────────────────────────────────────────────────── */

.chart-section {
    margin: 2rem 0;
}

.chart-container {
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    padding: 2rem;
    margin-top: 1rem;
}

.chart-container canvas {
    max-height: 400px;
}

/* ─── Catalysts Grid ──────────────────────────────────────────────────────── */

.catalysts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.5rem;
}

.catalyst-card {
    background: linear-gradient(135deg, var(--bg-card), var(--bg-tertiary));
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
}

.catalyst-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    opacity: 0.6;
}

.catalyst-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.catalyst-icon {
    font-size: 2rem;
    margin-bottom: 0.75rem;
}

.catalyst-title {
    font-size: 1.125rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.catalyst-overview {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 1rem;
}

.catalyst-progress {
    background: var(--bg-tertiary);
    height: 6px;
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.catalyst-progress-bar {
    height: 100%;
    transition: width 1s ease;
    box-shadow: 0 0 12px;
}

.catalyst-status {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

/* ─── News Container ──────────────────────────────────────────────────────── */

.news-container {
    max-width: 900px;
}

.news-article {
    background: var(--bg-card);
    border-left: 3px solid;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1rem;
    transition: all 0.2s;
}

.news-article:hover {
    background: var(--bg-tertiary);
}

.news-article.positive {
    border-left-color: var(--accent-green);
}

.news-article.negative {
    border-left-color: var(--accent-red);
}

.news-article.neutral {
    border-left-color: var(--text-tertiary);
}

.news-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.news-title {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.5;
    flex: 1;
}

.news-title a {
    color: var(--text-primary);
    text-decoration: none;
    transition: color 0.2s;
}

.news-title a:hover {
    color: var(--accent-blue);
}

.news-sentiment {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.news-sentiment.positive {
    background: rgba(0, 255, 156, 0.15);
    color: var(--accent-green);
}

.news-sentiment.negative {
    background: rgba(227, 25, 55, 0.15);
    color: var(--accent-red);
}

.news-sentiment.neutral {
    background: rgba(160, 160, 160, 0.15);
    color: var(--text-secondary);
}

.news-summary {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 0.5rem;
}

.news-meta {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

/* ─── Elon Milestones ──────────────────────────────────────────────────────── */

.elon-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
}

.progress-card {
    background: linear-gradient(135deg, var(--bg-card), var(--bg-tertiary));
    border: 1px solid rgba(0, 201, 255, 0.3);
    border-top: 2px solid var(--accent-blue);
    border-radius: var(--radius-lg);
    padding: 2rem;
}

.progress-header {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--accent-blue);
    margin-bottom: 1rem;
}

.progress-values {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 1rem;
}

.progress-current {
    font-size: 2rem;
    font-weight: 700;
    font-family: var(--font-mono);
}

.progress-target {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-blue);
    font-family: var(--font-mono);
}

.progress-bar-container {
    background: var(--bg-tertiary);
    height: 24px;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 0.75rem;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-red));
    transition: width 1s ease;
    box-shadow: 0 0 12px rgba(0, 201, 255, 0.6);
}

.progress-stats {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-align: center;
}

.milestone-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.milestone-item.achieved {
    background: rgba(0, 255, 156, 0.08);
    border-color: rgba(0, 255, 156, 0.3);
}

.milestone-icon {
    font-size: 1.5rem;
}

.milestone-details {
    flex: 1;
}

.milestone-label {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.milestone-date {
    font-size: 0.875rem;
    color: var(--text-tertiary);
    font-family: var(--font-mono);
}

.milestone-mc {
    font-size: 1.25rem;
    font-weight: 700;
    font-family: var(--font-mono);
}

/* ─── Loading State ──────────────────────────────────────────────────────── */

.loading {
    text-align: center;
    padding: 3rem;
    color: var(--text-tertiary);
}

.loading::after {
    content: '...';
    animation: dots 1.5s infinite;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* ─── Footer ──────────────────────────────────────────────────────────────── */

.footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-primary);
    padding: 2rem 0;
    text-align: center;
    color: var(--text-tertiary);
    font-size: 0.75rem;
    font-family: var(--font-mono);
}

.footer p {
    margin: 0.25rem 0;
}

/* ─── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 1024px) {
    .elon-grid {
        grid-template-columns: 1fr;
    }
}

/* ── Tablet / large phone (≤ 768px) ──────────────────────────────────────── */
@media (max-width: 768px) {

    /* Container */
    .container {
        padding: 0 1rem;
    }

    /* Header — compact single row */
    .header {
        padding: 0.75rem 0;
    }

    .header-content {
        gap: 0.5rem;
        flex-wrap: nowrap;
    }

    .brand {
        flex: 1;
        min-width: 0;
        gap: 0.5rem;
    }

    .brand-icon {
        width: 36px;
        height: 36px;
        font-size: 1.1rem;
        flex-shrink: 0;
    }

    .brand-text h1 {
        font-size: 1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .brand-subtitle {
        display: none;
    }

    /* Hide portfolio value in header on mobile — visible in Overview metrics */
    .header-portfolio {
        display: none !important;
    }

    /* Refresh: icon only */
    .refresh-btn {
        padding: 0.5rem;
        flex-shrink: 0;
    }

    .refresh-btn .btn-text {
        display: none;
    }

    /* Tabs */
    .tabs-list {
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .tabs-list::-webkit-scrollbar {
        display: none;
    }

    .tab-btn {
        padding: 0.6rem 0.9rem;
        font-size: 0.8rem;
    }

    /* Main */
    .main-content {
        padding: 1.5rem 0 3rem;
    }

    .section-header {
        margin: 1.5rem 0 1rem;
    }

    .section-header h2 {
        font-size: 1.25rem;
    }

    /* Metrics grid — 2 columns is more useful than 1 on phone */
    .metrics-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
        margin-bottom: 1.5rem;
    }

    .metric-card.primary {
        grid-column: span 2;
    }

    .metric-card {
        padding: 1rem 1rem;
    }

    .metric-value {
        font-size: 1.25rem;
    }

    .metric-card.primary .metric-value {
        font-size: 2rem;
    }

    /* Charts */
    .chart-container {
        padding: 1rem;
    }

    .chart-container canvas {
        max-height: 220px;
    }

    /* Catalysts */
    .catalysts-grid {
        grid-template-columns: 1fr;
    }

    /* Disable the hover lift on touch devices */
    .catalyst-card:hover {
        transform: none;
        box-shadow: none;
    }

    /* News */
    .news-header {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .news-article {
        padding: 1rem 1.1rem;
    }

    /* Elon milestones */
    .progress-values {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .progress-current {
        font-size: 1.5rem;
    }

    .progress-target {
        font-size: 1.2rem;
    }

    .progress-card {
        padding: 1.25rem;
    }

    .milestone-item {
        flex-wrap: wrap;
    }

    .milestone-mc {
        font-size: 1rem;
    }
}

/* ── Small phone (≤ 480px) ────────────────────────────────────────────────── */
@media (max-width: 480px) {

    .container {
        padding: 0 0.75rem;
    }

    .brand-text h1 {
        font-size: 0.875rem;
    }

    .metrics-grid {
        gap: 0.5rem;
    }

    .metric-card {
        padding: 0.75rem 0.875rem;
    }

    .metric-value {
        font-size: 1.05rem;
    }

    .metric-card.primary .metric-value {
        font-size: 1.6rem;
    }

    .tab-btn {
        padding: 0.5rem 0.65rem;
        font-size: 0.72rem;
    }

    .chart-container {
        padding: 0.75rem;
    }

    .chart-container canvas {
        max-height: 180px;
    }

    .progress-bar-container {
        height: 18px;
        border-radius: 9px;
    }
}

/* ── JS-generated inline grid overrides ──────────────────────────────────── */
/*
 * Many tab panels render their layouts via inline style="" attributes.
 * We use !important here to override those inline styles at mobile widths.
 */
@media (max-width: 768px) {

    /* Two-column chart + milestone panels (Energy, Semi, Optimus, Autobidder,
       FSD, Robotaxi, SOP, Elon detail, Autos detail grids) */
    .tab-content [style*="grid-template-columns:1fr 1fr"],
    .tab-content [style*="grid-template-columns: 1fr 1fr"],
    .tab-content [style*="grid-template-columns:1fr 1.15fr"],
    .tab-content [style*="grid-template-columns:1.4fr 1fr"],
    .tab-content [style*="grid-template-columns:1.5fr 1fr"],
    .tab-content [style*="grid-template-columns:1fr 1fr 1.3fr"],
    .tab-content [style*="grid-template-columns:1fr 1fr 1fr"],
    .tab-content [style*="grid-template-columns:1fr auto auto auto auto"],
    .tab-content [style*="grid-template-columns:1fr auto auto auto"] {
        grid-template-columns: 1fr !important;
    }

    /* SOP 7-segment card strip → 3 columns */
    .tab-content [style*="grid-template-columns:repeat(7,1fr)"] {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    /* Remove viewport-height-based fixed heights so content flows naturally */
    .tab-content [style*="height:calc(100vh"],
    .tab-content [style*="height: calc(100vh"] {
        height: auto !important;
    }
}

@media (max-width: 480px) {
    /* SOP segment strip → 2 columns on very small screens */
    .tab-content [style*="grid-template-columns:repeat(7,1fr)"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}
