/* AI StockPulse Modern Telegram Mini App Stylesheet */
:root {
    --bg-primary: #0e131f;
    --bg-secondary: #171f30;
    --bg-card: #1d283d;
    --bg-card-hover: #24324d;
    --border-color: #2b3a55;
    --text-primary: #f0f4f8;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-blue: #38bdf8;
    --accent-blue-bg: rgba(56, 189, 248, 0.12);
    --green: #10b981;
    --green-bg: rgba(16, 185, 129, 0.15);
    --red: #f43f5e;
    --red-bg: rgba(244, 63, 94, 0.15);
    --yellow: #f59e0b;
    --yellow-bg: rgba(245, 158, 11, 0.15);
    --gray-bg: rgba(148, 163, 184, 0.15);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

/* Telegram theme integration */
body.tg-theme {
    --bg-primary: var(--tg-theme-bg-color, #0e131f);
    --bg-secondary: var(--tg-theme-secondary-bg-color, #171f30);
    --text-primary: var(--tg-theme-text-color, #f0f4f8);
    --text-secondary: var(--tg-theme-hint-color, #94a3b8);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-sans);
    line-height: 1.5;
    font-size: 14px;
    padding-bottom: 24px;
    overflow-x: hidden;
}

.app-wrapper {
    max-width: 960px;
    margin: 0 auto;
    padding: 16px 12px;
}

/* Header */
.app-header {
    margin-bottom: 16px;
}

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

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    font-size: 28px;
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.2), rgba(16, 185, 129, 0.2));
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
}

.brand-title {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.brand-subtitle {
    font-size: 11px;
    color: var(--text-secondary);
}

.btn-refresh {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-refresh:hover, .btn-refresh:active {
    background: var(--bg-card);
    border-color: var(--accent-blue);
}

.btn-refresh.spinning .refresh-icon {
    animation: spin 1s linear infinite;
    display: inline-block;
}

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

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
}

.stat-value {
    font-size: 15px;
    font-weight: 700;
    font-family: var(--font-mono);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat-sub {
    font-size: 10px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Controls */
.controls-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    font-size: 14px;
}

.search-box input {
    width: 100%;
    padding: 10px 36px 10px 36px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font-sans);
    outline: none;
    transition: border-color 0.2s ease;
}

.search-box input:focus {
    border-color: var(--accent-blue);
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.clear-btn {
    position: absolute;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    padding: 4px;
}

/* Pill Tabs */
.pill-tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
}

.pill-tabs::-webkit-scrollbar {
    display: none;
}

.pill-btn {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.pill-btn.active {
    background: var(--accent-blue-bg);
    border-color: var(--accent-blue);
    color: var(--accent-blue);
    font-weight: 600;
}

.badge {
    padding: 1px 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    font-size: 10px;
    font-family: var(--font-mono);
}

/* Table */
.table-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 16px;
}

.forecast-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.forecast-table th {
    background: var(--bg-card);
    padding: 12px 14px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    user-select: none;
}

.forecast-table th.th-sortable:hover {
    color: var(--text-primary);
}

.forecast-table td {
    padding: 12px 14px;
    border-bottom: 1px solid rgba(43, 58, 85, 0.4);
    font-size: 13px;
    vertical-align: middle;
}

.forecast-table tbody tr {
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.forecast-table tbody tr:hover {
    background: var(--bg-card-hover);
}

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

/* Row elements */
.ticker-cell {
    display: flex;
    flex-direction: column;
}

.ticker-symbol {
    font-weight: 700;
    font-size: 14px;
    font-family: var(--font-mono);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.ticker-name {
    font-size: 11px;
    color: var(--text-secondary);
}

.price-text {
    font-family: var(--font-mono);
    font-weight: 600;
}

/* Action signals & Badges */
.signal-pill, .action-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    font-family: var(--font-mono);
    letter-spacing: 0.02em;
    text-align: center;
    text-transform: uppercase;
}

.signal-buy, .badge-buy { background: var(--green-bg); color: var(--green); border: 1px solid rgba(16, 185, 129, 0.3); }
.signal-strong-buy, .badge-strong-buy { background: rgba(16, 185, 129, 0.25); color: #34d399; border: 1px solid rgba(52, 211, 153, 0.5); box-shadow: 0 0 10px rgba(16, 185, 129, 0.2); }
.signal-hold, .badge-hold { background: var(--gray-bg); color: var(--text-secondary); border: 1px solid var(--border-color); }
.signal-sell, .badge-sell { background: var(--red-bg); color: var(--red); border: 1px solid rgba(244, 63, 94, 0.3); }
.signal-strong-sell, .badge-strong-sell { background: rgba(244, 63, 94, 0.25); color: #fb7185; border: 1px solid rgba(251, 113, 133, 0.5); box-shadow: 0 0 10px rgba(244, 63, 94, 0.2); }

/* Instrument type tag */
.type-tag, .type-pill {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
    border: 1px solid rgba(255, 255, 255, 0.06);
    vertical-align: middle;
}
.tag-stock { background: rgba(56, 189, 248, 0.12); color: #7dd3fc; border-color: rgba(56, 189, 248, 0.3); }
.tag-etf { background: rgba(168, 85, 247, 0.15); color: #c084fc; border-color: rgba(168, 85, 247, 0.3); }
.tag-futures { background: rgba(245, 158, 11, 0.15); color: #fbbf24; border-color: rgba(245, 158, 11, 0.3); }
.tag-crypto { background: rgba(236, 72, 153, 0.15); color: #f472b6; border-color: rgba(236, 72, 153, 0.3); }
.tag-commodity { background: rgba(234, 179, 8, 0.15); color: #facc15; border-color: rgba(234, 179, 8, 0.3); }

/* Expected return */
.expected-return {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 13px;
}

/* Probabilities mini bar & tracks */
.prob-bar-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 140px;
    margin: 0 auto;
}

.prob-bar-track, .prob-mini-track {
    display: flex;
    height: 7px;
    border-radius: 4px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.08);
    width: 100%;
}

.prob-mini-fill {
    height: 100%;
    transition: width 0.3s ease;
}

.prob-bar-bull { background: var(--green); }
.prob-bar-flat { background: #64748b; }
.prob-bar-bear { background: var(--red); }

.prob-legend, .prob-labels {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    font-family: var(--font-mono);
    margin-top: 3px;
}

.legend-bull { color: var(--green); }
.legend-flat { color: var(--text-muted); }
.legend-bear { color: var(--red); }

/* RSI indicator */
.rsi-badge {
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.05);
}

.rsi-high { color: var(--red); }
.rsi-low { color: var(--green); }
.rsi-mid { color: var(--text-secondary); }

/* Utility classes */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-green { color: var(--green) !important; }
.text-red { color: var(--red) !important; }
.text-blue { color: var(--accent-blue) !important; }
.text-muted { color: var(--text-muted) !important; }
.font-mono { font-family: var(--font-mono); }
.font-bold { font-weight: 700; }

/* Mobile Cards list (shown on narrow screens) */
.cards-list {
    display: none;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}

.stock-card, .mobile-item-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.2s ease, background 0.2s ease;
}

.stock-card:hover, .mobile-item-card:hover {
    background: var(--bg-card);
    border-color: rgba(56, 189, 248, 0.3);
}

.stock-card:active, .mobile-item-card:active {
    transform: scale(0.98);
    border-color: var(--accent-blue);
}

.card-top-row, .card-header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.card-ticker {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    margin-right: 6px;
}

.card-name {
    font-size: 12px;
    color: var(--text-secondary);
    margin-right: 6px;
}

.card-mid-row, .card-stats-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 2px;
}

.metric-label {
    display: block;
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.metric-val {
    font-size: 13px;
    font-weight: 600;
}

.card-empty {
    text-align: center;
    padding: 30px;
    color: var(--text-muted);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    border: 1px dashed var(--border-color);
}

/* Modal Drawer */
.modal-backdrop {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: none;
    align-items: flex-end;
    justify-content: center;
    z-index: 1000;
}

.modal-backdrop.open {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-width: 540px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 20px;
    animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.modal-ticker {
    font-size: 20px;
    font-weight: 800;
    font-family: var(--font-mono);
}

.modal-name {
    font-size: 13px;
    color: var(--text-secondary);
    margin-left: 8px;
}

.btn-close {
    background: var(--bg-card);
    border: none;
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Modal Sections */
.modal-stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

.modal-stat-item {
    background: var(--bg-card);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
}

.modal-stat-item .lbl {
    font-size: 11px;
    color: var(--text-muted);
    display: block;
}

.modal-stat-item .val {
    font-size: 15px;
    font-weight: 700;
    font-family: var(--font-mono);
}

.distribution-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.dist-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.dist-header {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
}

.dist-bar-track {
    height: 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    overflow: hidden;
}

.dist-bar-fill {
    height: 100%;
    border-radius: 4px;
}

/* Footer */
.app-footer {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    padding: 16px 8px;
}

.disclaimer {
    margin-top: 4px;
    font-size: 10px;
    color: #475569;
}

/* Real-time Training & Sync Progress Banner */
.progress-banner {
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.95), rgba(15, 23, 42, 0.95));
    border: 1px solid rgba(56, 189, 248, 0.35);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    margin-bottom: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35), 0 0 15px rgba(56, 189, 248, 0.15);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.progress-banner.completed {
    border-color: rgba(16, 185, 129, 0.45);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35), 0 0 15px rgba(16, 185, 129, 0.15);
}

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

.progress-banner-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pulsing-indicator {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background-color: var(--accent-blue);
    box-shadow: 0 0 8px var(--accent-blue);
    animation: pulse-glow 1.5s infinite ease-in-out;
}

.progress-banner.completed .pulsing-indicator {
    background-color: var(--green);
    box-shadow: 0 0 8px var(--green);
    animation: none;
}

@keyframes pulse-glow {
    0% { transform: scale(0.9); opacity: 0.7; }
    50% { transform: scale(1.2); opacity: 1; filter: drop-shadow(0 0 6px var(--accent-blue)); }
    100% { transform: scale(0.9); opacity: 0.7; }
}

.progress-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.2px;
}

.progress-percent {
    font-size: 14px;
    font-weight: 700;
    color: var(--accent-blue);
}

.progress-banner.completed .progress-percent {
    color: var(--green);
}

.progress-track {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    overflow: hidden;
    position: relative;
    margin-bottom: 8px;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #0284c7, #38bdf8, #818cf8);
    background-size: 200% 100%;
    border-radius: 999px;
    transition: width 0.4s ease-out;
    animation: shimmer-stripes 2s linear infinite;
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.5);
}

.progress-banner.completed .progress-bar-fill {
    background: linear-gradient(90deg, #059669, #10b981);
    animation: none;
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
}

@keyframes shimmer-stripes {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

.progress-banner-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: var(--text-secondary);
}

.progress-device-badge {
    background: rgba(255, 255, 255, 0.07);
    padding: 2px 7px;
    border-radius: 6px;
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--text-muted);
}

/* Responsive adjustments */
@media (max-width: 680px) {
    .table-container {
        display: none !important;
    }
    .cards-list {
        display: flex !important;
    }
    .stats-grid {
        grid-template-columns: 1fr;
    }
}
