/* ============================================================
   马良拆录薪资统计 · v3 设计系统（简约现代 · 浅色默认 · 深色可切）
   ============================================================ */

:root,
:root[data-theme="light"] {
  --bg: #f6f7fa;
  --surface: #ffffff;
  --surface-2: #f4f6f9;
  --border: #e8ebf1;
  --border-strong: #d8dde6;
  --text: #23272f;
  --text-dim: #697180;
  --text-faint: #9aa2b1;
  --primary: #3565f2;
  --primary-hover: #2b56d9;
  --primary-soft: #edf2ff;
  --accent: #0ea5e9;
  --green: #189a52;
  --green-soft: #e8f6ee;
  --amber: #c47512;
  --amber-soft: #fdf4e5;
  --red: #d93843;
  --red-soft: #fdeeee;
  --shadow: 0 6px 24px rgba(23, 35, 61, 0.08);
  --shadow-sm: 0 1px 2px rgba(23, 35, 61, 0.05);
  --tbl-hover: #f6f8fd;
  --focus-ring: rgba(53, 101, 242, 0.18);
}

:root[data-theme="dark"] {
  --bg: #14161b;
  --surface: #1c1f26;
  --surface-2: #24272f;
  --border: #2b2f38;
  --border-strong: #383d49;
  --text: #e6e9ef;
  --text-dim: #9aa2b1;
  --text-faint: #6b7280;
  --primary: #6289f5;
  --primary-hover: #7b9bf7;
  --primary-soft: rgba(98, 137, 245, 0.14);
  --accent: #38bdf8;
  --green: #3fbf7a;
  --green-soft: rgba(63, 191, 122, 0.13);
  --amber: #e0a13f;
  --amber-soft: rgba(224, 161, 63, 0.13);
  --red: #ef6a72;
  --red-soft: rgba(239, 106, 114, 0.12);
  --shadow: 0 8px 26px rgba(0, 0, 0, 0.32);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.25);
  --tbl-hover: rgba(98, 137, 245, 0.07);
  --focus-ring: rgba(98, 137, 245, 0.25);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--primary-soft); }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background-color: var(--text-faint); }

/* ============ 布局 ============ */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 216px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 16px 10px 12px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.logo { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; }
.logo-icon {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  font-size: 19px;
  border-radius: 10px;
  background: var(--primary-soft);
}
.logo b { font-size: 14.5px; display: block; line-height: 1.3; }
.logo small { color: var(--text-dim); font-size: 11.5px; }

.nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 9px;
  color: var(--text-dim);
  cursor: pointer;
  border: none;
  background: none;
  font-size: 13.5px;
  text-align: left;
  width: 100%;
  font-family: inherit;
  transition: background 0.14s, color 0.14s;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.user-chip {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-dim);
  padding: 4px 8px;
  white-space: nowrap;
  overflow: hidden;
}
.user-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); flex-shrink: 0; }

.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.14s;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-2); }
.icon-btn svg { width: 15px; height: 15px; }

.main { flex: 1; min-width: 0; padding: 22px 26px 64px; }
/* 宽屏下内容居中，不再整体偏左留出右侧大空白 */
.main > * { max-width: 1360px; margin-left: auto; margin-right: auto; }

.page { animation: pageIn 0.22s ease both; }
@keyframes pageIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.page-head h1 { margin: 0; font-size: 19px; }
.page-head .sub { color: var(--text-dim); font-size: 12.5px; margin-top: 3px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ============ 卡片 ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.card-title {
  font-size: 13.5px;
  font-weight: 600;
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.card-title .hint { font-weight: 400; font-size: 12px; color: var(--text-dim); }

.grid { display: grid; gap: 12px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: 3fr 2fr; }
@media (max-width: 1180px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }
@media (max-width: 560px) { .grid-4 { grid-template-columns: 1fr; } }

/* 统计卡 */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 15px 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.16s, transform 0.16s;
}
.stat-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.stat-card .s-label {
  color: var(--text-dim);
  font-size: 12.5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.s-icon {
  width: 30px; height: 30px;
  border-radius: 8px;
  display: grid; place-items: center;
  font-size: 14px;
  background: var(--primary-soft);
  flex-shrink: 0;
}
.s-icon.green { background: var(--green-soft); }
.s-icon.amber { background: var(--amber-soft); }
.stat-card .s-value {
  font-size: 24px;
  font-weight: 700;
  margin-top: 7px;
  font-variant-numeric: tabular-nums;
}
.stat-card .s-sub { color: var(--text-dim); font-size: 12px; margin-top: 3px; }
.stat-card .s-sub b { color: var(--text); }

/* 紧凑统计条（汇总页） */
.stat-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
}
.stat-strip .item {
  flex: 1;
  min-width: 130px;
  padding: 4px 18px;
  border-left: 1px solid var(--border);
}
.stat-strip .item:first-child { border-left: none; padding-left: 2px; }
.stat-strip .k { color: var(--text-dim); font-size: 12px; }
.stat-strip .v { font-size: 19px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
@media (max-width: 720px) {
  .stat-strip .item { min-width: 40%; border-left: none; padding: 6px 2px; }
}

/* ============ 按钮 ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: 9px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: all 0.14s;
  position: relative;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-faint); }
.btn svg { width: 14px; height: 14px; }

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn.danger { color: var(--red); border-color: var(--red-soft); background: var(--red-soft); }
.btn.danger:hover { border-color: var(--red); }

.btn.sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn.loading { color: transparent !important; pointer-events: none; }
.btn.loading::after {
  content: "";
  position: absolute;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}
.btn.loading:not(.primary)::after { border-color: var(--border-strong); border-top-color: var(--text-dim); }
@keyframes spin { to { transform: rotate(360deg); } }

.btn-mini {
  border: none;
  background: none;
  color: var(--primary);
  font-size: 12.5px;
  cursor: pointer;
  padding: 3px 7px;
  border-radius: 6px;
  font-family: inherit;
}
.btn-mini:hover { background: var(--primary-soft); }
.btn-mini.danger { color: var(--red); }
.btn-mini.danger:hover { background: var(--red-soft); }

/* 下拉菜单 */
.menu-wrap { position: relative; display: inline-flex; }
.menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 190px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 5px;
  z-index: 60;
  animation: menuIn 0.14s ease;
}
@keyframes menuIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}
.menu button {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 8px;
  border: none;
  background: none;
  color: var(--text);
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
}
.menu button:hover { background: var(--surface-2); }
.menu button.danger { color: var(--red); }
.menu .menu-divider { height: 1px; background: var(--border); margin: 4px 6px; }

