:root {
  --primary: #1677ff;
  --primary-hover: #4096ff;
  --primary-soft: #e6f4ff;
  --success: #52c41a;
  --success-soft: #f6ffed;
  --warning: #faad14;
  --warning-soft: #fffbe6;
  --error: #ff4d4f;
  --error-soft: #fff2f0;
  --text: #1f2329;
  --text-2: #646a73;
  --text-3: #8f959e;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e5e6eb;
  --border-strong: #d0d3d9;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 6px 20px rgba(31, 35, 41, 0.08);
  --shadow-sm: 0 2px 8px rgba(31, 35, 41, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }
code { font-family: var(--mono); font-size: 12px; }
.hidden { display: none !important; }
.muted { color: var(--text-2); }
.mono { font-family: var(--mono); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 22px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #1677ff, #0958d9);
  color: #fff; font-weight: 700; font-size: 18px;
  box-shadow: 0 4px 12px rgba(22, 119, 255, 0.28);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 15px; letter-spacing: .2px; }
.brand-text span { font-size: 12px; color: var(--text-3); }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; height: 40px; padding: 0 12px;
  border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-2);
  cursor: pointer; text-align: left; transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-icon { width: 18px; text-align: center; font-size: 15px; }
.nav-count {
  margin-left: auto; min-width: 22px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: var(--border); color: var(--text-2);
  font-size: 11px; line-height: 20px; text-align: center;
}
.nav-item.active .nav-count { background: #fff; color: var(--primary); }
.sidebar-footer { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--border); font-size: 12px; }
.status-line { display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.dot.ok { background: var(--success); box-shadow: 0 0 0 3px rgba(82, 196, 26, .15); }
.dot.bad { background: var(--error); box-shadow: 0 0 0 3px rgba(255, 77, 79, .15); }

.main { min-width: 0; padding: 24px 28px 48px; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.topbar h1 { margin: 0; font-size: 22px; line-height: 1.35; font-weight: 650; letter-spacing: .2px; }
.subtitle { margin: 4px 0 0; color: var(--text-2); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.api-chip {
  display: flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 8px 0 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); box-shadow: var(--shadow-sm);
}
.api-chip-label { font-size: 11px; font-weight: 700; color: var(--primary); letter-spacing: .5px; }
.api-chip code { color: var(--text-2); max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); cursor: pointer; white-space: nowrap;
  transition: border-color .15s, color .15s, background .15s, box-shadow .15s;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn:active { background: var(--primary-soft); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--primary); }
.btn.danger:hover { border-color: var(--error); color: var(--error); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn {
  width: 26px; height: 26px; border: 0; border-radius: 4px;
  background: transparent; color: var(--text-3); cursor: pointer; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.view { animation: fade .18s ease; }
@keyframes fade { from { opacity: .4; transform: translateY(2px); } to { opacity: 1; transform: none; } }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow-sm);
}
.stat-label { color: var(--text-2); font-size: 12px; }
.stat-value { margin-top: 6px; font-size: 26px; line-height: 1.2; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-foot { margin-top: 4px; color: var(--text-3); font-size: 12px; }

.two-col { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 16px; margin-bottom: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow-sm); min-width: 0;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-kicker { color: var(--text-3); font-size: 11px; letter-spacing: .6px; text-transform: uppercase; }
.card-head h2 { margin: 2px 0 0; font-size: 16px; font-weight: 600; }
.active-card { display: flex; flex-direction: column; }
.active-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--text-2); font-size: 12px; margin-bottom: 14px; }
.active-meta strong { color: var(--text); font-weight: 600; }
.quota-list { display: flex; flex-direction: column; gap: 14px; }
.quota-item { display: flex; flex-direction: column; gap: 6px; }
.quota-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.quota-name { font-weight: 600; }
.quota-num { color: var(--text-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.bar { height: 7px; border-radius: 4px; background: #eef0f3; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 4px; background: var(--success); transition: width .35s ease; }
.bar.warn > span { background: var(--warning); }
.bar.danger > span { background: var(--error); }
.policy-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.policy-list li { display: flex; flex-direction: column; gap: 2px; padding-left: 12px; border-left: 2px solid var(--primary-soft); }
.policy-list strong { font-size: 13px; }
.policy-list span { color: var(--text-2); font-size: 12px; }

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px; border-radius: 11px;
  font-size: 12px; line-height: 22px; white-space: nowrap;
  background: #f2f3f5; color: var(--text-2);
}
.tag.ok { background: var(--success-soft); color: #389e0d; }
.tag.warn { background: var(--warning-soft); color: #d48806; }
.tag.bad { background: var(--error-soft); color: #cf1322; }
.tag.info { background: var(--primary-soft); color: #0958d9; }
.tag .dot { width: 6px; height: 6px; }

.table-wrap { overflow: auto; border-radius: var(--radius-sm); }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.table th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2); color: var(--text-2);
  font-weight: 500; font-size: 12px; text-align: left;
  padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 11px 10px; border-bottom: 1px solid #f0f1f3; vertical-align: middle; }
.table tbody tr { cursor: default; }
.table tbody tr:hover { background: #f8fafd; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .muted-cell { color: var(--text-3); font-size: 12px; }
.table .ellipsis { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.w-priority { width: 82px; }
.w-actions { width: 190px; }
.actions { display: flex; gap: 4px; justify-content: flex-end; }
.actions .btn { height: 28px; padding: 0 8px; font-size: 12px; }

.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 32px 16px; color: var(--text-3); text-align: center;
}
.empty.small { padding: 18px; font-size: 12px; }
.empty-icon { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--text-3); font-size: 20px; }
.empty p { margin: 0; max-width: 460px; font-size: 13px; line-height: 1.7; }

.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin: 4px 0 14px; }
.section-head h2 { margin: 0; font-size: 18px; font-weight: 650; }
.section-head p { margin: 4px 0 0; font-size: 12px; }
.section-actions { display: flex; gap: 8px; align-items: center; }

.input {
  width: 100%; height: 36px; padding: 0 11px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(22, 119, 255, .12); }
.input.compact { width: auto; min-width: 120px; height: 34px; }
textarea.input { height: auto; padding: 9px 11px; resize: vertical; line-height: 1.5; }
.input-group { display: flex; gap: 8px; }
.input-group .input { flex: 1; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; font-weight: 500; }
.field small { color: var(--text-3); font-size: 12px; line-height: 1.5; }
.field small code { color: var(--text-2); }
.switch-field { flex-direction: row; align-items: center; justify-content: space-between; gap: 20px; padding: 12px 0; border-bottom: 1px solid #f0f1f3; }
.switch-field > span { display: flex; flex-direction: column; gap: 3px; }
.switch { appearance: none; width: 40px; height: 22px; border-radius: 11px; background: #d9dce1; position: relative; cursor: pointer; flex: none; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.15); transition: transform .15s; }
.switch:checked { background: var(--primary); }
.switch:checked::after { transform: translateX(18px); }
.info-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid #f0f1f3; font-size: 12px; }
.info-row:last-child { border-bottom: 0; }
.info-row span { color: var(--text-2); }
.info-row code { color: var(--text); max-width: 70%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

.modal, .drawer { position: fixed; inset: 0; z-index: 50; display: flex; }
.modal-backdrop, .drawer-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .42); backdrop-filter: blur(2px); }
.modal-panel {
  position: relative; margin: auto; width: min(620px, calc(100vw - 32px));
  max-height: calc(100vh - 48px); overflow: auto;
  background: var(--surface); border-radius: 12px; box-shadow: var(--shadow);
  animation: pop .18s ease;
}
@keyframes pop { from { opacity: .6; transform: scale(.98); } to { opacity: 1; transform: none; } }
.modal-head, .drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 14px; border-bottom: 1px solid var(--border); }
.modal-head h2, .drawer-head h2 { margin: 2px 0 0; font-size: 17px; }
.modal-body { padding: 18px 20px 20px; }
.drawer-panel {
  position: relative; margin-left: auto; width: min(760px, 100vw); height: 100%;
  background: var(--surface); box-shadow: var(--shadow); display: flex; flex-direction: column;
  animation: slide .2s ease;
}
@keyframes slide { from { transform: translateX(20px); opacity: .5; } to { transform: none; opacity: 1; } }
.drawer-body { padding: 18px 20px 28px; overflow: auto; }
.waiting { display: flex; align-items: center; gap: 10px; padding: 14px; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text-2); font-size: 13px; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.divider { display: flex; align-items: center; gap: 10px; margin: 18px 0 14px; color: var(--text-3); font-size: 12px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.alert { margin-top: 12px; padding: 9px 12px; border-radius: var(--radius-sm); font-size: 12px; line-height: 1.5; }
.alert.error { background: var(--error-soft); color: #cf1322; }
.alert.info { background: var(--primary-soft); color: #0958d9; }
.toast {
  position: fixed; right: 24px; bottom: 24px; z-index: 80;
  max-width: 360px; padding: 10px 14px; border-radius: var(--radius-sm);
  background: #1f2329; color: #fff; font-size: 13px; box-shadow: var(--shadow);
  opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: #cf1322; }

.log-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 18px; margin-bottom: 16px; }
.log-meta div { display: flex; flex-direction: column; gap: 2px; }
.log-meta span { color: var(--text-3); font-size: 11px; }
.log-meta strong { font-weight: 600; font-size: 13px; word-break: break-all; }
.usage-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin: 14px 0 18px; }
.usage-cell { padding: 10px; border-radius: var(--radius-sm); background: var(--surface-2); }
.usage-cell span { display: block; color: var(--text-3); font-size: 11px; }
.usage-cell strong { display: block; margin-top: 2px; font-size: 16px; font-variant-numeric: tabular-nums; }
.pre-block { margin: 0 0 16px; padding: 12px; border-radius: var(--radius-sm); background: #0f172a; color: #d7e0ea; font-family: var(--mono); font-size: 11px; line-height: 1.55; overflow: auto; max-height: 280px; white-space: pre-wrap; word-break: break-all; }
.detail-label { display: flex; align-items: center; justify-content: space-between; margin: 16px 0 6px; font-size: 12px; color: var(--text-2); }

@media (max-width: 1080px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-col { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; gap: 12px; padding: 12px 14px; }
  .brand { padding: 0; }
  .brand-text span, .sidebar-footer { display: none; }
  .nav { flex-direction: row; overflow: auto; }
  .nav-item { width: auto; padding: 0 10px; }
  .nav-count { display: none; }
  .main { padding: 16px 14px 40px; }
  .topbar { flex-direction: column; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .api-chip code { max-width: 140px; }
  .section-head { flex-direction: column; align-items: stretch; }
  .section-actions { flex-wrap: wrap; }
  .stat-grid { grid-template-columns: 1fr; }
  .usage-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .log-meta { grid-template-columns: 1fr; }
}

.account-id { font-family: var(--mono); font-size: 11px; color: var(--text-3); }
.fingerprint { font-family: var(--mono); font-size: 11px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.today-total { font-weight: 600; font-variant-numeric: tabular-nums; }
.model-line { display: flex; justify-content: space-between; gap: 10px; margin-top: 3px; color: var(--text-2); font-size: 12px; }
.model-line span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-line span:last-child { flex: none; font-variant-numeric: tabular-nums; }
.model-line em { font-style: normal; }
.rate-good { color: var(--success); font-variant-numeric: tabular-nums; }
.rate-warn { color: var(--warning); font-variant-numeric: tabular-nums; }
.rate-bad { color: var(--error); font-variant-numeric: tabular-nums; }

.token-row { display: flex; gap: 8px; align-items: center; }
.token-row .input { flex: 1; min-width: 0; }
.token-row .btn { flex: none; }

/* account quota / token breakdown */
.quota-models { display: flex; flex-direction: column; gap: 9px; }
.quota-model { display: flex; flex-direction: column; gap: 4px; }
.quota-model-top { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.quota-model-top span:first-child { color: var(--text); font-weight: 500; }
.token-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; margin-top: 6px; }
.token-cell { display: flex; flex-direction: column; gap: 1px; padding: 4px 6px; border-radius: 4px; background: var(--surface-2); }
.token-cell span { color: var(--text-3); font-size: 10px; }
.token-cell strong { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* login */
.login-body { display: flex; min-height: 100vh; background: radial-gradient(1200px 600px at 50% -10%, #e6f4ff 0%, transparent 60%), var(--bg); }
.login-wrap { margin: auto; width: min(420px, calc(100vw - 32px)); padding: 24px 0; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px; box-shadow: var(--shadow); }
.login-brand { padding: 0 0 22px; }
.login-card h1 { margin: 0 0 6px; font-size: 20px; }
.login-card > p { margin: 0 0 18px; color: var(--text-2); font-size: 13px; line-height: 1.6; }
.login-card .field { margin-bottom: 16px; }
.login-card .btn { height: 38px; }
.login-hint { margin: 16px 0 0; color: var(--text-3); font-size: 12px; line-height: 1.6; }
.login-hint code { color: var(--text-2); }

/* Activity center */
.activity-list { display: grid; gap: 10px; }
.activity-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: var(--surface-2);
}
.activity-card-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.activity-card-title { font-weight: 600; }
.activity-card-meta { color: var(--text-2); font-size: 12px; line-height: 1.6; }
.activity-benefits { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.activity-benefit { border: 1px solid var(--border); border-radius: 999px; padding: 2px 8px; font-size: 12px; color: var(--text-2); }
.activity-campaigns { margin-top: 12px; color: var(--text-2); font-size: 12px; }

.quota-plan { margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px dashed var(--border); }
.quota-plan:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: 0; }
.quota-plan-head { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; font-weight: 600; margin-bottom: 6px; }

.model-state { margin-top: 4px; font-size: 12px; color: var(--warning); }
.model-state.bad { color: var(--error); }
