/* ============================================================
   MARKET MAYHEM - Retro Financial Terminal Aesthetic
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;600;700&family=Space+Grotesk:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #0f1520;
    --bg-panel: #111927;
    --bg-card: #151d2e;
    --bg-hover: #1a2436;
    --bg-input: #0d1219;
    --border: #1e2a3a;
    --border-focus: #2d4a6f;
    --text-primary: #e0e6ed;
    --text-secondary: #7a8ba0;
    --text-muted: #4a5568;
    --text-label: #5a6b80;
    --green: #00e676;
    --green-dim: #00a854;
    --green-bg: rgba(0,230,118,0.08);
    --red: #ff1744;
    --red-dim: #c41230;
    --red-bg: rgba(255,23,68,0.08);
    --blue: #40c4ff;
    --blue-dim: #0091ea;
    --yellow: #ffd740;
    --yellow-dim: #c8a000;
    --purple: #b388ff;
    --orange: #ff9100;
    --cyan: #18ffff;
    --accent: #40c4ff;
    --accent-dim: #0091ea;
    --glow-green: 0 0 10px rgba(0,230,118,0.3);
    --glow-red: 0 0 10px rgba(255,23,68,0.3);
    --glow-blue: 0 0 10px rgba(64,196,255,0.3);
    --font-mono: 'JetBrains Mono', 'IBM Plex Mono', monospace;
    --font-sans: 'Space Grotesk', sans-serif;
    --radius: 4px;
    --radius-lg: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { font-size: 14px; }

body {
    font-family: var(--font-mono);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: calc(var(--vh, 1vh) * 100);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── AUTH SCREENS ─────────────────────────────────────── */
#auth-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: calc(var(--vh, 1vh) * 100);
    background: var(--bg-primary);
    position: relative;
    overflow: hidden;
}

#auth-screen::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: 
        radial-gradient(ellipse at 20% 50%, rgba(0,145,234,0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(0,230,118,0.04) 0%, transparent 50%);
    pointer-events: none;
}

.auth-container {
    width: 100%;
    max-width: 420px;
    padding: 2rem;
    position: relative;
    z-index: 1;
}

.auth-logo {
    text-align: center;
    margin-bottom: 2.5rem;
}

.auth-logo h1 {
    font-family: var(--font-mono);
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: 4px;
    color: var(--green);
    text-shadow: var(--glow-green);
    text-transform: uppercase;
}

.auth-logo .subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    letter-spacing: 3px;
    margin-top: 0.5rem;
    text-transform: uppercase;
}

.auth-box {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem;
}

.auth-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.auth-tabs button {
    flex: 1;
    padding: 0.75rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    letter-spacing: 1px;
    text-transform: uppercase;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.auth-tabs button.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.form-group { margin-bottom: 1.25rem; }

.form-group label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-label);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 0.4rem;
}

input[type="text"], input[type="email"], input[type="password"], input[type="number"], select {
    width: 100%;
    padding: 0.7rem 0.9rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

input:focus, select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent-dim);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.7rem 1.4rem;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #000;
    width: 100%;
}

.btn-primary:hover { background: var(--blue); box-shadow: var(--glow-blue); }

.btn-buy {
    background: var(--green-bg);
    border-color: var(--green-dim);
    color: var(--green);
}
.btn-buy:hover { background: var(--green); color: #000; box-shadow: var(--glow-green); }

.btn-sell {
    background: var(--red-bg);
    border-color: var(--red-dim);
    color: var(--red);
}
.btn-sell:hover { background: var(--red); color: #fff; box-shadow: var(--glow-red); }

.btn-ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--text-secondary);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.7rem; }

.btn-xs { padding: 0.25rem 0.5rem; font-size: 0.65rem; }

.auth-error {
    color: var(--red);
    font-size: 0.8rem;
    margin-bottom: 1rem;
    padding: 0.5rem;
    background: var(--red-bg);
    border-radius: var(--radius);
    display: none;
}

