/* 默认隐藏禁用的搜索词行，勾选 checkbox 时显示全部 */
.query-row-disabled { display: none; }
body.show-all-disabled .query-row-disabled { display: table-row; }
/* ═══════════════════════════════════════════════════════════════
   CSS Variables — test.150420.xyz / OpenCode 去蓝版
   ═══════════════════════════════════════════════════════════════ */
:root {
  /* 背景层级 — 暖深灰，无彩色 */
  --bg-root: #1a1a1a;
  --bg-body: #222222;
  --bg-card: #2a2a2a;
  --bg-card-hover: #323232;
  --bg-input: #222222;
  --border: rgba(255,255,255,0.08);
  --border-hover: rgba(255,255,255,0.15);

  /* 主色 — 浅灰白，无任何蓝色/青色 */
  --accent: #e0e0e0;
  --accent-hover: #f0f0f0;
  --accent-active: #ffffff;

  /* 文字 */
  --text-primary: #f5f5f5;
  --text-body: #a0a0a0;
  --text-dim: #707070;
  --text-muted: #606060;

  /* 向后兼容 — JS 内联引用 */
  --cyan: var(--accent);
  --green: var(--success);
  --amber: var(--warning);
  --red: var(--danger);

  /* 语义色 — 保持 Apple HIG 但降低饱和度 */
  --success: #30d158;
  --success-bg: rgba(48,209,88,0.08);
  --danger: #ff453a;
  --danger-bg: rgba(255,69,58,0.08);
  --warning: #ff9f0a;
  --warning-bg: rgba(255,159,10,0.08);

  /* 字号 */
  --fs-xs: 0.6875rem;    /* 11px */
  --fs-sm: 0.75rem;      /* 12px */
  --fs-body: 0.8125rem;  /* 13px */
  --fs-md: 0.875rem;     /* 14px */
  --fs-lg: 1rem;         /* 16px */
  --fs-mono: 0.75rem;    /* 12px */

  /* 圆角 — test.150420.xyz 是 4px */
  --radius: 4px;
  --radius-sm: 4px;

  /* 字体 */
  --font-mono: "JetBrains Mono", "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --transition: 0.15s ease;
}

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

body {
  font-family: var(--font-body);
  background: #111111;
  color: var(--text-body);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  line-height: 1.5;
  font-size: var(--fs-body);
  -webkit-font-smoothing: antialiased;
}

/* ═══════════════════════════════════════════════════════════════
   Login Page
   ═══════════════════════════════════════════════════════════════ */
.login-wrap {
  display: flex; justify-content: center; align-items: center;
  min-height: 100vh; width: 100%;
  background: var(--bg-root);
}
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 360px;
}
.login-card h1 {
  font-size: var(--fs-md);
  color: var(--text-primary);
  text-align: center;
  margin-bottom: 4px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.login-card .sub {
  font-size: var(--fs-sm);
  color: var(--text-dim);
  text-align: center;
  margin-bottom: 24px;
}
.login-card input {
  width: 100%; padding: 10px 14px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  font-size: var(--fs-sm); font-family: var(--font-mono);
  outline: none; transition: var(--transition);
}
.login-card input:focus { border-color: var(--accent); }
.login-card button {
  width: 100%; padding: 10px; margin-top: 14px;
  background: var(--accent); color: var(--bg-root);
  border: none; border-radius: var(--radius-sm);
  font-size: var(--fs-sm); font-weight: 600; cursor: pointer;
  transition: var(--transition);
}
.login-card button:hover { background: var(--accent-hover); }
.login-card .err { color: var(--danger); font-size: var(--fs-sm); text-align: center; margin-bottom: 10px; }

/* ═══════════════════════════════════════════════════════════════
   Layout
   ═══════════════════════════════════════════════════════════════ */
.app {
  display: flex;
  width: 100%;
  max-width: 1480px;
  min-height: 100vh;
  background: var(--bg-root);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  margin: 0 auto;
}

.sidebar {
  width: 200px; min-width: 200px;
  background: var(--bg-body);
  border-right: 1px solid var(--border);
  padding: 0;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.side-logo {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}
.side-logo h2 {
  font-size: var(--fs-body);
  color: var(--text-primary);
  font-weight: 600;
}
.side-logo .ver {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  margin-top: 2px;
}

.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 16px;
  margin: 0;
  cursor: pointer;
  font-size: var(--fs-sm);
  color: var(--text-dim);
  transition: var(--transition);
  text-decoration: none;
  user-select: none;
  border-left: 2px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,0.03); color: var(--text-body); }
