/* ========================================
   INVESTMENTS MOBILE CSS
   Patch spécifique pour le mobile sans toucher au CSS desktop
   ======================================== */

@media (max-width: 768px) {

    /* NUCLEAR FIX: Force header to stay fixed on mobile */
    .mobile-header {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100vw !important;
        z-index: 999999 !important;
        display: flex !important;
        transform: none !important;
    }

    /* RESET MARGINS TOP */
    .portfolio-summary-enhanced {
        margin-top: 0 !important;
        padding-top: 0 !important;
    }

    /* --- MOBILE KPI GRID (Total Value Left / Others Right) --- */
    .summary-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto;
        gap: 12px;
        margin-bottom: 24px;
    }

    .summary-card {
        min-height: auto;
        padding: 12px;
    }

    /* Total Value: Takes Left Column, Spans 2 Rows */
    .summary-card:nth-child(1) {
        grid-column: 1;
        grid-row: 1 / 3;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        /* Center horizontally */
        text-align: center;
        /* Center text */
        height: auto;
    }

    /* Total Return: Right Top */
    .summary-card:nth-child(2) {
        grid-column: 2;
        grid-row: 1;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    /* Var Today: Right Bottom */
    .summary-card:nth-child(3) {
        grid-column: 2;
        grid-row: 2;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    /* Adjust font sizes for compact 2-col view */
    .summary-card-value {
        font-size: 20px !important;
    }

    /* Bigger font specifically for Total Value (1st card) */
    .summary-card:nth-child(1) .summary-card-value {
        font-size: 26px !important;
        /* Larger font */
        margin-bottom: 8px;
        /* Space */
    }

    .summary-card-label {
        font-size: 10px !important;
        margin-bottom: 4px;
    }

    .meta-info,
    .meta-large {
        font-size: 11px !important;
    }

    /* --- PERFORMANCE STATS GRID (Best/Worst Performer) --- */
    .summary-stats {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 12px !important;
    }

    .summary-stats .stat-item {
        min-width: auto !important;
        width: auto !important;
    }

    /* Cash Reserve (Last Item) - SPAN FULL WIDTH */
    .summary-stats .stat-item:last-child {
        grid-column: 1 / -1 !important;
    }

    /* --- CHART HEIGHT & INNER BORDER REMOVAL --- */
    .chart-wrapper.tall {
        height: 250px !important;
        /* Force smaller height */
        margin: 0 !important;
        border: none !important;
        /* REMOVE INNER FRAME */
        background: transparent !important;
        box-shadow: none !important;
        padding-left: 10px;
        padding-right: 10px;
    }

    .historical-chart-container.ultra-compact {
        padding-left: 0px !important;
        padding-right: 0px !important;
        padding-top: 0px !important;
        padding-bottom: 10px !important;
        /* Remove ALL padding */
    }

    /* --- CHART HEADER ALIGNMENT (Match Dashboard) --- */
    .chart-header-mini {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
        padding: 10px !important;
        border-bottom: 1px solid var(--border-color) !important;
        /* Add separator line */
        margin-bottom: 0 !important;
        /* Remove margin so it sits on grid/chart */
    }

    /* Reduce Title Size & Remove Box Style */
    .chart-title {
        font-size: 14px !important;
        margin: 0 !important;
        flex: 1 1 auto !important;
        /* Allow title to shrink/grow */
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        color: white !important;
        /* Force Title White */
    }

    #chart-title-text {
        font-size: 14px !important;
        color: white !important;
        /* ensure text is white */
    }

    /* Controls Container */
    .header-controls {
        flex: 1 0 100% !important;
        /* Force full width on new line if wrapped */
        display: flex !important;
        justify-content: space-between !important;
        /* Benchmark Left, Toggle Right */
        align-items: center !important;
        /* Align heights center */
        margin-top: 4px !important;
        gap: 0 !important;
        /* Space handled by justify-between */
    }

    /* Compact Buttons & Height Match */
    .benchmark-select-wrapper {
        display: flex;
        align-items: center;
    }

    .benchmark-select-wrapper select {
        padding: 0 8px !important;
        font-size: 11px !important;
        height: 28px !important;
        /* Explicit common height */
        line-height: normal !important;
        width: 130px !important;
        /* Slightly fixed width for stability */
    }

    .view-toggle {
        display: flex;
        align-items: center;
        height: 28px !important;
    }

    .view-toggle .toggle-btn {
        padding: 0 10px !important;
        font-size: 11px !important;
        height: 100% !important;
        /* Fill container 28px */
        display: flex !important;
        align-items: center !important;
    }

    /* Hide Title Text on very small screens if needed, or keep small */
    #chart-title-text {
        font-size: 14px !important;
        font-weight: 600 !important;
        white-space: nowrap !important;
    }

    /* Hide Time */
    #last-update {
        display: none !important;
    }

    /* --- CHART STATS COMPACT LAYOUT (3 Columns: Period | Var | Close) --- */
    .chart-stats-bar {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        padding: 10px 0 !important;
        /* Remove side padding to max width */
        gap: 0 !important;
        margin-top: 0 !important;
        /* Matches Dashboard: Let background inherit (var(--bg-secondary)) */
        /* background: transparent !important; -> REMOVED */

        border: none !important;
        /* Remove box border */
        box-shadow: none !important;
        border-top: 1px solid var(--border-color) !important;
        /* Match Dashboard color */
        border-radius: 0 !important;
        /* Ensure it blends if wide */
    }

    /* Group 1: Period (33%) */
    .stat-group-1 {
        flex: 0 0 34% !important;
        /* Fixed width matched to 1/3 roughly */
        border-right: 1px solid rgba(255, 255, 255, 0.1) !important;
        /* SEPARATOR */
        padding-right: 2px !important;
        display: flex !important;
        justify-content: center !important;
    }

    /* Group 2: Var + Close (66%) */
    .stat-group-2 {
        flex: 1 !important;
        display: flex !important;
        padding-left: 8px !important;
        /* Shift Right */
    }

    /* Inside Group 2: Var and Close need to share space */
    .stat-group-2 .stat {
        flex: 1 !important;
        display: block !important;
        /* Enable inline contents */
        text-align: center !important;
        white-space: nowrap !important;
        /* PREVENT WRAPPING */
        overflow: hidden !important;
        /* Safety */
    }

    /* FIX: Allow JS to hide elements (Respect display: none) */
    .stat-group-2 .stat[style*="none"] {
        display: none !important;
    }

    /* Ensure Layout for Block Display */
    .stat-group-1 .stat {
        display: block !important;
        text-align: center !important;
    }

    /* ALIGN VALUE AND PCT ON SAME LINE ("meme ligne") */
    .stat-group .label {
        display: block !important;
        font-size: 9px !important;
        margin-bottom: 2px !important;
        color: var(--text-muted) !important;
    }

    .stat-group .value {
        display: inline-block !important;
        /* Inline */
        font-size: 13px !important;
        /* Adjusted for single line fit */
        margin-right: 3px !important;
    }

    .stat-group .pct {
        display: inline-block !important;
        /* Inline */
        font-size: 11px !important;
        /* Smaller pct */
    }

    /* Tertiary Stats Row */
    /* Tertiary Stats Row */
    .stat-group-3 {
        display: flex !important;
        flex-direction: row !important;
        width: 100% !important;
        justify-content: space-between !important;
        border-top: none !important;
        /* Matches Dashboard (No extra line) */
        padding-top: 8px !important;
        margin-top: 8px !important;
        padding-left: 10px !important;
        padding-right: 10px !important;
    }

    .stat-group-3 .stat {
        min-width: auto !important;
        text-align: center !important;
    }

    .stat-group-3 .label {
        font-size: 8px !important;
        text-align: center !important;
    }

    .stat-group-3 .value {
        font-size: 11px !important;
        display: block !important;
        /* Restore block for these */
    }

    /* --- PERIOD BUTTONS (Segmented Control Look) --- */
    .chart-controls {
        display: flex !important;
        width: 100% !important;
        background: rgba(255, 255, 255, 0.03);
        padding: 4px;
        border-radius: 12px;
        margin-top: 15px;
        margin-bottom: 5px;
        justify-content: space-between;
        gap: 4px;
    }

    .chart-controls .period-btn {
        flex: 1;
        padding: 8px 0;
        border-radius: 8px;
        background: transparent;
        border: none;
        color: var(--text-muted);
        font-size: 12px;
        font-weight: 500;
        cursor: pointer;
        transition: all 0.2s ease;
        text-align: center;
    }

    .chart-controls .period-btn.active {
        background: var(--primary-color);
        color: white;
        box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
        font-weight: 600;
    }

    /* ========================================
       MOBILE SEARCH & FILTER OPTIMIZATION
       ======================================== */
    .filters-container {
        display: flex;
        flex-direction: column;
        gap: 12px;
        margin-bottom: 16px;
        width: 100%;
    }

    .search-row {
        display: flex;
        gap: 8px;
        width: 100%;
    }

    #search-input {
        flex: 1;
        min-width: 0;
        /* Allow shrinking */
        width: 100%;
    }

    #clear-filters {
        flex: 0 0 40px;
        /* Icon square button */
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .filter-row {
        display: flex;
        gap: 8px;
        width: 100%;
        overflow-x: auto;
        /* Safety scroll */
        padding-bottom: 4px;
        /* Space for scrollbar if any */
    }

    /* Force 3 items to fit on line equally */
    .filter-row>* {
        flex: 1 1 0px;
        /* Force equal width ignoring content properly */
        min-width: 0;
        max-width: 100%;
        /* Prevent overflow */
    }

    /* Dropdown specific styling for tight fit */
    .filter-row select,
    .filter-row #ticker-filter-dropdown {
        width: 100% !important;
        max-width: 100% !important;
    }

    .filter-row #ticker-filter-dropdown button {
        width: 100% !important;
        min-width: auto !important;
        font-size: 11px !important;
        padding: 8px 2px !important;
        /* Very tight padding */
        height: 36px !important;
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
        display: flex;
        align-items: center;
        justify-content: space-between;
        /* Ensure arrow pushes right */
    }

    .filter-row select {
        font-size: 11px !important;
        padding: 8px 2px !important;
        height: 36px !important;
    }

    /* Hide some ticker dropdown internal text if too long?? 
       The ticker dropdown might have complex structure. 
       Let's ensure it behaves like a select. 
    */
    #ticker-filter-dropdown #filter-toggle {
        min-width: auto !important;
        width: 100% !important;
        padding: 8px 4px !important;
        justify-content: space-between;
    }

    #ticker-filter-dropdown #filter-toggle span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .title-icon {
        font-size: 16px;
        filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
    }

    /* ========================================
       INVESTMENTS TABLE - MOBILE CARDS REMOVED
       (Handled by investments-table-compact.css)
       ======================================== */
}