:root {
  --purple-900: #4c1d95;
  --purple-800: #5b21b6;
  --purple-700: #6d28d9;
  --purple-600: #7c3aed;
  --purple-500: #8b5cf6;
  --purple-400: #a78bfa;
  --purple-100: #ede9fe;
  --purple-50: #f5f3ff;
  --bg: #f8f7fc;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e9e5f5;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(91, 33, 182, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; color: var(--text); background: var(--bg); }
.hidden { display: none !important; }

/* 登录 */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--purple-900) 0%, var(--purple-600) 50%, #c4b5fd 100%);
  padding: 24px;
}
.login-card {
  background: var(--card);
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 25px 60px rgba(76, 29, 149, 0.35);
}
.brand { text-align: center; margin-bottom: 28px; }
.brand-icon {
  width: 56px; height: 56px; margin: 0 auto 12px;
  background: linear-gradient(135deg, var(--purple-600), var(--purple-400));
  color: #fff; font-weight: 700; font-size: 20px;
  border-radius: 16px; display: flex; align-items: center; justify-content: center;
}
.brand-icon.sm { width: 36px; height: 36px; font-size: 14px; border-radius: 10px; margin: 0; }
.brand h1 { margin: 0; font-size: 22px; color: var(--purple-800); }
.brand p { margin: 8px 0 0; color: var(--muted); font-size: 14px; }

/* 布局 */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; flex-shrink: 0;
  background: linear-gradient(180deg, var(--purple-900), var(--purple-800));
  color: #fff; display: flex; flex-direction: column; padding: 20px 12px;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px 24px; font-weight: 600; font-size: 15px;
}
.nav { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  text-align: left; border: 0; background: transparent; color: rgba(255,255,255,.75);
  padding: 12px 16px; border-radius: 10px; cursor: pointer; font-size: 14px;
  transition: all .2s;
}
.nav-item:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.18); color: #fff; font-weight: 600; }
.audit-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.input-search {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 160px;
}
.audit-pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 16px;
}
.audit-clear-actions {
  display: inline-flex;
  gap: 8px;
  margin-left: 4px;
}
.btn-audit-clear {
  color: #b91c1c;
  border-color: #fca5a5;
}
.btn-audit-clear:hover {
  background: #fef2f2;
  color: #991b1b;
}
.mode-readonly .att-card .status-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.sidebar-footer {
  padding: 16px 12px; border-top: 1px solid rgba(255,255,255,.15);
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; color: rgba(255,255,255,.8);
}

