/* ============================================================
   UniMeter · AI 用量网关 — 共享样式（Design Contract 单一样式源）
   tech-dark / control-plane console
   ============================================================ */

:root {
  --primary: #35d0ba;
  --primary-hover: #4ae0cb;
  --accent-dim: rgba(53, 208, 186, .12);
  --bg: #0a0e14;
  --surface: #10161f;
  --surface-2: #151d29;
  --border: #1f2a38;
  --border-strong: #2a3849;
  --text: #e8edf5;
  --text-sub: #8a94a8;
  --success: #4ade80;
  --warning: #f5b545;
  --danger: #f87171;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, .35);
  --sidebar-w: 232px;
  --font-display: "Bahnschrift", "DIN Alternate", "Segoe UI", sans-serif;
  --font-body: "Segoe UI", "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
  --font-mono: "Cascadia Code", "JetBrains Mono", "SF Mono", Consolas, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { color-scheme: dark; }

body {
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background-color: var(--bg);
  /* bg-texture: 顶部青色微光 + 40px 细网格 */
  background-image:
    radial-gradient(900px 420px at 70% -10%, rgba(53, 208, 186, .07), transparent 60%),
    linear-gradient(rgba(232, 237, 245, .03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(232, 237, 245, .03) 1px, transparent 1px);
  background-size: 100% 100%, 40px 40px, 40px 40px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; transition: color .18s ease; }
a:hover { color: var(--primary-hover); }

::selection { background: rgba(53, 208, 186, .25); }

/* ============ App Shell：侧栏（每页 byte-identical） ============ */
.app-nav {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #0d1219 0%, #0a0e14 100%);
  border-right: 1px solid var(--border);
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 16px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: #062b26;
  background: linear-gradient(135deg, var(--primary) 0%, #1e9c8b 100%);
  box-shadow: 0 0 18px rgba(53, 208, 186, .35);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; }

.brand-name {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: .04em;
}

.brand-sub { font-size: 12px; color: var(--text-sub); }

.nav-menu {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 8px 12px;
  gap: 2px;
}

.nav-menu a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-sub);
  font-size: 14px;
  transition: background .18s ease, color .18s ease;
}

.nav-menu a svg { flex: 0 0 20px; }

.nav-menu a:hover {
  color: var(--text);
  background: var(--surface-2);
}

.nav-menu a.active {
  color: var(--primary);
  background: var(--accent-dim);
  box-shadow: inset 2px 0 0 var(--primary);
}

.nav-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-sub);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px rgba(74, 222, 128, .6);
  animation: pulse 2.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .4; }
}

/* ============ 内容区（每页相同 offset，导航不可能漂移） ============ */
.app-content {
  margin-left: var(--sidebar-w);
  padding: 32px;
  max-width: 1200px;
}

/* 页面载入编排：内容块依次上浮 */
.app-content > * {
  animation: rise .5s ease both;
}
.app-content > *:nth-child(1) { animation-delay: .02s; }
.app-content > *:nth-child(2) { animation-delay: .08s; }
.app-content > *:nth-child(3) { animation-delay: .14s; }
.app-content > *:nth-child(4) { animation-delay: .20s; }
.app-content > *:nth-child(5) { animation-delay: .24s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============ 页头 ============ */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.page-head h1 {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 700;
  letter-spacing: .02em;
  line-height: 1.2;
}

.page-head .page-desc {
  color: var(--text-sub);
  font-size: 14px;
  margin-top: 6px;
}

.page-head .page-actions { display: flex; gap: 12px; align-items: center; }

/* ============ 卡片 ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  transition: border-color .18s ease, box-shadow .18s ease;
}

.card:hover { border-color: var(--border-strong); }

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}

.card-desc {
  font-size: 12px;
  color: var(--text-sub);
  margin-bottom: 16px;
}

.card-link {
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
}

/* ============ 按钮 ============ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: filter .18s ease, background .18s ease, border-color .18s ease, color .18s ease;
  background: none;
  color: var(--text);
}

.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.btn-primary {
  background: var(--primary);
  color: #062421;
  font-weight: 600;
}
.btn-primary:hover { background: var(--primary-hover); filter: brightness(1.05); }

.btn-ghost { border-color: var(--border-strong); color: var(--text-sub); }
.btn-ghost:hover { color: var(--text); border-color: var(--primary); background: var(--accent-dim); }

.btn-danger { border-color: rgba(248, 113, 113, .35); color: var(--danger); }
.btn-danger:hover { background: rgba(248, 113, 113, .1); border-color: var(--danger); }

.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: var(--radius-sm); }

.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }

/* ============ 表单 ============ */
.input, .select, textarea.input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  transition: border-color .18s ease, box-shadow .18s ease;
}