.nav-item.active {
  background: rgba(255,255,255,0.05);
  color: var(--text-primary);
  border-left-color: var(--accent);
}
.nav-item .ico { font-size: 14px; width: 20px; text-align: center; flex-shrink: 0; }

.side-status {
  margin-top: auto;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  font-size: var(--fs-xs);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}
.side-status .dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
}
.side-status .dot.on { background: var(--success); }
.side-status .dot.off { background: var(--danger); }

/* ═══════════════════════════════════════════════════════════════
   Main Content
   ═══════════════════════════════════════════════════════════════ */
.main { flex: 1; padding: 24px; overflow-x: hidden; max-width: 1400px; }

.page-header { margin-bottom: 20px; }
.page-header h2 {
  font-size: var(--fs-md);
  color: var(--text-primary);
  font-weight: 600;
}
.page-header p {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  margin-top: 2px;
}

/* ── Stats Cards ── */
.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
@media (max-width: 900px) { .cards { grid-template-columns: repeat(2, 1fr); } }
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}
.card .c-num {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
  font-family: var(--font-mono);
  line-height: 1.2;
}
.card .c-num.accent { color: var(--accent); }
.card .c-num.success { color: var(--success); }
.card .c-num.warning { color: var(--warning); }
.card .c-label {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ── Panels ── */
.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
@media (max-width: 900px) { .panel-grid { grid-template-columns: 1fr; } }
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.panel h3 {
  font-size: var(--fs-sm);
  color: var(--text-dim);
  margin-bottom: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ── Bar Chart ── */
.bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.bar-label {
  width: 80px; text-align: right; font-size: var(--fs-xs);
  color: var(--text-body); flex-shrink: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bar-track {
  flex: 1; background: var(--bg-input);
  border-radius: 3px; height: 14px; overflow: hidden;
}
.bar-fill {
  height: 100%; border-radius: 3px;
  min-width: 2px; transition: width 0.6s ease;
}
.bar-fill.c1 { background: var(--accent); opacity: 0.8; }
.bar-fill.c2 { background: var(--success); opacity: 0.8; }
.bar-fill.c3 { background: var(--warning); opacity: 0.8; }
.bar-fill.c4 { background: var(--text-dim); }
.bar-fill.c5 { background: var(--danger); opacity: 0.8; }
.bar-count {
  width: 32px; font-size: var(--fs-xs);
  color: var(--text-dim); font-family: var(--font-mono); flex-shrink: 0;
}

/* ── Pie Chart ── */
.pie-wrap { display: flex; align-items: center; gap: 16px; }
.pie { width: 80px; height: 80px; border-radius: 50%; flex-shrink: 0; }
.pie-legend { font-size: var(--fs-xs); }
.pie-legend .pl { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.pie-legend .swatch { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }

/* ── Table ── */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
th {
  text-align: left; color: var(--text-dim);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  color: var(--text-body);
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--fs-xs);
}
tr:hover td { background: rgba(255,255,255,0.02); }
.key-cell {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  cursor: pointer;
  transition: var(--transition);
}
.key-cell:hover { color: var(--text-primary); }
.key-cell.copied { color: var(--success); }

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-xs);
  font-weight: 500;
  border: 1px solid transparent;
}
.status-badge.valid { background: var(--success-bg); color: var(--success); border-color: rgba(48,209,88,0.2); }
.status-badge.invalid { background: var(--danger-bg); color: var(--danger); border-color: rgba(255,69,58,0.2); }
.status-badge.found { background: var(--warning-bg); color: var(--warning); border-color: rgba(255,159,10,0.2); }
.status-badge.error { background: rgba(255,255,255,0.05); color: var(--text-dim); }
.status-badge.quota_exceeded { background: var(--warning-bg); color: var(--warning); border-color: rgba(255,159,10,0.2); }
.status-badge.skipped { background: rgba(255,255,255,0.03); color: var(--text-dim); }
.status-badge.cached { background: rgba(255,255,255,0.05); color: var(--text-dim); }
.status-badge.l1 { background: rgba(255,255,255,0.03); color: var(--text-dim); }

/* ── Filters ── */
.filters {
  display: flex; gap: 8px; margin-bottom: 14px;
  flex-wrap: wrap; align-items: center;
}
.filters select, .filters input {
  padding: 6px 10px; background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-body);
  font-size: var(--fs-xs); font-family: var(--font-mono);
  outline: none; transition: var(--transition);
}
.filters select:focus, .filters input:focus { border-color: var(--accent); }
.filters input[type=text] { width: 180px; }

