:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1c2430;
  --muted: #6b7686;
  --line: #e4e8ee;
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --green: #16a34a;
  --amber: #b45309;
  --red: #dc2626;
  --night: #7c3aed;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.07), 0 1px 2px rgba(16, 24, 40, 0.05);
  --tabs-bg: #eceff3;
  --btn-hover-bg: #f8fafc;
  --btn-hover-line: #c9d2de;
}

/* ---- 暗色主题（html[data-theme="dark"]） ---- */
html[data-theme="dark"] {
  --bg: #12151c;
  --panel: #1b2029;
  --ink: #e6e9ef;
  --muted: #9aa4b2;
  --line: #2c3440;
  --primary: #3b82f6;
  --primary-ink: #ffffff;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --night: #a78bfa;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
  --tabs-bg: #232a35;
  --btn-hover-bg: #242b36;
  --btn-hover-line: #3d4756;
}

* { box-sizing: border-box; }

/* 键盘导航可见焦点（鼠标点击不显示双圈） */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.55;
}

#app { max-width: 1080px; margin: 0 auto; padding: 0 20px 40px; }

/* ---- 头部与导航 ---- */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px;
  padding: 18px 0 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
}
.brand { display: flex; align-items: center; gap: 9px; }
.logo-img {
  width: 28px; height: 28px; border-radius: 8px;
  box-shadow: var(--shadow); display: block;
}
.title { font-size: 20px; font-weight: 700; letter-spacing: 0.5px; }
.subtitle { font-size: 13px; }

.tabs { display: flex; gap: 4px; background: var(--tabs-bg); padding: 4px; border-radius: 999px; }
.tab {
  padding: 6px 18px; border-radius: 999px; text-decoration: none;
  color: var(--muted); font-weight: 500; transition: all 0.15s;
}
.tab:hover { color: var(--ink); }
.tab.active { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }

