:root {
  color-scheme: light;
  font-family: Arial, "Microsoft YaHei", sans-serif;
  background: #f4f6f8;
  color: #1f2933;
  --border: #d8dee6;
  --muted: #65717f;
  --soft: #f8fafc;
  --panel: #ffffff;
  --accent: #2454a6;
  --accent-dark: #1d4385;
  --warning: #8a5a10;
  --success: #256f58;
  --error: #a33a3a;
}

* {
  box-sizing: border-box;
}

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

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

button,
select,
input,
textarea {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
  color: #1f2933;
}

button,
select,
input {
  height: 30px;
}

button {
  padding: 0 10px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

button:hover:not(:disabled) {
  border-color: #b9c4d1;
  background: #f7f9fc;
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

input,
select,
textarea {
  padding: 0 10px;
}

textarea {
  min-height: 112px;
  padding-top: 9px;
  resize: vertical;
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.primary-button:hover:not(:disabled) {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

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

.brand-main {
  padding: 7px 16px 6px;
  border-bottom: 1px solid #edf1f5;
}

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

.brand-name {
  font-size: 21px;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-domain {
  display: inline-block;
  margin-left: 3px;
  color: #334155;
  font-size: 17px;
  font-weight: 700;
  transform: scaleX(0.86);
  transform-origin: left center;
}

.brand-subtitle {
  margin-top: 2px;
  color: #334155;
  font-size: 13px;
  font-weight: 600;
}

.beta-stack {
  flex: 0 1 420px;
  display: grid;
  justify-items: end;
  gap: 3px;
  text-align: right;
}

.beta-badge {
  flex: 0 0 auto;
  padding: 3px 8px;
  border: 1px solid #cfdae7;
  border-radius: 999px;
  background: #f6f9fd;
  color: #3b536f;
  font-size: 12px;
  line-height: 1.4;
}

.risk-line {
  line-height: 1.45;
}

.risk-line {
  color: #6f5b2b;
  font-size: 11px;
}

.search-panel {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px 16px;
  overflow-x: auto;
}

.control-group {
  display: grid;
  gap: 3px;
  min-width: 230px;
}

.control-group.compact {
  min-width: 128px;
}

.control-group.period-group {
  min-width: 128px;
}

.control-group label {
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
}

#stockInput {
  width: 250px;
}

.backfill-wrap {
  min-width: 112px;
}

.top-actions {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 8px;
  margin-left: auto;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  min-height: calc(100vh - 86px);
}

.chart-area {
  min-width: 0;
  display: flex;
}

.chart-pane {
  min-width: 0;
  min-height: 520px;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px 10px;
}

iframe {
  width: 100%;
  min-height: 0;
  flex: 1 1 auto;
  display: block;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
}

.side {
  border-left: 1px solid var(--border);
  background: #fbfcfd;
  padding: 12px;
  overflow: auto;
}

.status-block,
.rule-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.status-block {
  padding: 12px;
}

.status-trial-hint {
  margin: 10px 0 0;
  padding-top: 10px;
  border-top: 1px solid #edf1f5;
  color: #65717f;
  font-size: 12px;
  line-height: 1.45;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.3;
}

.status-badge {
  flex: 0 0 auto;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eef3f9;
  color: #40556e;
  font-size: 12px;
}

.status-badge[data-state="ready"] {
  background: #edf8f4;
  color: var(--success);
}

.status-badge[data-state="warning"],
.status-badge[data-state="busy"] {
  background: #fff7e8;
  color: var(--warning);
}

.status-badge[data-state="error"] {
  background: #fff0f0;
  color: var(--error);
}

dl {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 8px 9px;
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
}

dt {
  color: var(--muted);
}

dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  color: #1f2933;
}

.status-term {
  border-bottom: 1px dotted #9aa7b5;
  cursor: help;
}

.backfill-result-ok {
  color: var(--success);
  font-weight: 700;
}

.backfill-result-empty {
  color: var(--error);
  font-weight: 700;
}

.rule-panel {
  margin-top: 12px;
  padding: 0;
}

.rule-panel summary {
  padding: 11px 12px;
  color: #243244;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.rule-content {
  padding: 0 12px 12px;
  border-top: 1px solid #edf1f5;
  color: #4a5563;
  font-size: 12px;
  line-height: 1.6;
}

.rule-content p {
  margin: 10px 0 0;
}

.rule-content ol {
  margin: 8px 0 0;
  padding-left: 20px;
}

.rule-content ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.disclaimer-footer {
  border-top: 1px solid var(--border);
  background: #ffffff;
  padding: 9px 18px;
  color: #65717f;
  font-size: 12px;
  line-height: 1.45;
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(16, 24, 40, 0.42);
}

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

.dialog {
  width: min(460px, 100%);
  max-height: min(720px, calc(100vh - 40px));
  overflow: auto;
  border-radius: 8px;
  border: 1px solid #cfd8e3;
  background: #ffffff;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.22);
}

.feedback-dialog {
  width: min(560px, 100%);
}

.guide-dialog {
  width: min(500px, 100%);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid #edf1f5;
}

.icon-button {
  width: 32px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.dialog-actions {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.dialog-actions button {
  justify-content: center;
}

.dialog-intro {
  margin: 0;
  padding: 14px 16px 0;
  color: #4a5563;
  font-size: 13px;
  line-height: 1.55;
}

.dialog-note {
  margin: 0;
  padding: 8px 16px 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.guide-content {
  padding: 14px 16px 0;
  color: #3f4c5f;
  font-size: 13px;
  line-height: 1.6;
}

.guide-content p {
  margin: 0 0 9px;
}

.guide-content ol {
  margin: 6px 0 10px;
  padding-left: 20px;
}

.guide-risk {
  color: #6f5b2b;
}

.link-button {
  height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
}

.link-button:hover:not(:disabled) {
  border-color: transparent;
  background: transparent;
  color: var(--accent-dark);
  text-decoration: underline;
}

.period-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 16px 16px 0;
}

.period-options label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fbfcfd;
  color: #334155;
  font-size: 13px;
  cursor: pointer;
}

.period-options input {
  width: 15px;
  height: 15px;
  padding: 0;
}

.field {
  display: grid;
  gap: 6px;
  padding: 14px 16px 0;
  color: #334155;
  font-size: 13px;
}

.field span {
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  width: 100%;
}

.dialog-footer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px;
}

.dialog-message {
  min-height: 22px;
  margin: 0;
  padding: 0 16px 16px;
  color: var(--success);
  font-size: 13px;
  line-height: 1.45;
}

.dialog-message[data-state="error"] {
  color: var(--error);
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .side {
    border-left: 0;
    border-top: 1px solid var(--border);
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(260px, 0.7fr);
    gap: 12px;
  }

  .rule-panel {
    margin-top: 0;
  }
}

@media (max-width: 720px) {
  .brand-main,
  .search-panel,
  .disclaimer-footer {
    padding-left: 12px;
    padding-right: 12px;
  }

  .brand-row,
  .dialog-footer-actions {
    flex-direction: column;
  }

  .brand-row,
  .dialog-footer-actions {
    align-items: stretch;
  }

  .beta-stack {
    justify-items: start;
    text-align: left;
  }

  .search-panel {
    align-items: stretch;
    flex-wrap: wrap;
    overflow: visible;
  }

  .control-group,
  .control-group.compact,
  .backfill-wrap,
  #stockInput {
    width: 100%;
    min-width: 0;
  }

  .top-actions {
    width: 100%;
    margin-left: 0;
    flex-wrap: wrap;
  }

  .top-actions button {
    flex: 1 1 180px;
  }

  .chart-pane {
    min-height: 420px;
  }

  .side {
    grid-template-columns: 1fr;
  }
}
