:root {
  color-scheme: light;
  --ink: #1c2430;
  --muted: #6b7280;
  --line: #d8dee8;
  --panel: #ffffff;
  --canvas: #f6f7f3;
  --nav: #17202a;
  --nav-soft: #253140;
  --green: #16805a;
  --red: #bc3d3b;
  --amber: #ad7219;
  --teal: #167c80;
  --blue: #315f9c;
  --shadow: 0 18px 45px rgba(26, 34, 44, 0.09);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--canvas);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

body.modal-open {
  overflow: hidden;
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background: var(--nav);
  color: #f9fbfc;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #f2b84b;
  color: #18202b;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #aab5c4;
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  color: #c8d1dd;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
}

.nav-item:hover,
.nav-item.active {
  background: var(--nav-soft);
  color: #ffffff;
}

.market-clock {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
}

.market-clock span,
.market-clock strong {
  display: block;
}

.market-clock span {
  color: #aab5c4;
  font-size: 12px;
}

.workspace {
  padding: 28px;
  display: grid;
  gap: 28px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
}

.topbar h1 {
  margin: 4px 0 0;
  max-width: 760px;
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1.08;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.risk-profile {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(64px, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
}

.profile-option {
  border: 0;
  min-height: 40px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
}

.profile-option.active {
  background: var(--ink);
  color: #ffffff;
}

.section-grid {
  display: grid;
  gap: 16px;
}

.two-column {
  grid-template-columns: minmax(320px, 0.88fr) minmax(360px, 1.12fr);
}

.full {
  grid-column: 1 / -1;
}

.section-heading h2 {
  margin: 2px 0 0;
  font-size: 24px;
  letter-spacing: 0;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 14px;
}

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

.metric-card {
  padding: 18px;
  min-height: 112px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-top: 4px solid var(--blue);
}

.metric-card.positive {
  border-top-color: var(--green);
}

.metric-card.negative {
  border-top-color: var(--red);
}

.metric-card.warning {
  border-top-color: var(--amber);
}

.metric-card span {
  color: var(--muted);
  font-size: 13px;
}

.metric-card strong {
  font-size: 24px;
  letter-spacing: 0;
}

.panel {
  padding: 18px;
}

.panel-header,
.task-card-main {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
}

.panel-header h3 {
  margin: 2px 0 0;
  font-size: 18px;
}

.icon-button,
.ghost-button,
.primary-button,
.search-box button {
  border-radius: 8px;
  border: 1px solid var(--line);
  min-height: 40px;
}

.icon-button {
  width: 40px;
  background: #f4f7f9;
  color: var(--ink);
}

.ghost-button {
  background: #f4f7f9;
  padding: 0 12px;
  color: var(--ink);
}

.ghost-button:disabled,
.primary-button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.primary-button {
  background: var(--ink);
  color: #ffffff;
  border-color: var(--ink);
  padding: 0 16px;
  font-weight: 700;
}

.report-list,
.result-list,
.task-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.report-item,
.answer-line,
.empty-state {
  padding: 12px;
  border-radius: 8px;
  background: #f6f8fa;
  color: #354052;
}

.input-label,
label span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.search-box {
  display: grid;
  grid-template-columns: 1fr 44px;
  gap: 8px;
}

.quote-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding: 12px;
  border-radius: 8px;
  background: #f6f8fa;
}

.quote-toolbar strong,
.quote-toolbar span {
  display: block;
}

.quote-toolbar span {
  color: var(--muted);
  font-size: 12px;
}

.market-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.filter-chip {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--muted);
}

.filter-chip.active {
  border-color: var(--ink);
  background: var(--ink);
  color: #ffffff;
}

.add-stock-box {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.add-stock-box summary {
  cursor: pointer;
  color: var(--ink);
  font-weight: 800;
}

.stock-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  min-height: 42px;
  padding: 10px 12px;
  resize: vertical;
}

.search-box button {
  background: #f4f7f9;
}

.stock-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.stock-card:hover {
  border-color: var(--teal);
}

.stock-card strong,
.stock-card span,
.task-card strong,
.task-card span,
.holding-table td span {
  display: block;
}

.stock-card span,
.task-card span,
.holding-table td span {
  color: var(--muted);
  font-size: 12px;
}

.stock-price {
  text-align: right;
  min-width: 96px;
}

.stock-card-side {
  display: flex;
  align-items: center;
  gap: 10px;
}

.quote-line {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 18px 0 12px;
}

.quote-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.quote-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-weight: 800;
}

.quote-badge.live {
  background: #eaf4f1;
  color: var(--green);
}

.quote-badge.cached {
  background: #fff3df;
  color: var(--amber);
}

.quote-badge.sample {
  background: #eef2f7;
  color: var(--muted);
}

.quote-line strong {
  font-size: 32px;
  letter-spacing: 0;
}

.positive-text {
  color: var(--green);
}

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

.market-chip,
.stage-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: #eaf4f1;
  color: #116a57;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

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

