/* ==========================================================================
   Firstrade Relay · web UI
   Dark theme, Chinese market convention for this deployment:
   跌 = 红 (#f0384c)   涨 = 绿 (#16c784)
   ========================================================================== */

:root {
  --bg:            #0a0d14;
  --bg-elevated:   #111621;
  --surface:       #151b28;
  --surface-2:     #1c2333;
  --surface-3:     #232b3d;
  --border:        #242c3d;
  --border-strong: #313b52;

  --text:          #e8ecf4;
  --text-dim:      #9aa3b8;
  --text-faint:    #6b7488;

  --up:            #16c784;   /* 涨 */
  --down:          #f0384c;   /* 跌 */
  --flat:          #8b93a7;
  --accent:        #4d8dff;
  --accent-soft:   rgba(77, 141, 255, .14);
  --warn:          #f5a524;

  --radius:        14px;
  --radius-sm:     9px;
  --shadow:        0 10px 34px rgba(0, 0, 0, .45);
  --shadow-soft:   0 2px 10px rgba(0, 0, 0, .3);

  --topbar-h:      58px;
  --sidebar-w:     236px;
  --tabbar-h:      58px;

  --mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body { overscroll-behavior-y: none; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ------------------------------------------------------------------ login */

.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1100px 620px at 12% -12%, rgba(77, 141, 255, .16), transparent 62%),
    radial-gradient(900px 520px at 105% 8%, rgba(22, 199, 132, .10), transparent 60%),
    var(--bg);
}

.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 32px 28px 26px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 6px;
}

.login-logo {
  width: 38px; height: 38px;
  border-radius: 11px;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--accent), #7c5cff);
  font-weight: 800; font-size: 17px; color: #fff;
  box-shadow: 0 6px 18px rgba(77, 141, 255, .32);
}

.login-title { font-size: 19px; font-weight: 650; letter-spacing: .2px; }
.login-sub { color: var(--text-dim); font-size: 13px; margin-bottom: 22px; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12.5px;
  color: var(--text-dim);
  margin-bottom: 6px;
  letter-spacing: .3px;
}

