/* ===== 概览页 ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: #fff;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.stat-value small { font-size: 14px; font-weight: 500; color: var(--text-secondary); margin-left: 3px; }

.stat-foot {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.trend { font-weight: 600; }
.trend.up { color: var(--success); }
.trend.down { color: var(--danger); }

.stat-icon {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
}

.stat-icon .icon { width: 16px; height: 16px; stroke: var(--accent); stroke-width: 1.8; fill: none; }
.stat-icon.green { background: var(--success-soft); }
.stat-icon.green .icon { stroke: var(--success); }
.stat-icon.purple { background: var(--purple-soft); }
.stat-icon.purple .icon { stroke: var(--purple); }
.stat-icon.orange { background: var(--warning-soft); }
.stat-icon.orange .icon { stroke: var(--warning); }

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
  gap: 16px;
  margin-bottom: 18px;
}

@media (max-width: 1080px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* ===== 折线图区域 ===== */
.chart-box { padding: 8px 12px 4px; }

.chart-legend {
  display: flex;
  gap: 16px;
  padding: 0 8px 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 8px; height: 8px; border-radius: 3px; display: inline-block; }

.range-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-hover);
  padding: 3px;
  border-radius: var(--radius);
}

.range-tabs button {
  border: none;
  background: transparent;
  height: 24px;
  padding: 0 10px;
  font-size: 12px;
  color: var(--text-secondary);
  border-radius: 6px;
}

.range-tabs button.is-active {
  background: #fff;
  color: var(--text-primary);
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}

/* ===== 上游健康列表 ===== */
.upstream-list { display: flex; flex-direction: column; }

.upstream-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 20px;
  border-bottom: 1px solid var(--border);
}

.upstream-row:last-child { border-bottom: none; }

.upstream-logo {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex: 0 0 32px;
  letter-spacing: -0.3px;
}

.upstream-meta { min-width: 0; flex: 1; }
.upstream-name { font-size: 13px; font-weight: 500; }
.upstream-sub { font-size: 11.5px; color: var(--text-muted); }

.meter {
  width: 78px;
  height: 5px;
  background: var(--bg-hover);
  border-radius: 4px;
  overflow: hidden;
  flex: 0 0 78px;
}

.meter i { display: block; height: 100%; border-radius: 4px; background: var(--success); }
.meter i.warn { background: var(--warning); }
.meter i.bad { background: var(--danger); }

/* ===== 数据看板 ===== */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
}

.span-8 { grid-column: span 8; }
.span-4 { grid-column: span 4; }
.span-12 { grid-column: span 12; }
.span-6 { grid-column: span 6; }

@media (max-width: 1080px) {
  .span-8, .span-4, .span-6 { grid-column: span 12; }
}

/* 横向条形排行 */
.rank-list { padding: 6px 20px 16px; display: flex; flex-direction: column; gap: 14px; }

.rank-item { display: flex; flex-direction: column; gap: 6px; }
.rank-top { display: flex; justify-content: space-between; font-size: 13px; }
.rank-top .v { color: var(--text-secondary); font-variant-numeric: tabular-nums; }

