/* ==========================================
   MARKETS PAGE STYLES
   Prediction market — Polymarket/Kalshi aesthetic
   Uses :root vars from forecast-styles.css
   ========================================== */

/* ---- Base ---- */

:root {
    --bg: #0a0a0a;
    --bg-elevated: #111111;
    --bg-card: #141414;
    --primary: #00ff88;
    --primary-dim: rgba(0, 255, 136, 0.1);
    --secondary: #ff3d71;
    --secondary-dim: rgba(255, 61, 113, 0.1);
    --text: #ffffff;
    --text-secondary: #e0e0e0;
    --text-tertiary: #b8b8b8;
    --border: #1a1a1a;
    --border-bright: #222222;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ---- Page Layout ---- */

.markets-page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* ---- Hero ---- */

.markets-hero {
    text-align: center;
    padding: 4rem 0 2rem;
}

.markets-hero .hero-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.85rem;
    border-radius: 100px;
    background: var(--fc-surface-2);
    border: 1px solid var(--fc-border-bright);
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--fc-gold);
    text-transform: lowercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.75rem;
}

.markets-hero .hero-badge .dot {
    width: 6px;
    height: 6px;
    background: var(--fc-gold);
    border-radius: 50%;
    animation: pulse 2.5s ease-in-out infinite;
}

.markets-hero h1 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 3.5rem;
    font-weight: 900;
    text-transform: lowercase;
    margin: 0.75rem 0 0.5rem;
    letter-spacing: -0.03em;
    line-height: 1;
}

.markets-hero .hero-sub {
    font-size: 1.125rem;
    color: var(--fc-text-dim);
    max-width: 600px;
    margin: 0 auto 1.5rem;
    line-height: 1.5;
}

/* Hero stats row */
.markets-hero-stats {
    display: flex;
    justify-content: center;
    gap: 2.5rem;
    margin-top: 1.5rem;
}

.mh-stat {
    text-align: center;
}

.mh-stat-value {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.75rem;
    font-weight: 900;
    color: var(--fc-text);
    font-variant-numeric: tabular-nums;
}

.mh-stat-value.credits {
    color: var(--fc-gold);
}

.mh-stat-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--fc-text-muted);
    text-transform: lowercase;
    margin-top: 0.15rem;
}

/* ---- Category Tabs ---- */

.markets-categories {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: center;
    padding: 1.5rem 0 2rem;
    border-bottom: 1px solid var(--fc-border);
    margin-bottom: 2rem;
}

.market-cat-tab {
    padding: 0.45rem 1rem;
    border-radius: 100px;
    border: 1px solid var(--fc-border-bright);
    background: transparent;
    color: var(--fc-text-dim);
    font-size: 0.8rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: lowercase;
}

.market-cat-tab:hover {
    border-color: var(--fc-gold);
    color: var(--fc-text);
    background: rgba(255, 202, 40, 0.05);
}

.market-cat-tab.active {
    background: var(--fc-gold);
    border-color: var(--fc-gold);
    color: #000;
    font-weight: 700;
}

.market-cat-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.1);
    padding: 0.1rem 0.4rem;
    border-radius: 100px;
    font-size: 0.65rem;
    font-weight: 700;
    margin-left: 0.25rem;
    min-width: 1rem;
}

.market-cat-tab.active .market-cat-count {
    background: rgba(0,0,0,0.2);
    color: #000;
}

/* ---- Featured Section ---- */

.markets-featured-section {
    margin-bottom: 2.5rem;
}

.markets-section-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--fc-text-muted);
    text-transform: lowercase;
    letter-spacing: 0.08em;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.markets-section-title .icon {
    font-size: 1rem;
}

/* ---- Market Cards Grid ---- */

.markets-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 3rem;
}

/* ---- Market Card ---- */

.market-card {
    background: var(--fc-surface);
    border: 1px solid var(--fc-border);
    border-radius: 0.875rem;
    padding: 1.25rem;
    cursor: pointer;
    transition: all 0.25s;
    display: flex;
    flex-direction: column;
    position: relative;
}

.market-card:hover {
    border-color: var(--fc-border-bright);
    background: var(--fc-surface-2);
    transform: translateY(-2px);
}

.market-card.expanded {
    border-color: var(--fc-gold);
    background: var(--fc-surface-2);
}

.market-card-top {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.market-card-emoji {
    font-size: 1.75rem;
    line-height: 1;
    flex-shrink: 0;
}

.market-card-question {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--fc-text);
    line-height: 1.35;
    flex: 1;
}

