:root {
    --bg-color: var(--tg-theme-bg-color, #1e1e24);
    --card-bg: var(--tg-theme-secondary-bg-color, #2b2b36);
    --text-main: var(--tg-theme-text-color, #ffffff);
    --text-muted: var(--tg-theme-hint-color, #aaaaaa);
    --text-desc: var(--tg-theme-text-color, #dddddd);
    --border-color: var(--tg-theme-secondary-bg-color, #444444);
    --btn-bg: var(--tg-theme-button-color, #4CAF50);
    --shadow: 0 2px 4px rgba(0,0,0,0.15);
}
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; margin: 0; padding: 15px; background-color: var(--bg-color); color: var(--text-main); user-select: none; }
.header { position: fixed; top: 112px; left: 0; width: 100%; box-sizing: border-box; height: 50px; z-index: 9999; background-color: var(--bg-color); display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border-color); padding: 0 15px; }
.header h2 { margin: 0; font-size: 18px; color: var(--btn-bg); }
.filters { display: flex; gap: 10px; margin-bottom: 15px; }
select { flex: 1; padding: 8px; background-color: var(--card-bg); color: var(--text-main); border: 1px solid var(--border-color); border-radius: 8px; outline: none; font-size: 13px; appearance: none; }
.alerts-container { display: flex; flex-direction: column; gap: 12px;   padding-bottom: 120px; }
.alert-card { background-color: var(--card-bg); border-radius: 10px; padding: 12px; border-left: 4px solid var(--btn-bg); box-shadow: var(--shadow); color: var(--text-main); }
.alert-card.market-forex { border-left-color: #2196F3 !important; }
.alert-card.market-crypto { border-left-color: #FFC107 !important; }
.alert-card.market-stocks { border-left-color: #9C27B0 !important; }
.alert-card.market-indices { border-left-color: #00BCD4 !important; }
.alert-card.market-commodities { border-left-color: #FFD700 !important; }
.alert-card.market-bonds { border-left-color: #4CAF50 !important; }
.alert-header { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.delete-btn { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 16px; padding: 2px 8px; border-radius: 4px; }
.delete-btn.confirm-mode { background-color: #F44336; color: white; font-size: 11px; padding: 4px 8px; }
.alert-title { font-size: 15px; font-weight: bold; margin-bottom: 6px; color: var(--text-main); }
.alert-desc { 
    font-size: 14px; 
    color: var(--text-desc); 
    line-height: 1.5;
    white-space: pre-wrap; /* This fixes the newlines issue! */
}
.loading, .no-alerts { text-align: center; color: var(--text-muted); margin-top: 30px; font-size: 15px; }

@keyframes newsBlink { 0% { color: #e53e3e; text-shadow: 0 0 8px rgba(229,62,62,0.6); transform: scale(1.05); } 50% { color: #a0aec0; text-shadow: none; transform: scale(1); } 100% { color: #e53e3e; text-shadow: 0 0 8px rgba(229,62,62,0.6); transform: scale(1.05); } } .news-blink { animation: newsBlink 1s infinite; font-weight: bold; }

/* Responsive Badge & Header Protection */
.header { min-width: 0; overflow: hidden; }
.header > div { min-width: 0; }
#user-tier-badge { display: inline-flex; align-items: center; flex-shrink: 0; }
#user-tier-badge span { display: inline-flex !important; align-items: center !important; gap: 3px !important; white-space: nowrap !important; flex-shrink: 0 !important; }
.alert-header { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.alert-header > div { min-width: 0; }
.alert-header span { white-space: nowrap; }
.alert-header .vip-badge-item { display: inline-flex !important; align-items: center !important; gap: 3px !important; white-space: nowrap !important; flex-shrink: 0 !important; }


/* Rich Article & Guide Typography & Responsive Modals */
#articleModal, #guideModal, #pollModal {
    box-sizing: border-box !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
    overscroll-behavior: contain !important;
    padding: 10px !important;
}

#articleModal > div, #guideModal > div, #pollModal > div {
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 650px !important;
    margin: 15px auto 50px auto !important;
    overflow-x: hidden !important;
    word-break: break-word !important;
    overflow-wrap: anywhere !important;
    touch-action: auto !important;
}

#articleContent, #guideContent {
    user-select: text !important;
    -webkit-user-select: text !important;
    touch-action: auto !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.7;
    color: var(--text-main);
    font-size: 14px;
    word-break: break-word !important;
    overflow-wrap: anywhere !important;
    box-sizing: border-box !important;
    width: 100% !important;
    overflow-x: hidden !important;
}

#articleContent *, #guideContent * {
    max-width: 100% !important;
    box-sizing: border-box !important;
}

#articleContent table, #guideContent table {
    width: 100% !important;
    max-width: 100% !important;
    display: block !important;
    overflow-x: auto !important;
    border-collapse: collapse !important;
    margin: 12px 0 !important;
}

#articleContent img, #guideContent img {
    max-width: 100% !important;
    height: auto !important;
    border-radius: 8px;
    margin: 10px auto;
    display: block;
}

#articleContent iframe, #guideContent iframe {
    max-width: 100% !important;
}

#articleContent h1, #guideContent h1 { font-size: 20px; font-weight: bold; margin: 16px 0 8px 0; color: #38bdf8; }
#articleContent h2, #guideContent h2 { font-size: 17px; font-weight: bold; margin: 14px 0 6px 0; color: #38bdf8; }
#articleContent h3, #guideContent h3 { font-size: 15px; font-weight: bold; margin: 12px 0 4px 0; color: #38bdf8; }
#articleContent p, #guideContent p { margin-bottom: 10px; }
#articleContent blockquote, #guideContent blockquote { border-left: 4px solid #06b6d4; padding-left: 12px; margin: 10px 0; color: var(--text-muted); font-style: italic; }
#articleContent ul, #guideContent ul, #articleContent ol, #guideContent ol { padding-left: 20px; margin-bottom: 10px; }
#articleContent li, #guideContent li { margin-bottom: 4px; }
#articleContent pre, #guideContent pre, #articleContent code, #guideContent code { background: rgba(0,0,0,0.3); padding: 2px 6px; border-radius: 4px; font-family: monospace; font-size: 12px; white-space: pre-wrap; word-break: break-all; }
#articleContent .ql-align-center, #guideContent .ql-align-center { text-align: center; }
#articleContent .ql-align-right, #guideContent .ql-align-right { text-align: right; }
#articleContent .ql-align-justify, #guideContent .ql-align-justify { text-align: justify; }
#articleContent .ql-direction-rtl, #guideContent .ql-direction-rtl { direction: rtl; text-align: right; }

/* Modern Close Button Hover */
.modal-close-btn:hover {
    background: rgba(239, 68, 68, 0.2) !important;
    border-color: rgba(239, 68, 68, 0.4) !important;
    color: #ef4444 !important;
    transform: rotate(90deg) scale(1.05);
}
.modal-close-btn:active {
    transform: rotate(90deg) scale(0.95);
}



/* Web App Header Spacing (Comfortable & Clean) */
.header { 
    padding: 0 12px !important; 
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    box-sizing: border-box !important;
}
.header-brand {
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    min-width: 0 !important;
    flex-shrink: 0 !important;
}
.header h2 { 
    font-size: 15px !important; 
    font-weight: 700 !important; 
    white-space: nowrap !important; 
    margin: 0 !important;
}
.header-actions { 
    display: flex !important; 
    align-items: center !important; 
    gap: 8px !important; 
    flex-shrink: 0 !important; 
}
.header-actions button { 
    padding: 3px !important; 
    font-size: 16px !important; 
    width: 26px !important; 
    height: 26px !important; 
    display: inline-flex !important; 
    align-items: center !important; 
    justify-content: center !important; 
    cursor: pointer !important; 
    transition: transform 0.15s ease !important; 
}
.header-actions button:hover { transform: scale(1.12); }
.header-actions button svg { width: 18px !important; height: 18px !important; }
#user-tier-badge { margin-left: 4px !important; flex-shrink: 0 !important; }
#user-tier-badge span { padding: 2px 5px !important; font-size: 10px !important; font-weight: bold; white-space: nowrap; }

/* Dedicated Coin Wallet Pill Styling */
#coinWalletPill {
    display: inline-flex !important;
    align-items: center !important;
    gap: 4px !important;
    padding: 3px 8px !important;
    border-radius: 14px !important;
    font-size: 11px !important;
    font-weight: 800 !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    cursor: pointer;
    background: linear-gradient(135deg, rgba(245,158,11,0.22), rgba(217,119,6,0.38)) !important;
    border: 1px solid #f59e0b !important;
    color: #fbbf24 !important;
    box-shadow: 0 0 10px rgba(245,158,11,0.25) !important;
}
#coinWalletPill svg {
    width: 14px !important;
    height: 14px !important;
    flex-shrink: 0 !important;
}

/* Two-Story Header Layout for Mobile Devices (under 600px) */
@media (max-width: 600px) {
    body {
        padding-top: 202px !important;
    }
    .header {
        height: auto !important;
        min-height: 74px !important;
        flex-direction: column !important;
        justify-content: center !important;
        align-items: stretch !important;
        padding: 6px 12px !important;
        gap: 6px !important;
    }
    /* Story 1: Brand & VIP Badge on left, Coin Wallet on right */
    .header-brand {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        width: 100% !important;
    }
    .header-brand > div:first-child {
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
    }
    .header h2 {
        font-size: 15px !important;
        font-weight: 800 !important;
        letter-spacing: 0.3px;
    }
    /* Story 2: Action buttons neatly distributed across width */
    .header-actions {
        display: flex !important;
        justify-content: space-around !important;
        align-items: center !important;
        width: 100% !important;
        gap: 8px !important;
        padding-top: 4px !important;
        border-top: 1px solid rgba(255, 255, 255, 0.06) !important;
    }
    .header-actions button {
        width: 32px !important;
        height: 28px !important;
        font-size: 16px !important;
        padding: 2px !important;
        border-radius: 6px !important;
        background: rgba(255, 255, 255, 0.04) !important;
    }
}


/* Enforce Coin Pill Single Display Between Mobile & Desktop */
@media (max-width: 600px) {
    #coinWalletPill {
        display: none !important;
    }
    #coinWalletPillMobile {
        display: inline-flex !important;
    }
}
@media (min-width: 601px) {
    #coinWalletPillMobile {
        display: none !important;
    }
    #coinWalletPill {
        display: inline-flex !important;
    }
}

/* Ensure heatmap and chat iframes clear header on mobile without overlap */
#heatmap-container, #chat-container {
    top: 165px !important;
}
@media (max-width: 600px) {
    #heatmap-container, #chat-container {
        top: 200px !important;
    }
}
