/* ================================
   GLOBAL STYLES
   ================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #0a0e27 0%, #1a1f3a 100%);
    color: #ffffff;
    min-height: 100vh;
}

/* ================================
   LOGIN PAGE
   ================================ */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.login-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 40px;
    max-width: 1000px;
    width: 100%;
}

.login-card {
    background: linear-gradient(135deg, #1a1f3a 0%, #2c3658 100%);
    padding: 50px;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.login-header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.login-header p {
    color: #888;
    font-size: 1.1em;
    margin-bottom: 30px;
}

.login-error {
    background: #e74c3c;
    color: white;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-weight: 600;
}

.login-form {
    margin: 30px 0;
}

.form-group {
    margin-bottom: 25px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #aaa;
}

.form-group input {
    width: 100%;
    padding: 15px;
    font-size: 1.1em;
    background: #0a0e27;
    border: 2px solid #2c3658;
    border-radius: 8px;
    color: white;
    transition: all 0.3s;
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.3);
}

.login-button {
    width: 100%;
    padding: 18px;
    font-size: 1.2em;
    font-weight: 700;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.login-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.4);
}

.login-footer {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #2c3658;
    text-align: center;
    color: #888;
}

.login-features {
    background: #1a1f3a;
    padding: 40px;
    border-radius: 20px;
    border: 1px solid #2c3658;
}

.login-features h3 {
    font-size: 1.5em;
    margin-bottom: 20px;
    color: #667eea;
}

.login-features ul {
    list-style: none;
    padding: 0;
}

.login-features li {
    padding: 12px 0;
    font-size: 1.05em;
    color: #aaa;
    border-bottom: 1px solid #2c3658;
}

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

@media (max-width: 968px) {
    .login-container {
        grid-template-columns: 1fr;
    }
}

/* ================================
   SIDEBAR NAVIGATION
   ================================ */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    width: 280px;
    background: linear-gradient(135deg, #1a1f3a 0%, #2c3658 100%);
    border-right: 1px solid #2c3658;
    overflow-y: auto;
    transition: all 0.3s;
    z-index: 1000;
}

.sidebar.collapsed {
    width: 60px;
}

.sidebar-header {
    padding: 15px 20px;
    border-bottom: 1px solid #2c3658;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    font-size: 1.3em;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar.collapsed .sidebar-header h2 {
    display: none;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: white;
    font-size: 1.5em;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 5px;
    transition: background 0.2s;
}

.sidebar-toggle:hover {
    background: #667eea;
}

.sidebar-nav {
    padding: 10px 0;
}

.nav-section {
    margin: 2px 0;
}

.nav-link {
    display: block;
    padding: 10px 20px;
    color: #aaa;
    text-decoration: none;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.nav-link:hover {
    background: #667eea22;
    color: white;
    border-left-color: #667eea;
}

.nav-link.active {
    background: #667eea;
    color: white;
    border-left-color: #764ba2;
    font-weight: 600;
}

.nav-link.logout-link {
    color: #e74c3c;
}

.nav-link.logout-link:hover {
    background: #e74c3c22;
    border-left-color: #e74c3c;
}

.nav-header {
    padding: 8px 20px;
    color: #aaa;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s;
    user-select: none;
}

.nav-header:hover {
    background: #2c365822;
    color: white;
}

.nav-arrow {
    font-size: 0.8em;
    transition: transform 0.3s;
}

.nav-content {
    display: none;
    padding-left: 10px;
}

.nav-sublink {
    display: block;
    padding: 6px 20px;
    color: #888;
    text-decoration: none;
    font-size: 0.9em;
    transition: all 0.2s;
    border-left: 2px solid transparent;
}

.nav-sublink:hover {
    background: #2c365844;
    color: white;
    border-left-color: #3498db;
}

.sidebar-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 20px;
    border-top: 1px solid #2c3658;
    background: #1a1f3a;
}

.user-info {
    text-align: center;
}

.user-info strong {
    display: block;
    margin-bottom: 5px;
    color: #667eea;
}

