<?php 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>Position Distribution</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;
            --bf:         #F4F1EB;
            --profit:     #0F7A5A;
            --profit-bg:  #EDFAF4;
            --loss:       #C94848;
            --loss-bg:    #FDF0F0;
            --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 20px rgba(15,22,40,.08);
        }

        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: 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; }

        /* ─── Layout ─── */
        .content-wrap { max-width: 1100px; margin: 0 auto; padding: 40px 40px 0; display: flex; gap: 32px; align-items: flex-start; flex-wrap: wrap; }

        /* ─── Widget Card ─── */
        .widget-card {
            background: var(--white);
            border: 1px solid var(--border);
            border-radius: 16px;
            padding: 50px;
            box-shadow: var(--shadow-md);
            flex: 0 0 460px;
            max-width: 460px;
            animation: slideUp .4s ease both;
        }
        @keyframes slideUp { from { opacity:0; transform:translateY(16px); } to { opacity:1; transform:translateY(0); } }

        /* Card Header */
        .card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 22px; }
        .card-title { font-family: var(--serif); font-size: 20px; font-weight: 700; }
        .card-title em { font-style: italic; color: var(--gold); }

        /* Custom Select */
        .pair-wrap { position: relative; }
        .pair-select {
            font-family: var(--sans); font-size: 12px; font-weight: 700;
            color: var(--navy); background: var(--ivory);
            border: 1px solid var(--border); border-radius: 8px;
            padding: 8px 32px 8px 12px; cursor: pointer; outline: none;
            appearance: none;
            background-image: url('data:image/svg+xml;charset=US-ASCII,<svg width="10" height="10" 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 10px center;
            transition: border-color .2s;
        }
        .pair-select:hover, .pair-select:focus { border-color: var(--gold-ring); }

        /* Short / Long labels */
        .sl-labels {
            display: flex; justify-content: space-between;
            font-size: 10px; font-weight: 800; letter-spacing: .6px;
            text-transform: uppercase; color: var(--muted);
            padding-right: 72px; margin-bottom: 8px;
        }

        /* Chart wrapper */
        .chart-wrap { position: relative; padding-right: 72px; margin-bottom: 6px; }

        /* Grid lines */
        .grid { position: absolute; top: 0; bottom: 0; left: 0; right: 72px; display: flex; justify-content: space-between; pointer-events: none; z-index: 1; }
        .gl { width: 1px; background: var(--bf); }
        .gl.center { background: var(--border); }

        /* Rows */
        .rows { position: relative; z-index: 2; display: flex; flex-direction: column; gap: 3px; }
        .row { display: flex; align-items: center; height: 7px; position: relative; }
        .side { flex: 1; display: flex; height: 100%; }
        .side.short { justify-content: flex-end; }
        .side.long  { justify-content: flex-start; }
        .bar { height: 100%; border-radius: 1px; transition: width .6s cubic-bezier(.16,1,.3,1); }
        .bar.profit { background: var(--profit); }
        .bar.loss   { background: var(--loss); }

        /* Y labels */
        .y-lbl {
            position: absolute; right: -72px; top: 50%; transform: translateY(-50%);
            font-size: 10px; font-weight: 700; color: var(--navy);
            width: 64px; text-align: left; padding-left: 10px;
            font-family: 'SF Mono','Fira Code', monospace;
        }

        /* Current price line */
        .price-line {
            position: absolute; left: 0; right: -72px;
            height: 1px; border-top: 1.5px dashed var(--blue);
            z-index: 3; display: flex; align-items: center; justify-content: flex-end;
        }
        .price-badge {
            background: var(--blue); color: #fff;
            padding: 4px 9px; border-radius: 6px;
            font-size: 11px; font-weight: 800; letter-spacing: .3px;
            transform: translateY(-50%);
            font-family: 'SF Mono','Fira Code', monospace;
            box-shadow: 0 2px 8px rgba(29,95,204,.3);
        }

        /* X-axis */
        .x-axis {
            display: flex; justify-content: space-between;
            padding-right: 72px; font-size: 11px; font-weight: 700;
            color: var(--muted); margin-bottom: 16px; position: relative;
        }
        .x-axis::before {
            content: ''; position: absolute; top: -8px; left: 0; right: 72px;
            height: 1px; background: var(--border);
        }

        /* Legend */
        .legend { display: flex; gap: 14px; margin-bottom: 22px; }
        .leg-item { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600; color: var(--muted); }
        .leg-swatch { width: 16px; height: 5px; border-radius: 3px; }
        .leg-profit { background: var(--profit); }
        .leg-loss   { background: var(--loss); }

        /* Divider */
        .divider { height: 1px; background: var(--bf); margin: 0 0 18px; }

        /* Info blocks */
        .info-block { margin-bottom: 18px; }
        .info-title { font-size: 11px; font-weight: 800; letter-spacing: .5px; text-transform: uppercase; color: var(--navy); margin-bottom: 6px; display: flex; align-items: center; gap: 7px; }
        .info-title i { color: var(--gold); font-size: 11px; }
        .info-text { font-size: 12px; color: var(--muted); font-weight: 500; line-height: 1.7; }

        /* Footer note */
        .card-footer { display: flex; align-items: center; gap: 5px; font-size: 10px; color: var(--muted); font-weight: 500; padding-top: 14px; border-top: 1px solid var(--bf); }
        .card-footer i { color: #3b82f6; }

        /* ─── Side info panel ─── */
        .side-panel { flex: 1; min-width: 240px; display: flex; flex-direction: column; gap: 16px; animation: slideUp .4s .1s ease both; }

        .info-card {
            background: var(--white); border: 1px solid var(--border);
            border-radius: 12px; padding: 20px;
            box-shadow: var(--shadow-sm);
        }
        .info-card-title { font-family: var(--serif); font-size: 15px; font-weight: 700; margin-bottom: 10px; }
        .info-card-title em { font-style: italic; color: var(--gold); }
        .info-card p { font-size: 12px; color: var(--muted); font-weight: 500; line-height: 1.75; }

        .stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
        .stat-cell { background: var(--ivory); border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
        .stat-label { font-size: 10px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; color: var(--muted); margin-bottom: 5px; }
        .stat-acc { width: 18px; height: 2px; background: var(--gold); border-radius: 2px; margin-bottom: 5px; }
        .stat-value { font-family: var(--serif); font-size: 16px; font-weight: 700; color: var(--navy); }
        .stat-value.green { color: var(--profit); }
        .stat-value.red   { color: var(--loss); }

        @media (max-width: 820px) {
            .page-hero, .content-wrap { padding-left: 20px; padding-right: 20px; }
            .widget-card { flex: 1 1 100%; max-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; ?>/vps/vps.php">VPS</a><i class="fas fa-chevron-right"></i>
            <span>Position Distribution</span>
        </div>
        <h1 class="hero-title">Position <em>Distribution</em> Chart</h1>
        <p class="hero-sub">Identify key support & resistance levels — visualize profit/loss position clusters across price.</p>
    </div>
</div>

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

    <!-- ── Widget Card ── -->
    <div class="widget-card">

        <div class="card-header">
            <div class="card-title">Position <em>Map</em></div>
            <div class="pair-wrap">
                <select class="pair-select" id="pairSelect">
                    <option>EUR / USD</option>
                    <option>GBP / USD</option>
                    <option>AUD / USD</option>
                    <option>NZD / USD</option>
                    <option>USD / JPY</option>
                    <option selected>USD / CAD</option>
                    <option>USD / CHF</option>
                    <option>XAU / USD</option>
                </select>
            </div>
        </div>

        <div class="sl-labels">
            <span>◀ Short</span>
            <span>Long ▶</span>
        </div>

        <div class="chart-wrap" id="chartWrap">
            <!-- Grid -->
            <div class="grid">
                <div class="gl"></div><div class="gl"></div><div class="gl"></div><div class="gl"></div>
                <div class="gl center"></div>
                <div class="gl"></div><div class="gl"></div><div class="gl"></div><div class="gl"></div>
            </div>

            <!-- Rows -->
            <div class="rows" id="chartRows">
                <!-- Above price -->
                <div class="row"><div class="side short"><div class="bar profit" style="width:60%"></div></div><div class="side long"><div class="bar loss" style="width:80%"></div></div><div class="y-lbl">1.37279</div></div>
                <div class="row"><div class="side short"><div class="bar profit" style="width:30%"></div></div><div class="side long"><div class="bar loss" style="width:0%"></div></div></div>
                <div class="row"><div class="side short"><div class="bar profit" style="width:40%"></div></div><div class="side long"><div class="bar loss" style="width:65%"></div></div></div>
                <div class="row"><div class="side short"><div class="bar profit" style="width:35%"></div></div><div class="side long"><div class="bar loss" style="width:15%"></div></div><div class="y-lbl">1.37039</div></div>
                <div class="row"><div class="side short"><div class="bar profit" style="width:45%"></div></div><div class="side long"><div class="bar loss" style="width:85%"></div></div></div>
                <div class="row"><div class="side short"><div class="bar profit" style="width:62%"></div></div><div class="side long"><div class="bar loss" style="width:65%"></div></div></div>
                <div class="row"><div class="side short"><div class="bar profit" style="width:15%"></div></div><div class="side long"><div class="bar loss" style="width:5%"></div></div><div class="y-lbl">1.36799</div></div>
                <div class="row"><div class="side short"><div class="bar profit" style="width:45%"></div></div><div class="side long"><div class="bar loss" style="width:0%"></div></div></div>
                <div class="row"><div class="side short"><div class="bar profit" style="width:75%"></div></div><div class="side long"><div class="bar loss" style="width:25%"></div></div></div>
                <div class="row"><div class="side short"><div class="bar profit" style="width:55%"></div></div><div class="side long"><div class="bar loss" style="width:35%"></div></div><div class="y-lbl">1.36559</div></div>
                <div class="row"><div class="side short"><div class="bar profit" style="width:20%"></div></div><div class="side long"><div class="bar loss" style="width:5%"></div></div></div>
                <div class="row"><div class="side short"><div class="bar profit" style="width:15%"></div></div><div class="side long"><div class="bar loss" style="width:90%"></div></div></div>
                <div class="row"><div class="side short"><div class="bar profit" style="width:85%"></div></div><div class="side long"><div class="bar loss" style="width:30%"></div></div><div class="y-lbl">1.36319</div></div>
                <div class="row"><div class="side short"><div class="bar profit" style="width:50%"></div></div><div class="side long"><div class="bar loss" style="width:25%"></div></div></div>
                <div class="row"><div class="side short"><div class="bar profit" style="width:15%"></div></div><div class="side long"><div class="bar loss" style="width:70%"></div></div></div>

                <!-- Current price line -->
                <div class="price-line" id="priceLine" style="top:50%">
                    <div class="price-badge" id="priceBadge">1.36079</div>
                </div>

                <!-- Below price -->
                <div class="row"><div class="side short"><div class="bar loss" style="width:50%"></div></div><div class="side long"><div class="bar profit" style="width:65%"></div></div></div>
                <div class="row"><div class="side short"><div class="bar loss" style="width:60%"></div></div><div class="side long"><div class="bar profit" style="width:35%"></div></div></div>
                <div class="row"><div class="side short"><div class="bar loss" style="width:60%"></div></div><div class="side long"><div class="bar profit" style="width:55%"></div></div><div class="y-lbl">1.35839</div></div>
                <div class="row"><div class="side short"><div class="bar loss" style="width:5%"></div></div><div class="side long"><div class="bar profit" style="width:25%"></div></div></div>
                <div class="row"><div class="side short"><div class="bar loss" style="width:40%"></div></div><div class="side long"><div class="bar profit" style="width:40%"></div></div></div>
                <div class="row"><div class="side short"><div class="bar loss" style="width:55%"></div></div><div class="side long"><div class="bar profit" style="width:90%"></div></div><div class="y-lbl">1.35599</div></div>
                <div class="row"><div class="side short"><div class="bar loss" style="width:40%"></div></div><div class="side long"><div class="bar profit" style="width:10%"></div></div></div>
                <div class="row"><div class="side short"><div class="bar loss" style="width:85%"></div></div><div class="side long"><div class="bar profit" style="width:60%"></div></div></div>
                <div class="row"><div class="side short"><div class="bar loss" style="width:55%"></div></div><div class="side long"><div class="bar profit" style="width:30%"></div></div><div class="y-lbl">1.35359</div></div>
                <div class="row"><div class="side short"><div class="bar loss" style="width:5%"></div></div><div class="side long"><div class="bar profit" style="width:65%"></div></div></div>
                <div class="row"><div class="side short"><div class="bar loss" style="width:90%"></div></div><div class="side long"><div class="bar profit" style="width:55%"></div></div></div>
                <div class="row"><div class="side short"><div class="bar loss" style="width:45%"></div></div><div class="side long"><div class="bar profit" style="width:25%"></div></div><div class="y-lbl">1.35119</div></div>
                <div class="row"><div class="side short"><div class="bar loss" style="width:75%"></div></div><div class="side long"><div class="bar profit" style="width:50%"></div></div></div>
                <div class="row"><div class="side short"><div class="bar loss" style="width:90%"></div></div><div class="side long"><div class="bar profit" style="width:25%"></div></div></div>
                <div class="row"><div class="side short"><div class="bar loss" style="width:25%"></div></div><div class="side long"><div class="bar profit" style="width:10%"></div></div><div class="y-lbl">1.34879</div></div>
            </div>
        </div>

        <!-- X Axis -->
        <div class="x-axis">
            <span>4</span><span>3</span><span>2</span><span>1</span>
            <span style="color:var(--navy);font-weight:800">0%</span>
            <span>1</span><span>2</span><span>3</span><span>4</span>
        </div>

        <!-- Legend -->
        <div class="legend">
            <div class="leg-item"><div class="leg-swatch leg-profit"></div><span>Profit positions</span></div>
            <div class="leg-item"><div class="leg-swatch leg-loss"></div><span>Loss positions</span></div>
        </div>

        <div class="divider"></div>

        <!-- Info -->
        <div class="info-block">
            <div class="info-title"><i class="fas fa-lightbulb"></i> Chart Meaning</div>
            <p class="info-text">Find out the potential support / resistance position of the market and understand the price-intensive trading area. Identify key cost levels in the current market landscape.</p>
        </div>
        <div class="info-block">
            <div class="info-title"><i class="fas fa-database"></i> Statistical Description</div>
            <p class="info-text">Based on varieties and the current price, statistics are drawn from the last 30 days — including registered orders, warehouse receipt prices, and any changes within the past 24 hours. Updated hourly.</p>
        </div>

        <div class="card-footer">
            <i class="fas fa-shield-alt"></i>
            The data is provided by <strong style="color:var(--navy);margin:0 3px">Trader Safety Data</strong> &nbsp;2026-05-04 16:48:08
        </div>
    </div>

    <!-- ── Side Panel ── -->
    <div class="side-panel">
        <div class="info-card">
            <div class="info-card-title">How to <em>Read</em> This Chart</div>
            <p>Each horizontal bar represents an open position cluster at that price level. Green bars indicate positions currently in <strong>profit</strong>; red bars show positions in <strong>loss</strong>.</p>
            <br>
            <p>The dashed blue line marks the <strong>current price</strong>. Positions above it are short-side, below it are long-side.</p>
        </div>

        <div class="info-card">
            <div class="info-card-title">Market <em>Snapshot</em></div>
            <div class="stat-grid">
                <div class="stat-cell">
                    <div class="stat-label">Current Price</div>
                    <div class="stat-acc"></div>
                    <div class="stat-value">1.36079</div>
                </div>
                <div class="stat-cell">
                    <div class="stat-label">Pair</div>
                    <div class="stat-acc"></div>
                    <div class="stat-value" id="snapPair">USD/CAD</div>
                </div>
                <div class="stat-cell">
                    <div class="stat-label">Long Bias</div>
                    <div class="stat-acc"></div>
                    <div class="stat-value green">62.4%</div>
                </div>
                <div class="stat-cell">
                    <div class="stat-label">Short Bias</div>
                    <div class="stat-acc"></div>
                    <div class="stat-value red">37.6%</div>
                </div>
                <div class="stat-cell">
                    <div class="stat-label">Data Window</div>
                    <div class="stat-acc"></div>
                    <div class="stat-value" style="font-size:13px">30 Days</div>
                </div>
                <div class="stat-cell">
                    <div class="stat-label">Updated</div>
                    <div class="stat-acc"></div>
                    <div class="stat-value" style="font-size:11px;color:var(--muted)">Hourly</div>
                </div>
            </div>
        </div>

        <div class="info-card">
            <div class="info-card-title">Price <em>Levels</em></div>
            <div style="display:flex;flex-direction:column;gap:8px;margin-top:4px;">
                <?php
                $levels = [
                    ['price'=>'1.37279','label'=>'Strong Resistance','cls'=>'loss'],
                    ['price'=>'1.36799','label'=>'Resistance Zone','cls'=>'loss'],
                    ['price'=>'1.36079','label'=>'Current Price','cls'=>'blue'],
                    ['price'=>'1.35599','label'=>'Support Zone','cls'=>'profit'],
                    ['price'=>'1.34879','label'=>'Strong Support','cls'=>'profit'],
                ];
                $colors = ['profit'=>'var(--profit)','loss'=>'var(--loss)','blue'=>'var(--blue)'];
                foreach ($levels as $lv):
                ?>
                <div style="display:flex;align-items:center;justify-content:space-between;padding:8px 10px;background:var(--ivory);border:1px solid var(--border);border-radius:7px;">
                    <span style="font-size:11px;font-weight:600;color:var(--muted)"><?= $lv['label'] ?></span>
                    <span style="font-size:12px;font-weight:800;font-family:monospace;color:<?= $colors[$lv['cls']] ?>"><?= $lv['price'] ?></span>
                </div>
                <?php endforeach; ?>
            </div>
        </div>
    </div>

</div>

<script>
// Sync pair select → snapshot
document.getElementById('pairSelect').addEventListener('change', function(){
    const val = this.value.replace(' / ','/');
    document.getElementById('snapPair').textContent = val;
});

// Animate bars on load
document.addEventListener('DOMContentLoaded', () => {
    const bars = document.querySelectorAll('.bar');
    bars.forEach(b => {
        const w = b.style.width;
        b.style.width = '0%';
        setTimeout(() => { b.style.width = w; }, 80);
    });

    // Position price line correctly between rows 15 and 16
    const rows = document.querySelectorAll('.row');
    const wrap = document.getElementById('chartRows');
    if (rows.length >= 15) {
        const rowH   = rows[0].offsetHeight + 3; // height + gap
        const topPx  = rowH * 15;
        document.getElementById('priceLine').style.top = topPx + 'px';
    }
});
</script>

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