/**
 * Market Yearly Performance Template Styles
 * Specific styling for the yearly market performance page template
 */

/* Prevent horizontal scroll on the page */
body.market-yearly-page {
    max-width: 100%;
    overflow-x: hidden;
}

/* Main container styles */
.market-yearly-performance {
    padding: 2rem 0;
}

.market-yearly-performance .container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* Stock header styling - matching existing patterns */
.market-yearly-performance .stock-header {
    margin-bottom: 0rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}

.market-yearly-performance .stock-header h1 {
    font-size: var(--h1-size);
    margin-top: 0;
    margin-bottom: 1rem;
    padding: 0;
    line-height: var(--heading-line-height);
}

/* Market cap section styling - no background, let card background show through */
.market-yearly-performance .market-cap-section {
    margin-bottom: 2rem;
    padding: 1rem;
    border-bottom: none;
}

.market-yearly-performance .market-cap-section:last-child {
    margin-bottom: 0;
}

.market-yearly-performance .market-cap-section h3 {
    font-size: 1.3rem;
    margin-bottom: 1rem;
    color: var(--text-color);
    font-weight: 600;
}

.market-yearly-performance .market-cap-section h4 {
    font-size: 1.15rem;
    margin-bottom: 0.75rem;
    color: var(--text-color);
    font-weight: 500;
}

/* Gainers and Losers section styling */
.market-yearly-performance .gainers-section,
.market-yearly-performance .losers-section {
    margin-bottom: 3rem;
    padding: 1.5rem;
}

.market-yearly-performance .gainers-section:last-child,
.market-yearly-performance .losers-section:last-child {
    margin-bottom: 0;
}

.market-yearly-performance .section-title {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    color: var(--text-color);
    font-weight: 600;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--border-color);
}