.market-status {
    font-size: 0.85em;
    color: #888;
}

.sidebar.collapsed .sidebar-footer {
    padding: 10px 5px;
}

.sidebar.collapsed .user-info strong,
.sidebar.collapsed .market-status {
    display: none;
}

/* ================================
   MAIN CONTENT AREA
   ================================ */
.main-content {
    margin-left: 280px;
    min-height: 100vh;
    transition: margin-left 0.3s;
}

.main-content.expanded {
    margin-left: 60px;
}

.top-header {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    padding: 20px 30px;
    border-bottom: 1px solid #2c3658;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 1.5em;
    cursor: pointer;
    margin-right: 15px;
}

.page-title {
    font-size: 1.5em;
    font-weight: 700;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.market-timer {
    font-size: 1.1em;
    font-weight: 600;
    padding: 8px 15px;
    background: #0a0e27;
    border-radius: 8px;
}

.content-wrapper {
    padding: 30px;
}

/* ================================
   CONTAINERS & CARDS
   ================================ */
.container {
    max-width: 1800px;
    margin: 0 auto;
}

.card {
    background: linear-gradient(135deg, #1a1f3a 0%, #2c3658 100%);
    border-radius: 15px;
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    border: 1px solid #2c3658;
}

.collapsible-card {
    padding: 0;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 20px 30px;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    border-radius: 15px 15px 0 0;
    user-select: none;
    transition: background 0.3s;
}

.card-header:hover {
    background: linear-gradient(135deg, #2a5298 0%, #1e3c72 100%);
}

.card-header h2 {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.collapse-icon {
    font-size: 1.5em;
    font-weight: bold;
    color: #fff;
    transition: transform 0.3s;
}

.card-content {
    padding: 30px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.section-header h2 {
    margin: 0;
}

/* ================================
   BADGES & LABELS
   ================================ */
.api-badge {
    background: #3498db;
    color: #fff;
    padding: 4px 12px;
    border-radius: 5px;
    font-size: 0.75em;
    font-weight: 600;
    margin-left: 10px;
}

.info-badge {
    background: #f39c12;
    color: #fff;
    padding: 4px 12px;
    border-radius: 5px;
    font-size: 0.75em;
    font-weight: 600;
    margin-left: 10px;
}

.premium-badge {
    background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
    color: white;
    padding: 4px 10px;
    border-radius: 5px;
    font-weight: 700;
    font-size: 0.95em;
}

.signal-badge {
    background: #3498db;
    color: white;
    padding: 4px 10px;
    border-radius: 5px;
    font-size: 0.85em;
    font-weight: 600;
}

/* ================================
   MARKET WIDGETS
   ================================ */
.market-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
}

.market-widget {
    background: #0b1020;
    padding: 20px;
    border-radius: 10px;
    border-left: 4px solid #3498db;
    transition: transform 0.2s;
}

.market-widget-clickable {
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.market-widget-clickable:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 20px rgba(52, 152, 219, 0.3);
}

.widget-label {
    font-size: 0.9em;
    color: #888;
    margin-bottom: 8px;
}

.widget-value {
    font-size: 1.8em;
    font-weight: 700;
}

.mini-chart-preview {
    font-size: 0.75em;
    color: #3498db;
    margin-top: 8px;
    text-align: center;
}

.positive {
    color: #2ecc71;
}

.negative {
    color: #e74c3c;
}

/* ================================
   VIX WARNING SECTION
   ================================ */
.vix-probability {
    text-align: center;
    font-size: 3em;
    font-weight: 900;
    margin: 20px 0;
}

.vix-posture {
    padding: 20px;
    border-radius: 10px;
    margin: 15px 0;
}

.vix-signal {
    background: #0b1020;
    padding: 15px;
    border-radius: 8px;
    margin: 10px 0;
    border-left: 3px solid #3498db;
}

.signal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.signal-explanation {
    color: #aaa;
    font-size: 0.9em;
}

.vix-legend {
    background: #1a0f2e;
    padding: 20px;
    border-radius: 10px;
    margin-top: 20px;
    border: 1px solid #764ba2;
    line-height: 1.8;
}

/* ================================
   FORMS & FILTERS
   ================================ */
.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

.filter-group {
    display: flex;
    flex-direction: column;
}

.filter-group label {
    margin-bottom: 8px;
    font-weight: 600;
    color: #aaa;
}

.filter-group input,
.filter-group select,
.filter-group textarea {
    padding: 12px;
    background: #0a0e27;
    border: 2px solid #2c3658;
    border-radius: 8px;
    color: white;
    font-size: 1em;
    transition: all 0.3s;
}

.filter-group input:focus,
.filter-group select:focus,
.filter-group textarea:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 10px rgba(52, 152, 219, 0.3);
}

.filter-group textarea {
    resize: vertical;
    font-family: 'Courier New', monospace;
}

.filter-group small {
    margin-top: 5px;
    color: #888;
    font-size: 0.85em;
}

.capital-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.capital-section input {
    flex: 1;
}

.list-manager {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 15px;
    margin: 20px 0;
    align-items: end;
}

.ticker-preview {
    background: #0b1020;
    padding: 15px;
    border-radius: 8px;
    margin-top: 15px;
    color: #aaa;
    font-size: 0.9em;
    border-left: 3px solid #3498db;
}

/* ================================
   BUTTONS
   ================================ */
button,
.btn-primary,
.btn-secondary {
    padding: 12px 25px;
    font-size: 1em;
    font-weight: 700;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary,
.scan1 {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover,
.scan1:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.scan2 {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
}

.scan2:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(240, 147, 251, 0.4);
}

.scan3 {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
}

.scan3:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(79, 172, 254, 0.4);
}

.secondary,
.small.secondary {
    background: #2c3658;
    color: white;
}

.secondary:hover,
.small.secondary:hover {
    background: #3d4a70;
}

.small {
    padding: 8px 15px;
    font-size: 0.9em;
}

.danger {
    background: #e74c3c;
    color: white;
}

.danger:hover {
    background: #c0392b;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-group {
    display: flex;
    gap: 15px;
    align-items: center;
    margin-top: 20px;
}

.timer {
    color: #888;
    font-size: 0.9em;
}

/* ================================
   TOGGLE SWITCH
   ================================ */
.toggle {
    display: flex;
    align-items: center;
    gap: 15px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 30px;
}

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

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #2c3658;
    transition: 0.4s;
    border-radius: 30px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: 0.4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: #2ecc71;
}

input:checked + .slider:before {
    transform: translateX(30px);
}

/* ================================
   HEATMAP CONTAINER
   ================================ */
.heatmap-container {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

/* ================================
   TOP STOCKS SELECTION
   ================================ */
.top-stock-selectable {
    background: #0b1020;
    padding: 15px;
    margin: 8px 0;
    border-radius: 8px;
    border-left: 3px solid #3498db;
    transition: all 0.2s;
}

.top-stock-selectable:hover {
    background: #1a2540;
    border-left-color: #2ecc71;
}

.top-stock-checkbox {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

/* ================================
   TABLES
   ================================ */
.table-wrapper {
    overflow-x: auto;
    margin-top: 20px;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: #0b1020;
    border-radius: 10px;
    overflow: visible;
}

thead {
    position: sticky;
    top: 0;
    z-index: 10;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
}

th {
    padding: 15px 12px;
    text-align: left;
    font-weight: 700;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    font-size: 0.9em;
}

th:hover {
    background: #2a5298;
}

td {
    padding: 12px;
    border-bottom: 1px solid #2c3658;
    font-size: 0.9em;
}

tbody tr:hover {
    background: #1a2540;
}

tbody tr:last-child td {
    border-bottom: none;
}

/* ================================
   MODALS
   ================================ */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.8);
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: linear-gradient(135deg, #1a1f3a 0%, #2c3658 100%);
    margin: 5% auto;
    padding: 40px;
    border: 1px solid #2c3658;
    border-radius: 15px;
    width: 90%;
    max-width: 800px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: slideDown 0.3s;
}

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

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
}

.close:hover {
    color: #fff;
}

/* Chart Modal */
.chart-modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.9);
}

