:root {
  --bg: #0e1014;
  --panel: #161a20;
  --panel-2: #1c2129;
  --line: #262c36;
  --text: #e6e8eb;
  --muted: #8a919c;
  --faint: #5c6370;
  --accent: #f0b90b;
  --up: #16c784;
  --down: #ea3943;
  --slow: #7c8cff;
  --mode: var(--accent);
  font-family: "Segoe UI", "Microsoft YaHei UI", sans-serif;
  font-size: 13px;
  color: var(--text);
}
body[data-mode="testnet"] { --mode: #3ba5ff; }
body[data-mode="live"] { --mode: var(--down); }

* { box-sizing: border-box; }
/* 下面很多元素设了 display:flex，会盖过浏览器对 hidden 的默认处理，这里统一强制隐藏 */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; background: var(--bg); }
body { display: flex; flex-direction: column; overflow: hidden; }
.num, .v, td, .log { font-variant-numeric: tabular-nums; }

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; border-bottom: 1px solid var(--line); background: var(--panel);
  border-top: 3px solid var(--mode);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 600; }
.logo { color: var(--accent); }
.mode-badge {
  font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 4px;
  color: var(--mode); border: 1px solid var(--mode);
}
.head-right { display: flex; align-items: center; gap: 18px; }
.run-state { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.run-state .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.run-state.on { color: var(--up); }
.run-state.on .dot { background: var(--up); box-shadow: 0 0 0 4px rgba(22, 199, 132, .15); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(22, 199, 132, 0); } }

main { flex: 1; display: grid; grid-template-columns: 300px 1fr; gap: 12px; padding: 12px; min-height: 0; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px 0; }
h2 { margin: 0 0 10px; font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .04em; }
.panel-head h2 { margin: 0; }