/* Country switcher section - matching card styling for consistency */
.market-yearly-performance .country-switcher-section {
    margin: 1.5rem 0;
    padding: 1rem;
    background-color: var(--bg-secondary, #f5f5f7);
    border-radius: 0.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    border: 1px solid var(--border-color);
    overflow: visible;
    position: relative;
}

.market-yearly-performance .country-switcher-text {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.market-yearly-performance .country-switcher-text strong {
    color: var(--color-text);
    font-weight: 600;
}

/* Country Switcher Dropdown Styles */
.market-yearly-performance .country-switcher-inline.dropdown {
    display: inline-flex;
    position: relative;
    margin-left: 0.5rem;
    vertical-align: middle;
}

.market-yearly-performance .country-switcher-inline .dropdown-toggle {
    display: inline-flex;
    align-items: center;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 0.9rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s ease;
}

.market-yearly-performance .country-switcher-inline .dropdown-toggle:hover {
    background-color: rgba(0, 0, 0, 0.03);
    border-color: var(--color-primary);
}

[data-theme="dark"] .market-yearly-performance .country-switcher-inline .dropdown-toggle:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.market-yearly-performance .country-switcher-inline .dropdown-toggle .flag-icon {
    margin-right: 6px;
    font-size: 1rem;
    line-height: 1;
}

.market-yearly-performance .country-switcher-inline .dropdown-toggle .country-name {
    margin-right: 6px;
    font-weight: 500;
}

.market-yearly-performance .country-switcher-inline .dropdown-toggle .caret {
    margin-left: 4px;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 4px solid var(--text-primary);
    display: inline-block;
    transition: transform 0.3s ease;
}

.market-yearly-performance .country-switcher-inline .dropdown-toggle[aria-expanded="true"] .caret {
    transform: rotate(180deg);
}

.market-yearly-performance .country-switcher-inline .dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 9999;
    display: none;
    min-width: 200px;
    max-height: 300px;
    overflow-y: auto;
    padding: 8px 0;
    margin: 2px 0 0;
    background-color: var(--color-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.3s, transform 0.3s;
}

.market-yearly-performance .country-switcher-inline .dropdown-toggle[aria-expanded="true"] + .dropdown-menu,
.market-yearly-performance .country-switcher-inline .dropdown-menu.show {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

.market-yearly-performance .country-switcher-inline .dropdown-item {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    color: var(--text-primary);
    text-decoration: none;
    transition: background-color 0.2s;
    position: relative;
}

.market-yearly-performance .country-switcher-inline .dropdown-item:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .market-yearly-performance .country-switcher-inline .dropdown-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.market-yearly-performance .country-switcher-inline .dropdown-item.active {
    background-color: rgba(0, 123, 255, 0.1);
    font-weight: 600;
}

.market-yearly-performance .country-switcher-inline .dropdown-item .flag-icon {
    margin-right: 8px;
    font-size: 1.1rem;
}

.market-yearly-performance .country-switcher-inline .dropdown-item .check-icon {
    margin-left: auto;
    color: var(--color-success);
}


/* Alert Notices */
.market-yearly-performance .alert {
    padding: 1rem 1.5rem;
    margin: 1rem 0;
    border-radius: 0.5rem;
    font-size: 0.9rem;
    line-height: 1.5;
}

.market-yearly-performance .alert.alert-info {
    background-color: var(--info-bg, #e7f3ff);
    color: var(--info-text, #0066cc);
    border: 1px solid var(--info-border, #b3d9ff);
}

.market-yearly-performance .alert.alert-warning {
    background-color: var(--warning-bg, #fff3cd);
    color: var(--warning-text, #856404);
    border: 1px solid var(--warning-border, #ffeaa7);
}

[data-theme="dark"] .market-yearly-performance .alert.alert-info {
    background-color: rgba(59, 130, 246, 0.1);
    color: #93bbfc;
    border-color: rgba(59, 130, 246, 0.3);
}

[data-theme="dark"] .market-yearly-performance .alert.alert-warning {
    background-color: rgba(255, 193, 7, 0.1);
    color: #ffc107;
    border-color: rgba(255, 193, 7, 0.3);
}


.market-yearly-performance .no-data-message {
    text-align: center;
    margin: 3rem auto;
    max-width: 600px;
}

.market-yearly-performance .no-data-message h3 {
    margin-top: 0;
    margin-bottom: 1rem;
    font-size: 1.25rem;
}

.market-yearly-performance .no-data-message p {
    margin: 0;
}

/* Summary Statistics */
.market-yearly-performance .stats-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin: 2rem 0;
}

.market-yearly-performance .stat-card {
    background-color: var(--bg-secondary, #f5f5f7);
    border-radius: 0.5rem;
    padding: 1.5rem;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    border: 1px solid var(--border-color);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.market-yearly-performance .stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.market-yearly-performance .stat-label {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.market-yearly-performance .stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.2;
}

.market-yearly-performance .stat-value.positive {
    color: var(--color-success);
}

.market-yearly-performance .stat-value.negative {
    color: var(--color-danger);
}

.market-yearly-performance .stat-value.neutral {
    color: var(--text-primary);
}

.market-yearly-performance .stat-value.near-high {
    color: #ff6b6b;
}

.market-yearly-performance .stat-value.near-low {
    color: #4ecdc4;
}

.market-yearly-performance .stat-value.new-high {
    color: #e74c3c;
}

.market-yearly-performance .stat-value.new-low {
    color: #3498db;
}

/* Tab Navigation - Sticky Implementation */
.market-yearly-performance .tab-navigation {
    display: flex;
    margin-bottom: 0;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    background-color: var(--color-bg, #fff);
    z-index: 10;
    padding: 0;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none; /* Firefox */
    top: 98px; /* Default top position, will be adjusted by JavaScript */
    box-shadow: none;
    border-top: none;
    margin-top: -1px; /* Negative margin to eliminate gap and stick properly */
}

.market-yearly-performance .tab-navigation::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Edge */
}

.market-yearly-performance .tab-button {
    padding: 0.6rem 1.2rem;
    margin-right: 0;
    cursor: pointer;
    font-weight: 400;
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-decoration: none;
    background: none;
    border: none;
    position: relative;
    transition: all var(--transition-speed) ease;
    border-bottom: 2px solid transparent;
    flex-shrink: 0;
    border-right: none;
}

.market-yearly-performance .tab-button:hover {
    color: var(--primary-color);
    background-color: rgba(0,0,0,0.03);
}

.market-yearly-performance .tab-button.active {
    color: var(--primary-color);
    background-color: transparent;
    border-bottom: 2px solid var(--primary-color);
    font-weight: 500;
}

/* Dark theme support for sticky tabs */
[data-theme="dark"] .market-yearly-performance .tab-navigation {
    background-color: var(--color-bg-dark, #1a1a1a);
    border-bottom-color: var(--border-color-dark, #333);
}

[data-theme="dark"] .market-yearly-performance .tab-button {
    color: var(--text-secondary-dark, #b3b3b3);
}

[data-theme="dark"] .market-yearly-performance .tab-button:hover {
    background-color: rgba(255,255,255,0.03);
}

[data-theme="dark"] .market-yearly-performance .tab-button.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    background-color: transparent;
}

/* Card Styles */
.market-yearly-performance .card {
    border-radius: 0.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    border: 1px solid var(--border-color);
    margin-bottom: 1.5rem; /* Consistent spacing with stock-overview */
    overflow: hidden;
    padding: 1rem; /* Add padding to make background visible around content */
}

/* Section content scroll margin for proper positioning */
.market-yearly-performance .section-content {
    scroll-margin-top: 120px; /* Adjust based on sticky header height */
}

/* Add spacing after sticky navigation */
.market-yearly-performance .tab-navigation + .card,
.market-yearly-performance .tab-navigation + * {
    margin-top: 1rem; /* Reduce spacing after sticky navigation */
}

.market-yearly-performance .card-header {
    padding: 1.5rem;
    margin: -1rem -1rem 1rem -1rem; /* Extend to card edges while maintaining internal spacing */
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    background-color: rgba(0, 0, 0, 0.02);
}

[data-theme="dark"] .market-yearly-performance .card-header {
    background-color: rgba(255, 255, 255, 0.02);
}

/* Market cap filter buttons */
.market-yearly-performance .market-cap-filter {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.market-yearly-performance .filter-button {
    padding: 0.5rem 1rem;
    background: var(--bg-secondary, #f5f5f7);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    outline: none;
    
    /* Mobile touch optimizations */
    -webkit-tap-highlight-color: transparent; /* Remove iOS tap highlight */
    -webkit-touch-callout: none; /* Disable iOS callout */
    -webkit-user-select: none; /* Disable text selection on WebKit */
    -moz-user-select: none; /* Disable text selection on Firefox */
    -ms-user-select: none; /* Disable text selection on IE/Edge */
    user-select: none; /* Disable text selection (standard) */
    touch-action: manipulation; /* Optimize for touch interactions */
    -webkit-appearance: none; /* Remove default button styling */
    -moz-appearance: none; /* Remove default button styling on Firefox */
    appearance: none; /* Remove default button styling (standard) */
}

.market-yearly-performance .filter-button:hover {
    background-color: #e3f2fd; /* Light blue background for hover */
    color: var(--primary-color); /* Primary color text */
    border-color: var(--primary-color);
    border-width: 2px; /* Thicker border on hover */
    transform: translateY(-1px); /* Subtle lift effect */
}


/* Focus states for accessibility - only show on keyboard navigation */
.market-yearly-performance .filter-button:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    border-radius: 20px; /* Maintain rounded outline */
}

/* Ensure no focus outline on mouse/touch interaction */
.market-yearly-performance .filter-button:focus:not(:focus-visible) {
    outline: none;
}

/* Mobile-specific optimizations for smooth animations */
@media (max-width: 768px) {
    .market-yearly-performance .filter-button {
        /* Force hardware acceleration for smooth animations on mobile */
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
        -webkit-perspective: 1000;
        perspective: 1000;
        
        /* Optimize touch response */
        -webkit-tap-highlight-color: rgba(0,0,0,0); /* Extra insurance against tap highlights */
        tap-highlight-color: rgba(0,0,0,0);
        
        /* Prevent zoom on double tap */
        touch-action: manipulation;
    }
    
    .market-yearly-performance .filter-button:hover {
        /* On mobile, hover is triggered by touch - ensure it works smoothly */
        -webkit-transform: translateY(-1px) translateZ(0);
        transform: translateY(-1px) translateZ(0);
    }
    
}

/* Dark theme adjustments - comprehensive high contrast states */
[data-theme="dark"] .market-yearly-performance .filter-button {
    background-color: var(--bg-secondary-dark, #252525);
    border-color: var(--border-color-dark, #333);
    color: var(--text-secondary, #e5e5e5); /* Updated to use improved contrast color */
}

[data-theme="dark"] .market-yearly-performance .filter-button:hover {
    background-color: rgba(59, 130, 246, 0.15); /* Dark blue-tinted background */
    color: #60a5fa; /* Bright blue text */
    border-color: #60a5fa;
    border-width: 2px;
    transform: translateY(-1px);
}


.market-yearly-performance .filter-count {
    font-size: 0.8rem;
    /* Removed opacity to maintain WCAG AA contrast compliance */
}

/* CSS-Only Filtering with :has() Selector */
/* Hide radio buttons */
.market-yearly-performance input[type="radio"][name$="-filter"] {
    display: none;
}

/* Style labels as buttons */
.market-yearly-performance label.filter-button {
    cursor: pointer;
}

/* Active state when radio button is checked */
.market-yearly-performance input[type="radio"]:checked + .filter-button {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    border-width: 2px;
    box-shadow: 0 3px 8px rgba(0,0,0,0.25);
    font-weight: 600;
    transform: none;
}

/* Dark mode active state */
[data-theme="dark"] .market-yearly-performance input[type="radio"]:checked + .filter-button {
    background-color: #3b82f6;
    color: white;
    border-color: #3b82f6;
    border-width: 2px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    font-weight: 600;
}

/* Hover state for checked radio buttons */
.market-yearly-performance input[type="radio"]:checked + .filter-button:hover {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    border-width: 2px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    font-weight: 600;
    transform: translateY(-1px);
}

/* Dark mode hover state for checked radio buttons */
[data-theme="dark"] .market-yearly-performance input[type="radio"]:checked + .filter-button:hover {
    background-color: #3b82f6;
    color: white;
    border-color: #3b82f6;
    border-width: 2px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    font-weight: 600;
    transform: translateY(-1px);
}

/* Show all sections by default */
.market-yearly-performance .market-cap-section {
    display: block;
    opacity: 1;
    transition: opacity 0.3s ease;
}

/* When ANY radio button (except "all") is checked in a filter group, hide ALL sections in that container */
#market-overview:has(input[type="radio"]:checked:not([value="all"])) .market-cap-section,
#market-active:has(input[type="radio"]:checked:not([value="all"])) .market-cap-section,
#market-gainers-losers:has(input[type="radio"]:checked:not([value="all"])) .market-cap-section {
    display: none;
}

/* Show all sections when "All" is selected */
#market-overview:has(input[value="all"]:checked) .market-cap-section,
#market-active:has(input[value="all"]:checked) .market-cap-section,
#market-gainers-losers:has(input[value="all"]:checked) .market-cap-section {
    display: block;
}

/* Then show only the sections matching checked filters */
/* For market-overview dual sections */
#market-overview:has(#market-overview-mega-cap:checked) .market-cap-section[data-market-cap="mega_cap"],
#market-overview:has(#market-overview-large-cap:checked) .market-cap-section[data-market-cap="large_cap"],
#market-overview:has(#market-overview-mid-cap:checked) .market-cap-section[data-market-cap="mid_cap"],
#market-overview:has(#market-overview-small-cap:checked) .market-cap-section[data-market-cap="small_cap"] {
    display: block;
}

/* Hide parent sections by default when filters are active */
#market-overview:has(input[type="radio"]:checked:not([value="all"])) .green-streak-section,
#market-overview:has(input[type="radio"]:checked:not([value="all"])) .red-streak-section {
    display: none;
}

/* Show all parent sections when "All" is selected */
#market-overview:has(input[value="all"]:checked) .green-streak-section,
#market-overview:has(input[value="all"]:checked) .red-streak-section {
    display: block;
}

/* ========================================
   UNIFIED TABLE ROW-LEVEL FILTERING
   ======================================== */

/* Show all rows by default in unified tables */
.market-yearly-performance .unified-market-cap-table tbody tr {
    display: table-row;
    transition: opacity 0.3s ease;
}

/* When ANY radio button (except "all") is checked in gainers-losers filter group, 
   hide ALL rows in unified tables */
#market-gainers-losers:has(input[type="radio"]:checked:not([value="all"])) .unified-market-cap-table tbody tr {
    display: none;
}

/* Show all rows when "All" is selected in gainers-losers */
#market-gainers-losers:has(input[value="all"]:checked) .unified-market-cap-table tbody tr {
    display: table-row;
}

/* Show only rows matching checked filters in gainers-losers */
#market-gainers-losers:has(#gainers-losers-mega-cap:checked) .unified-market-cap-table tbody tr[data-market-cap="mega_cap"],
#market-gainers-losers:has(#gainers-losers-large-cap:checked) .unified-market-cap-table tbody tr[data-market-cap="large_cap"],
#market-gainers-losers:has(#gainers-losers-mid-cap:checked) .unified-market-cap-table tbody tr[data-market-cap="mid_cap"],
#market-gainers-losers:has(#gainers-losers-small-cap:checked) .unified-market-cap-table tbody tr[data-market-cap="small_cap"] {
    display: table-row;
}

/* Extend for overview section when it gets unified tables */
#market-overview:has(input[type="radio"]:checked:not([value="all"])) .unified-market-cap-table tbody tr {
    display: none;
}

#market-overview:has(input[value="all"]:checked) .unified-market-cap-table tbody tr {
    display: table-row;
}

#market-overview:has(#market-overview-mega-cap:checked) .unified-market-cap-table tbody tr[data-market-cap="mega_cap"],
#market-overview:has(#market-overview-large-cap:checked) .unified-market-cap-table tbody tr[data-market-cap="large_cap"],
#market-overview:has(#market-overview-mid-cap:checked) .unified-market-cap-table tbody tr[data-market-cap="mid_cap"],
#market-overview:has(#market-overview-small-cap:checked) .unified-market-cap-table tbody tr[data-market-cap="small_cap"] {
    display: table-row;
}

/* Extend for most active section when it gets unified tables */
#market-active:has(input[type="radio"]:checked:not([value="all"])) .unified-market-cap-table tbody tr {
    display: none;
}

#market-active:has(input[value="all"]:checked) .unified-market-cap-table tbody tr {
    display: table-row;
}

#market-active:has(#most-active-mega-cap:checked) .unified-market-cap-table tbody tr[data-market-cap="mega_cap"],
#market-active:has(#most-active-large-cap:checked) .unified-market-cap-table tbody tr[data-market-cap="large_cap"],
#market-active:has(#most-active-mid-cap:checked) .unified-market-cap-table tbody tr[data-market-cap="mid_cap"],
#market-active:has(#most-active-small-cap:checked) .unified-market-cap-table tbody tr[data-market-cap="small_cap"] {
    display: table-row;
}

/* Fallback for browsers without :has() support */
@supports not selector(:has(*)) {
    .market-yearly-performance .unified-market-cap-table tbody tr {
        display: table-row !important;
    }
}

/* Show parent sections only if they contain visible child sections */
#market-overview:has(#market-overview-mega-cap:checked) .green-streak-section:has(.market-cap-section[data-market-cap="mega_cap"]),
#market-overview:has(#market-overview-large-cap:checked) .green-streak-section:has(.market-cap-section[data-market-cap="large_cap"]),
#market-overview:has(#market-overview-mid-cap:checked) .green-streak-section:has(.market-cap-section[data-market-cap="mid_cap"]),
#market-overview:has(#market-overview-small-cap:checked) .green-streak-section:has(.market-cap-section[data-market-cap="small_cap"]),
#market-overview:has(#market-overview-mega-cap:checked) .red-streak-section:has(.market-cap-section[data-market-cap="mega_cap"]),
#market-overview:has(#market-overview-large-cap:checked) .red-streak-section:has(.market-cap-section[data-market-cap="large_cap"]),
#market-overview:has(#market-overview-mid-cap:checked) .red-streak-section:has(.market-cap-section[data-market-cap="mid_cap"]),
#market-overview:has(#market-overview-small-cap:checked) .red-streak-section:has(.market-cap-section[data-market-cap="small_cap"]) {
    display: block;
}

/* Hide child sections when specific filters are active */
#market-overview:has(input[type="radio"]:checked:not([value="all"])) .market-cap-section {
    display: none;
}

