/* ============================================================
   AIAPI 控制台样式
   浅色主题 · 白色侧栏 · 蓝色强调（对齐参考站点的信息架构）
   ============================================================ */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --line: #e9edf3;
  --line-strong: #dde3ec;
  --fg: #0f172a;
  --fg-2: #475569;
  --dim: #8a94a6;
  --acc: #2563eb;
  --acc-weak: #e8f1fe;
  --ok: #16a34a;
  --ok-weak: #e7f7ee;
  --warn: #d97706;
  --warn-weak: #fdf3e3;
  --bad: #dc2626;
  --bad-weak: #fdeaea;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .04);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.55 system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--acc); text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }

/* ---------------------------------------------------------------- 布局 */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 244px; flex: 0 0 244px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  z-index: 30;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 18px 14px;
  font-weight: 650; font-size: 15px; letter-spacing: -.01em;
}
.brand .logo {
  width: 26px; height: 26px; border-radius: 8px;
  background: linear-gradient(135deg, #2563eb, #5b9dff);
  display: grid; place-items: center; color: #fff; flex: 0 0 26px;
}
.brand .logo svg { width: 15px; height: 15px; }

.nav { padding: 0 10px 18px; }
.nav-label {
  font-size: 11px; color: var(--dim); font-weight: 600;
  padding: 14px 10px 6px; letter-spacing: .06em;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; margin: 1px 0;
  border-radius: 10px; color: var(--fg-2);
  font-size: 14px; cursor: pointer; user-select: none;
}
.nav-item svg { width: 17px; height: 17px; flex: 0 0 17px; opacity: .85; }
.nav-item:hover { background: var(--surface-2); color: var(--fg); }
.nav-item.active { background: var(--acc-weak); color: var(--acc); font-weight: 600; }
.nav-item.active svg { opacity: 1; }
.nav-item .badge-dot {
  margin-left: auto; background: var(--acc); color: #fff;
  font-size: 10px; border-radius: 20px; padding: 1px 6px; font-weight: 600;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; min-height: 58px;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 16px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
.topbar .spacer { flex: 1; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center;
  border: 1px solid transparent; background: transparent; color: var(--fg-2);
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--line); }
.icon-btn svg { width: 18px; height: 18px; }
.menu-btn { display: none; }

.content { padding: 20px; max-width: 1180px; width: 100%; }
.page { display: grid; gap: 16px; }

/* ---------------------------------------------------------------- 组件 */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.card.pad-0 { padding: 0; overflow: hidden; }
.card-head {
  display: flex; align-items: center; gap: 10px; margin-bottom: 12px;
}
.card-head h2 { font-size: 14px; margin: 0; font-weight: 650; }
.card-head .sub { color: var(--dim); font-size: 12px; }
.card-head .spacer { flex: 1; }

.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.metric {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px;
}
.metric .k { color: var(--dim); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.metric .v { font-size: 24px; font-weight: 650; margin-top: 6px; letter-spacing: -.02em; }
.metric .d { font-size: 11.5px; color: var(--dim); margin-top: 2px; }
.metric .v.ok { color: var(--ok); }
.metric .v.bad { color: var(--bad); }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--fg); border-radius: 9px; padding: 7px 12px; font-size: 13px;
  transition: .12s;
}
.btn:hover { border-color: #c9d2e0; background: var(--surface-2); }
.btn.primary { background: var(--acc); border-color: var(--acc); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { color: var(--bad); border-color: #f3caca; }
.btn.danger:hover { background: var(--bad-weak); }
.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; padding: 2px 8px; border-radius: 20px; font-weight: 550;
  background: #eef1f6; color: var(--fg-2);
}
.badge.ok { background: var(--ok-weak); color: var(--ok); }
.badge.bad { background: var(--bad-weak); color: var(--bad); }
.badge.warn { background: var(--warn-weak); color: var(--warn); }
.badge.acc { background: var(--acc-weak); color: var(--acc); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--dim); font-weight: 550; font-size: 12px; background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fbfcfe; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

.empty { padding: 28px 16px; text-align: center; color: var(--dim); font-size: 13px; }

.avatar {
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, #2563eb, #93c5fd);
  color: #fff; display: grid; place-items: center;
  font-size: 22px; font-weight: 600;
}

.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 12.5px; color: var(--fg-2); font-weight: 550; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line-strong);
  border-radius: 9px; background: var(--surface); color: var(--fg); outline: none;
}
.field input:focus, .field select:focus { border-color: var(--acc); box-shadow: 0 0 0 3px rgba(37, 99, 235, .1); }
.field .hint { font-size: 11.5px; color: var(--dim); }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.muted { color: var(--dim); }
.small { font-size: 12px; }

