/* ===== 全局 ===== */
:root {
  --bg: #0b0f1a;
  --bg-soft: #111827;
  --bg-card: #151e2e;
  --border: #1f2a3d;
  --text: #e6ebf4;
  --text-muted: #8b97ad;
  --text-faint: #5c6a82;
  --accent: #6ea8fe;
  --accent-strong: #3b82f6;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 12px;
  --mono: "SFMono-Regular", "Cascadia Code", Consolas, "JetBrains Mono", monospace;
}

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

html { scrollbar-color: #2c3a52 var(--bg); }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.55;
  min-height: 100vh;
  background-image:
    radial-gradient(1200px 500px at 15% -10%, rgba(59, 130, 246, 0.10), transparent 60%),
    radial-gradient(900px 400px at 90% -5%, rgba(217, 119, 87, 0.08), transparent 55%);
}

/* ===== 顶栏 ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 15, 26, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 50;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  font-size: 26px; font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, var(--accent-strong), #8b5cf6);
  border-radius: 11px;
  box-shadow: 0 4px 18px rgba(59, 130, 246, 0.35);
}
.brand h1 { font-size: 19px; font-weight: 700; letter-spacing: 0.3px; }
.brand-sub { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

.topbar-right { display: flex; align-items: center; gap: 10px; }

.status-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--text-muted);
}
.status-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber);
}
.status-pill.ok .status-dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.status-pill.error .status-dot { background: var(--red); box-shadow: 0 0 8px var(--red); }

.countdown {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-faint);
  padding: 7px 6px;
  min-width: 52px;
  text-align: center;
}

.refresh-btn {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.refresh-btn:hover { border-color: var(--accent); color: var(--accent); }
.refresh-btn:disabled { opacity: 0.5; cursor: wait; }
.refresh-btn.spinning { animation: spin 0.9s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 容器 ===== */
.container { max-width: 1240px; margin: 0 auto; padding: 22px 20px 40px; }