/* For gainers-losers */
#market-gainers-losers:has(#gainers-losers-mega-cap:checked) .market-cap-section[data-market-cap="mega_cap"],
#market-gainers-losers:has(#gainers-losers-large-cap:checked) .market-cap-section[data-market-cap="large_cap"],
#market-gainers-losers:has(#gainers-losers-mid-cap:checked) .market-cap-section[data-market-cap="mid_cap"],
#market-gainers-losers:has(#gainers-losers-small-cap:checked) .market-cap-section[data-market-cap="small_cap"] {
    display: block;
}

/* For most-active */
#market-active:has(#most-active-mega-cap:checked) .market-cap-section[data-market-cap="mega_cap"],
#market-active:has(#most-active-large-cap:checked) .market-cap-section[data-market-cap="large_cap"],
#market-active:has(#most-active-mid-cap:checked) .market-cap-section[data-market-cap="mid_cap"],
#market-active:has(#most-active-small-cap:checked) .market-cap-section[data-market-cap="small_cap"] {
    display: block;
}


/* Fallback for browsers without :has() support */
@supports not selector(:has(*)) {
    .market-yearly-performance .market-cap-filter {
        display: none;
    }
    /* Show all sections if filters not supported */
    .market-yearly-performance .market-cap-section {
        display: block !important;
    }
}

