/**
 * Tesla Stock Calculator - Custom Styles
 * Built on top of Tailwind CSS
 */

/* ============================================
   CSS Variables for theming
   ============================================ */
:root {
    --tesla-red: #e82127;
    --tesla-red-dark: #c41d22;
    --surface-dark: #0f0f0f;
    --surface: #1a1a1a;
    --surface-light: #2a2a2a;
    
    /* Chart colors */
    --chart-bear: #ef4444;
    --chart-base: #eab308;
    --chart-bull: #22c55e;
    --chart-automotive: #3b82f6;
    --chart-optimus: #8b5cf6;
    --chart-robotaxi: #06b6d4;
    --chart-energy: #f59e0b;
}

/* Light mode overrides */
html:not(.dark) {
    --surface-dark: #f8fafc;
    --surface: #ffffff;
    --surface-light: #f1f5f9;
}

/* ============================================
   Base styles
   ============================================ */
body {
    font-feature-settings: 'kern' 1, 'liga' 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* ============================================
   Top section (Current Reality + Scenario)
   ============================================ */
.comparison-section {
    background: linear-gradient(180deg, var(--surface-dark) 0%, var(--surface) 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

html:not(.dark) .comparison-section {
    background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

/* ============================================
   Custom scrollbar
   ============================================ */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--surface-dark);
}

::-webkit-scrollbar-thumb {
    background: var(--surface-light);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #3a3a3a;
}

/* ============================================
   Form elements
   ============================================ */

/* Custom range slider */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
    width: 100%;
}

input[type="range"]::-webkit-slider-track {
    background: var(--surface-light);
    height: 6px;
    border-radius: 3px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--tesla-red);
    margin-top: -6px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    transition: transform 0.15s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

input[type="range"]::-moz-range-track {
    background: var(--surface-light);
    height: 6px;
    border-radius: 3px;
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--tesla-red);
    border: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* Custom number input */
input[type="number"] {
    -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* ============================================
   Toggle switch
   ============================================ */
.toggle-switch {
    position: relative;
    width: 48px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--surface-light);
    transition: 0.3s;
    border-radius: 24px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: #888;
    transition: 0.3s;
    border-radius: 50%;
}

input:checked + .toggle-slider {
    background-color: var(--tesla-red);
}

input:checked + .toggle-slider:before {
    transform: translateX(24px);
    background-color: white;
}

/* ============================================
   Cards and panels
   ============================================ */
.card {
    background: var(--surface);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
}

.card-static {
    background: var(--surface);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
}

/* ============================================
   Button styles
   ============================================ */
.btn-primary {
    background: linear-gradient(135deg, var(--tesla-red), var(--tesla-red-dark));
    color: white;
    font-weight: 600;
    padding: 12px 32px;
    border-radius: 8px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 15px rgba(232, 33, 39, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(232, 33, 39, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--surface-light);
    color: white;
    font-weight: 500;
    padding: 10px 24px;
    border-radius: 8px;
    transition: all 0.2s ease;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover {
    background: #3a3a3a;
    border-color: rgba(255, 255, 255, 0.2);
}

/* ============================================
   Chart container
   ============================================ */
.chart-container {
    position: relative;
    width: 100%;
    min-height: 300px;
}

/* ============================================
   Price display
   ============================================ */
.price-display {
    font-family: 'Bebas Neue', sans-serif;
    font-size: 3rem;
    letter-spacing: 0.05em;
}

.price-display.bear {
    color: var(--chart-bear);
}

.price-display.base {
    color: var(--chart-base);
}

.price-display.bull {
    color: var(--chart-bull);
}

/* ============================================
   Segment colors
   ============================================ */
.segment-automotive { color: var(--chart-automotive); }
.segment-optimus { color: var(--chart-optimus); }
.segment-robotaxi { color: var(--chart-robotaxi); }
.segment-energy { color: var(--chart-energy); }

.bg-segment-automotive { background-color: var(--chart-automotive); }
.bg-segment-optimus { background-color: var(--chart-optimus); }
.bg-segment-robotaxi { background-color: var(--chart-robotaxi); }
.bg-segment-energy { background-color: var(--chart-energy); }

/* ============================================
   Loading spinner
   ============================================ */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ============================================
   Section headers
   ============================================ */
.section-header {
    font-family: 'Bebas Neue', sans-serif;
    font-size: 2rem;
    letter-spacing: 0.05em;
    position: relative;
    display: inline-block;
}

.section-header::after {
    content: '';
    position: absolute;
    left: 0;
    bottom: -4px;
    width: 60px;
    height: 3px;
    background: var(--tesla-red);
    border-radius: 2px;
}

/* Year in scenario header */
.section-header span {
    color: var(--tesla-red);
}

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

.fade-in {
    animation: fadeIn 0.5s ease forwards;
}

/* Staggered animation delays */
.stagger-1 { animation-delay: 0.1s; }
.stagger-2 { animation-delay: 0.2s; }
.stagger-3 { animation-delay: 0.3s; }
.stagger-4 { animation-delay: 0.4s; }

/* ============================================
   Light mode adjustments
   ============================================ */
html:not(.dark) .card,
html:not(.dark) .card-static {
    background: white;
    border-color: rgba(0, 0, 0, 0.1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

html:not(.dark) .btn-secondary {
    background: #f1f5f9;
    color: #1e293b;
    border-color: rgba(0, 0, 0, 0.1);
}

html:not(.dark) .btn-secondary:hover {
    background: #e2e8f0;
}

html:not(.dark) input[type="range"]::-webkit-slider-track {
    background: #e2e8f0;
}

html:not(.dark) input[type="range"]::-moz-range-track {
    background: #e2e8f0;
}

html:not(.dark) .toggle-slider {
    background-color: #e2e8f0;
}

html:not(.dark) header {
    background: rgba(255, 255, 255, 0.8);
    border-color: rgba(0, 0, 0, 0.1);
}

html:not(.dark) footer {
    background: #f8fafc;
    border-color: rgba(0, 0, 0, 0.1);
}

/* Light mode form inputs and labels */
html:not(.dark) input[type="text"],
html:not(.dark) input[type="number"],
html:not(.dark) textarea,
html:not(.dark) select {
    background: #f1f5f9 !important;
    color: #1e293b !important;
    border-color: #cbd5e1 !important;
}

html:not(.dark) input::placeholder,
html:not(.dark) textarea::placeholder {
    color: #94a3b8 !important;
}

/* Light mode text colors for form elements */
html:not(.dark) .text-white {
    color: #1e293b !important;
}

html:not(.dark) .text-gray-400 {
    color: #475569 !important;
}

html:not(.dark) .text-gray-500 {
    color: #64748b !important;
}

html:not(.dark) .text-gray-300 {
    color: #334155 !important;
}

/* Light mode border colors */
html:not(.dark) .border-gray-700 {
    border-color: #cbd5e1 !important;
}

html:not(.dark) .border-gray-800 {
    border-color: #e2e8f0 !important;
}

/* Light mode backgrounds */
html:not(.dark) .bg-surface-dark,
html:not(.dark) .bg-surface-dark\/95 {
    background-color: rgba(248, 250, 252, 0.95) !important;
}

/* Light mode stream header hover */
html:not(.dark) .stream-header:hover {
    background-color: rgba(0, 0, 0, 0.02);
}

/* Light mode helper text */
html:not(.dark) .helper-text {
    color: #64748b;
}

/* Light mode headlines and display text */
html:not(.dark) h1,
html:not(.dark) h2,
html:not(.dark) h3,
html:not(.dark) h4,
html:not(.dark) .font-display,
html:not(.dark) .section-header {
    color: #0f172a !important;
}

/* Light mode surface-light backgrounds (used in breakdown cards, social buttons) */
html:not(.dark) .bg-surface-light,
html:not(.dark) [class*="bg-surface-light"] {
    background-color: #e2e8f0 !important;
}

/* Light mode social buttons hover */
html:not(.dark) .bg-surface-light:hover {
    background-color: #cbd5e1 !important;
}

/* Light mode icon colors in social buttons */
html:not(.dark) .text-gray-400.group-hover\:text-white {
    color: #64748b !important;
}

html:not(.dark) .group:hover .group-hover\:text-white {
    color: #1e293b !important;
}

/* Light mode body background */
html:not(.dark) body {
    background-color: #f8fafc !important;
    color: #1e293b !important;
}

/* Light mode text-gray-100 (body default) */
html:not(.dark) .text-gray-100 {
    color: #1e293b !important;
}

/* Light mode footer */
html:not(.dark) footer {
    background: #ffffff !important;
}

html:not(.dark) footer .text-gray-400,
html:not(.dark) footer .text-gray-500 {
    color: #64748b !important;
}

html:not(.dark) footer a:hover {
    color: #1e293b !important;
}

/* Breakdown cards (CAGR, Earnings Growth, P/E) */
.breakdown-card {
    background: rgba(42, 42, 42, 0.3);
}

html:not(.dark) .breakdown-card {
    background: #e2e8f0 !important;
}

/* Scenario selector container */
.scenario-selector {
    background: rgba(42, 42, 42, 0.3);
}

html:not(.dark) .scenario-selector {
    background: #e2e8f0 !important;
}

/* ============================================
   Tooltip
   ============================================ */
.tooltip {
    position: static;
    display: inline-block;
}

.tooltip::after {
    content: attr(data-tooltip);
    position: fixed;
    padding: 8px 12px;
    background: #1a1a1a;
    text-transform: none; /* Prevent inheriting uppercase from parent */
    color: white;
    font-size: 12px;
    border-radius: 6px;
    white-space: normal;
    max-width: 280px;
    width: max-content;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease;
    z-index: 99999;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    line-height: 1.4;
    /* Position will be set by JavaScript */
    top: var(--tooltip-top, 0);
    left: var(--tooltip-left, 0);
    transform: translateX(-50%) translateY(-100%);
    margin-top: -8px;
}

.tooltip:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Info icon tooltip */
.info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    margin-left: 6px;
    cursor: help;
    color: #6b7280;
    transition: color 0.2s ease;
}

.info-icon:hover {
    color: #9ca3af;
}

.info-icon svg {
    width: 100%;
    height: 100%;
}

/* Helper text below inputs */
.helper-text {
    font-size: 11px;
    color: #6b7280;
    margin-top: 4px;
    line-height: 1.4;
}

/* ============================================
   Scenario buttons
   ============================================ */
.scenario-btn {
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    background: var(--surface-light);
    color: #9ca3af;
    border: 1px solid transparent;
    transition: all 0.2s ease;
    cursor: pointer;
}

.scenario-btn:hover {
    background: #3a3a3a;
    color: white;
}

.scenario-btn.active {
    background: var(--tesla-red);
    color: white;
    border-color: var(--tesla-red);
}

.scenario-btn[data-scenario="bear"].active {
    background: #ef4444;
    border-color: #ef4444;
}

.scenario-btn[data-scenario="base"].active {
    background: #eab308;
    border-color: #eab308;
    color: #1a1a1a;
}

.scenario-btn[data-scenario="bull"].active {
    background: #22c55e;
    border-color: #22c55e;
}

/* Light mode scenario buttons - only style inactive ones */
html:not(.dark) .scenario-btn:not([class*="bg-red"]):not([class*="bg-yellow"]):not([class*="bg-green"]) {
    background: #f1f5f9;
    color: #64748b;
}

html:not(.dark) .scenario-btn:hover {
    background: #e2e8f0;
    color: #1e293b;
}

/* Active scenario button backgrounds - dark mode */
.scenario-btn-active.scenario-btn-bear {
    background-color: rgba(239, 68, 68, 0.2) !important;
}

.scenario-btn-active.scenario-btn-base {
    background-color: rgba(234, 179, 8, 0.2) !important;
}

.scenario-btn-active.scenario-btn-bull {
    background-color: rgba(34, 197, 94, 0.2) !important;
}

/* Light mode active scenario buttons */
html:not(.dark) .scenario-btn-active.scenario-btn-bear {
    background-color: rgba(239, 68, 68, 0.25) !important;
    color: #b91c1c !important;
}

html:not(.dark) .scenario-btn-active.scenario-btn-base {
    background-color: rgba(234, 179, 8, 0.25) !important;
    color: #a16207 !important;
}

html:not(.dark) .scenario-btn-active.scenario-btn-bull {
    background-color: rgba(34, 197, 94, 0.25) !important;
    color: #15803d !important;
}

/* Light mode inactive scenario button text colors */
html:not(.dark) .scenario-btn.text-red-400 {
    color: #dc2626 !important;
}

html:not(.dark) .scenario-btn.text-yellow-400 {
    color: #ca8a04 !important;
}

html:not(.dark) .scenario-btn.text-green-400 {
    color: #16a34a !important;
}

/* ============================================
   Collapsible sections
   ============================================ */
.stream-collapsible {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out, opacity 0.2s ease-out;
    opacity: 0;
}

.stream-collapsible.expanded {
    max-height: 5000px;
    opacity: 1;
    transition: max-height 0.5s ease-in, opacity 0.3s ease-in;
}

/* Inner content wrapper allows tooltips to overflow */
.stream-collapsible > div {
    overflow: visible;
    position: relative;
}

/* Ensure card containers don't clip tooltips - but allow overflow for animations */
.card-static {
    position: relative;
}

/* Special handling for stream cards - allow tooltip overflow */
.card-static.mb-6 {
    overflow: visible;
}

.stream-header {
    cursor: pointer;
    user-select: none;
}

.stream-header:hover {
    background-color: rgba(255, 255, 255, 0.02);
}

.stream-header.disabled {
    opacity: 0.5;
}

/* ============================================
   Form validation error states
   ============================================ */
.input-invalid {
    border-color: #ef4444 !important;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2) !important;
}

.validation-error-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.4);
    border-radius: 8px;
    color: #ef4444;
    font-size: 14px;
    font-weight: 500;
    animation: shake 0.4s ease;
}

.validation-error-bar svg {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-4px); }
    40%, 80% { transform: translateX(4px); }
}

