/* ===== 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; }
/* Right column can hold more than fits (real book + Binance mirror + trades):
   the real book stays pinned at the top, the reference blocks scroll below it. */
.right { overflow-y: auto; }

/* ===== 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 { position: relative; height: 340px; min-height: 160px; 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; min-height: 0; overflow-y: auto; }
.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; }
/* flex-shrink:0 so the track never collapses to 0 in a tight column; padding gives a
   comfortable grab zone around the 4px bar (background-clip keeps the bar itself thin). */
.slider { flex: 0 0 auto; height: 4px; background: var(--border); border-radius: 4px; position: relative; margin: 10px 4px; padding: 8px 0; background-clip: content-box; cursor: pointer; touch-action: none; }
.slider .dot { position: absolute; left: 0; top: 50%; width: 13px; height: 13px; background: var(--blue); border-radius: 50%; transform: translate(-2px, -50%); pointer-events: none; box-shadow: 0 0 0 3px rgba(47,107,255,.18); }
.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); }
.btn-buy[disabled], .btn-sell[disabled] { filter: grayscale(.6) brightness(.7); cursor: not-allowed; }

/* ===== Market mode: worst-price preview (shown before signing) ===== */
.market-info { display: flex; flex-direction: column; gap: 6px; padding: 9px 10px; margin-top: 2px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; font-size: 12px; }
.market-info[hidden] { display: none; }  /* explicit display above would otherwise beat the [hidden] attribute */
.mkt-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); }
.mkt-row b { color: var(--text); }
.mkt-slip-wrap { display: inline-flex; align-items: center; gap: 4px; }
.mkt-slip { width: 46px; background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 4px; padding: 3px 6px; text-align: right; outline: none; }
.mkt-slip-wrap b { color: var(--muted); }
/* the worst-price line is the headline the user confirms — make it stand out */
.mkt-worst { margin-top: 1px; padding-top: 6px; border-top: 1px dashed var(--border); color: var(--text); }
.mkt-worst b { color: var(--blue-hi); font-size: 13px; font-weight: 700; }
.mkt-warn { color: #e7c45a; background: rgba(216,162,0,.10); border: 1px solid rgba(216,162,0,.30); border-radius: 5px; padding: 6px 8px; line-height: 1.45; }

/* ===== 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; min-height: 0; 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); }
.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; }

/* ===== Two separate books: REAL escrows vs Binance reference ===== */
/* Source badge in panel heads — makes "what am I looking at" unmissable. */
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.src-badge { font-size: 10px; font-weight: 700; letter-spacing: .3px; padding: 2px 7px; border-radius: 999px; white-space: nowrap; text-transform: uppercase; }
.src-badge.real   { color: var(--up);   background: var(--up-bg);   border: 1px solid rgba(22,199,132,.35); }
.src-badge.mirror { color: #d8a200;     background: rgba(216,162,0,.10); border: 1px solid rgba(216,162,0,.40); }

/* REAL book — DOMINANT: takes most of the column, brighter surface, larger
   rows + spread, strong green frame. This is where the eye should land first. */
.realbook { flex: 3 1 auto; min-height: 320px;
  background: linear-gradient(180deg, rgba(22,199,132,.06), var(--panel) 60%);
  border-color: rgba(22,199,132,.45); box-shadow: 0 0 0 1px rgba(22,199,132,.08); }
.realbook-head { background: linear-gradient(90deg, var(--up-bg), transparent); }
.realbook-sub { padding: 7px 12px 2px; font-size: 12px; color: var(--muted); }
.realbook .book-row { padding: 4px 12px; font-size: 13px; }
.realbook .book-row .px { font-size: 14px; font-weight: 600; }
.realbook .book-spread { font-size: 18px; padding: 10px 12px; }
.book-empty { padding: 26px 16px; font-size: 13px; color: var(--text); text-align: center; line-height: 1.7; }

/* Binance MIRROR — visually DEMOTED: small, faint, dashed, monochrome, few levels.
   Deliberately lighter in mass than the real book so it can't read as the main book. */
.mirror-panel { flex: 0 0 auto; opacity: .72; border-style: dashed; border-color: rgba(216,162,0,.40); background: var(--panel-2); }
.mirror-head { background: rgba(216,162,0,.06); padding: 7px 12px; }
.mirror-head .panel-title { font-size: 12px; }
.mirror-warn { display: flex; align-items: center; gap: 6px; padding: 6px 12px; font-size: 10.5px; color: #e7c45a;
  background: rgba(216,162,0,.08); border-bottom: 1px solid rgba(216,162,0,.20); }
.mirror-warn b { color: #ffd84d; }
.mirror-warn-icon { font-size: 12px; }
.mirror-panel .book-cols { font-size: 10px; padding: 5px 12px 2px; }
/* Mirror rows are small + monochrome (no tradable green/red) so they never read as a live book. */
.mirror-panel .book-asks, .mirror-panel .book-bids { flex: 0 0 auto; max-height: 76px; }
.mirror-panel .book-row { cursor: default; padding: 1px 12px; font-size: 10.5px; }
.mirror-panel .book-row .px { font-size: 10.5px; font-weight: 400; }
.mirror-panel .book-row.ask .px, .mirror-panel .book-row.bid .px { color: var(--muted); }
.mirror-panel .book-row.ask .depth, .mirror-panel .book-row.bid .depth { background: rgba(123,133,160,.08); }
.mirror-mid { font-size: 12px; padding: 5px 12px; font-weight: 600; }

/* ===== Trades ===== */
.trades-panel { flex: 0 0 auto; height: 170px; 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 { position: relative; margin: 0 8px 8px; display: flex; flex-direction: column; height: 220px; min-height: 120px; }
/* grab the top edge of a panel and drag up/down to resize it (the flexible sibling
   above shrinks/grows to fit). Used on the orders panel AND the order form. */
.edge-resize { position: absolute; top: -5px; left: 0; right: 0; height: 10px; cursor: ns-resize; z-index: 6; }
.edge-resize::after { content: ""; position: absolute; left: 50%; top: 3px; transform: translateX(-50%); width: 44px; height: 3px; border-radius: 2px; background: var(--border); transition: background .15s; }
.edge-resize:hover::after, .resizing .edge-resize::after { background: var(--blue); }
.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; flex: 1; min-height: 0; }
.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; }

/* ===== Honest fill: status chips + per-order breakdown row ===== */
.status-chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; border: 1px solid transparent; }
.status-chip.resting   { color: var(--muted); background: rgba(123,133,160,.12); border-color: rgba(123,133,160,.30); }
.status-chip.partial   { color: #d8a200; background: rgba(216,162,0,.12); border-color: rgba(216,162,0,.40); }
.status-chip.filled    { color: var(--up); background: var(--up-bg); border-color: rgba(22,199,132,.40); }
.status-chip.cancelled { color: var(--down); background: var(--down-bg); border-color: rgba(234,57,67,.35); }
.status-chip.withdrawn { color: var(--muted); background: transparent; border-color: var(--border); }

/* compact by default: each order is ONE row; the honest breakdown expands on click */
.ord-main { cursor: pointer; }
.ord-main:hover { background: rgba(47,107,255,.05); }
.ord-toggle { display: inline-block; width: 12px; margin-right: 5px; color: var(--muted); font-size: 10px; transition: transform .15s; }
.ord-toggle.open { transform: rotate(90deg); }
/* detail row sits attached UNDER its order: no top border, indented, faint surface */
.ord-detail td { border-top: 0 !important; padding: 2px 12px 12px 30px; font-size: 12px; line-height: 1.55; color: var(--text); background: var(--panel-2); }
.ord-detail b { font-weight: 700; }
.improve { color: var(--up); font-weight: 700; }

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