/* Price row */
.market-card-prices {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.market-price-yes {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.75rem;
    font-weight: 900;
    color: var(--fc-green);
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.market-price-label {
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--fc-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.market-price-no {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1rem;
    font-weight: 800;
    color: var(--fc-red);
    font-variant-numeric: tabular-nums;
    opacity: 0.7;
}

/* Sparkline canvas */
.market-card-sparkline {
    width: 100%;
    height: 32px;
    margin-bottom: 0.75rem;
}

.market-card-sparkline canvas {
    width: 100%;
    height: 100%;
}

/* Card footer */
.market-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: auto;
}

.market-card-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.55rem;
    border-radius: 100px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: lowercase;
    background: var(--fc-surface-3);
    border: 1px solid var(--fc-border);
    color: var(--fc-text-dim);
}

.market-card-volume {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--fc-text-muted);
    font-variant-numeric: tabular-nums;
}

.market-card-resolve {
    font-size: 0.6rem;
    color: var(--fc-text-muted);
}

/* ---- Market Detail Panel (inline expansion) ---- */

.market-detail {
    display: none;
    padding-top: 1rem;
    border-top: 1px solid var(--fc-border);
    margin-top: 1rem;
}

.market-card.expanded .market-detail {
    display: block;
}

/* Description */
.market-detail-desc {
    font-size: 0.82rem;
    color: var(--fc-text-dim);
    line-height: 1.55;
    margin-bottom: 1.25rem;
}

/* Price chart */
.market-detail-chart {
    width: 100%;
    height: 120px;
    margin-bottom: 1.25rem;
    background: var(--fc-surface);
    border-radius: 0.5rem;
    border: 1px solid var(--fc-border);
    overflow: hidden;
}

.market-detail-chart canvas {
    width: 100%;
    height: 100%;
}

/* Trade interface */
.market-trade-panel {
    background: var(--fc-surface);
    border: 1px solid var(--fc-border-bright);
    border-radius: 0.75rem;
    padding: 1rem;
    margin-bottom: 1rem;
}

.trade-side-btns {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.trade-side-btn {
    flex: 1;
    padding: 0.65rem;
    border-radius: 0.5rem;
    border: 2px solid var(--fc-border-bright);
    background: transparent;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.9rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
}

.trade-side-btn.yes {
    color: var(--fc-green);
}

.trade-side-btn.yes:hover,
.trade-side-btn.yes.active {
    background: rgba(0, 230, 118, 0.1);
    border-color: var(--fc-green);
}

.trade-side-btn.no {
    color: var(--fc-red);
}

.trade-side-btn.no:hover,
.trade-side-btn.no.active {
    background: rgba(255, 61, 113, 0.1);
    border-color: var(--fc-red);
}

/* Amount slider */
.trade-amount-section {
    margin-bottom: 0.75rem;
}

.trade-amount-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--fc-text-dim);
    margin-bottom: 0.35rem;
}

.trade-amount-value {
    color: var(--fc-gold);
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 800;
}

.trade-amount-slider {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: var(--fc-surface-3);
    border-radius: 2px;
    outline: none;
    margin-bottom: 0.35rem;
}

.trade-amount-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--fc-gold);
    cursor: pointer;
    border: 2px solid var(--fc-bg);
}

.trade-amount-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--fc-gold);
    cursor: pointer;
    border: 2px solid var(--fc-bg);
}

.trade-quick-amounts {
    display: flex;
    gap: 0.35rem;
}

.trade-quick-btn {
    padding: 0.25rem 0.5rem;
    border-radius: 0.35rem;
    border: 1px solid var(--fc-border-bright);
    background: transparent;
    color: var(--fc-text-dim);
    font-size: 0.65rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}

.trade-quick-btn:hover {
    border-color: var(--fc-gold);
    color: var(--fc-gold);
}

/* Preview */
.trade-preview {
    display: flex;
    justify-content: space-between;
    padding: 0.65rem 0;
    border-top: 1px solid var(--fc-border);
    margin-bottom: 0.75rem;
}

.trade-preview-item {
    text-align: center;
}

.trade-preview-label {
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--fc-text-muted);
    text-transform: lowercase;
}

.trade-preview-value {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--fc-text);
    font-variant-numeric: tabular-nums;
}