.settings { padding: 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.settings section { display: flex; flex-direction: column; }
label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
input, select {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 6px; padding: 7px 9px; outline: none; width: 100%;
}
input:focus, select:focus { border-color: var(--accent); }
input:disabled, select:disabled { opacity: .55; }
.hint { margin: 2px 0 0; color: var(--faint); font-size: 12px; line-height: 1.5; }
body[data-mode="live"] #modeHint { color: var(--down); }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 3px; gap: 3px; }
.segmented button { border: 0; background: transparent; padding: 6px 0; }
.segmented button.active { background: var(--panel-2); color: var(--mode); font-weight: 600; }

button {
  font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 6px; padding: 8px 10px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--faint); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #111; font-weight: 600; padding: 10px; }
button.danger { background: var(--down); border-color: var(--down); color: #fff; font-weight: 600; padding: 10px; }
button.link { background: none; border: 0; color: var(--muted); padding: 0; }
.actions { display: flex; flex-direction: column; gap: 8px; margin-top: auto; }
.actions .row, #notifyBox .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.content { display: grid; grid-template-rows: auto minmax(260px, 1fr) minmax(200px, .75fr); gap: 12px; min-height: 0; min-width: 0; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.middle { display: grid; grid-template-columns: minmax(380px, .9fr) 1.4fr; gap: 12px; min-height: 0; }
.watch-panel { display: flex; flex-direction: column; min-height: 0; }
table.watch tbody tr { cursor: pointer; }
table.watch tbody tr:hover { background: var(--panel-2); }
table.watch tbody tr.sel { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
td.sym-cell { font-weight: 600; }
td.muted-cell { color: var(--faint); }
.chart-info { margin: 6px 14px 0; color: var(--muted); font-size: 12px; min-height: 1.4em; }
.accent { color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 2px; cursor: pointer;
  padding: 4px 4px 4px 10px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--bg); font-size: 12px; font-weight: 600;
}
.chip.active { border-color: var(--accent); color: var(--accent); }
.chip .x { background: none; border: 0; padding: 0 5px; color: var(--faint); font-size: 14px; line-height: 1; }
.chip .x:hover:not(:disabled) { color: var(--down); }
.add-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 4px; }
#btnApplyAll { margin-top: 8px; }

.log-tools { display: flex; align-items: center; gap: 14px; }
label.check { flex-direction: row; align-items: center; gap: 5px; margin: 0; cursor: pointer; }
label.check input { width: auto; margin: 0; }
.log .sym { color: var(--accent); font-weight: 600; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.stat .k { color: var(--muted); font-size: 12px; }
.stat .v { font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .s { color: var(--faint); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.up { color: var(--up) !important; }
.down { color: var(--down) !important; }

.chart-panel { display: flex; flex-direction: column; min-height: 0; }
#chart { flex: 1; width: 100%; min-height: 0; display: block; }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 12px; }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend b { font-weight: 400; }
.sw { display: inline-block; width: 14px; height: 2px; }
.sw.price { background: var(--text); }
.sw.fast { background: var(--accent); }
.sw.slow { background: var(--slow); }
.tri { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; }
.tri.up { border-bottom: 8px solid var(--up); }
.tri.down { border-top: 8px solid var(--down); }

.bottom { display: grid; grid-template-columns: 1.4fr 1fr; gap: 12px; min-height: 0; }
.bottom .panel { display: flex; flex-direction: column; min-height: 0; }
.muted { color: var(--faint); font-size: 12px; }
.tabs { display: flex; gap: 18px; }
.tab {
  background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0;
  padding: 0 0 4px; color: var(--muted); font-size: 12px; font-weight: 600;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab span { margin-left: 4px; color: var(--accent); }
.table-wrap { overflow: auto; flex: 1; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: right; padding: 6px 14px; white-space: nowrap; }
th:first-child, td:first-child, th:last-child, td:last-child { text-align: left; }
th { position: sticky; top: 0; background: var(--panel); color: var(--faint); font-weight: 400; font-size: 12px; border-bottom: 1px solid var(--line); }
td { border-bottom: 1px solid #1d222a; }
tr.empty td { text-align: center; color: var(--faint); padding: 28px; border: 0; }

.log { list-style: none; margin: 8px 0 0; padding: 0 14px 10px; overflow-y: auto; flex: 1; font-family: Consolas, "Microsoft YaHei UI", monospace; font-size: 12px; line-height: 1.7; }
.log li { display: flex; gap: 8px; }
.log time { color: var(--faint); flex: none; }
.log .warn { color: var(--accent); }
.log .error { color: var(--down); }
.log .trade { color: var(--up); }

dialog {
  width: min(720px, 90vw); height: min(620px, 85vh); padding: 0;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
.dlg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 16px 18px 6px; }
.dlg-head h3 { margin: 0 0 4px; font-size: 15px; }
.dlg-tools { display: flex; gap: 8px; }
.dlg-tools input { width: 140px; }
dialog .table-wrap { margin: 0 4px; }
dialog th:not(:first-child), dialog td:not(:first-child) { text-align: right; }
dialog td:first-child { font-weight: 600; }
dialog .hint { padding: 8px 18px 14px; margin: 0; border-top: 1px solid var(--line); }

/* 手机和窄屏：整页上下滚动，各区块依次排列 */
@media (max-width: 900px) {
  body { overflow: auto; }
  header { padding: 10px 16px; }
  .brand { font-size: 14px; }
  main { display: flex; flex-direction: column; padding: 12px 16px; }
  .settings { overflow: visible; }
  .content { display: flex; flex-direction: column; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat .v { font-size: 16px; }
  .middle { display: flex; flex-direction: column; }
  .watch-panel { max-height: 420px; }
  .chart-panel { height: 320px; }
  .bottom { display: flex; flex-direction: column; }
  .bottom .panel { max-height: 360px; }
  .legend { gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
  .dlg-head { flex-direction: column; }
  .toast { max-width: calc(100% - 32px); }
}

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 16px; max-width: 70%; box-shadow: 0 8px 30px rgba(0, 0, 0, .4);
}
.toast.error { border-color: var(--down); color: #ffb4bb; }
.toast.ok { border-color: var(--up); }
