/* ===================================================================
   HX Africa — trading terminal. Sleek, dense, Binance/OKX-grade.
   =================================================================== */
:root {
  --bg: #0a0d12;
  --bg-1: #0e1219;
  --bg-2: #131926;
  --bg-3: #1a2130;
  --bg-hover: #1c2433;
  --line: rgba(255, 255, 255, 0.06);
  --line-2: rgba(255, 255, 255, 0.10);
  --text: #eef1f6;
  --text-dim: #8b95a5;
  --text-faint: #58606e;
  --gold: #f0b90b;
  --gold-2: #ffd75e;
  --up: #2ebd85;
  --up-bg: rgba(46, 189, 133, 0.10);
  --up-line: rgba(46, 189, 133, 0.20);
  --down: #f6465d;
  --down-bg: rgba(246, 70, 93, 0.10);
  --down-line: rgba(246, 70, 93, 0.20);
  --radius: 10px;
  --mono: "SF Mono", "Roboto Mono", ui-monospace, Menlo, Consolas, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --nav-h: 54px;
  --pair-h: 62px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 13px; -webkit-font-smoothing: antialiased; }
button, input { font-family: inherit; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }
.r { text-align: right; }
.accent { color: var(--gold); }
.mono { font-family: var(--mono); }
.up { color: var(--up); } .down { color: var(--down); }

/* ============================ Nav ============================ */
.nav {
  display: flex; align-items: center; justify-content: space-between;
  height: var(--nav-h); padding: 0 18px;
  background: var(--bg-1); border-bottom: 1px solid var(--line);
}
.nav-left { display: flex; align-items: center; gap: 30px; }
.brand { display: flex; align-items: baseline; gap: 6px; }
.brand-mark {
  font-weight: 800; font-size: 19px; letter-spacing: -0.5px; color: #1a1400;
  background: linear-gradient(120deg, var(--gold), var(--gold-2)); padding: 2px 7px; border-radius: 6px;
}
.brand-name { font-weight: 700; font-size: 18px; }
.nav-links { display: flex; gap: 22px; }
.nav-links a { color: var(--text-dim); font-weight: 500; font-size: 14px; transition: color .15s; }
.nav-links a:hover, .nav-links a.active { color: var(--text); }
.nav-right { display: flex; align-items: center; gap: 12px; }
.conn { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); transition: background .3s; }
.dot.live { background: var(--up); box-shadow: 0 0 8px var(--up); }
.dot.down { background: var(--down); }
.btn { border: none; border-radius: 8px; padding: 8px 15px; font-weight: 600; font-size: 13px; cursor: pointer; transition: all .15s; }
.btn-ghost { background: var(--bg-3); color: var(--text); }
.btn-ghost:hover { color: var(--gold); }
.btn-primary { background: linear-gradient(120deg, var(--gold), var(--gold-2)); color: #1a1400; }
.btn-primary:hover { filter: brightness(1.06); transform: translateY(-1px); }

/* ============================ Pair bar ============================ */
.pairbar {
  display: flex; align-items: center; gap: 26px; height: var(--pair-h); padding: 0 18px;
  background: var(--bg-1); border-bottom: 1px solid var(--line);
  overflow-x: auto; overflow-y: hidden; flex-shrink: 0; white-space: nowrap;
}
.pair-select, .pairbar-price, .pairbar-stats { flex-shrink: 0; }
.pair-select {
  display: flex; align-items: center; gap: 10px; background: transparent; border: none;
  color: var(--text); cursor: pointer; padding: 6px 10px; border-radius: 8px; transition: background .15s;
}
.pair-select:hover { background: var(--bg-2); }
.pair-icon { font-size: 26px; }
.pair-meta { display: flex; flex-direction: column; align-items: flex-start; }
.pair-symbol { font-size: 17px; font-weight: 700; letter-spacing: -0.3px; }
.pair-name { font-size: 11px; color: var(--text-dim); }
.chev { color: var(--text-faint); }
.pairbar-price { display: flex; flex-direction: column; min-width: 120px; }
.pb-last { font-size: 22px; font-weight: 700; font-family: var(--mono); letter-spacing: -0.5px; transition: color .2s; }
.pb-usd { font-size: 11px; color: var(--text-dim); font-family: var(--mono); }
.pairbar-stats { display: flex; gap: 26px; }
.pb-stat { display: flex; flex-direction: column; gap: 3px; white-space: nowrap; }
.pb-stat .lbl { font-size: 11px; color: var(--text-faint); }
.pb-stat .val { font-size: 13px; font-weight: 600; font-family: var(--mono); }
@keyframes flashUpText { 0% { color: var(--up); } 100% {} }
@keyframes flashDownText { 0% { color: var(--down); } 100% {} }
.pb-last.fup { animation: flashUpText .5s; } .pb-last.fdn { animation: flashDownText .5s; }

/* ============================ Layout ============================ */
.layout {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr) 288px 300px;
  gap: 8px; padding: 8px;
  height: calc(100vh - var(--nav-h) - var(--pair-h));
}
.panel {
  background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; position: relative;
}
.panel::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 1px; background: linear-gradient(90deg, transparent, rgba(255,255,255,0.05), transparent); }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 13px; }

