/* ===== MEX theme — dark, blue accent ===== */
:root {
  --bg:        #0a0e1a;   /* app background (deep blue-black) */
  --panel:     #111729;   /* panel surface */
  --panel-2:   #0d1322;   /* nested surface */
  --border:    #1e2740;   /* hairlines */
  --text:      #e8ebf2;   /* primary text */
  --muted:     #7b85a0;   /* secondary text */
  --blue:      #2f6bff;   /* brand / primary accent */
  --blue-hi:   #4f86ff;
  --blue-dim:  #16224a;   /* tinted fills, selected rows */
  --up:        #16c784;   /* bids / positive */
  --down:      #ea3943;   /* asks / negative */
  --up-bg:     rgba(22,199,132,0.10);
  --down-bg:   rgba(234,57,67,0.10);
  --radius:    8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  display: flex;
  flex-direction: column;
}
.muted { color: var(--muted); }
.up { color: var(--up); }
.down { color: var(--down); }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.panel-head { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.panel-title { font-weight: 600; }

/* ===== Header ===== */
.topbar {
  display: flex; align-items: center; gap: 22px;
  height: 56px; padding: 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; }
.logo { color: var(--blue); font-size: 20px; }
.brand-name { font-size: 19px; font-weight: 800; letter-spacing: .5px; }
.pair-selector {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 6px 12px; border-radius: var(--radius); background: var(--panel-2);
  border: 1px solid var(--border);
}
.pair-name { font-size: 15px; font-weight: 700; }
.ticker { display: flex; gap: 22px; align-items: center; }
.tk { display: flex; flex-direction: column; gap: 2px; }
.tk-price { font-size: 16px; font-weight: 700; }
.tk-label { font-size: 11px; color: var(--muted); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.net-pill { font-size: 12px; color: var(--up); }
.btn-wallet {
  background: var(--blue); color: #fff; border: 0; cursor: pointer;
  padding: 9px 18px; border-radius: var(--radius); font-weight: 600;
}
.btn-wallet:hover { background: var(--blue-hi); }
.btn-wallet.connected { background: var(--blue-dim); color: var(--blue-hi); font-family: ui-monospace, monospace; }

/* ===== Main grid ===== */
.grid {
  flex: 1; min-height: 0;
  display: grid; gap: 8px; padding: 8px;
  grid-template-columns: 240px 1fr 320px;
  grid-template-rows: 1fr;
}
.center, .right { display: flex; flex-direction: column; gap: 8px; min-height: 0; }

/* ===== Markets ===== */
.markets { display: flex; flex-direction: column; min-height: 0; }
.search {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 6px; padding: 7px 10px; outline: none;
}
.search:focus { border-color: var(--blue); }
.market-tabs { display: flex; gap: 4px; padding: 8px 12px; }
.mtab {
  background: transparent; border: 0; color: var(--muted); cursor: pointer;
  padding: 4px 10px; border-radius: 6px; font-weight: 600;
}
.mtab.active { color: var(--text); background: var(--blue-dim); }
.market-list { overflow-y: auto; flex: 1; }
.market-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 8px;
  padding: 7px 12px; cursor: pointer; align-items: center;
}
.market-row:hover { background: var(--panel-2); }
.market-row.active { background: var(--blue-dim); }
.market-row .sym { font-weight: 600; }
.market-row .sym small { color: var(--muted); font-weight: 400; }
.market-row .chg { text-align: right; font-size: 12px; }

/* ===== Chart ===== */
.chart-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chart-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.chart-intervals { display: flex; gap: 2px; }
.ivl { background: transparent; border: 0; color: var(--muted); cursor: pointer; padding: 4px 9px; border-radius: 5px; font-weight: 600; }
.ivl.active { color: var(--blue-hi); background: var(--blue-dim); }
.chart-canvas { flex: 1; width: 100%; min-height: 0; display: block; }

/* ===== Order form ===== */
.form-panel { height: 340px; display: flex; flex-direction: column; }
.form-tabs { display: flex; gap: 4px; padding: 10px 12px 0; }
.ftab { background: transparent; border: 0; color: var(--muted); cursor: pointer; padding: 6px 12px; font-weight: 700; border-bottom: 2px solid transparent; }
.ftab.active { color: var(--text); border-bottom-color: var(--blue); }
.order-forms { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; padding: 14px; flex: 1; }
.oform { display: flex; flex-direction: column; gap: 9px; min-height: 0; }
.oform-head { font-weight: 700; }
.buy-text { color: var(--up); }
.sell-text { color: var(--down); }
.field {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 0 10px;
}
.field span { color: var(--muted); min-width: 46px; font-size: 12px; }
.field input { flex: 1; background: transparent; border: 0; color: var(--text); padding: 9px 0; outline: none; text-align: right; }
.field b { color: var(--muted); font-weight: 500; font-size: 12px; }
.slider { height: 4px; background: var(--border); border-radius: 4px; position: relative; margin: 6px 4px; }
.slider .dot { position: absolute; left: 0; top: 50%; width: 12px; height: 12px; background: var(--blue); border-radius: 50%; transform: translateY(-4px); }
.pcts { display: flex; gap: 6px; }
.pcts button { flex: 1; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); border-radius: 5px; padding: 5px 0; cursor: pointer; font-size: 12px; }
.pcts button:hover { border-color: var(--blue); color: var(--text); }
.avail { font-size: 12px; }
.btn-buy, .btn-sell { margin-top: auto; flex-shrink: 0; min-height: 42px; border: 0; color: #fff; padding: 0 11px; border-radius: 6px; font-weight: 700; font-size: 14px; cursor: pointer; }
.btn-buy { background: var(--up); }
.btn-sell { background: var(--down); }
.btn-buy:hover { filter: brightness(1.1); }
.btn-sell:hover { filter: brightness(1.1); }

/* ===== Order book ===== */
.book-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.book-cols, .trade-cols { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px; padding: 8px 12px 4px; font-size: 11px; }
.book-cols span:nth-child(2), .book-cols span:nth-child(3),
.trade-cols span:nth-child(2), .trade-cols span:nth-child(3) { text-align: right; }
.book-asks, .book-bids { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.book-asks { justify-content: flex-end; }
.book-row {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px;
  padding: 2px 12px; font-size: 12px; position: relative; cursor: pointer;
}
.book-row span:nth-child(2), .book-row span:nth-child(3) { text-align: right; z-index: 1; }
.book-row .depth { position: absolute; right: 0; top: 0; bottom: 0; z-index: 0; }
.book-row.ask .depth { background: var(--down-bg); }
.book-row.bid .depth { background: var(--up-bg); }
.book-row .px { z-index: 1; }
.book-row.ask .px { color: var(--down); }
.book-row.bid .px { color: var(--up); }
/* our own on-chain orders — lighter + blue accent so they stand out from Binance liquidity */
.book-row.mine { background: rgba(47,107,255,0.16); box-shadow: inset 3px 0 0 var(--blue); }
.book-row.mine span { font-weight: 700; }
.book-row.mine .px { filter: brightness(1.55); }
.book-spread { display: flex; align-items: center; gap: 12px; padding: 8px 12px; font-size: 15px; font-weight: 700; border-block: 1px solid var(--border); }
.book-spread .muted { font-size: 12px; font-weight: 400; }

/* ===== Trades ===== */
.trades-panel { height: 220px; display: flex; flex-direction: column; }
.trade-list { overflow-y: auto; flex: 1; }
.trade-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px; padding: 2px 12px; font-size: 12px; }
.trade-row span:nth-child(2), .trade-row span:nth-child(3) { text-align: right; }

/* ===== Bottom ===== */
.bottom { margin: 0 8px 8px; display: flex; flex-direction: column; max-height: 220px; }
.bottom-tabs { display: flex; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.btab { background: transparent; border: 0; color: var(--muted); cursor: pointer; font-weight: 700; padding: 4px 4px; border-bottom: 2px solid transparent; }
.btab.active { color: var(--text); border-bottom-color: var(--blue); }
.badge { background: var(--blue-dim); color: var(--blue-hi); border-radius: 10px; padding: 1px 7px; font-size: 11px; margin-left: 4px; }
.bottom-body { overflow: auto; }
.otable { width: 100%; border-collapse: collapse; }
.otable th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 8px 12px; position: sticky; top: 0; background: var(--panel); }
.otable td { padding: 9px 12px; border-top: 1px solid var(--border); font-size: 12px; }
.tag { padding: 2px 7px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.tag.buy { color: var(--up); background: var(--up-bg); }
.tag.sell { color: var(--down); background: var(--down-bg); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; color: var(--muted); }
.btn-cancel { background: transparent; border: 1px solid var(--border); color: var(--muted); border-radius: 5px; padding: 4px 10px; cursor: pointer; }
.btn-cancel:hover { border-color: var(--down); color: var(--down); }

/* ===== Status bar ===== */
.statusbar { padding: 6px 16px; border-top: 1px solid var(--border); background: var(--panel); font-size: 12px; }
.statusbar .mono { color: var(--blue-hi); }

/* ===== Toast ===== */
.toast {
  position: fixed; right: 18px; bottom: 18px; z-index: 1000;
  max-width: 360px; padding: 12px 16px; border-radius: 8px;
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
  opacity: 0; transform: translateY(10px); pointer-events: none;
  transition: opacity .2s, transform .2s; font-size: 13px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { border-color: var(--up); }
.toast.error { border-color: var(--down); }
.toast.pending { border-color: var(--blue); }
.btn-cancel[disabled] { opacity: .4; cursor: not-allowed; }
.btn-cancel + .btn-cancel { margin-left: 6px; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
