:root {
  --bg: #f6f6f5;
  --surface: #ffffff;
  --line: #e5e4e1;
  --line-strong: #d3d1c7;
  --text: #1f1f1e;
  --text-2: #5f5e5a;
  --text-3: #8a8983;
  --accent: #1f1f1e;
  --green-bg: #eaf3de;
  --green-fg: #3b6d11;
  --amber-bg: #faeeda;
  --amber-fg: #854f0b;
  --red-bg: #fcebeb;
  --red-fg: #a32d2d;
  --radius: 8px;
}

* { box-sizing: border-box; }

/* 关键修复：hidden 属性必须能隐藏元素。
   否则下面 .modal 的 display:flex、.dup-tip 的 display:block 会把 hidden 覆盖掉，
   导致弹窗永远显示、页面无法交互。 */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 32px 28px;
}
.login-title { font-size: 19px; font-weight: 600; text-align: center; }
.login-sub { font-size: 13px; color: var(--text-2); text-align: center; margin: 6px 0 24px; }
.login-error {
  background: var(--red-bg);
  color: var(--red-fg);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 12px;
}
.demo-hint {
  margin-top: 20px;
  padding: 12px;
  background: var(--amber-bg);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--amber-fg);
  line-height: 1.7;
}
.demo-hint-title { font-weight: 600; margin-bottom: 4px; }
.demo-hint code { font-size: 12px; word-break: break-all; }
.muted { color: var(--text-3); }

/* ---------- 布局 ---------- */
.app { max-width: 1240px; margin: 0 auto; padding: 0 20px 60px; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 0 14px;
  gap: 12px;
  flex-wrap: wrap;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 17px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--text-2); }
.me-label { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--amber-bg);
  color: var(--amber-fg);
}
.notice {
  background: #e6f1fb;
  color: #0c447c;
  border-radius: var(--radius);
  padding: 8px 14px;
  font-size: 13px;
  margin-bottom: 12px;
}

/* ---------- 工具栏 ---------- */
.toolbar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}
.toolbar-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toolbar-row + .toolbar-row { margin-top: 10px; }
.toolbar-row:first-child #searchInput { flex: 1; min-width: 200px; }
.count { margin-left: auto; font-size: 13px; color: var(--text-2); }

/* ---------- 表单控件 ---------- */
.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.field-label em { color: #c0392b; font-style: normal; }
.input {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
.input:focus { outline: none; border-color: var(--text-2); }
.input-sm { width: auto; min-width: 130px; }
textarea.input { resize: vertical; }
.input.dup-hit { border-color: #e24b4a; background: #fdf6f6; }
.dup-tip {
  display: block;
  margin-top: 5px;
  font-size: 12px;
  color: var(--red-fg);
}
.field-hint {
  display: block;
  margin-top: 5px;
  font-size: 12px;
  color: var(--text-3);
}

/* ---------- 按钮 ---------- */
.btn {
  padding: 8px 15px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.btn:hover { border-color: var(--text-3); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #000; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); padding: 6px 8px; }
.btn-ghost:hover { color: var(--text); text-decoration: underline; }
.btn-sm { padding: 5px 11px; font-size: 13px; }
.btn-block { width: 100%; margin-top: 4px; }
.btn-danger { background: #a32d2d; border-color: #a32d2d; color: #fff; }
.btn-danger:hover { background: #8b2626; }
.btn-danger-ghost { color: var(--red-fg); border-color: #e8b4b4; }
.btn-danger-ghost:hover { background: var(--red-bg); }

/* ---------- 表格 ---------- */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow-x: auto;
}
.grid { width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap; }
.grid th, .grid td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.grid th {
  background: #fafaf9;
  font-weight: 600;
  color: var(--text-2);
  position: sticky;
  top: 0;
  user-select: none;
}
.grid th.sortable { cursor: pointer; }
.grid th i {
  display: inline-block;
  width: 0; height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 5px solid var(--line-strong);
  margin-left: 4px;
  vertical-align: middle;
}
.grid th.asc i { border-bottom: 5px solid var(--text); }
.grid th.desc i { border-bottom: none; border-top: 5px solid var(--text); }
.grid tbody tr:hover { background: #fafaf9; }
.grid td.remark-cell { white-space: normal; min-width: 160px; max-width: 320px; color: var(--text-2); }
.col-ops { text-align: right; }
.ops { display: flex; gap: 6px; justify-content: flex-end; }
.link-btn {
  background: none; border: none; padding: 2px 4px;
  color: var(--text-2); font-size: 13px; cursor: pointer; font-family: inherit;
}
.link-btn:hover { color: var(--text); text-decoration: underline; }
.link-btn.danger:hover { color: var(--red-fg); }
.tag {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
}
.tag-done { background: var(--green-bg); color: var(--green-fg); }
.tag-wait { background: var(--amber-bg); color: var(--amber-fg); }
.mono { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; }
.empty { padding: 48px 20px; text-align: center; color: var(--text-3); font-size: 13px; }

/* ---------- 分页 ---------- */
.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 2px;
  font-size: 13px;
  color: var(--text-2);
  flex-wrap: wrap;
}
.page-label { min-width: 60px; text-align: center; }

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-mask { position: absolute; inset: 0; background: rgba(20, 20, 19, 0.45); }
.modal-box {
  position: relative;
  width: 100%;
  max-width: 440px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.16);
}
.modal-box-wide { max-width: 620px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
  font-size: 15px; font-weight: 600;
}
.modal-head-warn { color: var(--red-fg); background: var(--red-bg); border-radius: 12px 12px 0 0; }
.modal-x { background: none; border: none; font-size: 22px; line-height: 1; color: var(--text-3); cursor: pointer; }
.modal-body { padding: 18px 20px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--line);
}
.form-error {
  background: var(--red-bg); color: var(--red-fg);
  padding: 8px 12px; border-radius: var(--radius); font-size: 13px;
}
.dup-lead { margin: 0 0 8px; font-size: 13px; color: var(--text-2); }
.dup-fields { margin-bottom: 18px; display: flex; flex-wrap: wrap; gap: 8px; }
.dup-chip {
  font-size: 13px; padding: 4px 10px; border-radius: var(--radius);
  background: var(--red-bg); color: var(--red-fg);
}
.dup-records {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.dup-row {
  display: flex; gap: 8px; padding: 8px 12px; font-size: 13px;
  border-bottom: 1px solid var(--line);
}
.dup-row:last-child { border-bottom: none; }
.dup-row .k { color: var(--text-3); min-width: 62px; flex-shrink: 0; }
.dup-row .v { color: var(--text); word-break: break-all; }
.dup-record + .dup-record { border-top: 1px solid var(--line-strong); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%; bottom: 40px;
  transform: translateX(-50%);
  background: #1f1f1e; color: #fff;
  padding: 9px 18px; border-radius: var(--radius);
  font-size: 13px; z-index: 90;
}

/* ---------- 移动端 ---------- */
@media (max-width: 640px) {
  .app { padding: 0 12px 40px; }
  .toolbar-row { flex-direction: column; align-items: stretch; }
  .toolbar-row #searchInput,
  .toolbar-row .input-sm { width: 100%; }
  .toolbar-row .btn { width: 100%; }
  .count { margin-left: 0; text-align: center; }
  .topbar { padding: 14px 0 10px; }
  .grid th, .grid td { padding: 9px 10px; }
}
