/* ===== IPHONE SAFE AREA & MOBILE COMPATIBILITY ===== */

/* CRITICAL: Lock viewport and prevent any zoom/shift on mobile - MUST be first */
@media (max-width: 768px) {
    html {
        -webkit-text-size-adjust: 100% !important;
        text-size-adjust: 100% !important;
        touch-action: manipulation !important;
        -ms-touch-action: manipulation !important;
    }
    
    body {
        touch-action: manipulation !important;
        -ms-touch-action: manipulation !important;
        width: 100% !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
    }
    
    /* Override Bootstrap card styles completely - use 100% not 100vw to prevent overflow */
    .card,
    .card.mb-4,
    div.card {
        margin-left: 0 !important;
        margin-right: 0 !important;
        margin-bottom: 15px !important;
        padding: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
        min-width: 100% !important;
        box-sizing: border-box !important;
        transform: none !important;
        scale: 1 !important;
        zoom: 1 !important;
    }
    
    .card-body,
    div.card-body {
        margin: 0 !important;
        padding: 15px !important;
        max-width: 100% !important;
        width: 100% !important;
        min-width: 100% !important;
        box-sizing: border-box !important;
        transform: none !important;
        scale: 1 !important;
        zoom: 1 !important;
    }
    
    .card-header,
    div.card-header {
        margin: 0 !important;
        padding: 15px 20px !important;
        max-width: 100% !important;
        width: 100% !important;
        min-width: 100% !important;
        box-sizing: border-box !important;
        transform: none !important;
        scale: 1 !important;
        zoom: 1 !important;
    }
    
    /* Ensure main container doesn't cause issues */
    .main-container {
        margin-left: 0 !important;
        margin-right: 0 !important;
        padding-left: 8px !important;
        padding-right: 8px !important;
        max-width: 100vw !important;
        width: 100% !important;
        min-width: 100% !important;
        box-sizing: border-box !important;
        transform: none !important;
        scale: 1 !important;
        zoom: 1 !important;
    }
}

/* Global safe area handling for iPhone notch, home indicator, and Android navigation */
html {
    /* Support for dynamic viewport height on mobile browsers */
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height */
    /* Prevent horizontal scrolling */
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
    /* Prevent all zoom gestures - critical for mobile */
    touch-action: manipulation;
    -ms-touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

body {
    /* Safe area insets for iPhone notch and Android navigation */
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);

    /* Ensure minimum safe spacing even without safe-area support */
    padding-top: max(env(safe-area-inset-top, 0px), 0px);
    padding-bottom: max(env(safe-area-inset-bottom, 0px), 0px);
    padding-left: max(env(safe-area-inset-left, 0px), 0px);
    padding-right: max(env(safe-area-inset-right, 0px), 0px);

    /* Prevent content from extending into safe areas */
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;

    /* Ensure proper scrolling behavior */
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    
    /* Prevent zoom on touch - critical fix */
    touch-action: manipulation;
    -ms-touch-action: manipulation;
    -webkit-touch-callout: none;
    position: relative;
}

/* White background for safe areas to prevent content bleeding */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #f8f9fa; /* Match your app's background color */
    z-index: -10;
    pointer-events: none;
}

/* Safe area utilities for specific components */
.safe-area-top {
    padding-top: env(safe-area-inset-top, 0px);
}

.safe-area-bottom {
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.safe-area-left {
    padding-left: env(safe-area-inset-left, 0px);
}

.safe-area-right {
    padding-right: env(safe-area-inset-right, 0px);
}

.safe-area-all {
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
}

/* Fixed positioning with safe areas */
.fixed-safe-top {
    position: fixed;
    top: env(safe-area-inset-top, 0px);
    left: 0;
    right: 0;
    z-index: 1000;
}

.fixed-safe-bottom {
    position: fixed;
    bottom: env(safe-area-inset-bottom, 0px);
    left: 0;
    right: 0;
    z-index: 1000;
}

/* Viewport height utilities for mobile */
.vh-100-safe {
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for mobile browsers */
}

/* ===== MODERN DESIGN TOKENS & VARIABLES ===== */

:root {
    /* Color Palette - Modern Dashboard Colors */
    --primary-color: #667eea;
    --primary-color-dark: #5a67d8;
    --primary-color-light: #818cf8;
    --secondary-color: #764ba2;
    --secondary-color-dark: #6b46c1;
    
    /* Text Colors */
    --text-primary: #2c3e50;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --text-light: #a0aec0;
    --text-white: #ffffff;
    
    /* Background Colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    
    /* Status Colors */
    --success-color: #28a745;
    --warning-color: #ffc107;
    --danger-color: #dc3545;
    --info-color: #17a2b8;
    
    /* Spacing Scale */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;
    
    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-2xl: 24px;
    --radius-full: 9999px;
    
    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.05), 0 2px 4px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.05), 0 4px 6px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.1), 0 10px 10px rgba(0, 0, 0, 0.04);
    
    /* Transitions */
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Viewport Height Fix (Mobile Safari) */
    --vh: 1vh;
    
    /* Z-Index Scale */
    --z-base: 1;
    --z-dropdown: 1000;
    --z-sticky: 1020;
    --z-fixed: 1030;
    --z-modal-backdrop: 1040;
    --z-modal: 1050;
    --z-popover: 1060;
    --z-tooltip: 1070;
    --z-skip-link: 10000;
}