/* ── Pagination ── */
.pager {
  display: flex; gap: 4px; align-items: center;
  margin-top: 12px; font-size: var(--fs-xs);
  font-family: var(--font-mono);
}
.pager button {
  padding: 5px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  transition: var(--transition);
  font-size: var(--fs-xs);
}
.pager button:hover { border-color: var(--accent); color: var(--text-primary); }
.pager button:disabled { opacity: 0.3; cursor: default; }
.pager .cur {
  padding: 5px 12px;
  background: rgba(255,255,255,0.06);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  font-weight: 600;
}

/* ── Logs ── */
.log-wrap {
  background: var(--bg-root);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  height: 380px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  line-height: 1.7;
}
.log-entry { display: flex; gap: 8px; }
.log-entry .lt { color: var(--text-muted); flex-shrink: 0; width: 42px; font-size: var(--fs-xs); }
.log-entry .lm { color: var(--text-body); word-break: break-all; }
.log-entry.warn .lm { color: var(--warning); }
.log-entry.err .lm { color: var(--danger); }

/* ── Settings ── */
.set-group { margin-bottom: 20px; }
.set-group h3 {
  font-size: var(--fs-sm);
  color: var(--accent);
  margin-bottom: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.set-row {
  display: flex; gap: 12px;
  margin-bottom: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.set-row label {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  min-width: 110px;
  flex-shrink: 0;
}
.set-row input, .set-row select {
  padding: 6px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-body);
  font-size: var(--fs-xs);
  font-family: var(--font-mono);
  width: 130px;
  outline: none;
  transition: var(--transition);
}
.set-row input:focus, .set-row select:focus { border-color: var(--accent); }
.set-row input[type=text] { width: 260px; }
.set-row .hint { font-size: var(--fs-xs); color: var(--text-dim); }
.set-saved { color: var(--success); font-size: var(--fs-xs); margin-left: 10px; display: none; }

/* ── Buttons — test.150420.xyz 风格：浅灰底+深色字, 无蓝色 ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 7px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--fs-xs);
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  font-family: var(--font-mono);
  line-height: 1.25;
  background: transparent;
  color: var(--text-body);
}
.btn:hover { border-color: var(--accent); color: var(--text-primary); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* 次要按钮 */
.btn-gray {
  background: transparent;
  color: var(--text-dim);
  border-color: var(--border);
}
.btn-gray:hover { border-color: var(--accent); color: var(--text-primary); }

/* 主要操作按钮 — 浅灰背景+深色文字（test.150420.xyz 风格） */
.btn-primary, .btn-cyan {
  background: var(--accent);
  color: var(--bg-root);
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover, .btn-cyan:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: var(--bg-root);
}

/* 危险操作 */
.btn-danger, .btn-red {
  border-color: var(--danger);
  color: var(--danger);
}
.btn-danger:hover, .btn-red:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

/* 小按钮 */
.btn-sm {
  padding: 4px 10px;
  font-size: var(--fs-xs);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
}
.btn-sm:hover { border-color: var(--accent); color: var(--text-primary); }
.btn-sm.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-sm.btn-danger:hover { background: var(--danger); color: #fff; }

.bar { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }

/* ── Token list ── */
.token-card {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: var(--bg-body);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px; font-size: var(--fs-xs);
  font-family: var(--font-mono);
}

/* ── Query management ── */
.query-table td select {
  padding: 3px 6px; background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-body);
  font-size: var(--fs-xs);
  font-family: var(--font-mono);
}

/* ═══════════════════════════════════════════════════════════════
   Page visibility
   ═══════════════════════════════════════════════════════════════ */
.page-view { display: none; }
.page-view.active { display: block; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.06); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.12); }