.input {
  width: 100%;
  padding: 11px 13px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input::placeholder { color: var(--text-faint); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .08s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); border-color: #3d4760; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(140deg, var(--accent), #6f5cff);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
  padding: 11px 16px;
  box-shadow: 0 6px 18px rgba(77, 141, 255, .26);
}
.btn-primary:hover { filter: brightness(1.08); background: linear-gradient(140deg, var(--accent), #6f5cff); }

/* Only the login form's submit button spans the full width. */
.login-card .btn-primary { width: 100%; }

.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-danger { color: var(--down); border-color: rgba(240, 56, 76, .35); background: rgba(240, 56, 76, .08); }
.btn-danger:hover { background: rgba(240, 56, 76, .16); border-color: rgba(240, 56, 76, .5); }

.alert {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 14px;
  border: 1px solid transparent;
}
.alert-error { background: rgba(240, 56, 76, .1); border-color: rgba(240, 56, 76, .32); color: #ff9aa6; }
.alert-ok    { background: rgba(22, 199, 132, .1); border-color: rgba(22, 199, 132, .3); color: #6ee7b7; }
.alert-info  { background: var(--accent-soft); border-color: rgba(77, 141, 255, .3); color: #9dc1ff; }

.totp-secret {
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 1px;
  word-break: break-all;
  background: var(--bg-elevated);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 10px 0;
}
.qr-box { display: grid; place-items: center; margin: 14px 0; }
.qr-box svg, .qr-box img { width: 190px; height: 190px; background: #fff; padding: 8px; border-radius: 10px; }

.code-input {
  letter-spacing: 10px;
  text-align: center;
  font-family: var(--mono);
  font-size: 21px;
  padding: 12px 13px;
}

/* ------------------------------------------------------------------ shell */

.app { display: none; min-height: 100dvh; }
.app.ready { display: block; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: rgba(10, 13, 20, .86);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  color: var(--text-dim);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; letter-spacing: .2px; }
.brand-logo {
  width: 28px; height: 28px; border-radius: 8px;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--accent), #7c5cff);
  font-size: 13px; font-weight: 800; color: #fff;
}
.brand-sub { color: var(--text-faint); font-size: 11.5px; font-weight: 400; letter-spacing: .4px; }

.spacer { flex: 1; }

/* 桌面端不显示汉堡按钮：侧边栏本来就常驻，按钮点了没反应会像坏了。 */
@media (min-width: 901px) {
  #menu-btn { display: none; }
}

.btn-refresh {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  font-size: 13px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
}
.btn-refresh:hover { color: var(--text); background: var(--surface-3); }
.btn-refresh .ico { font-size: 14px; line-height: 1; }
@media (max-width: 480px) {
  .btn-refresh .lbl { display: none; }
  .btn-refresh { padding: 8px 11px; }
}

.user-chip { cursor: pointer; }
.user-chip:hover { border-color: var(--border-strong); }
.user-caret { color: var(--text-faint); font-size: 10px; }

.modal-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* 设置页 */
.settings-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(36, 44, 61, .6);
}
.settings-row:last-child { border-bottom: none; }
.settings-main { flex: 1; min-width: 0; }
.settings-name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.settings-detail { color: var(--text-dim); font-size: 12.5px; margin-top: 3px; }
.settings-caps { color: var(--text-faint); font-size: 11.5px; margin-top: 3px; }
.settings-actions { flex: 0 0 auto; }

/* 持仓表里的名称列 */
td.pos-name {
  display: inline-block;
  margin-left: 8px;
  color: var(--text-faint);
  font-size: 12px;
  font-family: var(--sans);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

/* 表格对齐：数字列右对齐，操作列右对齐，单元格垂直居中 */
table.data th.num, table.data td.num { text-align: right; }
table.data th:last-child, table.data td:last-child { text-align: right; }
table.data td, table.data th { vertical-align: middle; }
table.data td.name { white-space: nowrap; }

/* 关注列表：标签栏与下方内容之间留出间距 */
#list-chips { margin-bottom: 14px; }
#list-card .card-head { gap: 8px; }
#list-card .card-head .btn { margin-left: auto; }
#list-card td .btn { min-width: 56px; }

/* ------------------------------------------------------- market status */

.market-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--text-dim);
  cursor: default;
  white-space: nowrap;
}
.market-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  flex: 0 0 auto;
}
.market-chip.open   { color: #6ee7b7; border-color: rgba(22, 199, 132, .32); }
.market-chip.open   .market-dot { background: var(--up); box-shadow: 0 0 0 3px rgba(22, 199, 132, .16); }
.market-chip.pre    { color: #f7c26b; border-color: rgba(245, 165, 36, .3); }
.market-chip.pre    .market-dot { background: var(--warn); }
.market-chip.after  { color: #9dc1ff; border-color: rgba(77, 141, 255, .3); }
.market-chip.after  .market-dot { background: var(--accent); }
.market-chip.closed .market-dot { background: var(--text-faint); }

.market-banner {
  display: flex;
  align-items: center;
  gap: 8px 16px;
  flex-wrap: wrap;
  padding: 10px 14px;
  margin-bottom: 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  color: var(--text-dim);
}
.market-state {
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-3);
  color: var(--text-dim);
}
.market-state.open   { background: rgba(22, 199, 132, .16); color: #6ee7b7; }
.market-state.pre    { background: rgba(245, 165, 36, .16); color: #f7c26b; }
.market-state.after  { background: var(--accent-soft); color: #9dc1ff; }
.market-state.closed { background: var(--surface-3); color: var(--text-dim); }
.mb-item { font-family: var(--mono); font-size: 12px; white-space: nowrap; }

.source-select {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  padding: 7px 10px;
  cursor: pointer;
  outline: none;
}
.source-select:focus { border-color: var(--accent); }

.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 10px 5px 5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(140deg, #3d4a66, #263049);
  font-size: 12px; font-weight: 700; color: #cdd6e8;
}

.layout { display: flex; align-items: flex-start; }

.sidebar {
  position: sticky;
  top: var(--topbar-h);
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  height: calc(100dvh - var(--topbar-h));
  padding: 14px 10px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  background: var(--bg);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14.5px;
  margin-bottom: 2px;
  border: 1px solid transparent;
  transition: background .14s, color .14s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.active {
  background: var(--accent-soft);
  color: #b9d0ff;
  border-color: rgba(77, 141, 255, .22);
  font-weight: 600;
}
.nav-item .nav-ico { width: 18px; text-align: center; opacity: .9; }
.nav-badge {
  margin-left: auto;
  background: var(--surface-3);
  color: var(--text-dim);
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
}

.nav-sep { height: 1px; background: var(--border); margin: 12px 8px; }
.nav-label { font-size: 11px; color: var(--text-faint); padding: 0 12px 6px; letter-spacing: .6px; }

.main {
  flex: 1;
  min-width: 0;
  padding: 18px 20px 40px;
  max-width: 1400px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.page-title { font-size: 20px; font-weight: 650; margin: 0; letter-spacing: .2px; }
.page-desc { color: var(--text-dim); font-size: 13px; margin: 3px 0 0; }
.page-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ------------------------------------------------------------------ cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 14.5px; font-weight: 620; }
.card-body { padding: 16px; }
.card-note { color: var(--text-dim); font-size: 12.5px; margin-top: 10px; }

.grid { display: grid; gap: 14px; }
.grid-index { grid-template-columns: repeat(auto-fit, minmax(178px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }

.index-card {
  background: linear-gradient(168deg, var(--surface) 0%, var(--bg-elevated) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 15px;
  position: relative;
  overflow: hidden;
}
.index-card::after {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 3px;
  background: var(--flat); opacity: .85;
}
.index-card.up::after   { background: var(--up); }
.index-card.down::after { background: var(--down); }

.index-name { color: var(--text-dim); font-size: 12.5px; margin-bottom: 6px; }
.index-level { font-size: 25px; font-weight: 660; font-family: var(--mono); letter-spacing: -.4px; }
.index-meta { margin-top: 5px; display: flex; gap: 10px; font-size: 12.5px; font-family: var(--mono); }
.index-sym { color: var(--text-faint); font-size: 11px; margin-top: 7px; }

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

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 12px; }
.stat {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
}
.stat-label { color: var(--text-dim); font-size: 12px; }
.stat-value { font-size: 17px; font-weight: 620; font-family: var(--mono); margin-top: 3px; }

/* ----------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  min-width: 520px;
}
table.data th {
  text-align: left;
  padding: 9px 12px;
  color: var(--text-faint);
  font-weight: 500;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--surface);
}
table.data td {
  padding: 9px 12px;
  border-bottom: 1px solid rgba(36, 44, 61, .55);
  white-space: nowrap;
  font-family: var(--mono);
}
table.data td.name { font-family: var(--sans); font-weight: 600; }
table.data tbody tr:hover { background: rgba(28, 35, 51, .55); }
table.data tbody tr:last-child td { border-bottom: none; }
.num { text-align: right; }
.cell-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* --------------------------------------------------------------- 可排序表头 */
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--text); background: rgba(28, 35, 51, .6); }
table.data th.sorted { color: var(--text); }
table.data th .sort-arrow { color: var(--accent); font-size: 10px; margin-left: 2px; }

.sym-link { cursor: pointer; color: var(--text); font-weight: 650; }
.sym-link:hover { color: var(--accent); text-decoration: underline; }

.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  background: var(--surface-3);
  color: var(--text-dim);
  font-family: var(--sans);
}
.tag-up   { background: rgba(22, 199, 132, .14); color: #4fdcac; }
.tag-down { background: rgba(240, 56, 76, .14);  color: #ff8d9b; }
.tag-accent { background: var(--accent-soft); color: #9dc1ff; }
.tag-warn { background: rgba(245, 165, 36, .14); color: #f7c26b; }

.empty {
  padding: 44px 20px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13.5px;
}
.empty .big { font-size: 30px; margin-bottom: 10px; opacity: .5; }

/* ------------------------------------------------------------------ forms */

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.toolbar .input { width: auto; min-width: 150px; }

.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  padding: 6px 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-dim);
  transition: all .14s;
}
.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip.active {
  background: var(--accent-soft);
  border-color: rgba(77, 141, 255, .35);
  color: #b9d0ff;
  font-weight: 600;
}

/* ----------------------------------------------------------------- charts */

.chart-wrap { position: relative; width: 100%; }

/* KLineCharts 容器：高度决定主图与副图各占多少 */
.kline-wrap {
  position: relative;
  width: 100%;
  height: 520px;
}
.kline-hint {
  color: var(--text-faint);
  font-size: 11.5px;
  padding: 8px 4px 0;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}
@media (max-width: 900px) {
  .kline-wrap { height: 420px; }
}
@media (max-width: 480px) {
  .kline-wrap { height: 360px; }
}
.chart-wrap canvas { display: block; width: 100%; touch-action: pan-y; }
.chart-legend {
  display: flex; gap: 14px; flex-wrap: wrap;
  font-size: 11.5px; font-family: var(--mono);
  color: var(--text-dim);
  padding: 0 4px 8px;
}
.chart-legend i { display: inline-block; width: 9px; height: 2.5px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

.chart-tip {
  position: absolute;
  pointer-events: none;
  background: rgba(10, 13, 20, .95);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.65;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .1s;
  z-index: 5;
  box-shadow: var(--shadow);
}
.chart-tip.on { opacity: 1; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13px; }
.kv dt { color: var(--text-dim); }
.kv dd { margin: 0; font-family: var(--mono); text-align: right; }

/* ------------------------------------------------------------------ news */

.news-item {
  padding: 13px 0;
  border-bottom: 1px solid rgba(36, 44, 61, .6);
}
.news-item:last-child { border-bottom: none; }
.news-head {
  font-size: 14px;
  font-weight: 580;
  color: var(--text);
  margin-bottom: 4px;
  cursor: pointer;
}
.news-head:hover { color: var(--accent); }
.news-meta { color: var(--text-faint); font-size: 11.5px; display: flex; gap: 10px; flex-wrap: wrap; }
.news-sum { color: var(--text-dim); font-size: 12.8px; margin-top: 5px; }

/* ------------------------------------------------------------------ docs */

.doc-body { font-size: 14px; line-height: 1.72; color: var(--text-dim); }
.doc-body h1 { font-size: 21px; color: var(--text); margin: 26px 0 12px; padding-bottom: 7px; border-bottom: 1px solid var(--border); }
.doc-body h2 { font-size: 17px; color: var(--text); margin: 24px 0 10px; }
.doc-body h3 { font-size: 15px; color: var(--text); margin: 18px 0 8px; }
.doc-body p { margin: 9px 0; }
.doc-body ul, .doc-body ol { padding-left: 22px; margin: 9px 0; }
.doc-body li { margin: 4px 0; }
.doc-body code {
  font-family: var(--mono); font-size: 12.5px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  padding: 1px 5px; border-radius: 5px; color: #a9d0ff;
}
.doc-body pre {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 15px;
  overflow-x: auto;
  margin: 12px 0;
}
.doc-body pre code { background: none; border: none; padding: 0; color: #c9d3e6; font-size: 12.5px; }
.doc-body table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 13px; }
.doc-body th, .doc-body td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; }
.doc-body th { background: var(--bg-elevated); color: var(--text); font-weight: 600; }
.doc-body blockquote {
  margin: 12px 0; padding: 8px 14px;
  border-left: 3px solid var(--accent);
  background: var(--bg-elevated);
  border-radius: 0 8px 8px 0;
  color: var(--text-dim);
}
.doc-body hr { border: none; border-top: 1px solid var(--border); margin: 22px 0; }

/* --------------------------------------------------------------- 一键复制 */
.doc-body .code-block { position: relative; }
.doc-body .code-block pre { margin: 12px 0; }
.copy-code {
  position: absolute; top: 20px; right: 24px; z-index: 2;
  font-size: 11.5px; line-height: 1.4; padding: 3px 10px;
  background: var(--bg-elevated); color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 6px;
  cursor: pointer; opacity: .62; transition: opacity .12s, color .12s, border-color .12s;
}
.copy-code:hover { opacity: 1; color: var(--text); border-color: var(--accent); }
.copy-code.copied { opacity: 1; color: var(--up); border-color: rgba(22, 199, 132, .55); }
@media (hover: none) { .copy-code { opacity: .9; } }

/* --------------------------------------------------------------- drawer/tab */

.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .58);
  z-index: 45;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.drawer-backdrop.on { opacity: 1; pointer-events: auto; }

.tabbar { display: none; }

.toast-wrap {
  position: fixed;
  right: 16px; bottom: 16px;
  z-index: 90;
  display: flex; flex-direction: column; gap: 8px;
  max-width: min(360px, calc(100vw - 32px));
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-left-width: 3px;
  border-radius: 10px;
  padding: 10px 13px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: slide-in .22s ease-out;
}
.toast.ok   { border-left-color: var(--up); }
.toast.err  { border-left-color: var(--down); }
.toast.info { border-left-color: var(--accent); }
@keyframes slide-in { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .6);
  z-index: 80;
  display: none;
  align-items: center; justify-content: center;
  padding: 20px;
}
.modal-backdrop.on { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: min(460px, 100%);
  max-height: 86dvh;
  overflow-y: auto;
}
.modal-head { padding: 15px 18px; border-bottom: 1px solid var(--border); font-weight: 620; }
.modal-body { padding: 18px; }
.modal-foot { padding: 13px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

.spin {
  width: 15px; height: 15px;
  border: 2px solid rgba(255, 255, 255, .22);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-bar {
  height: 2px; background: var(--accent);
  position: fixed; top: 0; left: 0; z-index: 100;
  width: 0; transition: width .2s, opacity .3s;
}

/* ------------------------------------------------------------- responsive */

@media (max-width: 900px) {
  .layout { display: block; }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    height: 100dvh;
    z-index: 50;
    width: 268px;
    flex-basis: 268px;
    padding-top: 14px;
    transform: translateX(-102%);
    transition: transform .24s cubic-bezier(.4, 0, .2, 1);
    box-shadow: var(--shadow);
    background: var(--bg-elevated);
  }
  .sidebar.on { transform: none; }
  .main { padding: 14px 13px calc(var(--tabbar-h) + 26px); }
  .brand-sub { display: none; }
  .brand { font-size: 14px; }
  .topbar { gap: 7px; padding: 0 10px; }
  .source-select { padding: 6px 8px; font-size: 13px; }
  .grid-index { grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); }
  .index-level { font-size: 21px; }

  .tabbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: var(--tabbar-h);
    z-index: 44;
    display: flex;
    background: rgba(10, 13, 20, .95);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tab {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px;
    color: var(--text-faint);
    font-size: 10.5px;
    cursor: pointer;
    border: none; background: none;
  }
  .tab .tab-ico { font-size: 17px; line-height: 1; }
  .tab.active { color: var(--accent); }
  .toast-wrap { bottom: calc(var(--tabbar-h) + 12px); right: 10px; left: 10px; max-width: none; }
}

@media (max-width: 480px) {
  /* 顶栏挤不下整块品牌名与用户名文字，只留图标。 */
  .brand > div:last-child { display: none; }
  .user-chip span { display: none; }
  .user-chip { padding: 4px; border: none; background: none; }
  .index-level { font-size: 19px; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .page-title { font-size: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