/* ── MAIN LAYOUT ─────────────────────────────────────── */
#app-screen { display: none; height: 100vh; height: calc(var(--vh, 1vh) * 100); flex-direction: column; }
#app-screen.visible { display: flex; }

/* Top Bar */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    height: 48px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 100;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.top-bar .logo {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--green);
    letter-spacing: 2px;
    text-transform: uppercase;
    text-shadow: var(--glow-green);
    cursor: pointer;
}

.top-bar-stats {
    display: flex;
    gap: 1.5rem;
    font-size: 0.75rem;
}

.top-bar-stats .stat {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.top-bar-stats .stat-label {
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.65rem;
    letter-spacing: 1px;
}

.top-bar-stats .stat-value {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.top-bar-right .regime-badge {
    padding: 0.2rem 0.6rem;
    border-radius: 2px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.regime-bull { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-dim); }
.regime-bear { background: var(--red-bg); color: var(--red); border: 1px solid var(--red-dim); }
.regime-sideways { background: rgba(255,215,64,0.08); color: var(--yellow); border: 1px solid var(--yellow-dim); }
.regime-volatile { background: rgba(255,145,0,0.08); color: var(--orange); border: 1px solid var(--orange); }
.regime-recovery { background: rgba(64,196,255,0.08); color: var(--blue); border: 1px solid var(--blue-dim); }
.regime-mania { background: rgba(179,136,255,0.08); color: var(--purple); border: 1px solid var(--purple); }
.regime-crunch { background: var(--red-bg); color: var(--red); border: 1px solid var(--red-dim); }

.user-menu {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    padding: 0.3rem 0.6rem;
    border-radius: var(--radius);
    transition: background 0.15s;
}
.user-menu:hover { background: var(--bg-hover); }
.user-menu .username { font-size: 0.8rem; font-weight: 500; }
.user-menu .level-badge {
    font-size: 0.6rem;
    padding: 0.1rem 0.35rem;
    background: var(--accent);
    color: #000;
    border-radius: 2px;
    font-weight: 700;
}

/* Sidebar Nav */
.app-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.sidebar {
    width: 200px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    padding: 0.75rem 0;
    overflow-y: auto;
    flex-shrink: 0;
}

.sidebar .nav-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 1rem;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    border-left: 3px solid transparent;
    text-decoration: none;
}

.sidebar .nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar .nav-item.active {
    color: var(--accent);
    background: rgba(64,196,255,0.05);
    border-left-color: var(--accent);
}

.sidebar .nav-item .icon { font-size: 1rem; width: 1.2rem; text-align: center; }

.sidebar .nav-divider {
    height: 1px;
    background: var(--border);
    margin: 0.5rem 1rem;
}

/* Main Content */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    background: var(--bg-primary);
}

