:root {
  --bg: #0d1216;
  --bg-2: #10161b;
  --surface: #121a20;
  --surface-2: #172129;
  --hover: #1b2831;
  --line: #25323b;
  --line-soft: rgba(143, 162, 174, 0.15);
  --text: #ecf1f4;
  --muted: #94a4ae;
  --faint: #687882;
  --green: #00c08b;
  --green-soft: rgba(0, 192, 139, 0.14);
  --red: #ee4056;
  --red-soft: rgba(238, 64, 86, 0.13);
  --blue: #91c9ff;
  --blue-soft: rgba(145, 201, 255, 0.13);
  --amber: #d6a84c;
  --shadow: none;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
  --sans: "Inter", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: var(--sans);
  overflow-x: hidden;
}
body::before { content: none; }

a { color: inherit; }
.terminal-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: #0c1115;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  font-weight: 900;
}
.brand img {
  width: 34px;
  height: 34px;
  border-radius: 3px;
  object-fit: cover;
  background: #fff;
}
.brand span { font-size: 1rem; }
.brand small {
  color: var(--muted);
  font: 600 0.78rem var(--mono);
}
.market-state {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 9px;
  color: var(--muted);
  font: 600 0.78rem var(--mono);
}
.market-state strong { color: var(--text); font-family: var(--sans); }
.market-state time { color: var(--faint); }
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
}
.status-dot.ok { background: var(--green); }
.status-dot.error { background: var(--red); }
.status-dot.demo { background: var(--blue); }

.market-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 292px;
  grid-template-rows: minmax(620px, calc(100vh - 226px)) auto;
  gap: 1px;
  min-height: calc(100vh - 58px);
  background: var(--line);
}
.panel,
.chart-panel,
.positions-panel {
  background: #0f1519;
}
.panel {
  padding: 14px;
  overflow: auto;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 28px;
  margin-bottom: 12px;
}
.panel-head h2 {
  margin: 0;
  color: var(--muted);
  font: 800 0.68rem var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.panel-head span {
  color: var(--faint);
  font: 700 0.72rem var(--mono);
}
.panel-head.compact { margin: 20px 0 10px; }

.watchlist { display: grid; gap: 2px; }
.watch-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 10px 9px;
  border: 1px solid transparent;
  border-radius: 2px;
  cursor: pointer;
}
.watch-item:hover,
.watch-item.active {
  background: var(--surface);
  border-color: var(--line);
}
.watch-main {
  min-width: 0;
}
.watch-symbol {
  display: block;
  font: 800 0.84rem var(--mono);
}
.watch-name {
  display: block;
  margin-top: 2px;
  color: var(--faint);
  font-size: 0.74rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.watch-values {
  text-align: right;
  font-family: var(--mono);
}
.watch-price {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
}
.watch-change {
  display: block;
  margin-top: 2px;
  font-size: 0.72rem;
  font-weight: 800;
}
.up { color: var(--green); }
.down { color: var(--red); }

.chart-panel {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}
.instrument-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px 13px;
  border-bottom: 1px solid var(--line);
  background: #10171c;
}
.instrument-kicker {
  margin-bottom: 5px;
  color: var(--faint);
  font: 800 0.7rem var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
h1 {
  margin: 0;
  font-size: clamp(1.55rem, 2.8vw, 2.55rem);
  line-height: 1;
  letter-spacing: 0;
}
.instrument-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 9px;
  color: var(--muted);
  font: 600 0.78rem var(--mono);
}
.quote-block {
  text-align: right;
  font-family: var(--mono);
  white-space: nowrap;
}
.quote-block strong {
  display: block;
  font-size: clamp(1.55rem, 3.4vw, 2.65rem);
  line-height: 1;
}
.quote-block span {
  display: block;
  margin-top: 5px;
  font-weight: 900;
}
.quote-block small {
  display: block;
  margin-top: 6px;
  color: var(--faint);
  font-size: 0.72rem;
}

.chart-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 18px;
  border-bottom: 1px solid var(--line);
}
.range-tabs,
.chart-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}
.range-tab {
  border: 0;
  border-radius: 3px;
  padding: 7px 12px;
  color: var(--muted);
  background: transparent;
  font: 900 0.76rem var(--sans);
  cursor: pointer;
}
.range-tab:hover { color: var(--text); background: var(--surface); }
.range-tab.active { color: #07100f; background: var(--blue); }
.tool-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--muted);
  background: rgba(255,255,255,0.02);
  font: 800 0.72rem var(--sans);
}
.tool-pill.is-on::before {
  content: "";
  width: 18px;
  height: 10px;
  margin-right: 7px;
  border-radius: 999px;
  background: var(--blue);
  box-shadow: inset 8px 0 0 #0d1519;
}