.market-yearly-performance .card-header h2 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
}

/* Overview Section */
.market-yearly-performance .overview-subsection {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.market-yearly-performance .overview-subsection:last-child {
    border-bottom: none;
}

.market-yearly-performance .overview-subsection h3 {
    margin: 0 0 1rem 0;
    font-size: 1.25rem;
    font-weight: 600;
}

/* Ensure card content has proper padding when directly after header */
.market-yearly-performance .card-header + * {
    padding: 1.5rem;
    margin-top: 0; /* Remove top margin to maintain spacing consistency */
}

/* Stock List (reusing from country-overview) */
.market-yearly-performance .stock-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
    padding: 0;
}

/* Table Styles */
.market-yearly-performance .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.market-yearly-performance .stock-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.market-yearly-performance .stock-table thead {
    background-color: var(--bg-secondary);
    position: sticky;
    top: 0;
    z-index: 10;
}

.market-yearly-performance .stock-table th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    border-bottom: 2px solid var(--border-color);
}

.market-yearly-performance .stock-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.market-yearly-performance .stock-table tbody tr:hover {
    background-color: rgba(0, 0, 0, 0.02);
}

[data-theme="dark"] .market-yearly-performance .stock-table tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.02);
}

.market-yearly-performance .stock-symbol {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 600;
    display: block;
    margin-bottom: 0.25rem;
}

.market-yearly-performance .stock-symbol:hover {
    text-decoration: underline;
}

/* Sortable Table Headers */
.market-yearly-performance .sortable-header {
    position: relative;
    user-select: none;
    cursor: pointer;
}

.market-yearly-performance .sortable-header .sort-link {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    color: inherit;
    text-decoration: none;
    padding: 0;
    font-weight: inherit;
    transition: all 0.2s ease;
    width: 100%;
}

.market-yearly-performance .sortable-header .sort-link:hover {
    color: var(--primary-color);
    text-decoration: none;
}

.market-yearly-performance .sortable-header .sort-link:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    border-radius: 2px;
}

.market-yearly-performance .sortable-header.active-sort .sort-link {
    color: var(--primary-color);
    font-weight: 700;
}

.market-yearly-performance .sort-indicator {
    font-size: 0.75rem;
    opacity: 0.8;
    transition: opacity 0.2s ease;
    color: var(--primary-color);
    font-weight: bold;
}

.market-yearly-performance .sortable-header:hover .sort-indicator {
    opacity: 1;
}

/* Inactive sortable headers get a subtle hover effect */
.market-yearly-performance .sortable-header:not(.active-sort) .sort-link:hover {
    background-color: rgba(0, 0, 0, 0.03);
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    margin: -0.25rem -0.5rem;
}

[data-theme="dark"] .market-yearly-performance .sortable-header:not(.active-sort) .sort-link:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

/* Visual cue for sortable headers when not active - always visible for better UX */
.market-yearly-performance .sortable-header:not(.active-sort)::after {
    content: "⇅";
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
    opacity: 0.35;
    color: var(--text-secondary);
    transition: opacity 0.2s ease;
    pointer-events: none;
    font-weight: normal;
}

/* Enhanced visibility on hover for better user feedback */

.market-yearly-performance .sortable-header:not(.active-sort):hover::after {
    opacity: 0.7;
}

/* Accessibility improvements */
.market-yearly-performance .sortable-header .sort-link:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .market-yearly-performance .sortable-header .sort-link {
        gap: 0.25rem;
        font-size: 0.9rem;
    }
    
    .market-yearly-performance .sort-indicator {
        font-size: 0.7rem;
    }
    
    .market-yearly-performance .sortable-header:not(.active-sort)::after {
        right: 0.25rem;
        font-size: 0.65rem;
    }
}

.market-yearly-performance .company-name {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.market-yearly-performance .current-price {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.market-yearly-performance .current-price.price-negative {
    color: var(--color-danger);
}

.market-yearly-performance .percentage-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.market-yearly-performance .percentage-badge.positive {
    background-color: rgba(34, 197, 94, 0.1);
    color: var(--color-success);
}

.market-yearly-performance .percentage-badge.negative {
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--color-danger);
}

.market-yearly-performance .percentage-badge.near-high {
    background-color: rgba(255, 107, 107, 0.1);
    color: #ff6b6b;
}

.market-yearly-performance .percentage-badge.near-low {
    background-color: rgba(78, 205, 196, 0.1);
    color: #4ecdc4;
}

/* Market Cap Badge Styling */
.market-yearly-performance .company-name {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: var(--text-sm);
    color: var(--text-secondary);
    flex-wrap: wrap;
}

.market-yearly-performance .company-name .sector {
    color: var(--text-secondary);
}

.market-yearly-performance .company-name .separator {
    color: var(--text-secondary);
    opacity: 0.6;
}

.market-yearly-performance .market-cap-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    border-radius: 0.75rem;
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.025em;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    white-space: nowrap;
}

/* Market cap category colors - Light mode */
.market-yearly-performance .market-cap-mega_cap {
    background-color: rgba(59, 130, 246, 0.1);
    color: #1d4ed8;
    border-color: rgba(59, 130, 246, 0.2);
}

.market-yearly-performance .market-cap-large_cap {
    background-color: rgba(16, 185, 129, 0.1);
    color: #047857;
    border-color: rgba(16, 185, 129, 0.2);
}