/* ── PANELS & CARDS ──────────────────────────────────── */
.panel {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 1rem;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

.panel-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.panel-body { padding: 1rem; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }

.stat-card {
    padding: 0.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.stat-card .label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.3rem;
}

.stat-card .value {
    font-size: 1.2rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.stat-card .change {
    font-size: 0.75rem;
    font-weight: 500;
    margin-top: 0.15rem;
}

/* ── TABLES ──────────────────────────────────────────── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
}

.data-table thead th {
    padding: 0.5rem 0.75rem;
    text-align: left;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}

.data-table thead th:hover { color: var(--text-secondary); }
.data-table thead th.text-right, .data-table td.text-right { text-align: right; }

.data-table tbody tr {
    border-bottom: 1px solid rgba(30,42,58,0.5);
    transition: background 0.1s;
    cursor: pointer;
}

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

.data-table td {
    padding: 0.55rem 0.75rem;
    white-space: nowrap;
}

.ticker-cell {
    font-weight: 700;
    color: var(--accent);
}

.asset-name {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

/* ── COLORS & UTILITIES ──────────────────────────────── */
.positive { color: var(--green) !important; }
.negative { color: var(--red) !important; }
.neutral { color: var(--text-secondary) !important; }
.text-accent { color: var(--accent) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-yellow { color: var(--yellow) !important; }
.text-purple { color: var(--purple) !important; }
.text-orange { color: var(--orange) !important; }

.tag {
    display: inline-block;
    padding: 0.15rem 0.4rem;
    border-radius: 2px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tag-green { background: var(--green-bg); color: var(--green); }
.tag-red { background: var(--red-bg); color: var(--red); }
.tag-blue { background: rgba(64,196,255,0.1); color: var(--blue); }
.tag-yellow { background: rgba(255,215,64,0.1); color: var(--yellow); }
.tag-purple { background: rgba(179,136,255,0.1); color: var(--purple); }

/* ── SECTOR HEATMAP ──────────────────────────────────── */
.sector-heatmap {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
}

.sector-tile {
    padding: 0.6rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
}

.sector-tile:hover { border-color: var(--accent); transform: translateY(-1px); }

.sector-tile .sector-name {
    font-size: 0.65rem;
    color: var(--text-secondary);
    margin-bottom: 0.2rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sector-tile .sector-change {
    font-size: 1rem;
    font-weight: 700;
}

/* ── NEWS FEED ───────────────────────────────────────── */
.news-item {
    padding: 0.75rem;
    border-bottom: 1px solid rgba(30,42,58,0.5);
    cursor: pointer;
    transition: background 0.1s;
}

.news-item:last-child { border-bottom: none; }
.news-item:hover { background: var(--bg-hover); }

.news-item .news-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
    font-size: 0.65rem;
}

.news-item .news-source {
    color: var(--blue);
    font-weight: 600;
}

.news-item .news-time {
    color: var(--text-muted);
}

.news-item .news-scope {
    padding: 0.1rem 0.3rem;
    border-radius: 2px;
    font-size: 0.6rem;
    font-weight: 600;
    text-transform: uppercase;
}

.news-item .news-headline {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.4;
}

.news-item .news-ticker {
    color: var(--accent);
    font-weight: 700;
}

/* ── MISSION CARDS ───────────────────────────────────── */
.mission-card {
    padding: 0.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
}

.mission-card .mission-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.4rem;
}

.mission-card .mission-title {
    font-size: 0.85rem;
    font-weight: 600;
}

.mission-card .mission-type {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.mission-card .mission-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.mission-card .mission-progress {
    height: 4px;
    background: var(--bg-input);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 0.4rem;
}

.mission-card .mission-progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s;
}

.mission-card .mission-progress-bar.complete {
    background: var(--green);
}

.mission-card .mission-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.7rem;
}

.mission-card .mission-rewards {
    display: flex;
    gap: 0.75rem;
    color: var(--text-muted);
}

.mission-card .mission-rewards .reward {
    display: flex;
    align-items: center;
    gap: 0.2rem;
}

/* ── CHART CONTAINER ─────────────────────────────────── */
.chart-container {
    position: relative;
    width: 100%;
    height: 300px;
    padding: 0.5rem;
}

.chart-container canvas { width: 100% !important; height: 100% !important; }

/* ── TRADE PANEL ─────────────────────────────────────── */
.trade-panel {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem;
}

.trade-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 1rem;
}

.trade-tabs button {
    flex: 1;
    padding: 0.6rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.15s;
}

.trade-tabs button:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.trade-tabs button:last-child { border-radius: 0 var(--radius) var(--radius) 0; }

.trade-tabs button.active-buy {
    background: var(--green-bg);
    border-color: var(--green-dim);
    color: var(--green);
}

.trade-tabs button.active-sell {
    background: var(--red-bg);
    border-color: var(--red-dim);
    color: var(--red);
}

.trade-summary {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-card);
    border-radius: var(--radius);
    font-size: 0.8rem;
}

.trade-summary .trade-row {
    display: flex;
    justify-content: space-between;
    padding: 0.2rem 0;
}

