/* ============================================
   MOBILE-OPTIMIZED STYLES
   Add AFTER styles.css in all HTML files
   ============================================ */

/* ============================================
   RESPONSIVE TYPOGRAPHY
   ============================================ */

/* Override base font sizes to be mobile-first */
body {
    font-size: 14px !important; /* Mobile base - override the 19.6px */
}

@media (min-width: 768px) {
    body {
        font-size: 15px !important; /* Tablet */
    }
}

@media (min-width: 1024px) {
    body {
        font-size: 16px !important; /* Desktop */
    }
}

/* ============================================
   TOUCH-FRIENDLY TARGETS
   Apple HIG: 44x44px minimum
   ============================================ */

@media (max-width: 768px) {
    .action-btn,
    .market-item,
    .news-item,
    .crypto-item,
    .nav-link,
    button,
    a.btn {
        min-height: 44px;
        padding: 12px 16px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Make search input taller on mobile */
    #search-input {
        min-height: 44px;
        padding: 12px 16px;
        font-size: 16px; /* Prevents iOS zoom */
    }
}

/* ============================================
   MOBILE NAVIGATION
   ============================================ */

@media (max-width: 768px) {
    .header-content {
        padding: 0.75rem 1rem;
    }
    
    .nav-links {
        position: fixed;
        top: 60px;
        left: -100%;
        width: 80%;
        max-width: 300px;
        height: calc(100vh - 60px);
        background: var(--bg-secondary);
        flex-direction: column;
        transition: left 0.3s ease-in-out;
        z-index: 999;
        padding: 1rem 0;
        overflow-y: auto;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.5);
    }
    
    .nav-links.mobile-open {
        left: 0;
    }
    
    .nav-link {
        width: 100%;
        padding: 1rem 1.5rem;
        border-bottom: 1px solid var(--border-primary);
        justify-content: flex-start;
        font-size: 16px;
    }
    
    /* Mobile menu overlay */
    .nav-links.mobile-open::before {
        content: '';
        position: fixed;
        top: 60px;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: -1;
    }
    
    /* Hamburger menu animation */
    .mobile-menu-toggle {
        display: flex !important;
    }
    
    .logo-text {
        display: none; /* Hide "Terminal" text on mobile */
    }
}

/* ============================================
   MOBILE DASHBOARD LAYOUT
   ============================================ */

@media (max-width: 768px) {
    .dashboard {
        padding: 1rem;
    }
    
    .dashboard-header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    
    .dashboard-title {
        font-size: 1.5rem;
    }
    
    .dashboard-actions {
        width: 100%;
        justify-content: space-between;
    }
    
    /* Make search full width on mobile */
    .search-container {
        width: 100%;
        max-width: none;
    }
}

/* ============================================
   MOBILE CARDS & GRIDS
   ============================================ */

@media (max-width: 768px) {
    /* Single column on mobile */
    .market-grid,
    .content-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }
    
    /* 2-column for stats on mobile */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem;
    }
    
    .section {
        padding: 1rem;
    }
    
    .section-header {
        font-size: 1.25rem;
        padding: 0.75rem 0;
    }
}

/* ============================================
   MOBILE DETAILS PAGE
   ============================================ */