.chart-modal-content {
    background: #1a1f3a;
    margin: 3% auto;
    padding: 30px;
    border: 1px solid #2c3658;
    border-radius: 15px;
    width: 90%;
    max-width: 1200px;
}

.chart-modal-content img {
    width: 100%;
    border-radius: 10px;
}

.chart-close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.chart-close:hover {
    color: #fff;
}

/* ================================
   TRS LEGEND & EXPLANATION
   ================================ */
.trs-legend {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    margin: 15px 0;
}

.trs-item {
    padding: 10px 18px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.95em;
}

.trs-trust {
    background: #2ecc71;
    color: #fff;
}

.trs-mixed {
    background: #f39c12;
    color: #fff;
}

.trs-caution {
    background: #e74c3c;
    color: #fff;
}

.trs-explanation {
    background: #0b1020;
    padding: 25px;
    border-radius: 10px;
    line-height: 1.9;
    color: #aaa;
}

.trs-explanation strong {
    color: #fff;
}

/* ================================
   SUGGESTIONS
   ================================ */
.suggestion-item {
    background: #0b1020;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 15px;
    border-left: 4px solid #3498db;
}

/* ================================
   API SECTION
   ================================ */
.api-section {
    background: #0b1020;
    padding: 20px;
    border-radius: 10px;
    margin: 15px 0;
    border-left: 3px solid #3498db;
}