.trade-summary .trade-total {
    border-top: 1px solid var(--border);
    margin-top: 0.3rem;
    padding-top: 0.3rem;
    font-weight: 700;
}

/* ── XP BAR ──────────────────────────────────────────── */
.xp-bar-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0;
}

.xp-bar {
    flex: 1;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
}

.xp-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--blue-dim), var(--accent));
    border-radius: 3px;
    transition: width 0.5s ease;
}

.xp-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ── ACHIEVEMENT BADGES ──────────────────────────────── */
.achievement-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.75rem;
}

.achievement-badge {
    padding: 0.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-align: center;
    opacity: 0.4;
    transition: all 0.2s;
}

.achievement-badge.earned {
    opacity: 1;
    border-color: var(--yellow-dim);
    background: rgba(255,215,64,0.03);
}

.achievement-badge .ach-icon { font-size: 1.5rem; margin-bottom: 0.3rem; }
.achievement-badge .ach-title { font-size: 0.75rem; font-weight: 600; margin-bottom: 0.2rem; }
.achievement-badge .ach-desc { font-size: 0.65rem; color: var(--text-muted); }

/* ── OFFICE UPGRADES ─────────────────────────────────── */
.upgrade-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.75rem;
}

.upgrade-card {
    padding: 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: all 0.2s;
}

.upgrade-card:hover { border-color: var(--accent); }

.upgrade-card.owned { border-color: var(--green-dim); background: rgba(0,230,118,0.03); }
.upgrade-card.locked { opacity: 0.4; }

.upgrade-card .ug-icon { font-size: 1.5rem; margin-bottom: 0.5rem; }
.upgrade-card .ug-name { font-size: 0.85rem; font-weight: 600; margin-bottom: 0.3rem; }
.upgrade-card .ug-desc { font-size: 0.7rem; color: var(--text-secondary); margin-bottom: 0.5rem; line-height: 1.4; }
.upgrade-card .ug-cost { font-size: 0.8rem; font-weight: 700; color: var(--yellow); }
.upgrade-card .ug-level { font-size: 0.65rem; color: var(--text-muted); }

/* ── TOAST NOTIFICATIONS ─────────────────────────────── */
#toast-container {
    position: fixed;
    top: 60px;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    padding: 0.75rem 1rem;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.8rem;
    min-width: 280px;
    max-width: 380px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    animation: slideIn 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toast.toast-success { border-left: 3px solid var(--green); }
.toast.toast-error { border-left: 3px solid var(--red); }
.toast.toast-info { border-left: 3px solid var(--blue); }
.toast.toast-warning { border-left: 3px solid var(--yellow); }

@keyframes slideIn {
    from { opacity: 0; transform: translateX(50px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ── SEARCH BAR ──────────────────────────────────────── */
.search-bar {
    position: relative;
}

.search-bar input {
    width: 200px;
    padding: 0.4rem 0.7rem;
    padding-left: 1.8rem;
    font-size: 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: var(--font-mono);
}

.search-bar::before {
    content: '⌕';
    position: absolute;
    left: 0.6rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.9rem;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 0.25rem;
    max-height: 300px;
    overflow-y: auto;
    z-index: 200;
    display: none;
}

.search-results.visible { display: block; }

.search-result-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    border-bottom: 1px solid rgba(30,42,58,0.5);
}

.search-result-item:hover { background: var(--bg-hover); }

/* ── TRADINGVIEW CHART ────────────────────────────────── */
#tv-chart-container {
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    overflow: hidden;
}

.ct-tf.active, .ct-mode.active {
    background: var(--accent) !important;
    color: #000 !important;
    border-color: var(--accent) !important;
}

.lev-btn.active {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
}

/* ── LIVE PRICE FLASH ────────────────────────────────── */
.price-flash-up { animation: flashUp 0.6s ease; }
.price-flash-down { animation: flashDown 0.6s ease; }

@keyframes flashUp {
    0% { color: var(--text-primary); }
    30% { color: var(--green); text-shadow: var(--glow-green); }
    100% { color: var(--text-primary); text-shadow: none; }
}

@keyframes flashDown {
    0% { color: var(--text-primary); }
    30% { color: var(--red); text-shadow: var(--glow-red); }
    100% { color: var(--text-primary); text-shadow: none; }
}

/* Live indicator dot */
.live-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--green);
    border-radius: 50%;
    margin-right: 0.4rem;
    animation: livePulse 2s infinite;
}

