:root {
  --primary: #4f6bf0;
  --primary-dark: #3d55d8;
  --bg: #f2f4f8;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --blue: #2563eb;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
  --shadow-lg: 0 10px 25px rgba(16,24,40,.12);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }

/* ---------- login ---------- */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #4f6bf0 0%, #7c5cf0 60%, #a05cf0 100%);
  padding: 20px;
}
.login-card {
  background: var(--card);
  border-radius: 16px;
  padding: 40px 44px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-logo { margin-bottom: 14px; }
.company-logo { max-width: 260px; max-height: 70px; object-fit: contain; }
.logo-fallback { display: inline-block; }
.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.login-sub { color: var(--muted); font-size: 12px; margin-bottom: 28px; letter-spacing: .5px; }
.login-form { text-align: left; }
.login-error { color: var(--red); font-size: 13px; margin: 10px 0; text-align: center; }

/* ---------- layout ---------- */
.app-view { display: flex; height: 100vh; }
.sidebar {
  width: 220px;
  background: #161b2e;
  color: #cdd3e0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 18px;
  font-size: 16px; font-weight: 600; color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-logo { max-width: 160px; max-height: 40px; object-fit: contain; }
.brand span { white-space: nowrap; }
nav { flex: 1; padding: 14px 10px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px;
  margin-bottom: 4px;
  border-radius: 8px;
  color: #cdd3e0;
  text-decoration: none;
  font-size: 14px;
  transition: background .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 500; }
.nav-ico { font-size: 16px; width: 20px; text-align: center; }
.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 600;
}
.user-meta { line-height: 1.4; }
.user-name { color: #fff; font-size: 13px; font-weight: 500; }
.link-btn { background: none; border: none; color: #8b93a7; font-size: 12px; cursor: pointer; padding: 0; }
.link-btn:hover { color: #fff; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.main-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.main-header h2 { font-size: 18px; }
.main-actions { display: flex; align-items: center; gap: 12px; }
.clock { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

.main { overflow-y: auto; }
.view { display: none; padding: 24px 28px; }
.view.active { display: block; }

/* ---------- panels & cards ---------- */
.panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.panel-title {
  font-size: 15px; font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 14px; padding: 20px;
}
.stat-icon { width: 46px; height: 46px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 22px; }
.stat-icon.blue { background: #e8effe; }
.stat-icon.green { background: #e6f6ec; }
.stat-icon.purple { background: #f0ecfe; }
.stat-icon.red { background: #feecec; }
.stat-num { font-size: 26px; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ---------- table ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 12px; color: var(--muted);
  font-weight: 600; padding: 10px 12px;
  background: #fafbfc; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:hover { background: #f8faff; }
.table .actions { white-space: nowrap; }
.table .actions .btn { margin-right: 6px; }

/* ---------- badges ---------- */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
}
.badge.registered { background: #e8effe; color: var(--blue); }
.badge.checked_in { background: #e6f6ec; color: var(--green); }
.badge.checked_out { background: #f3f4f6; color: var(--muted); }
.badge.blacklisted { background: #feecec; color: var(--red); }
.badge.on { background: #e6f6ec; color: var(--green); }
.badge.off { background: #feecec; color: var(--red); }

/* ---------- forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.form-row { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.grow { flex: 1; min-width: 180px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; color: var(--muted); font-weight: 500; }
.req { color: var(--red); }
.field.submit-field { display: flex; align-items: flex-end; }
.input, .field input, .field select, .field textarea {
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 12px; font-size: 14px; background: #fff; color: var(--text);
  width: 100%; outline: none; transition: border-color .15s;
  font-family: inherit;
}
.field textarea { resize: vertical; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.form-actions { display: flex; align-items: center; gap: 12px; }
.form-error { color: var(--red); font-size: 13px; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid transparent; border-radius: 8px;
  padding: 9px 16px; font-size: 14px; cursor: pointer;
  transition: all .15s; font-family: inherit; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: #fff; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-danger { color: var(--red); }
.btn-danger:hover { border-color: var(--red); }
.btn-success { color: var(--green); }
.btn-success:hover { border-color: var(--green); }
.btn-wecom { background: #fff; border-color: #07c160; color: #07c160; }
.btn-wecom:hover { background: #07c160; color: #fff; }
.login-divider { display: flex; align-items: center; gap: 10px; margin: 14px 0 12px; color: #999; font-size: 12px; }
.login-divider::before, .login-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ---------- toolbar & pager ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar-left { display: flex; gap: 10px; flex-wrap: wrap; }
.toolbar-right { margin-left: auto; }
.toolbar .input { width: 200px; }
.toolbar select.input { width: 140px; }
.toolbar input[type=date].input { width: 150px; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.pager span { color: var(--muted); font-size: 13px; }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15,23,42,.45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-box {
  background: #fff; border-radius: 14px; width: 100%; max-width: 440px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.modal-close { background: none; border: none; font-size: 16px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 20px; }
.modal-body .field { margin-bottom: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }
.modal-note { font-size: 13px; color: var(--muted); margin-bottom: 12px; line-height: 1.6; }

.empty { text-align: center; color: var(--muted); padding: 24px; }
@media (max-width: 900px) {
  .sidebar { width: 64px; }
  .brand span, .user-meta, .nav-item span:not(.nav-ico) { display: none; }
  .nav-item { justify-content: center; }
  .sidebar-user { justify-content: center; padding: 12px; }
}