/* ===== 控制区 ===== */
.controls {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.search-box {
  flex: 1;
  min-width: 240px;
  max-width: 460px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 14px;
  transition: border-color 0.15s;
}
.search-box:focus-within { border-color: var(--accent); }
.search-icon { color: var(--text-faint); font-size: 16px; }
.search-box input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 14px;
}
.search-box input::placeholder { color: var(--text-faint); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 13px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.chip:hover { color: var(--text); border-color: #334561; }
.chip.active { color: #fff; border-color: transparent; box-shadow: 0 2px 12px rgba(0,0,0,0.35); }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; }
.chip.active .dot { box-shadow: 0 0 6px currentColor; }

/* ===== 订阅套餐 ===== */
.plans { margin: 8px 0 22px; }
.section-title {
  font-size: 15px; font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 12px;
  display: flex; align-items: center; gap: 8px;
}
.section-title::before { content: ""; width: 4px; height: 15px; background: var(--accent); border-radius: 2px; }
.plan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.plan-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: border-color 0.15s;
}
.plan-card:hover { border-color: #334561; }
.plan-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.plan-name { font-size: 14.5px; font-weight: 600; }
.plan-price { font-family: var(--mono); font-size: 19px; font-weight: 700; color: var(--accent); }
.plan-unit { font-size: 11px; color: var(--text-faint); font-family: inherit; font-weight: 400; }
.plan-desc { font-size: 12px; color: var(--text-muted); margin-top: 8px; }
.plan-provider { font-size: 11px; color: var(--text-faint); margin-bottom: 6px; }

/* ===== 表格 ===== */
.table-wrap { margin-top: 4px; }
.table-toolbar { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.table-count { font-size: 12.5px; color: var(--text-faint); }

.table-scroll {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  overflow-x: auto;
}

.price-table { width: 100%; border-collapse: collapse; min-width: 860px; }
.price-table thead th {
  position: sticky; top: 0;
  background: #121a2b;
  padding: 12px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  z-index: 2;
}
.price-table thead th small { display: block; font-size: 10.5px; color: var(--text-faint); font-weight: 500; }
.price-table thead th.col-num { text-align: right; }

.price-table tbody td {
  padding: 13px 14px;
  border-bottom: 1px solid #182236;
  font-size: 13.5px;
  vertical-align: middle;
}
.price-table tbody tr { transition: background 0.1s; cursor: pointer; }
.price-table tbody tr:hover { background: #16203a; }
.price-table tbody tr:last-child td { border-bottom: none; }
.price-table .col-num { text-align: right; font-family: var(--mono); }

.provider-group td {
  background: #0e1524;
  padding: 9px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.4px;
  border-bottom: 1px solid var(--border);
}

.model-name { font-weight: 600; }
.model-sub { font-size: 11px; color: var(--text-faint); margin-top: 2px; }
.tag {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 6px;
  background: rgba(110, 168, 254, 0.14);
  color: #93c5fd;
  vertical-align: middle;
}

.price-val { font-weight: 600; }
.price-val.free { color: var(--green); }
.price-main { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }
.price-main .delta {
  font-size: 10px;
  color: var(--amber);
  border-bottom: 1px dashed rgba(251,191,36,0.4);
  cursor: help;
  font-family: inherit;
}
.price-null { color: var(--text-faint); font-weight: 400; }

/* ===== 阶梯多档价 ===== */
.tier-row {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 7px;
  line-height: 1.7;
  white-space: nowrap;
}
.tier-lbl {
  font-family: inherit;
  font-size: 10.5px;
  color: var(--text-faint);
}
.tier-val {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  min-width: 46px;
  text-align: right;
}
.tier-row .tier-val.free { color: var(--green); }
.tier-row .price-null { font-size: 12px; }

/* 上下文列: 总上下文 + 分档阈值 */
.context-cell { text-align: right; }
.context-cell .context-val { display: block; }
.tier-hint {
  font-size: 10px;
  color: var(--amber);
  margin-top: 2px;
  white-space: nowrap;
}

/* 峰谷徽标 */
.peak-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 7px;
  margin-left: 6px;
  border-radius: 999px;
  color: #fcd34d;
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.3);
  cursor: help;
  vertical-align: middle;
}
.model-sub .peak-badge { margin-left: 0; margin-top: 2px; }

/* 弹层内完整阶梯表 */
.tier-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 12.5px;
}
.tier-table th {
  text-align: right;
  padding: 6px 8px;
  color: var(--text-faint);
  font-weight: 500;
  font-size: 11px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.tier-table th:first-child { text-align: left; }
.tier-table td {
  text-align: right;
  padding: 6px 8px;
  font-family: var(--mono);
  border-bottom: 1px solid #182236;
  white-space: nowrap;
}
.tier-table td:first-child { text-align: left; font-family: inherit; color: var(--text-muted); }
.tier-table tr:last-child td { border-bottom: none; }
.tier-table .free { color: var(--green); }

.provider-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-muted);
  white-space: nowrap;
}
.provider-badge .dot { width: 8px; height: 8px; border-radius: 50%; }

.source-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.source-official {
  background: rgba(52, 211, 153, 0.12);
  color: #6ee7b7;
  border: 1px solid rgba(52, 211, 153, 0.25);
}
.source-live {
  background: rgba(110, 168, 254, 0.12);
  color: #93c5fd;
  border: 1px solid rgba(110, 168, 254, 0.25);
}
.source-unknown { color: var(--text-faint); }

.context-val { color: var(--text-muted); font-size: 12.5px; }

/* ===== 弹层 ===== */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(3, 6, 12, 0.7);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
/* 关键修复: .modal-mask 的 display:flex 会覆盖浏览器默认的 [hidden] 样式,
   导致 hidden 属性失效、弹层永远显示且无法关闭。这里显式声明 hidden 时隐藏。 */
.modal-mask[hidden] { display: none !important; }
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: min(560px, 92vw);
  max-height: 84vh;
  overflow-y: auto;
  padding: 26px;
  position: relative;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
}
.modal-close {
  position: absolute; top: 14px; right: 14px;
  background: none; border: none;
  color: var(--text-faint); font-size: 18px;
  cursor: pointer;
}
.modal-close:hover { color: var(--text); }
.modal h3 { font-size: 18px; margin-bottom: 4px; }
.modal .modal-id { font-family: var(--mono); font-size: 12px; color: var(--text-faint); }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.detail-item {
  background: #0f1729;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.detail-item .label { font-size: 11px; color: var(--text-faint); margin-bottom: 4px; }
.detail-item .value { font-family: var(--mono); font-size: 16px; font-weight: 700; }
.detail-item.wide { grid-column: 1 / -1; }
.modal-note { margin-top: 16px; font-size: 12.5px; color: var(--text-muted); }
.modal-source { margin-top: 10px; font-size: 11.5px; color: var(--text-faint); word-break: break-all; }
.modal-source a { color: var(--accent); text-decoration: none; }
.modal-source a:hover { text-decoration: underline; }

/* ===== 底部 ===== */
.footnote {
  margin-top: 30px;
  padding: 18px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12.5px;
  color: var(--text-muted);
}
.footnote .muted { margin-top: 8px; color: var(--text-faint); font-size: 11.5px; }

/* ===== 空状态 ===== */
.empty {
  padding: 50px 20px;
  text-align: center;
  color: var(--text-faint);
  font-size: 14px;
}

/* ===== 响应式 ===== */
@media (max-width: 720px) {
  .topbar { padding: 14px 16px; }
  .brand-sub { display: none; }
  .price-table { min-width: 760px; }
  .controls { flex-direction: column; align-items: stretch; }
  .search-box { max-width: none; }
}
