/* =================================================================
   MIZORA TERMINAL v2 - institutional cut.
   Density is the aesthetic: more data per pixel, numerals right-
   aligned on a strict tabular grid, color rationed to meaning.
   Type scale: 19/13/11/10/9/8.5/8/7.5 - nothing between.
   ================================================================= */
:root {
  --ground: #070404;
  --panel:  #0c0807;
  --head:   #0a0605;
  --input:  #120b09;
  --hover:  #170e0b;

  --line:   #221410;
  --line-soft: rgba(34, 20, 16, .55);
  --line2:  #331c14;

  --ink:    #ece4d8;
  --dim:    #9d9084;
  --faint:  #675a4f;
  --ghost:  #3b322b;

  --red:    #e0281e;
  --red-2:  #b0170f;
  --red-dim: rgba(224, 40, 30, .1);
  --label:  rgba(220, 72, 52, .78);

  --green:  #2fbf68;
  --up-flash: rgba(47, 191, 104, .16);
  --dn-flash: rgba(224, 40, 30, .16);

  --mono: 'DM Mono', 'SF Mono', Consolas, monospace;
  --sans: 'Inter', -apple-system, sans-serif;
  --jp: 'Noto Sans JP', 'Hiragino Sans', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: var(--ground);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 11px;
  overflow: hidden;
  display: flex; flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

.pos { color: var(--green) !important; }
.neg { color: var(--red) !important; }
::selection { background: var(--red); color: #fff; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line2); }
::-webkit-scrollbar-thumb:hover { background: #45261a; }

a:focus-visible, button:focus-visible, input:focus-visible {
  outline: 1.5px solid var(--red); outline-offset: 1px;
}

/* =================================================================
   TOP BAR - 44px, one line of truth
   ================================================================= */
.tbar {
  display: flex; align-items: center; gap: 18px;
  height: 44px; padding: 0 12px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.tbar__brand { display: flex; align-items: center; gap: 9px; }
.tbar__logo { width: 22px; height: 22px; }
.tbar__name { font-family: var(--sans); font-size: 12.5px; font-weight: 800; letter-spacing: .3em; padding-top: 1px; }
.tbar__live {
  display: inline-flex; align-items: center; gap: 6px;
  margin-left: 8px; padding: 3px 8px;
  border: 1px solid var(--line);
  font-size: 7.5px; letter-spacing: .22em; text-transform: uppercase;
  color: var(--dim);
}
.tbar__live i { width: 5px; height: 5px; border-radius: 50%; background: var(--green); animation: blink 2s infinite; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

.tbar__nav { display: flex; gap: 20px; margin: 0 auto; }
.tbar__nav a {
  position: relative;
  font-family: var(--sans);
  font-size: 9.5px; font-weight: 700;
  letter-spacing: .17em; text-transform: uppercase;
  color: var(--faint); text-decoration: none;
  padding: 14px 1px;
  transition: color .15s;
}
.tbar__nav a:hover { color: var(--dim); }
.tbar__nav a.active { color: var(--ink); }
.tbar__nav a.active::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -1px;
  height: 2px; background: var(--red);
}

.tbar__right { display: flex; align-items: center; gap: 14px; }
.tbar__account {
  padding: 5px 10px; border: 1px solid var(--line);
  font-size: 8.5px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--dim); cursor: default; white-space: nowrap;
}
.tbar__account .chev { color: var(--ghost); margin-left: 3px; }
.tbar__stat { display: flex; flex-direction: column; gap: 2px; }
.tbar__stat span { font-size: 7px; letter-spacing: .22em; text-transform: uppercase; color: var(--label); }
.tbar__stat b { font-size: 11px; font-weight: 500; font-variant-numeric: tabular-nums; color: var(--ink); white-space: nowrap; }
.conn-dot { display: inline-block; width: 5px; height: 5px; border-radius: 50%; background: #c9a227; margin-right: 5px; vertical-align: 1px; }
.conn-dot.ok { background: var(--green); }
.tbar__execute {
  padding: 9px 20px;
  background: var(--red); border: 1px solid var(--red);
  color: #fff;
  font-family: var(--sans);
  font-size: 9.5px; font-weight: 800; letter-spacing: .2em; text-transform: uppercase;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.tbar__execute:hover { background: var(--red-2); }
.tbar__execute:active { transform: translateY(1px); }

/* =================================================================
   GRID - 6px gutters, band mirrors the columns above it
   ================================================================= */
.grid {
  flex: 1; min-height: 0;
  display: grid;
  gap: 6px; padding: 6px;
  grid-template-columns: 264px 1fr 276px;
  grid-template-rows: minmax(0, 1fr) 196px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  display: flex; flex-direction: column;
  min-height: 0; min-width: 0;
  transition: box-shadow .3s;
}
.panel.focused { box-shadow: 0 0 0 1px var(--red), 0 0 22px rgba(224, 40, 30, .1); }

.panel__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 10px 6px;
  background: var(--head);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.panel__head h2 {
  font-family: var(--sans);
  font-size: 9px; font-weight: 800;
  letter-spacing: .18em; text-transform: uppercase;
  color: var(--ink);
  display: flex; align-items: baseline; gap: 8px;
  white-space: nowrap;
}
.panel__kanji { font-family: var(--jp); font-size: 8px; font-weight: 700; letter-spacing: .16em; color: rgba(220, 72, 52, .42); }
.panel__foot {
  padding: 5px 10px; border-top: 1px solid var(--line);
  font-size: 7.5px; letter-spacing: .2em; text-transform: uppercase; color: var(--ghost);
  flex-shrink: 0;
}

.panel--watch { grid-column: 1; grid-row: 1; }
.panel--chart { grid-column: 2; grid-row: 1; }
.rail { grid-column: 3; grid-row: 1; display: flex; flex-direction: column; gap: 6px; min-height: 0; }
.rail .panel:first-child { flex: 0 0 auto; }
.rail .panel--positions { flex: 1 1 auto; }

.band {
  grid-column: 1 / -1; grid-row: 2;
  display: grid;
  grid-template-columns: 264px 1fr 1.3fr 1fr 276px;
  gap: 6px;
  min-height: 0;
}
.band .panel { min-height: 0; }

/* =================================================================
   MARKET WATCH - 30px rows, numerals on the right rail
   ================================================================= */
.market-tabs { display: flex; gap: 1px; }
.market-tabs button {
  background: transparent; border: 1px solid var(--line);
  color: var(--faint);
  font-family: var(--mono); font-size: 7.5px; letter-spacing: .1em; text-transform: uppercase;
  padding: 3px 6px; cursor: pointer;
  transition: color .12s, border-color .12s;
}
.market-tabs button:hover { color: var(--dim); }
.market-tabs button.on { color: var(--ink); border-color: rgba(224, 40, 30, .55); background: var(--red-dim); }

.watch-cols {
  display: grid;
  grid-template-columns: 1fr 78px 48px 48px;
  gap: 5px; padding: 5px 10px 4px;
  font-size: 7px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--ghost);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.watch-cols span:nth-child(2), .watch-cols span:nth-child(3), .watch-cols span:nth-child(4) { text-align: right; }

.watch { flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0; }
.watch-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 78px 48px 48px;
  gap: 5px; align-items: center;
  height: 30px; padding: 0 10px;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  transition: background .12s;
}
.watch-row:nth-child(odd) { background: rgba(255, 252, 245, .012); }
.watch-row:hover { background: var(--hover); }
.watch-row.on { background: rgba(224, 40, 30, .07); }
.watch-row.on::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: -1px;
  width: 2px; background: var(--red);
}
.w-id { min-width: 0; overflow: hidden; }
.w-id b { font-family: var(--sans); font-size: 10.5px; font-weight: 800; letter-spacing: .05em; }
.w-last {
  font-size: 10.5px; font-weight: 500; font-variant-numeric: tabular-nums;
  text-align: right; padding: 2px 3px; margin: 0 -3px;
  transition: background .25s;
}
.w-last.f-up { background: var(--up-flash); transition: none; }
.w-last.f-dn { background: var(--dn-flash); transition: none; }
.w-chg { font-size: 9px; font-variant-numeric: tabular-nums; text-align: right; }
.w-spark { width: 48px; height: 18px; justify-self: end; }

.watch-foot {
  padding: 5px 10px; border-top: 1px solid var(--line);
  font-size: 7.5px; letter-spacing: .16em; color: var(--ghost);
  display: flex; justify-content: flex-end;
  flex-shrink: 0;
}

/* =================================================================
   CHART - the head earns its height, then gets out of the way
   ================================================================= */
.chart-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px 6px; flex-shrink: 0;
}
.chart-id { display: flex; align-items: center; gap: 11px; }
.chart-sym {
  font-family: var(--sans); font-size: 27px; font-weight: 800; letter-spacing: 0; line-height: .9;
  padding-right: 11px; border-right: 1px solid var(--line2);
}
.chart-id__mid { display: flex; flex-direction: column; gap: 1px; }
.chart-sub { font-size: 7px; letter-spacing: .2em; text-transform: uppercase; color: var(--faint); }
.chart-px { font-family: var(--sans); font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.chart-chg { display: flex; flex-direction: column; gap: 1px; font-size: 9.5px; font-variant-numeric: tabular-nums; text-align: left; }
.chart-stats { display: flex; gap: 16px; }
.chart-stats > div { display: flex; flex-direction: column; gap: 2px; text-align: right; }
.chart-stats span { font-size: 7px; letter-spacing: .18em; text-transform: uppercase; color: var(--label); }
.chart-stats b { font-size: 10px; font-weight: 500; font-variant-numeric: tabular-nums; }

.chart-tools {
  display: flex; align-items: center;
  padding: 0 12px 4px; flex-shrink: 0; gap: 14px;
}
.tf-row { display: flex; gap: 0; }
.tf-row button {
  background: transparent; border: 0;
  color: var(--faint);
  font-family: var(--mono); font-size: 9px; letter-spacing: .04em;
  padding: 4px 7px; cursor: pointer;
}
.tf-row button:hover { color: var(--dim); }
.tf-row button.on { color: var(--red); box-shadow: inset 0 -2px 0 var(--red); }
.chart-note { font-size: 7.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--faint); margin-left: auto; }

.chart-legend {
  padding: 0 12px 4px; flex-shrink: 0;
  font-size: 8.5px; color: var(--dim); font-variant-numeric: tabular-nums;
  display: flex; gap: 13px; flex-wrap: wrap;
  min-height: 14px;
}
.chart-legend .lg-ohlc { color: var(--dim); letter-spacing: .02em; }
.chart-legend .lg-ema20 { color: #e0281e; }
.chart-legend .lg-ema50 { color: #c9a227; }
.chart-legend .lg-ema200 { color: #837a70; }

.chart-host { flex: 1; min-height: 0; position: relative; }

.session-strip {
  display: flex; align-items: center; gap: 2px;
  padding: 5px 12px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
  font-size: 7.5px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--faint);
}
.ss-label { color: var(--ghost); margin-right: 6px; }
.session-strip [data-sess] { padding: 3px 8px; border: 1px solid transparent; white-space: nowrap; }
.session-strip [data-sess].on {
  color: var(--ink);
  border-color: rgba(224, 40, 30, .5);
  background: var(--red-dim);
}
.ss-clock { margin-left: auto; color: var(--dim); letter-spacing: .08em; }

.chart-wait {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  pointer-events: none;
  color: var(--ghost);
}
.chart-wait b {
  font-family: var(--sans); font-size: 9px; font-weight: 800;
  letter-spacing: .3em; text-transform: uppercase; color: var(--faint);
}
.chart-wait span { font-size: 7.5px; letter-spacing: .2em; text-transform: uppercase; }
.chart-wait i {
  width: 5px; height: 5px; border-radius: 50%; background: var(--red);
  animation: blink 1.6s infinite;
}

/* =================================================================
   ORDER ENTRY - four fields, two rows, zero waste
   ================================================================= */
.ticket { padding: 9px 10px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.ticket-tabs { display: flex; border: 1px solid var(--line); flex-shrink: 0; }
.ticket-tabs button {
  flex: 1; padding: 6px 0;
  background: transparent; border: 0;
  color: var(--faint);
  font-family: var(--sans); font-size: 8px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase;
  cursor: pointer;
}
.ticket-tabs button.on { background: var(--red); color: #fff; }

.ticket-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.t-field { display: flex; flex-direction: column; gap: 4px; position: relative; }
.t-field span { font-size: 7px; letter-spacing: .18em; text-transform: uppercase; color: var(--label); }
.t-field input {
  width: 100%;
  background: var(--input);
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: var(--mono); font-size: 11.5px; font-variant-numeric: tabular-nums;
  padding: 6px 8px;
}
.t-field input:disabled { color: var(--faint); background: rgba(18, 11, 9, .5); border-style: dashed; }
.t-field input::-webkit-inner-spin-button, .t-field input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.t-field input[type=number] { -moz-appearance: textfield; appearance: textfield; }
.t-field input:focus { border-color: var(--red); outline: none; }
.t-field input::placeholder { color: var(--ghost); }
.t-calc {
  position: absolute; right: 7px; bottom: 7px;
  font-style: normal; font-size: 7.5px; color: var(--faint); font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.ticket-risk, .ticket-quotes {
  display: flex; justify-content: space-between;
  font-size: 7.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--faint);
}
.ticket-risk b, .ticket-quotes b { color: var(--ink); font-variant-numeric: tabular-nums; margin-left: 5px; letter-spacing: 0; font-size: 9.5px; }
.ticket-quotes b#tBid { color: var(--green); }
.ticket-quotes b#tAsk { color: var(--red); }

.ticket-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ticket-actions button {
  padding: 10px 4px;
  font-family: var(--sans); font-size: 11px; font-weight: 800; letter-spacing: .08em;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  transition: background .15s, border-color .15s, transform .1s;
}
.ticket-actions button:active { transform: translateY(1px); }
.ticket-actions small { font-size: 6.5px; font-weight: 700; letter-spacing: .24em; opacity: .65; }
.btn-buy { background: var(--red); border: 1px solid var(--red); color: #fff; }
.btn-buy:hover { background: var(--red-2); }
.btn-sell { background: transparent; border: 1px solid var(--line2); color: var(--ink); }
.btn-sell:hover { border-color: var(--red); }
.ticket-note { font-size: 6.5px; letter-spacing: .2em; text-transform: uppercase; color: var(--ghost); text-align: center; }

/* =================================================================
   POSITIONS
   ================================================================= */
.positions { overflow-y: auto; min-height: 0; }
.positions .empty {
  padding: 16px 10px; text-align: center;
  font-size: 7.5px; letter-spacing: .2em; text-transform: uppercase; color: var(--ghost);
}
.pos-card { padding: 7px 10px 8px; border-bottom: 1px solid var(--line-soft); }
.pos-card__top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 5px; }
.pos-card__sym { font-family: var(--sans); font-size: 11px; font-weight: 800; letter-spacing: .03em; }
.pos-card__tag { font-size: 7px; font-weight: 500; letter-spacing: .14em; padding: 2px 6px; }
.pos-card__tag.long { color: var(--green); border: 1px solid rgba(47, 191, 104, .4); }
.pos-card__tag.short { color: var(--red); border: 1px solid rgba(224, 40, 30, .45); }
.pos-card__grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.pos-card__grid > div { display: flex; flex-direction: column; gap: 1px; }
.pos-card__grid span { font-size: 6.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--ghost); }
.pos-card__grid b { font-size: 9.5px; font-weight: 500; font-variant-numeric: tabular-nums; }
.pos-card__close {
  margin-top: 6px; width: 100%;
  background: transparent; border: 1px solid var(--line2);
  color: var(--faint);
  font-family: var(--mono); font-size: 7px; letter-spacing: .2em; text-transform: uppercase;
  padding: 4px 0; cursor: pointer;
  transition: border-color .15s, color .15s;
}
.pos-card__close:hover { border-color: var(--red); color: var(--ink); }

/* =================================================================
   BOTTOM BAND
   ================================================================= */
.kv { padding: 3px 10px; overflow-y: auto; }
.kv > div {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4.5px 0;
  border-bottom: 1px solid var(--line-soft);
}
.kv > div:last-child { border-bottom: 0; }
.kv dt { font-size: 7.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--faint); }
.kv dd { font-size: 10px; font-weight: 500; font-variant-numeric: tabular-nums; }

.pf-spark { width: calc(100% - 20px); height: 34px; margin: 0 10px 7px; flex-shrink: 0; }

.trades-scroll { overflow: auto; min-height: 0; }
.trades { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.trades th {
  position: sticky; top: 0; background: var(--panel); z-index: 1;
  padding: 4px 10px; text-align: right;
  font-size: 7px; font-weight: 500; letter-spacing: .16em; text-transform: uppercase;
  color: var(--ghost);
  border-bottom: 1px solid var(--line);
}
.trades th:nth-child(1), .trades th:nth-child(2), .trades th:nth-child(3) { text-align: left; }
.trades td { padding: 3.5px 10px; font-size: 9.5px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; text-align: right; }
.trades td:nth-child(1), .trades td:nth-child(2), .trades td:nth-child(3) { text-align: left; }
.trades tbody tr:nth-child(odd) { background: rgba(255, 252, 245, .012); }
.trades .empty-row td { text-align: center; color: var(--ghost); font-size: 7.5px; letter-spacing: .2em; text-transform: uppercase; padding: 16px; }

.book-cols {
  display: grid; grid-template-columns: 1fr .7fr .7fr;
  padding: 4px 10px; gap: 5px;
  font-size: 7px; letter-spacing: .16em; text-transform: uppercase; color: var(--ghost);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.book-cols span:nth-child(2), .book-cols span:nth-child(3) { text-align: right; }
.book { flex: 1; overflow: hidden; min-height: 0; font-variant-numeric: tabular-nums; }
.book-row {
  position: relative;
  display: grid; grid-template-columns: 1fr .7fr .7fr;
  gap: 5px; padding: 2.5px 10px;
  font-size: 9px;
}
.book-row span:nth-child(2), .book-row span:nth-child(3) { text-align: right; }
.book-row .depth {
  position: absolute; top: 1px; bottom: 1px; right: 0;
  max-width: 58px;
  opacity: .13; pointer-events: none;
}
.book-row.ask { color: var(--red); }
.book-row.ask .depth { background: var(--red); }
.book-row.bid { color: var(--green); }
.book-row.bid .depth { background: var(--green); }
.book-row.mid {
  background: var(--red); color: #fff;
  font-weight: 500; font-size: 9.5px;
  padding: 3px 10px;
  margin: 1px 0;
}

.act-spark { width: calc(100% - 20px); height: 28px; margin: 6px 10px 3px; flex-shrink: 0; }
.activity { flex: 1; overflow-y: auto; min-height: 0; }
.act-row {
  display: grid; grid-template-columns: 46px 38px 1fr auto;
  gap: 7px; padding: 3.5px 10px;
  font-size: 8.5px; font-variant-numeric: tabular-nums;
  border-bottom: 1px solid var(--line-soft);
  color: var(--dim);
}
.act-row b { color: var(--ink); font-weight: 500; }
.act-row .side-buy { color: var(--green); }
.act-row .side-sell { color: var(--red); }

/* =================================================================
   FOOTER - 28px colophon
   ================================================================= */
.tfoot {
  display: flex; align-items: center; gap: 13px;
  height: 28px; padding: 0 12px;
  border-top: 1px solid var(--line);
  font-size: 7.5px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--faint);
  flex-shrink: 0;
}
.tfoot__jp { font-family: var(--jp); font-size: 9px; font-weight: 700; letter-spacing: .36em; color: var(--label); }
.tfoot__sep { width: 1px; height: 11px; background: var(--line2); }
.tfoot__grow { flex: 1; }
.tfoot b { color: var(--dim); font-weight: 500; letter-spacing: .06em; }
.tfoot__clock { color: var(--dim); letter-spacing: .08em; }
.tfoot__seal {
  font-family: var(--jp); font-size: 9.5px; font-weight: 700; letter-spacing: .18em;
  color: var(--red);
  border: 1px solid rgba(224, 40, 30, .5);
  padding: 2px 8px;
}

/* =================================================================
   RESPONSIVE
   ================================================================= */
@media (max-width: 1100px) {
  body { overflow: auto; }
  .grid { display: flex; flex-direction: column; height: auto; }
  .panel { min-height: 190px; }
  .panel--chart { min-height: 400px; }
  .band { display: flex; flex-direction: column; }
  .tbar { flex-wrap: wrap; height: auto; padding: 8px 12px; }
  .tbar__nav { order: 3; width: 100%; justify-content: flex-start; gap: 16px; overflow-x: auto; }
  .tbar__nav a { padding: 8px 1px; }
}
@media (prefers-reduced-motion: reduce) {
  .tbar__live i { animation: none; }
  .w-last.f-up, .w-last.f-dn { background: transparent; }
}
