:root {
  color-scheme: light;
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, sans-serif;
  color: #1d2939;
  background: #f4f6f8;
  font-synthesis: none;
  --border: #dfe3e8;
  --muted: #667085;
  --red: #b42318;
  --red-bg: #fef3f2;
  --green: #087a4b;
  --green-bg: #ecfdf3;
  --dark: #20262e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: #f4f6f8;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.topbar {
  background: #ffffff;
  border-bottom: 1px solid var(--border);
}

.topbar__inner,
main,
footer {
  width: min(1120px, calc(100% - 32px));
  margin-inline: auto;
}

.topbar__inner {
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--red);
  font-size: 12px;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.25;
  letter-spacing: 0;
}

.button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: #ffffff;
  font-weight: 700;
  white-space: nowrap;
}

.button:focus-visible,
.remove-button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(21, 112, 239, 0.25);
  outline-offset: 2px;
}

.button--primary { background: var(--red); }
.button--primary:hover { background: #912018; }
.button--dark { background: var(--dark); }
.button--dark:hover { background: #101828; }
.button:disabled { cursor: wait; opacity: 0.65; }

.refresh-icon {
  width: 18px;
  height: 18px;
  line-height: 17px;
  font-size: 22px;
}

.is-spinning .refresh-icon { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main { padding: 28px 0 18px; }

.controls {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(300px, 1fr);
  gap: 32px;
  align-items: end;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.add-form label,
.interval-label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 700;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(120px, 150px) 82px;
  grid-template-areas: "code yield submit";
  gap: 10px;
}

.input-row .button {
  grid-area: submit;
  width: 82px;
  padding-inline: 12px;
}

input[type="text"],
input[type="number"],
input:not([type]),
#stockCode,
select {
  min-height: 42px;
  border: 1px solid #c7cdd4;
  border-radius: 6px;
  background: #ffffff;
  color: #101828;
}

#stockCode,
#targetYield {
  min-width: 0;
  width: 100%;
  padding: 0 13px;
  font-variant-numeric: tabular-nums;
}

#stockCode { grid-area: code; }
#targetYield { grid-area: yield; }

.hint {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.refresh-settings {
  display: grid;
  grid-template-columns: 1fr 132px;
  gap: 16px;
  align-items: end;
}

.switch-row {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.switch-row strong,
.switch-row small { display: block; }
.switch-row strong { font-size: 14px; }
.switch-row small { margin-top: 2px; color: var(--muted); }

input[role="switch"] {
  appearance: none;
  width: 44px;
  height: 24px;
  margin: 0;
  border-radius: 12px;
  background: #98a2b3;
  position: relative;
  transition: background 0.18s ease;
}

input[role="switch"]::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 0.18s ease;
}

input[role="switch"]:checked { background: var(--red); }
input[role="switch"]:checked::after { transform: translateX(20px); }

.interval-label { margin: 0; color: var(--muted); font-weight: 500; }
select { width: 100%; margin-top: 7px; padding: 0 10px; }

.summary {
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 13px;
}

.summary > div { display: flex; align-items: center; gap: 8px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #98a2b3; }
.status-dot.is-live { background: #12b76a; box-shadow: 0 0 0 3px #d1fadf; }
.status-dot.is-error { background: #f04438; box-shadow: 0 0 0 3px #fee4e2; }

.message {
  margin: 0 0 18px;
  padding: 12px 14px;
  border: 1px solid #fecdca;
  border-radius: 6px;
  background: var(--red-bg);
  color: #912018;
  font-size: 14px;
}

.stock-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.stock-card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  padding: 18px;
}

.stock-card__head {
  min-height: 46px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: flex-start;
  gap: 12px;
}

.stock-identity { min-width: 0; }

.stock-card__price {
  min-width: 72px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  text-align: right;
}

.stock-card__price .price-label { white-space: nowrap; }

.stock-card h2 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 18px;
  line-height: 1.35;
  letter-spacing: 0;
}

.stock-code { margin: 3px 0 0; color: var(--muted); font-size: 12px; }

.remove-button {
  min-height: 30px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  padding: 0 4px;
  font-size: 12px;
}

.remove-button:hover { color: var(--red); background: var(--red-bg); }

.price-row {
  min-height: 80px;
  display: grid;
  grid-template-columns: minmax(0, 0.7fr) minmax(0, 1.3fr);
  align-items: stretch;
  margin-top: 10px;
  padding-top: 12px;
  border-top: 1px solid #edf0f2;
}

.dividend-column,
.target-column {
  min-width: 0;
}

.dividend-column,
.target-column {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.dividend-column { padding-right: 12px; }

.target-column {
  padding-left: 12px;
  border-left: 1px solid #edf0f2;
}

.target-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.price-label {
  color: var(--muted);
  font-size: 12px;
}

.stock-price {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 24px;
  line-height: 1;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.stock-distance {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 18px;
  line-height: 1.1;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stock-dividend {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 20px;
  line-height: 1.1;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.stock-target,
.stock-current-yield {
  min-height: 15px;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.target-edit-button {
  min-height: 24px;
  border: 0;
  background: transparent;
  color: #475467;
  padding: 0 2px;
  font-size: 11px;
}

.target-edit-button:hover { color: var(--red); }

.is-up { color: var(--red); }
.is-down { color: var(--green); }

.stock-card.is-loading .stock-price,
.stock-card.is-loading .stock-dividend,
.stock-card.is-loading .stock-distance { color: #98a2b3; }

.target-dialog {
  width: min(440px, calc(100% - 28px));
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  color: #1d2939;
  background: #ffffff;
  box-shadow: 0 18px 48px rgba(16, 24, 40, 0.2);
}

.target-dialog::backdrop { background: rgba(16, 24, 40, 0.5); }

.target-form { padding: 20px; }

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

.dialog-head h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.35;
  letter-spacing: 0;
}

.icon-button {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border: 0;
  border-radius: 4px;
  background: #f2f4f7;
  color: #475467;
  font-size: 24px;
  line-height: 1;
}

.icon-button:hover { background: #e4e7ec; color: #101828; }

.dialog-code {
  margin: 6px 0 20px;
  color: var(--muted);
  font-size: 13px;
}

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

.form-field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
}

.form-field:first-child { grid-column: 1 / -1; }

#dividendDialogInput,
#yieldDialogInput,
#targetDialogInput {
  width: 100%;
  padding: 0 13px;
  font-variant-numeric: tabular-nums;
}

.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 22px;
}

.dialog-actions__right { display: flex; align-items: center; gap: 8px; }

.text-button {
  min-height: 40px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #344054;
  padding: 0 10px;
  font-weight: 600;
}

.text-button:hover { background: #f2f4f7; }
.text-button--danger { color: var(--red); }

.empty-state { padding: 72px 20px; text-align: center; color: var(--muted); }
.empty-state strong { color: #344054; }
.empty-state p { margin: 7px 0 0; font-size: 14px; }

footer {
  padding: 20px 0 32px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

@media (max-width: 900px) {
  .controls { grid-template-columns: 1fr; gap: 18px; }
  .stock-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
  .topbar__inner, main, footer { width: min(100% - 24px, 1120px); }
  .topbar__inner { min-height: 76px; }
  h1 { font-size: 22px; }
  .button { padding-inline: 14px; }
  main { padding-top: 20px; }
  .refresh-settings { grid-template-columns: 1fr 120px; }
  .stock-grid { grid-template-columns: 1fr; gap: 12px; }
  .summary { align-items: flex-start; flex-direction: column; justify-content: center; gap: 4px; }
  .stock-card { padding: 16px; }
}

@media (max-width: 480px) {
  .input-row {
    grid-template-columns: minmax(0, 1fr) 82px;
    grid-template-areas:
      "code code"
      "yield submit";
  }

  .dialog-actions { align-items: stretch; flex-direction: column-reverse; }
  .dialog-actions__right { justify-content: flex-end; }
  .text-button--danger { align-self: flex-start; }
}

@media (max-width: 390px) {
  .refresh-settings { grid-template-columns: 1fr; }
  .interval-label { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
  select { width: 120px; margin-top: 0; }
}

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