:root {
  color-scheme: light;
  --bg: #eef2f6;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #64748b;
  --line: #dbe3ec;
  --red: #ef4444;
  --blue: #2563eb;
  --green: #059669;
  --amber: #b45309;
  --shadow: 0 14px 38px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 22px;
}

.topbar,
.section-heading,
.holdings-panel,
.footer,
.detail-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 86px;
  padding: 18px 20px;
  border-radius: 8px;
}

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

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 19px;
  letter-spacing: 0;
}

.status-pill {
  flex: 0 0 auto;
  border: 1px solid #bbf7d0;
  background: #f0fdf4;
  color: #166534;
  padding: 10px 12px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 13px;
}

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

.market-card {
  min-height: 146px;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.market-card span,
.market-card em,
.metric b,
.stock-main em {
  display: block;
  color: var(--muted);
  font-style: normal;
}

.market-card strong {
  display: block;
  margin: 8px 0 3px;
  font-size: 23px;
}

.market-card small {
  font-weight: 800;
}

.investor-flow {
  display: grid;
  gap: 4px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--line);
}

.investor-flow span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.investor-flow b {
  color: #334155;
}

.up small,
.up.price-block,
.stock-row .up,
.market-card.up small {
  color: var(--red);
}

.down small,
.down.price-block,
.stock-row .down,
.market-card.down small {
  color: var(--blue);
}

.flat small,
.flat.price-block,
.flat {
  color: var(--muted);
}

