:root {
  color-scheme: light;
  --bg: #f6f7f3;
  --ink: #20242b;
  --muted: #687080;
  --line: #dde1d8;
  --panel: #ffffff;
  --blue: #2f6fed;
  --green: #087f5b;
  --red: #c92a2a;
  --yellow: #b7791f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

.hidden {
  display: none !important;
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgba(246, 247, 243, 0.94);
}

.login-box {
  width: min(360px, calc(100vw - 32px));
  display: grid;
  gap: 12px;
  padding: 22px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.login-box p {
  margin: 0;
  color: var(--muted);
}

.app {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.brand {
  display: grid;
  gap: 5px;
}

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

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 26px;
}

h2 {
  font-size: 16px;
}

.actions {
  display: flex;
  gap: 10px;
}

.view-tabs {
  display: flex;
  gap: 8px;
  margin: 0 0 14px;
}

.tab-button {
  background: #fff;
}

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

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  padding: 0 12px;
  cursor: pointer;
}

button:first-child {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

button.small-button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 13px;
}

button.danger {
  border-color: #f1b7b7;
  background: #fff5f5;
  color: var(--red);
}

button.secondary {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

#refreshBtn {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1.4fr repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

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

.metric {
  padding: 15px;
}

.metric span,
.metric small,
.panel-head span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin: 6px 0 4px;
  font-size: 26px;
}

.metric.primary strong {
  font-size: 30px;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.v3-grid {
  margin-bottom: 14px;
}

.advisor-panel {
  padding-bottom: 13px;
}

.advisor-sections {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}

.advisor-section {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 9px;
}

.section-head {
  min-height: 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

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

.panel {
  padding: 15px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.risk-list {
  display: grid;
  gap: 10px;
}

.risk {
  border-left: 4px solid var(--yellow);
  background: #fff8e1;
  border-radius: 6px;
  padding: 10px 12px;
}

.risk.red {
  border-left-color: var(--red);
  background: #fff0f0;
}

.risk strong {
  display: block;
  margin-bottom: 3px;
}

.advisor-list,
.status-list {
  display: grid;
  gap: 10px;
}

.advice-item,
.brief-card,
.status-row,
.empty-state {
  width: 100%;
  min-height: auto;
  display: grid;
  gap: 5px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-left: 4px solid #b8c0b2;
  border-radius: 8px;
  background: #fff;
  text-align: left;
}

.brief-card {
  border-left-color: var(--blue);
  background: #f7faff;
}

.advice-item.warning,
.status-row[data-status="pending"] {
  border-left-color: var(--yellow);
  background: #fffaf0;
}

.advice-item.critical,
.status-row[data-status="overdue"] {
  border-left-color: var(--red);
  background: #fff5f5;
}

.advice-item.info,
.status-row[data-status="done"] {
  border-left-color: var(--green);
}

.advice-item.unread strong::after {
  content: "  新";
  color: var(--red);
  font-size: 12px;
}

.advice-item span,
.brief-card span,
.status-row span,
.empty-state,
.brief-card small,
.advice-item small {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.status-row {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.status-row em {
  font-style: normal;
  color: var(--muted);
  font-size: 13px;
}

.bars {
  display: grid;
  gap: 12px;
}

.bar-row {
  display: grid;
  gap: 6px;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 14px;
}

.bar-track {
  height: 10px;
  background: #eef1eb;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--green);
}

.table-wrap {
  overflow-x: auto;
}

.account-groups {
  display: grid;
  gap: 14px;
}

.account-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcf8;
}

.account-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.account-head h3 {
  margin: 0;
  font-size: 17px;
}

.account-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.account-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 12px;
}

.row-actions {
  position: relative;
  display: inline-block;
}

.row-actions summary {
  min-width: 58px;
  min-height: 30px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
  list-style: none;
}

.row-actions summary::-webkit-details-marker {
  display: none;
}

.row-actions[open] summary {
  border-color: var(--blue);
}

.row-actions[open]::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 1;
}

.menu-button {
  width: 92px;
  min-height: 34px;
  display: block;
  border: 0;
  border-radius: 0;
  background: #fff;
  text-align: left;
}

.menu-button:hover {
  background: #f1f4ee;
}

.row-actions .menu-button {
  position: relative;
  z-index: 2;
}

.row-actions[open] .menu-button:first-of-type {
  margin-top: 6px;
  border-radius: 8px 8px 0 0;
}

.row-actions[open] .menu-button:last-of-type {
  border-radius: 0 0 8px 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  white-space: nowrap;
}

.account-cell {
  max-width: 260px;
  white-space: normal;
  line-height: 1.35;
}

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

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

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

.file-box {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 74px;
  border: 1px dashed #b8c0b2;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
}

.file-box input {
  display: none;
}

.trade-form,
.settings-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.settings-form {
  grid-template-columns: 1fr 1fr auto;
  align-items: end;
}

.password-form {
  margin-top: 12px;
}

.ai-auto-form {
  grid-template-columns: 1.4fr 1fr auto auto;
}

.ai-auto-status-box {
  margin-top: 12px;
}

.connector-box {
  display: grid;
  gap: 12px;
}

.connector-box p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.connector-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.copy-fallback {
  width: 100%;
  min-height: 128px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf8;
  color: var(--ink);
  font: inherit;
  line-height: 1.45;
  padding: 10px;
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
}

label span {
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  padding: 0 10px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}

.checkbox-label input {
  width: 18px;
  min-height: 18px;
}

@media (max-width: 820px) {
  .app {
    width: min(100vw - 14px, 1180px);
    padding: 10px 0 24px;
  }

  .topbar {
    display: block;
    margin-bottom: 8px;
  }

  h1 {
    font-size: 20px;
  }

  h2 {
    font-size: 15px;
  }

  .eyebrow {
    display: none;
  }

  .layout,
  .v3-grid,
  .advisor-sections {
    grid-template-columns: 1fr;
    display: grid;
  }

  .advisor-sections {
    gap: 10px;
  }

  .advisor-section {
    gap: 6px;
  }

  .section-head {
    min-height: 26px;
  }

  .section-head h3 {
    font-size: 13px;
  }

  .title-row {
    justify-content: space-between;
    gap: 10px;
  }

  .summary-grid {
    grid-template-columns: 1fr;
    gap: 7px;
    margin-bottom: 9px;
  }

  button {
    flex: 0 0 auto;
    min-height: 32px;
    font-size: 13px;
  }

  #refreshBtn {
    min-height: 30px;
    padding: 0 10px;
    font-size: 12px;
    border-radius: 7px;
  }

  .metric {
    min-height: 0;
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 1px 7px;
    padding: 7px 10px;
  }

  .metric strong,
  .metric.primary strong {
    display: inline;
    margin: 0;
    font-size: 20px;
    line-height: 1.18;
  }

  .metric.primary strong {
    font-size: 21px;
  }

  .metric span,
  .metric small {
    line-height: 1.2;
  }

  .metric span {
    flex: 0 0 100%;
  }

  .metric small,
  .panel-head span,
  .section-head span,
  th,
  label span,
  .advice-item span,
  .brief-card span,
  .status-row span,
  .empty-state,
  .brief-card small,
  .advice-item small {
    font-size: 10.5px;
  }

  .panel {
    padding: 10px;
  }

  .panel-head {
    margin-bottom: 9px;
  }

  th,
  td {
    padding: 8px 7px;
  }

  .trade-form,
  .settings-form {
    grid-template-columns: 1fr;
  }
}