.keycard {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; background: var(--surface);
  display: grid; gap: 10px;
}
.keycard.disabled { opacity: .62; background: var(--surface-2); }
.keycard .top { display: flex; align-items: center; gap: 8px; }
.keycard .name { font-weight: 600; }
.keycard .k { font-family: ui-monospace, monospace; font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--line); padding: 7px 9px; border-radius: 8px; word-break: break-all; }
.keycard .meta { display: flex; gap: 16px; font-size: 12px; color: var(--dim); flex-wrap: wrap; }
.keycard .meta b { color: var(--fg); font-weight: 600; }

.chart { width: 100%; height: auto; display: block; }
.chart text { font-size: 10px; fill: var(--dim); }

.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 90px; gap: 10px; align-items: center; font-size: 12.5px; }
.bar-track { height: 8px; background: #eef1f6; border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--acc); border-radius: 6px; }

/* --------------------------------------------------------------- 登录页 */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #eaf1fe 0%, var(--bg) 55%);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 16px;
  padding: 26px 24px; box-shadow: var(--shadow);
}
.login-card .brand { padding: 0 0 18px; }
.login-card h2 { margin: 0 0 4px; font-size: 19px; letter-spacing: -.02em; }
.login-card p.tip { margin: 0 0 18px; color: var(--dim); font-size: 12.5px; }
.login-card .btn { width: 100%; justify-content: center; padding: 10px; }
.login-err { color: var(--bad); font-size: 12.5px; min-height: 18px; margin-bottom: 6px; }

/* --------------------------------------------------------------- 弹窗 */
.overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .38);
  display: grid; place-items: center; padding: 20px; z-index: 100;
}
.modal {
  background: var(--surface); border-radius: 14px; width: 100%; max-width: 440px;
  padding: 20px; box-shadow: 0 20px 50px rgba(15, 23, 42, .2);
  max-height: 88vh; overflow: auto;
}
.modal h3 { margin: 0 0 4px; font-size: 16px; }
.modal p.sub { margin: 0 0 14px; color: var(--dim); font-size: 12.5px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 13px; z-index: 200; box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
  opacity: 0; transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }

/* --------------------------------------------------------------- 响应式 */
@media (max-width: 980px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 260px;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(15, 23, 42, .16);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: grid; }
  .content { padding: 14px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: minmax(0, 1fr); }
  .metric .v { font-size: 21px; }
  .bar-row { grid-template-columns: 96px 1fr 74px; }
  .scrim { position: fixed; inset: 0; background: rgba(15, 23, 42, .3); z-index: 25; }
  .topbar { padding: 10px 14px; }
}

/* --------------------------------------------------- 手机端：表格变卡片 */
@media (max-width: 760px) {
  .table-wrap { overflow: visible; }
  .table-wrap table { display: block; }
  .table-wrap thead { display: none; }
  .table-wrap tbody { display: block; }
  .table-wrap tr {
    display: block; padding: 10px 12px; margin-bottom: 10px;
    border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  }
  .table-wrap td {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    border: 0; padding: 5px 0; text-align: right;
  }
  .table-wrap td::before {
    content: attr(data-label); color: var(--dim); font-size: 12px;
    flex: 0 0 auto; text-align: left;
  }
  .table-wrap td:empty { display: none; }
  .table-wrap td > div.row { justify-content: flex-end; }

  /* 点按区域放大 */
  .btn { padding: 9px 14px; }
  .btn.sm { padding: 8px 12px; }
  .nav-item { padding: 12px 14px; }
  .modal .actions .btn { flex: 1; }
  .card { padding: 14px; }

  /* 顶部指标两列，不挤成一条 */
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .metric { padding: 12px; }
  .metric .v { font-size: 19px; }
  .bar-row { grid-template-columns: 84px 1fr 70px; gap: 8px; }

  /* 卡片头在窄屏允许换行 */
  .card-head { flex-wrap: wrap; row-gap: 8px; }
  .card-head .spacer { flex: 1 1 0; }
  select.btn, input, .field input { font-size: 16px; } /* iOS 不自动放大 */
}