/* Confirm button */
.trade-confirm-btn {
    width: 100%;
    padding: 0.75rem;
    border-radius: 0.625rem;
    border: none;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.95rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: lowercase;
}

.trade-confirm-btn.buy-yes {
    background: var(--fc-green);
    color: #000;
}

.trade-confirm-btn.buy-yes:hover {
    background: #00dd77;
    transform: translateY(-1px);
}

.trade-confirm-btn.buy-no {
    background: var(--fc-red);
    color: #fff;
}

.trade-confirm-btn.buy-no:hover {
    background: #ff2255;
    transform: translateY(-1px);
}

.trade-confirm-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* Resolution info */
.market-resolution-info {
    padding: 0.75rem;
    background: var(--fc-surface-3);
    border-radius: 0.5rem;
    border: 1px solid var(--fc-border);
}

.resolution-title {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--fc-text-muted);
    text-transform: lowercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.35rem;
}

.resolution-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    padding: 0.2rem 0;
}

.resolution-label {
    color: var(--fc-text-muted);
}

.resolution-value {
    color: var(--fc-text-dim);
    font-weight: 600;
}

.resolution-value a {
    color: var(--fc-gold);
    text-decoration: none;
}

.resolution-value a:hover {
    text-decoration: underline;
}

/* ---- Portfolio Section ---- */

.markets-portfolio-section {
    margin-bottom: 3rem;
    padding: 1.5rem;
    background: var(--fc-surface);
    border: 1px solid var(--fc-border);
    border-radius: 1rem;
}

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

.portfolio-title {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.25rem;
    font-weight: 900;
    text-transform: lowercase;
}

.portfolio-net-worth {
    text-align: right;
}

.portfolio-nw-label {
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--fc-text-muted);
    text-transform: lowercase;
}

.portfolio-nw-value {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.5rem;
    font-weight: 900;
    color: var(--fc-gold);
    font-variant-numeric: tabular-nums;
}

.portfolio-stats {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1.25rem;
}

.portfolio-stat {
    text-align: center;
    flex: 1;
    padding: 0.75rem;
    background: var(--fc-surface-2);
    border-radius: 0.5rem;
    border: 1px solid var(--fc-border);
}

.portfolio-stat-value {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.1rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.portfolio-stat-value.positive { color: var(--fc-green); }
.portfolio-stat-value.negative { color: var(--fc-red); }
.portfolio-stat-value.neutral { color: var(--fc-text); }
.portfolio-stat-value.gold { color: var(--fc-gold); }

.portfolio-stat-label {
    font-size: 0.62rem;
    font-weight: 600;
    color: var(--fc-text-muted);
    text-transform: lowercase;
    margin-top: 0.15rem;
}

/* Position cards */
.portfolio-positions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.position-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: var(--fc-surface-2);
    border: 1px solid var(--fc-border);
    border-radius: 0.625rem;
    cursor: pointer;
    transition: all 0.2s;
}

.position-card:hover {
    border-color: var(--fc-border-bright);
}

.position-emoji {
    font-size: 1.25rem;
}

.position-info {
    flex: 1;
}

.position-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--fc-text);
    margin-bottom: 0.15rem;
}

.position-detail {
    font-size: 0.65rem;
    color: var(--fc-text-muted);
}

.position-side-yes { color: var(--fc-green); font-weight: 700; }
.position-side-no { color: var(--fc-red); font-weight: 700; }

.position-pnl {
    text-align: right;
}

.position-pnl-value {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.95rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.position-pnl-value.positive { color: var(--fc-green); }
.position-pnl-value.negative { color: var(--fc-red); }

.position-pnl-percent {
    font-size: 0.62rem;
    font-weight: 600;
    color: var(--fc-text-muted);
}

/* ---- Trade History ---- */

.markets-history-section {
    margin-bottom: 3rem;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: var(--fc-surface);
    border: 1px solid var(--fc-border);
    border-radius: 0.5rem;
    font-size: 0.75rem;
}

.history-side {
    padding: 0.15rem 0.4rem;
    border-radius: 0.25rem;
    font-weight: 800;
    font-size: 0.6rem;
    text-transform: uppercase;
    font-family: 'Space Grotesk', sans-serif;
}

.history-side.buy-yes { background: rgba(0,230,118,0.15); color: var(--fc-green); }
.history-side.buy-no { background: rgba(255,61,113,0.15); color: var(--fc-red); }
.history-side.sell-yes { background: rgba(0,230,118,0.08); color: var(--fc-green); border: 1px dashed rgba(0,230,118,0.3); }
.history-side.sell-no { background: rgba(255,61,113,0.08); color: var(--fc-red); border: 1px dashed rgba(255,61,113,0.3); }

.history-question {
    flex: 1;
    color: var(--fc-text-dim);
    font-weight: 500;
}

.history-cost {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--fc-text);
}