@media (max-width: 768px) {
    .details-page {
        padding: 1rem !important;
    }
    
    .details-hero {
        padding: 1.5rem 1rem;
    }
    
    .details-header-section {
        flex-direction: column;
        gap: 1.5rem;
    }
    
    .company-name {
        font-size: 1.5rem !important;
    }
    
    .company-meta {
        font-size: 12px;
        flex-wrap: wrap;
    }
    
    .price-section {
        text-align: left;
        width: 100%;
    }
    
    .current-price {
        font-size: 2rem !important;
    }
    
    .price-change {
        font-size: 1.25rem !important;
        justify-content: flex-start;
    }
    
    /* Action buttons stack on mobile */
    .action-buttons {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .action-btn {
        width: 100%;
        justify-content: center;
    }
}

/* ============================================
   MOBILE CHART OPTIMIZATIONS
   ============================================ */

@media (max-width: 768px) {
    .chart-container {
        height: 300px !important;
        padding: 0.75rem;
    }
    
    .chart-period-btn {
        padding: 0.5rem 0.75rem;
        font-size: 11px;
    }
    
    #tradingview_chart,
    .yahoo-chart-container {
        min-height: 250px;
    }
}

/* ============================================
   MOBILE TABLES
   ============================================ */

@media (max-width: 768px) {
    .info-card {
        padding: 1rem;
        overflow-x: auto;
    }
    
    .info-card-title {
        font-size: 1rem;
    }
    
    /* Make tables scrollable */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Compact table on mobile */
    table {
        font-size: 12px;
    }
    
    table th,
    table td {
        padding: 0.5rem 0.75rem;
        white-space: nowrap;
    }
}

/* ============================================
   MOBILE NEWS FEED
   ============================================ */

@media (max-width: 768px) {
    .news-item {
        flex-direction: column;
        align-items: flex-start;
        padding: 1rem;
    }
    
    .news-thumbnail {
        width: 100%;
        height: 150px;
        margin-bottom: 0.75rem;
    }
    
    .news-content {
        width: 100%;
    }
    
    .news-title {
        font-size: 14px;
        line-height: 1.4;
    }
    
    .news-meta {
        font-size: 11px;
        margin-top: 0.5rem;
    }
}

/* ============================================
   MOBILE WATCHLIST
   ============================================ */

@media (max-width: 768px) {
    .watchlist-empty {
        padding: 2rem 1rem;
        text-align: center;
    }
    
    .watchlist-item {
        padding: 1rem;
    }
    
    .watchlist-info {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
}

/* ============================================
   MOBILE PERFORMANCE INDICATORS
   ============================================ */

@media (max-width: 768px) {
    .performance-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem;
    }
    
    .performance-card {
        padding: 0.75rem;
    }
    
    .performance-label {
        font-size: 11px;
    }
    
    .performance-value {
        font-size: 1rem;
    }
}

/* ============================================
   MOBILE CONTENT LAYOUT
   ============================================ */

@media (max-width: 768px) {
    .content-layout {
        flex-direction: column !important;
        gap: 1.5rem;
    }
    
    .main-content,
    .sidebar {
        width: 100% !important;
        max-width: none !important;
    }
}

/* ============================================
   MOBILE SCROLLBAR
   ============================================ */

@media (max-width: 768px) {
    /* Hide scrollbar but keep functionality */
    .info-card::-webkit-scrollbar {
        height: 4px;
    }
    
    .info-card::-webkit-scrollbar-thumb {
        background: var(--border-secondary);
        border-radius: 2px;
    }
}

/* ============================================
   LANDSCAPE MOBILE FIXES
   ============================================ */

@media (max-width: 896px) and (orientation: landscape) {
    .header-content {
        padding: 0.5rem 1rem;
    }
    
    .logo {
        font-size: 14px;
    }
    
    .nav-links {
        top: 50px;
        height: calc(100vh - 50px);
    }
    
    .chart-container {
        height: 250px !important;
    }
}

/* ============================================
   VERY SMALL SCREENS (iPhone SE, etc)
   ============================================ */

@media (max-width: 375px) {
    body {
        font-size: 13px !important;
    }
    
    .company-name {
        font-size: 1.25rem !important;
    }
    
    .current-price {
        font-size: 1.75rem !important;
    }
    
    .stats-grid {
        grid-template-columns: 1fr !important;
    }
    
    .chart-period-btn {
        padding: 0.4rem 0.6rem;
        font-size: 10px;
    }
}

/* ============================================
   PREVENT ZOOM ON INPUT FOCUS (iOS)
   ============================================ */

@media (max-width: 768px) {
    input[type="text"],
    input[type="search"],
    select,
    textarea {
        font-size: 16px !important; /* iOS won't zoom if >= 16px */
    }
}

/* ============================================
   SAFE AREA INSETS (iPhone notch)
   ============================================ */

@supports (padding: env(safe-area-inset-left)) {
    .header-content {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
    
    .dashboard {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
}

/* ============================================
   ACCESSIBILITY IMPROVEMENTS
   ============================================ */

@media (max-width: 768px) {
    /* Larger tap targets for accessibility */
    .btn,
    button,
    a {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Better focus indicators */
    *:focus-visible {
        outline: 2px solid var(--accent-primary);
        outline-offset: 2px;
    }
}

/* ============================================
   LOADING STATES (Mobile optimized)
   ============================================ */

@media (max-width: 768px) {
    .loading-state {
        padding: 3rem 1rem;
    }
    
    .loading-spinner {
        width: 40px;
        height: 40px;
    }
}

/* ============================================
   MODAL/OVERLAY IMPROVEMENTS
   ============================================ */

@media (max-width: 768px) {
    .modal,
    .overlay {
        padding: 1rem;
    }
    
    .modal-content {
        width: 95%;
        max-width: 500px;
        margin: 2rem auto;
    }
}

/* ============================================
   FOOTER (if exists)
   ============================================ */

@media (max-width: 768px) {
    .footer {
        padding: 2rem 1rem;
        text-align: center;
    }
    
    .footer-links {
        flex-direction: column;
        gap: 1rem;
    }
}