.api-section h3 {
    color: #3498db;
    margin-bottom: 15px;
}

.api-section p {
    color: #aaa;
    line-height: 1.8;
    margin: 8px 0;
}

/* ================================
   SPINNER ANIMATION
   ================================ */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
}

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

/* ================================
   RESPONSIVE DESIGN
   ================================ */
@media (max-width: 1200px) {
    .heatmap-container {
        grid-template-columns: 1fr;
    }
    
    .market-row {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 968px) {
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .mobile-menu-toggle {
        display: block;
    }
    
    .filter-grid {
        grid-template-columns: 1fr;
    }
    
    .market-row {
        grid-template-columns: 1fr;
    }
    
    .list-manager {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .content-wrapper {
        padding: 15px;
    }
    
    .card {
        padding: 20px;
    }
    
    .card-header,
    .card-content {
        padding: 20px;
    }
    
    table {
        font-size: 0.8em;
    }
    
    th, td {
        padding: 8px 6px;
    }
}

/* ================================
   UTILITY CLASSES
   ================================ */
.text-center {
    text-align: center;
}

.mt-20 {
    margin-top: 20px;
}

.mb-20 {
    margin-bottom: 20px;
}

.hidden {
    display: none;
}

/* Hide mobile menu button on desktop */
.mobile-menu-btn {
    display: none;
}

/* MOBILE RESPONSIVE */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -260px;
        top: 0;
        height: 100vh;
        width: 250px;
        z-index: 9999;
        transition: left 0.3s ease;
    }
    .sidebar.active {
        left: 0;
    }
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }
    .mobile-menu-btn {
        display: block !important;
        position: fixed;
        top: 10px;
        left: 10px;
        z-index: 9998;
        background: #667eea;
        border: none;
        color: white;
        font-size: 24px;
        padding: 8px 12px;
        border-radius: 8px;
        cursor: pointer;
    }
    .mobile-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,0.5);
        z-index: 9998;
    }
    .mobile-overlay.show {
        display: block;
    }
    .top-right-controls {
        right: 10px;
    }
    .market-timer-top {
        display: none;
    }
}

/* Fix page title overlap with hamburger on mobile */
@media (max-width: 768px) {
    .top-header .page-title {
        margin-left: 50px !important;
        font-size: 1.1em !important;
    }
    .top-header > div:first-child {
        padding-left: 10px;
    }
}