/* ============================================
   Mobile navigation menu
   ============================================ */
.mobile-menu {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.3s ease-out, opacity 0.2s ease-out;
}

.mobile-menu.open {
    max-height: 400px;
    opacity: 1;
    transition: max-height 0.3s ease-in, opacity 0.2s ease-in;
}

/* Mobile nav link hover state - light mode */
html:not(.dark) .mobile-nav-link:hover {
    background-color: #f1f5f9 !important;
}

/* ============================================
   Responsive adjustments
   ============================================ */
@media (max-width: 768px) {
    .price-display {
        font-size: 2rem;
    }
    
    .section-header {
        font-size: 1.5rem;
    }
    
    .scenario-btn {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    .validation-error-bar {
        font-size: 12px;
        padding: 6px 12px;
    }
}

/* ============================================
   Blog Content Styles
   ============================================ */

/* Lead paragraph - larger intro text */
.blog-content .lead {
    font-size: 1.25rem;
    line-height: 1.75;
    color: #d1d5db;
    margin-bottom: 2rem;
    border-left: 3px solid #e31937;
    padding-left: 1.25rem;
}

/* Headings */
.blog-content h3 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #ffffff;
    margin-top: 2.5rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #374151;
}

.blog-content h4 {
    font-size: 1.125rem;
    font-weight: 600;
    color: #e5e7eb;
    margin-top: 1.75rem;
    margin-bottom: 0.75rem;
}