/* ============================ Markets ============================ */
.markets { display: flex; flex-direction: column; }
.search { background: var(--bg-3); border: 1px solid var(--line); border-radius: 7px; color: var(--text); padding: 6px 9px; width: 110px; font-size: 12px; outline: none; transition: border-color .15s; }
.search:focus { border-color: var(--gold); }
.search.wide { width: 100%; margin-bottom: 10px; }
.market-cols, .book-cols, .orders-cols { display: grid; padding: 7px 12px; font-size: 11px; color: var(--text-faint); border-bottom: 1px solid var(--line); }
.market-cols { grid-template-columns: 1.5fr 1fr 0.8fr; }
.market-list { overflow-y: auto; flex: 1; }
.market-row { display: grid; grid-template-columns: 1.5fr 1fr 0.8fr; align-items: center; padding: 8px 12px; cursor: pointer; border-left: 2px solid transparent; transition: background .1s; }
.market-row:hover { background: var(--bg-hover); }
.market-row.active { background: var(--bg-2); border-left-color: var(--gold); }
.market-row .mk-pair { display: flex; align-items: center; gap: 8px; min-width: 0; }
.market-row .mk-icon { font-size: 15px; }
.market-row .mk-base { font-weight: 600; font-size: 13px; }
.market-row .mk-quote { color: var(--text-faint); font-size: 11px; }
.market-row .mk-city { font-size: 10px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.market-row .mk-price { text-align: right; font-family: var(--mono); font-size: 12px; }
.market-row .mk-chg { text-align: right; font-family: var(--mono); font-size: 12px; font-weight: 600; }

/* ============================ Center ============================ */
.center { display: flex; flex-direction: column; gap: 8px; min-width: 0; min-height: 0; }
.chart-panel { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; }
.chart-toolbar { display: flex; align-items: center; gap: 16px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.intervals { display: flex; gap: 2px; }
.intervals button { background: transparent; border: none; color: var(--text-dim); padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: 600; transition: all .12s; }
.intervals button:hover { color: var(--text); background: var(--bg-3); }
.intervals button.active { color: #1a1400; background: linear-gradient(120deg, var(--gold), var(--gold-2)); }
.chart-legend { font-family: var(--mono); font-size: 11px; color: var(--text-dim); flex: 1; }
.chart-legend b { color: var(--text); }
.chart-brand { font-size: 10px; letter-spacing: 1px; color: var(--text-faint); text-transform: uppercase; }
.chart-wrap { position: relative; flex: 1; min-height: 260px; }
#chart { width: 100%; height: 100%; }
.crosshair-tip { position: absolute; pointer-events: none; display: none; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 6px; padding: 8px 10px; font-family: var(--mono); font-size: 11px; z-index: 5; box-shadow: 0 6px 18px rgba(0,0,0,.5); line-height: 1.5; }

/* Property strip */
.property-strip { padding: 12px 16px; }
.ps-top { display: flex; align-items: center; gap: 12px; }
.ps-badge { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-size: 22px; background: var(--bg-3); flex-shrink: 0; }
.ps-title { flex: 1; min-width: 0; }
.ps-title h3 { font-size: 15px; font-weight: 700; display: inline; }
.ps-type { font-size: 10px; letter-spacing: .5px; text-transform: uppercase; color: var(--gold); border: 1px solid rgba(240,185,11,.4); padding: 2px 7px; border-radius: 20px; margin-left: 8px; }
.ps-loc { color: var(--text-dim); font-size: 12px; margin-top: 2px; }
.ps-metrics { display: flex; gap: 22px; }
.ps-metric { text-align: right; }
.ps-metric .k { font-size: 10px; color: var(--text-faint); }
.ps-metric .v { font-size: 14px; font-weight: 700; font-family: var(--mono); }
.ps-desc { margin-top: 10px; color: var(--text-dim); font-size: 12px; line-height: 1.55; }

/* Orders panel */
.orders-panel { display: flex; flex-direction: column; max-height: 210px; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: none; color: var(--text-dim); cursor: pointer; padding: 10px 14px; font-weight: 600; font-size: 13px; border-bottom: 2px solid transparent; transition: color .12s; }
.tabs button.active { color: var(--text); border-bottom-color: var(--gold); }
.badge { display: inline-grid; place-items: center; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--bg-3); color: var(--text-dim); font-size: 10px; font-family: var(--mono); margin-left: 4px; }
.orders-cols, .orders-row { display: grid; grid-template-columns: 1.2fr 1fr 0.8fr 0.7fr 1fr 1fr 1fr 0.8fr; align-items: center; }
.orders-list { overflow-y: auto; flex: 1; }
.orders-row { padding: 8px 12px; font-family: var(--mono); font-size: 12px; border-bottom: 1px solid var(--line); }
.orders-row .side-b { color: var(--up); } .orders-row .side-s { color: var(--down); }
.cancel-btn { background: var(--bg-3); border: 1px solid var(--line-2); color: var(--text-dim); border-radius: 5px; padding: 3px 8px; cursor: pointer; font-size: 11px; }
.cancel-btn:hover { color: var(--down); border-color: var(--down); }
.empty { padding: 26px 12px; text-align: center; color: var(--text-faint); font-size: 12px; }

/* ============================ Book ============================ */
.book-panel { display: flex; flex-direction: column; }
.book-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--line); font-weight: 600; }
.book-modes { display: flex; gap: 3px; }
.book-modes button { background: transparent; border: 1px solid var(--line); color: var(--text-faint); width: 24px; height: 22px; border-radius: 5px; cursor: pointer; font-size: 10px; }
.book-modes button.active { color: var(--gold); border-color: rgba(240,185,11,.4); }
.book-cols { grid-template-columns: 1fr 1fr 1fr; }
.asks, .bids { flex: 1; overflow: hidden; display: flex; flex-direction: column; min-height: 60px; }
.asks { justify-content: flex-end; }
.book-row { position: relative; display: grid; grid-template-columns: 1fr 1fr 1fr; padding: 2.5px 12px; font-family: var(--mono); font-size: 12px; cursor: pointer; }
.book-row:hover { background: var(--bg-hover); }
.book-row .depth { position: absolute; top: 0; right: 0; bottom: 0; z-index: 0; opacity: .12; transition: width .2s ease; }
.book-row span { position: relative; z-index: 1; }
.book-row .bp-ask { color: var(--down); } .book-row .bp-bid { color: var(--up); }
.book-row .amt, .book-row .tot { text-align: right; color: var(--text-dim); }
.book-mid { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.mid-price { font-size: 18px; font-weight: 700; font-family: var(--mono); }
#mid-arrow { color: var(--up); }
.mid-spread { font-size: 11px; color: var(--text-faint); margin-left: auto; }
.trades-head { padding: 9px 12px; border-top: 1px solid var(--line); font-weight: 600; font-size: 12px; }
.trade-list { overflow-y: auto; height: 150px; }
.trade-row { display: grid; grid-template-columns: 1fr 1fr 1fr; padding: 2.5px 12px; font-family: var(--mono); font-size: 12px; }
.trade-row .ta, .trade-row .tt { text-align: right; color: var(--text-dim); }
.flash-up { animation: fUp .5s; } .flash-down { animation: fDn .5s; }
@keyframes fUp { from { background: var(--up-bg); } to { background: transparent; } }
@keyframes fDn { from { background: var(--down-bg); } to { background: transparent; } }

/* ============================ Order form ============================ */
.form-panel { padding: 14px; display: flex; flex-direction: column; }
.side-tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg-3); border-radius: 8px; padding: 3px; margin-bottom: 14px; }
.side-tab { padding: 9px; border: none; border-radius: 6px; cursor: pointer; font-weight: 700; font-size: 14px; background: transparent; color: var(--text-dim); transition: all .15s; }
.side-tab.buy.active { background: var(--up); color: #052015; }
.side-tab.sell.active { background: var(--down); color: #2a0810; }
.type-tabs { display: flex; gap: 18px; margin-bottom: 14px; }
.type-tabs button { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 13px; font-weight: 600; padding-bottom: 5px; border-bottom: 2px solid transparent; }
.type-tabs button.active { color: var(--text); border-bottom-color: var(--gold); }
.avail { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-dim); margin-bottom: 12px; }
.fields { display: flex; flex-direction: column; gap: 12px; flex: 1; }
.field span { font-size: 11px; color: var(--text-dim); display: block; margin-bottom: 5px; }
.field .input { display: flex; align-items: center; background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px; padding: 0 11px; transition: border-color .15s; }
.field .input:focus-within { border-color: var(--gold); }
.field .input input { background: none; border: none; color: var(--text); outline: none; padding: 10px 0; width: 100%; font-family: var(--mono); font-size: 13px; }
.field .input input::-webkit-outer-spin-button, .field .input input::-webkit-inner-spin-button { -webkit-appearance: none; }
.field .input em { color: var(--text-dim); font-style: normal; font-size: 12px; }

/* Custom slider */
.slider { position: relative; padding: 6px 0 2px; }
.slider-track { position: absolute; top: 12px; left: 0; right: 0; height: 4px; background: var(--bg-3); border-radius: 2px; }
.slider-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--gold), var(--gold-2)); border-radius: 2px; }
.slider input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; background: transparent; position: relative; z-index: 2; margin: 0; height: 24px; cursor: pointer; }
.slider input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: #fff; border: 3px solid var(--gold); margin-top: 0; box-shadow: 0 2px 6px rgba(0,0,0,.4); cursor: grab; }
.slider input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--gold); }
.slider-ticks { display: flex; justify-content: space-between; padding: 0 6px; margin-top: -6px; }
.slider-ticks i { width: 6px; height: 6px; border-radius: 50%; background: var(--bg-3); transform: rotate(45deg); }
.slider-val { text-align: right; font-size: 11px; color: var(--text-dim); font-family: var(--mono); margin-top: 4px; }

