:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --border: #e4e6eb;
  --text: #1d2129;
  --muted: #86909c;
  --accent: #1e6fff;
  --up: #d92e2e;
  --down: #1aaa5b;
  --flat: #86909c;
  --danger: #d92e2e;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 1px 8px rgba(0,0,0,.04);
  --shadow-lg: 0 4px 24px rgba(0,0,0,.12);
  --radius: 8px;
}
:root.dark {
  --bg: #0f1216;
  --surface: #1a1f26;
  --border: #2a313a;
  --text: #e6e8eb;
  --muted: #8a93a0;
  --accent: #5a8dff;
  --up: #ff5b5b;
  --down: #2bcf7a;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 1px 8px rgba(0,0,0,.2);
  --shadow-lg: 0 4px 24px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
/* class 选择器优先级高于 UA 的 [hidden]，必须显式声明 */
[hidden] { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.wrap { max-width: 1280px; margin: 0 auto; padding: 0 16px; }

/* =========================== Topbar =========================== */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
  box-shadow: var(--shadow);
}
.topbar .wrap {
  display: flex; align-items: center; gap: 16px;
  padding-top: 12px; padding-bottom: 12px;
  flex-wrap: wrap;
}
.logo { margin: 0; font-size: 18px; font-weight: 600; }

.search { display: flex; flex: 1; min-width: 220px; max-width: 420px; gap: 8px; }
.search input {
  flex: 1; padding: 8px 12px; font-size: 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--text); outline: none;
}
.search input:focus { border-color: var(--accent); }
.search button {
  padding: 8px 14px; cursor: pointer;
  border: 1px solid var(--accent); border-radius: var(--radius);
  background: var(--accent); color: #fff;
}
.search button:hover { opacity: .9; }