@keyframes livePulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 4px var(--green); }
    50% { opacity: 0.3; box-shadow: none; }
}

/* ── LOADING ─────────────────────────────────────────── */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.loading::before {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 0.5rem;
}

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

/* ── MOBILE ELEMENTS (hidden on desktop) ─────────────── */
.mobile-menu-btn { display: none; }
.mobile-account-bar { display: none; }
.mobile-overlay { display: none; }
.mobile-drawer { display: none; }
.mobile-bottom-nav { display: none; }
.desktop-only { display: inline-flex; }

/* Hamburger button */
.mobile-menu-btn {
    width: 36px;
    height: 36px;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px;
    flex-shrink: 0;
}

.mobile-menu-btn span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--text-secondary);
    border-radius: 1px;
    transition: all 0.25s;
}

.mobile-menu-btn.open span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.mobile-menu-btn.open span:nth-child(2) { opacity: 0; }
.mobile-menu-btn.open span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* ── RESPONSIVE ──────────────────────────────────────── */

/* TABLET: 769px – 1024px */
@media (max-width: 1024px) {
    .sidebar { width: 56px; }
    .sidebar .nav-item span:not(.icon) { display: none; }
    .sidebar .nav-item { justify-content: center; padding: 0.6rem; }
    .sidebar .nav-item .icon { width: auto; }
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .sector-heatmap { grid-template-columns: repeat(2, 1fr); }
    .top-bar-stats { gap: 1rem; }
}

