:root {
  color-scheme: dark;
  --bg: #0b0b0f;
  --panel: #111116;
  --panel-2: #15151c;
  --panel-3: #0f0f14;
  --line: #282831;
  --line-strong: #383844;
  --text: #eef2ff;
  --muted: #858b98;
  --green: #00c5a8;
  --green-soft: rgba(0, 197, 168, 0.16);
  --red: #ff5a1f;
  --red-soft: rgba(255, 90, 31, 0.16);
  --up: var(--red);
  --down: var(--green);
  --up-soft: var(--red-soft);
  --down-soft: var(--green-soft);
  --blue: #3398ff;
  --yellow: #f5ba3d;
  --pink: #ff66bd;
  font-family:
    Inter, "Microsoft YaHei", "PingFang SC", "Segoe UI", system-ui, sans-serif;
}

body.theme-green-up {
  --up: var(--green);
  --down: var(--red);
  --up-soft: var(--green-soft);
  --down-soft: var(--red-soft);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

/* ===== 模态框 / 复盘报告 / 历史（P1） ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
  padding: 24px;
}
.modal-overlay[hidden] {
  display: none;
}
.modal {
  position: relative;
  width: min(680px, 96vw);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 22px 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}
.modal-close:hover {
  color: var(--text);
}
.modal-title {
  margin: 0 0 6px;
  font-size: 18px;
}
.modal-sub {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}
.ghost-button {
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 8px;
}
.primary-action {
  background: var(--blue);
  color: #fff;
  padding: 8px 18px;
  border-radius: 8px;
}
.rating-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.rating-row button {
  flex: 1 1 auto;
  min-width: 72px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 14px 8px;
  border-radius: 10px;
  font-weight: 600;
}
.rating-row button:hover {
  border-color: var(--blue);
  background: var(--panel-3);
}
.report-grid {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.report-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 120px;
  padding: 14px 18px;
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
}
.report-score strong {
  font-size: 38px;
  line-height: 1.1;
  color: var(--yellow);
}
.report-score span {
  color: var(--muted);
  font-size: 13px;
}
.report-score small {
  color: var(--muted);
  font-size: 11px;
  margin-top: 2px;
}
.report-results {
  flex: 1 1 260px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 18px;
  align-content: center;
}
.report-results > div {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 4px 0;
}
.report-results span {
  color: var(--muted);
}
.report-section {
  margin-top: 14px;
}
.report-section h4 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--muted);
}
.report-findings {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.report-findings li {
  background: var(--red-soft);
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
}
.report-findings li.good {
  background: var(--green-soft);
}
.report-selfcheck {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.report-selfcheck p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.report-table th,
.report-table td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.report-table th {
  color: var(--muted);
  font-weight: 600;
}
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.history-item {
  display: grid;
  grid-template-columns: 92px 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.history-item:hover {
  background: var(--panel-2);
}
.history-date {
  color: var(--muted);
  font-size: 13px;
}
.history-score {
  color: var(--yellow);
  font-size: 13px;
}
.finish-button {
  color: var(--yellow);
}

/* ===== 长期画像 ===== */
.insight-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
  margin-bottom: 8px;
}
.insight-grid > div {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.insight-grid span {
  color: var(--muted);
  font-size: 12px;
}
.insight-grid strong {
  font-size: 20px;
}
.spark {
  width: 100%;
  height: 130px;
  display: block;
}
.spark-line {
  stroke: var(--yellow);
  stroke-width: 2;
}
.spark-grid {
  stroke: rgba(255, 255, 255, 0.12);
  stroke-dasharray: 4 4;
}
.spark circle {
  fill: var(--yellow);
}
.spark-axis {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 11px;
  margin-top: 2px;
}
.rank-row {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 5px 0;
}
.rank-label {
  font-size: 13px;
}
.rank-bar {
  background: var(--panel-3);
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}
.rank-bar i {
  display: block;
  height: 100%;
  background: var(--red-soft);
  border-right: 2px solid var(--red);
}
.rank-count {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.app-shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.topbar {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: #101016;
  color: #dce6ff;
}

.ticker-left,
.top-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.ticker-left strong {
  font-size: 14px;
  white-space: nowrap;
}

.ticker-left span {
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.ticker-price,
.quote-price,
.positive {
  color: var(--up) !important;
}

.ticker-change,
.negative {
  color: var(--down) !important;
}

.ticker-badge {
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--red);
  color: #fff;
}

.tool-button {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  border-radius: 4px;
  background: transparent;
  color: #c9d3e6;
  font-size: 13px;
}

.import-button {
  white-space: nowrap;
}

.file-input {
  display: none;
}

.tool-button:hover {
  background: #1b1b24;
}

.settings-wrap {
  position: relative;
}

.settings-menu {
  position: absolute;
  top: 34px;
  right: 0;
  z-index: 20;
  width: 150px;
  padding: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #15151d;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.42);
}

.settings-title {
  padding: 4px 7px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.theme-option,
.plan-option {
  width: 100%;
  height: 30px;
  padding: 0 8px;
  border-radius: 4px;
  background: transparent;
  color: #dce6ff;
  text-align: left;
  font-size: 13px;
}

.theme-option:hover,
.theme-option.active,
.plan-option:hover,
.plan-option.active {
  background: #22222d;
  color: #fff;
}

.workspace {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 306px;
  border-bottom: 1px solid var(--line);
}

.chart-panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.chart-header {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: #121218;
}

.market-title {
  font-size: 14px;
  font-weight: 900;
}

.market-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.indicator-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 12px;
  color: #b8bfcc;
  font-size: 12px;
  font-weight: 800;
}

.indicator-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.swatch {
  width: 10px;
  height: 3px;
  display: inline-block;
  border-radius: 99px;
}

.swatch-volume {
  background: var(--up);
}

.swatch-k {
  background: var(--yellow);
}

.swatch-d {
  background: #3f7cff;
}

.swatch-j {
  background: var(--pink);
}

.swatch-dif {
  background: #4c82ff;
}

.swatch-dea {
  background: var(--yellow);
}

.chart-wrap {
  min-height: 0;
  flex: 1;
  overflow: hidden;
  background: #111116;
  cursor: grab;
}

.chart-wrap.dragging {
  cursor: grabbing;
}

#priceCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.timeline {
  min-height: 46px;
  display: grid;
  grid-template-columns: auto auto auto minmax(140px, 160px) minmax(120px, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-top: 1px solid var(--line);
  background: #101016;
}

.timeline-controls,
.trade-buttons {
  display: flex;
  align-items: center;
  gap: 7px;
}

.icon-button,
.day-button,
.buy-button,
.short-button,
.close-button {
  min-height: 30px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  color: var(--text);
  background: #171720;
}

.icon-button {
  width: 32px;
  display: grid;
  place-items: center;
  font-size: 18px;
}

.day-button {
  padding: 0 10px;
  color: #dce6ff;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.primary-day-button {
  border-color: rgba(51, 152, 255, 0.5);
  background: rgba(51, 152, 255, 0.15);
  color: #9dccff;
}

.date-chip {
  min-height: 30px;
  display: grid;
  place-items: center;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: #15151d;
  color: #c4cad5;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.zoom-chip {
  color: #80e8df;
}

.width-chip {
  color: #f1c65b;
}

.candle-width-control {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.candle-width-control input[type="range"] {
  width: 78px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--blue);
}

.speed-control {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

select,
input,
textarea {
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: #0f0f14;
  color: var(--text);
}

select {
  height: 30px;
  padding: 0 7px;
}

.side-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: #0f0f14;
}

.quote-head {
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--line);
}

.quote-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #dfe8ff;
  font-size: 14px;
  font-weight: 900;
}

