:root {
  color-scheme: light;
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  --bg: #eef2f7;
  --header: #101828;
  --header-soft: #172033;
  --surface: #ffffff;
  --surface-soft: #f7f9fa;
  --surface-warm: #fbfaf7;
  --line: #d7e0ea;
  --line-strong: #aebdca;
  --text: #142033;
  --muted: #64748b;
  --muted-strong: #475569;
  --accent: #1e40af;
  --accent-strong: #173a86;
  --accent-soft: #eaf1ff;
  --red: #c83b2e;
  --red-soft: #fff0ee;
  --green: #14783f;
  --green-soft: #edf8f1;
  --amber: #a15b00;
  --amber-soft: #fff4d7;
  --blue: #2563a8;
  --blue-soft: #edf5ff;
  --shadow: 0 12px 28px rgba(17, 28, 24, .08);
  --shadow-soft: 0 8px 18px rgba(17, 28, 24, .06);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(16, 24, 40, .04), rgba(16, 24, 40, 0) 280px),
    var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

h1,
h2,
p {
  margin: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-header {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  align-items: center;
  gap: 18px;
  padding: 14px 24px;
  color: #fff;
  background: var(--header);
  border-bottom: 1px solid #26364f;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 10px 24px rgba(16, 24, 40, .16);
}

.brand span {
  display: block;
  color: #9fb1ad;
  font-size: 12px;
  font-weight: 700;
}

h1 {
  margin-top: 2px;
  font-size: 22px;
  line-height: 1.15;
  font-weight: 800;
}

h2 {
  font-size: 15px;
  line-height: 1.2;
  font-weight: 800;
}

.header-status,
.toolbar,
.inline-form,
.settings-form,
.row-actions,
.filter-bar,
.segmented,
.group-list {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.header-status {
  justify-content: flex-end;
  max-width: 560px;
}

.toolbar {
  justify-content: flex-end;
}

.app-main {
  width: min(1680px, calc(100% - 28px));
  margin: 16px auto 32px;
}

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

.metric {
  min-height: 88px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
  position: relative;
  overflow: hidden;
}

.metric::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--line-strong);
}

.metric-primary::before {
  background: var(--accent);
}

.metric-live::before,
.metric-ok::before {
  background: var(--green);
}

.metric-market::before {
  background: var(--blue);
}

.metric-warning::before {
  background: var(--amber);
}

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

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 27px;
  line-height: 1;
  font-weight: 800;
}