/* MOBILE: <=768px — Complete mobile overhaul */
@media (max-width: 768px) {

    html { font-size: 13px; }

    /* ── Top Bar Mobile ──────────────────── */
    .top-bar {
        height: 52px;
        padding: 0 0.75rem;
    }

    .top-bar-stats { display: none !important; }
    .desktop-only { display: none !important; }
    .user-menu .username { display: none; }
    .mobile-menu-btn { display: flex; }

    .top-bar .logo {
        font-size: 0.8rem;
        letter-spacing: 1.5px;
    }

    .top-bar-right {
        gap: 0.5rem;
    }

    .search-bar input {
        width: 120px;
        padding: 0.35rem 0.6rem 0.35rem 1.6rem;
        font-size: 0.7rem;
    }

    .search-results {
        position: fixed;
        top: 52px;
        left: 0.5rem;
        right: 0.5rem;
        width: auto;
        max-height: 50vh;
    }

    .search-result-item { padding: 0.75rem; min-height: 44px; }

    /* ── Mobile Account Bar ──────────────── */
    .mobile-account-bar {
        display: flex;
        align-items: center;
        justify-content: space-around;
        background: var(--bg-secondary);
        border-bottom: 1px solid var(--border);
        padding: 0.5rem 0.75rem;
        flex-shrink: 0;
    }

    .mob-stat { text-align: center; flex: 1; }

    .mob-stat-val {
        display: block;
        font-size: 0.8rem;
        font-weight: 700;
        font-variant-numeric: tabular-nums;
        color: var(--text-primary);
        line-height: 1.2;
    }

    .mob-stat-lbl {
        display: block;
        font-size: 0.55rem;
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    /* ── Mobile Overlay + Drawer ─────────── */
    .mobile-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.6);
        z-index: 500;
        -webkit-backdrop-filter: blur(2px);
        backdrop-filter: blur(2px);
    }

    .mobile-overlay.open { display: block; }

    .mobile-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0;
        left: 0;
        width: 280px;
        height: 100%;
        background: var(--bg-secondary);
        border-right: 1px solid var(--border);
        z-index: 550;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .mobile-drawer.open { transform: translateX(0); }

    .mobile-drawer-header {
        padding: 1.25rem 1rem;
        background: var(--bg-panel);
        border-bottom: 1px solid var(--border);
    }

    .mobile-drawer-user {
        display: flex;
        align-items: center;
        gap: 0.6rem;
        margin-bottom: 0.5rem;
    }

    .mob-username {
        font-size: 1rem;
        font-weight: 700;
        color: var(--text-primary);
    }

    .mob-league {
        font-size: 0.7rem;
        color: var(--accent);
        margin-bottom: 0.5rem;
        letter-spacing: 1px;
        text-transform: uppercase;
    }

    .mob-xp-bar {
        height: 4px;
        background: var(--bg-input);
        border-radius: 2px;
        overflow: hidden;
    }

    .mob-xp-fill {
        height: 100%;
        background: linear-gradient(90deg, var(--blue-dim), var(--accent));
        border-radius: 2px;
        transition: width 0.3s;
    }

    .mobile-drawer-nav { padding: 0.5rem 0; flex: 1; }

    .mob-nav-item {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding: 0.85rem 1.25rem;
        color: var(--text-secondary);
        font-size: 0.9rem;
        font-weight: 500;
        cursor: pointer;
        transition: all 0.15s;
        min-height: 48px;
        text-decoration: none;
    }

    .mob-nav-item:hover, .mob-nav-item:active { background: var(--bg-hover); color: var(--text-primary); }
    .mob-nav-item.active { color: var(--accent); background: rgba(64,196,255,0.05); }
    .mob-nav-item .icon { font-size: 1.2rem; width: 1.5rem; text-align: center; }

    .mob-nav-divider { height: 1px; background: var(--border); margin: 0.4rem 1rem; }

    .mob-nav-logout { color: var(--red-dim); }
    .mob-nav-logout:hover { color: var(--red); }

    /* ── Hide Desktop Sidebar ────────────── */
    .sidebar { display: none !important; }

    /* ── Main Content Mobile ─────────────── */
    .main-content {
        padding: 0.75rem;
        padding-bottom: calc(0.75rem + 64px); /* Space for bottom nav */
    }

    /* ── Bottom Navigation ───────────────── */
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 60px;
        background: var(--bg-secondary);
        border-top: 1px solid var(--border);
        z-index: 400;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .bottom-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.2rem;
        cursor: pointer;
        color: var(--text-muted);
        text-decoration: none;
        transition: color 0.15s;
        -webkit-tap-highlight-color: transparent;
        position: relative;
    }

    .bottom-nav-item::before {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%) scaleX(0);
        width: 32px;
        height: 2px;
        background: var(--accent);
        border-radius: 1px;
        transition: transform 0.2s;
    }

    .bottom-nav-item.active { color: var(--accent); }
    .bottom-nav-item.active::before { transform: translateX(-50%) scaleX(1); }

    .bottom-nav-icon { font-size: 1.2rem; line-height: 1; }
    .bottom-nav-label { font-size: 0.55rem; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }

    /* ── Grid Overrides ──────────────────── */
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }

    /* Mobile stat cards in 2-column for compact views */
    .grid-4 { grid-template-columns: 1fr 1fr; gap: 0.5rem; }

    .stat-card {
        padding: 0.6rem;
    }

    .stat-card .label { font-size: 0.6rem; }
    .stat-card .value { font-size: 1rem; }
    .stat-card .change { font-size: 0.7rem; }

    /* ── Sector Heatmap Mobile ────────────── */
    .sector-heatmap { grid-template-columns: 1fr 1fr; gap: 0.4rem; }

    .sector-tile {
        padding: 0.5rem 0.4rem;
    }

    .sector-tile .sector-name { font-size: 0.6rem; }
    .sector-tile .sector-change { font-size: 0.85rem; }

    /* ── Panels Mobile ───────────────────── */
    .panel { border-radius: var(--radius); margin-bottom: 0.75rem; }
    .panel-header { padding: 0.6rem 0.75rem; }
    .panel-body { padding: 0.75rem; }
    .panel-title { font-size: 0.7rem; }

    /* ── Tables Mobile ───────────────────── */
    .data-table { font-size: 0.75rem; }
    .data-table thead th { padding: 0.4rem 0.5rem; font-size: 0.6rem; }
    .data-table td { padding: 0.5rem; }

    /* Horizontal scroll wrapper for wide tables */
    .table-scroll {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -0.75rem;
        padding: 0 0.75rem;
    }

    .table-scroll .data-table { min-width: 600px; }

    /* ── Trade Panel Mobile ──────────────── */
    .trade-panel { padding: 0.75rem; }
    .trade-tabs button { padding: 0.7rem; font-size: 0.75rem; min-height: 44px; }

    /* ── Asset Detail Mobile ─────────────── */
    .chart-container { height: 220px; }
    #tv-chart-container { height: 280px !important; }

    /* ── News Mobile ─────────────────────── */
    .news-item { padding: 0.7rem 0.75rem; }
    .news-item .news-headline { font-size: 0.82rem; line-height: 1.45; }
    .news-item .news-meta { flex-wrap: wrap; gap: 0.3rem; font-size: 0.6rem; }

    /* ── Mission Cards Mobile ────────────── */
    .mission-card { padding: 0.65rem; }
    .mission-card .mission-title { font-size: 0.8rem; }
    .mission-card .mission-footer { flex-wrap: wrap; gap: 0.4rem; }

    /* ── Achievements Mobile ─────────────── */
    .achievement-grid { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
    .achievement-badge { padding: 0.6rem 0.4rem; }
    .achievement-badge .ach-icon { font-size: 1.3rem; }
    .achievement-badge .ach-title { font-size: 0.7rem; }
    .achievement-badge .ach-desc { font-size: 0.6rem; }

    /* ── Office Upgrades Mobile ───────────── */
    .upgrade-grid { grid-template-columns: 1fr; gap: 0.5rem; }
    .upgrade-card { padding: 0.75rem; display: flex; gap: 0.75rem; align-items: flex-start; }
    .upgrade-card .ug-icon { font-size: 1.8rem; flex-shrink: 0; }
    .upgrade-card .ug-name { font-size: 0.85rem; }

    /* ── Buttons Touch Targets ────────────── */
    .btn { min-height: 44px; padding: 0.7rem 1rem; }
    .btn-sm { min-height: 38px; padding: 0.5rem 0.8rem; }
    .btn-xs { min-height: 34px; padding: 0.35rem 0.6rem; }

    /* ── Inputs Touch Targets ────────────── */
    input[type="text"], input[type="email"], input[type="password"], input[type="number"], select {
        min-height: 44px;
        padding: 0.7rem 0.9rem;
        font-size: 1rem; /* Prevents iOS zoom */
    }

    /* ── Auth Screen Mobile ──────────────── */
    .auth-container { padding: 1.25rem; }
    .auth-logo h1 { font-size: 1.5rem; letter-spacing: 3px; }
    .auth-logo .subtitle { font-size: 0.65rem; }
    .auth-box { padding: 1.25rem; }

    /* ── Toasts Mobile ───────────────────── */
    #toast-container {
        top: auto;
        bottom: 70px;
        right: 0.5rem;
        left: 0.5rem;
    }

    .toast {
        min-width: auto;
        max-width: none;
        font-size: 0.75rem;
    }

    /* ── Ticker Strip Mobile ─────────────── */
    .ticker-strip { height: 24px; font-size: 0.65rem; }

    /* ── Filter Buttons Scroll Mobile ────── */
    .filter-scroll {
        display: flex;
        overflow-x: auto;
        gap: 0.4rem;
        padding-bottom: 0.5rem;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .filter-scroll::-webkit-scrollbar { display: none; }
    .filter-scroll .btn { white-space: nowrap; flex-shrink: 0; }

    /* ── Misc Mobile Tweaks ──────────────── */
    .flex-between {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .empty-state { padding: 2rem 1rem; }
    .empty-state .empty-icon { font-size: 2rem; }

    /* Trade summary compact */
    .trade-summary { padding: 0.6rem; font-size: 0.75rem; }

    /* Leaderboard compact */
    .lb-rank { font-size: 0.85rem; width: 1.8rem; }

    /* XP bar bigger on mobile */
    .xp-bar { height: 8px; }

    /* Pull-to-refresh indicator placeholder */
    .ptr-indicator {
        text-align: center;
        padding: 1rem;
        color: var(--text-muted);
        font-size: 0.75rem;
        display: none;
    }
}

/* SMALL MOBILE: <=420px */
@media (max-width: 420px) {
    html { font-size: 12px; }

    .top-bar .logo { font-size: 0.75rem; letter-spacing: 1px; }

    .search-bar input { width: 90px; }

    .mobile-account-bar { padding: 0.4rem 0.5rem; }
    .mob-stat-val { font-size: 0.72rem; }

    .grid-4 { grid-template-columns: 1fr 1fr; gap: 0.4rem; }

    .stat-card .value { font-size: 0.9rem; }

    .chart-container { height: 180px; }

    .achievement-grid { grid-template-columns: 1fr 1fr; }

    .regime-badge { font-size: 0.6rem; padding: 0.15rem 0.4rem; }

    .user-menu .level-badge { font-size: 0.55rem; }
}

/* ── TICKER STRIP ────────────────────────────────────── */
.ticker-strip {
    display: flex;
    height: 28px;
    align-items: center;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    overflow: hidden;
    flex-shrink: 0;
    font-size: 0.7rem;
    font-variant-numeric: tabular-nums;
}

.ticker-strip-inner {
    display: flex;
    gap: 2rem;
    animation: tickerScroll 60s linear infinite;
    white-space: nowrap;
    padding: 0 1rem;
}

.ticker-strip-item {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.ticker-strip-item .ts-ticker { font-weight: 700; color: var(--text-secondary); }
.ticker-strip-item .ts-price { color: var(--text-primary); }

@keyframes tickerScroll {
    from { transform: translateX(0); }
    to { transform: translateX(-50%); }
}

/* ── EMPTY STATE ─────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 0.75rem; opacity: 0.4; }
.empty-state .empty-text { font-size: 0.85rem; margin-bottom: 0.5rem; }
.empty-state .empty-sub { font-size: 0.75rem; }

/* ── FLEX UTILS ──────────────────────────────────────── */
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-sm { gap: 0.5rem; }
.gap-md { gap: 1rem; }
.mt-sm { margin-top: 0.5rem; }
.mt-md { margin-top: 1rem; }
.mb-sm { margin-bottom: 0.5rem; }
.mb-md { margin-bottom: 1rem; }
.w-full { width: 100%; }

/* Mobile-responsive column hiding */
.hide-mobile, .hide-small { /* visible by default */ }
@media (max-width: 768px) { .hide-mobile { display: none !important; } }
@media (max-width: 520px) { .hide-small { display: none !important; } }

/* ── ASSET HEADER ─────────────────────────────────────── */
.asset-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
}
.asset-header-price { text-align: right; flex-shrink: 0; }

@media (max-width: 520px) {
    .asset-header { flex-direction: column; gap: 0.5rem; }
    .asset-header-price { text-align: left; }
    .asset-header-price div:first-child { font-size: 1.5rem !important; }
}

/* ── LEADERBOARD ─────────────────────────────────────── */
.lb-rank {
    font-size: 1rem;
    font-weight: 700;
    width: 2rem;
    text-align: center;
}
.lb-rank-1 { color: #ffd700; }
.lb-rank-2 { color: #c0c0c0; }
.lb-rank-3 { color: #cd7f32; }