/* Portfolio Calculator mobile fixes */
@media (max-width: 768px) {
    /* Button row in card-footer */
    .card-footer > div {
        flex-wrap: wrap !important;
    }
    .card-footer .btn {
        flex: 1 1 45% !important;
        margin-bottom: 8px !important;
        padding: 10px 15px !important;
        font-size: 12px !important;
    }
    
    /* Add Individual Stock form */
    div[style*="display:flex;gap:15px;align-items:flex-end;flex-wrap:wrap"] {
        flex-direction: column !important;
        align-items: stretch !important;
    }
    div[style*="display:flex;gap:15px;align-items:flex-end;flex-wrap:wrap"] > div,
    div[style*="display:flex;gap:15px;align-items:flex-end;flex-wrap:wrap"] > button {
        flex: none !important;
        width: 100% !important;
    }
    
    /* Results header actions */
    .card-header div[style*="display:flex;align-items:center;gap:15px"] {
        flex-wrap: wrap !important;
        gap: 10px !important;
    }
    
    /* View buttons */
    .view-btn {
        padding: 5px 10px !important;
        font-size: 11px !important;
    }
    
    /* Action buttons */
    .action-btn {
        padding: 5px 10px !important;
        font-size: 11px !important;
    }
}

/* ================================
   MOBILE RESPONSIVE FIXES - Dec 2024
   ================================ */

