/* ============================================================
   账户跟踪 · 界面样式
   配色：冷静的灰蓝底 + 蓝色主色；涨红跌绿沿用国内习惯
   ============================================================ */

:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --line: #e6eaf1;
  --line-strong: #d3dae6;
  --text: #1c2434;
  --text-2: #46536b;
  --muted: #78849a;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #eef3ff;
  --accent-line: #cddcff;
  --up: #d92b2b;
  --down: #12a150;
  --warn: #b45309;
  --changed: #fff8e8;
  --changed-line: #f0d191;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(23, 33, 55, 0.05), 0 6px 18px -12px rgba(23, 33, 55, 0.18);
}

* { box-sizing: border-box; }

/* hidden 属性在按钮/表格等元素上也要生效（会被 display 规则覆盖） */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------- 顶栏 */

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  height: 60px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(1.4) blur(6px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.6px;
  white-space: nowrap;
}
.brand::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 18px;
  border-radius: 3px;
  background: linear-gradient(180deg, #4f86ff, var(--accent));
  vertical-align: -3px;
  margin-right: 9px;
}

.topbar-right { margin-left: auto; white-space: nowrap; }

.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: 0;
  background: transparent;
  padding: 0 15px;
  height: 34px;
  border-radius: 999px;
  font-size: 13.5px;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.tabs button:hover { background: #f1f4f9; color: var(--text); }
.tabs button.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px var(--accent-line);
}

/* ---------------------------------------------------------- 布局 */