/* ============ 表单 ============ */
.input, .select {
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  padding: 8px 11px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.14s, box-shadow 0.14s;
  outline: none;
}
.input:focus, .select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus-ring); }
.input::placeholder { color: var(--text-faint); }
:root[data-theme="dark"] input[type="date"].input { color-scheme: dark; }

.field-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.search-box { position: relative; }
.search-box .input { padding-left: 30px; width: 200px; max-width: 100%; }
.search-box::before {
  content: "";
  position: absolute;
  left: 10px; top: 50%;
  width: 13px; height: 13px;
  transform: translateY(-50%);
  background: var(--text-faint);
  -webkit-mask: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2.4"><circle cx="11" cy="11" r="7"/><path d="M21 21l-4.3-4.3"/></svg>') center/contain no-repeat;
  mask: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2.4"><circle cx="11" cy="11" r="7"/><path d="M21 21l-4.3-4.3"/></svg>') center/contain no-repeat;
}

.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12.5px;
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.14s;
}
.chip:hover { color: var(--text); border-color: var(--text-faint); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip .cnt { opacity: 0.72; margin-left: 3px; font-size: 11px; }

/* ============ 表格 ============ */
.tbl-wrap { overflow: auto; border-radius: 9px; max-height: 68vh; }

.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  position: sticky;
  top: 0;
  z-index: 2;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface);
  padding: 9px 11px;
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
  user-select: none;
}
.tbl th.sortable { cursor: pointer; }
.tbl th.sortable:hover { color: var(--text); }
.tbl th .arrow { font-size: 9px; margin-left: 3px; color: var(--primary); }
.tbl td { padding: 8px 11px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl tbody tr { transition: background 0.1s; }
.tbl tbody tr:hover { background: var(--tbl-hover); }
.tbl tr.warn { background: var(--amber-soft); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl th.num { text-align: right; }
.tbl .ref { color: var(--text-faint); }
.tbl .money { color: var(--green); font-weight: 600; }
.tbl tfoot td {
  font-weight: 700;
  background: var(--surface);
  border-top: 1px solid var(--border-strong);
  border-bottom: none;
  position: sticky;
  bottom: 0;
}
.tbl .input, .tbl .select { padding: 4px 8px; border-radius: 7px; font-size: 12.5px; }
.tbl input.input { width: 140px; }

/* 响应式列优先级：col-lo 最先隐藏，col-md 其次 */
@media (max-width: 1150px) { .tbl .col-lo { display: none; } }
@media (max-width: 860px) { .tbl .col-md { display: none; } .tbl input.input { width: 100px; } }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.pill::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.pill.paid { color: var(--green); background: var(--green-soft); }
.pill.unpaid { color: var(--amber); background: var(--amber-soft); }

select.select.status-paid { color: var(--green); font-weight: 600; }
.paid-time { font-size: 11px; color: var(--text-faint); margin-top: 2px; }

.missing-tag { color: var(--amber); font-size: 12.5px; }

.bar { height: 6px; border-radius: 4px; background: var(--surface-2); overflow: hidden; min-width: 60px; }
.bar > i { display: block; height: 100%; border-radius: 4px; background: var(--green); transition: width 0.35s ease; }

/* ============ 弹窗 ============ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 30, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.16s ease;
  padding: 20px;
}
@keyframes fadeIn { from { opacity: 0; } }

.dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 22px;
  width: min(420px, 100%);
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  box-shadow: var(--shadow);
  animation: popIn 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}
@keyframes popIn {
  from { opacity: 0; transform: scale(0.96) translateY(6px); }
  to { opacity: 1; transform: none; }
}
.dialog h3 { margin: 0 0 5px; font-size: 15.5px; }
.dialog .dialog-desc { color: var(--text-dim); font-size: 13px; margin: 0 0 14px; line-height: 1.7; }
.dialog form label { display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 11px; }
.dialog form input { display: block; width: 100%; margin-top: 4px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 16px; }
.required { color: var(--red); }

/* ============ Toast ============ */
.toast-root {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(340px, calc(100vw - 32px));
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--primary);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toastIn 0.2s ease;
}
.toast.out { animation: toastOut 0.2s ease forwards; }
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
@keyframes toastIn { from { opacity: 0; transform: translateX(24px); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(24px); } }

/* ============ 骨架屏 / 空状态 ============ */
.sk {
  border-radius: 7px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 45%, var(--surface-2) 65%);
  background-size: 220% 100%;
  animation: shimmer 1.1s infinite;
}
@keyframes shimmer { from { background-position: 130% 0; } to { background-position: -90% 0; } }
.sk-line { height: 12px; margin: 12px 0; }