.detail-grid span {
  padding: 10px;
  border-radius: 8px;
  background: #f6f8fa;
  color: var(--muted);
}

.detail-grid strong {
  display: block;
  color: var(--ink);
}

.detail-copy,
.risk-copy,
.fine-print {
  margin: 12px 0 0;
}

.risk-copy {
  color: #6b4b1c;
}

.fine-print {
  color: var(--muted);
  font-size: 12px;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}

.tag-row span {
  padding: 6px 9px;
  border-radius: 999px;
  background: #eef2f7;
  color: #435166;
  font-size: 12px;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.chart-panel {
  display: grid;
  gap: 14px;
}

.chart-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
}

.chart-toolbar label {
  min-width: 240px;
}

.range-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.range-button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
}

.range-button.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #ffffff;
}

.chart-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  min-height: 42px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #f6f8fa;
  color: var(--muted);
}

.chart-summary strong {
  color: var(--ink);
}

.chart-wrap {
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.kline-canvas {
  display: block;
  width: 100%;
  min-height: 420px;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}

.modal-kline-canvas {
  min-height: 390px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  color: var(--muted);
  font-size: 12px;
}

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

.chart-legend i {
  width: 18px;
  height: 3px;
  border-radius: 999px;
  display: inline-block;
}

.legend-up {
  background: var(--green);
}

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

.legend-ma5 {
  background: var(--blue);
}

.legend-ma20 {
  background: var(--amber);
}

.watch-form,
.holding-form,
.dca-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.holding-form {
  grid-template-columns: minmax(180px, 1.2fr) minmax(140px, 0.9fr) minmax(140px, 0.9fr) auto;
  align-items: end;
}

.full-field {
  grid-column: 1 / -1;
}

.task-card {
  position: relative;
  padding: 14px 46px 14px 14px;
  box-shadow: none;
}

.clickable-card {
  cursor: pointer;
}

.clickable-card:hover {
  border-color: var(--teal);
}

.task-card p {
  margin: 12px 0 6px;
}

.task-card small {
  color: var(--amber);
}

.remove-watch {
  position: absolute;
  right: 10px;
  top: 10px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: #f4f7f9;
  color: var(--muted);
}

.task-chart-action {
  margin-top: 10px;
}

.table-action {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 34px;
  padding: 0 10px;
  background: #f4f7f9;
  color: var(--muted);
}

.table-actions,
.dca-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.link-button,
.plan-item-main {
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.link-button:hover strong,
.plan-item-main:hover strong {
  color: var(--teal);
}

.plan-item-main {
  flex: 1;
  cursor: pointer;
}

.plan-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.plan-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px;
  border-radius: 8px;
  background: #f6f8fa;
  color: #354052;
}

.plan-item strong,
.plan-item span {
  display: block;
}

.plan-item span {
  color: var(--muted);
  font-size: 12px;
}

.holding-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.holding-table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

.holding-table th,
.holding-table td {
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.holding-table th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  background: #f8fafb;
}

.holding-table tr:last-child td {
  border-bottom: 0;
}

.dca-output,
.assistant-answer {
  min-height: 238px;
}

#assistantQuestion {
  margin-bottom: 14px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(23, 32, 42, 0.58);
}

.modal-backdrop.is-open {
  display: flex;
}

.modal-panel {
  width: min(1120px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.28);
}

.kline-modal {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.modal-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.modal-header h2 {
  margin: 2px 0 0;
  font-size: 24px;
  letter-spacing: 0;
}

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

.modal-close {
  flex: 0 0 auto;
  font-size: 20px;
}

.modal-range-switch {
  justify-content: flex-end;
}

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

  .sidebar {
    position: static;
    height: auto;
  }

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

  .market-clock {
    margin-top: 0;
  }

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

@media (max-width: 720px) {
  .workspace {
    padding: 18px;
  }

  .topbar {
    display: grid;
  }

  .chart-toolbar {
    display: grid;
  }

  .stock-card,
  .stock-card-side,
  .plan-item,
  .modal-header {
    align-items: stretch;
  }

  .stock-card,
  .stock-card-side,
  .plan-item,
  .modal-header,
  .dca-header-actions {
    display: grid;
  }

  .stock-price {
    text-align: left;
  }

  .modal-backdrop {
    padding: 10px;
  }

  .kline-modal {
    padding: 14px;
  }

  .modal-panel {
    max-height: calc(100vh - 20px);
  }

  .modal-range-switch {
    justify-content: start;
  }

  .chart-toolbar label {
    min-width: 0;
  }

  .risk-profile,
  .metric-grid,
  .two-column,
  .watch-form,
  .holding-form,
  .stock-form,
  .dca-form,
  .detail-grid {
    grid-template-columns: 1fr;
  }

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

  .full-field,
  .full {
    grid-column: auto;
  }

  .quote-line {
    display: grid;
    gap: 4px;
  }
}
