.brand-mark {
  width: 30px;
  height: 30px;
  object-fit: cover;
  border-radius: 50%;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.whop-sync { border: 0; border-radius: 7px; padding: 7px 10px; color: #fff; background: #435049; font: 600 11px "Noto Sans SC"; cursor: pointer; }
.whop-sync.connected { background: #287e61; }
.whop-status { max-width: 110px; color: var(--muted); font: 500 10px "Noto Sans SC"; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.whop-disconnect { border: 1px solid #cfd6cf; border-radius: 7px; padding: 6px 8px; color: #435049; background: rgb(251 251 249 / 78%); font: 600 10px "Noto Sans SC"; cursor: pointer; }
.whop-disconnect:hover { border-color: #aeb9af; color: var(--ink); }

.topbar {
  position: relative;
}

.topbar-actions .tabs {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.whitelist-menu {
  position: relative;
  z-index: 3;
}

.data-transfer { position: relative; z-index: 3; }
.data-transfer summary { list-style: none; border: 1px solid var(--line); border-radius: 7px; background: #fbfbf9; color: var(--muted); padding: 7px 9px; font: 500 11px "Noto Sans SC"; cursor: pointer; }
.data-transfer summary::-webkit-details-marker { display: none; }
.data-transfer-popover { position: absolute; right: 0; top: calc(100% + 8px); width: 220px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: rgb(251 251 249 / 96%); box-shadow: 0 12px 28px rgb(15 21 18 / 14%); backdrop-filter: blur(9px); }
.data-transfer-popover button, .import-records { display: block; width: 100%; box-sizing: border-box; border: 0; border-radius: 6px; padding: 8px 9px; color: #fff; background: #435049; font: 600 11px "Noto Sans SC"; text-align: center; cursor: pointer; }
.import-records { margin-top: 7px; background: #287e61; }
.import-records input { display: none; }
.data-transfer-popover textarea { display: block; box-sizing: border-box; width: 100%; margin-top: 8px; resize: vertical; border: 1px solid var(--line); border-radius: 6px; padding: 7px; color: var(--ink); background: #fff; font: 11px "DM Mono"; }
.data-transfer-popover .paste-import { margin-top: 6px; background: #66726b; }
.sign-out { border: 0; border-radius: 6px; padding: 7px 9px; color: #fff; background: #66726b; font: 600 12px "Noto Sans SC"; cursor: pointer; }
.brand-sign-out { margin-left: 2px; padding: 6px 9px; font-size: 11px; white-space: nowrap; }

/* Whop 待确认采用可编辑的居中表单，与本地账本的确认体验保持一致。 */
.whop-confirm-card { width: min(530px, calc(100vw - 36px)); }
.whop-confirm-head { padding: 15px 20px 9px; }
.whop-original { margin: 13px 20px 11px; padding: 11px 13px; }
.whop-confirm-result { margin: 0 20px; gap: 8px; }
.whop-confirm-result div { padding: 9px 11px; }
.whop-confirm-result input,
.whop-confirm-result select { margin-top: 5px; padding: 8px 10px; border-color: #d5ddd5; background: #fff; font-size: 13px; }
.whop-confirm-actions { margin: 14px 20px 17px; }
.whop-confirm-actions button { padding: 9px 11px; }
.whop-confirm-error { margin: 9px 20px 0; }
@media (max-width: 520px) {
  .whop-confirm-head { padding: 17px 18px 10px; }
  .whop-original, .whop-confirm-result { margin-left: 18px; margin-right: 18px; }
  .whop-confirm-actions, .whop-confirm-error { margin-left: 18px; margin-right: 18px; }
}
.viewer-mode #tradeCard, .viewer-mode #clearRecords, .viewer-mode #dataTransfer, .viewer-mode #whopSync, .viewer-mode #whopDisconnect, .viewer-mode #whopStatus, .viewer-mode .undo-trade { display: none !important; }
/* 公开页仍展示常用股票，但不提供任何新增入口。 */
.viewer-mode .whitelist-popover > label { display: none; }
body.public-view .appearance-actions,
body.admin-view .appearance-actions { display: none; }
.admin-login-link { border: 1px solid rgb(255 255 255 / 62%); border-radius: 7px; padding: 7px 10px; color: #435049; background: rgb(251 251 249 / 66%); backdrop-filter: blur(8px); font: 600 12px "Noto Sans SC"; text-decoration: none; }
.admin-login-link:hover { border-color: #b8c1ba; color: #17211c; }
body.public-view,
body.admin-view {
  background-color: #d9ddd7;
  background-image: linear-gradient(rgb(243 244 240 / 25%), rgb(243 244 240 / 25%)), url("./public-background.jpg");
  background-position: center;
  background-size: cover;
  background-attachment: fixed;
}
body.public-view .positions-panel,
body.public-view .trade-card,
body.public-view .history-card,
body.admin-view .positions-panel,
body.admin-view .trade-card,
body.admin-view .history-card {
  background: rgb(251 251 249 / 74%);
  border-color: transparent;
  backdrop-filter: blur(8px);
}
body.public-view .topbar,
body.admin-view .topbar { border-bottom-color: transparent; }
body.public-view .summary,
body.admin-view .summary { background: rgb(21 25 24 / 84%); }
body.public-view .tabs,
body.public-view .nav-tab.active,
body.admin-view .tabs,
body.admin-view .nav-tab.active { backdrop-filter: blur(8px); background-color: rgb(251 251 249 / 72%); }
body.auth-pending #appShell { display: none; }
.data-transfer-status { min-height: 16px; margin: 7px 0 0; color: #287e61; font: 500 10px "Noto Sans SC"; }
.data-transfer-popover small { display: block; margin-top: 9px; color: var(--muted); font: 500 10px "Noto Sans SC"; line-height: 1.55; }

.whitelist-menu summary {
  list-style: none;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfbf9;
  color: var(--muted);
  padding: 7px 9px;
  font: 500 11px "Noto Sans SC";
  cursor: pointer;
}

.whitelist-menu summary::-webkit-details-marker { display: none; }
.whitelist-menu summary span { margin-left: 3px; color: var(--accent, #287e61); }

.whitelist-popover {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 250px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgb(251 251 249 / 96%);
  box-shadow: 0 12px 28px rgb(15 21 18 / 14%);
  backdrop-filter: blur(9px);
}

.whitelist-popover label,
.whitelist-popover small { display: block; font: 500 11px "Noto Sans SC"; color: var(--muted); }
.whitelist-add { display: grid; grid-template-columns: 1fr auto; gap: 6px; margin-top: 6px; }
.whitelist-add input { min-width: 0; height: 32px; padding: 0 8px; border: 1px solid var(--line); border-radius: 6px; font: 500 13px "DM Mono"; }
.whitelist-add button { border: 0; border-radius: 6px; padding: 0 10px; color: #fff; background: #435049; cursor: pointer; }
.whitelist-list { display: flex; flex-wrap: wrap; gap: 6px; max-height: 150px; margin: 10px 0; overflow: auto; }
.whitelist-sector { width: 100%; }
.whitelist-sector-name { display: block; margin-bottom: 5px; font: 500 10px "Noto Sans SC"; color: var(--muted); }
.whitelist-sector-symbols { display: flex; flex-wrap: wrap; gap: 6px; }
.whitelist-chip { border: 0; border-radius: 5px; padding: 5px 7px; color: var(--ink); background: #edf0eb; font: 500 11px "DM Mono"; cursor: pointer; }
.whitelist-chip:hover { background: #dce7df; }
.whitelist-empty { color: var(--muted); font-size: 11px; }
.whitelist-chip.sector-large-cap,
.position-group.sector-large-cap .position-symbol { background: rgb(225 236 247 / 92%); }
.whitelist-chip.sector-star,
.position-group.sector-star .position-symbol { background: rgb(252 235 207 / 92%); }
.whitelist-chip.sector-crypto,
.position-group.sector-crypto .position-symbol { background: rgb(236 225 249 / 92%); }
.whitelist-chip.sector-index,
.position-group.sector-index .position-symbol { background: rgb(220 240 225 / 92%); }
.whitelist-chip.sector-unclassified,
.position-group.sector-unclassified .position-symbol { background: rgb(235 239 234 / 92%); }

/* 占用仓位页使用整行板块色，操作详情维持中性底色以便阅读。 */
.position-group.sector-large-cap > .position-row { background: rgb(225 236 247 / 78%); }
.position-group.sector-star > .position-row { background: rgb(252 235 207 / 78%); }
.position-group.sector-crypto > .position-row { background: rgb(236 225 249 / 78%); }
.position-group.sector-index > .position-row { background: rgb(220 240 225 / 78%); }
.position-group.sector-unclassified > .position-row { background: rgb(235 239 234 / 78%); }
.position-group.sector-large-cap > .position-row:hover { background: rgb(213 229 244 / 92%); }
.position-group.sector-star > .position-row:hover { background: rgb(249 224 188 / 92%); }
.position-group.sector-crypto > .position-row:hover { background: rgb(228 211 244 / 92%); }
.position-group.sector-index > .position-row:hover { background: rgb(205 233 213 / 92%); }
.position-group.sector-unclassified > .position-row:hover { background: rgb(225 232 224 / 92%); }

.position-group.sector-large-cap.priority-stock > .position-row { background: rgb(174 207 234 / 92%); }
.position-group.sector-large-cap.priority-stock > .position-row:hover { background: rgb(156 195 228 / 96%); }

.position-symbol-wrap { display: flex; align-items: center; justify-content: center; gap: 7px; }
.position-tag { padding: 3px 6px; border-radius: 999px; color: #57615b; background: rgb(255 255 255 / 56%); font: 500 10px "Noto Sans SC"; white-space: nowrap; }
.position-tag.has-tooltip { position: relative; cursor: default; }
.position-tag.has-tooltip::after { content: attr(data-tooltip); position: absolute; z-index: 8; left: 50%; bottom: calc(100% + 8px); width: max-content; max-width: 210px; padding: 7px 9px; border-radius: 6px; color: #fff; background: rgb(24 31 27 / 92%); font: 400 11px/1.5 "Noto Sans SC"; white-space: normal; text-align: left; opacity: 0; pointer-events: none; transform: translate(-50%, 4px); transition: opacity .15s, transform .15s; }
.position-tag.has-tooltip:hover::after,
.position-tag.has-tooltip:focus-visible::after { opacity: 1; transform: translate(-50%, 0); }

.background-picker,
.clear-background {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfbf9;
  color: var(--muted);
  padding: 7px 9px;
  font: 500 11px "Noto Sans SC";
  cursor: pointer;
}

.background-picker input {
  display: none;
}

.clear-background:hover,
.background-picker:hover {
  color: var(--ink);
  border-color: #cbd1cb;
}

body.has-custom-background {
  background-color: #d9ddd7;
  background-image: linear-gradient(rgb(243 244 240 / 16%), rgb(243 244 240 / 16%)), var(--custom-background-image);
  background-position: center;
  background-size: cover;
  background-attachment: fixed;
}

body.has-custom-background .positions-panel,
body.has-custom-background .trade-card,
body.has-custom-background .history-card {
  background: rgb(251 251 249 / 68%);
  border-color: transparent;
  backdrop-filter: blur(7px);
}

body.has-custom-background .topbar {
  border-bottom-color: transparent;
}

body.has-custom-background .positions-head,
body.has-custom-background .position-total,
body.has-custom-background .position-operations {
  background: rgb(240 241 238 / 62%);
}

body.has-custom-background .summary {
  background: rgb(21 25 24 / 84%);
}

body.has-custom-background .tabs,
body.has-custom-background .nav-tab.active,
body.has-custom-background .background-picker,
body.has-custom-background .clear-background {
  backdrop-filter: blur(7px);
  background-color: rgb(251 251 249 / 66%);
}

.trade-card .card-heading {
  display: none;
}

.quick-entry {
  margin-bottom: 18px;
}

.quick-entry-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
}

.quick-entry-row input {
  min-width: 0;
}

#parseQuickEntry {
  border: 0;
  border-radius: 8px;
  padding: 0 13px;
  color: #fff;
  background: #435049;
  font: 500 12px "Noto Sans SC";
  cursor: pointer;
}

#parseQuickEntry:hover {
  background: #151918;
}

.quick-submit {
  display: flex;
  align-items: center;
  gap: 7px;
  border: 0;
  border-radius: 8px;
  padding: 0 11px;
  color: #fff;
  background: var(--accent, #db4b47);
  font: 600 12px "Noto Sans SC";
  white-space: nowrap;
  cursor: pointer;
}

.quick-submit:hover { filter: brightness(.94); }

.source-lot-field[hidden] {
  display: none;
}

.overview-combined .summary {
  border-radius: 15px 15px 0 0;
  box-shadow: none;
}

.overview-combined .history-card {
  min-height: 0;
  border-top: 0;
  border-radius: 0 0 15px 15px;
}

.content-grid {
  grid-column: 2;
  display: block;
  margin-top: 0;
}

#ledger.page.active {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(330px, 0.9fr);
  gap: 20px;
  align-items: start;
}

#ledger.page.active,
#positions.page.active {
  width: 100%;
}

@media (max-width: 680px) {
  .topbar-actions {
    gap: 4px;
  }

  .topbar-actions .tabs {
    position: static;
    transform: none;
  }

  .background-picker,
  .clear-background {
    padding: 6px;
    font-size: 10px;
  }

  #ledger.page.active {
    display: block;
  }

  .content-grid {
    margin-top: 20px;
  }
}

.lot-group {
  border-bottom: 1px solid var(--line);
  margin-left: calc(-1 * var(--operation-left-inset, 52px));
  margin-right: calc(-1 * var(--operation-right-inset, 26px));
  padding: 12px var(--operation-right-inset, 26px) 12px var(--operation-left-inset, 52px);
  cursor: pointer;
}

.position-operations {
  --operation-left-inset: 52px;
  --operation-right-inset: 26px;
}

.lot-group:last-child {
  border-bottom: 0;
}

.completed-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 11px;
  padding: 12px 0 4px;
}

.completed-divider::before,
.completed-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.completed-lot {
  opacity: .72;
}

.completed-lot .lot-buy {
  position: relative;
}

.completed-lot .lot-buy::after {
  content: "";
  position: absolute;
  left: 62px;
  right: 112px;
  top: 50%;
  height: 1px;
  background: currentColor;
  opacity: .55;
}

.position-total {
  background: #f0f1ee;
}

.position-total .position-symbol,
.position-total .position-value,
.position-total .position-lots {
  color: #257b58;
}

.position-group .position-symbol {
  display: inline-block;
  padding: 5px 9px;
  border-radius: 6px;
  background: #edf0eb;
}

.buy-price {
  color: #b93f3b;
  background: #fff0ee;
  border-radius: 5px;
  padding: 3px 6px;
  text-align: center;
  font-weight: 700;
}

.position-cost.average-cost,
.sell-price {
  color: #257b58;
  background: #e9f5ed;
  border-radius: 5px;
  padding: 3px 6px;
  text-align: center;
  font-weight: 700;
}

.position-cost.average-cost {
  justify-self: center;
  width: fit-content;
}

.position-lots {
  text-align: right;
  font: 500 14px "DM Mono";
}

.summary {
  display: block;
  padding: 22px 28px 25px;
}

.summary-head {
  margin-bottom: 20px;
}

.summary-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
}

.summary-metric {
  display: grid;
  gap: 7px;
}

.summary-metric span {
  color: #aeb5af;
  font-size: 11px;
}

.summary-metric strong {
  color: #fff;
  font: 500 24px "DM Mono";
  letter-spacing: -.05em;
}

.summary-metric strong.positive {
  color: #79d4aa;
}

.summary-metric strong.negative {
  color: #ff8c88;
}

.positions-head,
.position-row {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.positions-head > span,
.position-row > span,
.position-row > div:first-child {
  text-align: center !important;
}

.position-group > .position-row {
  cursor: pointer;
}

.position-group > .position-row:hover {
  background: #f7f8f5;
}

@media (max-width: 680px) {
  .position-operations {
    --operation-left-inset: 40px;
    --operation-right-inset: 15px;
  }
}

@media (max-width: 680px) {
  .positions-head,
  .position-row {
    min-width: 650px;
  }

  .summary-metrics {
    grid-template-columns: 1fr 1fr;
    row-gap: 16px;
  }
}

.history-filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
}

.history-filters label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
}

.history-filters input {
  min-width: 0;
  padding: 8px 9px;
  font-size: 12px;
}

.allocation-note {
  color: var(--muted);
  font-size: 10px;
  font-weight: 400;
}

.symbol-input-wrap {
  position: relative;
  display: block;
  width: 100%;
  border: 1px solid #dfe3de;
  border-radius: 8px;
  background: #fff;
}

.symbol-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
}

.symbol-input-wrap #symbol {
  position: relative;
  z-index: 1;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.symbol-input-wrap #symbol:focus {
  box-shadow: none;
}

.common-symbol-hint {
  position: absolute;
  z-index: 0;
  top: 50%;
  left: 12px;
  transform: translateY(-50%);
  color: #aeb5af;
  font: 400 14px "DM Mono";
  pointer-events: none;
}

.filter-empty {
  padding: 36px 0;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
}

.trade-row {
  grid-template-columns: 68px minmax(0, 1fr) auto auto;
}

.undo-trade {
  border: 0;
  border-radius: 5px;
  padding: 5px 7px;
  color: #a15b57;
  background: rgb(255 240 238 / 78%);
  font: 500 11px "Noto Sans SC";
  cursor: pointer;
}

.undo-trade:hover {
  color: #fff;
  background: #db4b47;
}

.lot-buy,
.lot-sale {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr) 220px;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 11px;
}

.lot-buy strong,
.lot-sale strong {
  color: var(--ink);
  font: 500 13px "DM Mono";
}

.lot-sale {
  grid-template-columns: 70px minmax(0, 1fr) 220px;
}

.lot-rebuys {
  display: grid;
  gap: 7px;
  margin: 7px 0 0;
  padding: 7px 0 0;
}

.lot-rebuy {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr) 220px;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 11px;
}

.lot-rebuy strong {
  color: var(--ink);
  font: 500 13px "DM Mono";
}

.lot-rebuy-sales {
  display: grid;
  gap: 7px;
  margin-top: 7px;
}

.lot-rebuy-sale {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr) 220px;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 11px;
}

.lot-rebuy-sale strong {
  color: var(--ink);
  font: 500 13px "DM Mono";
}

.lot-meta {
  display: grid;
  grid-template-columns: 138px 132px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.lot-time,
.buy-price,
.sell-price,
.average-price {
  white-space: nowrap;
}

.lot-time {
  color: #151918;
  font-weight: 600;
}

.average-price {
  color: #257b58;
  background: #e9f5ed;
  border-radius: 5px;
  padding: 3px 6px;
  width: fit-content;
  text-align: center;
  font-weight: 700;
}

.lot-buy {
  grid-template-columns: 108px minmax(0, 1fr) 220px;
  cursor: pointer;
}

.lot-buy:hover {
  background: #f3f5f1;
}

.lot-status {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 22px;
  align-items: center;
  white-space: nowrap;
}

.sale-lots {
  padding-left: 0;
  white-space: nowrap;
}

.initial-lot,
.remaining-lot,
.sale-lots span {
  display: inline-block;
  border-radius: 5px;
  padding: 4px 7px;
  text-align: center;
}

.initial-lot {
  color: #b93f3b;
  background: #fff0ee;
}

.remaining-lot {
  color: #2665a8;
  background: #eaf3ff;
}

.sale-lots span {
  color: #257b58;
  background: #e9f5ed;
}

.replenish-lots span {
  color: #b93f3b;
  background: #fff0ee;
}

.toggle-lot-sales {
  justify-self: end;
  border: 0;
  background: #edf0eb;
  color: #435049;
  border-radius: 6px;
  padding: 6px 8px;
  font: 500 11px "Noto Sans SC";
  cursor: pointer;
}

.toggle-lot-sales span {
  display: inline-block;
  transition: transform .2s;
}

.toggle-lot-sales[aria-expanded="true"] span {
  transform: rotate(180deg);
}

@media (min-width: 681px) {
  body.ledger-mode {
    overflow: hidden;
  }

  #ledger.page.active {
    height: calc(100vh - 142px);
  }

  #positions.page.active {
    height: calc(100vh - 142px);
  }

  #positions.page.active .positions-panel {
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .overview-combined {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
  }

  .overview-combined .history-card {
    display: flex;
    flex: 1;
    min-height: 0;
    flex-direction: column;
  }

  .overview-combined .trade-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding-right: 8px;
  }
}

.lot-sales {
  display: grid;
  gap: 8px;
  margin: 9px 0 0 25px;
  padding: 9px 0 0 13px;
  border-left: 2px solid #dce9e0;
}

.lot-empty {
  margin: 8px 0 0 63px;
  color: var(--muted);
  font-size: 11px;
}

/* 顶部工具分区：外观在左、常用股票居中、同步控制在右。 */
.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 16px;
  justify-content: normal;
}

.topbar-left,
.topbar-right,
.appearance-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-left {
  justify-self: start;
  min-width: 0;
}

.topbar-right {
  justify-self: end;
  min-width: 0;
}

.topbar-center .tabs {
  position: static;
  transform: none;
}

.topbar-center {
  display: flex;
  align-items: center;
  justify-self: center;
  gap: 8px;
}

.topbar-whitelist {
  position: relative;
}

.whop-status {
  color: #151918;
  font-weight: 800;
}

@media (max-width: 900px) {
  .topbar {
    height: auto;
    min-height: 82px;
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 10px 0;
    row-gap: 8px;
  }

  .topbar-center {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .topbar-right {
    gap: 6px;
  }
}

@media (max-width: 680px) {
  .topbar-left .brand span {
    display: none;
  }

  .topbar-left,
  .topbar-right,
  .appearance-actions {
    gap: 4px;
  }

  .whop-status {
    max-width: 64px;
  }
}
