:root {
  --bg: #f4f8fb;
  --panel: #ffffff;
  --elev: #eaf7e5;
  --line: #d0dde9;
  --text: #0a1628;
  --muted: #5b6b7c;
  --cyan: #6cf84c;
  --cyan-dark: #4fd636;
  --navy: #1f6b12;
  --navy-deep: #0f3d08;
  --blue: #3fae2a;
  --blue-soft: #e3fbdc;
  --green: #0d9f6e;
  --red: #d92d20;
  --danger: #ef4444;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
button, input, select { font: inherit; }
.terminal { display: flex; flex-direction: column; height: 100vh; background: var(--bg); }

.topbar {
  display: flex; align-items: center; gap: .5rem;
  height: 54px; padding: 0 .75rem;
  background: linear-gradient(180deg, #fff 0%, #f8fbfd 100%);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.brand-chip {
  display: flex; align-items: center; gap: .45rem;
  padding-right: .75rem; margin-right: .25rem;
  border-right: 1px solid var(--line);
  font-weight: 700; font-size: .85rem;
}
.brand-chip .brand-mark {
  width: 28px; height: 28px; border-radius: 6px;
}
.brand-chip .brand-name { font-weight: 700; letter-spacing: -.02em; color: var(--navy); }
.brand-chip .brand-sub {
  font-size: 10px; font-weight: 600; color: var(--cyan-dark);
  background: var(--blue-soft); padding: .15rem .4rem; border-radius: 4px;
  text-transform: uppercase; letter-spacing: .04em;
}
.metrics {
  display: flex; flex: 1; overflow-x: auto; gap: .1rem; align-items: center;
}
.metric {
  display: flex; flex-direction: column; min-width: 86px; padding: .15rem .55rem;
}
.metric span {
  font-size: 9px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600;
}
.metric b {
  font-size: .8rem; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--navy);
}
.metric b.danger { color: var(--danger); }
.metric b.up { color: var(--green); }
.metric b.down { color: var(--red); }
.top-actions { display: flex; align-items: center; gap: .45rem; }
.icon-btn {
  width: 32px; height: 32px; border: 0; border-radius: 8px; color: #fff;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.icon-btn.cyan { background: var(--cyan); }
.icon-btn.cyan:hover { background: var(--cyan-dark); }
.user-chip {
  position: relative; display: flex; align-items: center; gap: .5rem;
  padding: .2rem .7rem .2rem .2rem; border: 1px solid var(--line);
  border-radius: 999px; background: var(--bg); cursor: pointer;
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: .75rem; font-weight: 700;
}
.user-meta .name { font-size: .75rem; font-weight: 600; line-height: 1.15; }
.user-meta .uid { font-size: 10px; color: var(--muted); }
.user-dropdown {
  position: absolute; right: 0; top: calc(100% + 6px); width: 180px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 30px rgba(31,107,18,.14); z-index: 40; overflow: hidden;
}
.user-dropdown a, .user-dropdown button {
  display: block; width: 100%; text-align: left; padding: .65rem .85rem;
  border: 0; background: transparent; color: var(--text); font-size: .8rem; cursor: pointer;
  text-decoration: none;
}
.user-dropdown a:hover, .user-dropdown button:hover { background: var(--elev); }

.workspace {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 44px 260px;
  flex: 1; min-height: 0;
}
.watchlist {
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.wl-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .55rem .65rem; border-bottom: 1px solid var(--line);
  font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
}
.wl-head select {
  border: 1px solid var(--line); border-radius: 6px; background: var(--bg);
  font-size: .72rem; padding: .15rem .3rem; color: var(--navy);
}
.wl-search { padding: .45rem .55rem; border-bottom: 1px solid var(--line); }
.wl-search input {
  width: 100%; border: 1px solid var(--line); border-radius: 8px;
  padding: .4rem .55rem; background: var(--bg); font-size: .75rem; color: var(--text);
}
.wl-search input:focus { outline: 2px solid rgba(108,248,76,.3); border-color: var(--cyan); }
.wl-list { overflow: auto; flex: 1; }
.wl-item {
  display: grid; grid-template-columns: 1fr auto; gap: .15rem .4rem;
  padding: .6rem .65rem; border-bottom: 1px solid var(--elev); cursor: pointer;
  transition: background .12s ease;
}
.wl-item:hover { background: #f2fbef; }
.wl-item.on { background: var(--blue-soft); border-left: 3px solid var(--cyan); padding-left: calc(.65rem - 3px); }
.wl-item .sym { font-size: .8rem; font-weight: 700; color: var(--navy); }
.wl-item .chg { font-size: .72rem; font-variant-numeric: tabular-nums; text-align: right; font-weight: 600; }
.wl-item .bid, .wl-item .ask {
  font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.up { color: var(--green); }
.down { color: var(--red); }

.centre { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.chart-toolbar {
  display: flex; align-items: center; gap: .55rem; flex-wrap: wrap;
  padding: .4rem .65rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.cfd-badge {
  background: var(--navy); color: #fff; border: 0; border-radius: 6px;
  font-size: .7rem; font-weight: 700; padding: .3rem .55rem; letter-spacing: .04em;
}
.clock { font-size: .78rem; font-variant-numeric: tabular-nums; color: var(--muted); }
.spacer { flex: 1; }
.pair-btn {
  border: 1px solid var(--line); background: var(--bg); border-radius: 6px;
  padding: .25rem .55rem; font-weight: 700; font-size: .85rem; cursor: pointer; color: var(--navy);
}
.ohlc { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tf-group { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.tf-group button {
  border: 0; background: var(--panel); padding: .25rem .45rem; font-size: 11px; cursor: pointer; color: var(--muted);
}
.tf-group button.on { background: var(--cyan); color: #0a1628; }
.tool-mini {
  border: 1px solid var(--line); background: var(--panel); border-radius: 6px;
  padding: .25rem .45rem; font-size: 11px; cursor: pointer; color: var(--muted);
}
.chart-wrap { flex: 1; min-height: 0; position: relative; background: #fff; }
.chart { position: absolute; inset: 0; }

.bottom-panels {
  height: 220px; flex-shrink: 0; background: var(--panel);
  border-top: 1px solid var(--line); display: flex; flex-direction: column;
}
.tabs-row {
  display: flex; align-items: center; gap: .25rem; padding: .35rem .5rem 0;
  border-bottom: 1px solid var(--line); background: var(--elev);
}
.tab {
  border: 0; background: transparent; color: var(--blue);
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  padding: .55rem .75rem; border-radius: 8px 8px 0 0; cursor: pointer;
}
.tab.on { background: #fff; color: var(--navy); }
.tab .count {
  display: inline-flex; min-width: 16px; height: 16px; padding: 0 4px;
  align-items: center; justify-content: center; border-radius: 999px;
  background: var(--cyan); color: #0a1628; font-size: 10px; margin-left: .25rem;
}
.filter-btn {
  margin-left: .35rem; display: inline-flex; align-items: center; gap: .3rem;
  border: 1px solid var(--line); background: #fff; border-radius: 6px;
  padding: .3rem .55rem; font-size: 11px; color: var(--muted); cursor: pointer;
}
.tabs-utils { margin-left: auto; display: flex; gap: .25rem; }
.util {
  width: 28px; height: 28px; border: 1px solid var(--line); border-radius: 6px;
  background: #fff; cursor: pointer; color: var(--muted);
}
.table-scroll { flex: 1; overflow: auto; background: #fff; }
.pos-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.pos-table thead th {
  position: sticky; top: 0; background: var(--bg);
  text-align: left; padding: .45rem .55rem; font-size: 10px;
  text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700;
  white-space: nowrap; border-bottom: 1px solid var(--line);
}
.pos-table td {
  padding: .45rem .55rem; border-bottom: 1px solid var(--elev);
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
.pos-table tbody tr:hover { background: #f2fbef; }
.empty { text-align: center; color: var(--muted); padding: 1.5rem !important; }
.btn-close {
  border: 0; background: #fee2e2; color: #b91c1c; border-radius: 4px;
  padding: .15rem .45rem; font-size: 10px; font-weight: 700; cursor: pointer;
}
.btn-cancel {
  border: 0; background: #e2e8f0; color: #334155; border-radius: 4px;
  padding: .15rem .45rem; font-size: 10px; font-weight: 700; cursor: pointer;
}

.tool-rail {
  display: flex; flex-direction: column; align-items: center; gap: .35rem;
  padding: .5rem 0; background: var(--panel); border-left: 1px solid var(--line);
}
.rail-btn {
  width: 34px; height: 34px; border: 1px solid var(--cyan); border-radius: 8px;
  background: #fff; color: #1f6b12; display: inline-flex; align-items: center;
  justify-content: center; cursor: pointer;
}
.rail-btn.on, .rail-btn:hover { background: var(--blue-soft); }

.ticket {
  background: var(--panel); border-left: 1px solid var(--line);
  padding: .75rem; display: flex; flex-direction: column; gap: .55rem; overflow: auto;
}
.ticket-head { display: flex; align-items: center; justify-content: space-between; }
.ticket-head strong { font-size: 1rem; color: var(--navy); }
.live-pill {
  background: var(--green); color: #fff; font-size: 10px; font-weight: 700;
  padding: .15rem .4rem; border-radius: 4px; animation: pulse 2s ease infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .75; }
}
.bidask { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }
.side {
  border: 0; border-radius: 8px; padding: .55rem .4rem; cursor: pointer; color: #fff; text-align: left;
  transition: transform .1s ease, box-shadow .1s ease;
}
.side:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,.12); }
.side small { display: block; font-size: 10px; opacity: .9; }
.side b { font-size: .95rem; font-variant-numeric: tabular-nums; }
.side.sell { background: var(--red); }
.side.buy { background: var(--green); }
.side.active-sell, .side.active-buy { outline: 2px solid var(--navy); outline-offset: 1px; }

.order-type {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0;
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
}
.order-type .ot {
  border: 0; background: var(--bg); padding: .45rem; font-size: .75rem;
  font-weight: 700; cursor: pointer; color: var(--muted);
}
.order-type .ot.on { background: var(--navy); color: #fff; }

.stepper {
  display: grid; grid-template-columns: 32px 1fr 32px; gap: 0;
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--bg);
}
.stepper button {
  border: 0; background: var(--elev); color: var(--navy); font-weight: 700; cursor: pointer;
}
.stepper button:hover { background: var(--blue-soft); }
.stepper input {
  border: 0; text-align: center; background: transparent; padding: .45rem;
  color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums;
}

.field { display: flex; flex-direction: column; gap: .25rem; font-size: 11px; color: var(--muted); font-weight: 600; }
.field input, .field select {
  border: 1px solid var(--line); border-radius: 8px; padding: .5rem .6rem;
  background: var(--bg); color: var(--text); font-weight: 500;
}
.field input:focus, .field select:focus {
  outline: 2px solid rgba(108,248,76,.3); border-color: var(--cyan);
}
.ticket-summary {
  display: grid; grid-template-columns: 1fr 1fr; gap: .4rem;
  padding: .5rem; background: var(--elev); border-radius: 8px;
}
.ticket-summary div { display: flex; flex-direction: column; gap: .1rem; }
.ticket-summary span { font-size: 9px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.ticket-summary b { font-size: .8rem; color: var(--navy); font-variant-numeric: tabular-nums; }

.place {
  border: 0; border-radius: 8px; padding: .75rem; font-weight: 700; cursor: pointer; color: #fff;
  transition: filter .12s ease;
}
.place:hover { filter: brightness(1.06); }
.buy-place { background: var(--green); }
.sell-place { background: var(--red); }
.ticket-note { font-size: 10px; color: var(--muted); margin: 0; line-height: 1.4; }
.back-link { font-size: 12px; color: var(--cyan-dark); text-decoration: none; margin-top: auto; }
.back-link:hover { text-decoration: underline; }

.ticker-bar {
  height: 30px; flex-shrink: 0; background: var(--navy-deep); color: #b8cad9;
  display: flex; align-items: center; gap: 1.4rem; padding: 0 .85rem;
  overflow: hidden; white-space: nowrap; font-size: 11px; font-variant-numeric: tabular-nums;
}
.ticker-bar span b { color: #fff; margin-right: .35rem; }
.ticker-bar .up { color: #5eead4; }
.ticker-bar .down { color: #fca5a5; }

.modal {
  position: fixed; inset: 0; background: rgba(15,61,8,.5);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal[hidden] { display: none !important; }
.modal-card {
  width: min(400px, calc(100% - 2rem)); background: #fff; border-radius: 14px;
  padding: 1.25rem; border: 1px solid var(--line); box-shadow: 0 20px 50px rgba(31,107,18,.25);
}
.modal-card header { display: flex; justify-content: space-between; align-items: center; }
.modal-card h2 { margin: 0; font-size: 1.05rem; color: var(--navy); }
.modal-card .close { border: 0; background: transparent; font-size: 1.4rem; cursor: pointer; color: var(--muted); }
.modal-card p { color: var(--muted); font-size: .9rem; }

@media (max-width: 1200px) {
  .workspace { grid-template-columns: 180px minmax(0,1fr) 44px 240px; }
}
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 0 minmax(0,1fr) 44px 0; }
  .watchlist, .ticket { display: none; }
  .brand-sub { display: none; }
}
@media (max-width: 720px) {
  .metric:nth-child(n+5) { display: none; }
  .bottom-panels { height: 180px; }
}