/* ===== FADE-IN ANIMATION (Intersection Observer) ===== */
/* DISABLED to prevent scroll flickering - elements are now visible by default */

/* Ensure all cards and stock cards are visible by default - no opacity animations */
/* Prevents flicker during scroll by ensuring elements are always visible */
.card,
.stock-card,
.fade-in {
    opacity: 1 !important;
}

/* Animation keyframes kept for reference but not used */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== FORM VALIDATION STYLES ===== */

.form-control.is-valid,
.form-select.is-valid,
.input-group .form-control.is-valid {
    border-color: var(--success-color);
    padding-right: calc(1.5em + 0.75rem);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%2328a745' d='M2.3 6.73L.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.form-control.is-valid:focus,
.form-select.is-valid:focus {
    border-color: var(--success-color);
    box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25);
}

.form-control.is-invalid,
.form-select.is-invalid,
.input-group .form-control.is-invalid {
    border-color: var(--danger-color);
    padding-right: calc(1.5em + 0.75rem);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23dc3545'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.form-control.is-invalid:focus,
.form-select.is-invalid:focus {
    border-color: var(--danger-color);
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}

.invalid-feedback {
    display: block;
    width: 100%;
    margin-top: 0.25rem;
    font-size: 0.875rem;
    color: var(--danger-color);
    font-weight: 500;
}

.valid-feedback {
    display: block;
    width: 100%;
    margin-top: 0.25rem;
    font-size: 0.875rem;
    color: var(--success-color);
    font-weight: 500;
}

/* ===== LOADING STATE STYLES ===== */

.loading-state {
    pointer-events: none;
    opacity: 0.6;
    position: relative;
}

.loading-state::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

/* ===== SCROLL HINT STYLES ===== */

.scroll-hint {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 8px;
    background: rgba(102, 126, 234, 0.05);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: opacity var(--transition-base);
}

.scroll-hint i {
    font-size: 0.875rem;
    color: var(--primary-color);
}

/* ===== ACCESSIBILITY ENHANCEMENTS ===== */

/* Skip to main content link */
.visually-hidden-focusable {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.visually-hidden-focusable:focus {
    position: absolute;
    width: auto;
    height: auto;
    padding: 8px 16px;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
    background: var(--primary-color);
    color: var(--text-white);
    text-decoration: none;
    border-radius: var(--radius-md);
    z-index: var(--z-skip-link);
}

/* Enhanced focus states */
*:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

.btn:focus-visible,
button:focus-visible {
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.25);
}

/* ===== MAIN CONTENT AREA ===== */

#main-content {
    scroll-margin-top: 80px; /* Account for fixed header */
}

/* Global CTA and navigation button styles */
.cta-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    box-shadow: 0 2px 10px rgba(102, 126, 234, 0.15);
    transition: background 0.3s, box-shadow 0.3s, transform 0.2s;
}
.cta-btn:hover, .cta-btn:focus {
    background: #5a67d8;
    color: #fff;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.25);
    transform: translateY(-2px) scale(1.04);
}
.btn-warning.cta-btn {
    background: linear-gradient(135deg, #ffc107 0%, #ffb300 100%);
    color: #222;
    font-weight: 500;
}
.btn-warning.cta-btn:hover, .btn-warning.cta-btn:focus {
    background: #ffb300;
    color: #111;
    box-shadow: 0 4px 20px rgba(255, 193, 7, 0.25);
    transform: translateY(-2px) scale(1.04);
}

/* ===== MOBILE-FIRST RESPONSIVE UTILITIES ===== */

/* Horizontal Scroll Table Container */
.table-responsive-mobile {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
    margin-bottom: 1rem;
}

/* Scroll shadows for better UX */
.table-responsive-mobile::before,
.table-responsive-mobile::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 20px;
    pointer-events: none;
    z-index: 2;
    transition: opacity 0.3s;
}