main { padding: 18px 20px 48px; }
.view { display: none; }
.view.active { display: block; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.hint { color: var(--muted); margin: 10px 2px 0; line-height: 1.75; font-size: 12.5px; }
.hint b { color: var(--text-2); }

.toolbar {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 12px;
  flex-wrap: nowrap;
}
.toolbar.wrap { flex-wrap: wrap; }
.sep { width: 1px; height: 22px; background: var(--line-strong); margin: 0 3px; }

/* ---------------------------------------------------------- 控件 */

button, .btn, input, select, textarea {
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
}

button, .btn {
  border: 1px solid var(--line-strong);
  background: #fff;
  padding: 0 14px;
  height: 34px;
  line-height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
button:hover, .btn:hover { border-color: #bcc6d6; background: #f7f9fc; }
button:active, .btn:active { background: #eff2f7; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
button.primary:hover, .btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
button.ghost { background: #fff; }
button.danger { color: var(--up); }
button.danger:hover { background: #fff5f5; border-color: #f3c9c9; }
button.tiny { height: 24px; line-height: 22px; padding: 0 7px; font-size: 12px; border-radius: 6px; }

input[type=date], input[type=search], input[type=text], input[type=number],
input[type=password], select, textarea {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  height: 34px;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { height: auto; padding: 8px 10px; }
input::placeholder, textarea::placeholder { color: #a9b3c4; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
input[type=search] { min-width: 200px; }

.check { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); white-space: nowrap; font-size: 13px; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; }

/* ---------------------------------------------------------- 表格 */

.tablewrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: auto;
  max-height: 70vh;
  box-shadow: var(--shadow);
}
.tablewrap::-webkit-scrollbar { width: 11px; height: 11px; }
.tablewrap::-webkit-scrollbar-thumb { background: #c9d2e0; border-radius: 8px; border: 3px solid var(--panel); }
.tablewrap::-webkit-scrollbar-thumb:hover { background: #b2bccd; }
.tablewrap::-webkit-scrollbar-track { background: transparent; }

table.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-variant-numeric: tabular-nums; }
table.grid th, table.grid td {
  border-bottom: 1px solid var(--line);
  padding: 0 10px;
  text-align: center;
  white-space: nowrap;
  height: 38px;
  font-size: 13.5px;
}
table.grid thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #f7f9fc;
  color: var(--text-2);
  font-weight: 600;
  font-size: 12.5px;
  letter-spacing: 0.2px;
  box-shadow: inset 0 -1px 0 var(--line-strong);
}
table.grid tbody tr:nth-child(even) td { background: #fbfcfe; }
table.grid tbody tr:hover td { background: #f3f7ff; }
table.grid tbody tr:last-child td { border-bottom: 0; }
table.grid tfoot td {
  position: sticky;
  bottom: 0;
  z-index: 4;
  background: #f4f7fd;
  font-weight: 600;
  box-shadow: inset 0 1px 0 var(--line-strong);
}
table.grid td.c-num, table.grid th.c-num { text-align: center; }
table.grid td.calc { color: var(--text-2); font-weight: 600; }
/* 盈亏颜色要盖过 .calc 的默认色：盈利红、亏损绿 */
table.grid td.calc.pos, table.grid td.pos { color: var(--up); }
table.grid td.calc.neg, table.grid td.neg { color: var(--down); }

/* 表内可编辑格 */
table.grid .in { padding: 3px 5px; }
table.grid .in input, table.grid .in select {
  width: 100%;
  height: 30px;
  border: 1px solid transparent;
  background: transparent;
  padding: 0 8px;
  border-radius: 6px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  box-shadow: none;
}
table.grid .in select { padding: 0 4px; }
table.grid .in input:hover, table.grid .in select:hover { border-color: var(--line-strong); background: #fff; }
table.grid .in input:focus, table.grid .in select:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
table.grid .in input.changed, table.grid .in select.changed {
  background: var(--changed);
  border-color: var(--changed-line);
}
table.grid td.left, table.grid td.memo { text-align: left; }
table.grid td.left input, table.grid td.memo input { text-align: left; }
table.grid .in select { min-width: 84px; }   /* 状态这类下拉要放得下「未启用」 */
table.grid .in input[type="date"] { width: 138px; text-align: left; }

/* 列宽比例 */
.c-name { min-width: 168px; }
.c-sm { min-width: 72px; }
.c-broker { min-width: 122px; }
.c-memo { min-width: 340px; }
table.grid td.c-memo input { width: 100%; }

.pos { color: var(--up); }
.neg { color: var(--down); }
.row-idle td { color: #6f7b8f; }
.row-closed td { color: #9aa4b5; }
.row-idle td:first-child, .row-closed td:first-child { font-style: normal; }

/* 状态胶囊 */
.pill {
  display: inline-block;
  padding: 0 8px;
  height: 20px;
  line-height: 19px;
  border-radius: 999px;
  font-size: 11.5px;
  border: 1px solid transparent;
  vertical-align: middle;
}
.st-active { color: #0f7b45; background: #e9f8f0; border-color: #c6ecd7; }
.st-idle { color: #9a6200; background: #fff6e6; border-color: #ffe0ad; }
.st-closed { color: #6b7688; background: #f1f3f7; border-color: #e2e6ee; }
.tag .pill { margin-right: 4px; }

/* 可排序表头 */
table.grid th.sortable { cursor: pointer; user-select: none; }
table.grid th.sortable:hover { color: var(--accent); background: #f1f5fd; }
table.grid th .arrow { font-size: 9px; margin-left: 4px; color: var(--accent); }

/* 拖动排序 */
table.grid th.c-handle, table.grid td.c-handle { width: 50px; text-align: center; color: var(--muted); padding: 0 4px; }
table.grid td.c-handle { cursor: grab; user-select: none; }
table.grid td.c-handle:active { cursor: grabbing; }
table.grid tbody tr.dragging td { opacity: 0.45; background: #eef3ff; }
table.grid tbody tr.drop-before td { box-shadow: inset 0 2px 0 var(--accent); }
table.grid tbody tr.drop-after td { box-shadow: inset 0 -2px 0 var(--accent); }
table.grid td.c-handle .mv { display: flex; flex-direction: column; align-items: center; line-height: 9px; }
table.grid td.c-handle .mv button {
  border: 0;
  background: transparent;
  height: 13px;
  line-height: 11px;
  padding: 0 4px;
  font-size: 9px;
  color: #9aa4b5;
  border-radius: 3px;
}
table.grid td.c-handle .mv button:hover { color: var(--accent); background: #eef3ff; }

/* 列宽可拖动 */
table.grid th { position: relative; }
table.grid th .col-resizer {
  position: absolute;
  top: 0;
  right: -3px;
  width: 7px;
  height: 100%;
  cursor: col-resize;
  z-index: 6;
  user-select: none;
}
table.grid th .col-resizer::after {
  content: "";
  position: absolute;
  top: 22%;
  right: 3px;
  width: 1px;
  height: 56%;
  background: transparent;
}
table.grid th:hover .col-resizer::after { background: var(--line-strong); }
table.grid th .col-resizer:hover::after,
table.grid th .col-resizer.active::after { background: var(--accent); width: 2px; }
body.resizing { cursor: col-resize; user-select: none; }
body.resizing * { cursor: col-resize !important; }

/* 顶栏里的小按钮（退出账号等） */
.topbar-right { display: flex; align-items: center; gap: 10px; }
button.tiny { height: 26px; line-height: 24px; padding: 0 10px; font-size: 12.5px; border-radius: 6px; }

/* ---------------------------------------------------------- 卡片区 */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(178px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.kpi {
  background: linear-gradient(180deg, #ffffff, #fafcff);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.kpi .label { color: var(--muted); font-size: 12px; letter-spacing: 0.3px; }
.kpi .value { font-size: 21px; font-weight: 700; line-height: 1.4; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; }

table.grid td button, table.grid td .btn {
  height: 26px;
  line-height: 24px;
  padding: 0 10px;
  font-size: 12.5px;
  border-radius: 6px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.panel-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; min-height: 34px; }
.panel-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.panel-head h3::before {
  content: "";
  width: 3px;
  height: 15px;
  border-radius: 2px;
  background: var(--accent);
}
.panel-tools { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

canvas { width: 100%; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.legend span b { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }

/* 记事本是独立的一块，曲线图顶部居中显示账户名 */
.chart-title {
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.4px;
  color: var(--text);
  margin: 0 0 8px;
}
.panel > textarea {
  width: 100%;
  min-height: 76px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  line-height: 1.7;
  font-size: 13.5px;
  background: #fcfdff;
}
.panel > textarea:focus { outline: none; border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }

/* ---------------------------------------------------------- 账户页 */

.split { display: grid; grid-template-columns: 330px 1fr; gap: 14px; align-items: start; }
.split > * { min-width: 0; }   /* 表格再宽也只在自己容器里滚动，不会把页面撑宽 */
.list-panel { padding-bottom: 8px; }
.list-tip { font-size: 12px; color: var(--muted); margin: 8px 2px 0; }
.account-list { list-style: none; margin: 8px 0 0; padding: 0; max-height: 66vh; overflow: auto; }
.account-list::-webkit-scrollbar { width: 8px; }
.account-list::-webkit-scrollbar-thumb { background: #d7dee9; border-radius: 4px; }
.account-list li {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  gap: 8px;
  align-items: center;
  border: 1px solid transparent;
  transition: background 0.12s;
}
.account-list li:hover { background: #f4f7fc; }
.account-list li.active { background: var(--accent-soft); border-color: var(--accent-line); }
.account-list li .nm { font-weight: 600; font-size: 13.5px; }
.account-list li .rt { margin-left: auto; font-variant-numeric: tabular-nums; font-size: 13px; font-weight: 600; }
.account-list li .tag { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.account-list li .move { display: flex; flex-direction: column; gap: 1px; opacity: 0; }
.account-list li:hover .move { opacity: 1; }
.account-list li .move button { height: 14px; line-height: 12px; padding: 0 5px; font-size: 9px; border-radius: 4px; }

.empty { color: var(--muted); text-align: center; padding: 48px 0; font-size: 13px; }
.detail-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.detail-head h2 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: 0.3px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 12px 14px; margin: 6px 0 4px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 12.5px; }
.form-grid input, .form-grid select { width: 100%; }
.form-grid label.wide { grid-column: 1 / -1; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 4px 20px; color: var(--text-2); }
.stats div { border-bottom: 1px dashed var(--line); padding: 7px 0; display: flex; font-size: 13px; }
.stats b { margin-left: auto; font-variant-numeric: tabular-nums; }

/* 数据页的框不要拉太长 */
#view-data .panel { max-width: 880px; }
/* 安全页：一排窄卡片，字里行间留出呼吸空间，不要挤成一坨 */
#view-security .panel { max-width: 680px; padding: 18px 22px 20px; margin-bottom: 16px; }
#view-security #usersPanel { max-width: 720px; }
#view-security .panel-head { margin-bottom: 14px; }
#view-security .hint { font-size: 13px; line-height: 1.95; margin: 12px 0 0; }
#view-security .toolbar { margin-top: 14px; gap: 8px 10px; }
#view-security .toolbar .muted { line-height: 1.7; }
#view-security .stats { gap: 4px 24px; }
#view-security .stats div { padding: 9px 0; border-bottom-style: solid; }
#view-security table.grid th, #view-security table.grid td { padding-top: 12px; padding-bottom: 12px; }

/* 竖排小表单（安全页用） */
.v-form { display: flex; flex-direction: column; gap: 14px; max-width: 370px; margin: 16px 0 6px; }
.v-form label { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-2); }
.v-form label > span { flex: 0 0 96px; text-align: right; color: var(--muted); font-size: 13px; }
.v-form input { flex: 1; max-width: 224px; height: 34px; }
.v-form + .toolbar { padding-left: 106px; }

/* ---------------------------------------------------------- 浮层 */

.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%) translateY(12px);
  background: #1f2733;
  color: #fff;
  padding: 11px 22px;
  border-radius: 9px;
  font-size: 13.5px;
  box-shadow: 0 10px 30px rgba(15, 22, 36, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 60;
  max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.modal { position: fixed; inset: 0; background: rgba(20, 26, 36, 0.34); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal.hidden { display: none; }
.modal-box {
  background: #fff;
  border-radius: 14px;
  padding: 22px 24px;
  min-width: 480px;
  max-width: 92vw;
  max-height: 88vh;
  overflow: auto;
  box-shadow: 0 24px 60px -18px rgba(15, 22, 36, 0.4);
}
.modal-box h3 { margin: 0 0 16px; font-size: 16px; font-weight: 600; }
.modal-actions { display: flex; gap: 9px; justify-content: flex-end; margin-top: 18px; }

.lock { position: fixed; inset: 0; background: linear-gradient(150deg, #eef3fb, #e3ebf9 60%, #dfe8f8); display: flex; align-items: center; justify-content: center; z-index: 90; }
.lock.hidden { display: none; }
.lock-box {
  background: #fff;
  border-radius: 16px;
  padding: 32px 34px;
  width: 340px;
  text-align: center;
  box-shadow: 0 26px 60px -22px rgba(15, 22, 36, 0.45);
}
.lock-title { font-size: 19px; font-weight: 700; margin-bottom: 4px; }
.lock-box input { width: 100%; margin: 14px 0; height: 40px; text-align: center; font-size: 15px; letter-spacing: 2px; }
.lock-box select { text-align: center; }
.lock-tabs { display: flex; gap: 6px; margin: 14px 0 4px; }
.lock-tabs button {
  flex: 1;
  height: 34px;
  line-height: 32px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--muted);
  font-size: 13.5px;
}
.lock-tabs button.active {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent);
  font-weight: 600;
}
.lock-actions { display: flex; justify-content: center; }
.lock-actions button { width: 100%; height: 38px; line-height: 36px; font-size: 14px; }
.lock-msg { min-height: 18px; color: var(--up); font-size: 12.5px; margin: 10px 0 0; }
#errMsg { white-space: pre-line; text-align: left; color: var(--text-2); line-height: 1.8; }

.expired { color: var(--up); font-weight: 600; }
.soon { color: var(--warn); font-weight: 600; }
.pwd-cell { font-family: Consolas, Menlo, monospace; letter-spacing: 0.5px; }

/* ---------------------------------------------------------- 窄屏 */

@media (max-width: 1180px) {
  .split { grid-template-columns: 280px 1fr; }
}
@media (max-width: 960px) {
  .split { grid-template-columns: 1fr; }
  .topbar { height: auto; padding: 10px 14px; flex-wrap: wrap; gap: 10px; }
  main { padding: 14px; }
}
