:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --line: #e3e7ec;
  --brand: #0f4c81;
  --brand-ink: #ffffff;
  --ok: #157f3b;
  --ok-bg: #e6f4ea;
  --warn: #9a5b00;
  --warn-bg: #fff4dc;
  --bad: #b42318;
  --bad-bg: #fde8e7;
  --info: #175cd3;
  --info-bg: #e8f0fe;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.2; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
a { color: var(--brand); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* Borang */
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .25rem; }
input, select, textarea, button { font: inherit; }
input, select, textarea {
  width: 100%;
  padding: .55rem .7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
input[type=checkbox] { width: auto; }
button, .btn {
  display: inline-block;
  padding: .55rem 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}
button:hover { filter: brightness(.97); }
button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
button.danger { color: var(--bad); }
button.link { border: 0; background: none; padding: 0; color: var(--brand); text-decoration: underline; }
button:disabled { opacity: .6; cursor: default; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.grid { display: grid; gap: .75rem; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 160px; }
.row > button { flex: 0 0 auto; }

/* Mesej */
.msg { padding: .8rem 1rem; border-radius: 8px; margin: .75rem 0; }
.msg.ok { background: var(--ok-bg); color: var(--ok); }
.msg.warn { background: var(--warn-bg); color: var(--warn); }
.msg.bad { background: var(--bad-bg); color: var(--bad); }

/* Lencana status */
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.mute { background: #eef0f3; color: var(--muted); }

/* Jadual */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tfoot td { font-weight: 700; }
.empty { color: var(--muted); padding: .5rem 0; }

/* ---------- Kiosk ---------- */
.kiosk { max-width: 460px; margin: 0 auto; padding: 24px 16px 40px; }
.kiosk .brand { text-align: center; margin-bottom: 1rem; }
.kiosk .brand h1 { color: var(--brand); font-size: 1.6rem; letter-spacing: .04em; margin: 0; }
.kiosk .clock { text-align: center; margin: 1rem 0 1.25rem; }
.kiosk .clock .time { font-size: 3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kiosk .clock .date { color: var(--muted); }
.kiosk .actions { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-top: 1rem; }
.kiosk .actions button { padding: 1rem; font-size: 1.1rem; font-weight: 700; border: 0; color: #fff; }
.kiosk .btn-in { background: var(--ok); }
.kiosk .btn-out { background: #c2410c; }
.kiosk .pin { font-size: 1.4rem; letter-spacing: .3em; text-align: center; }
.kiosk .camera { position: relative; margin-top: .9rem; aspect-ratio: 4 / 3; background: #111; border-radius: 8px; overflow: hidden; }
.kiosk .camera video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; }
.kiosk .cam-status { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 1rem; text-align: center; color: #fff; background: rgba(0,0,0,.6); }
.kiosk .gps-status { margin-top: .4rem; }
.kiosk .gps-status.ok { color: var(--ok); }
.kiosk .gps-status.bad { color: var(--bad); }
.kiosk footer { text-align: center; margin-top: 1.5rem; }

/* ---------- Admin ---------- */
.topbar { background: var(--brand); color: var(--brand-ink); }
.topbar .inner { max-width: 1200px; margin: 0 auto; padding: .75rem 16px; display: flex; align-items: center; gap: 1rem; }
.topbar h1 { font-size: 1.1rem; margin: 0; flex: 1; }
.topbar button { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); padding: .35rem .8rem; }
.tabs { background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2; }
.tabs .inner { max-width: 1200px; margin: 0 auto; padding: 0 8px; display: flex; overflow-x: auto; }
.tabs button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; padding: .8rem .9rem; white-space: nowrap; color: var(--muted); }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
main.admin { max-width: 1200px; margin: 0 auto; padding: 16px; }
.login { max-width: 340px; margin: 12vh auto; padding: 0 16px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; cursor: default; }
.stat .n { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: .85rem; }
.stat.ok .n { color: var(--ok); }
.stat.warn .n { color: var(--warn); }
.stat.bad .n { color: var(--bad); }
.stat.info .n { color: var(--info); }

.sections { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }
.sections .card { margin: 0; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: .5rem; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }

.att-cell { display: flex; gap: .5rem; align-items: flex-start; min-width: 260px; }
.att-cell input { margin-bottom: .25rem; }
img.selfie { width: 52px; height: 52px; object-fit: cover; border-radius: 6px; background: #ddd; cursor: zoom-in; flex: 0 0 auto; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.8); display: flex; align-items: center; justify-content: center; z-index: 10; cursor: zoom-out; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
code { background: #eef0f3; padding: 0 .3em; border-radius: 4px; }

.toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: end; margin-bottom: 1rem; }
.toolbar > div { min-width: 150px; }

@media print {
  .topbar, .tabs, .toolbar, .no-print { display: none !important; }
  body { background: #fff; }
  .card { border: 0; padding: 0; }
}