/* ---- 布局 ---- */
.page { display: flex; flex-direction: column; gap: 20px; }
.row { display: flex; align-items: flex-start; gap: 10px; }
.row.between { justify-content: space-between; }
.row.center { align-items: center; }
.row.end { justify-content: flex-end; }
.row.gap { gap: 12px; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.sm-text { font-size: 12px; margin: 6px 0 0; }
h2 { font-size: 15px; margin: 0 0 10px; }
h3 { font-size: 16px; margin: 0 0 12px; }

.empty {
  background: var(--panel); border: 1px dashed var(--line);
  border-radius: var(--radius); padding: 40px; text-align: center;
}
.empty p { margin: 4px 0; }

/* ---- 按钮 ---- */
.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 8px; padding: 7px 14px; font-size: 13px; cursor: pointer;
  transition: all 0.12s; white-space: nowrap;
}
.btn:hover { border-color: var(--btn-hover-line); background: var(--btn-hover-bg); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { color: var(--red); border-color: #f3c5c5; }
.btn.danger:hover { background: #fef2f2; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); background: #f1f4f8; }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn.xs { padding: 2px 8px; font-size: 12px; border-radius: 6px; }

/* ---- 预警 ---- */
.alerts {
  background: #fffbeb; border: 1px solid #fde68a;
  border-radius: var(--radius); padding: 14px 16px;
}
.alert-item {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 6px 0; font-size: 13px; color: #92400e;
}
.alert-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--amber); margin-top: 6px; flex-shrink: 0;
}

/* ---- 推荐卡 ---- */
.picks { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 720px) { .picks { grid-template-columns: 1fr; } }
.pick-card {
  background: var(--panel); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
  border-top: 3px solid var(--green);
}
.pick-card.high { border-top-color: var(--night); }
.pick-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.pick-name { font-size: 17px; font-weight: 650; }
.pick-meters { display: flex; flex-direction: column; gap: 6px; }
.value-line { font-size: 12px; color: var(--green); margin: 8px 0 0; }
.loss-line { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.loss-line.risky { color: var(--amber); }

.adjust-row {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line);
}

/* ---- 全部订阅列表 ---- */
.rank-list { display: flex; flex-direction: column; gap: 8px; }
.rank-row {
  background: var(--panel); border-radius: var(--radius);
  padding: 12px 16px; box-shadow: var(--shadow);
  display: grid; grid-template-columns: minmax(180px, 1fr) 2fr; gap: 4px 16px;
}
.rank-row.ineligible { opacity: 0.62; }
.rank-name { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.rank-bars { display: flex; flex-direction: column; gap: 4px; }
.rank-note { grid-column: 1 / -1; font-size: 12px; }

/* ---- 计量条 ---- */
.meter { display: flex; align-items: center; gap: 8px; }
.meter-label { font-size: 12px; width: 74px; flex-shrink: 0; }
.meter-val { font-size: 12px; width: 38px; text-align: right; font-variant-numeric: tabular-nums; }
.bar {
  flex: 1; height: 8px; background: #edf0f4;
  border-radius: 999px; overflow: hidden;
}
.bar-fill { height: 100%; border-radius: 999px; transition: width 0.25s; }
.bar-fill.ok { background: var(--green); }
.bar-fill.warn { background: #f59e0b; }
.bar-fill.danger { background: var(--red); }
.bar-fill.blue.ok { background: var(--primary); }

/* ---- 徽标 ---- */
.badge {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: #eef2f7; color: var(--muted); white-space: nowrap;
}
.badge.high { background: #ede9fe; color: var(--night); }
.badge.low { background: #dcfce7; color: #15803d; }
.badge.on { background: #dcfce7; color: #15803d; }
.badge.off { background: #f1f1f1; color: #5f6b7a; }
.badge.night { background: #ede9fe; color: var(--night); }
.badge.free { background: #e0f2fe; color: #0369a1; }
.badge.api { background: #eef2f7; color: var(--muted); }
.badge.model { background: #f5f3ff; color: #6d28d9; }
.badge.price { background: #ecfdf5; color: #047857; }
.badge.exp { background: #fff7ed; color: #c2410c; }

/* ---- 订阅页 ---- */
.nl-box {
  background: var(--panel); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.nl-input {
  flex: 1; resize: vertical; min-height: 52px;
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font: inherit;
}
.nl-input:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }

.sub-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .sub-grid { grid-template-columns: 1fr; } }
.sub-card {
  background: var(--panel); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 8px;
}
.sub-card.disabled { opacity: 0.6; }
.sub-head { display: flex; align-items: center; gap: 8px; }
.sub-name { font-size: 15px; }
.sub-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.sub-meter { display: flex; align-items: center; gap: 8px; }
.sub-meter .meter { flex: 1; }
.mini-btns { display: flex; gap: 4px; flex-shrink: 0; }
.copy-row { display: flex; gap: 6px; flex-wrap: wrap; padding-top: 6px; border-top: 1px dashed var(--line); }
.sub-actions { display: flex; gap: 6px; margin-top: auto; padding-top: 8px; }

/* ---- 面板（设置页） ---- */
.panel {
  background: var(--panel); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.panel p { margin: 6px 0 12px; }

/* ---- 表单 ---- */
.in {
  width: 100%; border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 10px; font: inherit; background: #fff;
}
.in:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
.field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 140px; }
.field-label { font-size: 12px; color: var(--muted); }
.field-hint { font-size: 11px; }
.field-err { font-size: 12px; color: var(--red); }
.in.invalid { border-color: var(--red); }
.field.check { flex-direction: row; align-items: center; gap: 8px; }
.field.check input { width: auto; }
.form-group {
  border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; display: flex; flex-direction: column; gap: 10px;
}
.sub-form { display: flex; flex-direction: column; gap: 12px; min-width: min(560px, 86vw); }
.form-actions { margin-top: 4px; }

/* ---- 模态框 ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.4);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px; z-index: 100; overflow-y: auto;
}
.modal {
  background: var(--panel); border-radius: 14px;
  padding: 20px 22px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
  max-width: 100%;
}

/* ---- Toast ---- */
#toast {
  position: fixed; bottom: 28px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #111827; color: #fff; font-size: 13px;
  padding: 8px 18px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: all 0.2s; z-index: 200;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.app-footer { text-align: center; font-size: 12px; padding-top: 24px; }
.footer-link { color: var(--muted); text-decoration: none; }
.footer-link:hover { color: var(--primary); }

/* ---- 管理后台 ---- */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat-card {
  background: var(--panel); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); text-align: center;
}
.stat-val { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; margin-top: 2px; }

.adm-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.adm-table th, .adm-table td {
  text-align: left; padding: 8px 10px;
  border-bottom: 1px solid var(--line); vertical-align: middle;
}
.adm-table th { color: var(--muted); font-weight: 500; font-size: 12px; }
.adm-table tr:last-child td { border-bottom: none; }
.adm-table .mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.sm-in { padding: 4px 8px; font-size: 12px; }
.panel { overflow-x: auto; }

/* ---- 暗色主题微调：覆盖亮色硬编码的局部配色 ---- */
html[data-theme="dark"] { color-scheme: dark; }
html[data-theme="dark"] .btn.primary:hover { background: #1e4fd6; }
html[data-theme="dark"] .btn.danger { border-color: #5c2b2b; }
html[data-theme="dark"] .btn.danger:hover { background: #3a2426; }
html[data-theme="dark"] .btn.ghost:hover { background: #232a35; }
html[data-theme="dark"] .alerts { background: #2b2313; border-color: #5b4a1a; }
html[data-theme="dark"] .alert-item { color: #fbbf24; }
html[data-theme="dark"] .bar { background: #2a313d; }
html[data-theme="dark"] .badge { background: #262d38; }
html[data-theme="dark"] .badge.high,
html[data-theme="dark"] .badge.night { background: #2e2650; color: #c4b5fd; }
html[data-theme="dark"] .badge.low,
html[data-theme="dark"] .badge.on { background: #14351f; color: #4ade80; }
html[data-theme="dark"] .badge.off { background: #262d38; color: #9aa3af; }
html[data-theme="dark"] .badge.free { background: #0c2a3f; color: #7dd3fc; }
html[data-theme="dark"] .badge.api { background: #262d38; }
html[data-theme="dark"] .badge.model { background: #2a2340; color: #a78bfa; }
html[data-theme="dark"] .badge.price { background: #0e3126; color: #34d399; }
html[data-theme="dark"] .badge.exp { background: #38230f; color: #fb923c; }
html[data-theme="dark"] .in,
html[data-theme="dark"] .nl-input { background: #232a35; color: var(--ink); }
html[data-theme="dark"] .in:focus,
html[data-theme="dark"] .nl-input:focus { outline-color: #1e3a8a; }
html[data-theme="dark"] .badge.off { color: #c3ccd6; }
html[data-theme="dark"] .in.invalid { border-color: var(--red); }

/* ---- 移动端适配（≤640px：触控目标 ≥44px、网格塌单列、无横向滚动） ---- */
@media (max-width: 640px) {
  #app { padding: 0 12px 32px; }

  /* 头部：品牌行紧凑，导航铺满整行等分 */
  .app-header { padding: 12px 0 10px; margin-bottom: 14px; gap: 8px; }
  .title { font-size: 17px; }
  .subtitle { font-size: 12px; }
  .tabs { width: 100%; }
  .tab {
    flex: 1; text-align: center; padding: 10px 8px;
    display: flex; align-items: center; justify-content: center;
    min-height: 44px;
  }

  /* 触控目标：所有按钮移动端统一 ≥44px 高 */
  .btn { min-height: 44px; padding: 10px 14px; }
  .btn.sm { min-height: 44px; padding: 10px 12px; }
  .btn.xs { min-height: 44px; padding: 10px 12px; font-size: 13px; }
  .mini-btns { gap: 6px; }
  .mini-btns .btn.xs { min-width: 44px; }

  /* 复选框加大触控面积（配合外层 label 点击） */
  .field.check input { width: 20px; height: 20px; }

  /* 仪表盘排名行：双列网格塌单列 */
  .rank-row { grid-template-columns: 1fr; padding: 12px 14px; }
  .rank-row .rank-bars { margin-top: 4px; }

  /* 卡片与间距收紧 */
  .page { gap: 16px; }
  .picks { gap: 12px; }
  .pick-card, .panel, .nl-box { padding: 14px; }
  .adjust-row { gap: 6px; }

  /* 一句话输入行换行：textarea 独占一行 */
  .nl-box .row { flex-direction: column; }
  .nl-box .row .btn { width: 100%; }

  /* 模态框：贴边不留大空白，表单不再强制最小宽 */
  .modal-overlay { padding: 12px; }
  .modal { padding: 16px; width: 100%; }
  .sub-form { min-width: 0; width: 100%; }
  .form-group .row.gap { flex-direction: column; }
}
