<?php
$brokers_data = [
    ['name' => 'ALL',              'long' => 51.06, 'short' => 48.94],
    ['name' => 'Exness',           'long' => 50.57, 'short' => 49.43],
    ['name' => 'Robo',              'long' => 34.49, 'short' => 65.51],
    ['name' => 'XM',               'long' => 54.29, 'short' => 45.71],
    ['name' => 'IC',                'long' => 35.76, 'short' => 64.24],
    ['name' => 'D',                  'long' => 67.04, 'short' => 32.96],
    ['name' => 'EC',                 'long' => 33.90, 'short' => 66.10],
    ['name' => 'vantage',          'long' => 50.87, 'short' => 49.13],
    ['name' => 'TMGM',             'long' => 32.41, 'short' => 67.59],
    ['name' => 'LIRUNEX',          'long' => 85.46, 'short' => 14.54],
    ['name' => 'FBS',              'long' => 63.18, 'short' => 36.82],
];
include __DIR__ . '/../includes/header.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>User Long / Short Positions</title>

    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link href="https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,500;0,700;1,500&family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css" rel="stylesheet">

    <style>
        *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

        :root {
            --ivory:       #FAFAF7;
            --white:       #FFFFFF;
            --navy:        #0F1628;
            --gold:        #B8890A;
            --gold-light:  #F5EDD3;
            --gold-ring:   #D4A82A;
            --muted:       #7D8799;
            --border:      #EDE9DF;
            --border-soft: #F4F1EB;
            --long-fill:   #C94848;
            --long-bg:     #FDF0F0;
            --long-text:   #7A1C1C;
            --short-fill:  #0F7A5A;
            --short-bg:    #EDFAF4;
            --short-text:  #065038;
            --sans:        'Plus Jakarta Sans', sans-serif;
            --serif:       'Playfair Display', Georgia, serif;
            --shadow-sm:   0 1px 3px rgba(15,22,40,.05), 0 1px 2px rgba(15,22,40,.04);
            --shadow-md:   0 4px 16px rgba(15,22,40,.07);
            --radius:      14px;
        }

        body {
            font-family: var(--sans);
            background: var(--ivory);
            color: var(--navy);
            padding: 0 0 80px;
        }

        /* ─── Page Hero ─── */
        .page-hero {
            background: var(--white);
            border-bottom: 1px solid var(--border);
            padding: 44px 40px 32px;
        }
        .hero-inner { max-width: 1100px; margin: 0 auto; }

        .breadcrumb {
            font-size: 11px; font-weight: 700; letter-spacing: .7px;
            text-transform: uppercase; color: var(--muted);
            margin-bottom: 16px; display: flex; align-items: center; gap: 8px;
        }
        .breadcrumb a { color: var(--muted); text-decoration: none; }
        .breadcrumb a:hover { color: var(--navy); }
        .breadcrumb i { font-size: 8px; }

        .hero-title {
            font-family: var(--serif);
            font-size: clamp(24px, 3vw, 36px);
            font-weight: 700; line-height: 1.2; margin-bottom: 6px;
        }
        .hero-title em { font-style: italic; color: var(--gold); }
        .hero-sub { font-size: 13px; color: var(--muted); font-weight: 500; }

        /* ─── Summary pills ─── */
        .summary-row {
            display: flex; gap: 12px; margin-top: 28px; flex-wrap: wrap;
        }
        .summary-pill {
            display: flex; align-items: center; gap: 10px;
            background: var(--ivory); border: 1px solid var(--border);
            border-radius: 40px; padding: 8px 18px 8px 10px;
        }
        .pill-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
        .dot-long  { background: var(--long-fill); }
        .dot-short { background: var(--short-fill); }
        .pill-label { font-size: 11px; font-weight: 600; letter-spacing: .4px; color: var(--muted); text-transform: uppercase; }
        .pill-value { font-family: var(--serif); font-size: 17px; font-weight: 700; color: var(--navy); margin-left: 4px; }

        /* ─── Content ─── */
        .content-wrap { max-width: 1100px; margin: 0 auto; padding: 36px 40px 0; }

        /* ─── Toolbar ─── */
        .toolbar {
            display: flex; align-items: center;
            justify-content: space-between; flex-wrap: wrap; gap: 14px;
            margin-bottom: 28px;
        }
        .section-label {
            font-size: 11px; font-weight: 700; letter-spacing: .8px;
            text-transform: uppercase; color: var(--muted);
            display: flex; align-items: center; gap: 10px;
        }
        .section-label::after {
            content: ''; width: 40px; height: 1px; background: var(--border);
        }

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

        .currency-wrap { position: relative; }
        .currency-select {
            font-family: var(--sans); font-size: 13px; font-weight: 700;
            color: var(--navy); background: var(--white);
            border: 1px solid var(--border); border-radius: 9px;
            padding: 9px 36px 9px 14px; cursor: pointer; outline: none;
            appearance: none;
            background-image: url('data:image/svg+xml;charset=US-ASCII,<svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="%237D8799" stroke-width="2.5"><path d="M6 9l6 6 6-6"/></svg>');
            background-repeat: no-repeat;
            background-position: right 12px center;
            transition: border-color .2s;
        }
        .currency-select:hover { border-color: var(--gold-ring); }
        .currency-select:focus { border-color: var(--gold-ring); }

        .legend-row {
            display: flex; gap: 16px; align-items: center;
        }
        .leg-item { display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600; color: var(--muted); }
        .leg-swatch { width: 18px; height: 6px; border-radius: 3px; }
        .sw-long  { background: var(--long-fill); }
        .sw-short { background: var(--short-fill); }

        /* ─── Panel ─── */
        .panel {
            background: var(--white); border: 1px solid var(--border);
            border-radius: var(--radius); box-shadow: var(--shadow-sm);
            overflow: hidden;
        }

        /* ─── Data Row ─── */
        .data-row {
            display: flex; align-items: center; gap: 20px;
            padding: 16px 24px; border-bottom: 1px solid var(--border-soft);
            transition: background .18s;
            position: relative;
        }
        .data-row:last-child { border-bottom: none; }
        .data-row:hover { background: var(--ivory); }

        /* "ALL" row styled as summary */
        .data-row.is-all {
            background: #FAFAF2;
            border-bottom: 2px solid var(--border);
        }
        .data-row.is-all .broker-name {
            font-family: var(--serif); font-size: 15px; font-weight: 700;
        }
        .data-row.is-all .broker-avatar {
            background: var(--gold-light); color: var(--gold);
            border-color: var(--gold-ring);
        }

        /* Broker column */
        .broker-info {
            display: flex; align-items: center; gap: 12px;
            width: 195px; flex-shrink: 0;
        }
        .broker-avatar {
            width: 34px; height: 34px; border-radius: 8px;
            border: 1px solid var(--border);
            background: var(--ivory);
            display: flex; align-items: center; justify-content: center;
            font-size: 11px; font-weight: 800; color: var(--navy);
            overflow: hidden; flex-shrink: 0;
        }
        .broker-avatar img {
            width: 100%; height: 100%; object-fit: contain;
        }
        .broker-name { font-size: 13px; font-weight: 700; color: var(--navy); }

        /* Bar track */
        .bar-track {
            flex: 1; display: flex; height: 26px; border-radius: 6px;
            overflow: hidden; gap: 2px;
        }

        .bar-long, .bar-short {
            height: 100%; display: flex; align-items: center;
            font-size: 11px; font-weight: 700; color: #fff;
            transition: width 1s cubic-bezier(.16,1,.3,1);
        }
        .bar-long {
            background: var(--long-fill);
            justify-content: flex-start; padding-left: 9px;
            border-radius: 5px 0 0 5px;
        }
        .bar-short {
            background: var(--short-fill);
            justify-content: flex-end; padding-right: 9px;
            border-radius: 0 5px 5px 0;
        }

        /* Percentage labels outside bar */
        .pct-labels {
            display: flex; flex-direction: column;
            gap: 2px; min-width: 52px; flex-shrink: 0;
        }
        .pct-long {
            font-size: 11px; font-weight: 700;
            color: var(--long-fill);
        }
        .pct-short {
            font-size: 11px; font-weight: 700;
            color: var(--short-fill);
        }

        /* Sentiment tag */
        .sentiment-tag {
            min-width: 60px; flex-shrink: 0; text-align: right;
        }
        .tag {
            display: inline-flex; align-items: center; gap: 4px;
            font-size: 10px; font-weight: 800; letter-spacing: .5px;
            text-transform: uppercase; padding: 3px 9px; border-radius: 4px;
        }
        .tag-bull { background: var(--short-bg); color: var(--short-text); }
        .tag-bear { background: var(--long-bg);  color: var(--long-text);  }
        .tag-neut { background: var(--ivory); color: var(--muted); border: 1px solid var(--border); }

        /* ─── Footer note ─── */
        .footer-note {
            text-align: right; margin-top: 32px;
            font-size: 11px; color: var(--muted); font-weight: 500;
            display: flex; align-items: center; justify-content: flex-end; gap: 6px;
        }
        .footer-note i { color: #3b82f6; font-size: 12px; }

        /* ─── Responsive ─── */
        @media (max-width: 768px) {
            .page-hero, .content-wrap { padding-left: 20px; padding-right: 20px; }
            .data-row { flex-wrap: wrap; gap: 10px; }
            .broker-info { width: 100%; }
            .pct-labels, .sentiment-tag { display: none; }
            .bar-track { width: 100%; }
        }
    </style>
</head>
<body>

<!-- ═══ HERO ═══ -->
<div class="page-hero">
    <div class="hero-inner">
        <div class="breadcrumb">
            <a href="<?php echo $base_url; ?>/index.php">Home</a><i class="fas fa-chevron-right"></i>
            <a href="<?php echo $base_url; ?>/index.php">VPS</a><i class="fas fa-chevron-right"></i>
            <span>Long / Short Positions</span>
        </div>
        <h1 class="hero-title">User <em>Long / Short</em> Positions</h1>
        <p class="hero-sub">Live aggregated sentiment across all connected brokers — updated in real-time.</p>

        <?php
            // Pull ALL row for hero summary
            $all = $brokers_data[0];
        ?>
        <div class="summary-row">
            <div class="summary-pill">
                <div class="pill-dot dot-long"></div>
                <span class="pill-label">Long</span>
                <span class="pill-value"><?= number_format($all['long'], 2) ?>%</span>
            </div>
            <div class="summary-pill">
                <div class="pill-dot dot-short"></div>
                <span class="pill-label">Short</span>
                <span class="pill-value"><?= number_format($all['short'], 2) ?>%</span>
            </div>
            <div class="summary-pill" style="background:var(--gold-light);border-color:var(--gold-ring);">
                <div class="pill-dot" style="background:var(--gold);"></div>
                <span class="pill-label" style="color:var(--gold);">Brokers Tracked</span>
                <span class="pill-value" style="color:var(--gold);"><?= count($brokers_data) - 1 ?></span>
            </div>
        </div>
    </div>
</div>

<!-- ═══ CONTENT ═══ -->
<div class="content-wrap">

    <!-- Toolbar -->
    <div class="toolbar">
        <div class="section-label">Live Sentiment by Broker</div>
        <div class="toolbar-right">
            <div class="legend-row">
                <div class="leg-item">
                    <div class="leg-swatch sw-long"></div> Long
                </div>
                <div class="leg-item">
                    <div class="leg-swatch sw-short"></div> Short
                </div>
            </div>
            <div class="currency-wrap">
                <select class="currency-select" id="currencySelect">
                    <option>EUR/USD</option>
                    <option>GBP/USD</option>
                    <option>USD/JPY</option>
                    <option>AUD/USD</option>
                    <option>NZD/USD</option>
                    <option>USD/CAD</option>
                    <option>USD/CHF</option>
                    <option>XAU/USD</option>
                </select>
            </div>
        </div>
    </div>

    <!-- Panel -->
    <div class="panel">
        <?php foreach ($brokers_data as $i => $broker):
            $isAll   = ($broker['name'] === 'ALL');
            $long    = $broker['long'];
            $short   = $broker['short'];
            $initials = strtoupper(substr($broker['name'], 0, 2));
            $clean   = strtolower(str_replace(' ', '_', $broker['name']));
            $imgPath = '../assets/images/ea/' . ($isAll ? 'all' : $clean) . '.png';

            // Sentiment tag
            $diff = $long - $short;
            if ($diff > 10)       { $tagClass = 'tag-bear'; $tagIcon = 'fa-arrow-trend-up';   $tagLabel = 'Bullish'; }
            elseif ($diff < -10)  { $tagClass = 'tag-bull'; $tagIcon = 'fa-arrow-trend-down'; $tagLabel = 'Bearish'; }
            else                  { $tagClass = 'tag-neut'; $tagIcon = 'fa-minus';             $tagLabel = 'Neutral'; }
        ?>
        <div class="data-row <?= $isAll ? 'is-all' : '' ?>">

            <!-- Avatar / Logo -->
            <div class="broker-info">
                <div class="broker-avatar">
                    <img src="<?= htmlspecialchars($imgPath) ?>"
                         alt="<?= htmlspecialchars($broker['name']) ?>"
                         onerror="this.parentNode.innerHTML='<?= htmlspecialchars($initials) ?>'">
                </div>
                <span class="broker-name"><?= htmlspecialchars($broker['name']) ?></span>
            </div>

            <!-- Dual bar -->
            <div class="bar-track">
                <div class="bar-long"  style="width:0%" data-target="<?= $long ?>">
                    <?= $long >= 12 ? number_format($long, 1).'%' : '' ?>
                </div>
                <div class="bar-short" style="width:0%" data-target="<?= $short ?>">
                    <?= $short >= 12 ? number_format($short, 1).'%' : '' ?>
                </div>
            </div>

            <!-- Pct labels -->
            <div class="pct-labels">
                <span class="pct-long"><?= number_format($long, 2) ?>%</span>
                <span class="pct-short"><?= number_format($short, 2) ?>%</span>
            </div>

            <!-- Sentiment -->
            <div class="sentiment-tag">
                <span class="tag <?= $tagClass ?>">
                    <i class="fas <?= $tagIcon ?>" style="font-size:9px;"></i>
                    <?= $tagLabel ?>
                </span>
            </div>

        </div>
        <?php endforeach; ?>
    </div>

    <!-- Footer note -->
    <div class="footer-note">
        <i class="fas fa-shield-alt"></i>
        Data provided by <strong>BrokerPortal Data</strong> &nbsp;&mdash;&nbsp; 2026-05-04 15:29:41
    </div>

</div>

<script>
(function(){
    const animate = () => {
        document.querySelectorAll('[data-target]').forEach(el => {
            const target = parseFloat(el.dataset.target);
            const start = performance.now();
            const dur = 900 + Math.random() * 300;
            const tick = now => {
                const p = Math.min((now - start) / dur, 1);
                const e = 1 - Math.pow(1 - p, 3);
                el.style.width = (target * e).toFixed(2) + '%';
                if (p < 1) requestAnimationFrame(tick);
            };
            requestAnimationFrame(tick);
        });
    };

    const io = new IntersectionObserver(entries => {
        entries.forEach(e => { if (e.isIntersecting) { animate(); io.disconnect(); } });
    }, { threshold: 0.1 });
    io.observe(document.querySelector('.panel'));
})();
</script>

<?php include __DIR__ . '/../includes/footer.php'; ?>