.bar-track { height: 8px; background: var(--bg-hover); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; background: linear-gradient(90deg, #4c8ef7, #1a73e8); }
.bar-fill.g2 { background: linear-gradient(90deg, #8f6bfa, #6b3fe0); }
.bar-fill.g3 { background: linear-gradient(90deg, #3fc283, #12a150); }
.bar-fill.g4 { background: linear-gradient(90deg, #f2b544, #e08600); }

/* 环形图 */
.donut-wrap {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 20px 20px;
}

.donut-legend { display: flex; flex-direction: column; gap: 9px; font-size: 12.5px; }
.donut-legend .li { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); }
.donut-legend .li i { width: 8px; height: 8px; border-radius: 3px; }
.donut-legend .li b { margin-left: auto; color: var(--text-primary); font-variant-numeric: tabular-nums; }

/* ===== 密钥页 ===== */
.key-cell { display: flex; align-items: center; gap: 8px; }

.key-mask {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  color: var(--text-secondary);
  letter-spacing: 0.3px;
}

.icon-btn {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: none;
  background: transparent;
  display: grid;
  place-items: center;
  transition: background 0.14s ease;
}

.icon-btn:hover { background: var(--bg-hover); }
.icon-btn .icon { width: 14px; height: 14px; stroke: var(--text-muted); stroke-width: 1.8; fill: none; }

.usage-mini { display: flex; flex-direction: column; gap: 5px; min-width: 110px; }
.usage-mini .txt { font-size: 12px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.usage-mini .track { height: 5px; background: var(--bg-hover); border-radius: 4px; overflow: hidden; }
.usage-mini .track i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.usage-mini .track i.warn { background: var(--warning); }
.usage-mini .track i.bad { background: var(--danger); }

/* ===== 日志页 ===== */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

.filter-bar .grow { flex: 1; }

.status-code {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
}

.status-code.ok { color: var(--success); }
.status-code.warn { color: var(--warning); }
.status-code.err { color: var(--danger); }

.log-msg { color: var(--text-secondary); max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-time { font-variant-numeric: tabular-nums; color: var(--text-secondary); white-space: nowrap; }

/* 日志详情抽屉 */
.drawer-mask {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 40;
}

.drawer-mask.is-open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: 480px;
  max-width: 92vw;
  background: #fff;
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform 0.24s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 41;
  display: flex;
  flex-direction: column;
}

.drawer.is-open { transform: none; }

.drawer-head {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.drawer-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.drawer-body { padding: 18px 20px; overflow-y: auto; }

.kv { display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; }
.kv-row { display: flex; gap: 12px; font-size: 13px; }
.kv-row dt { flex: 0 0 88px; color: var(--text-muted); margin: 0; }
.kv-row dd { flex: 1; margin: 0; word-break: break-all; }

.code-block {
  background: #f6f8fa;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.7;
  color: #24292f;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0;
  max-height: 260px;
  overflow: auto;
}

/* ===== 钱包 ===== */
.wallet-hero {
  padding: 22px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, #1a73e8, #4b8ef8 55%, #6fa4fb);
  color: #fff;
  position: relative;
  overflow: hidden;
}

.wallet-hero::after {
  content: "";
  position: absolute;
  right: -60px;
  top: -70px;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
}

.wallet-hero .label { font-size: 12.5px; opacity: 0.86; }
.wallet-hero .amount { font-size: 34px; font-weight: 650; letter-spacing: -0.6px; margin: 6px 0 4px; font-variant-numeric: tabular-nums; }
.wallet-hero .amount small { font-size: 16px; font-weight: 500; opacity: 0.85; margin-left: 4px; }
.wallet-hero .hint { font-size: 12.5px; opacity: 0.82; }
.wallet-hero .hero-actions { margin-top: 16px; display: flex; gap: 10px; position: relative; z-index: 1; }

.btn-on-blue {
  background: rgba(255, 255, 255, 0.96);
  border-color: transparent;
  color: #1758b8;
}

.btn-on-blue:hover { background: #fff; }

.btn-on-blue-ghost {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.4);
  color: #fff;
}

.btn-on-blue-ghost:hover { background: rgba(255, 255, 255, 0.22); }

/* ===== 个人资料 ===== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  padding: 20px;
}

.form-grid .full { grid-column: 1 / -1; }

@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
}

.avatar-lg {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e8f0fe, #bcd5fa);
  color: #1758b8;
  display: grid;
  place-items: center;
  font-size: 22px;
  font-weight: 600;
}

.profile-head {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.profile-head .meta { flex: 1; }
.profile-head .name { font-size: 16px; font-weight: 600; }
.profile-head .sub { font-size: 12.5px; color: var(--text-muted); }

/* ===== 安全页 ===== */
.setting-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.setting-row:last-child { border-bottom: none; }
.setting-row .txt { flex: 1; min-width: 0; }
.setting-row .title { font-size: 13.5px; font-weight: 500; }
.setting-row .desc { font-size: 12.5px; color: var(--text-muted); }
.setting-row .right { flex: 0 0 auto; }

/* 开关 */
.switch {
  width: 38px;
  height: 22px;
  border-radius: 20px;
  border: none;
  background: #d5d8dd;
  position: relative;
  transition: background 0.16s ease;
  padding: 0;
  flex: 0 0 38px;
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
  transition: transform 0.16s ease;
}

.switch.is-on { background: var(--accent); }
.switch.is-on::after { transform: translateX(16px); }

/* ===== 聊天（对话调试）页 ===== */
.chat-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  height: calc(100vh - var(--header-h) - 110px);
  min-height: 520px;
}

@media (max-width: 1080px) {
  .chat-layout { grid-template-columns: 1fr; height: auto; }
}

.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}

.msg { display: flex; gap: 10px; max-width: 92%; }
.msg.me { margin-left: auto; flex-direction: row-reverse; }

.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  flex: 0 0 28px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
}

.msg.me .msg-avatar { background: #5f6368; }

.bubble {
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  font-size: 13.5px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.me .bubble {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.msg-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 5px;
  font-variant-numeric: tabular-nums;
}

.chat-input-area {
  border-top: 1px solid var(--border);
  padding: 12px 16px 14px;
  background: #fff;
}

.chat-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.chat-toolbar .select { height: 30px; width: auto; font-size: 12.5px; padding: 0 28px 0 10px; }

.chat-input-row { display: flex; gap: 10px; align-items: flex-end; }

.chat-input {
  flex: 1;
  min-height: 42px;
  max-height: 140px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.6;
  resize: none;
  outline: none;
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

.chat-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.12);
}

.params-panel { padding: 16px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }

.param-note { font-size: 11.5px; color: var(--text-muted); }

/* ===== 用户菜单右上 ===== */
.top-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 4px 4px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: #fff;
  height: 34px;
}

.top-user .avatar { width: 24px; height: 24px; flex: 0 0 24px; font-size: 11px; }
.top-user .name { font-size: 12.5px; font-weight: 500; }

/* ===== 弹窗 ===== */
.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.98);
  width: 460px;
  max-width: 92vw;
  background: #fff;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  z-index: 45;
  overflow: hidden;
  animation: modalIn 0.18s ease forwards;
}

@keyframes modalIn {
  from { opacity: 0; transform: translate(-50%, -48%) scale(0.97); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.modal-head {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.modal-head .icon-btn { margin-left: auto; }

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 62vh;
  overflow-y: auto;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translate(-50%, 12px);
  background: #1f2328;
  color: #fff;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 60;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 顶栏刷新区图标按钮 */
.icon-only { width: 34px; padding: 0; }

/* 密钥表：防换行与列宽控制 */
.tbl-keys td { white-space: nowrap; }
.tbl-keys .key-mask { white-space: nowrap; }
.tbl-keys .usage-mini { min-width: 0; width: 100%; }
.tbl-keys .usage-mini .txt { white-space: nowrap; font-size: 11.5px; }
.tbl-keys td:first-child b { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
.tbl-keys td:nth-child(4) { white-space: normal; line-height: 1.45; font-size: 12px; }
.tbl-keys .row-actions { flex-wrap: nowrap; }

/* 表格在窄屏允许横向滚动 */
.tbl-keys { min-width: 860px; }

/* 通用：长内容单元格可换行，短字段不换行 */
.tbl td.mono { white-space: nowrap; }

/* 用户消息的元信息跟随气泡靠右 */
.msg.me .msg-meta { text-align: right; }
.msg.me > div:last-child { display: flex; flex-direction: column; align-items: flex-end; }

/* ===== 移动端修正 ===== */
@media (max-width: 780px) {
  .topbar > div:first-child { min-width: 0; flex: 1; }
  .topbar h1 { white-space: nowrap; font-size: 15px; }
  .topbar-crumb { display: none; }
  .topbar { height: auto; min-height: 56px; padding: 10px 14px; flex-wrap: nowrap; gap: 10px; }
  .topbar-actions { flex: 0 0 auto; gap: 6px; }
  .topbar-actions .search { display: none; }
  .top-user .name { display: none; }
  .top-user { padding: 4px; border-radius: 50%; height: 32px; }
  .sidebar { padding: 10px 10px 12px; max-height: none; }
  .sidebar-brand { padding: 2px 6px 10px; }
  .nav-item { height: 38px; }
  .nav-group-label { margin: 12px 0 4px; }
  .page-title { font-size: 19px; }
  .page-head-actions { justify-content: flex-start; }
  .stat-value { font-size: 23px; }
  .chart-box svg { height: 190px !important; }
  .chat-layout { min-height: 0; }
  .chat-scroll { max-height: 46vh; }
  .drawer { width: 100%; max-width: 100%; }
  .modal { width: calc(100% - 28px); }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .form-grid { padding: 16px; gap: 14px; }
  .card-pad { padding: 16px; }
  .rank-list { padding: 6px 16px 14px; }
  .donut-wrap { flex-direction: column; align-items: flex-start; gap: 14px; }
  .donut-legend { width: 100%; }
}

/* 上游列表副标题防折行 */
.upstream-sub {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.upstream-meta { min-width: 0; }

/* 上游副标题：合并为短文案，避免截断丢信息 */
.upstream-sub {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}

/* 用户卡：余额过长时允许换行但不挤压 */
.user-chip-meta { min-width: 0; }
.user-chip-role {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