.empty { text-align: center; color: var(--text-dim); padding: 44px 20px; font-size: 13.5px; line-height: 2; }
.empty .e-icon {
  width: 52px; height: 52px;
  margin: 0 auto 10px;
  border-radius: 15px;
  display: grid; place-items: center;
  font-size: 23px;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
}

.muted { color: var(--text-dim); font-size: 12.5px; }
.mono { font-variant-numeric: tabular-nums; }

.summary-line { font-size: 13px; color: var(--text-dim); }
.summary-line strong { color: var(--text); font-size: 14.5px; }
.summary-line .money { color: var(--green); font-weight: 700; }

.tbl-head-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 11px;
}

.eye-btn {
  border: none; background: none;
  cursor: pointer;
  color: var(--text-faint);
  font-size: 13px;
  padding: 2px 5px;
  border-radius: 5px;
}
.eye-btn:hover { color: var(--text); background: var(--surface-2); }

.danger-zone { border-color: var(--red-soft); }
.danger-zone .card-title { color: var(--red); }

/* ============ 登录 / 查询 独立页 ============ */
.center-body { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.center-card {
  width: min(392px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 30px 28px 26px;
  box-shadow: var(--shadow);
  animation: popIn 0.24s cubic-bezier(0.2, 0.9, 0.3, 1.12);
}
.brand-block { text-align: center; margin-bottom: 20px; }
.brand-block .logo-icon { width: 48px; height: 48px; font-size: 24px; border-radius: 14px; margin: 0 auto 10px; }
.brand-block h1 { margin: 0; font-size: 18px; }
.brand-block p { margin: 4px 0 0; color: var(--text-dim); font-size: 12.5px; }

.stack-form { display: flex; flex-direction: column; gap: 11px; }
.stack-form .input { width: 100%; padding: 10px 12px; }
.stack-form .btn.primary { width: 100%; padding: 10px; font-size: 13.5px; }
.form-err { color: var(--red); font-size: 12.5px; min-height: 17px; margin: 0; }
.foot-note { text-align: center; color: var(--text-faint); font-size: 12px; margin-top: 16px; }
.foot-note a { color: var(--primary); text-decoration: none; }

/* ============ 查询页（手机端优先） ============ */
.query-body { max-width: 620px; margin: 0 auto; padding: 26px 16px 60px; }
.q-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.q-head .t { display: flex; align-items: center; gap: 10px; }
.q-head .t b { font-size: 16px; }
.q-head .t small { display: block; color: var(--text-dim); font-size: 11.5px; }

.q-search { display: flex; gap: 8px; margin-bottom: 14px; }
.q-search .input { flex: 1; padding: 11px 13px; font-size: 14px; }

.month-block { margin-bottom: 14px; }
.month-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 4px 4px 8px;
  font-size: 13px;
}
.month-head b { font-size: 14.5px; }
.day-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 11px 14px;
  margin-bottom: 7px;
}
.day-row .d { font-weight: 600; font-size: 13px; }
.day-row .d small { display: block; color: var(--text-faint); font-size: 11px; font-weight: 400; }
.day-row .mid { text-align: right; flex: 1; }
.day-row .mid .c { font-size: 12px; color: var(--text-dim); }
.day-row .mid .m { font-weight: 700; color: var(--green); font-variant-numeric: tabular-nums; }
.day-row .pill-box { text-align: right; min-width: 76px; }
.day-row .pill-box .paid-time { text-align: right; }

/* ============ 响应式 ============ */
@media (max-width: 940px) {
  .sidebar { width: 60px; padding: 12px 7px; }
  .logo { justify-content: center; padding: 2px 0 12px; }
  .logo > div { display: none; }
  .nav-item { justify-content: center; padding: 10px 0; }
  .nav-item span { display: none; }
  .user-chip { display: none; }
  .sidebar-foot { flex-direction: column; }
  .main { padding: 16px 12px 56px; }
}

@media (max-width: 560px) {
  .page-head h1 { font-size: 17px; }
  .main { padding: 12px 8px 56px; }
  .card { padding: 13px 14px; border-radius: 11px; }
  .page-actions .btn { padding: 7px 11px; font-size: 12.5px; }
}