.table-responsive-mobile::before {
    left: 0;
    background: linear-gradient(to right, rgba(255,255,255,0.95), transparent);
}

.table-responsive-mobile::after {
    right: 0;
    background: linear-gradient(to left, rgba(255,255,255,0.95), transparent);
}

/* Table styles optimized for mobile */
.table-mobile-optimized {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    min-width: 100%;
}

.table-mobile-optimized thead {
    position: sticky;
    top: 0;
    z-index: 10;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.table-mobile-optimized th,
.table-mobile-optimized td {
    padding: 12px;
    text-align: left;
    white-space: nowrap;
    border-bottom: 1px solid #e9ecef;
    min-width: 100px;
}

.table-mobile-optimized th:first-child,
.table-mobile-optimized td:first-child {
    position: sticky;
    left: 0;
    z-index: 5;
    background: white;
    font-weight: 600;
    min-width: 80px;
    box-shadow: 2px 0 5px rgba(0,0,0,0.05);
}

.table-mobile-optimized thead th:first-child {
    z-index: 15;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.table-mobile-optimized tbody tr:hover {
    background-color: #f8f9fa;
}

.table-mobile-optimized tbody tr:hover td:first-child {
    background-color: #f8f9fa;
}

/* Mobile-optimized buttons */
.btn-mobile-friendly {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* Touch-friendly form inputs */
.form-control-mobile,
.form-select-mobile {
    min-height: 48px;
    font-size: 16px; /* Prevents iOS zoom */
    border-radius: 8px;
    padding: 12px 16px;
}

/* Responsive card layout */
.card-mobile-stack {
    margin-bottom: 1rem;
}

@media (max-width: 768px) {
    .card-mobile-stack {
        margin-bottom: 0.75rem;
    }
    
    .table-mobile-optimized th,
    .table-mobile-optimized td {
        padding: 10px 8px;
        font-size: 0.9rem;
        min-width: 80px;
    }
    
    .table-mobile-optimized th:first-child,
    .table-mobile-optimized td:first-child {
        min-width: 70px;
        padding: 10px;
    }
}

/* Mobile spacing utilities */
@media (max-width: 768px) {
    .mobile-px-2 {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }
    
    .mobile-py-2 {
        padding-top: 0.5rem !important;
        padding-bottom: 0.5rem !important;
    }
    
    .mobile-p-2 {
        padding: 0.5rem !important;
    }
    
    .mobile-mb-2 {
        margin-bottom: 0.5rem !important;
    }
    
    .mobile-mt-2 {
        margin-top: 0.5rem !important;
    }
}

/* Full width on mobile */
@media (max-width: 768px) {
    .mobile-full-width {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    .mobile-stack > * {
        display: block !important;
        width: 100% !important;
        margin-bottom: 0.5rem;
    }
}

/* Hide on mobile */
@media (max-width: 768px) {
    .mobile-hide {
        display: none !important;
    }
}

/* ===== ENHANCED MOBILE CARD SYSTEM ===== */

/* Mobile Card Container */
.mobile-card-container {
    display: none;
}

@media (max-width: 768px) {
    .mobile-card-container {
        display: block;
    }
    
    .mobile-card {
        background: white;
        border-radius: 12px;
        margin-bottom: 12px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
        border: 1px solid #e9ecef;
        overflow: hidden;
        transition: all 0.3s ease;
    }
    
    .mobile-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
    }
    
    .mobile-card-header {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        padding: 16px 20px;
        font-weight: 600;
        font-size: 1rem;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    
    .mobile-card-header i {
        font-size: 1.2rem;
        margin-right: 8px;
    }
    
    .mobile-card-body {
        padding: 20px;
    }
    
    .mobile-metric-row {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 12px 0;
        border-bottom: 1px solid #f8f9fa;
    }
    
    .mobile-metric-row:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }
    
    .mobile-metric-label {
        font-weight: 600;
        color: #6c757d;
        font-size: 0.9rem;
        flex: 1;
    }
    
    .mobile-metric-value {
        font-weight: 700;
        color: #2c3e50;
        font-size: 1rem;
        text-align: right;
        flex: 1;
    }
    
    .mobile-metric-value.positive {
        color: #28a745;
    }
    
    .mobile-metric-value.negative {
        color: #dc3545;
    }
    
    .mobile-metric-value.neutral {
        color: #6c757d;
    }
}

/* ===== MOBILE-FIRST FORM OPTIMIZATION ===== */

@media (max-width: 768px) {
    /* Date inputs specifically - critical for calendar picker and prevents iOS zoom */
    input[type="date"],
    input[type="date"].form-control,
    input[type="datetime-local"],
    input[type="time"] {
        font-size: 16px !important;
        min-height: 48px;
        padding: 12px 16px;
        -webkit-appearance: none;
        appearance: none;
    }
    
    /* All form controls - prevents iOS zoom on focus */
    .form-control-mobile,
    .form-select-mobile,
    .form-control,
    .form-select,
    input[type="text"],
    input[type="email"],
    input[type="number"],
    input[type="tel"],
    input[type="password"],
    textarea,
    select {
        min-height: 48px;
        font-size: 16px !important; /* Prevents iOS zoom */
        border-radius: 10px;
        padding: 14px 16px;
        border: 2px solid #e9ecef;
        transition: all 0.3s ease;
    }
    
    .form-control:focus,
    .form-select:focus,
    .form-control-mobile:focus,
    .form-select-mobile:focus,
    input[type="date"]:focus,
    input[type="datetime-local"]:focus {
        border-color: #667eea;
        box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
        outline: none;
    }
    
    .btn-mobile-optimized,
    .btn {
        min-height: 48px;
        min-width: 48px;
        padding: 12px 20px;
        border-radius: 10px;
        font-weight: 600;
        font-size: 1rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        transition: all 0.3s ease;
    }
    
    .btn-mobile-optimized:active,
    .btn:active {
        transform: scale(0.98);
    }
    
    /* Prevent container width issues on mobile - fixes "pinch in" effect */
    .main-container,
    .container,
    .container-fluid {
        max-width: 100vw !important;
        width: 100% !important;
        padding-left: 12px !important;
        padding-right: 12px !important;
    }
    
    /* CRITICAL: Prevent ALL zoom gestures on mobile - this is the main fix */
    * {
        touch-action: manipulation !important;
        -ms-touch-action: manipulation !important;
    }
    
    /* Allow text selection in text content */
    p,
    span,
    label:not([for]),
    div:not([role]),
    h1, h2, h3, h4, h5, h6 {
        -webkit-user-select: auto;
        user-select: auto;
    }
    
    /* Inputs need manipulation for proper interaction */
    input,
    textarea,
    select,
    [contenteditable],
    button,
    a {
        touch-action: manipulation !important;
        -webkit-user-select: auto;
        user-select: auto;
    }
    
    /* Ensure cards don't overflow on mobile - comprehensive override */
    .card,
    .card.mb-4,
    div.card,
    .card-body,
    div.card-body,
    .card-header,
    div.card-header,
    .filter-group,
    .filter-group-body,
    .filter-group-header,
    .stock-card {
        max-width: 100% !important;
        width: 100% !important;
        min-width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        box-sizing: border-box !important;
        transform: none !important;
        scale: 1 !important;
        zoom: 1 !important;
    }
    
    /* Allow horizontal scrolling for tables that need it */
    .table-responsive,
    .table-responsive-mobile,
    .table-wrapper {
        touch-action: pan-x pan-y !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Prevent any element from causing horizontal scroll */
    body,
    html {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100vw !important;
    }
}

/* ===== RANKING BADGE FIXES ===== */
/* Fix for circular ranking badges to prevent distortion when text wraps */

.stock-card-symbol-section {
    display: flex;
    align-items: flex-start !important;
    gap: 12px;
}

.stock-card-rank,
.rank-badge {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0 !important;
    line-height: 1 !important;
    min-width: 36px !important;
    min-height: 36px !important;
    margin-top: 2px;
}

/* Ensure rank badges maintain circular shape */
.stock-card-rank {
    width: 36px;
    height: 36px;
}

.rank-badge {
    width: 35px;
    height: 35px;
    min-width: 35px;
    min-height: 35px;
}

/* ===== COMPANY NAME TRUNCATION ===== */
/* Standard practice: Limit company names to 2 lines with ellipsis for consistent card heights */

.stock-card {
    min-height: 80px !important; /* Ensure consistent card height */
}

.stock-card-header {
    min-height: 60px !important; /* Fixed height for header to ensure consistency */
    align-items: flex-start !important;
}

/* Company name truncation - 2 lines max with ellipsis */
.stock-card-symbol-section small,
.stock-card-symbol-section .company-name {
    display: -webkit-box !important;
    -webkit-line-clamp: 2 !important;
    -webkit-box-orient: vertical !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    line-height: 1.4 !important;
    max-height: 2.8em !important; /* 2 lines * 1.4 line-height */
    word-break: break-word !important;
    hyphens: auto !important;
}

.stock-card-info,
.stock-card-momentum {
    align-self: flex-start !important; /* Align to top when company name wraps */
    margin-top: 0 !important;
}

/* ===== STANDARDIZED HEADERS, SPACING, AND BUTTONS ===== */
/* Consistent sizing across all pages */

/* Card Headers - Standardized padding and sizing with gradient background */
/* Maximum specificity to override Bootstrap and any other CSS */
.card-header,
div.card-header,
.card .card-header,
.card > .card-header,
.card.mb-4 .card-header,
.card.mb-4 > .card-header,
div.card > div.card-header,
.card-header:not([style*="background"]):not([style*="background-image"]) {
    padding: 12px 15px !important; /* Consistent with momentum_screener mobile size */
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    background-image: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    background-color: transparent !important;
    color: white !important;
    border-radius: 10px 10px 0 0 !important;
    font-weight: 600 !important; /* Slightly lighter than bold for better readability */
    font-size: 1rem !important; /* Standard size */
    margin-bottom: 0 !important;
    min-height: auto !important; /* Let content determine height */
    line-height: 1.4 !important; /* Consistent line height */
}

/* Card Header Text (h5, h4, etc.) */
.card-header h5,
.card-header h4,
.card-header h3 {
    font-size: 1rem !important;
    font-weight: 600 !important;
    margin-bottom: 0 !important;
    line-height: 1.4 !important;
}

/* Buttons inside card headers should not add extra height */
.card-header .btn-link,
.card-header button {
    padding: 0 !important;
    margin: 0 !important;
    line-height: 1.4 !important;
    font-size: 1rem !important;
    font-weight: 600 !important;
    height: auto !important;
    min-height: auto !important;
}

/* Ensure flexbox buttons don't add extra height */
.card-header .btn-link.d-flex {
    align-items: center !important;
    min-height: auto !important;
    height: auto !important;
}

/* Card Body - Standardized padding */
.card-body {
    padding: 15px !important;
}

/* Card spacing between cards */
.card {
    margin-bottom: 20px !important; /* Consistent spacing */
}

/* Standardized Button Sizes */
.btn-primary {
    padding: 12px 30px !important;
    font-size: 1rem !important;
    font-weight: 600 !important;
    border-radius: 8px !important;
    min-height: 44px !important; /* Touch-friendly on mobile */
}

.btn-secondary,
.btn-outline-primary,
.btn-outline-secondary {
    padding: 12px 24px !important;
    font-size: 1rem !important;
    font-weight: 600 !important;
    border-radius: 8px !important;
    min-height: 44px !important;
}

.btn-sm {
    padding: 8px 16px !important;
    font-size: 0.875rem !important;
    font-weight: 600 !important;
    border-radius: 6px !important;
    min-height: 36px !important;
}

.btn-lg {
    padding: 14px 36px !important;
    font-size: 1.1rem !important;
    font-weight: 600 !important;
    border-radius: 10px !important;
    min-height: 52px !important;
}

/* ===== FULL-WIDTH FORM SUBMIT BUTTONS ===== */
/* Standard: All primary form submit buttons should be full width for consistency */

/* Form submit buttons - full width by default */
form button[type="submit"].btn-primary,
form button[type="submit"].btn-lg,
form .btn-primary[type="submit"],
form .btn-lg[type="submit"] {
    width: 100% !important;
}

/* Exception: Button groups and inline buttons should not be full width */
.btn-group button,
.d-flex button:not([type="submit"]),
.inline-buttons button {
    width: auto !important;
}

/* Submit button containers - standardized spacing */
form > div.mt-4:last-child,
form > div.mb-4:last-child {
    margin-top: 1.5rem !important;
    margin-bottom: 0 !important;
}

/* Section spacing */
.section-spacing {
    margin-bottom: 30px !important;
}

/* Form spacing */
.form-group,
.mb-3 {
    margin-bottom: 1rem !important; /* 16px */
}

.mb-4 {
    margin-bottom: 1.5rem !important; /* 24px */
}

.mb-5 {
    margin-bottom: 2rem !important; /* 32px */
}

/* ===== MOBILE RESPONSIVE ADJUSTMENTS ===== */

@media (max-width: 768px) {
    /* Maintain header consistency on mobile */
    .card-header {
        padding: 12px 15px !important; /* Same as desktop for consistency */
        font-size: 1rem !important;
    }
    
    /* Button sizes remain consistent on mobile */
    .btn-primary,
    .btn-secondary,
    .btn-outline-primary {
        min-height: 44px !important; /* Touch-friendly */
        padding: 12px 24px !important; /* Slightly reduced horizontal padding */
    }
    
    .btn-sm {
        min-height: 36px !important;
        padding: 8px 16px !important;
    }
    
    /* Card spacing slightly reduced on mobile */
    .card {
        margin-bottom: 15px !important;
    }
}

/* ===== MOBILE CHART CONTAINERS ===== */

@media (max-width: 768px) {
    .chart-container-mobile {
        position: relative;
        width: 100%;
        height: 300px;
        margin-bottom: 20px;
    }
    
    .chart-expand-btn-mobile {
        position: absolute;
        top: 10px;
        right: 10px;
        background: rgba(255, 255, 255, 0.95);
        border: none;
        border-radius: 50%;
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #667eea;
        font-size: 1.2rem;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        z-index: 10;
        transition: all 0.3s ease;
    }
    
    .chart-expand-btn-mobile:hover {
        background: white;
        transform: scale(1.1);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
    
    .chart-expand-btn-mobile:active {
        transform: scale(0.95);
    }
}

/* ===== MOBILE ACCORDION SYSTEM ===== */

@media (max-width: 768px) {
    .mobile-accordion {
        margin-bottom: 16px;
    }
    
    .mobile-accordion-header {
        background: #f8f9fa;
        border: 2px solid #e9ecef;
        padding: 16px 20px;
        cursor: pointer;
        border-radius: 10px;
        margin-bottom: 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
        transition: all 0.3s ease;
        font-weight: 600;
        color: #2c3e50;
    }
    
    .mobile-accordion-header:hover {
        background: #e9ecef;
        border-color: #667eea;
    }
    
    .mobile-accordion-header.active {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        border-color: #667eea;
    }
    
    .mobile-accordion-content {
        display: none;
        padding: 20px;
        background: white;
        border: 2px solid #e9ecef;
        border-top: none;
        border-radius: 0 0 10px 10px;
        margin-top: -2px;
    }
    
    .mobile-accordion-content.show {
        display: block;
        animation: slideDown 0.3s ease;
    }
    
    .mobile-accordion-arrow {
        transition: transform 0.3s ease;
        font-size: 1.1rem;
    }
    
    .mobile-accordion-header.active .mobile-accordion-arrow {
        transform: rotate(180deg);
    }
}

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

/* ===== MOBILE TABLE REPLACEMENT ===== */

/* Show desktop table by default */
.table-mobile-replacement {
    display: block;
}

.mobile-table-cards {
    display: none;
}

@media (max-width: 768px) {
    .table-mobile-replacement {
        display: none;
    }
    
    .mobile-table-cards {
        display: block;
    }
    
    .mobile-table-card {
        background: white;
        border-radius: 12px;
        margin-bottom: 12px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
        border: 1px solid #e9ecef;
        overflow: hidden;
    }
    
    .mobile-table-card-header {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        padding: 16px 20px;
        font-weight: 600;
        font-size: 1.1rem;
    }
    
    .mobile-table-card-body {
        padding: 20px;
    }
    
    .mobile-table-row {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 12px 0;
        border-bottom: 1px solid #f8f9fa;
    }
    
    .mobile-table-row:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }
    
    .mobile-table-label {
        font-weight: 600;
        color: #6c757d;
        font-size: 0.9rem;
        flex: 1;
    }
    
    .mobile-table-value {
        font-weight: 700;
        color: #2c3e50;
        font-size: 1rem;
        text-align: right;
        flex: 1;
    }
}

/* ===== MOBILE SIDEBAR LAYOUT OPTIMIZATION ===== */

@media (max-width: 768px) {
    .mobile-sidebar-layout {
        display: flex;
        flex-direction: column;
        gap: 16px;
    }
    
    .mobile-sidebar-section {
        background: white;
        border-radius: 12px;
        padding: 20px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
        border: 1px solid #e9ecef;
    }
    
    .mobile-sidebar-section-header {
        font-weight: 700;
        color: #2c3e50;
        margin-bottom: 16px;
        font-size: 1.1rem;
        display: flex;
        align-items: center;
        gap: 8px;
    }
    
    .mobile-sidebar-section-header i {
        color: #667eea;
        font-size: 1.2rem;
    }
}

/* ===== MOBILE FULL-SCREEN UTILIZATION ===== */

@media (max-width: 768px) {
    .mobile-full-screen {
        width: 100vw;
        margin-left: calc(-50vw + 50%);
        margin-right: calc(-50vw + 50%);
        padding-left: 16px;
        padding-right: 16px;
    }
    
    .mobile-no-margins {
        margin-left: 0 !important;
        margin-right: 0 !important;
        padding-left: 12px !important;
        padding-right: 12px !important;
    }
    
    .mobile-tight-spacing {
        padding: 8px !important;
        margin-bottom: 8px !important;
    }
    
    .mobile-loose-spacing {
        padding: 24px !important;
        margin-bottom: 24px !important;
    }
}

/* ===== MOBILE TOUCH TARGETS ===== */

@media (max-width: 768px) {
    .mobile-touch-target {
        min-height: 48px;
        min-width: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 12px;
    }
    
    .mobile-touch-target-large {
        min-height: 56px;
        min-width: 56px;
        padding: 16px;
    }
    
    .mobile-touch-target-small {
        min-height: 40px;
        min-width: 40px;
        padding: 8px;
    }
}

/* ===== MOBILE LOADING STATES ===== */

@media (max-width: 768px) {
    .mobile-loading {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 40px 20px;
        text-align: center;
    }
    
    .mobile-loading-spinner {
        width: 40px;
        height: 40px;
        border: 4px solid #f3f3f3;
        border-top: 4px solid #667eea;
        border-radius: 50%;
        animation: spin 1s linear infinite;
        margin-bottom: 16px;
    }
    
    .mobile-loading-text {
        color: #6c757d;
        font-size: 0.9rem;
        font-weight: 500;
    }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Show only on mobile */
.mobile-only {
    display: none !important;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block !important;
    }
    
    .mobile-only-flex {
        display: flex !important;
    }
    
    .mobile-only-inline {
        display: inline !important;
    }
}

/* Mobile grid utilities */
@media (max-width: 768px) {
    .mobile-grid-1 {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    .mobile-grid-2 {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
}

/* Smooth transitions for specific interactive elements only */
/* Removed universal * selector to prevent scroll flickering */

/* Enhanced button interactions */
.btn, button, .nav-link, .action-link {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.btn:hover, button:hover, .nav-link:hover, .action-link:hover {
    transform: translateY(-1px);
}

.btn:active, button:active, .nav-link:active, .action-link:active {
    transform: translateY(0);
    transition: all 0.1s ease;
}

/* Haptic feedback for mobile */
@media (hover: none) and (pointer: coarse) {
    .btn:active, button:active, .nav-link:active, .action-link:active {
        animation: haptic-feedback 0.15s ease;
    }
}

@keyframes haptic-feedback {
    0% { transform: scale(1); }
    50% { transform: scale(0.98); }
    100% { transform: scale(1); }
}

/* Modern shadow system */
.shadow-subtle {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.1);
}

.shadow-medium {
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05), 0 2px 4px rgba(0, 0, 0, 0.06);
}

.shadow-large {
    box-shadow: 0 10px 15px rgba(0, 0, 0, 0.05), 0 4px 6px rgba(0, 0, 0, 0.05);
}

/* Tooltip styles */
.tooltip-trigger {
    position: relative;
    cursor: help;
}

.tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    white-space: nowrap;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(5px);
    transition: all 0.2s ease;
    pointer-events: none;
}

.tooltip-trigger:hover .tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.tooltip::before {
    content: '';
    position: absolute;
    top: -5px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 5px solid rgba(0, 0, 0, 0.9);
}

/* Accordion styles */
.accordion-item {
    border: none;
    margin-bottom: 1rem;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.accordion-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1rem 1.5rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s ease;
    font-weight: 700;
    letter-spacing: -0.01em;
    font-size: 1.1rem;
}

.accordion-header:hover {
    background: linear-gradient(135deg, #5a67d8 0%, #6b46c1 100%);
}

.accordion-content {
    padding: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.accordion-content.active {
    padding: 1.5rem;
    max-height: 1000px;
}

.accordion-icon {
    transition: transform 0.3s ease;
}

.accordion-icon.rotated {
    transform: rotate(180deg);
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== PRICING TABLE STYLES (from landing.html) ===== */

.pricing-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 30px;
    margin: 40px 0;
    align-items: stretch;
}

.pricing-card {
    background: rgba(255,255,255,0.95);
    padding: 40px 30px;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    text-align: center;
    position: relative;
    transition: transform 0.3s ease;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.pricing-card:hover {
    transform: translateY(-5px);
}

.pricing-card.popular {
    border: 3px solid #f39c12;
}

.popular-badge {
    background: #f39c12;
    color: black;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: bold;
    position: absolute;
    top: -15px;
    left: 50%;
    transform: translateX(-50%);
}

.pricing-card h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.5rem;
}

.pricing-card .price {
    font-size: 3rem;
    font-weight: bold;
    color: #e74c3c;
    margin-bottom: 5px;
}

.pricing-card .price-period {
    font-size: 1rem;
    color: #666;
    margin-bottom: 30px;
}

.features-list {
    list-style: none;
    padding: 0;
    margin: 30px 0;
    text-align: left;
    flex-grow: 1;
}

.features-list li {
    padding: 18px 0;
    color: #4a5568;
    font-size: 1rem;
    position: relative;
    padding-left: 40px;
    line-height: 1.6;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.features-list li:last-child {
    border-bottom: none;
}

.features-list li:before {
    content: "✅";
    position: absolute;
    left: 0;
    top: 15px;
    font-size: 1.2rem;
}

/* Ensure text doesn't get cut off */
.pricing-card .features-list {
    width: 100%;
    max-width: 100%;
}

.pricing-card .features-list li {
    white-space: normal;
    word-break: normal;
    overflow: visible;
    text-align: left;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.pricing-button {
    display: inline-block;
    padding: 15px 30px;
    border: none;
    border-radius: 50px;
    font-size: 1.1rem;
    font-weight: bold;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    text-align: center;
}

@media (max-width: 768px) {
    .pricing-grid {
        grid-template-columns: 1fr;
    }
    
    .pricing-card.popular {
        transform: none;
    }
}

/* ===== BACKTEST RESULTS - METRIC CARDS ===== */

.results-content {
    padding: 30px;
}

.chart-container { 
    position: relative; 
    height: 400px; 
    background: #fff; 
    border-radius: 8px; 
    padding: 15px; 
}

@media (max-width: 768px) { 
    .chart-container { 
        height: 300px; 
    } 
}

.metric-card { 
    min-height: 120px; 
    display: flex; 
    flex-direction: column; 
    justify-content: center; 
    background: #f8f9fa; 
    border: 1px solid #e9ecef; 
    border-radius: 8px; 
    padding: 20px; 
    text-align: center;
}

.metric-value { 
    font-size: 1.8rem; 
    font-weight: bold; 
    margin-bottom: 8px; 
    line-height: 1.2; 
}

.metric-label { 
    font-size: 0.85rem; 
    color: #495057; 
    font-weight: 500;
    line-height: 1.3; 
}

.metric-info-icon {
    color: #667eea;
    font-size: 0.85rem;
    margin-left: 5px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.metric-info-icon:hover {
    color: #764ba2;
    transform: scale(1.2);
}

.stats-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); 
    gap: 20px; 
    margin-bottom: 30px; 
}

/* Mobile optimization for metric cards - smaller and closer together */
@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        margin-bottom: 20px;
    }
    
    .metric-card {
        min-height: 85px;
        padding: 12px;
        border-radius: 6px;
    }
    
    .metric-value {
        font-size: 1.4rem;
        margin-bottom: 4px;
    }
    
    .metric-label {
        font-size: 0.75rem;
        line-height: 1.2;
    }
    
    .metric-info-icon {
        font-size: 0.75rem;
        margin-left: 3px;
    }
    
    .results-content {
        padding: 20px 15px;
    }
} 