.market-yearly-performance .market-cap-mid_cap {
    background-color: rgba(245, 158, 11, 0.1);
    color: #d97706;
    border-color: rgba(245, 158, 11, 0.2);
}

.market-yearly-performance .market-cap-small_cap {
    background-color: rgba(139, 92, 246, 0.1);
    color: #7c3aed;
    border-color: rgba(139, 92, 246, 0.2);
}

.market-yearly-performance .market-cap-unknown {
    background-color: rgba(107, 114, 128, 0.1);
    color: #4b5563;
    border-color: rgba(107, 114, 128, 0.2);
}

/* Dark mode colors */
[data-theme="dark"] .market-yearly-performance .market-cap-mega_cap {
    background-color: rgba(59, 130, 246, 0.15);
    color: #93c5fd;
    border-color: rgba(59, 130, 246, 0.3);
}

[data-theme="dark"] .market-yearly-performance .market-cap-large_cap {
    background-color: rgba(16, 185, 129, 0.15);
    color: #6ee7b7;
    border-color: rgba(16, 185, 129, 0.3);
}

[data-theme="dark"] .market-yearly-performance .market-cap-mid_cap {
    background-color: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
    border-color: rgba(245, 158, 11, 0.3);
}

[data-theme="dark"] .market-yearly-performance .market-cap-small_cap {
    background-color: rgba(139, 92, 246, 0.15);
    color: #c4b5fd;
    border-color: rgba(139, 92, 246, 0.3);
}

[data-theme="dark"] .market-yearly-performance .market-cap-unknown {
    background-color: rgba(107, 114, 128, 0.15);
    color: #d1d5db;
    border-color: rgba(107, 114, 128, 0.3);
}

/* Responsive design for mobile */
@media (max-width: 768px) {
    .market-yearly-performance .company-name {
        gap: 0.375rem;
    }
    
    .market-yearly-performance .market-cap-badge {
        padding: 0.1rem 0.375rem;
        font-size: 0.75rem;
    }
}

.market-yearly-performance .volume,
.market-yearly-performance .market-cap {
    font-variant-numeric: tabular-nums;
    text-align: right;
}

/* Volume column headers should align right to match data cells */
.market-yearly-performance .stock-table th.volume-header {
    text-align: right;
}

/* Stock table logo styles */
.market-yearly-performance .stock-cell {
    position: relative;
}

.market-yearly-performance .stock-info-with-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.market-yearly-performance .stock-logo.table-logo {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    object-fit: contain;
    background-color: white;
    padding: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    flex-shrink: 0;
}