.content { flex: 1; padding: 28px 32px 80px; overflow: auto; width: 100%; }
.page { display: none; }
.page.active { display: block; }
.page-header { margin-bottom: 24px; }
.page-header.row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-header h2 { margin: 0; font-size: 24px; color: var(--purple-900); }
.subtitle { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.header-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* 卡片与统计 */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 20px 24px; box-shadow: var(--shadow); border: 1px solid var(--border);
  margin-bottom: 20px;
}
.card h3 { margin: 0 0 16px; font-size: 16px; color: var(--purple-800); }
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  .stat-grid { grid-template-columns: 1fr; }
}
.stat-card {
  background: var(--card); border-radius: var(--radius); padding: 18px 20px;
  border: 1px solid var(--border); box-shadow: var(--shadow);
}
.stat-card .label { font-size: 13px; color: var(--muted); line-height: 1.4; }
.stat-card .value { font-size: 26px; font-weight: 700; color: var(--purple-700); margin-top: 6px; }
.stat-card.stat-success .value { color: var(--success); }
.stat-card.stat-warn .value { color: var(--warning); }
.stat-card.stat-danger .value { color: var(--danger); }
.stat-card.stat-info .value { color: #2563eb; }
.stat-card.stat-muted .value { color: var(--muted); }

/* 按钮 */
.btn {
  border: 0; border-radius: 8px; padding: 10px 18px; font-size: 14px;
  cursor: pointer; font-weight: 500; transition: all .15s;
}
.btn-primary { background: var(--purple-600); color: #fff; }
.btn-primary:hover { background: var(--purple-700); }
.btn-secondary { background: var(--purple-100); color: var(--purple-800); }
.btn-secondary:hover { background: #ddd6fe; }
.btn-success { background: var(--success); color: #fff; }
.btn-outline { background: #fff; border: 1px solid var(--border); color: var(--text); }
.btn-ghost { background: transparent; color: rgba(255,255,255,.9); }
.btn-ghost:hover { background: rgba(255,255,255,.1); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-outline { background: #fff; border: 1px solid var(--border); color: var(--text); }
.nav-super.hidden { display: none; }
.nav-item.hidden { display: none; }
.perm-super-only.hidden { display: none; }
.perm-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px 20px;
}
.perm-grid label {
  display: flex; align-items: center; gap: 10px;
  font-weight: 500; color: var(--purple-900);
  padding: 12px 14px;
  background: var(--purple-50);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin: 0;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.perm-grid label:hover { border-color: var(--purple-400); background: #fff; }
.perm-grid input { width: 18px; height: 18px; accent-color: var(--purple-600); }
@media (max-width: 1100px) {
  .perm-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 768px) {
  .perm-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.btn-block { width: 100%; }
.btn-lg { padding: 14px 32px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* 表单 */
label { display: block; font-size: 14px; color: #374151; margin-bottom: 16px; }
label input, label textarea, label select {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
label input:focus, label textarea:focus { outline: 2px solid var(--purple-400); border-color: var(--purple-500); }
.checkbox { display: flex; align-items: center; gap: 8px; }
.checkbox input { width: auto; margin: 0; }
.form-error { color: var(--danger); font-size: 13px; margin-top: 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }

.toolbar { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input, .toolbar select {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.toolbar input[type=search] { flex: 1; min-width: 200px; }

.input-date, .input-month {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
}

/* 表格 */
.table-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th {
  text-align: left; padding: 14px 16px; background: var(--purple-50);
  color: var(--purple-800); font-weight: 600; border-bottom: 1px solid var(--border);
}
.th-sortable { white-space: nowrap; }
.th-sortable .sort-btn {
  margin-left: 6px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--purple-700);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  vertical-align: middle;
}
.th-sortable .sort-btn:hover,
.th-sortable .sort-btn.sort-active {
  background: var(--purple-100);
  border-color: var(--purple-400);
}
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tr:hover td { background: var(--purple-50); }
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px;
}
.badge-active { background: #d1fae5; color: #065f46; }
.badge-left { background: #fee2e2; color: #991b1b; }
.badge-draft { background: var(--purple-100); color: var(--purple-800); }
.badge-confirmed { background: #d1fae5; color: #065f46; }

.link-btn {
  background: none; border: 0; color: var(--purple-600); cursor: pointer;
  padding: 0 8px 0 0; font-size: 14px;
}
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--danger); }

/* 签到网格 */
.quick-bar {
  display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap;
}
.quick-bar .hint { color: var(--muted); font-size: 14px; margin-left: auto; }
.att-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px; margin-bottom: 100px;
}
.att-card {
  background: var(--card); border: 2px solid var(--border); border-radius: var(--radius);
  padding: 16px; transition: border-color .2s, box-shadow .2s;
}
.att-card.inactive { opacity: .45; pointer-events: none; }
.att-card.present { border-color: var(--success); box-shadow: 0 0 0 1px var(--success); }
.att-card.late { border-color: var(--warning); }
.att-card.absent { border-color: var(--danger); }
.att-card.leave { border-color: var(--purple-400); }
.att-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.att-card .name { font-weight: 600; font-size: 16px; margin: 0; }
.att-clear-one {
  flex-shrink: 0; padding: 2px 8px; font-size: 12px; color: var(--muted);
  background: transparent; border: 1px solid var(--border); border-radius: 6px; cursor: pointer;
}
.att-clear-one:hover { color: var(--danger); border-color: var(--danger); }
.att-card .status-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.status-btn {
  flex: 1; min-width: 58px; padding: 6px 4px; font-size: 12px;
  border: 1px solid var(--border); border-radius: 6px; background: #fff; cursor: pointer;
}
.status-btn.active { background: var(--purple-600); color: #fff; border-color: var(--purple-600); }
.status-btn[data-s=present].active { background: var(--success); border-color: var(--success); }
.status-btn[data-s=late].active { background: var(--warning); border-color: var(--warning); }
.status-btn[data-s=absent].active { background: var(--danger); border-color: var(--danger); }
.status-pill {
  display: inline-block; padding: 6px 12px; font-size: 13px; border-radius: 8px;
  border: 1px solid var(--border); color: var(--muted); background: #f9fafb;
}
.status-pill.active { font-weight: 600; color: #fff; border-color: transparent; }
.status-pill-present.active { background: var(--success); }
.status-pill-late.active { background: var(--warning); }
.status-pill-absent.active { background: var(--danger); }
.status-btns-auto { margin-bottom: 6px; }
.status-btns-manual .status-btn.manual.active { background: var(--purple-600); border-color: var(--purple-600); }
.att-meta { font-size: 12px; color: var(--muted); margin: -4px 0 8px; }
.att-meta-warn { color: var(--danger); }
.att-meta-checkout { color: #5b21b6; font-size: 11px; line-height: 1.4; }
.att-loc-link { margin-left: 4px; font-size: 11px; }
.loc-cell { max-width: 220px; font-size: 12px; line-height: 1.4; word-break: break-all; }

.sticky-footer {
  position: fixed; bottom: 0; left: 240px; right: 0;
  background: rgba(255,255,255,.95); backdrop-filter: blur(8px);
  border-top: 1px solid var(--border); padding: 16px 32px;
  display: flex; justify-content: flex-end; z-index: 10;
}
@media (max-width: 768px) {
  .sidebar { width: 72px; }
  .sidebar-brand span:last-child, .nav-item, .sidebar-footer span { display: none; }
  .sticky-footer { left: 72px; }
}

.mini-list { margin-bottom: 16px; }
.mini-item {
  display: flex; justify-content: space-between; padding: 10px 0;
  border-bottom: 1px solid var(--border); font-size: 14px;
}

.formula-card { font-size: 13px; color: var(--muted); line-height: 1.65; }
.table-wrap-salary { margin-top: 12px; }
.data-table-compact th,
.data-table-compact td {
  padding: 10px 12px;
  font-size: 13px;
  white-space: nowrap;
}
#salary-table .salary-actions { white-space: nowrap; }
.salary-total {
  text-align: right; font-size: 18px; font-weight: 700;
  color: var(--purple-800); margin-top: 16px;
}

.divider { border: 0; border-top: 1px solid var(--border); margin: 24px 0; }

/* 系统设置页 */
.settings-layout {
  display: flex;
  flex-direction: column;
  gap: 24px;
  width: 100%;
}
.settings-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
  align-items: start;
}
@media (max-width: 960px) {
  .settings-row { grid-template-columns: 1fr; }
}
.settings-card {
  margin-bottom: 0;
  padding: 24px 28px;
}
.settings-card-head {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.settings-card-head h3 {
  margin: 0 0 8px;
  font-size: 17px;
  color: var(--purple-900);
}
.settings-card-foot {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}
.settings-sections {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.settings-section {
  padding: 22px 0;
  border-bottom: 1px solid var(--border);
}
.settings-section:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}
.settings-section:first-child {
  padding-top: 0;
}
.settings-section h4 {
  margin: 0 0 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--purple-800);
  letter-spacing: 0.02em;
}
.settings-fields {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.settings-fields label {
  margin-bottom: 14px;
}
.settings-fields label:last-child {
  margin-bottom: 0;
}
.settings-fields .field-narrow {
  max-width: 280px;
}
.settings-fields .field-wide {
  flex: 1 1 100%;
  max-width: 480px;
}
.settings-fields .field-wide input {
  width: 100%;
}
.settings-fields-account label {
  max-width: 360px;
}
.settings-check-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 24px;
  margin-top: 4px;
}
@media (max-width: 600px) {
  .settings-check-group { grid-template-columns: 1fr; }
}
.settings-check-group .checkbox {
  margin-bottom: 0;
  padding: 10px 12px;
  background: var(--purple-50);
  border-radius: 8px;
  border: 1px solid transparent;
}
.setting-hint {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.55;
  margin: 0;
}
.setting-hint.block-hint {
  margin-top: 8px;
}
#page-settings .setting-hint {
  margin-top: 0;
}

.qr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}
.qr-card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  text-align: center; border: 1px solid var(--border); box-shadow: var(--shadow);
}
.qr-card .name { font-weight: 600; margin-bottom: 10px; color: var(--purple-900); }
.qr-card canvas { margin: 0 auto 8px; }
.qr-row { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.qr-image {
  width: 180px; height: 180px; flex-shrink: 0;
  border: 4px solid #ede9fe; border-radius: 12px; background: #fff;
  object-fit: contain;
}
.qr-url { font-size: 12px; color: var(--muted); word-break: break-all; margin: 8px 0; }
.modal-qr { max-width: 360px; }
.qr-dialog-body { padding: 28px; text-align: center; }
.qr-dialog-body canvas { margin: 16px auto; }
.signature-preview { max-width: 100%; border: 1px solid var(--border); border-radius: 8px; margin: 12px 0; }
.daily-qr-card .daily-qr-info h3 { margin: 0 0 8px; color: var(--purple-800); }
.qr-warn { font-size: 12px; color: var(--warning); margin-top: 12px; }

/* 弹窗 */
.modal {
  border: 0; border-radius: 16px; padding: 0; max-width: 520px; width: 92%;
  box-shadow: 0 25px 60px rgba(0,0,0,.25);
}
#dlg-employee { max-width: 680px; }
.modal::backdrop { background: rgba(76, 29, 149, .4); }
.modal form { padding: 28px; }
.modal .qr-dialog-body { padding: 28px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; gap: 12px;
}
.modal-header h3 { margin: 0; color: var(--purple-800); font-size: 1.15rem; }
.modal-close {
  border: 0; background: #f5f3ff; color: var(--purple-800);
  width: 36px; height: 36px; border-radius: 8px; font-size: 22px; line-height: 1;
  cursor: pointer; flex-shrink: 0;
}
.modal-close:hover { background: #ede9fe; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.modal .btn-secondary {
  background: #fff; color: var(--purple-800); border: 1px solid var(--border);
}
.modal .btn-secondary:hover { background: #f5f3ff; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--purple-900); color: #fff; padding: 12px 24px; border-radius: 8px;
  font-size: 14px; opacity: 0; transition: all .3s; z-index: 100; pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