/* Paragraphs */
.blog-content p {
    color: #9ca3af;
    line-height: 1.8;
    margin-bottom: 1.25rem;
}

/* Bold text */
.blog-content strong {
    color: #ffffff;
    font-weight: 600;
}

/* Lists */
.blog-content ul {
    list-style: none;
    padding-left: 0;
    margin-bottom: 1.5rem;
}

.blog-content ul li {
    position: relative;
    padding-left: 1.5rem;
    margin-bottom: 0.75rem;
    color: #9ca3af;
    line-height: 1.6;
}

.blog-content ul li::before {
    content: "→";
    position: absolute;
    left: 0;
    color: #e31937;
    font-weight: bold;
}

.blog-content ul li strong {
    color: #ffffff;
}

/* Tables */
.blog-content table,
.blog-content .data-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    background: #111827;
    border: 1px solid #374151;
    border-radius: 8px;
    overflow: hidden;
}

.blog-content table th,
.blog-content .data-table th {
    background: #1f2937;
    color: #ffffff;
    font-weight: 600;
    text-align: left;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid #374151;
}

.blog-content table td,
.blog-content .data-table td {
    padding: 0.75rem 1rem;
    color: #9ca3af;
    border-bottom: 1px solid #1f2937;
}

.blog-content table tr:last-child td,
.blog-content .data-table tr:last-child td {
    border-bottom: none;
}

