:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
  --radius: 14px;
  --sidebar-w: 248px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: 15px; }
a { color: var(--primary); text-decoration: none; }

.hidden { display: none !important; }
.muted { color: var(--text-muted); }

/* ============ LOGIN ============ */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
}

.login-card {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
  padding: 40px 32px;
}

.login-logo {
  text-align: center;
  margin-bottom: 8px;
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.5px;
}

.login-sub { text-align: center; color: var(--text-muted); margin-bottom: 28px; }

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.field textarea { resize: vertical; min-height: 72px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 15px;
  transition: background 0.15s, opacity 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: var(--bg); color: var(--text); }
.btn-ghost:hover { background: var(--border); }
.btn-block { width: 100%; }
.btn-lg { padding: 15px 24px; font-size: 16px; }

.form-error {
  background: var(--danger-light);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  margin-top: 12px;
}

/* ============ APP SHELL ============ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-logo {
  padding: 22px 24px;
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.5px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo span { color: var(--text); font-weight: 700; }

.nav { flex: 1; padding: 12px; overflow-y: auto; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 10px;
  color: var(--text-muted);
  font-weight: 500;
  width: 100%;
  text-align: left;
  margin-bottom: 2px;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }
.nav-item .ico { font-size: 18px; width: 22px; text-align: center; }

.sidebar-user {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  flex-shrink: 0;
}
.sidebar-user-info { min-width: 0; flex: 1; }
.sidebar-user-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 12px; color: var(--text-muted); }

/* Main */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-title { font-weight: 700; font-size: 18px; }
.hamburger { font-size: 24px; padding: 4px 8px; }

.content { padding: 28px 32px; max-width: 1100px; width: 100%; }
.page-title { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.page-sub { color: var(--text-muted); margin-bottom: 24px; }

/* ============ CARDS ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 20px 22px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.stat-card .stat-ico {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 22px;
  margin-bottom: 14px;
}
.stat-ico.blue { background: var(--primary-light); }
.stat-ico.green { background: var(--success-light); }
.stat-ico.amber { background: var(--warning-light); }
.stat-ico.red { background: var(--danger-light); }
.stat-value { font-size: 26px; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.stat-change { font-size: 12px; margin-top: 8px; font-weight: 600; }
.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

/* Section */
.section { margin-bottom: 28px; }
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.section-title { font-size: 17px; font-weight: 700; }

/* Rows */
.row { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: none; }
.row-label { color: var(--text-muted); }
.row-value { font-weight: 600; }

/* Badge */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.badge.green { background: var(--success-light); color: var(--success); }
.badge.red { background: var(--danger-light); color: var(--danger); }
.badge.amber { background: var(--warning-light); color: var(--warning); }
.badge.blue { background: var(--primary-light); color: var(--primary-dark); }
.badge.gray { background: var(--bg); color: var(--text-muted); }

/* Week bars */
.week-bars { display: flex; gap: 10px; align-items: flex-end; height: 160px; padding-top: 10px; }
.week-bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; height: 100%; }
.week-bar-track { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.week-bar-fill {
  width: 100%; border-radius: 8px 8px 0 0;
  background: linear-gradient(180deg, var(--primary) 0%, var(--primary-dark) 100%);
  min-height: 4px; transition: height 0.4s ease;
}
.week-bar-label { font-size: 12px; color: var(--text-muted); }
.week-bar-val { font-size: 11px; font-weight: 600; }

/* Table */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--border); }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); font-weight: 600; }
.table tbody tr:hover { background: var(--bg); }

/* Empty state */
.empty {
  text-align: center; padding: 40px 20px; color: var(--text-muted);
}
.empty-ico { font-size: 40px; margin-bottom: 10px; }

/* Tabs */
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab {
  padding: 10px 16px; font-weight: 600; color: var(--text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ============ CAMERA / CHECK-IN ============ */
.checkin-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
.camera-box {
  position: relative; width: 100%; aspect-ratio: 4/3;
  background: #000; border-radius: var(--radius); overflow: hidden;
}
.camera-box video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.face-ring {
  position: absolute; top: 50%; left: 50%; width: 55%; aspect-ratio: 0.78;
  transform: translate(-50%, -50%);
  border: 3px dashed rgba(255,255,255,0.55); border-radius: 50%;
  transition: border-color 0.2s;
}
.face-ring.ok { border-color: var(--success); border-style: solid; }
.face-ring.fail { border-color: var(--danger); }
.challenge {
  margin-top: 16px; text-align: center;
}
.challenge-ico { font-size: 34px; height: 42px; animation: pulse 1.4s infinite; }
.challenge-ico.done { animation: none; }
.challenge-text { font-weight: 600; font-size: 16px; margin: 6px 0 10px; min-height: 22px; }
@keyframes pulse { 0%,100% { transform: scale(1);} 50% { transform: scale(1.15);} }
.progress-bar { height: 7px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--success); width: 0; transition: width 0.3s; }

.gps-line { display: flex; align-items: center; gap: 10px; padding: 12px 0; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-muted); }
.dot.ok { background: var(--success); }
.dot.bad { background: var(--danger); }

/* ============ TOAST / OVERLAY / MODAL ============ */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: #fff; padding: 12px 20px; border-radius: 10px;
  box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s; z-index: 2000; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }

.overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.4);
  display: none; place-items: center; z-index: 1500;
}
.overlay.show { display: grid; }
.overlay-card { background: var(--surface); padding: 28px 36px; border-radius: var(--radius); text-align: center; }
.overlay-label { margin-top: 14px; color: var(--text-muted); font-size: 14px; }

.spinner {
  width: 38px; height: 38px; margin: 0 auto;
  border: 3px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
.spinner.sm { width: 20px; height: 20px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.modal-back {
  position: fixed; inset: 0; background: rgba(15,23,42,0.45);
  display: grid; place-items: center; padding: 20px; z-index: 1800;
  opacity: 0; transition: opacity 0.2s;
}
.modal-back.show { opacity: 1; }
.modal {
  background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 460px;
  max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow-lg);
  transform: scale(0.96); transition: transform 0.2s;
}
.modal-back.show .modal { transform: scale(1); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 17px; }
.modal-body { padding: 20px; }
.modal-actions { display: flex; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--border); }
.modal-actions .btn { flex: 1; }
.icon-btn { font-size: 18px; color: var(--text-muted); padding: 4px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--bg); }

/* Drawer (mobile sidebar) */
.scrim {
  position: fixed; inset: 0; background: rgba(15,23,42,0.4); z-index: 40;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.scrim.show { opacity: 1; pointer-events: auto; }

/* ============ RESPONSIVE ============ */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: 80%; max-width: 300px;
    z-index: 50; transform: translateX(-100%); transition: transform 0.25s;
  }
  .sidebar.open { transform: translateX(0); }
  .topbar { display: flex; }
  .content { padding: 18px 16px; }
  .checkin-layout { grid-template-columns: 1fr; }
  .page-title { font-size: 20px; }
}