.order-meta { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--text-dim); margin: 4px 0 12px; }
.order-meta > div { display: flex; justify-content: space-between; }
.submit { padding: 13px; border: none; border-radius: 8px; cursor: pointer; font-weight: 700; font-size: 15px; color: #052015; transition: filter .15s, transform .1s; }
.submit.buy { background: var(--up); }
.submit.sell { background: var(--down); color: #2a0810; }
.submit:hover { filter: brightness(1.07); }
.submit:active { transform: scale(.99); }

/* ============================ Picker overlay ============================ */
.picker { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 200; display: none; padding-top: calc(var(--nav-h) + 10px); }
.picker.open { display: block; }
.picker-box { width: 460px; max-width: 92vw; margin: 0 auto; background: var(--bg-1); border: 1px solid var(--line-2); border-radius: 12px; padding: 14px; box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.picker-list { max-height: 60vh; overflow-y: auto; }
.picker-row { display: grid; grid-template-columns: 1.6fr 1fr 0.9fr; align-items: center; padding: 10px; border-radius: 8px; cursor: pointer; }
.picker-row:hover { background: var(--bg-2); }
.picker-row .p-pair { display: flex; align-items: center; gap: 10px; }
.picker-row .p-ic { font-size: 18px; }
.picker-row .p-name { font-size: 11px; color: var(--text-faint); }
.picker-row .p-px { text-align: right; font-family: var(--mono); }
.picker-row .p-chg { text-align: right; font-family: var(--mono); font-weight: 600; }

/* ============================ Toasts ============================ */
.toast-wrap { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 300; }
.toast { background: var(--bg-3); border: 1px solid var(--line-2); border-left: 3px solid var(--gold); border-radius: 8px; padding: 12px 16px; min-width: 260px; box-shadow: 0 8px 24px rgba(0,0,0,.5); animation: slideIn .2s ease; }
.toast.ok { border-left-color: var(--up); } .toast.err { border-left-color: var(--down); }
.toast .t-title { font-weight: 700; font-size: 13px; margin-bottom: 3px; text-transform: capitalize; }
.toast .t-body { font-size: 12px; color: var(--text-dim); font-family: var(--mono); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #2a3446; }
::-webkit-scrollbar-track { background: transparent; }

/* ============================ Responsive ============================ */
@media (max-width: 1360px) {
  .layout { grid-template-columns: 210px minmax(0,1fr) 260px 280px; }
  .pairbar-stats { gap: 18px; }
}
@media (max-width: 1140px) {
  .layout { grid-template-columns: 1fr 300px; grid-auto-rows: min-content; height: auto; }
  .markets { grid-row: auto; max-height: 260px; }
  .center { grid-column: 1 / -1; order: -1; }
  .form-panel { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .nav-links { display: none; }
  .pairbar-stats { gap: 14px; }
}
/* ============================ Account pill ============================ */
.acct { display: flex; align-items: center; gap: 8px; }
.acct-avatar { width: 28px; height: 28px; border-radius: 50%; background: linear-gradient(120deg, var(--gold), var(--gold-2)); color: #1a1400; display: grid; place-items: center; font-weight: 800; font-size: 13px; }
.acct-name { font-size: 13px; font-weight: 600; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-out { background: var(--bg-3); border: 1px solid var(--line-2); color: var(--text-dim); border-radius: 6px; padding: 6px 10px; cursor: pointer; font-size: 12px; }
.acct-out:hover { color: var(--down); border-color: var(--down); }

/* ============================ Hyperliquid-style chart chrome ======= */
.chart-toolbar { flex-wrap: nowrap; }
.tb-sep { width: 1px; height: 18px; background: var(--line); flex-shrink: 0; }
.chart-types { display: flex; gap: 2px; flex-shrink: 0; }
.chart-types button { background: transparent; border: none; color: var(--text-dim); cursor: pointer; border-radius: 6px; padding: 5px 8px; font-size: 13px; transition: all .12s; }
.chart-types button:hover { background: var(--bg-3); color: var(--text); }
.chart-types button.active { background: var(--bg-3); color: var(--gold); }
.tb-btn { background: transparent; border: none; color: var(--text-dim); cursor: pointer; border-radius: 6px; padding: 5px 9px; font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; gap: 5px; flex-shrink: 0; }
.tb-btn:hover { background: var(--bg-3); color: var(--text); }
.tb-btn.icon { font-size: 14px; }
.chart-body { display: flex; flex: 1; min-height: 0; }
.chart-tools {
  width: 42px; flex-shrink: 0; background: #0b0e13;
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 0;
}
.chart-tools button {
  width: 32px; height: 32px; background: transparent; border: none;
  color: #787b86; border-radius: 6px; cursor: pointer; padding: 0;
  display: grid; place-items: center; transition: background .12s, color .12s;
}
.chart-tools button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.chart-tools button:hover { background: rgba(255,255,255,0.06); color: #d1d4dc; }
.chart-tools button.active { background: rgba(38,194,129,0.14); color: #26c281; }
.tool-sep { width: 22px; height: 1px; background: var(--line); margin: 4px 0; }
.chart-wrap { flex: 1; }

/* Chart moving-average legend overlay */
.ma-legend { position: absolute; top: 8px; left: 12px; z-index: 4; font-family: var(--mono); font-size: 11px; pointer-events: none; text-shadow: 0 1px 3px rgba(0,0,0,.8); }
.tb-btn.active { background: rgba(240,185,11,.14); color: var(--gold); }
