:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --gray: #6b7280;
  --bg: #f3f4f6;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: #111827;
  color: #e5e7eb;
  flex-shrink: 0;
  padding: 18px 0;
}
.sidebar .brand {
  font-weight: 700;
  font-size: 17px;
  padding: 0 20px 18px;
  color: #fff;
  border-bottom: 1px solid #1f2937;
  margin-bottom: 12px;
}
.sidebar .brand small { display: block; font-weight: 400; color: #9ca3af; font-size: 12px; margin-top: 2px; }
.sidebar nav a {
  display: block;
  padding: 10px 20px;
  color: #d1d5db;
  font-size: 14px;
}
.sidebar nav a:hover { background: #1f2937; text-decoration: none; color: #fff; }
.sidebar nav a.active { background: var(--blue); color: #fff; font-weight: 600; }
.sidebar nav .section-label {
  padding: 14px 20px 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #6b7280;
}

.main { flex: 1; min-width: 0; }
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.topbar .user-info { font-size: 13px; color: var(--text-muted); }
.topbar .user-info strong { color: var(--text); }
.content { padding: 24px; max-width: 1200px; }

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.page-header { margin-bottom: 20px; display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 10px; }
.page-header p { margin: 2px 0 0; color: var(--text-muted); font-size: 13px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.card h2 { display: flex; justify-content: space-between; align-items: center; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-card .num { font-size: 26px; font-weight: 700; line-height: 1.2; }
.stat-card .label { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.stat-card.blue .num { color: var(--blue); }
.stat-card.green .num { color: var(--green); }
.stat-card.amber .num { color: var(--amber); }
.stat-card.red .num { color: var(--red); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); font-weight: 600; }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-gray { background: #f3f4f6; color: #4b5563; }

.btn {
  display: inline-block;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.btn:hover { background: var(--blue-dark); text-decoration: none; color: #fff; }
.btn.gray { background: #6b7280; }
.btn.gray:hover { background: #4b5563; }
.btn.red { background: var(--red); }
.btn.red:hover { background: #b91c1c; }
.btn.green { background: var(--green); }
.btn.green:hover { background: #15803d; }
.btn.outline { background: transparent; color: var(--blue); border: 1px solid var(--blue); }
.btn.outline:hover { background: #eff6ff; }
.btn.small { padding: 5px 11px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

form.inline { display: inline; }

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; margin-top: 12px; }
label:first-child { margin-top: 0; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=time], input[type=search], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid #d1d5db;
  border-radius: 7px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: 1px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-actions { margin-top: 18px; display: flex; gap: 10px; }
.help-text { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 16px; }
.filters .field { min-width: 140px; }
.filters label { margin: 0 0 4px; }

.flash { padding: 11px 15px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.flash-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.flash-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.flash-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }

.avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; background: #d1d5db; display: inline-block; vertical-align: middle; }
.avatar-lg { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; background: #d1d5db; }

.employee-cell { display: flex; align-items: center; gap: 10px; }
.employee-cell .name { font-weight: 600; }
.employee-cell .sub { font-size: 12px; color: var(--text-muted); }

.pill-tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.pill-tabs a { padding: 7px 14px; border-radius: 999px; background: #fff; border: 1px solid var(--border); color: var(--text); font-size: 13px; font-weight: 600; }
.pill-tabs a.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* ---- Scanner page (mobile-first, standalone, no sidebar) ---- */
.scanner-page { max-width: 480px; margin: 0 auto; padding: 16px; }
.scanner-page .brand { text-align: center; margin-bottom: 14px; font-weight: 700; font-size: 18px; }
#qr-reader { width: 100%; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.scan-result {
  border-radius: var(--radius);
  padding: 18px;
  margin-top: 14px;
  text-align: center;
  font-size: 16px;
}
.scan-result.in { background: #dcfce7; color: #166534; }
.scan-result.out { background: #dbeafe; color: #1e40af; }
.scan-result.err { background: #fee2e2; color: #991b1b; }
.scan-result .name { font-size: 20px; font-weight: 700; margin-bottom: 3px; }
.scan-result .time { font-size: 14px; opacity: .85; }
.recent-scans { margin-top: 18px; }
.recent-scans h2 { font-size: 14px; }
.recent-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }

/* Printable badge */
.badge-card {
  width: 330px;
  border: 1px solid #d1d5db;
  border-radius: 14px;
  padding: 18px;
  text-align: center;
  background: #fff;
  margin: 0 auto 20px;
}
.badge-card .avatar-lg { margin-bottom: 10px; }
.badge-card h3 { margin: 0 0 2px; font-size: 17px; }
.badge-card .role { color: var(--text-muted); font-size: 13px; margin-bottom: 12px; }
.badge-card .qr-box { display: flex; justify-content: center; margin: 10px 0; }
.badge-card .empno { font-family: monospace; font-size: 13px; color: var(--text-muted); margin-top: 8px; }

@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .badge-card { break-inside: avoid; box-shadow: none; border: 1px solid #999; }
}

@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; padding: 10px 0; }
  .sidebar nav { display: flex; overflow-x: auto; }
  .sidebar .brand { border-bottom: none; margin-bottom: 4px; padding-bottom: 10px; }
  .sidebar nav .section-label { display: none; }
  .sidebar nav a { white-space: nowrap; padding: 8px 14px; }
  .content { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
}