.history-time {
    color: var(--fc-text-muted);
    font-size: 0.62rem;
}

/* ---- Auth Prompt Modal ---- */

.auth-modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7);
    z-index: 10000;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.auth-modal-overlay.visible {
    display: flex;
}

.auth-modal {
    background: var(--fc-surface-2);
    border: 1px solid var(--fc-border-bright);
    border-radius: 1rem;
    padding: 2rem;
    max-width: 420px;
    width: 100%;
    text-align: center;
}

.auth-modal-emoji {
    font-size: 3rem;
    margin-bottom: 0.75rem;
}

.auth-modal h3 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.5rem;
    font-weight: 900;
    text-transform: lowercase;
    margin-bottom: 0.5rem;
}

.auth-modal p {
    font-size: 0.9rem;
    color: var(--fc-text-dim);
    line-height: 1.5;
    margin-bottom: 1.5rem;
}

.auth-modal-btn {
    width: 100%;
    padding: 0.85rem;
    border-radius: 0.625rem;
    border: none;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 0.5rem;
}

.auth-modal-btn.primary {
    background: var(--fc-gold);
    color: #000;
}

.auth-modal-btn.primary:hover {
    transform: translateY(-1px);
    filter: brightness(1.1);
}

.auth-modal-btn.secondary {
    background: transparent;
    border: 1px solid var(--fc-border-bright);
    color: var(--fc-text-dim);
}

.auth-modal-btn.secondary:hover {
    border-color: var(--fc-text-dim);
    color: var(--fc-text);
}

/* ---- Credit Badge (floating) ---- */

.credit-badge {
    position: fixed;
    top: 1rem;
    right: 1rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.85rem;
    background: var(--fc-surface-2);
    border: 1px solid rgba(255, 202, 40, 0.3);
    border-radius: 100px;
    z-index: 999;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.8rem;
    font-weight: 800;
    color: var(--fc-gold);
    font-variant-numeric: tabular-nums;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.credit-badge-icon {
    font-size: 0.9rem;
}

/* ---- Empty States ---- */

.markets-empty {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--fc-text-muted);
}

.markets-empty-emoji {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.markets-empty h3 {
    color: var(--fc-text-dim);
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.markets-empty p {
    font-size: 0.9rem;
}

/* ---- Responsive ---- */

@media (max-width: 1024px) {
    .markets-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .markets-page {
        padding: 0 1.25rem;
    }

    .markets-hero h1 {
        font-size: 2.5rem;
    }

    .markets-hero-stats {
        gap: 1.5rem;
    }

    .mh-stat-value {
        font-size: 1.35rem;
    }

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

    .markets-categories {
        justify-content: flex-start;
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 1.5rem;
        gap: 0.35rem;
    }

    .market-cat-tab {
        flex-shrink: 0;
    }

    .portfolio-stats {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .portfolio-stat {
        min-width: calc(50% - 0.25rem);
    }

    .credit-badge {
        top: auto;
        bottom: 1rem;
        right: 1rem;
    }

    .history-item {
        flex-wrap: wrap;
    }
}

@media (max-width: 480px) {
    .markets-hero h1 {
        font-size: 2rem;
    }

    .markets-hero-stats {
        flex-wrap: wrap;
        gap: 1rem;
    }

    .mh-stat {
        min-width: calc(50% - 0.5rem);
    }

    .trade-side-btns {
        gap: 0.35rem;
    }

    .market-card-prices {
        flex-wrap: wrap;
    }
}

/* ---- Animations ---- */

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

@keyframes marketFadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.market-card {
    animation: marketFadeIn 0.4s ease-out both;
}

/* Staggered delay via inline style */

/* Trade success flash */
@keyframes tradeFlash {
    0% { box-shadow: 0 0 0 0 rgba(255, 202, 40, 0.4); }
    50% { box-shadow: 0 0 20px 4px rgba(255, 202, 40, 0.2); }
    100% { box-shadow: none; }
}

.market-card.trade-success {
    animation: tradeFlash 0.6s ease-out;
}
