:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #f9fafc;
  --text: #111827;
  --muted: #64748b;
  --line: #d8dee8;
  --line-soft: #e9edf4;
  --green: #0f9f6e;
  --red: #c93737;
  --blue: #2f67d8;
  --amber: #b87716;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
  font-family: Inter, "PingFang SC", "Noto Sans SC", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

a {
  color: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(1480px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 22px 0 36px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 10px 0 22px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.08;
  font-weight: 720;
  letter-spacing: 0;
}

.topbar p,
.panel-head p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin-top: 6px;
}

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

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  gap: 7px;
  padding: 0 11px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  background: #111827;
  color: #ffffff;
  text-decoration: none;
  font-size: 12px;
  font-weight: 650;
  line-height: 1;
}

.icon-button.secondary {
  background: var(--surface);
  color: var(--text);
}

.icon-button svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

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

.market-card {
  padding: 16px;
}

.market-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 13px;
  border-bottom: 1px solid var(--line-soft);
}

.market-name {
  font-size: 14px;
  font-weight: 760;
}

.market-date {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 6px;
  border: 1px solid #f1d49d;
  background: #fff8e8;
  color: #8a560d;
  font-size: 11px;
  font-weight: 720;
  white-space: nowrap;
}

.status.final {
  border-color: #bfe6d2;
  background: #eefbf3;
  color: #09724d;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding-top: 14px;
}

.metric label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  line-height: 1.25;
}

.metric strong {
  display: block;
  margin-top: 5px;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  white-space: nowrap;
}

.metric span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}

.pos {
  color: var(--green);
}

.neg {
  color: var(--red);
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.85fr) minmax(320px, 0.75fr);
  gap: 12px;
  margin-bottom: 12px;
}

.panel {
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line-soft);
}

.panel-head.tight {
  padding-bottom: 14px;
}

.panel h2 {
  font-size: 15px;
  line-height: 1.2;
  font-weight: 760;
}

.segmented,
.tabs {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
}

.segmented button,
.tabs button {
  height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}

.segmented button.active,
.tabs button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.chart {
  min-height: 348px;
  padding: 12px 14px 4px;
}

.chart svg {
  display: block;
  width: 100%;
  height: 330px;
}

.axis {
  stroke: #d9e0ea;
  stroke-width: 1;
}

.gridline {
  stroke: #ecf0f5;
  stroke-width: 1;
}

.axis-label {
  fill: #7b8798;
  font-size: 11px;
  font-weight: 600;
}

.bar.foreign {
  fill: rgba(47, 103, 216, 0.72);
}

.bar.institution {
  fill: rgba(15, 159, 110, 0.7);
}

.bar.individual {
  fill: rgba(201, 55, 55, 0.64);
}

.chart-line {
  fill: none;
  stroke: #111827;
  stroke-width: 2.2;
}

.dot {
  fill: #111827;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 0 16px 15px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch,
.line-swatch {
  display: inline-block;
  width: 12px;
  height: 8px;
  border-radius: 2px;
}

.swatch.foreign {
  background: rgba(47, 103, 216, 0.72);
}

.swatch.institution {
  background: rgba(15, 159, 110, 0.7);
}

.swatch.individual {
  background: rgba(201, 55, 55, 0.64);
}

.line-swatch {
  width: 18px;
  height: 2px;
  background: #111827;
  border-radius: 999px;
}

.signal-list {
  display: grid;
  gap: 10px;
  padding: 14px 16px 16px;
}

.signal {
  border: 1px solid var(--line-soft);
  border-radius: 7px;
  padding: 12px;
  background: var(--surface-soft);
}

.signal label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.signal strong {
  display: block;
  margin-top: 7px;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.signal p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.table-panel {
  overflow: hidden;
}

.table-wrap {
  overflow-x: auto;
}

.stock-cards {
  display: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
}

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

th {
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 11px;
  font-weight: 760;
}

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

td:nth-child(2) {
  color: var(--text);
  font-weight: 660;
}

td:last-child {
  color: var(--muted);
}

.stock-card {
  border-top: 1px solid var(--line-soft);
  padding: 14px 16px;
  background: var(--surface);
}

.stock-card header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.stock-card header strong {
  display: block;
  font-size: 15px;
  line-height: 1.2;
  font-weight: 760;
}

.stock-card header span:not(.status) {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.stock-card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stock-metric {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 7px;
  background: var(--surface-soft);
}

.stock-metric label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
}

.stock-metric strong {
  display: block;
  margin-top: 5px;
  font-size: 14px;
  line-height: 1.2;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

@media (max-width: 980px) {
  .app-shell {
    width: min(100vw - 20px, 760px);
    padding-top: 14px;
  }

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

  .actions {
    justify-content: flex-start;
  }

  .status-grid,
  .main-grid {
    grid-template-columns: 1fr;
  }

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

  .chart {
    min-height: 286px;
  }

  .chart svg {
    height: 270px;
  }
}

@media (max-width: 520px) {
  h1 {
    font-size: 23px;
  }

  .metric strong {
    font-size: 16px;
  }

  .icon-button {
    flex: 1 1 120px;
  }

  .topbar {
    gap: 16px;
    padding-bottom: 18px;
  }

  .topbar p {
    font-size: 12px;
  }

  .actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .icon-button {
    width: 100%;
    min-height: 36px;
    padding: 0 8px;
    font-size: 12px;
  }

  .icon-button.secondary {
    grid-column: 1 / -1;
  }

  .market-card {
    padding: 14px;
  }

  .market-card header {
    align-items: flex-start;
    gap: 10px;
  }

  .status {
    min-height: 24px;
    padding: 0 7px;
    font-size: 10px;
  }

  .segmented,
  .tabs {
    width: 100%;
  }

  .segmented button,
  .tabs button {
    flex: 1;
  }

  .panel-head {
    padding: 15px 14px 12px;
  }

  .chart {
    min-height: 262px;
    padding: 10px 8px 0;
  }

  .chart svg {
    height: 248px;
  }

  .axis-label {
    font-size: 10px;
  }

  .legend {
    gap: 9px;
    padding: 0 14px 14px;
    font-size: 11px;
  }

  .table-wrap {
    display: none;
  }

  .stock-cards {
    display: grid;
  }

  .table-panel {
    overflow: hidden;
  }
}
