:root {
  --navy: #0b2545; --navy2: #13315c; --teal: #13a3a3; --teal-d: #0e8080; --red: #e63946;
  --amber: #e9a23b; --green: #2a9d5c; --bg: #f3f6fa; --card: #fff; --text: #1b2733; --muted: #66768a; --line: #dfe5ec;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
button, input, select, textarea { font: inherit; }
[hidden] { display: none !important; }

/* header */
.topbar { background: var(--navy); color: #fff; padding: 14px 16px; display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 800; font-size: 19px; letter-spacing: .2px; }
.brand small { display: block; font-weight: 600; font-size: 10px; letter-spacing: 2.5px; color: #9fd8d8; }
.topbar .spacer { flex: 1; }
.topbar button { background: transparent; color: #cfe3f3; border: 1px solid rgba(255,255,255,.25); border-radius: 8px; padding: 6px 10px; font-size: 13px; cursor: pointer; }

main { max-width: 720px; margin: 0 auto; padding: 16px 14px 96px; }
.wide main, main.wide { max-width: 1180px; }

.card { background: var(--card); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; box-shadow: 0 1px 3px rgba(11,37,69,.08); }
.card h2 { margin: 0 0 12px; font-size: 17px; }
.card h3 { margin: 14px 0 8px; font-size: 15px; }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; }

label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--teal); border-color: transparent; }
textarea { min-height: 70px; resize: vertical; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 10px; padding: 11px 16px; font-weight: 700; cursor: pointer; background: var(--teal); color: #fff; }
.btn:hover { background: var(--teal-d); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.ghost { background: #eef3f8; color: var(--navy); }
.btn.danger { background: var(--red); }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn.navy { background: var(--navy2); }

/* login */
.login-wrap { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px; background: linear-gradient(160deg, var(--navy) 0 45%, var(--bg) 45%); }
.login-wrap .card { max-width: 400px; width: 100%; margin: 0 auto; padding: 26px 22px; }
.login-logo { text-align: center; color: #fff; margin-bottom: 22px; }
.login-logo .brand { font-size: 30px; }
.login-logo .brand small { font-size: 12px; }
.err { color: var(--red); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* status / big button */
.hello { font-size: 20px; font-weight: 800; margin: 0; }
.today { color: var(--muted); font-size: 14px; }
.status { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 12px; background: #f1f5f9; margin: 14px 0; }
.status .dot { width: 12px; height: 12px; border-radius: 50%; background: #a8b4c2; flex: none; }
.status.in .dot { background: var(--green); }
.status.done .dot { background: var(--navy2); }
.status b { display: block; }
.bigbtn { width: 100%; padding: 22px; font-size: 20px; border-radius: 16px; }
.bigbtn.out { background: var(--navy2); }
.timeline { margin: 12px 0 0; padding: 0; list-style: none; }
.timeline li { padding: 10px 0; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: space-between; font-size: 14px; }

.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: #e6eef6; color: var(--navy2); vertical-align: middle; }
.badge.late, .badge.rejected { background: #fde8ea; color: var(--red); }
.badge.ok, .badge.approved, .badge.office { background: #e3f5ec; color: var(--green); }
.badge.pending, .badge.site { background: #fdf2e0; color: #a86b10; }
.badge.leave { background: #e9e6fb; color: #5a49c4; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: #f1f5f9; border-radius: 12px; padding: 12px; text-align: center; }
.stat b { display: block; font-size: 24px; color: var(--navy); }
.stat span { font-size: 12px; color: var(--muted); }

.list-item { padding: 12px 0; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; }
.list-item:first-child { border-top: 0; }

/* bottom nav */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--line); display: flex; z-index: 20; padding-bottom: env(safe-area-inset-bottom); }
.tabbar button { flex: 1; background: none; border: 0; padding: 10px 4px 12px; color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer; }
.tabbar button .ic { display: block; font-size: 20px; line-height: 1.2; }
.tabbar button.active { color: var(--teal-d); }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(8,20,36,.55); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.modal .sheet { background: #fff; width: 100%; max-width: 520px; max-height: 94vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 20px 18px 24px; }
@media (min-width: 700px) { .modal { align-items: center; } .modal .sheet { border-radius: 18px; } }
.sheet h2 { margin: 0 0 6px; }
.cam { position: relative; background: #000; border-radius: 12px; overflow: hidden; aspect-ratio: 3/4; max-height: 40vh; max-width: 30vh; margin: 10px auto; }
.cam video, .cam img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam video { transform: scaleX(-1); }
.locbox { padding: 12px; border-radius: 10px; background: #f1f5f9; font-size: 14px; }

#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); background: var(--navy); color: #fff; padding: 11px 18px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .25s; z-index: 99; max-width: 90vw; font-size: 14px; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.error { background: var(--red); }

/* admin */
.admin-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.admin-tabs button { border: 0; background: #fff; padding: 9px 14px; border-radius: 10px; font-weight: 700; color: var(--navy2); cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.admin-tabs button.active { background: var(--navy2); color: #fff; }
.admin-tabs .count { background: var(--red); color: #fff; border-radius: 99px; font-size: 11px; padding: 1px 7px; margin-left: 4px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); background: #f8fafc; }
.table-wrap { overflow-x: auto; }
.thumb { width: 46px; height: 46px; border-radius: 8px; object-fit: cover; cursor: zoom-in; background: #e6eef6; }
.selfie-big { width: 100%; border-radius: 12px; }
.toolbar { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar > div { min-width: 160px; }
.code-LT { color: var(--red); font-weight: 700; }
.code-A, .code-LWP { color: var(--red); }
.code-L { color: #5a49c4; font-weight: 700; }
.code-S, .code-H, .code--, .code-\? { color: #a8b4c2; }
.register td, .register th { padding: 5px 4px; text-align: center; font-size: 12px; }
.register td:first-child, .register th:first-child { text-align: left; white-space: nowrap; }
a { color: var(--teal-d); }

/* ---------- admin on phones ---------- */
@media (max-width: 700px) {
  .wide main, main.wide { padding: 12px 10px 40px; }
  #admin-email { display: none; }
  .admin-tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; margin: 0 -10px 12px; padding-left: 10px; padding-right: 10px; }
  .admin-tabs button { flex: none; white-space: nowrap; }
  .card { padding: 14px; }
  .toolbar > div { min-width: 0; flex: 1 1 100%; }
  .toolbar .btn { flex: 1; }
  #day-stats { grid-template-columns: repeat(2, 1fr) !important; }
  /* daily attendance: one card per employee */
  #day-table, #day-table tbody, #day-table tr, #day-table td { display: block; width: 100%; }
  #day-table tr:first-child { display: none; }
  #day-table tr { position: relative; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; }
  #day-table td { border: 0; padding: 4px 0; }
  #day-table td:empty, #day-table td[data-label="Hours"]:empty { display: none; }
  #day-table td.c-name { padding-right: 70px; }
  #day-table td.c-edit { position: absolute; top: 8px; right: 10px; width: auto; }
  #day-table td[data-label]::before { content: attr(data-label); display: inline-block; width: 52px; font-size: 12px; font-weight: 700; color: var(--muted); vertical-align: top; }
  #day-table td[data-label] { overflow: hidden; }
  .list-item { flex-wrap: wrap; }
}
.topbar .topbtn { color: #cfe3f3; border: 1px solid rgba(255,255,255,.25); border-radius: 8px; padding: 6px 10px; font-size: 13px; text-decoration: none; }
.topbar .topbtn:hover { background: rgba(255,255,255,.08); }
.err a { color: var(--teal-d); font-weight: 700; }