/* Prevent horizontal scrolling */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* Mobile-first improvements */
@media (max-width: 768px) {
    /* Prevent any horizontal overflow */
    .main-content {
        overflow-x: hidden;
        padding: 10px !important;
    }
    
    .container {
        padding: 10px !important;
        max-width: 100% !important;
        overflow-x: hidden;
    }
    
    /* Cards - full width, less padding */
    .card {
        padding: 12px !important;
        margin-bottom: 15px !important;
        border-radius: 8px !important;
    }
    
    /* Tables - horizontal scroll contained */
    .table-wrapper, 
    .results-wrapper,
    div[style*="overflow-x"] {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Buttons - touch-friendly */
    button, .btn, .btn-primary, .btn-secondary {
        min-height: 44px;
        padding: 12px 16px !important;
        font-size: 14px !important;
    }
    
    button.small, .btn.small {
        min-height: 36px;
        padding: 8px 12px !important;
        font-size: 12px !important;
    }
    
    /* Form inputs - touch-friendly */
    input, select, textarea {
        min-height: 44px;
        font-size: 16px !important; /* Prevents iOS zoom */
        padding: 10px !important;
    }
    
    /* Grid layouts - stack on mobile */
    div[style*="grid-template-columns: repeat(4"],
    div[style*="grid-template-columns: repeat(5"],
    div[style*="grid-template-columns:repeat(4"],
    div[style*="grid-template-columns:repeat(5"] {
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
    }
    
    div[style*="grid-template-columns: repeat(3"],
    div[style*="grid-template-columns:repeat(3"],
    div[style*="grid-template-columns: 1fr 1fr 1fr"] {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }
    
    /* Flex layouts - wrap on mobile */
    div[style*="display:flex"][style*="gap"] {
        flex-wrap: wrap !important;
    }
    
    /* Typography - readable on mobile */
    h1 { font-size: 1.5em !important; }
    h2 { font-size: 1.3em !important; }
    h3 { font-size: 1.1em !important; }
    
    /* Hide less important elements on mobile */
    .desktop-only {
        display: none !important;
    }
    
    /* Universe buttons - smaller on mobile */
    .universe-btn {
        padding: 8px 10px !important;
        font-size: 11px !important;
    }
    .universe-btn span {
        font-size: 11px !important;
    }
    
    /* Filter groups - stack */
    .filter-group {
        width: 100% !important;
        margin-bottom: 10px;
    }
    
    /* Top header adjustments */
    .top-header {
        padding: 8px 10px !important;
    }
    
    .page-title {
        font-size: 1em !important;
        margin-left: 45px !important;
    }
    
    /* Heatmap container */
    #heatmapContainer,
    #heatmapScroll {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Modals - full width on mobile */
    .modal-content {
        width: 95% !important;
        max-width: 95% !important;
        margin: 10px auto !important;
        padding: 15px !important;
        max-height: 90vh;
        overflow-y: auto;
    }
    
    /* Premium/promo cards */
    .card[style*="gradient"] {
        padding: 15px !important;
    }
    
    /* Scan button */
    .scan-btn {
        width: 100% !important;
        padding: 15px !important;
        font-size: 16px !important;
    }
}

/* Extra small screens (iPhone SE, etc) */
@media (max-width: 380px) {
    .container {
        padding: 5px !important;
    }
    
    .card {
        padding: 10px !important;
    }
    
    div[style*="grid-template-columns: repeat"],
    div[style*="grid-template-columns:repeat"] {
        grid-template-columns: 1fr !important;
    }
    
    .universe-btn {
        padding: 6px 8px !important;
    }
    
    button, .btn {
        font-size: 13px !important;
    }
}

/* Sidebar mobile improvements */
@media (max-width: 768px) {
    .sidebar {
        width: 280px;
        left: -290px;
    }
    
    .sidebar.active {
        left: 0;
        box-shadow: 5px 0 30px rgba(0,0,0,0.5);
    }
    
    .sidebar-nav a {
        padding: 12px 15px !important;
        font-size: 14px !important;
    }
    
    .nav-section {
        padding: 5px 0;
    }
    
    /* Hide sidebar header logo text on mobile, keep icon */
    .sidebar-header span {
        font-size: 14px;
    }
}

/* ================================
   MOBILE SPECIFIC FIXES - Heatmap & Scanner
   ================================ */
@media (max-width: 768px) {
    /* Heatmap controls - smaller buttons */
    #heatmapSection .small,
    .heatmap-limit-btn,
    .display-mode-btn {
        padding: 6px 10px !important;
        font-size: 11px !important;
        min-height: 32px !important;
    }
    
    /* Heatmap header - stack vertically */
    #heatmapSection > div:first-child {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 10px !important;
    }
    
    /* View/Display button groups - inline */
    #heatmapSection div[style*="display:inline-flex"],
    #heatmapSection div[style*="display: inline-flex"] {
        margin-left: 0 !important;
        margin-top: 5px;
    }
    
    /* Results header - stack */
    .section-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 10px !important;
    }
    
    .section-header h2 {
        font-size: 1.1em !important;
    }
    
    /* Toggle switch area */
    .toggle {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .toggle label {
        font-size: 12px !important;
    }
    
    /* Export CSV button */
    .section-header .btn-primary,
    .section-header .btn-secondary {
        width: 100%;
        text-align: center;
    }
    
    /* Fix blue on blue - ensure text contrast */
    input, select, textarea {
        background: #0d1b2a !important;
        border: 1px solid #4a5568 !important;
        color: #fff !important;
    }
    
    input::placeholder,
    textarea::placeholder {
        color: #888 !important;
    }
    
    /* Universe buttons grid on mobile */
    div[style*="grid-template-columns:repeat(auto-fill"] {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 6px !important;
    }
    
    .universe-btn {
        padding: 8px 6px !important;
    }
    
    .universe-btn span {
        font-size: 10px !important;
    }
    
    /* Manual tickers textarea */
    #customTickers {
        font-size: 14px !important;
        min-height: 60px;
    }
    
    /* Filter sections - more compact */
    div[style*="background:#1a2a4a"] {
        padding: 10px !important;
    }
    
    div[style*="background:#1a2a4a"] h4 {
        font-size: 13px !important;
        margin-bottom: 10px !important;
    }
    
    /* Scan button */
    #scanBtn, .scan-btn {
        font-size: 14px !important;
        padding: 12px !important;
    }
    
    /* Color legend - wrap */
    #heatmapSection > div:last-child {
        flex-wrap: wrap !important;
        gap: 8px !important;
        padding: 8px !important;
    }
    
    #heatmapSection > div:last-child > div {
        font-size: 10px !important;
    }
}

/* Extra small - 3 col universe becomes 2 */
@media (max-width: 400px) {
    div[style*="grid-template-columns:repeat(auto-fill"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    .universe-btn span {
        font-size: 9px !important;
    }
}
