/* ============ 设计令牌（参考 dataviz 校验过的默认色板） ============ */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #ffffff;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-weak: #cde2fb;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --on-accent: #ffffff;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 14px rgba(11, 11, 11, 0.05);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #20201f;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-weak: #184f95;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #20201f;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-weak: #184f95;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

/* ============ 基础 ============ */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--page);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; }
input, select, textarea {
  font-family: inherit;
  font-size: 15px;
  color: var(--text-primary);
  background: var(--surface-2);
  border: 1px solid var(--baseline);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}
textarea { resize: vertical; min-height: 130px; line-height: 1.6; }
.excel-row { display: flex; gap: 10px; align-items: center; margin-top: 6px; }
.excel-row input[type="file"] { flex: 1; padding: 8px; }
.excel-row .btn { flex-shrink: 0; }
input:focus { outline: none; border-color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }

/* ============ 顶栏 ============ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--gridline);
}
.brand { font-weight: 650; font-size: 17px; letter-spacing: 0.2px; }
.user { display: flex; align-items: center; gap: 10px; color: var(--text-secondary); font-size: 13px; }
.user .uname { font-weight: 600; color: var(--text-primary); }
.user a { font-weight: 600; }
.demo-badge {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--on-accent);
  background: var(--warning);
  border-radius: 999px;
  padding: 2px 9px;
}

/* ============ 布局 ============ */
.container {
  max-width: 680px;
  margin: 0 auto;
  padding: 14px 16px calc(env(safe-area-inset-bottom, 0px) + 28px);
}

/* ============ 选项卡 ============ */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--gridline);
  border-radius: 12px;
  padding: 4px;
}
.tab {
  flex: 1;
  padding: 9px 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.tab.is-active { background: var(--accent); color: var(--on-accent); }

/* ============ 卡片 ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ============ 主指标（达成率） ============ */
.hero { padding: 20px; margin-top: 12px; }
.hero-label { font-size: 13px; color: var(--text-secondary); }
.hero-value {
  font-size: 46px;
  font-weight: 650;
  line-height: 1.05;
  margin: 6px 0 14px;
  letter-spacing: -0.02em;
}
.meter {
  height: 9px;
  background: var(--gridline);
  border-radius: 999px;
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.5s ease, background 0.3s ease;
}
.hero-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.hero-gap { font-size: 13px; color: var(--text-secondary); }

/* ============ KPI 网格 ============ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 12px;
}
.kpi { padding: 16px; }
.kpi-label { font-size: 13px; color: var(--text-secondary); }
.kpi-value { font-size: 22px; font-weight: 650; margin-top: 6px; letter-spacing: -0.01em; }
@media (min-width: 520px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
}

.updated { text-align: center; font-size: 12px; color: var(--muted); margin-top: 20px; }

/* ============ 水印 ============ */
#watermark {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  pointer-events: none;
  background-repeat: repeat;
  background-position: 0 0;
}

/* ============ 状态 / 加载 / 提示 ============ */
.state {
  margin-top: 20px;
  padding: 40px 20px;
  text-align: center;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px dashed var(--baseline);
  border-radius: var(--radius);
}
.state .icon { font-size: 30px; margin-bottom: 10px; }
.state p { margin: 6px 0; }
.state .strong { color: var(--text-primary); font-weight: 650; }

.unmapped-info {
  margin-top: 16px;
  text-align: left;
  display: inline-block;
  background: var(--surface-2);
  border: 1px solid var(--gridline);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 14px;
}
.unmapped-info div { margin: 4px 0; }
.unmapped-info b { color: var(--text-primary); word-break: break-all; }

.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--gridline);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.dev-login {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
.dev-login input { flex: 1; }
.dev-login button { flex-shrink: 0; }

/* ============ 按钮 ============ */
.btn {
  display: inline-block;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 15px;
  font-weight: 600;
  padding: 11px 18px;
  cursor: pointer;
}
.btn:active { opacity: 0.85; }
.btn.block { width: 100%; }

/* ============ 管理后台 ============ */
.admin-panel { padding: 20px; margin-top: 14px; }
.admin-panel h1 { font-size: 20px; margin: 0 0 12px; }
.admin-panel h2 { font-size: 16px; margin: 4px 0 12px; }
.admin-panel label { display: block; font-size: 13px; color: var(--text-secondary); margin: 10px 0 0; }
.admin-panel label input { margin-top: 6px; }
.hint { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.err { color: var(--critical); font-size: 13px; min-height: 18px; margin: 10px 0 0; }
.ok { color: var(--good); font-size: 13px; min-height: 18px; margin: 10px 0 0; }

.add-form { padding: 16px; margin-top: 14px; }
.add-form .btn { margin-top: 14px; width: 100%; }

.table-card { margin-top: 14px; padding: 8px 0; overflow-x: auto; }
.table-card table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table-card th, .table-card td {
  text-align: left;
  padding: 10px 16px;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}
.table-card th { font-size: 12px; color: var(--muted); font-weight: 600; }
.table-card tr:last-child td { border-bottom: 0; }
.row-actions { display: flex; gap: 12px; }
button.link {
  border: 0; background: none; padding: 0;
  color: var(--accent); font-size: 14px; cursor: pointer;
}
button.link.danger { color: var(--critical); }