.input::placeholder { color: #5a6478; }

.input:focus, .select:focus, textarea.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a94a8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
  cursor: pointer;
}

.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-sub);
  margin-bottom: 6px;
  letter-spacing: .03em;
}

.field .field-hint { font-size: 12px; color: var(--text-sub); margin-top: 4px; }

/* ============ 表格 ============ */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

table.table { width: 100%; border-collapse: collapse; font-size: 14px; }

.table th {
  text-align: left;
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-sub);
  letter-spacing: .08em;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
}

.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr { transition: background .18s ease; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: none; }

.table .mono, .mono { font-family: var(--font-mono); font-size: 13px; }

/* ============ 标签 ============ */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid transparent;
  white-space: nowrap;
}

.tag-success { color: var(--success); background: rgba(74, 222, 128, .1); border-color: rgba(74, 222, 128, .25); }
.tag-warning { color: var(--warning); background: rgba(245, 181, 69, .1); border-color: rgba(245, 181, 69, .25); }
.tag-danger  { color: var(--danger);  background: rgba(248, 113, 113, .1); border-color: rgba(248, 113, 113, .25); }
.tag-neutral { color: var(--text-sub); background: var(--surface-2); border-color: var(--border-strong); }
.tag-accent  { color: var(--primary); background: var(--accent-dim); border-color: rgba(53, 208, 186, .3); }

/* ============ 开关 ============ */
.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex: 0 0 40px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.switch .track {
  position: absolute;
  inset: 0;
  background: var(--border-strong);
  border-radius: 999px;
  cursor: pointer;
  transition: background .18s ease;
}

.switch .track::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: var(--text-sub);
  transition: transform .18s ease, background .18s ease;
}

.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::before { transform: translateX(18px); background: #062421; }
.switch input:focus-visible + .track { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ============ 弹窗 ============ */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal.open { display: flex; }

.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(4, 7, 12, .6);
  backdrop-filter: blur(2px);
}

.modal-box {
  position: relative;
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-md);
  animation: rise .3s ease both;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-head h3 { font-family: var(--font-display); font-size: 20px; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-sub);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  display: flex;
  transition: color .18s ease, background .18s ease;
}
.modal-close:hover { color: var(--text); background: var(--surface-2); }

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 20px;
}

/* ============ Toast ============ */
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 300;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  font-size: 14px;
  animation: toast-in .28s ease both;
}

.toast.toast-success { border-left-color: var(--success); }
.toast.toast-danger { border-left-color: var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(24px); }
  to { opacity: 1; transform: translateX(0); }
}

.toast.hide { animation: toast-out .28s ease both; }

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(24px); }
}

/* ============ 进度条 ============ */
.progress {
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
  transition: width .6s ease;
}

.progress-bar.warn { background: var(--warning); }
.progress-bar.danger { background: var(--danger); }

/* ============ 空状态 / 骨架屏 ============ */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 48px 24px;
  color: var(--text-sub);
  text-align: center;
}

.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-2) 25%, #1b2431 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* ============ 网格工具 ============ */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ============ 代码块 ============ */
.code-block {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
  background: #080b11;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  overflow-x: auto;
  color: #b8c4d4;
  white-space: pre;
}

.code-block .tok-accent { color: var(--primary); }
.code-block .tok-str { color: #a3d9a5; }
.code-block .tok-key { color: var(--warning); }

/* ============ 响应式 ============ */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .app-nav {
    position: static;
    width: 100%;
    flex-direction: row;
    align-items: center;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .nav-brand { padding: 12px 16px; }
  .brand-sub { display: none; }
  .nav-menu {
    flex-direction: row;
    overflow-x: auto;
    padding: 4px 8px;
  }
  .nav-menu a { white-space: nowrap; padding: 8px 10px; }
  .nav-menu a.active { box-shadow: inset 0 -2px 0 var(--primary); }
  .nav-foot { display: none; }
  .app-content { margin-left: 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 24px; }
}

@media (max-width: 480px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .modal { padding: 12px; }
}