.quote-title span {
  color: #a3abb9;
  font-size: 13px;
}

.quote-price {
  margin-top: 14px;
  font-size: 34px;
  line-height: 1;
  font-weight: 900;
}

.quote-change,
.quote-date {
  margin-top: 7px;
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
}

.quote-date {
  color: var(--muted);
  font-weight: 700;
}

.quote-table {
  display: grid;
  gap: 7px;
  padding: 12px 16px 14px;
  border-bottom: 1px solid var(--line);
}

.quote-table div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
}

.quote-table span {
  color: #c9cfda;
}

.quote-table strong,
.hot {
  color: var(--up);
  font-weight: 900;
}

.quote-table .cool {
  color: var(--down);
}

.panel-block {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-title {
  margin-bottom: 9px;
  color: #a3abb9;
  font-size: 12px;
  font-weight: 900;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.metric-grid div {
  min-height: 56px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #121218;
}

.metric-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric-grid strong {
  display: block;
  margin-top: 7px;
  font-size: 15px;
}

.form-row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 16px;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  color: #b8bfcc;
  font-size: 13px;
}

.form-row input {
  height: 30px;
  padding: 0 8px;
}

.order-hint {
  margin: -2px 0 7px;
  color: var(--muted);
  font-size: 12px;
}

.reason-input {
  width: 100%;
  height: 34px;
  margin: 3px 0 10px;
  padding: 0 9px;
}

.buy-button,
.short-button,
.close-button {
  flex: 1;
  padding: 0 10px;
  font-weight: 900;
}

.buy-button {
  border-color: rgba(0, 197, 168, 0.42);
  background: var(--green-soft);
  color: #3be8d2;
}

.short-button {
  border-color: rgba(255, 90, 31, 0.45);
  background: var(--red-soft);
  color: #ff8b61;
}

.close-button {
  border-color: rgba(51, 152, 255, 0.45);
  background: rgba(51, 152, 255, 0.16);
  color: #9dccff;
}

.position-card {
  min-height: 76px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #121218;
}

.position-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.position-card strong {
  display: block;
  margin-top: 6px;
  font-size: 17px;
}

.position-card small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  line-height: 1.45;
}