.metric-warning {
  background: linear-gradient(180deg, #fffaf0, #fff);
  border-color: #f2d7a4;
}

.metric-ok {
  background: linear-gradient(180deg, #f3fbf6, #fff);
}

.metric > span {
  display: block;
  margin-top: 9px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 352px;
  gap: 14px;
}

.primary-column,
.side-column {
  display: grid;
  align-content: start;
  gap: 14px;
}

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

.monitor-surface {
  overflow: hidden;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.action-panel {
  padding-bottom: 16px;
}

.filter-bar {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.search-input {
  flex: 1 1 260px;
  min-width: 240px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea,
button {
  border-radius: 7px;
  border: 1px solid var(--line);
}

input,
select {
  height: 40px;
  min-width: 150px;
  padding: 0 11px;
  color: var(--text);
  background: #fff;
}

textarea {
  width: 100%;
  min-height: 112px;
  padding: 10px 11px;
  color: var(--text);
  background: #fff;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: #97a4ab;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 3px solid rgba(8, 117, 104, .22);
  outline-offset: 1px;
  border-color: var(--accent);
}

button {
  min-height: 40px;
  padding: 0 14px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 700;
  transition: background .16s ease, border-color .16s ease, transform .12s ease;
}

button:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

button:active {
  transform: translateY(1px);
}

button.secondary {
  background: #eef4ff;
  color: var(--accent-strong);
  border-color: #cad9ff;
}

button.secondary:hover {
  background: #dce8ff;
}

button.danger {
  background: #fff1ef;
  color: var(--red);
  border-color: #ffd0ca;
}

button.danger:hover {
  background: #ffe3df;
  border-color: #ffbeb5;
}

.stack-form {
  display: grid;
  gap: 12px;
  padding: 14px 16px 0;
}

.stack-form input,
.stack-form select {
  width: 100%;
}

.inline-form,
.settings-form {
  align-items: end;
}

.compact {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.compact input,
.compact select {
  min-width: 132px;
}

.settings-form input {
  width: 96px;
  min-width: 96px;
}

.status {
  min-height: 28px;
}

.status .badge {
  height: 28px;
}

.segmented {
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.segmented button {
  min-height: 38px;
  min-width: 58px;
  padding: 0 12px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: #fff;
  color: var(--muted);
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button.active {
  background: var(--accent);
  color: #fff;
}

.group-list {
  flex: 2 1 380px;
}

.group-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 8px 0 11px;
  border: 1px solid #ccd7de;
  border-radius: 999px;
  background: #fff;
  color: var(--text);
}

.group-chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.group-chip small {
  color: var(--muted);
}

.group-chip > button:first-child {
  min-height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
}

.group-chip > button:first-child:hover {
  background: transparent;
}

.chip-x {
  width: 24px;
  min-height: 24px;
  height: 24px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  border: 0;
  color: var(--muted);
}

.chip-x:hover {
  background: #e6eef1;
  color: var(--text);
}

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

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

.watch-table {
  min-width: 1260px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  background: #f6f8f9;
  white-space: nowrap;
}

td {
  background: #fff;
}

tbody tr:hover td {
  background: #f8fbff;
}

.watch-table td:first-child,
.watch-table th:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
}

.watch-table th:first-child {
  z-index: 3;
}

.watch-table .up-row td:first-child {
  box-shadow: inset 3px 0 0 var(--red);
}

.watch-table .down-row td:first-child {
  box-shadow: inset 3px 0 0 var(--green);
}

.watch-table .signal-row td {
  background: #fffafa;
}

.watch-table .signal-row:hover td {
  background: #fff4f2;
}

.watch-table .issue-row td {
  background: #fffdf6;
}

.watch-table .signal-row.issue-row td {
  background: #fff8f3;
}

.stock-name {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 190px;
}

.market-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 28px;
  border-radius: 7px;
  background: #eef2f4;
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 800;
}

.market-mark.market-a {
  background: #eef4ff;
  color: var(--accent-strong);
}

.market-mark.market-hk {
  background: #f6efff;
  color: #6d28d9;
}

.stock-main strong {
  display: block;
  font-size: 14px;
}

.code {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.numeric,
.price,
.change-stack,
.range-stack {
  font-variant-numeric: tabular-nums;
}

.price {
  display: block;
  font-size: 18px;
  line-height: 1.15;
  font-weight: 800;
}

.change-stack,
.range-stack {
  display: grid;
  gap: 2px;
  font-weight: 800;
}

.range-stack span:last-child {
  color: var(--muted);
}

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

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

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

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

.nowrap {
  white-space: nowrap;
}

.badge,
.signal-pill {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.live-badge {
  gap: 7px;
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(20, 120, 63, .12);
  flex: 0 0 auto;
}

.muted-dot {
  background: #9aa7b1;
  box-shadow: none;
}

@keyframes livePulse {
  0% {
    box-shadow: 0 0 0 0 rgba(20, 120, 63, .30);
  }

  70% {
    box-shadow: 0 0 0 7px rgba(20, 120, 63, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(20, 120, 63, 0);
  }
}

.live-badge .live-dot {
  animation: livePulse 2s ease-out infinite;
}

.badge.off,
.signal-pill.neutral {
  background: #f0f3f5;
  color: var(--muted-strong);
}

.group-badge {
  background: var(--blue-soft);
  color: var(--blue);
}

.badge.warn {
  background: var(--amber-soft);
  color: var(--amber);
}

.alert-badge {
  background: var(--red-soft);
  color: var(--red);
}

.signal-pill.active {
  background: var(--red-soft);
  color: var(--red);
}

.indicator-stack,
.status-stack {
  display: grid;
  gap: 5px;
  min-width: 116px;
}

.status-stack {
  min-width: 92px;
}

.row-actions {
  flex-wrap: nowrap;
}

.row-actions button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.compact-table table {
  min-width: 760px;
}

.compact-table td,
.compact-table th {
  padding-top: 9px;
  padding-bottom: 9px;
}

.log-content {
  max-width: 680px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(430px, calc(100vw - 36px));
  padding: 11px 13px;
  background: var(--header);
  color: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity .16s ease, transform .16s ease;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
  }
}

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

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

@media (max-width: 960px) {
  .app-header {
    grid-template-columns: 1fr;
  }

  .header-status,
  .toolbar {
    justify-content: flex-start;
  }

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

@media (max-width: 720px) {
  .app-header {
    position: static;
    padding: 14px 12px;
  }

  .app-main {
    width: calc(100% - 16px);
    margin-top: 8px;
  }

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

  .section-head,
  .toolbar,
  .header-status,
  .filter-bar,
  .settings-form,
  .inline-form {
    align-items: stretch;
    flex-direction: column;
  }

  input,
  select,
  .search-input {
    min-width: 100%;
  }

  button {
    min-height: 44px;
  }

  .segmented,
  .group-list {
    width: 100%;
  }
}