.market-yearly-performance .stock-logo-fallback.table-fallback {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    background-color: var(--bg-secondary, #f5f5f7);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 1px solid var(--border-color);
}

.market-yearly-performance .stock-text-info {
    flex: 1;
    min-width: 0;
}

/* Dark mode support for table logos */
[data-theme="dark"] .market-yearly-performance .stock-logo.table-logo {
    filter: brightness(0.9) contrast(1.1);
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .market-yearly-performance .stock-logo-fallback.table-fallback {
    background-color: var(--bg-secondary-dark, #252525);
    border-color: var(--border-color-dark, #333);
}

/* Sector Performance Grid */
.market-yearly-performance .sector-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
    padding: 1.5rem;
    margin: -1rem; /* Extend to card edges */
    margin-top: 0; /* Don't extend to top since header handles that */
}

.market-yearly-performance .sector-card {
    background-color: rgba(255, 255, 255, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 1.5rem;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

[data-theme="dark"] .market-yearly-performance .sector-card {
    background-color: rgba(255, 255, 255, 0.05);
}

.market-yearly-performance .sector-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.market-yearly-performance .sector-name {
    margin: 0 0 1rem 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.market-yearly-performance .sector-stats {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.market-yearly-performance .sector-return {
    font-size: 1.5rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.market-yearly-performance .sector-return.positive {
    color: var(--color-success);
}

.market-yearly-performance .sector-return.negative {
    color: var(--color-danger);
}

.market-yearly-performance .sector-count {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.market-yearly-performance .sector-leaders {
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.market-yearly-performance .leader-label {
    font-size: 0.95rem;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
    font-weight: 600;
    display: block;
}

/* Container for market cap leaders */
.market-yearly-performance .leaders-by-cap {
    background-color: rgba(0, 0, 0, 0.02);
    border-radius: 0.375rem;
    padding: 0.75rem;
    margin-top: 0.5rem;
}

[data-theme="dark"] .market-yearly-performance .leaders-by-cap {
    background-color: rgba(255, 255, 255, 0.02);
}

/* Individual market cap leader */
.market-yearly-performance .cap-leader {
    display: flex;
    align-items: baseline;
    margin-bottom: 0.5rem;
    padding-left: 0.5rem;
}

.market-yearly-performance .cap-leader:last-child {
    margin-bottom: 0;
}

/* Market cap label (Large Cap:, Mid Cap:, etc.) */
.market-yearly-performance .cap-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
    min-width: 75px;
    margin-right: 0.75rem;
    flex-shrink: 0;
}

.market-yearly-performance .leader-link {
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 400;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: baseline;
    gap: 0.5rem;
    transition: color 0.2s ease;
}

.market-yearly-performance .leader-link:hover {
    color: var(--color-primary);
    text-decoration: none;
}

.market-yearly-performance .leader-return {
    font-size: 0.85rem;
    font-weight: 600;
    margin-left: auto;
}

/* Empty State */
.market-yearly-performance .empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-secondary);
}

.market-yearly-performance .empty-state h3 {
    margin: 0 0 0.5rem 0;
    color: var(--text-primary);
}

/* Data Disclaimer */
.market-yearly-performance .data-disclaimer {
    margin-top: 3rem;
    padding: 1rem;
    background-color: var(--bg-secondary, #f5f5f7);
    border-radius: 0.5rem;
    text-align: center;
}

.market-yearly-performance .data-disclaimer p {
    margin: 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Responsive Design */
@media (max-width: 1200px) {
    .market-yearly-performance .container {
        max-width: 100%;
    }
}

@media (max-width: 768px) {
    .market-yearly-performance .stats-summary {
        grid-template-columns: repeat(2, 1fr);
    }
    
    
    .market-yearly-performance .tab-navigation {
        padding: 0 0.5rem;
        top: 90px; /* Adjust for mobile header */
    }
    
    .market-yearly-performance .tab-button {
        padding: 0.5rem 1rem;
        font-size: 0.8rem;
    }
    
    .market-yearly-performance .section-content {
        scroll-margin-top: 110px;
    }
    
    .market-yearly-performance .stock-list {
        grid-template-columns: 1fr;
    }
    
    .market-yearly-performance .sector-grid {
        grid-template-columns: 1fr;
    }
    
    .market-yearly-performance .stock-table {
        font-size: 0.85rem;
    }
    
    .market-yearly-performance .stock-table th,
    .market-yearly-performance .stock-table td {
        padding: 0.75rem 0.5rem;
    }
    
    /* Mobile adjustments for filter buttons */
    .market-yearly-performance .market-cap-filter {
        gap: 0.375rem;
    }
    
    .market-yearly-performance .filter-button {
        padding: 0.45rem 0.85rem;
        font-size: 0.8rem;
    }
    
    /* Mobile adjustments for table logos */
    .market-yearly-performance .stock-info-with-logo {
        gap: 0.5rem;
    }
    
    .market-yearly-performance .stock-logo.table-logo {
        width: 28px;
        height: 28px;
        padding: 3px;
    }
    
    .market-yearly-performance .stock-logo-fallback.table-fallback {
        width: 28px;
        height: 28px;
        font-size: 0.75rem;
    }
    
    /* Responsive adjustments for sector performance */
    .market-yearly-performance .leaders-by-cap {
        padding: 0.5rem;
    }
    
    .market-yearly-performance .cap-label {
        min-width: 65px;
        font-size: 0.75rem;
    }
    
    .market-yearly-performance .leader-link {
        font-size: 0.85rem;
    }
}

@media (max-width: 480px) {
    .market-yearly-performance .container {
        padding: 0 0.5rem;
    }
    
    
    .market-yearly-performance .stat-card {
        padding: 1rem;
    }
    
    .market-yearly-performance .stat-value {
        font-size: 1.5rem;
    }
    
    .market-yearly-performance .card-header {
        padding: 1rem;
    }
    
    .market-yearly-performance .card-header h2 {
        font-size: 1.25rem;
    }
    
    /* Very small screen adjustments for filter buttons */
    .market-yearly-performance .market-cap-filter {
        gap: 0.25rem;
        margin-top: 0.5rem;
        width: 100%;
    }
    
    .market-yearly-performance .filter-button {
        padding: 0.35rem 0.7rem;
        font-size: 0.75rem;
    }
    
    .market-yearly-performance .filter-count {
        font-size: 0.7rem;
    }
    
    .market-yearly-performance .tab-navigation {
        top: 85px;
    }
    
    .market-yearly-performance .tab-button {
        padding: 0.625rem 0.75rem;
        font-size: 0.8rem;
    }
    
    .market-yearly-performance .section-content {
        scroll-margin-top: 105px;
    }
    
    /* Extra small mobile adjustments for table logos */
    .market-yearly-performance .stock-info-with-logo {
        gap: 0.375rem;
    }
    
    .market-yearly-performance .stock-logo.table-logo {
        width: 24px;
        height: 24px;
        padding: 2px;
    }
    
    .market-yearly-performance .stock-logo-fallback.table-fallback {
        width: 24px;
        height: 24px;
        font-size: 0.7rem;
    }
    
    /* Mobile adjustments for sector performance */
    .market-yearly-performance .sector-card {
        padding: 1rem;
    }
    
    .market-yearly-performance .leader-label {
        font-size: 0.875rem;
    }
    
    .market-yearly-performance .cap-leader {
        padding-left: 0.25rem;
    }
    
    .market-yearly-performance .cap-label {
        min-width: 60px;
    }
    
    .market-yearly-performance .leader-return {
        font-size: 0.8rem;
    }
}

/* Dark Mode Adjustments */
[data-theme="dark"] .market-yearly-performance .card {
    /* No background color - inherit from parent */
}

[data-theme="dark"] .market-yearly-performance .country-switcher-section {
    background-color: var(--bg-secondary-dark, #252525);
}

[data-theme="dark"] .market-yearly-performance .stat-card {
    background-color: var(--bg-secondary-dark, #252525);
}

[data-theme="dark"] .market-yearly-performance .market-cap-section {
    /* No background color - transparent in both themes */
}

[data-theme="dark"] .market-yearly-performance .sector-card {
    background-color: var(--bg-secondary-dark, #252525);
}

[data-theme="dark"] .market-yearly-performance .data-disclaimer {
    background-color: var(--bg-secondary-dark, #252525);
}

/* Old dark theme filter button styles - REMOVED to prevent conflicts */
/* These rules have been moved and consolidated above for better organization */

/* Red Streak Stocks Styles */

/* Section Description */
.market-yearly-performance .section-description {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin: 0.5rem 0 1rem 0;
    font-style: italic;
}

/* Table Layout Styles */
.market-yearly-performance .red-streak-table {
    border-collapse: collapse;
    width: 100%;
}

.market-yearly-performance .red-streak-table th {
    border-bottom: 2px solid var(--border-color);
    padding: 12px 8px;
    font-weight: 600;
    text-align: left;
}

[data-theme="dark"] .market-yearly-performance .red-streak-table th {
    /* No background color - inherit from parent */
}

.market-yearly-performance .red-streak-row {
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s ease;
}

.market-yearly-performance .red-streak-row:hover {
    /* No background color on hover */
}

[data-theme="dark"] .market-yearly-performance .red-streak-row:hover {
    /* No background color on hover */
}

.market-yearly-performance .streak-badge {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    color: white;
}

.market-yearly-performance .streak-badge.positive {
    background: linear-gradient(135deg, #10b981, #059669);
}

.market-yearly-performance .streak-badge.negative {
    background: linear-gradient(135deg, #ef4444, #dc2626);
}

/* Section styling for green and red streak sections */
.market-yearly-performance .green-streak-section,
.market-yearly-performance .red-streak-section {
    margin-bottom: 3rem;
}

.market-yearly-performance .green-streak-section:last-child,
.market-yearly-performance .red-streak-section:last-child {
    margin-bottom: 0;
}

/* ========================================
   FINANCIAL INSIGHT ROWS
   ======================================== */

/* Financial insight row styling */
.market-yearly-performance .financial-insight-row {
    background-color: var(--bg-tertiary, #f8f9fa);
    border-bottom: 1px solid var(--border-color);
    transition: opacity 0.3s ease, background-color 0.2s ease;
}

[data-theme="dark"] .market-yearly-performance .financial-insight-row {
    background-color: rgba(255, 255, 255, 0.03);
}

/* Financial insight cell */
.market-yearly-performance .financial-insight-cell {
    padding: 0 !important;
}

/* Financial insight content container */
.market-yearly-performance .financial-insight-content {
    padding: 1.25rem 1.5rem;
    border-left: 4px solid transparent;
    position: relative;
    overflow: hidden;
}

/* Green streak insight styling */
.market-yearly-performance .green-streak-insight {
    border-left-color: #10b981;
    background: linear-gradient(to right, rgba(16, 185, 129, 0.05) 0%, transparent 50%);
}

[data-theme="dark"] .market-yearly-performance .green-streak-insight {
    background: linear-gradient(to right, rgba(16, 185, 129, 0.08) 0%, transparent 50%);
}

/* Red streak insight styling */
.market-yearly-performance .red-streak-insight {
    border-left-color: #ef4444;
    background: linear-gradient(to right, rgba(239, 68, 68, 0.05) 0%, transparent 50%);
}

[data-theme="dark"] .market-yearly-performance .red-streak-insight {
    background: linear-gradient(to right, rgba(239, 68, 68, 0.08) 0%, transparent 50%);
}

/* Insight text styling */
.market-yearly-performance .insight-text {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.65;
    color: var(--text-secondary);
    letter-spacing: -0.01em;
}

[data-theme="dark"] .market-yearly-performance .insight-text {
    color: var(--text-primary);
    opacity: 0.9;
}

/* Ensure financial insight rows follow filter visibility rules */
#market-overview:has(input[type="radio"]:checked:not([value="all"])) .financial-insight-row {
    display: none;
}

#market-overview:has(input[value="all"]:checked) .financial-insight-row {
    display: table-row;
}

/* Show financial insight rows only for matching market cap filters */
#market-overview:has(#market-overview-mega-cap:checked) .financial-insight-row[data-market-cap="mega_cap"],
#market-overview:has(#market-overview-large-cap:checked) .financial-insight-row[data-market-cap="large_cap"],
#market-overview:has(#market-overview-mid-cap:checked) .financial-insight-row[data-market-cap="mid_cap"],
#market-overview:has(#market-overview-small-cap:checked) .financial-insight-row[data-market-cap="small_cap"] {
    display: table-row;
}

/* Mobile optimization for insight text */
@media (max-width: 768px) {
    .market-yearly-performance .financial-insight-content {
        padding: 1rem 1rem;
    }
    
    .market-yearly-performance .insight-text {
        font-size: 0.875rem;
        line-height: 1.6;
    }
}

/* Hover effects for better interaction */
.market-yearly-performance tr:hover + .financial-insight-row {
    background-color: var(--bg-secondary);
}

[data-theme="dark"] .market-yearly-performance tr:hover + .financial-insight-row {
    background-color: rgba(255, 255, 255, 0.05);
}

/* Animation for smooth appearance */
.market-yearly-performance .financial-insight-row {
    animation: fadeIn 0.3s ease-out;
}

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

/* Year Button Selector Styles */
.market-yearly-performance .year-selector-section {
    margin-bottom: 2rem;
    padding: 1.5rem 0;
    border-bottom: 1px solid var(--border-color);
}

.market-yearly-performance .year-button-selector {
    display: flex;
    justify-content: center;
    align-items: center;
}

.market-yearly-performance .year-button-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
    align-items: center;
    max-width: 100%;
}

.market-yearly-performance .year-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.25rem;
    min-width: 4rem;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    color: var(--text-color);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    transition: all 0.2s ease;
    white-space: nowrap;
}

.market-yearly-performance .year-button:hover {
    color: var(--accent-color);
    background-color: var(--bg-secondary);
    border-color: var(--accent-color);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.market-yearly-performance .year-button:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--accent-color), 0 0 0 4px rgba(59, 130, 246, 0.2);
}

.market-yearly-performance .year-button.current-year {
    color: var(--bg-primary);
    background-color: var(--accent-color);
    border-color: var(--accent-color);
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.market-yearly-performance .year-button.current-year:hover {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Dark theme support */
[data-theme="dark"] .market-yearly-performance .year-button {
    background-color: var(--bg-secondary);
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .market-yearly-performance .year-button:hover {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: var(--accent-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .market-yearly-performance .year-button.current-year {
    color: var(--text-dark);
    background-color: var(--accent-color);
}

/* Mobile responsive styles */
@media (max-width: 768px) {
    .market-yearly-performance .year-selector-section {
        margin-bottom: 1.5rem;
        padding: 1rem 0;
    }
    
    .market-yearly-performance .year-button-selector {
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        scrollbar-color: var(--accent-color) transparent;
    }
    
    .market-yearly-performance .year-button-list {
        flex-wrap: nowrap;
        justify-content: flex-start;
        gap: 0.5rem;
        min-width: max-content;
        padding: 0 1rem;
    }
    
    .market-yearly-performance .year-button {
        padding: 0.625rem 1rem;
        min-width: 3.5rem;
        font-size: 0.8rem;
        flex-shrink: 0;
    }
    
    /* Scroll current year into view on mobile */
    .market-yearly-performance .year-button.current-year {
        scroll-margin-left: 1rem;
        scroll-margin-right: 1rem;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    .market-yearly-performance .year-button {
        padding: 0.5rem 0.875rem;
        min-width: 3rem;
        font-size: 0.75rem;
    }
    
    .market-yearly-performance .year-button-list {
        gap: 0.375rem;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .market-yearly-performance .year-button {
        border-width: 2px;
    }
    
    .market-yearly-performance .year-button.current-year {
        border-width: 3px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .market-yearly-performance .year-button {
        transition: none;
    }
    
    .market-yearly-performance .year-button:hover {
        transform: none;
    }
}

/* ========================================
   DETAILED MARKET CAP STATS TOGGLE
   ======================================== */

/* Detailed stats toggle container */
.market-yearly-performance .detailed-stats-toggle {
    margin: 1.5rem 0;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background-color: var(--bg-secondary, #f5f5f7);
    overflow: hidden;
    transition: all 0.3s ease;
}

.market-yearly-performance .detailed-stats-toggle:hover {
    border-color: var(--accent-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* Summary button styling */
.market-yearly-performance .view-detailed-btn {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-color);
    background-color: transparent;
    border: none;
    width: 100%;
    text-align: left;
    transition: all 0.2s ease;
    user-select: none;
}

.market-yearly-performance .view-detailed-btn:hover {
    background-color: var(--bg-primary);
    color: var(--accent-color);
}

.market-yearly-performance .view-detailed-btn:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* Toggle icon */
.market-yearly-performance .toggle-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--accent-color);
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

/* Rotate icon when open */
.market-yearly-performance .detailed-stats-toggle[open] .toggle-icon {
    transform: rotate(45deg);
}

/* Content area */
.market-yearly-performance .detailed-stats-content {
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-primary);
    animation: fadeIn 0.3s ease;
}

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

/* Market cap table container and styling */
.market-yearly-performance .market-cap-table-container {
    padding: 1.5rem;
    overflow-x: auto;
}

.market-yearly-performance .market-cap-stats-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    background-color: var(--bg-primary);
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.market-yearly-performance .market-cap-stats-table thead {
    background-color: var(--bg-secondary, #f5f5f7);
}

.market-yearly-performance .market-cap-stats-table th {
    padding: 1rem 0.75rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-color);
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}

.market-yearly-performance .market-cap-stats-table th:first-child {
    padding-left: 1rem;
}

.market-yearly-performance .market-cap-stats-table th:last-child {
    padding-right: 1rem;
}

.market-yearly-performance .market-cap-stats-table tbody tr {
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s ease;
}

.market-yearly-performance .market-cap-stats-table tbody tr:hover {
    background-color: var(--bg-secondary, #f5f5f7);
}

.market-yearly-performance .market-cap-stats-table tbody tr:last-child {
    border-bottom: none;
}

.market-yearly-performance .market-cap-stats-table td {
    padding: 1rem 0.75rem;
    font-size: 0.9rem;
    vertical-align: middle;
}

.market-yearly-performance .market-cap-stats-table td:first-child {
    padding-left: 1rem;
}

.market-yearly-performance .market-cap-stats-table td:last-child {
    padding-right: 1rem;
}

.market-yearly-performance .market-cap-stats-table .market-cap-name {
    font-weight: 500;
    color: var(--text-color);
    min-width: 120px;
}

.market-yearly-performance .market-cap-stats-table .stat-value {
    font-weight: 600;
    text-align: center;
    min-width: 80px;
}

/* Color coding for table values */
.market-yearly-performance .market-cap-stats-table .stat-value.positive {
    color: var(--success-color, #10b981);
}

.market-yearly-performance .market-cap-stats-table .stat-value.negative {
    color: var(--danger-color, #ef4444);
}

.market-yearly-performance .market-cap-stats-table .stat-value.neutral {
    color: var(--text-color);
}

/* Dark theme support */
[data-theme="dark"] .market-yearly-performance .detailed-stats-toggle {
    background-color: var(--bg-secondary);
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .market-yearly-performance .view-detailed-btn:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .market-yearly-performance .detailed-stats-content {
    background-color: var(--bg-primary);
    border-top-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .market-yearly-performance .market-cap-stats-table {
    background-color: var(--bg-primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .market-yearly-performance .market-cap-stats-table thead {
    background-color: var(--bg-secondary);
}

[data-theme="dark"] .market-yearly-performance .market-cap-stats-table th {
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .market-yearly-performance .market-cap-stats-table tbody tr {
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .market-yearly-performance .market-cap-stats-table tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
    .market-yearly-performance .detailed-stats-toggle {
        margin: 1rem 0;
    }
    
    .market-yearly-performance .view-detailed-btn {
        padding: 0.875rem 1rem;
        font-size: 0.9rem;
    }
    
    .market-yearly-performance .market-cap-table-container {
        padding: 1rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .market-yearly-performance .market-cap-stats-table {
        min-width: 500px; /* Ensure table doesn't get too compressed */
    }
    
    .market-yearly-performance .market-cap-stats-table th,
    .market-yearly-performance .market-cap-stats-table td {
        padding: 0.75rem 0.5rem;
        font-size: 0.8rem;
    }
    
    .market-yearly-performance .market-cap-stats-table th:first-child,
    .market-yearly-performance .market-cap-stats-table td:first-child {
        padding-left: 0.75rem;
    }
    
    .market-yearly-performance .market-cap-stats-table th:last-child,
    .market-yearly-performance .market-cap-stats-table td:last-child {
        padding-right: 0.75rem;
    }
    
    .market-yearly-performance .market-cap-stats-table .market-cap-name {
        min-width: 100px;
        font-size: 0.8rem;
    }
    
    .market-yearly-performance .market-cap-stats-table .stat-value {
        min-width: 70px;
        font-size: 0.8rem;
    }
}

/* Reduced motion support for detailed stats */
@media (prefers-reduced-motion: reduce) {
    .market-yearly-performance .detailed-stats-toggle,
    .market-yearly-performance .view-detailed-btn,
    .market-yearly-performance .toggle-icon {
        transition: none;
    }
    
    .market-yearly-performance .detailed-stats-content {
        animation: none;
    }
}

/* Year Selector Styles */
.market-yearly-performance .year-selector-section {
    margin-bottom: 2rem;
    padding: 0 0 1.5rem 0;
    border-bottom: 1px solid var(--border-color);
}

.market-yearly-performance .year-button-selector {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    border-radius: var(--border-radius);
    outline: none;
}

/* Keyboard navigation focus styles */
.market-yearly-performance .year-button-selector:focus {
    box-shadow: 0 0 0 2px var(--accent-color), 0 0 0 4px rgba(59, 130, 246, 0.2);
    outline: none;
}

.market-yearly-performance .year-button-list {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.75rem;
    justify-content: center;
    align-items: center;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* Internet Explorer and Edge */
}

/* Hide scrollbar for Chrome, Safari and other WebKit browsers */
.market-yearly-performance .year-button-list::-webkit-scrollbar {
    display: none;
}

.market-yearly-performance .year-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.25rem;
    min-width: 8rem;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    color: var(--text-color);
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    transition: all 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Hover states */
.market-yearly-performance .year-button:hover {
    color: var(--accent-color);
    background-color: var(--bg-secondary);
    border-color: var(--accent-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Focus states */
.market-yearly-performance .year-button:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--accent-color), 0 0 0 4px rgba(59, 130, 246, 0.2);
}

/* Current/Active year styling */
.market-yearly-performance .year-button.current-year {
    color: var(--bg-primary);
    background-color: var(--accent-color);
    border-color: var(--accent-color);
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.market-yearly-performance .year-button.current-year:hover {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Dark Theme Support */
[data-theme="dark"] .market-yearly-performance .year-button {
    background-color: var(--bg-secondary);
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .market-yearly-performance .year-button:hover {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: var(--accent-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .market-yearly-performance .year-button.current-year {
    color: var(--text-dark);
    background-color: var(--accent-color);
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    .market-yearly-performance .year-selector-section {
        margin-bottom: 1.5rem;
        padding: 0 0 1rem 0;
    }
    
    .market-yearly-performance .year-button-selector {
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    
    .market-yearly-performance .year-button-list {
        flex-wrap: nowrap;
        justify-content: flex-start;
        gap: 0.5rem;
        min-width: max-content;
        padding: 0 1rem;
    }
    
    .market-yearly-performance .year-button {
        padding: 0.625rem 1rem;
        min-width: 7rem;
        font-size: 0.8rem;
        flex-shrink: 0;
    }
    
    .market-yearly-performance .year-button.current-year {
        scroll-margin-left: 1rem;
        scroll-margin-right: 1rem;
    }
}

@media (max-width: 480px) {
    .market-yearly-performance .year-button {
        padding: 0.5rem 0.75rem;
        min-width: 6rem;
        font-size: 0.7rem;
    }
    
    .market-yearly-performance .year-button-list {
        gap: 0.375rem;
    }
}

/* Accessibility Features */
/* High contrast mode support */
@media (prefers-contrast: high) {
    .market-yearly-performance .year-button {
        border-width: 2px;
    }
    
    .market-yearly-performance .year-button.current-year {
        border-width: 3px;
    }
}

/* Reduced motion support for year selector */
@media (prefers-reduced-motion: reduce) {
    .market-yearly-performance .year-button {
        transition: none;
    }
    
    .market-yearly-performance .year-button:hover {
        transform: none;
    }
}