:root {
  color-scheme: light;
  --ink: #102624;
  --muted: #647673;
  --line: #d7e1df;
  --line-strong: #becdca;
  --paper: #ffffff;
  --canvas: #f3f7f6;
  --green: #0b6258;
  --green-dark: #07463f;
  --green-soft: #e6f3f0;
  --cyan: #178aa3;
  --gold: #a66c0d;
  --gold-soft: #fff6e3;
  --red: #c84247;
  --red-soft: #fff0f0;
  --blue-soft: #eef5fb;
  --shadow: 0 12px 32px rgba(21, 52, 49, 0.08);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--canvas);
  color: var(--ink);
}

body {
  min-width: 320px;
}

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

button {
  font: inherit;
}

.market-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 66px;
  padding: 10px clamp(16px, 3vw, 48px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
}

.market-brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: inherit;
  text-decoration: none;
}

.market-brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 6px;
  background: var(--green-dark);
  color: #fff;
}

.market-brand-mark svg {
  width: 22px;
  height: 22px;
}

.market-brand > span:last-child {
  display: grid;
  gap: 1px;
}

.market-brand strong {
  font-size: 18px;
  line-height: 1.2;
}

.market-brand small {
  color: var(--muted);
  font-size: 12px;
}

.market-actions {
  display: flex;
  gap: 8px;
}

.header-link {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.header-link:hover {
  border-color: var(--green);
  color: var(--green);
}

.header-link.primary {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.header-link svg {
  width: 17px;
  height: 17px;
}

.market-main {
  width: min(1660px, 100%);
  margin: 0 auto;
  padding: 24px clamp(14px, 2.5vw, 40px) 42px;
}

.market-intro {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  padding: 2px 0 18px;
}

.title-line {
  display: flex;
  align-items: center;
  gap: 12px;
}

.market-intro h1 {
  margin: 0;
  font-size: clamp(25px, 3vw, 34px);
  line-height: 1.2;
  letter-spacing: 0;
}

.market-intro p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.live-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 800;
}

.live-state > span,
.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #14977f;
  box-shadow: 0 0 0 3px rgba(20, 151, 127, 0.14);
}

.live-state.pending > span,
.status-dot.pending {
  background: var(--gold);
  box-shadow: 0 0 0 3px rgba(166, 108, 13, 0.14);
}

.live-state.offline {
  background: var(--red-soft);
  color: #9f2930;
}

.live-state.offline > span,
.status-dot.offline {
  background: var(--red);
  box-shadow: 0 0 0 3px rgba(200, 66, 71, 0.14);
}

.clock-block {
  display: grid;
  justify-items: end;
  gap: 2px;
}