.blog-content table tr:hover td,
.blog-content .data-table tr:hover td {
    background: #1f2937;
}

/* Light mode blog styles */
html:not(.dark) .blog-content .lead {
    color: #4b5563;
}

html:not(.dark) .blog-content h3 {
    color: #111827;
    border-bottom-color: #e5e7eb;
}

html:not(.dark) .blog-content h4 {
    color: #374151;
}

html:not(.dark) .blog-content p {
    color: #4b5563;
}

html:not(.dark) .blog-content strong {
    color: #111827;
}

html:not(.dark) .blog-content ul li {
    color: #4b5563;
}

html:not(.dark) .blog-content ul li strong {
    color: #111827;
}

html:not(.dark) .blog-content table,
html:not(.dark) .blog-content .data-table {
    background: #ffffff;
    border-color: #e5e7eb;
}

html:not(.dark) .blog-content table th,
html:not(.dark) .blog-content .data-table th {
    background: #f9fafb;
    color: #111827;
    border-bottom-color: #e5e7eb;
}

html:not(.dark) .blog-content table td,
html:not(.dark) .blog-content .data-table td {
    color: #4b5563;
    border-bottom-color: #f3f4f6;
}

html:not(.dark) .blog-content table tr:hover td,
html:not(.dark) .blog-content .data-table tr:hover td {
    background: #f9fafb;
}

