<?php
$ticker_news = [
    ['broker' => 'XM',   'time' => '2026-05-04 12:58:11', 'instrument' => 'GOLD#',  'price' => '4572.52', 'amount' => '0.05Lot', 'stop_out' => 'USD -43.45'],
    ['broker' => 'EC',   'time' => '2026-05-04 12:57:48', 'instrument' => 'XAUUSD', 'price' => '4576.14', 'amount' => '0.11Lot', 'stop_out' => 'USD -24.20'],
    ['broker' => 'Octa', 'time' => '2026-05-04 12:14:18', 'instrument' => 'XAUUSD', 'price' => '4582.53', 'amount' => '0.05Lot', 'stop_out' => 'USD -36.20'],
];

$liquidation_data = [
    ['instrument' => 'ALL',    'rate' => '2.60%', 'amount' => '6,488,366.64', 'vol_long' => 81, 'vol_short' => 19, 'lots' => '3,079.92', 'lot_long' => 78, 'lot_short' => 22, 'orders' => '13,049', 'ord_long' => 66, 'ord_short' => 34, 'trend' => 'up'],
    ['instrument' => 'XAUUSD', 'rate' => '2.76%', 'amount' => '6,254,329.22', 'vol_long' => 83, 'vol_short' => 17, 'lots' => '2,897.54', 'lot_long' => 77, 'lot_short' => 23, 'orders' => '12,329', 'ord_long' => 66, 'ord_short' => 34, 'trend' => 'down'],
    ['instrument' => 'GBPUSD', 'rate' => '1.37%', 'amount' => '123,351.30',  'vol_long' => 10, 'vol_short' => 90, 'lots' => '17.64',    'lot_long' =>  9, 'lot_short' => 91, 'orders' => '101',    'ord_long' => 18, 'ord_short' => 82, 'trend' => 'up'],
    ['instrument' => 'USDJPY', 'rate' => '4.15%', 'amount' => '62,365.12',   'vol_long' => 95, 'vol_short' =>  5, 'lots' => '75.86',    'lot_long' => 97, 'lot_short' =>  3, 'orders' => '401',    'ord_long' => 90, 'ord_short' => 10, 'trend' => 'up'],
    ['instrument' => 'GBPJPY', 'rate' => '1.39%', 'amount' => '46,586.96',   'vol_long' => 99, 'vol_short' =>  1, 'lots' => '88.40',    'lot_long' => 99, 'lot_short' =>  1, 'orders' => '73',     'ord_long' => 85, 'ord_short' => 15, 'trend' => 'down'],
    ['instrument' => 'EURUSD', 'rate' => '0.62%', 'amount' => '1,734.82',    'vol_long' => 12, 'vol_short' => 88, 'lots' => '10.20',    'lot_long' => 33, 'lot_short' => 67, 'orders' => '135',    'ord_long' => 36, 'ord_short' => 64, 'trend' => 'up'],
];

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>Liquidation Data</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;
            --lf:          #C94848;
            --lb:          #FDF0F0;
            --lt:          #7A1C1C;
            --sf:          #0F7A5A;
            --sb:          #EDFAF4;
            --st:          #065038;
            --green:       #0F7A5A;
            --blue:        #1D5FCC;
            --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; }

        /* ─── Hero ─── */
        .page-hero { background: var(--white); border-bottom: 1px solid var(--border); padding: 44px 40px 32px; }
        .hero-inner { max-width: 1360px; 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; }

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

        /* ─── Time Tabs ─── */
        .tabs-row { display: flex; gap: 4px; margin-bottom: 28px; background: var(--white); border: 1px solid var(--border); border-radius: 10px; padding: 4px; width: fit-content; }
        .tab-btn { background: none; border: none; font-family: var(--sans); font-size: 12px; font-weight: 700; color: var(--muted); padding: 8px 18px; border-radius: 7px; cursor: pointer; transition: all .2s; white-space: nowrap; }
        .tab-btn:hover { color: var(--navy); background: var(--ivory); }
        .tab-btn.active { background: var(--navy); color: #fff; }

        /* ─── Ticker ─── */
        .ticker-wrap {
            display: flex; align-items: center; height: 48px;
            background: var(--white); border: 1px solid var(--border);
            border-radius: 10px; overflow: hidden; margin-bottom: 28px;
            box-shadow: var(--shadow-sm);
        }
        .ticker-label {
            display: flex; align-items: center; gap: 8px;
            padding: 0 18px; height: 100%;
            background: var(--gold-light); border-right: 1px solid var(--gold-ring);
            font-size: 11px; font-weight: 800; letter-spacing: .5px;
            text-transform: uppercase; color: var(--gold); white-space: nowrap; flex-shrink: 0;
        }
        .ticker-label i { font-size: 13px; }
        .ticker-scroll { flex: 1; height: 48px; overflow: hidden; position: relative; }
        .ticker-list { list-style: none; animation: tickUp 14s linear infinite; }
        .ticker-list:hover { animation-play-state: paused; }
        .ticker-item { height: 48px; display: flex; align-items: center; gap: 24px; padding: 0 20px; font-size: 12px; }
        .ti-broker { display: flex; align-items: center; gap: 8px; font-weight: 700; min-width: 80px; flex-shrink: 0; }
        .ti-avatar { width: 24px; height: 24px; border-radius: 5px; border: 1px solid var(--border); background: var(--ivory); display: flex; align-items: center; justify-content: center; font-size: 8px; font-weight: 800; overflow: hidden; flex-shrink: 0; }
        .ti-avatar img { width: 100%; height: 100%; object-fit: contain; }
        .ti-sep { width: 1px; height: 20px; background: var(--border); flex-shrink: 0; }
        .ti-group { display: flex; gap: 5px; align-items: center; white-space: nowrap; }
        .ti-label { color: var(--muted); font-weight: 500; }
        .ti-val { font-weight: 700; color: var(--navy); }
        .ti-val.red { color: var(--lf); }
        @keyframes tickUp {
            0%,22%  { transform: translateY(0); }
            33%,55% { transform: translateY(-48px); }
            66%,88% { transform: translateY(-96px); }
            100%    { transform: translateY(0); }
        }

        /* ─── Table panel ─── */
        .table-panel { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; }
        .panel-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 24px; border-bottom: 1px solid var(--border); }
        .panel-title { font-size: 11px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 8px; }
        .panel-title::after { content: ''; width: 32px; height: 1px; background: var(--border); }
        .panel-legend { display: flex; gap: 14px; align-items: center; }
        .leg { display: flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; color: var(--muted); }
        .leg-dot { width: 8px; height: 8px; border-radius: 50%; }
        .ld-long { background: var(--lf); }
        .ld-short { background: var(--sf); }

        .table-scroll { overflow-x: auto; }
        table { width: 100%; border-collapse: collapse; min-width: 1100px; }
        thead tr { background: var(--ivory); }
        th { font-size: 11px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; color: var(--muted); padding: 14px 16px; text-align: center; border-bottom: 1px solid var(--border); white-space: nowrap; }
        th.left { text-align: left; }
        td { padding: 14px 16px; font-size: 13px; font-weight: 600; text-align: center; border-bottom: 1px solid var(--border-soft); vertical-align: middle; color: var(--navy); transition: background .15s; }
        td.left { text-align: left; }
        tr:last-child td { border-bottom: none; }
        tr.is-all { background: #FAFAF2; }
        tr.is-all td { border-bottom: 2px solid var(--border); }
        tbody tr:hover td { background: var(--ivory); }

        /* Instrument cell */
        .inst-cell { display: flex; align-items: center; gap: 10px; }
        .inst-icon { width: 30px; height: 30px; border-radius: 7px; background: var(--ivory); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 9px; font-weight: 800; color: var(--muted); flex-shrink: 0; }
        .is-all .inst-icon { background: var(--gold-light); border-color: var(--gold-ring); color: var(--gold); }
        .inst-name { font-family: var(--serif); font-size: 14px; font-weight: 700; }

        /* Rate */
        .rate-val { color: var(--green); font-size: 13px; font-weight: 700; }

        /* Amount */
        .amount-val { font-size: 12px; font-family: 'SF Mono', 'Fira Code', monospace; }

        /* Ratio bar */
        .ratio-wrap { display: flex; justify-content: center; }
        .ratio-bar { display: flex; width: 110px; height: 20px; border-radius: 4px; overflow: hidden; gap: 2px; }
        .rb-long { background: var(--lf); height: 100%; display: flex; align-items: center; padding-left: 5px; font-size: 9px; font-weight: 800; color: #fff; justify-content: flex-start; border-radius: 3px 0 0 3px; }
        .rb-short { background: var(--sf); height: 100%; display: flex; align-items: center; padding-right: 5px; font-size: 9px; font-weight: 800; color: #fff; justify-content: flex-end; border-radius: 0 3px 3px 0; }

        /* Trend SVG */
        .trend-up   { stroke: var(--green); stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
        .trend-down { stroke: var(--lf);    stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }

        /* Lots / Orders */
        .num-val { font-size: 13px; color: var(--navy); }

        /* ─── Responsive ─── */
        @media (max-width: 900px) {
            .page-hero, .content-wrap { padding-left: 20px; padding-right: 20px; }
        }
    </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; ?>/vps/vps.php">VPS</a><i class="fas fa-chevron-right"></i>
            <span>Liquidation Data</span>
        </div>
        <h1 class="hero-title">Stop Out <em>Liquidation</em> Data</h1>
        <p class="hero-sub">Real-time forced liquidation events across instruments — long/short volume, lots & order ratios.</p>
    </div>
</div>

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

    <!-- Time Tabs -->
    <div class="tabs-row">
        <button class="tab-btn active" onclick="setTab(this)">Last week</button>
        <button class="tab-btn" onclick="setTab(this)">Nearly one month</button>
        <button class="tab-btn" onclick="setTab(this)">Past 3 months</button>
        <button class="tab-btn" onclick="setTab(this)">Past 6 months</button>
    </div>

    <!-- Ticker -->
    <div class="ticker-wrap">
        <div class="ticker-label">
            <i class="fas fa-bolt"></i> Stop Out Feed
        </div>
        <div class="ticker-scroll">
            <ul class="ticker-list">
                <?php
                $all_ticks = array_merge($ticker_news, [$ticker_news[0]]);
                foreach ($all_ticks as $news):
                    $clean = strtolower(str_replace(' ', '_', $news['broker']));
                    $imgPath = 'assets/images/ea/' . $clean . '.png';
                    $initials = strtoupper(substr($news['broker'], 0, 2));
                ?>
                <li class="ticker-item">
                    <div class="ti-broker">
                        <div class="ti-avatar">
                            <img src="<?= htmlspecialchars($imgPath) ?>" alt="<?= $news['broker'] ?>"
                                 onerror="this.parentNode.innerHTML='<?= $initials ?>'">
                        </div>
                        <span><?= htmlspecialchars($news['broker']) ?></span>
                    </div>
                    <div class="ti-sep"></div>
                    <div class="ti-group"><span class="ti-label">Time</span><span class="ti-val"><?= $news['time'] ?></span></div>
                    <div class="ti-sep"></div>
                    <div class="ti-group"><span class="ti-label">Instrument</span><span class="ti-val"><?= $news['instrument'] ?></span></div>
                    <div class="ti-sep"></div>
                    <div class="ti-group"><span class="ti-label">Close Price</span><span class="ti-val"><?= $news['price'] ?></span></div>
                    <div class="ti-sep"></div>
                    <div class="ti-group"><span class="ti-label">Amount</span><span class="ti-val"><?= $news['amount'] ?></span></div>
                    <div class="ti-sep"></div>
                    <div class="ti-group"><span class="ti-label">Stop Out</span><span class="ti-val red"><?= $news['stop_out'] ?></span></div>
                </li>
                <?php endforeach; ?>
            </ul>
        </div>
    </div>

    <!-- Table Panel -->
    <div class="table-panel">
        <div class="panel-header">
            <div class="panel-title">Instrument Breakdown</div>
            <div class="panel-legend">
                <div class="leg"><div class="leg-dot ld-long"></div> Long</div>
                <div class="leg"><div class="leg-dot ld-short"></div> Short</div>
            </div>
        </div>
        <div class="table-scroll">
            <table>
                <thead>
                    <tr>
                        <th class="left">Instrument</th>
                        <th>Liquidation Rate</th>
                        <th>Stop Out Amount ($)</th>
                        <th>Vol L/S Ratio</th>
                        <th>Liquidated Lots</th>
                        <th>Lot L/S Ratio</th>
                        <th>Orders</th>
                        <th>Order L/S Ratio</th>
                        <th>Trend</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($liquidation_data as $row):
                        $isAll = ($row['instrument'] === 'ALL');
                        $initials = strtoupper(substr($row['instrument'], 0, 2));
                    ?>
                    <tr class="<?= $isAll ? 'is-all' : '' ?>">
                        <td class="left">
                            <div class="inst-cell">
                                <div class="inst-icon"><?= $initials ?></div>
                                <span class="inst-name"><?= htmlspecialchars($row['instrument']) ?></span>
                            </div>
                        </td>
                        <td><span class="rate-val"><?= $row['rate'] ?></span></td>
                        <td><span class="amount-val"><?= $row['amount'] ?></span></td>

                        <!-- Volume Ratio -->
                        <td>
                            <div class="ratio-wrap">
                                <div class="ratio-bar">
                                    <div class="rb-long" style="width:<?= $row['vol_long'] ?>%"><?= $row['vol_long'] > 12 ? $row['vol_long'] : '' ?></div>
                                    <div class="rb-short" style="width:<?= $row['vol_short'] ?>%"><?= $row['vol_short'] > 12 ? $row['vol_short'] : '' ?></div>
                                </div>
                            </div>
                        </td>

                        <td><span class="num-val"><?= $row['lots'] ?></span></td>

                        <!-- Lot Ratio -->
                        <td>
                            <div class="ratio-wrap">
                                <div class="ratio-bar">
                                    <div class="rb-long" style="width:<?= $row['lot_long'] ?>%"><?= $row['lot_long'] > 12 ? $row['lot_long'] : '' ?></div>
                                    <div class="rb-short" style="width:<?= $row['lot_short'] ?>%"><?= $row['lot_short'] > 12 ? $row['lot_short'] : '' ?></div>
                                </div>
                            </div>
                        </td>

                        <td><span class="num-val"><?= $row['orders'] ?></span></td>

                        <!-- Order Ratio -->
                        <td>
                            <div class="ratio-wrap">
                                <div class="ratio-bar">
                                    <div class="rb-long" style="width:<?= $row['ord_long'] ?>%"><?= $row['ord_long'] > 12 ? $row['ord_long'] : '' ?></div>
                                    <div class="rb-short" style="width:<?= $row['ord_short'] ?>%"><?= $row['ord_short'] > 12 ? $row['ord_short'] : '' ?></div>
                                </div>
                            </div>
                        </td>

                        <!-- Sparkline -->
                        <td>
                            <?php if ($row['trend'] === 'up'): ?>
                                <svg width="44" height="22" viewBox="0 0 44 22"><path d="M4,17 L14,11 L22,13 L32,6 L40,4" class="trend-up"/></svg>
                            <?php else: ?>
                                <svg width="44" height="22" viewBox="0 0 44 22"><path d="M4,4 L14,9 L22,7 L32,14 L40,18" class="trend-down"/></svg>
                            <?php endif; ?>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    </div>

    <!-- Footer note -->
    <div style="display:flex;align-items:center;justify-content:flex-end;gap:6px;margin-top:20px;font-size:11px;color:var(--muted);font-weight:500;">
        <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="#3b82f6" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>
        Data by <strong style="color:var(--navy);">BrokerPortal Data</strong> &nbsp;—&nbsp; 2026-05-04 15:29:41
    </div>

</div>

<script>
function setTab(btn) {
    document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
    btn.classList.add('active');
}
</script>

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