/* ── Pulse ── */
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
.pulse { animation: pulse 2s infinite; }

/* ── Toast ── */
.toast {
  position: fixed; top: 20px; right: 20px; z-index: 999;
  padding: 8px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-body);
  font-size: var(--fs-xs);
  transform: translateX(120%);
  transition: transform 0.25s ease;
}
.toast.show { transform: translateX(0); }

/* ═══════════════════════════════════════════════════════════════
   响应式：平板 / 手机
   断点：
     ≤1024px  平板微调（面板留白收紧、表格可横滑）
     ≤860px   侧边栏变为顶部横向导航条
     ≤480px   手机（单/双列、控件全宽、字号收紧）
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
  .app { max-width: 100%; }
  .main { padding: 16px; }
  .panel { padding: 16px; }
  /* 多列表格在窄屏下横向滚动，不挤压列 */
  .tbl-wrap[data-scroll] table { min-width: 720px; }
}

@media (max-width: 860px) {
  body { align-items: stretch; }

  /* ── 侧边栏 → 顶部横向导航条 ── */
  .app { flex-direction: column; }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 50;
    width: 100%;
    min-width: 0;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    padding: 8px 10px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }
  .side-logo {
    padding: 4px 10px 4px 4px;
    border-bottom: none;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .side-logo h2 { font-size: var(--fs-body); white-space: nowrap; }
  .side-logo .ver { display: none; }
  .nav-item {
    flex-shrink: 0;
    white-space: nowrap;
    padding: 7px 10px;
    border-left: none;
    border-radius: var(--radius-sm);
    font-size: var(--fs-xs);
  }
  .nav-item.active {
    border-left: none;
    background: rgba(255,255,255,0.08);
    color: var(--text-primary);
  }
  .nav-item[style] { margin-top: 0 !important; border-top: none !important; padding-top: 7px !important; }
  .side-status {
    display: flex;
    margin-top: 0;
    padding: 0 8px;
    border-top: none;
    flex-shrink: 0;
    white-space: nowrap;
  }

  .main { padding: 12px; }
  .page-header { margin-bottom: 14px; }

  /* 登录卡片自适应 */
  .login-card {
    width: auto;
    max-width: 420px;
    margin: 16px;
    padding: 24px;
  }
}

@media (max-width: 600px) {
  .cards { grid-template-columns: 1fr 1fr; gap: 8px; }
  .card { padding: 12px 14px; }
  .card .c-num { font-size: 1.25rem; }

  .panel { padding: 14px; }
  .pie-wrap { flex-direction: column; align-items: flex-start; gap: 10px; }

  .filters { gap: 6px; }
  .filters select,
  .filters input,
  .filters input[type=date] { width: 100% !important; flex: 1 1 auto; min-width: 110px; margin-left: 0 !important; }
  .filters #f-date-from,
  .filters #f-date-to { width: auto !important; flex: 1 1 calc(50% - 12px); }

  .set-row { gap: 8px; }
  .set-row label { width: 100%; min-width: 0; }
  .set-row input,
  .set-row select,
  .set-row input[type=text],
  .set-row input[type=number] { width: 100% !important; margin-left: 0 !important; }
  .bar { gap: 4px; }
  .btn { padding: 8px 12px; }

  .token-card { flex-direction: column; align-items: flex-start; gap: 6px; }
  .pager { flex-wrap: wrap; }
  .log-wrap { height: 300px; }
  .toast { left: 12px; right: 12px; transform: translateY(-150%); text-align: center; }
  .toast.show { transform: translateY(0); }
}

@media (max-width: 380px) {
  .cards { grid-template-columns: 1fr; }
  .sidebar { padding: 6px; }
  .nav-item { padding: 7px 8px; }
}