.holdings-panel {
  margin-bottom: 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.flat-heading {
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
}

.holding-form {
  display: flex;
  gap: 8px;
  width: min(420px, 100%);
}

.search-combobox {
  position: relative;
  flex: 1;
  min-width: 0;
}

.holding-form input,
.price-edit input {
  min-width: 0;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.holding-form input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
}

.suggestion-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  left: 0;
  z-index: 5;
  display: grid;
  gap: 4px;
  padding: 6px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.suggestion-list[hidden] {
  display: none;
}

.suggestion-list button {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  min-height: 42px;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.suggestion-list button.active,
.suggestion-list button:hover {
  background: #eef2f6;
}

.suggestion-list strong,
.suggestion-list span {
  display: block;
  font-size: 13px;
}

.suggestion-list span {
  color: var(--muted);
  font-weight: 800;
}

.holding-form button,
.candidate-add,
.holding-delete {
  border: 1px solid #111827;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  cursor: pointer;
  font-weight: 900;
}

.holding-form button {
  min-width: 72px;
}

.holding-list {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.holding-empty {
  margin: 0;
  padding: 14px 16px 18px;
  color: var(--muted);
}

.holding-row {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) repeat(4, minmax(92px, 0.55fr)) 122px 66px;
  align-items: center;
  gap: 10px;
  min-height: 78px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.holding-open {
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.holding-metric,
.holding-advice {
  font-size: 13px;
  font-weight: 900;
}

.holding-metric b,
.price-edit b {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
}

.price-edit input {
  width: 100%;
  height: 34px;
  padding: 0 8px;
  font-weight: 900;
}

.holding-advice {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 34px;
  border-radius: 999px;
  padding: 0 10px;
  white-space: nowrap;
}

.holding-advice.buy {
  background: #fee2e2;
  color: #b91c1c;
}

.holding-advice.sell {
  background: #dbeafe;
  color: #1d4ed8;
}

.holding-advice.wait {
  background: #f1f5f9;
  color: #475569;
}

.holding-delete {
  min-height: 34px;
  border-color: #cbd5e1;
  background: #fff;
  color: #334155;
}

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

.leader-section {
  min-width: 0;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 74px;
  padding: 14px 16px;
  border-radius: 8px 8px 0 0;
  box-shadow: none;
}

.section-note {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.stock-list {
  display: grid;
  gap: 8px;
  padding: 8px 0 0;
}

.stock-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 62px;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 86px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.stock-select {
  display: grid;
  grid-template-columns: 38px minmax(150px, 1.3fr) minmax(92px, 0.8fr) repeat(5, minmax(82px, 0.7fr)) 86px 56px;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 62px;
  min-width: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.candidate-add {
  min-height: 34px;
  border-color: #cbd5e1;
  background: #fff;
  color: #111827;
}

.stock-row:hover,
.stock-row.selected {
  border-color: #94a3b8;
  transform: translateY(-1px);
}

.rank {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #111827;
  color: #fff;
  font-weight: 900;
}

.stock-main strong,
.price-block strong {
  display: block;
  font-size: 16px;
}

.price-block em,
.score,
.signal {
  font-style: normal;
  font-weight: 900;
}

.metric {
  color: #1f2937;
  font-size: 13px;
  font-weight: 800;
}

.metric b {
  margin-bottom: 3px;
  font-size: 11px;
  font-weight: 800;
}

.signal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
}

.signal.buy {
  background: #fee2e2;
  color: #b91c1c;
}

.signal.watch {
  background: #fef3c7;
  color: var(--amber);
}

.signal.sell {
  background: #dbeafe;
  color: #1d4ed8;
}

.signal.wait {
  background: #f1f5f9;
  color: #475569;
}

.score {
  text-align: right;
  color: #0f172a;
}

.detail-panel {
  display: grid;
  grid-template-columns: minmax(260px, 0.34fr) minmax(0, 0.66fr);
  gap: 18px;
  margin-top: 16px;
  padding: 18px;
  border-radius: 8px;
}

.detail-copy p:last-child {
  color: var(--muted);
  line-height: 1.6;
}

.chart-wrap {
  position: relative;
  min-width: 0;
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #f8fafc;
}

#priceChart {
  display: block;
  width: 100%;
  height: 420px;
  touch-action: none;
}

.chart-tooltip {
  position: absolute;
  z-index: 3;
  min-width: 166px;
  padding: 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  pointer-events: none;
}

.chart-tooltip strong,
.chart-tooltip span {
  display: block;
  font-size: 12px;
}

.chart-tooltip span {
  color: var(--muted);
  margin-top: 3px;
}

.detail-metrics {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 8px;
}

.detail-metrics div {
  min-height: 68px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.detail-metrics span,
.detail-metrics strong {
  display: block;
}

.detail-metrics span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.detail-metrics strong {
  margin-top: 6px;
  font-size: 15px;
}

.footer {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 8px;
  color: var(--muted);
  line-height: 1.6;
}

.footer div {
  color: #334155;
  font-weight: 800;
}

.footer p {
  margin-bottom: 0;
}

.confirm-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.42);
}

.confirm-backdrop[hidden] {
  display: none;
}

.confirm-dialog {
  width: min(420px, 100%);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.24);
}

.confirm-dialog h2 {
  margin-bottom: 8px;
}

.confirm-dialog p {
  color: var(--muted);
  line-height: 1.5;
}

.confirm-dialog div {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.confirm-dialog button {
  min-width: 82px;
  min-height: 38px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: #334155;
  cursor: pointer;
  font-weight: 900;
}

#confirmDelete {
  border-color: #111827;
  background: #111827;
  color: #fff;
}

@media (max-width: 1480px) {
  .leaders-grid,
  .detail-panel {
    grid-template-columns: 1fr;
  }
}

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

  .stock-select {
    grid-template-columns: 38px minmax(160px, 1fr) 92px 90px 90px 90px 90px;
  }

  .stock-select .metric:nth-of-type(n + 4),
  .score {
    display: none;
  }

  .holding-row {
    grid-template-columns: minmax(180px, 1fr) repeat(3, minmax(92px, 0.6fr)) 118px 64px;
  }

  .holding-row .holding-metric:nth-of-type(4) {
    display: none;
  }

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

@media (max-width: 640px) {
  .app-shell {
    padding: 12px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  h1 {
    font-size: 24px;
  }

  .status-pill {
    width: 100%;
    text-align: center;
  }

  .market-strip {
    grid-template-columns: 1fr;
  }

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

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .holding-form {
    width: 100%;
  }

  .holding-row {
    grid-template-columns: minmax(0, 1fr) 74px;
  }

  .holding-open {
    grid-column: 1 / 3;
  }

  .holding-row .holding-metric,
  .holding-advice {
    display: block;
  }

  .holding-row .holding-metric:nth-of-type(n + 4) {
    display: none;
  }

  .stock-row {
    grid-template-columns: 1fr 58px;
    min-height: 138px;
  }

  .stock-select {
    grid-template-columns: 34px minmax(0, 1fr) minmax(84px, auto);
    gap: 8px;
  }

  .stock-select .metric {
    display: block;
  }

  .stock-select .metric:nth-of-type(n + 3),
  .score {
    display: none;
  }

  .signal {
    grid-column: 2 / 4;
    justify-self: start;
    padding: 0 12px;
  }

  .chart-wrap {
    min-height: 360px;
  }

  #priceChart {
    height: 360px;
  }

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