.auth-area { display: flex; align-items: center; gap: 8px; }
.auth-btn {
  padding: 8px 14px; font-size: 13px; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
}
.auth-btn.primary {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.auth-btn:hover { opacity: .9; }
.hello { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.hello b { color: var(--text); }

.meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.meta button {
  padding: 6px 10px; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
}
.meta button:hover { background: var(--bg); }

/* =========================== Tabs =========================== */
.tabs {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.tabs .wrap {
  display: flex; gap: 4px;
}
.tab {
  padding: 12px 18px;
  border: none; background: transparent; cursor: pointer;
  font-size: 14px; color: var(--muted);
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--accent); border-bottom-color: var(--accent); font-weight: 500;
}

.tab-content {
  padding-top: 16px;
}

/* =========================== Quick picks =========================== */
.quick-picks {
  margin: 0 0 12px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
}
.quick-picks .label { color: var(--muted); margin-right: 4px; }
.quick-picks button {
  padding: 4px 10px; font-size: 12px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text);
}
.quick-picks button:hover { border-color: var(--accent); color: var(--accent); }

/* =========================== Holdings toolbar =========================== */
.holdings-toolbar {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}
.holdings-toolbar button.primary {
  padding: 8px 16px; cursor: pointer;
  border: 1px solid var(--accent); border-radius: var(--radius);
  background: var(--accent); color: #fff; font-weight: 500;
}
.holdings-toolbar button.primary:hover { opacity: .9; }

.summary {
  display: flex; flex-wrap: wrap; gap: 16px;
  margin-left: auto;
  font-size: 13px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.summary b { color: var(--text); font-weight: 600; margin-left: 4px; }

/* =========================== Tables =========================== */
.watchlist {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.empty-state {
  padding: 48px 24px; text-align: center; color: var(--muted);
}
.empty-state .hint { font-size: 12px; opacity: .8; }

table {
  width: 100%; border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
table th, table td {
  padding: 10px 12px; text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table thead th {
  font-weight: 500; color: var(--muted); font-size: 12px;
  background: var(--bg);
  position: sticky; top: 0;
}
table tbody tr { cursor: pointer; transition: background .1s; }
table tbody tr:hover { background: var(--bg); }
table tbody tr:last-child td { border-bottom: none; }

.col-num, td.col-num { text-align: right; }
.col-sym { font-weight: 600; }
.col-name { color: var(--muted); max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.col-op { width: 40px; text-align: center; }

.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--flat); }

.del-btn {
  background: none; border: none; color: var(--muted);
  font-size: 16px; cursor: pointer; padding: 4px 8px;
  border-radius: 4px;
}
.del-btn:hover { background: var(--border); color: var(--up); }

/* =========================== Modal (auth & holding & detail) =========================== */
.modal, .detail {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 60px 16px; z-index: 100;
  overflow-y: auto;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 460px;
  padding: 24px;
  position: relative;
}
.modal-card.detail-card {
  max-width: 720px; padding: 0;
}
.modal-card h3 {
  margin: 0 0 18px;
  font-size: 18px; font-weight: 600;
}
.close {
  position: absolute; top: 12px; right: 12px;
  width: 28px; height: 28px; border-radius: 4px;
  border: none; background: transparent; color: var(--muted);
  font-size: 22px; cursor: pointer; line-height: 1;
}
.close:hover { background: var(--border); color: var(--text); }

/* =========================== Form =========================== */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 12px; color: var(--muted); }
.field input {
  padding: 8px 10px; font-size: 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--text); outline: none;
  font-family: inherit;
}
.field input:focus { border-color: var(--accent); }
.field-row {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
}
.field-row .field { margin-bottom: 12px; }

.form-err {
  margin: 4px 0 12px; font-size: 13px; color: var(--up);
  min-height: 18px;
}
.form-actions {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; align-items: center;
}
.form-actions button {
  padding: 8px 16px; font-size: 14px; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-family: inherit;
}
.form-actions button.primary {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.form-actions button.danger {
  background: transparent; color: var(--danger); border-color: var(--danger);
}
.form-actions button.danger:hover { background: var(--danger); color: #fff; }
.form-actions button.link {
  background: transparent; border-color: transparent; color: var(--accent);
  padding: 8px 4px;
}
.form-actions button.link:hover { text-decoration: underline; }

/* =========================== Detail panel =========================== */
.detail-head {
  padding: 20px 24px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
}
.detail-head h2 { margin: 0; font-size: 22px; }
.detail-head .muted { color: var(--muted); font-size: 13px; }
.price-block { margin-left: auto; text-align: right; }
.price-block .price { font-size: 28px; font-weight: 600; display: block; }
.price-block .change { font-size: 14px; }
.detail-grid {
  padding: 20px 24px;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
  font-variant-numeric: tabular-nums;
}
.detail-grid > div { display: flex; flex-direction: column; gap: 4px; }
.detail-grid .muted { font-size: 12px; color: var(--muted); }
.detail-grid b { font-size: 16px; font-weight: 500; }

/* =========================== Footer =========================== */
.foot {
  margin: 24px auto;
  color: var(--muted); font-size: 12px;
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
}

/* =========================== Loading / animations =========================== */
.loading td { opacity: .5; }
.spin { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }

/* =========================== Responsive =========================== */
@media (max-width: 860px) {
  .logo { font-size: 16px; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .auth-area { order: 4; }
  .summary { margin-left: 0; font-size: 12px; gap: 10px; }
  #watchTable th:nth-child(n+6):not(:last-child),
  #watchTable td:nth-child(n+6):not(:last-child) {
    display: none;
  }
  #holdingsTable th:nth-child(3), #holdingsTable td:nth-child(3),
  #holdingsTable th:nth-child(7), #holdingsTable td:nth-child(7),
  #holdingsTable th:nth-child(10), #holdingsTable td:nth-child(10) {
    display: none;
  }
  table th, table td { padding: 8px 6px; }
  .field-row { grid-template-columns: 1fr; }
}
