:root {
  color-scheme: dark;
  --bg: #080b10;
  --surface: #10151d;
  --surface-2: #151c26;
  --surface-3: #1b2430;
  --text: #eef4f8;
  --muted: #8fa0af;
  --line: #263341;
  --accent: #2dd4bf;
  --accent-2: #f5c451;
  --good: #22c55e;
  --bad: #ef4444;
  --rise: #ef4444;
  --fall: #22c55e;
  --warn: #f59e0b;
  --shadow: 0 18px 50px rgba(0, 0, 0, .28);
}

:root.light {
  color-scheme: light;
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-2: #f7fafc;
  --surface-3: #e9eef4;
  --text: #111827;
  --muted: #607080;
  --line: #d8e0e8;
  --accent: #0f766e;
  --accent-2: #b7791f;
  --good: #15803d;
  --bad: #dc2626;
  --rise: #dc2626;
  --fall: #15803d;
  --warn: #b45309;
  --shadow: 0 16px 38px rgba(30, 41, 59, .12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 0 auto 14px;
  max-width: 1760px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--accent);
  color: var(--accent);
  background: var(--surface);
  border-radius: 8px;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(20px, 3vw, 30px);
  line-height: 1.1;
}

.brand p,
.detail-head p,
.notice,
.metric span,
.metric em,
.eyebrow,
.info-grid span {
  color: var(--muted);
}

.brand p {
  margin-top: 4px;
  font-size: 13px;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.ghost-btn,
.range-tabs button,
.rank-tabs button,
.segmented button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  min-height: 36px;
}

.ghost-btn {
  padding: 0 14px;
}

.ghost-btn:hover,
.range-tabs button:hover,
.rank-tabs button:hover,
.segmented button:hover {
  border-color: var(--accent);
}

main {
  max-width: 1760px;
  margin: 0 auto;
}

.up {
  color: var(--rise);
}

.down {
  color: var(--fall);
}

.flat {
  color: var(--muted);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.metric,
.panel {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  border-radius: 8px;
}

.metric {
  display: grid;
  gap: 6px;
  padding: 14px;
  min-height: 94px;
}

.metric strong {
  font-size: clamp(22px, 3vw, 34px);
  line-height: 1;
}

.metric em {
  font-size: 12px;
  font-style: normal;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, .95fr) minmax(540px, 1.45fr) minmax(330px, .8fr);
  gap: 12px;
  align-items: start;
}

.panel {
  min-width: 0;
  padding: 14px;
}

.panel h2 {
  font-size: 17px;
}

.panel h3 {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 8px;
}

.panel-head,
.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head input,
.input-line input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  min-height: 38px;
  padding: 0 10px;
  outline: none;
}

.panel-head input {
  max-width: 190px;
}

.panel-head input:focus,
.input-line input:focus {
  border-color: var(--accent);
}

.stock-table-wrap {
  overflow: auto;
  max-height: calc(100vh - 288px);
}

.stock-table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  vertical-align: middle;
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

tr.stock-row {
  cursor: pointer;
}

tr.stock-row:hover,
tr.stock-row.active {
  background: var(--surface-2);
}

.bank-cell {
  display: grid;
  gap: 2px;
}

.kind-tag {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.kind-tag.system {
  border-color: var(--accent);
  color: var(--accent);
}

.kind-tag.bank {
  border-color: var(--accent-2);
  color: var(--accent-2);
}

.bank-cell span {
  color: var(--muted);
  font-size: 12px;
}

.risk-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 12px;
}

.risk-healthy {
  color: var(--good);
  border-color: color-mix(in srgb, var(--good) 45%, var(--line));
}

.risk-tight {
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 45%, var(--line));
}

.risk-critical,
.risk-frozen {
  color: var(--bad);
  border-color: color-mix(in srgb, var(--bad) 45%, var(--line));
}

.detail-panel {
  display: grid;
  gap: 12px;
}

.eyebrow {
  display: block;
  font-size: 11px;
  font-weight: 800;
  margin-bottom: 5px;
}

.detail-head h2 {
  font-size: clamp(22px, 3vw, 34px);
}

.detail-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.detail-meta span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.price-box {
  display: grid;
  justify-items: end;
  gap: 5px;
  min-width: 120px;
}

.price-box strong {
  font-size: clamp(24px, 3vw, 38px);
}

.range-tabs,
.rank-tabs,
.segmented {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.range-tabs button,
.rank-tabs button,
.segmented button {
  padding: 0 12px;
}

.range-tabs button.active,
.rank-tabs button.active,
.segmented button.active {
  color: #061014;
  background: var(--accent);
  border-color: var(--accent);
}

.chart-shell {
  position: relative;
  width: 100%;
  min-height: 300px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.chart-tooltip {
  position: absolute;
  display: none;
  min-width: 190px;
  max-width: min(280px, calc(100% - 18px));
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow);
  pointer-events: none;
  z-index: 3;
  font-size: 12px;
  line-height: 1.45;
}

.chart-tooltip strong {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
}

#price-chart {
  display: block;
  width: 100%;
  height: 340px;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.info-grid div {
  display: grid;
  gap: 5px;
  min-height: 64px;
  padding: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.info-grid strong {
  overflow-wrap: anywhere;
}

.depth-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.depth-list,
.rank-list,
.trade-list {
  display: grid;
  gap: 6px;
}

.depth-row,
.rank-row,
.trade-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
}

.depth-row span,
.rank-row span,
.trade-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-column {
  display: grid;
  gap: 12px;
}

.side-column > section {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  border-radius: 8px;
  padding: 14px;
}

.command-box {
  display: grid;
  gap: 10px;
}

.input-line {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.quote-result {
  min-height: 104px;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 6px;
}

.quote-result strong,
.quote-result code {
  overflow-wrap: anywhere;
}

.command-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.command-actions button {
  min-height: 38px;
  border: 0;
  color: #061014;
  background: var(--accent);
  border-radius: 8px;
  font-weight: 800;
}

.command-actions button:last-child {
  background: var(--accent-2);
}

.notice {
  font-size: 12px;
  line-height: 1.45;
}

.rank-row,
.trade-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.trade-row small,
.rank-row small {
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  pointer-events: none;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  transition: opacity .18s ease, transform .18s ease;
  z-index: 10;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.empty {
  color: var(--muted);
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

@media (max-width: 1320px) {
  .workspace {
    grid-template-columns: minmax(330px, .95fr) minmax(500px, 1.25fr);
  }

  .side-column {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .app-shell {
    padding: 12px;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace,
  .side-column {
    grid-template-columns: 1fr;
  }

  .stock-table-wrap {
    max-height: 440px;
  }
}

@media (max-width: 620px) {
  .topbar,
  .panel-head,
  .detail-head {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .range-tabs,
  .rank-tabs,
  .segmented {
    width: 100%;
  }

  .ghost-btn,
  .range-tabs button,
  .rank-tabs button,
  .segmented button {
    flex: 1;
  }

  .metric-grid,
  .info-grid,
  .depth-grid,
  .command-actions {
    grid-template-columns: 1fr;
  }

  .panel-head input {
    max-width: none;
  }

  #price-chart {
    height: 280px;
  }
}
