:root {
  --primary: #1d6fe0;
  --primary-dark: #1756b3;
  --primary-light: #e8f1fd;
  --bg: #f2f4f8;
  --card: #ffffff;
  --text: #1a2233;
  --text-2: #6b7486;
  --border: #e3e7ee;
  --danger: #d9484d;
  --danger-light: #fdecec;
  --ok: #1a9e63;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 30, 60, .08), 0 4px 14px rgba(20, 30, 60, .06);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  line-height: 1.5;
}

.hidden { display: none !important; }

input, select, button {
  font: inherit;
  color: inherit;
}

/* ---------- 登录页 ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #1d6fe0 0%, #3b8df0 55%, #f2f4f8 55.5%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-logo {
  font-size: 26px;
  font-weight: 700;
  text-align: center;
  color: var(--primary);
}

.login-sub {
  text-align: center;
  color: var(--text-2);
  font-size: 13px;
  margin-bottom: 6px;
}

.error-text { color: var(--danger); font-size: 13px; text-align: center; }

/* ---------- 顶栏 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand { font-size: 18px; font-weight: 700; color: var(--primary); white-space: nowrap; }

.top-nav { display: flex; gap: 4px; flex: 1; }

.top-nav .nav-btn {
  background: none;
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  color: var(--text-2);
  font-weight: 500;
  cursor: pointer;
}

.top-nav .nav-btn.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }

.top-user { color: var(--text-2); font-size: 13px; white-space: nowrap; }

/* ---------- 主内容 ---------- */

.view {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 96px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

.card-title { font-size: 15px; font-weight: 600; margin-bottom: 12px; }

/* ---------- 首页 ---------- */

.stats-row { display: flex; gap: 10px; }

.stat-box {
  flex: 1;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 10px;
  text-align: center;
}

.stat-num { font-size: 24px; font-weight: 700; color: var(--primary); }

.stat-label { font-size: 12px; color: var(--text-2); margin-top: 2px; }

.search-row {
  display: flex;
  gap: 8px;
  margin: 14px 0;
}

.search-row input {
  flex: 1;
  min-width: 0;
}

.search-row select { width: 128px; }

/* ---------- 组合筛选（条件行动态添加） ---------- */

.filter-card { padding: 12px 14px; }

.filter-card #search-input { width: 100%; }

.cond-rows { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

.cond-row { display: flex; align-items: center; gap: 8px; }

.cond-row select,
.cond-row input {
  flex: 1;
  min-width: 0;
  padding: 9px 10px;
  font-size: 14px;
}

.cond-del {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border: none;
  background: var(--danger-light);
  color: var(--danger);
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}

.cond-add {
  margin-top: 10px;
  width: 100%;
  border-style: dashed;
}

.cond-hint { font-size: 12px; color: var(--text-2); margin-top: 8px; }

.home-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}

.result-count { font-size: 13px; color: var(--text-2); }

/* ---------- 应用页：查询/勾选 ---------- */

.query-tabs {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.query-tabs button {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 10px;
  padding: 10px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
}

.query-tabs button.on {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.mode-hint {
  background: #f0f6ff;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  color: #33527a;
  margin-bottom: 10px;
}

.check-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.check-toolbar #check-count { flex: 1; font-size: 13px; color: var(--text-2); }

.check-list { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; }

.check-item {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
}

.check-item.on { border-color: var(--primary); background: var(--primary-light); }

.check-item input { width: 20px; height: 20px; flex-shrink: 0; }

.check-info { display: flex; flex-direction: column; min-width: 0; }

.check-info b { font-size: 15px; }

.check-fields { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.app-row-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
}

input, select {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  background: var(--card);
  outline: none;
  font-size: 15px;
}

input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29, 111, 224, .12); }

.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  background: var(--card);
  color: var(--primary);
  border: 1px solid var(--border);
  transition: opacity .15s;
}

.btn:active { opacity: .7; }

.btn-primary { background: var(--primary); color: #fff; border: none; }

.btn-danger { background: var(--danger-light); color: var(--danger); border: none; }

.btn-block { width: 100%; }

.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }

.record-list { display: flex; flex-direction: column; gap: 10px; }

.record-row {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 13px 14px;
  cursor: pointer;
}