.clock-block span {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.clock-block strong {
  font-variant-numeric: tabular-nums;
  font-size: 20px;
}

.pair-strip {
  margin-bottom: 14px;
  overflow: hidden;
}

.pair-list {
  display: grid;
  grid-auto-columns: minmax(255px, 330px);
  grid-auto-flow: column;
  gap: 10px;
  overflow-x: auto;
  padding: 1px 1px 7px;
  scrollbar-width: thin;
}

.pair-button,
.pair-skeleton {
  position: relative;
  min-height: 92px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
}

.pair-skeleton::after {
  position: absolute;
  inset: 14px;
  border-radius: 4px;
  background: #eaf0ef;
  content: "";
  animation: pulse 1.4s ease-in-out infinite;
}

.pair-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 13px 14px;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.pair-button:hover {
  border-color: #91aaa5;
}

.pair-button.is-active {
  border-color: var(--green);
  box-shadow: inset 0 3px 0 var(--green);
}

.pair-button-copy {
  min-width: 0;
}

.pair-button strong {
  display: block;
  overflow: hidden;
  margin: 0 0 6px;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pair-button small {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pair-price {
  align-self: center;
  font-variant-numeric: tabular-nums;
  font-size: 21px;
  font-weight: 800;
}

.pair-price.positive {
  color: #118060;
}

.pair-price.negative {
  color: var(--red);
}

.pair-health {
  position: absolute;
  right: 9px;
  bottom: 8px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #14977f;
}

.pair-health.offline {
  background: var(--red);
}

.market-panel {
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.instrument-head {
  display: flex;
  min-height: 84px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.instrument-copy {
  min-width: 0;
}

.instrument-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.instrument-head h2 {
  overflow: hidden;
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.instrument-head p {
  overflow: hidden;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-chip {
  display: inline-flex;
  min-height: 25px;
  align-items: center;
  flex: 0 0 auto;
  padding: 0 8px;
  border: 1px solid #c9ddd8;
  border-radius: 4px;
  background: var(--green-soft);
  color: var(--green-dark);
  font-size: 11px;
  font-weight: 800;
}

.direction-switch,
.intervals {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f4f7f6;
}

.direction-switch button,
.intervals button {
  min-height: 35px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.direction-switch button {
  min-width: 92px;
  padding: 0 14px;
}

.direction-switch button.is-active,
.intervals button.is-active {
  background: var(--green-dark);
  color: #fff;
  box-shadow: 0 2px 6px rgba(7, 70, 63, 0.16);
}

.quote-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) minmax(220px, 0.8fr) minmax(300px, 1.15fr);
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #f8faf9;
}

.quote-card {
  min-width: 0;
  min-height: 104px;
  padding: 14px 15px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
}

.quote-card.neutral:nth-child(1) {
  border-top: 3px solid var(--cyan);
}

.quote-card.neutral:nth-child(2) {
  border-top: 3px solid var(--gold);
}

.quote-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.quote-card-head span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quote-card-head small {
  flex: 0 0 auto;
  font-size: 11px;
}

.book-values {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 17px;
}

.book-values span {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
}

.book-values strong {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-size: 18px;
}

.spread-card {
  border-color: #b7ddd4;
  background: var(--green-soft);
}

.spread-number {
  display: block;
  overflow: hidden;
  margin-top: 13px;
  color: var(--green-dark);
  font-variant-numeric: tabular-nums;
  font-size: 30px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.spread-number.negative {
  color: var(--red);
}

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

.stat {
  display: grid;
  gap: 4px;
}

.stat span {
  color: var(--muted);
  font-size: 10px;
}

.stat strong {
  overflow: hidden;
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-toolbar {
  display: flex;
  min-height: 56px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
}

.intervals button {
  min-width: 48px;
  padding: 0 11px;
}

.chart-legend {
  display: flex;
  align-items: center;
  gap: 15px;
  color: var(--muted);
  font-size: 11px;
}

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

.chart-legend i {
  width: 8px;
  height: 8px;
}

.legend-up {
  background: #168066;
}

.legend-down {
  background: var(--red);
}

.chart-stage {
  position: relative;
  height: clamp(430px, 59vh, 720px);
  min-height: 430px;
  background: #fff;
}

#spread-chart {
  width: 100%;
  height: 100%;
}

.chart-message {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 8px;
  padding: 30px;
  background: rgba(255, 255, 255, 0.9);
  text-align: center;
}

.chart-message[hidden] {
  display: none;
}

.chart-message strong {
  font-size: 15px;
}

.chart-message small {
  color: var(--muted);
}

.loader {
  width: 24px;
  height: 24px;
  border: 3px solid #dce8e5;
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.market-foot {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: #fafcfb;
}

.feed-status {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.feed-status strong {
  flex: 0 0 auto;
}

.feed-status span:last-child {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.market-foot p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

.toast {
  position: fixed;
  z-index: 50;
  right: 20px;
  bottom: 20px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 15px;
  border-radius: 5px;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  50% { opacity: 0.45; }
}

@media (max-width: 1180px) {
  .quote-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .quote-card {
    min-height: 98px;
  }
}

@media (max-width: 760px) {
  .market-header {
    min-height: 60px;
    padding: 8px 13px;
  }

  .market-brand-mark {
    width: 36px;
    height: 36px;
  }

  .market-brand small,
  .header-link span {
    display: none;
  }

  .header-link {
    width: 38px;
    padding: 0;
  }

  .market-main {
    padding: 17px 10px 28px;
  }

  .market-intro {
    align-items: center;
    padding-bottom: 14px;
  }

  .market-intro h1 {
    font-size: 24px;
  }

  .market-intro p {
    font-size: 12px;
  }

  .live-state {
    min-height: 25px;
    font-size: 11px;
  }

  .clock-block span {
    display: none;
  }

  .clock-block strong {
    font-size: 14px;
  }

  .pair-list {
    grid-auto-columns: minmax(230px, 78vw);
  }

  .instrument-head {
    display: grid;
    gap: 14px;
    padding: 15px 13px;
  }

  .instrument-title-row {
    align-items: flex-start;
  }

  .instrument-head h2 {
    font-size: 18px;
    white-space: normal;
  }

  .direction-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .direction-switch button {
    min-width: 0;
  }

  .quote-grid {
    grid-template-columns: 1fr;
    padding: 9px;
  }

  .quote-card {
    min-height: 88px;
  }

  .stats-card {
    min-height: 106px;
  }

  .chart-toolbar {
    align-items: stretch;
    padding: 8px;
  }

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

  .intervals button {
    min-width: 0;
    padding: 0 3px;
    font-size: 11px;
  }

  .chart-legend {
    display: none;
  }

  .chart-stage {
    height: 440px;
    min-height: 440px;
  }

  .market-foot {
    display: grid;
    gap: 7px;
    padding: 12px;
  }

  .market-foot p {
    text-align: left;
  }
}

@media (max-width: 430px) {
  .title-line {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }

  .clock-block {
    align-self: flex-start;
    padding-top: 5px;
  }

  .spread-number {
    font-size: 27px;
  }
}

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