/* Crypto order book trading simulator (/crypto-order-book.php). Full-height tool page on Terminal.Master.
   Layout and styling from the designer's "Crypto Trading Simulator" mock (layout B, live-sim parity):
   header | chart + market column (book over time & sales) + right rail (balance, ticket, position, orders) | footer. */
.ob-page {
    /* Trade buttons as in the design (a step brighter than the live sim's). */
    --s8-buy: #1FA75C; --s8-buy-hi: #25BB68; --s8-sell: #DE4551; --s8-sell-hi: #EC5460;
    position: relative; flex: 1; min-width: 0; min-height: 0; overflow: hidden;
    display: grid; gap: 1px; background: var(--s8-line);
    grid-template-columns: minmax(0, 1fr) 296px 330px;
    grid-template-rows: 52px minmax(0, 1fr) 28px;
    grid-template-areas: "bar bar bar" "chart market rail" "ft ft ft";
    font-size: 13px; line-height: 1.35; font-variant-numeric: tabular-nums;
}
.ob-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.ob-page .is-up, .ob-page .positive { color: var(--s8-up); }
.ob-page .is-down, .ob-page .negative { color: var(--s8-down); }
.ob-mut { color: var(--s8-fg-3); }
.ob-cap { font-size: 11px; letter-spacing: var(--s8-ls-caps); text-transform: uppercase; color: var(--s8-fg-3); font-weight: 600; }
.ob-panel { background: var(--s8-panel); min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.ob-page button { font: inherit; color: inherit; cursor: pointer; }
.ob-page button:disabled { cursor: default; opacity: .45; }
.ob-page button:focus-visible, .ob-page select:focus-visible, .ob-page input:focus-visible { outline: 2px solid var(--s8-accent-line); outline-offset: 1px; }

/* ---------- header ---------- */
.ob-bar { grid-area: bar; flex-direction: row; align-items: center; gap: 20px; padding: 0 16px; }
.ob-coins { display: flex; gap: 5px; flex-shrink: 0; }
.ob-coin { height: 30px; padding: 0 12px; border-radius: 15px; border: 1px solid var(--s8-line-2); background: none; font-weight: 600; font-size: 12.5px; color: var(--s8-fg-2); }
.ob-coin:hover { color: #fff; border-color: var(--s8-line-3); }
.ob-coin.is-active { border-color: var(--s8-accent); background: var(--s8-accent-tint); color: #fff; }
.ob-allc { position: relative; flex-shrink: 0; margin: 0; }
.ob-allc select { appearance: none; -webkit-appearance: none; height: 30px; padding: 0 30px 0 12px; border: 1px solid var(--s8-line-2); border-radius: 5px; background: var(--s8-inset); color: var(--s8-fg); font: 600 12.5px var(--s8-sans); cursor: pointer; }
.ob-allc select:hover { border-color: var(--s8-line-3); }
.ob-allc::after, .ob-ph__ctl::after { content: ""; position: absolute; right: 12px; top: 50%; width: 6px; height: 6px; margin-top: -5px; border-right: 1.5px solid var(--s8-fg-3); border-bottom: 1.5px solid var(--s8-fg-3); transform: rotate(45deg); pointer-events: none; }
.ob-vsep { width: 1px; align-self: stretch; margin: 12px 0; background: var(--s8-line); flex-shrink: 0; }
.ob-tick { display: flex; flex-direction: column; gap: 1px; white-space: nowrap; }
.ob-tick .ob-cap { font-size: 10.5px; }
.ob-big { font-size: 20px; font-weight: 600; color: var(--s8-fg); }
.ob-big small { font-size: 12.5px; margin-left: 7px; font-weight: 600; }
.ob-stats { display: flex; gap: 26px; min-width: 0; margin: 0 0 0 auto; overflow: hidden; flex-shrink: 1; }
.ob-stats div { display: flex; flex-direction: column; gap: 3px; white-space: nowrap; }
.ob-stats .ob-cap { font-size: 10.5px; }
.ob-stats dd { margin: 0; font-size: 14px; font-weight: 600; color: var(--s8-fg); }

/* ---------- chart ---------- */
.ob-chart { grid-area: chart; position: relative; background: #060709; }
.ob-chart__body { position: absolute; inset: 0; }
.ob-chart .sc-chart-container { border-radius: 0; box-shadow: none; }
.ob-msg { position: absolute; inset: 0; z-index: 2; display: flex; align-items: center; justify-content: center; padding: 16px; text-align: center; color: var(--s8-fg-2); background: #060709; }
.ob-msg[hidden] { display: none; }

/* ---------- market column: book + time & sales ---------- */
.ob-market { grid-area: market; }
.ob-ph { height: 40px; flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 14px; border-bottom: 1px solid var(--s8-line); }
.ob-ph h2 { margin: 0; font-size: 14px; font-weight: 600; color: var(--s8-fg); }
.ob-ph--tape { border-top: 1px solid var(--s8-line); }
.ob-ph__ctl { position: relative; display: flex; align-items: center; gap: 8px; margin: 0; font-size: 12px; font-weight: 500; color: var(--s8-fg-3); }
.ob-select { appearance: none; -webkit-appearance: none; height: 26px; padding: 0 26px 0 10px; border: 1px solid var(--s8-line-2); border-radius: 4px; background: var(--s8-inset); color: var(--s8-fg); font: 600 12px var(--s8-sans); cursor: pointer; }
.ob-ph__ctl::after { right: 10px; }
.ob-imb { padding: 9px 14px; display: flex; flex-direction: column; gap: 6px; flex: none; border-bottom: 1px solid var(--s8-line); }
.ob-imb__t { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; font-weight: 600; }
.ob-imb__t > * { white-space: nowrap; }
.ob-imb__t .ob-mut { font-weight: 500; }
.ob-imb__t--sm { font-size: 12px; }
.ob-ibar { height: 4px; border-radius: 2px; background: var(--s8-down); overflow: hidden; }
.ob-ibar i { display: block; height: 100%; width: 50%; background: var(--s8-up); transition: width .3s; }
.ob-bh { display: grid; grid-template-columns: 1.1fr 1fr 1fr 34px; column-gap: 10px; padding: 0 14px; height: 26px; align-items: center; flex: none; font-size: 11px; color: var(--s8-fg-4); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.ob-bh span:not(:first-child) { text-align: right; }
.ob-bh--tape { grid-template-columns: 1.15fr 1fr 1fr .8fr; }

/* Book ladder. Asks run bottom-up so the best ask always sits on the spread row and the far levels are
   the ones clipped when the column is short. */
.ob-side { flex: 1 1 0; min-height: 0; display: flex; overflow: hidden; }
.ob-side--asks { flex-direction: column-reverse; }
.ob-side--bids { flex-direction: column; }
/* Far levels are clipped by the column height; fade them out instead of cutting a row in half. */
.ob-side--asks { -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 22px); mask-image: linear-gradient(to bottom, transparent 0, #000 22px); }
.ob-side--bids { -webkit-mask-image: linear-gradient(to top, transparent 0, #000 22px); mask-image: linear-gradient(to top, transparent 0, #000 22px); }
.ob-row { position: relative; display: grid; grid-template-columns: 1.1fr 1fr 1fr 34px; column-gap: 10px; flex: none; height: 20px; align-items: center; padding: 0 14px; font-size: 13px; color: var(--s8-fg); cursor: pointer; }
.ob-row:hover { background: var(--s8-hover); }
.ob-row > span { position: relative; z-index: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: right; }
.ob-row > span:first-of-type { text-align: left; }
.ob-row__n { color: var(--s8-fg-4); font-size: 12px; }
.ob-row__bar { position: absolute; right: 0; top: 1px; bottom: 1px; width: 0; z-index: 0; transition: width .15s linear; }
.ob-side--asks .ob-row > span:first-of-type { color: var(--s8-down); }
.ob-side--bids .ob-row > span:first-of-type { color: var(--s8-up); }
.ob-side--asks .ob-row__bar { background: rgba(255, 110, 122, .13); }
.ob-side--bids .ob-row__bar { background: rgba(62, 214, 155, .13); }
.ob-row.is-empty { cursor: default; }
.ob-row.is-empty:hover { background: none; }
.ob-row.is-empty > span { visibility: hidden; }
.ob-row.is-wall .ob-row__size { color: #fff; font-weight: 600; }
/* Working order at this price: accent dot before the price (as in the design). */
.ob-row__ord { position: absolute; left: 4px; top: 50%; z-index: 2; width: 6px; height: 6px; margin-top: -3px; border-radius: 50%; background: var(--s8-accent); display: none; }
.ob-row.has-buy .ob-row__ord, .ob-row.has-sell .ob-row__ord { display: block; }
.ob-row.flash-up .ob-row__size { animation: ob-flash-up .6s ease-out; }
.ob-row.flash-down .ob-row__size { animation: ob-flash-down .6s ease-out; }
@keyframes ob-flash-up { from { background: var(--s8-up-line); } to { background: transparent; } }
@keyframes ob-flash-down { from { background: var(--s8-down-line); } to { background: transparent; } }
.ob-mid { display: flex; justify-content: space-between; align-items: center; height: 34px; padding: 0 14px; margin: 2px 0; flex: none; border-top: 1px solid var(--s8-line); border-bottom: 1px solid var(--s8-line); background: var(--s8-panel-2); }
.ob-mid b { font-size: 16px; font-weight: 600; color: var(--s8-fg); }
.ob-mid b.is-up { color: var(--s8-up); }
.ob-mid b.is-down { color: var(--s8-down); }
.ob-mid span { font-size: 12px; color: var(--s8-fg-3); }
.ob-bhint { height: 28px; flex: none; display: flex; align-items: center; justify-content: center; font-size: 11.5px; color: var(--s8-fg-4); border-top: 1px solid var(--s8-line); }

/* Time & sales */
.ob-tape { flex: 1.15 1 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.ob-print { display: grid; grid-template-columns: 1.15fr 1fr 1fr .8fr; padding: 0 14px; height: 20px; align-items: center; font-size: 13px; color: var(--s8-fg-2); }
.ob-print > span { text-align: right; white-space: nowrap; overflow: hidden; }
.ob-print > span:first-child { text-align: left; color: var(--s8-fg-4); }
.ob-print.is-buy > span:nth-child(2) { color: var(--s8-up); }
.ob-print.is-sell > span:nth-child(2) { color: var(--s8-down); }
.ob-print.is-big { font-weight: 600; color: #fff; }
.ob-print.is-big.is-buy { background: rgba(62, 214, 155, .11); }
.ob-print.is-big.is-sell { background: rgba(255, 110, 122, .11); }
.ob-print.is-new { animation: ob-in .4s ease-out; }
@keyframes ob-in { from { background: var(--s8-hover); } }
.ob-print__lv { color: var(--s8-fg-4); font-weight: 500; font-size: 11px; margin-left: 3px; }
.ob-empty { padding: 24px 12px; text-align: center; color: var(--s8-fg-3); font-size: 12px; }

/* ---------- right rail ---------- */
.ob-rail { grid-area: rail; display: flex; flex-direction: column; gap: 8px; padding: 8px; min-width: 0; min-height: 0; overflow-y: auto; background: var(--s8-bg); }
.ob-rail__h { display: flex; align-items: center; justify-content: space-between; height: 32px; padding: 0 6px; flex: none; }
.ob-rail__h > .ob-cap { display: flex; align-items: center; gap: 8px; color: var(--s8-fg-2); }
.ob-rail__h > .ob-cap i, .ob-conn i { width: 7px; height: 7px; border-radius: 50%; background: var(--s8-up); }
.ob-conn { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; letter-spacing: var(--s8-ls-caps); text-transform: uppercase; font-weight: 600; color: var(--s8-warn); }
.ob-conn i { background: var(--s8-warn); }
.ob-conn.is-live { color: var(--s8-up); }
.ob-conn.is-live i { background: var(--s8-up); animation: ob-pulse 2s infinite; }
.ob-conn.is-down { color: var(--s8-down); }
.ob-conn.is-down i { background: var(--s8-down); }
@keyframes ob-pulse { 50% { opacity: .35; } }
.ob-card { flex: none; background: var(--s8-panel); border: 1px solid var(--s8-line); border-radius: 6px; overflow: hidden; }
.ob-card__h { display: flex; justify-content: space-between; align-items: center; }
.ob-card__h .ob-cap b { color: #fff; margin-left: 4px; }
.ob-kv, .ob-kvs > div { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13px; color: var(--s8-fg-3); }
.ob-kv b, .ob-kv dd { margin: 0; color: var(--s8-fg); font-weight: 600; white-space: nowrap; }
.ob-kvs { display: flex; flex-direction: column; gap: 6px; padding-top: 4px; margin: 0; }
.ob-kvs dt { white-space: nowrap; }
.ob-lnk { padding: 0; border: 0; background: none; font-size: 12px; font-weight: 600; color: var(--s8-accent-fg) !important; }
.ob-lnk:hover { color: #fff !important; }
.ob-lnk[hidden] { display: none; }

/* Balance */
.ob-bal { display: flex; flex-direction: column; gap: 6px; padding: 14px 16px; }
.ob-bal__v { font-size: 34px; font-weight: 700; letter-spacing: -.01em; color: var(--s8-fg); }
.ob-bal__all { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.ob-bal__all b { font-weight: 600; color: var(--s8-fg); }
.ob-pill { padding: 1px 7px; border-radius: 10px; background: var(--s8-up-tint); font-weight: 600; font-size: 12px; color: var(--s8-up); }
.ob-pill.is-down { background: var(--s8-down-tint); color: var(--s8-down); }
.ob-pill:empty { display: none; }

/* Ticket */
.ob-order { display: flex; flex-direction: column; }
.ob-tabs { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--s8-line); }
.ob-tabs button { height: 40px; margin-bottom: -1px; border: 0; border-bottom: 2px solid transparent; background: none; font-weight: 600; font-size: 14px; color: var(--s8-fg-3) !important; }
.ob-tabs button:hover { color: #fff !important; }
.ob-tabs button[aria-selected="true"] { color: #fff !important; border-bottom-color: var(--s8-accent); }
.ob-order__body { display: flex; flex-direction: column; gap: 9px; padding: 12px 14px 14px; }
.ob-inp { display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; background: var(--s8-inset); border: 1px solid var(--s8-line-2); border-radius: 5px; }
.ob-inp[hidden] { display: none; }
.ob-inp:focus-within { border-color: var(--s8-accent-line); box-shadow: var(--s8-focus); }
.ob-inp input { flex: 1; min-width: 0; background: none; border: 0; outline: 0 !important; color: #fff; font: 600 15px var(--s8-sans); }
.ob-inp input::placeholder { color: var(--s8-fg-4); font-weight: 500; font-size: 12.5px; }
.ob-inp__cur { color: var(--s8-fg-3); font-weight: 600; }
.ob-inp .ob-mut { font-size: 12.5px; white-space: nowrap; }
.ob-chips { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.ob-chips button { height: 28px; border: 1px solid var(--s8-line-2); background: var(--s8-panel-2); border-radius: 4px; font-weight: 600; font-size: 12px; color: var(--s8-fg-2) !important; }
.ob-chips button:hover { color: #fff !important; border-color: var(--s8-line-3); }
.ob-chips button[aria-pressed="true"] { border-color: var(--s8-accent); background: var(--s8-accent-tint); color: #fff !important; }
.ob-hits { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 2px; }
.ob-hit { position: relative; display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 0; padding: 9px 6px; border: 0; border-radius: 5px; color: #fff !important; }
.ob-hit--buy { background: var(--s8-buy); }
.ob-hit--buy:not(:disabled):hover { background: var(--s8-buy-hi); }
.ob-hit--sell { background: var(--s8-sell); }
.ob-hit--sell:not(:disabled):hover { background: var(--s8-sell-hi); }
.ob-hit__lbl { font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.ob-hit b { font-size: 17px; font-weight: 700; }
.ob-hit small { font-size: 11px; opacity: .85; white-space: nowrap; }
.ob-hit kbd { position: absolute; top: 6px; right: 6px; padding: 1px 4px; border-radius: 3px; background: rgba(0, 0, 0, .25); color: rgba(255, 255, 255, .85); font: 600 10px var(--s8-sans); box-shadow: none; }

/* Position */
.ob-pos { display: flex; flex-direction: column; gap: 6px; padding: 14px; }
.ob-badge { display: grid; place-items: center; height: 20px; padding: 0 7px; border: 1px solid var(--s8-line-2); border-radius: 3px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--s8-fg-2); }
.ob-badge.is-long { border-color: var(--s8-up-line); background: var(--s8-up-tint); color: var(--s8-up); }
.ob-badge.is-short { border-color: var(--s8-down-line); background: var(--s8-down-tint); color: var(--s8-down); }
.ob-pos__l { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; min-width: 0; }
.ob-pos__l b { font-size: 18px; font-weight: 600; color: var(--s8-fg); white-space: nowrap; }
.ob-pos__l b.is-up { color: var(--s8-up); }
.ob-pos__l b.is-down { color: var(--s8-down); }
.ob-pos__btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 2px; }
.ob-ghost { height: 32px; border: 1px solid var(--s8-line-2); border-radius: 5px; background: var(--s8-panel-2); font-weight: 600; font-size: 13px; color: var(--s8-fg) !important; }
.ob-ghost:not(:disabled):hover { border-color: var(--s8-line-3); background: var(--s8-hover); }

/* Working orders */
.ob-ords { flex: 1 0 auto; display: flex; flex-direction: column; gap: 6px; padding: 14px; }
.ob-orders { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.ob-orders li { display: grid; grid-template-columns: 36px 1fr auto auto; gap: 10px; align-items: center; height: 24px; font-size: 12.5px; color: var(--s8-fg-2); }
.ob-orders li.ob-orders__none { display: block; height: auto; font-size: 13px; line-height: 1.45; color: var(--s8-fg-3); }
.ob-orders .is-up, .ob-orders .is-down { font-weight: 600; }

/* ---------- footer ---------- */
.ob-ft { grid-area: ft; flex-direction: row; align-items: center; padding: 0 14px; font-size: 12px; color: var(--s8-fg-4); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* The master's "More about simul8or" pill sits at the right end of the footer bar, as in the design. */
body:has(.ob-page) .s8-footer-pill { left: auto; right: 10px; bottom: 3px; transform: none; height: 22px; padding: 0 12px; font-size: 12px; font-weight: 600; box-shadow: none; }

/* ---------- scrollbars: thin, themed, no arrow buttons ---------- */
.ob-tape::-webkit-scrollbar, .ob-rail::-webkit-scrollbar, .ob-page::-webkit-scrollbar { width: 8px; height: 8px; }
.ob-tape::-webkit-scrollbar-track, .ob-rail::-webkit-scrollbar-track, .ob-page::-webkit-scrollbar-track { background: transparent; }
.ob-tape::-webkit-scrollbar-thumb, .ob-rail::-webkit-scrollbar-thumb, .ob-page::-webkit-scrollbar-thumb { background: var(--s8-line-2); border: 2px solid transparent; background-clip: content-box; border-radius: var(--s8-r-pill); }
.ob-tape::-webkit-scrollbar-thumb:hover, .ob-rail::-webkit-scrollbar-thumb:hover, .ob-page::-webkit-scrollbar-thumb:hover { background: var(--s8-line-3); background-clip: content-box; }
.ob-tape::-webkit-scrollbar-button, .ob-rail::-webkit-scrollbar-button, .ob-page::-webkit-scrollbar-button { display: none; }
/* Chrome/Edge 121+ ignore the ::-webkit-scrollbar rules (and draw arrow buttons) when the standard
   properties are set, so those are for Firefox only. */
@supports not selector(::-webkit-scrollbar) {
    .ob-tape, .ob-rail, .ob-page { scrollbar-width: thin; scrollbar-color: var(--s8-line-2) transparent; }
}

@media (prefers-reduced-motion: reduce) {
    .ob-row__bar, .ob-ibar i { transition: none; }
    .ob-row.flash-up .ob-row__size, .ob-row.flash-down .ob-row__size, .ob-print.is-new, .ob-conn.is-live i { animation: none; }
}
@media (max-width: 1500px) {
    .ob-coin:nth-child(n+6) { display: none; }
    .ob-stats { gap: 18px; }
}
@media (max-width: 1380px) {
    .ob-stats div:nth-child(n+5) { display: none; }
}
/* The master header + ticker bar take ~100px the mock did not have, so compact sooner. */
@media (max-height: 960px) {
    .ob-bal { padding: 10px 14px; }
    .ob-bal__v { font-size: 28px; }
    .ob-order__body { gap: 7px; padding: 10px 12px 12px; }
    .ob-tabs button { height: 36px; }
    .ob-pos, .ob-ords { padding: 10px 14px; }
}
/* Narrow screens: chart on top, then the market column and the rail side by side; the page scrolls. */
@media (max-width: 1100px) {
    .ob-page { overflow-y: auto; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: max-content 60vh 760px max-content; grid-template-areas: "bar bar" "chart chart" "market rail" "ft ft"; }
    .ob-bar { flex-wrap: wrap; row-gap: 8px; padding: 10px 16px; }
    .ob-stats { margin-left: 0; flex-basis: 100%; }
    .ob-ft { white-space: normal; padding: 6px 14px 44px; }
}
@media (max-width: 640px) {
    .ob-page { grid-template-columns: minmax(0, 1fr); grid-template-rows: max-content max-content 46vh 760px max-content; grid-template-areas: "bar" "rail" "chart" "market" "ft"; }
    .ob-coins { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
    .ob-coin:nth-child(n+6) { display: inline-block; }
    .ob-vsep { display: none; }
    .ob-stats { gap: 14px; }
    .ob-stats div:nth-child(n+4) { display: none; }
    .ob-rail { overflow: visible; }
    .ob-ords { flex: none; }
}

/* No keyboard on touch devices. */
@media (pointer: coarse) { .ob-hit kbd { display: none; } }
