:root {
  --bg: #f3f6f9;
  --surface: #ffffff;
  --rail: #093b42;
  --rail-hover: #11535c;
  --accent: #18c3c9;
  --primary: #093b42;
  --text: #102a30;
  --muted: #60787f;
  --border: #e1e8ee;
  --radius: 16px;
}

[hidden] { display: none !important; }
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

button, input, select, textarea { font-family: inherit; font-size: 13.5px; }
button { cursor: pointer; border: none; border-radius: 10px; font-weight: 600; transition: 0.15s ease; }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; padding: 9px 16px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.btn-primary:hover:not(:disabled) { background: #0e525c; }
.btn-outline { background: #fff; color: var(--text); border: 1px solid var(--border); padding: 8px 14px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn-outline:hover:not(:disabled) { border-color: var(--primary); }
.btn-ghost { background: transparent; color: #b42318; padding: 6px 10px; }
.btn-ghost:hover { background: #fef3f2; }
.btn-danger { background: #d92d20; color: #fff; padding: 9px 16px; }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn-block { width: 100%; }
.link-btn { background: none; color: #0f8a8f; padding: 0; font-size: 12.5px; }
.icon-btn { width: 30px; height: 30px; border-radius: 8px; background: #f1f5f8; color: var(--text); display: inline-flex; align-items: center; justify-content: center; }

/* LOGIN & FATAL */
.fatal-screen, .login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #093b42 0%, #0f5f69 100%);
}
.login-card, .fatal-card {
  width: 100%;
  max-width: 440px;
  background: #fff;
  border-radius: 20px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(4, 28, 32, 0.28);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.brand-logo {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--accent); color: var(--primary);
  font-weight: 800; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.login-brand h1 { font-size: 20px; color: var(--primary); }
.login-brand p { font-size: 12.5px; color: var(--muted); }
.login-notice {
  background: #fff8eb; border: 1px solid #f7d594; color: #8a5200;
  padding: 10px 12px; border-radius: 10px; font-size: 12.5px; margin-bottom: 14px;
}
.login-form { display: flex; flex-direction: column; gap: 13px; }
.api-box {
  background: #f6fafb; border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 12px;
}
.api-box-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; font-weight: 600; color: var(--primary); }
.api-input-row { display: flex; gap: 6px; margin-top: 8px; }
.api-input-row input { flex: 1; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 12px; }

/* APP SHELL 3 KOLOM */
.app-shell {
  display: grid;
  grid-template-columns: 74px 1fr 320px;
  min-height: 100vh;
}
.rail {
  background: var(--rail);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px 0;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.rail-logo {
  width: 42px; height: 42px; border-radius: 12px;
  background: var(--accent); color: var(--rail);
  font-weight: 800; display: flex; align-items: center; justify-content: center;
}
.rail-nav { display: flex; flex-direction: column; gap: 10px; flex: 1; }
.rail-bottom { display: flex; flex-direction: column; gap: 10px; }
.rail-btn {
  width: 44px; height: 44px; border-radius: 12px;
  background: transparent; color: #9ec5ca;
  display: flex; align-items: center; justify-content: center;
}
.rail-btn:hover { background: var(--rail-hover); color: #fff; }
.rail-btn.active { background: var(--accent); color: var(--rail); }

.main { padding: 20px 24px; display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; }
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar h1 { font-size: 21px; color: var(--primary); }
.mobile-only { display: none; }

.search-box {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border: 1px solid var(--border);
  border-radius: 12px; padding: 7px 12px; width: 310px; max-width: 100%;
}
.search-box input { border: none; outline: none; flex: 1; background: transparent; }
.search-clear { background: none; color: var(--muted); font-size: 16px; }

.greet-banner {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 20px; display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap;
}
.greet-left { display: flex; align-items: center; gap: 14px; }
.greet-avatar-wrap { position: relative; }
.greet-avatar {
  width: 48px; height: 48px; border-radius: 14px;
  background: #e1f7f8; color: var(--primary);
  font-weight: 800; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
}
.greet-badge {
  position: absolute; bottom: -4px; right: -4px;
  background: var(--accent); color: var(--primary);
  font-size: 11px; font-weight: 800; padding: 1px 6px; border-radius: 999px;
}
.greet-left h2 { font-size: 17px; color: var(--primary); }
.greet-left p { font-size: 12.5px; color: var(--muted); }

.panel {
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.loading-panel { text-align: center; padding: 48px 20px; color: var(--muted); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.card-title { font-size: 16px; font-weight: 700; color: var(--primary); }
.card-sub { font-size: 12.5px; color: var(--muted); }

/* DASHBOARD ANALYTICS */
.analytics-card { display: grid; grid-template-columns: 1.1fr 1fr; gap: 20px; align-items: end; }
.kpi-eyebrow { font-size: 11px; font-weight: 700; letter-spacing: 0.05em; color: var(--muted); margin-top: 14px; }
.kpi-big { font-size: 36px; font-weight: 800; color: var(--primary); line-height: 1.1; margin: 4px 0; }
.kpi-delta { font-size: 12px; color: #0f8a8f; font-weight: 600; }
.mini-stats { display: flex; gap: 16px; margin-top: 16px; flex-wrap: wrap; }
.mini-stat { display: flex; align-items: center; gap: 10px; }
.mini-icon { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; }
.mini-icon.teal { background: #e3f9f9; color: #0e8b90; }
.mini-icon.coral { background: #feece9; color: #d94832; }
.mini-val { font-weight: 800; font-size: 16px; }
.mini-lbl { font-size: 11.5px; color: var(--muted); }

.bar-chart { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; height: 165px; padding-top: 24px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.bar-fill { width: 100%; max-width: 34px; background: #e2edf1; border-radius: 8px 8px 4px 4px; position: relative; transition: 0.2s; }
.bar-fill.active { background: var(--accent); }
.bar-tooltip {
  position: absolute; top: -24px; left: 50%; transform: translateX(-50%);
  background: var(--primary); color: #fff; font-size: 10.5px; padding: 2px 6px; border-radius: 6px; white-space: nowrap;
}
.bar-label { font-size: 11.5px; color: var(--muted); }

.dash-bottom { display: grid; grid-template-columns: 1.15fr 1fr; gap: 18px; margin-top: 18px; }
.tile-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.tile { padding: 14px; border-radius: 14px; text-align: left; color: #fff; display: flex; flex-direction: column; gap: 12px; }
.tile.orange { background: linear-gradient(135deg, #ff9f2e, #f77816); }
.tile.blue { background: linear-gradient(135deg, #2d7ff9, #1859d1); }
.tile.cyan { background: linear-gradient(135deg, #18c3c9, #0c9aa0); }
.tile-lbl { font-size: 12px; opacity: 0.92; }
.tile-bottom { display: flex; justify-content: space-between; align-items: center; }
.tile-num { font-size: 24px; font-weight: 800; }
.tile-ico { font-size: 16px; opacity: 0.9; }
.rate-row { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.rate-val { font-size: 20px; font-weight: 800; color: var(--primary); }

.donut-wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; }
.legend-list { display: flex; flex-direction: column; gap: 10px; }
.legend-item { display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; }
.legend-num { font-weight: 700; font-size: 14px; }
.legend-txt { font-size: 11.5px; color: var(--muted); }
.donut-box { position: relative; width: 126px; height: 126px; }
.donut-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
}
.donut-center strong { font-size: 20px; color: var(--primary); }
.donut-center span { font-size: 10.5px; color: var(--muted); }

/* TOOLBAR, TABLES & CONTROLS */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ctrl-select, .ctrl-input {
  border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 12px; background: #fff; color: var(--text);
}
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; padding: 10px 12px; background: #f6f9fb; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--border); }
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.pagination { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; gap: 10px; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge-hadir, .badge-aktif { background: #e3f9f1; color: #0b6e4f; }
.badge-terlambat { background: #fff5e3; color: #9a5b00; }
.badge-sakit, .badge-izin { background: #e8f1ff; color: #1859d1; }
.badge-alpa, .badge-nonaktif { background: #feeceb; color: #b42318; }

.empty-state, .error-banner {
  text-align: center; padding: 34px 20px; border: 1px dashed var(--border);
  border-radius: 14px; display: flex; flex-direction: column; align-items: center; gap: 8px;
}

/* QR CARDS */
.qr-preview-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.qr-card-item { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: #fff; }
.qr-card-head { background: var(--primary); color: #fff; font-size: 11px; font-weight: 700; padding: 6px 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qr-card-body { padding: 10px; display: flex; gap: 10px; align-items: center; }
.qr-card-meta { display: flex; flex-direction: column; font-size: 11.5px; gap: 2px; min-width: 0; }
.qr-card-meta strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* SCANNER LIVE CAMERA */
.scanner-grid { display: grid; grid-template-columns: 1.35fr 0.95fr; gap: 18px; }
.cam-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.cam-bar select { flex: 1; min-width: 190px; }
.video-box {
  position: relative; width: 100%; aspect-ratio: 16 / 10;
  background: #071e22; border-radius: 14px; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.video-box video { width: 100%; height: 100%; object-fit: cover; display: block; }
.video-box video.mirrored { transform: scaleX(-1); }
.cam-placeholder { position: absolute; text-align: center; color: #cbe3e7; padding: 20px; }
.scan-guide {
  position: absolute; width: 200px; height: 200px;
  border: 2.5px solid var(--accent); border-radius: 16px;
  box-shadow: 0 0 0 9999px rgba(4, 22, 26, 0.38); pointer-events: none;
}
.scan-result { margin-top: 12px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: #f8fbfc; }
.scan-result.ok { background: #e3f9f1; border-color: #a3e4ce; color: #0b6e4f; }
.scan-result.warn { background: #fff5e3; border-color: #f7d594; color: #9a5b00; }
.scan-result.err { background: #feeceb; border-color: #f3b5b5; color: #b42318; }

/* RIGHT PANEL */
.right-panel {
  background: #fff; border-left: 1px solid var(--border);
  padding: 20px 18px; display: flex; flex-direction: column; gap: 16px;
}
.user-chip { display: flex; align-items: center; gap: 10px; }
.chip-avatar {
  width: 38px; height: 38px; border-radius: 12px;
  background: var(--primary); color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.user-chip strong { display: block; font-size: 13.5px; }
.user-chip span { font-size: 11.5px; color: var(--muted); }
.right-card { background: #f8fbfd; border: 1px solid var(--border); border-radius: 14px; padding: 14px; }
.cal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 13px; }
.week-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.day-pill {
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  padding: 6px 2px; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.day-pill.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.day-num { font-size: 12.5px; font-weight: 700; }
.day-name { font-size: 10px; opacity: 0.78; }
.day-dots { display: flex; gap: 2px; height: 4px; }
.day-dots span { width: 4px; height: 4px; border-radius: 50%; background: var(--accent); }

.sched-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.sched-row { display: flex; gap: 8px; align-items: center; }
.sched-time { font-size: 11px; font-weight: 700; color: var(--muted); width: 38px; }
.sched-card { flex: 1; padding: 8px 10px; border-radius: 10px; font-size: 11.5px; }
.sched-card strong { display: block; }
.sched-card.cyan { background: #e3f9f9; color: #094f54; }
.sched-card.orange { background: #fff4e2; color: #7c4600; }
.sched-card.blue { background: #eaf2ff; color: #13449c; }

.act-feed { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.act-item { display: flex; gap: 9px; align-items: flex-start; }
.act-avatar {
  width: 30px; height: 30px; border-radius: 9px; background: #e1f5f6;
  color: var(--primary); font-size: 11px; font-weight: 800;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.act-title { font-size: 12px; font-weight: 700; }
.act-time { font-size: 11px; color: var(--muted); }
.act-pill { font-size: 10.5px; color: var(--primary); background: #edf5f7; padding: 2px 7px; border-radius: 6px; display: inline-block; margin-top: 3px; }

/* MODAL, FORM & TOAST */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(7, 28, 32, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 900;
}
.modal-box {
  background: #fff; border-radius: 16px; width: 100%; max-width: 580px;
  overflow: hidden; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
}
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 18px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-field { display: flex; flex-direction: column; gap: 5px; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { font-size: 12px; font-weight: 600; color: var(--primary); }
.form-field input, .form-field select, .form-field textarea {
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 11px; background: #fff;
}
.form-field textarea { min-height: 74px; resize: vertical; }
.form-error { color: #b42318; font-size: 12.5px; margin-top: 8px; }

.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 1000;
  background: var(--primary); color: #fff; padding: 11px 16px;
  border-radius: 12px; font-size: 13px; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}
.toast.error { background: #b42318; }

/* RESPONSIVE */
@media (max-width: 1120px) {
  .app-shell { grid-template-columns: 74px 1fr; }
  .right-panel { display: none; }
}
@media (max-width: 780px) {
  .app-shell { grid-template-columns: 1fr; }
  .rail { display: none; position: fixed; left: 0; top: 0; z-index: 850; width: 74px; }
  .rail.open { display: flex; }
  .mobile-only { display: inline-flex; }
  .analytics-card, .dash-bottom, .scanner-grid, .form-grid { grid-template-columns: 1fr; }
}

/* PRINT A4 */
#print-host { display: none; }
@media print {
  body > *:not(#print-host) { display: none !important; }
  #print-host { display: block !important; background: #fff; color: #000; padding: 10mm; font-size: 11.5px; }
  #print-host table { width: 100%; border-collapse: collapse; margin-top: 8px; }
  #print-host th, #print-host td { border: 1px solid #333; padding: 5px 6px; text-align: left; }
  .qr-sheet-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .qr-print-card { border: 1px solid #333; padding: 6px; page-break-inside: avoid; }
  .qr-print-row { display: flex; gap: 8px; align-items: center; margin-top: 5px; }
  .sig-row { display: flex; justify-content: space-between; }
}