.terminal-bottom {
  height: 206px;
  min-height: 170px;
  display: grid;
  grid-template-columns: minmax(220px, 0.55fr) minmax(190px, 0.38fr) minmax(520px, 1.45fr);
  background: #0d0d12;
}

.journal-panel,
.notes-panel {
  min-width: 0;
  padding: 10px 12px;
  border-right: 1px solid var(--line);
}

.notes-panel {
  display: grid;
  grid-template-rows: auto minmax(62px, 1fr) auto;
  gap: 8px;
}

.bottom-trade-panel {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(340px, 1fr) minmax(170px, 0.48fr);
  border-right: 0;
}

.bottom-trade-panel .panel-block {
  padding: 10px 12px;
  border-right: 1px solid var(--line);
  border-bottom: 0;
}

.bottom-trade-panel .panel-block:last-child {
  border-right: 0;
}

.position-block {
  display: flex;
  flex-direction: column;
}

.bottom-trade-panel .position-card {
  min-height: 124px;
  flex: 1;
}

.order-block {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-content: start;
  gap: 5px 8px;
}

.order-block .panel-title,
.order-block .order-hint,
.order-block .reason-input,
.order-block .trade-buttons {
  grid-column: 1 / -1;
}

.order-block .panel-title {
  margin-bottom: 0;
}

.order-block .form-row {
  grid-template-columns: 34px minmax(0, 1fr) 12px;
  gap: 4px;
  margin-bottom: 0;
  font-size: 12px;
}

.order-block .form-row input {
  height: 28px;
  padding: 0 6px;
}

.order-block .order-hint {
  margin: 0;
}

.order-block .reason-input {
  height: 30px;
  margin: 0;
}

.order-block .trade-buttons {
  align-self: end;
}

.table-wrap {
  max-height: 172px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 4px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

th,
td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 12px;
}

th {
  position: sticky;
  top: 0;
  background: #121218;
  color: #a8afbc;
  font-weight: 900;
}

td {
  color: #dfe5f2;
}

.empty-row td {
  color: var(--muted);
  text-align: center;
}

textarea {
  width: 100%;
  min-height: 62px;
  resize: none;
  padding: 9px;
  line-height: 1.5;
}

.coach-box {
  min-height: 42px;
  padding: 9px;
  border: 1px solid rgba(0, 197, 168, 0.25);
  border-radius: 4px;
  background: rgba(0, 197, 168, 0.07);
  color: #b8ece8;
  font-size: 12px;
  line-height: 1.45;
}

@media (max-width: 1100px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
  }

  .workspace,
  .terminal-bottom {
    grid-template-columns: 1fr;
  }

  .workspace {
    flex: none;
  }

  .chart-wrap {
    height: 660px;
    flex: none;
  }

  .side-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .terminal-bottom {
    width: 100%;
    height: auto;
    grid-template-columns: minmax(0, 0.65fr) minmax(220px, 0.45fr) minmax(420px, 1.35fr);
  }

  .bottom-trade-panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .topbar,
  .ticker-left,
  .top-tools,
  .chart-header,
  .timeline {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    height: auto;
    padding: 8px 10px;
  }

  .top-tools,
  .ticker-left {
    flex-wrap: wrap;
  }

  .timeline {
    display: flex;
  }

  .timeline-controls {
    flex-wrap: wrap;
  }

  .chart-wrap {
    height: 620px;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }

  .terminal-bottom {
    width: 100%;
    display: block;
  }

  .order-block {
    grid-template-columns: 1fr;
  }

  .order-block .form-row {
    grid-template-columns: 48px minmax(0, 1fr) 16px;
  }
}
