:root {
  color-scheme: light;
  --bg: #f5f6f2;
  --surface: #ffffff;
  --surface-2: #f0f3ef;
  --ink: #1f2428;
  --muted: #687077;
  --line: #d9ded6;
  --accent: #1f7a8c;
  --accent-2: #b56b00;
  --accent-3: #8f3143;
  --good: #1c7c54;
  --bad: #b33f36;
  --warn: #b56b00;
  --shadow: 0 12px 32px rgba(31, 36, 40, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 34px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 4px 0 16px;
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  margin-top: 4px;
  font-size: 30px;
  line-height: 1.1;
  font-weight: 760;
}

h2 {
  font-size: 18px;
  line-height: 1.3;
}

.toolbar,
.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.segmented,
.refresh,
.market-filter,
.asset-filter {
  min-height: 36px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 6px;
  padding: 0 14px;
  font-weight: 680;
}

.segmented.active,
.market-filter.active,
.asset-filter.active {
  color: #ffffff;
  border-color: var(--accent);
  background: var(--accent);
}

.refresh {
  border-color: transparent;
  color: #ffffff;
  background: var(--ink);
}

.status-strip {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
}

.status-strip strong {
  color: var(--ink);
}

.layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 16px;
}

.sidebar,
.chart-section,
.panel,
.table-section,
.kpi-card {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  border-radius: 8px;
}

.sidebar {
  position: sticky;
  top: 16px;
  height: calc(100vh - 32px);
  min-height: 620px;
  padding: 14px;
  overflow: auto;
}

.filter-row {
  margin-bottom: 12px;
}

.market-filter,
.asset-filter {
  flex: 1 1 76px;
  padding: 0 8px;
}

.asset-filter-row {
  margin-bottom: 8px;
}

.instrument-list {
  display: grid;
  gap: 8px;
}

.instrument-button {
  width: 100%;
  min-height: 66px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  background: #ffffff;
  text-align: left;
  border-radius: 7px;
  display: grid;
  gap: 5px;
}

.instrument-button.active {
  border-color: var(--accent);
  background: #eaf5f6;
}

.instrument-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 760;
  line-height: 1.25;
}

.instrument-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--accent);
}

.instrument-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  display: grid;
  gap: 16px;
  min-width: 0;
}

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

.kpi-card {
  padding: 13px 14px;
  min-height: 106px;
}

.kpi-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.kpi-value {
  margin-top: 8px;
  font-size: 26px;
  line-height: 1;
  font-weight: 820;
  font-variant-numeric: tabular-nums;
}

.kpi-foot {
  margin-top: 11px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.contract-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid #d8dccf;
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.contract-notice strong {
  color: var(--ink);
}

.contract-notice span {
  display: inline-flex;
  margin-left: 8px;
  color: var(--accent);
  font-weight: 760;
}

.contract-notice p {
  max-width: 760px;
  text-align: right;
}

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

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

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

.warn {
  color: var(--warn);
}

.chart-section,
.panel,
.table-section {
  padding: 14px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.section-head p,
.section-head span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.section-head.compact {
  align-items: center;
  min-height: 28px;
}

.legend-inline {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.legend-item::before {
  content: "";
  width: 18px;
  height: 3px;
  border-radius: 999px;
  background: currentColor;
}

.legend-item.oi {
  color: var(--accent);
}

.legend-item.volume {
  color: var(--accent-2);
}

.legend-item.price {
  color: var(--accent-3);
}

.chart-shell {
  position: relative;
  width: 100%;
  height: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #fbfcfa);
  overflow: hidden;
}

#trendCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.tooltip {
  position: absolute;
  min-width: 190px;
  max-width: 260px;
  padding: 10px 11px;
  border-radius: 7px;
  background: rgba(31, 36, 40, 0.94);
  color: #fff;
  font-size: 12px;
  line-height: 1.55;
  pointer-events: none;
  z-index: 5;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, 0.7fr);
  gap: 16px;
}

.external-chart {
  height: 352px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
}

.external-chart iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.empty-state {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}

textarea {
  width: 100%;
  height: 198px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
  background: #fbfcfa;
  outline: none;
  line-height: 1.55;
}

textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 122, 140, 0.14);
}

.readout {
  min-height: 112px;
  margin-top: 10px;
  padding: 12px;
  border-radius: 8px;
  background: #f8f5ed;
  color: #57452f;
  font-size: 13px;
  line-height: 1.55;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 1240px;
  border-collapse: collapse;
  font-size: 13px;
  background: #ffffff;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

th:first-child,
td:first-child,
th:nth-child(2),
td:nth-child(2),
th:nth-child(4),
td:nth-child(4) {
  text-align: left;
}

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

tbody tr:hover {
  background: #f9fbf8;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #edf2ee;
  color: #4d5b51;
  font-size: 12px;
  font-weight: 700;
}

.signal-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #f1f4f1;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.signal-pill.up {
  background: #f8e9e7;
  color: var(--bad);
}

.signal-pill.down {
  background: #e7f3ec;
  color: var(--good);
}

.signal-pill.warn {
  background: #fbf0db;
  color: var(--warn);
}

.contract-cell {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.contract-cell small {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  background: #edf2ee;
  color: #4d5b51;
  font-size: 11px;
  font-weight: 760;
}

#biasTag {
  min-width: 66px;
  text-align: center;
  border-radius: 999px;
  padding: 4px 9px;
  color: #fff;
  background: var(--accent);
  font-weight: 750;
  white-space: nowrap;
}

@media (max-width: 1160px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    min-height: 0;
  }

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

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

  .contract-notice {
    align-items: flex-start;
    flex-direction: column;
  }

  .contract-notice p {
    max-width: none;
    text-align: left;
  }

  .split {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app {
    width: min(100% - 18px, 1480px);
    padding-top: 14px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  h1 {
    font-size: 24px;
  }

  .toolbar {
    width: 100%;
  }

  .segmented,
  .refresh {
    flex: 1 1 96px;
  }

  .instrument-list,
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .section-head {
    flex-direction: column;
  }

  .legend-inline {
    justify-content: flex-start;
  }

  .chart-shell {
    height: 360px;
  }
}
