:root {
  color-scheme: light;
  --bg: #f4f6f3;
  --panel: #ffffff;
  --soft: #eef5f2;
  --line: #d6dfdc;
  --line-strong: #a9beb7;
  --text: #15201d;
  --muted: #53615d;
  --accent: #146b5d;
  --accent-dark: #0d3d36;
  --up: #df3b3b;
  --down: #169b62;
  --gravity: #d49a00;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 22px 32px;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 252, 251, 0.96);
}

.topbar > a {
  padding: 8px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-decoration: none;
}

.topbar p,
.topbar h1,
.status,
.chart-foot p {
  margin: 0;
}

.topbar p {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.topbar h1 {
  margin-top: 2px;
  font-size: 26px;
}

main {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 22px 32px 42px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 1px 2px rgba(21, 32, 29, 0.05);
}

.search-panel {
  position: relative;
  z-index: 2;
  padding: 18px;
}

.search-panel > label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.search-row {
  display: flex;
  gap: 8px;
}

.search-row input {
  width: min(620px, 100%);
  min-width: 0;
  height: 44px;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  outline: none;
}

.search-row input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(20, 107, 93, 0.12);
}

.search-row button,
.periods button,
.chart-actions button {
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-weight: 720;
}

.search-row button {
  height: 44px;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.search-results {
  position: absolute;
  top: 92px;
  left: 18px;
  width: min(620px, calc(100% - 36px));
  max-height: 310px;
  overflow-y: auto;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 28px rgba(13, 61, 54, 0.18);
}

.search-results:empty {
  display: none;
}

.search-results button {
  width: 100%;
  display: block;
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  text-align: left;
}

.search-results button:hover,
.search-results button:focus {
  background: var(--soft);
  outline: none;
}

.status {
  min-height: 20px;
  margin-top: 8px;
  color: #a34b20;
  font-size: 13px;
}

.chart-panel {
  margin-top: 16px;
  padding: 18px;
}

.summary,
.toolbar,
.chart-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.identity strong {
  display: block;
  font-size: 24px;
}

.identity span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.summary dl {
  display: flex;
  gap: 8px;
  margin: 0;
}

.summary dl > div {
  min-width: 114px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.summary dt {
  color: var(--muted);
  font-size: 11px;
}

.summary dd {
  margin: 4px 0 0;
  font-size: 18px;
  font-weight: 800;
}

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

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

.toolbar {
  margin-top: 16px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.periods,
.chart-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

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

.chart-actions label {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.canvas-wrap {
  position: relative;
  min-width: 0;
  height: 680px;
  margin-top: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fcfdfc;
  touch-action: none;
}

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

.tooltip {
  position: absolute;
  top: 10px;
  left: 10px;
  max-width: calc(100% - 20px);
  padding: 7px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--text);
  font-size: 12px;
  line-height: 1.45;
  opacity: 0;
  pointer-events: none;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
}

.chart-foot {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.legend-candle,
.legend-gravity {
  width: 18px;
  height: 3px;
  display: inline-block;
  margin: 0 5px 2px 10px;
  background: var(--up);
  vertical-align: middle;
}

.legend-gravity {
  background: var(--gravity);
}

@media (max-width: 760px) {
  .topbar,
  main {
    padding-left: 14px;
    padding-right: 14px;
  }

  .topbar {
    gap: 12px;
  }

  .topbar h1 {
    font-size: 22px;
  }

  .summary,
  .toolbar,
  .chart-foot {
    align-items: stretch;
    flex-direction: column;
  }

  .summary dl {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .summary dl > div {
    min-width: 0;
    padding: 9px;
  }

  .summary dd {
    font-size: 15px;
  }

  .periods,
  .chart-actions {
    flex-wrap: wrap;
  }

  .periods button {
    flex: 1;
    min-width: 68px;
  }

  .canvas-wrap {
    height: 520px;
  }
}