.record-row:active { background: #f6f9ff; }

.record-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.record-phone { font-size: 17px; font-weight: 700; letter-spacing: .5px; }

.record-time { font-size: 11px; color: var(--text-2); white-space: nowrap; }

.record-fields { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 6px; font-size: 13px; color: var(--text-2); }

.record-fields b { color: var(--text); font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.chip {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 500;
}

.chip-empty { color: var(--text-2); font-size: 12px; }

.record-note {
  margin-top: 8px;
  background: #fff8e6;
  border: 1px solid #f3dc9a;
  border-left: 3px solid #e8b54a;
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  color: #7a5a10;
}

.app-note-group {
  margin-top: 12px;
  border-top: 1px dashed var(--border);
  padding-top: 12px;
}

.app-note-group label { font-weight: 600; color: var(--text); }

.empty-tip { text-align: center; color: var(--text-2); padding: 40px 0; font-size: 14px; }

.add-btn {
  position: fixed;
  right: 18px;
  bottom: 84px;
  z-index: 15;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 30px;
  line-height: 1;
  box-shadow: 0 6px 18px rgba(29, 111, 224, .4);
  cursor: pointer;
}

.add-btn:active { transform: scale(.94); }

/* ---------- 应用页 / 管理页 ---------- */

.section-block { margin-bottom: 18px; }

.app-select-row { display: flex; gap: 8px; align-items: center; }

.app-select-row select { flex: 1; }

.app-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}

.app-item:last-child { border-bottom: none; }

.app-item .name { flex: 1; font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.app-item .cnt { color: var(--text-2); font-size: 12px; white-space: nowrap; }

.add-row { display: flex; gap: 8px; }

.add-row input { flex: 1; min-width: 0; }

.field-item { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--border); }

.field-item:last-child { border-bottom: none; }

.field-item .name { flex: 1; font-weight: 600; font-size: 15px; }

.field-item .tag { font-size: 11px; color: var(--text-2); border: 1px solid var(--border); border-radius: 6px; padding: 1px 7px; }

.form-group { margin-bottom: 14px; }

.form-group label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }

.form-group input { width: 100%; }

.form-actions { display: flex; gap: 10px; margin-top: 18px; }

.form-actions .btn { flex: 1; }

.inline-edit { display: flex; gap: 8px; flex: 1; }

.inline-edit input { flex: 1; min-width: 0; padding: 7px 10px; font-size: 14px; }

.warn-banner {
  background: #fff7e6;
  border: 1px solid #f5d28a;
  color: #8a5a00;
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: 13px;
  margin-bottom: 14px;
}

.import-result { margin-top: 12px; }

.import-summary {
  background: var(--primary-light);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.8;
}

.import-errors {
  margin-top: 10px;
  background: var(--danger-light);
  color: var(--danger);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  max-height: 180px;
  overflow-y: auto;
  line-height: 1.7;
}

/* ---------- 弹窗 ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 16, 30, .45);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal {
  background: var(--card);
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  animation: slideup .22s ease-out;
}

@keyframes slideup {
  from { transform: translateY(40px); opacity: .6; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 8px;
}

.modal-head h3 { font-size: 17px; }

.modal-close {
  border: none;
  background: none;
  font-size: 26px;
  color: var(--text-2);
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}

.modal-body { padding: 8px 18px 20px; overflow-y: auto; }

.app-picker { display: flex; flex-wrap: wrap; gap: 8px; }

.app-pick {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
}

.app-pick.on { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 110px;
  transform: translateX(-50%);
  background: rgba(26, 34, 51, .92);
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 99;
  max-width: 86vw;
  text-align: center;
  animation: fadein .2s;
}

@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ---------- 桌面端 ---------- */

@media (min-width: 768px) {
  .bottom-nav { display: none; }

  .modal-backdrop { align-items: center; padding: 20px; }

  .modal { border-radius: 16px; max-height: 86vh; animation: fadein .18s; }

  .add-btn { position: static; width: auto; height: auto; border-radius: 10px; font-size: 15px; font-weight: 600; padding: 11px 20px; box-shadow: none; display: inline-block; }

  .view { padding-bottom: 32px; }

  .record-phone { font-size: 15px; }

  .stats-row { max-width: 480px; }
}

/* ---------- 手机端底部导航 ---------- */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav .nav-btn {
  flex: 1;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 0 7px;
  font-size: 11px;
  color: var(--text-2);
  cursor: pointer;
}

.bottom-nav .nav-btn.active { color: var(--primary); font-weight: 600; }

@media (max-width: 767px) {
  .top-nav { display: none; }
  .top-user { display: none; }
  .login-wrap { padding: 16px; }
}
