:root {
  --brand-primary: #1e40af;
  --brand-primary-dark: #1e3a8a;
  --brand-accent: #0ea5e9;
  --bg-app: #f1f5f9;
  --bg-card: #ffffff;
  --bg-sidebar: #0f172a;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --success: #15803d;
  --success-bg: #f0fdf4;
  --warning: #b45309;
  --warning-bg: #fffbeb;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.18);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang HK", "Microsoft JhengHei", Roboto, sans-serif;
  background: var(--bg-app);
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--text-muted); font-size: 13px; }
.mono { font-family: "SFMono-Regular", Consolas, "Courier New", monospace; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }

/* Global Top Progress Bar */
.top-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3.5px;
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  background: rgba(14, 165, 233, 0.18);
  overflow: hidden;
}
.top-progress-bar.active { opacity: 1; }
.top-progress-fill {
  height: 100%;
  width: 38%;
  background: linear-gradient(90deg, var(--brand-primary), var(--brand-accent));
  animation: topBarSlide 1.1s infinite ease-in-out;
}
@keyframes topBarSlide {
  0% { transform: translateX(-100%); }
  50% { transform: translateX(120%); }
  100% { transform: translateX(280%); }
}

/* Boot Screen */
.boot-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.spinner-lg {
  width: 38px;
  height: 38px;
  border: 3.5px solid #cbd5e1;
  border-top-color: var(--brand-primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
.spinner-sm {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  vertical-align: -2px;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* App Shell */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px;
  background: var(--bg-sidebar);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.22s ease;
}
.sidebar-brand {
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-logo {
  max-height: 34px;
  max-width: 140px;
  object-fit: contain;
  background: #fff;
  padding: 3px 6px;
  border-radius: 6px;
}
.sidebar-title { font-weight: 700; font-size: 15px; line-height: 1.25; }
.sidebar-sub { font-size: 11px; color: #94a3b8; }
.sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.nav-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: #cbd5e1;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  margin-bottom: 4px;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.nav-item.active { background: var(--brand-primary); color: #fff; font-weight: 600; }
.sidebar-foot {
  padding: 12px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
  color: #94a3b8;
}

.main-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mobile-menu-btn {
  display: none;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 16px;
  cursor: pointer;
}
.page-content { padding: 20px; max-width: 1380px; width: 100%; margin: 0 auto; }

/* Banners */
.kiosk-banner {
  background: #1e293b;
  color: #f8fafc;
  padding: 8px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}
.kiosk-countdown-banner {
  background: var(--success);
  color: #fff;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
}
.alert {
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  margin-bottom: 14px;
  font-size: 13.5px;
}
.alert-danger { background: var(--danger-bg); border-color: #fecaca; color: #991b1b; }
.alert-warning { background: var(--warning-bg); border-color: #fde68a; color: #92400e; }
.alert-success { background: var(--success-bg); border-color: #bbf7d0; color: #166534; }
.alert-info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }

/* Cards & Grid */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.card-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.card-hdr h2, .card-hdr h3 { margin: 0; font-size: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
}
.stat-lbl { font-size: 12px; color: var(--text-muted); }
.stat-val { font-size: 22px; font-weight: 700; margin-top: 4px; color: var(--brand-primary); }

/* Tabs */
.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2.5px solid transparent;
  padding: 9px 14px;
  cursor: pointer;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 13.5px;
}
.tab-btn.active { color: var(--brand-primary); border-bottom-color: var(--brand-primary); }

/* Forms & Buttons */
.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 150px; flex: 1; }
.field label { font-size: 12.5px; font-weight: 600; color: #334155; }
.field input, .field select, .field textarea {
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  font-size: 13.5px;
  background: #fff;
  color: var(--text-main);
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.12);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--brand-primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-primary-dark); }
.btn-secondary { background: #f1f5f9; color: #0f172a; border-color: #cbd5e1; }
.btn-secondary:hover:not(:disabled) { background: #e2e8f0; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: #d97706; color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-lg { padding: 13px 20px; font-size: 15px; border-radius: 10px; }
.btn-icon { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-muted); line-height: 1; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: #e2e8f0;
  color: #334155;
}
.badge-primary { background: #dbeafe; color: #1e40af; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.otp-pill {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #86efac;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

/* Tables */
.table-wrap { width: 100%; overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th, table.tbl td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
table.tbl th {
  background: #f8fafc;
  font-weight: 700;
  color: #334155;
  white-space: nowrap;
}
table.tbl tr:hover td { background: #f8fafc; }

/* Login View */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background-size: cover;
  background-position: center;
  background-color: #0f172a;
}
.login-card {
  width: 100%;
  max-width: 430px;
  background: rgba(255, 255, 255, 0.97);
  border-radius: 14px;
  padding: 28px;
  box-shadow: var(--shadow-lg);
}
.login-logo { max-height: 54px; max-width: 220px; object-fit: contain; margin-bottom: 10px; }

/* Clock-In Role Cards & QR Box */
.role-btn-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.role-clock-card {
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, transform 0.12s;
}
.role-clock-card:hover { border-color: var(--brand-primary); transform: translateY(-1px); }
.role-clock-card.highlighted {
  border-color: var(--brand-primary);
  background: #eff6ff;
}
.qr-reader-box {
  width: 100%;
  max-width: 380px;
  margin: 0 auto 14px auto;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid var(--brand-primary);
  background: #000;
}

/* Modals & Staged Overlay */
.modal-backdrop, .staged-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}
.staged-overlay { z-index: 2000; }
.modal-card {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 780px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal-card.modal-sm { max-width: 440px; }
.modal-card.modal-xl { max-width: 1020px; }
.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.staged-card {
  background: #fff;
  border-radius: 14px;
  padding: 28px 32px;
  max-width: 440px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.staged-card .spinner-lg { margin: 0 auto 14px auto; }
.staged-steps { text-align: left; margin: 14px 0; padding-left: 20px; font-size: 13.5px; }
.staged-steps li { padding: 4px 0; color: var(--text-muted); }
.staged-steps li.active { color: var(--brand-primary); font-weight: 700; }
.staged-steps li.done { color: var(--success); }
.staged-warn { font-size: 12px; color: var(--danger); margin-top: 8px; }

/* Floating Background File Uploader */
.bg-uploader {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 320px;
  max-width: calc(100vw - 24px);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  z-index: 900;
  overflow: hidden;
}
.bg-uploader-hdr {
  background: #0f172a;
  color: #fff;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.bg-uploader-list { max-height: 240px; overflow-y: auto; padding: 8px; }
.bg-uploader.collapsed .bg-uploader-list { display: none; }
.upload-item {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}
.upload-item:last-child { border-bottom: none; }

/* Toasts */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}
.toast {
  background: #0f172a;
  color: #fff;
  padding: 11px 15px;
  border-radius: 9px;
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
}
.toast-success { background: #166534; }
.toast-error { background: #991b1b; }
.toast-warning { background: #92400e; }

/* Holiday Red Day Cell */
.red-day { color: var(--danger); font-weight: 700; }

/* Responsive Mobile Drawer */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 200;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu-btn { display: inline-flex; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .page-content { padding: 12px; }
}