.chart-stage {
  position: relative;
  min-height: 420px;
  overflow: hidden;
}
.main-chart {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 420px;
  touch-action: none;
  user-select: none;
  shape-rendering: geometricPrecision;
  text-rendering: geometricPrecision;
}
.main-chart .chart-bg { fill: #0f1519; }
.main-chart .grid-line { stroke: rgba(135, 151, 162, 0.16); stroke-width: 1; vector-effect: non-scaling-stroke; }
.main-chart .grid-line.major { stroke: rgba(135, 151, 162, 0.25); }
.main-chart .axis-label {
  fill: var(--muted);
  font: 800 12px var(--mono);
}
.main-chart .y-label { text-anchor: end; }
.main-chart .x-label { text-anchor: middle; }
.main-chart .area { fill: url(#chartGradient); }
.main-chart .line {
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.main-chart .line.positive-line { stroke: var(--green); }
.main-chart .line.negative-line { stroke: var(--red); }
.main-chart .current-line { stroke: var(--red); stroke-width: 1; stroke-dasharray: 5 6; opacity: 0.78; vector-effect: non-scaling-stroke; }
.main-chart .baseline { stroke: rgba(236, 241, 244, 0.46); stroke-width: 1; stroke-dasharray: 5 7; vector-effect: non-scaling-stroke; }
.main-chart .price-tag {
  fill: var(--red);
}
.main-chart .price-tag-text {
  fill: #fff;
  font: 900 12px var(--mono);
}
.main-chart .volume-bars rect {
  fill: rgba(135, 151, 162, 0.22);
  shape-rendering: crispEdges;
}
.main-chart .crosshair-line { stroke: rgba(236,241,244,.62); stroke-width: 1; stroke-dasharray: 3 4; vector-effect: non-scaling-stroke; }
.main-chart .cursor-dot { fill: var(--bg); stroke-width: 2.5; }
.main-chart .cursor-dot.positive-line { stroke: var(--green); }
.main-chart .cursor-dot.negative-line { stroke: var(--red); }
.main-chart .tooltip-box {
  fill: rgba(20, 28, 33, 0.96);
  stroke: var(--line);
  filter: none;
}
.main-chart .tooltip-text {
  fill: var(--muted);
  font: 700 12px var(--mono);
}
.main-chart .tooltip-text.strong {
  fill: var(--text);
  font-size: 15px;
  font-weight: 900;
}
.main-chart .chart-hit {
  fill: transparent;
  pointer-events: all;
  cursor: crosshair;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  background: var(--line);
  gap: 1px;
}
.metric-box {
  min-width: 0;
  padding: 11px 13px;
  background: #0f1519;
}
.metric-box label {
  display: block;
  margin-bottom: 3px;
  color: var(--faint);
  font: 800 0.62rem var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.metric-box strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 900 0.84rem var(--mono);
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
}
.stat-cell {
  padding: 11px 12px;
  background: var(--bg);
}
.stat-cell label {
  display: block;
  margin-bottom: 4px;
  color: var(--faint);
  font: 800 0.62rem var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.stat-cell strong {
  display: block;
  font: 900 0.9rem var(--mono);
}
.allocation-list,
.movements-list { display: grid; gap: 8px; }
.allocation-row {
  display: grid;
  gap: 7px;
}
.allocation-row header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.78rem;
}
.allocation-row strong { font-family: var(--mono); }
.allocation-row span { color: var(--muted); font: 800 0.74rem var(--mono); }
.bar {
  height: 7px;
  background: rgba(143, 162, 174, 0.16);
  border-radius: 999px;
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  width: var(--w);
  border-radius: inherit;
  background: var(--green);
}
.movement {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line-soft);
}
.movement span {
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--green);
  background: var(--green-soft);
  font: 900 0.64rem var(--mono);
}
.movement.sell span { color: var(--red); background: var(--red-soft); }
.movement strong {
  display: block;
  font: 900 0.78rem var(--mono);
}
.movement p {
  margin: 2px 0 0;
  color: var(--faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.72rem;
}
.movement em {
  color: var(--muted);
  font: 900 0.74rem var(--mono);
  font-style: normal;
}

.positions-panel {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  overflow: hidden;
}
.positions-panel .panel-head {
  min-height: 44px;
  margin: 0;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: #111920;
}
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  min-width: 840px;
  border-collapse: collapse;
  font-family: var(--mono);
}
th, td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--muted);
  text-align: right;
  white-space: nowrap;
}
th {
  color: var(--faint);
  background: #0e1418;
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
td { font-size: 0.78rem; }
th:first-child,
th:nth-child(2),
td:first-child,
td:nth-child(2) { text-align: left; }
tr:hover td { background: rgba(255,255,255,0.025); color: var(--text); }
.asset-symbol { color: var(--text); font-weight: 900; }
.badge {
  display: inline-flex;
  justify-content: flex-end;
  min-width: 76px;
  font-weight: 900;
}
.sparkline { width: 82px; height: 24px; }
.sparkline path { fill: none; stroke: var(--green); stroke-width: 2; stroke-linecap: round; }
.sparkline.negative path { stroke: var(--red); }
.empty {
  color: var(--faint);
  padding: 18px 0;
}

@media (max-width: 1180px) {
  .market-shell {
    grid-template-columns: 230px minmax(0, 1fr);
    grid-template-rows: minmax(580px, calc(100vh - 244px)) auto auto;
  }
  .detail-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 18px;
  }
  .detail-panel > .panel-head { grid-column: 1 / -1; margin-bottom: -4px; }
  .side-section .panel-head.compact { margin-top: 0; }
}
@media (max-width: 820px) {
  .terminal-bar { align-items: flex-start; flex-direction: column; padding: 12px 16px; }
  .market-shell {
    display: block;
    background: var(--bg);
  }
  .panel,
  .chart-panel,
  .positions-panel { border-bottom: 1px solid var(--line); }
  .watch-panel { max-height: 250px; }
  .instrument-head,
  .chart-controls { display: grid; }
  .quote-block { text-align: left; }
  .metric-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-panel { display: block; }
}
