:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #16202a;
  --muted: #64707d;
  --line: #e3e7ec;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --late: #b45309;
  --late-bg: #fef3c7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --off: #64707d;
  --off-bg: #eef1f4;
  --wait-bg: #e0f2fe;
  --wait: #0369a1;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --card: #182028;
    --ink: #e6edf3;
    --muted: #93a1af;
    --line: #2a3540;
    --brand: #14b8a6;
    --brand-ink: #04211e;
    --ok: #4ade80;
    --ok-bg: #12321f;
    --late: #fbbf24;
    --late-bg: #3a2d0b;
    --bad: #f87171;
    --bad-bg: #3b1515;
    --off: #93a1af;
    --off-bg: #222c36;
    --wait-bg: #0c2a3d;
    --wait: #7dd3fc;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Malayalam", sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
}
button, input, select { font: inherit; color: inherit; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 17px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo { width: 28px; height: 28px; }

main { max-width: 980px; margin: 0 auto; padding: 14px 16px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  border: 0; background: none; padding: 8px 0 10px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; cursor: pointer;
}
.tabs button .ti { font-size: 19px; line-height: 1; }
.tabs button.on { color: var(--brand); font-weight: 600; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.card h2 { font-size: 15px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px;
  padding: 8px 12px; cursor: pointer; white-space: nowrap; min-height: 38px;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.btn.ghost { background: none; border-color: transparent; color: var(--brand); padding-left: 6px; padding-right: 6px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.icon { padding: 6px 10px; min-width: 38px; }

input[type=text], input[type=password], input[type=number], input[type=time], input[type=date], input[type=month], select {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 10px; min-height: 38px; width: 100%;
}
label.f { display: block; margin-bottom: 10px; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

.pill {
  font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--off-bg); color: var(--off); white-space: nowrap;
}
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.late { background: var(--late-bg); color: var(--late); }
.pill.wait { background: var(--wait-bg); color: var(--wait); }

.datebar { display: flex; align-items: center; gap: 6px; margin-bottom: 12px; }
.datebar input { flex: 1; text-align: center; font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px; text-align: center; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 12px; color: var(--muted); }

.person { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.person:first-of-type { border-top: 0; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 700; background: var(--off-bg); color: var(--muted);
}
.avatar.ok { background: var(--ok-bg); color: var(--ok); }
.avatar.late { background: var(--late-bg); color: var(--late); }
.avatar.bad { background: var(--bad-bg); color: var(--bad); }
.person .name { font-weight: 600; }
.time { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 17px; text-align: right; }

.banner { border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; background: var(--wait-bg); color: var(--wait); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.banner b { display: block; margin-bottom: 2px; }

.list-item { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.list-item:first-child { border-top: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: 13px;
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 4px 3px 10px; background: var(--bg);
}
.chip button { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 6px; font-size: 15px; }
.daypick { display: flex; gap: 4px; flex-wrap: wrap; }
.daypick label { border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; font-size: 13px; cursor: pointer; }
.daypick input { display: none; }
.daypick input:checked + span { color: var(--brand); font-weight: 700; }
.daypick label:has(input:checked) { border-color: var(--brand); }

.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
table.month { border-collapse: separate; border-spacing: 0; font-size: 12px; font-variant-numeric: tabular-nums; }
table.month th, table.month td { padding: 6px 5px; text-align: center; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.month th { position: sticky; top: 0; background: var(--card); font-weight: 600; color: var(--muted); }
table.month .nm {
  position: sticky; left: 0; background: var(--card); text-align: left; font-weight: 600; font-size: 13px;
  border-right: 1px solid var(--line); max-width: 120px; overflow: hidden; text-overflow: ellipsis; z-index: 1;
}
table.month th.nm { z-index: 2; }
table.month th.we { color: var(--bad); }
table.month th.today { color: var(--brand-ink); background: var(--brand); border-radius: 6px 6px 0 0; }
td.c-present { color: var(--ok); }
td.c-late { color: var(--late); background: var(--late-bg); font-weight: 700; }
td.c-absent { color: var(--bad); background: var(--bad-bg); font-weight: 700; }
td.c-off { color: var(--off); }
td.tot { font-weight: 700; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin: 8px 2px; }

dialog { border: 0; border-radius: 16px; padding: 0; width: min(440px, calc(100vw - 32px)); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog form { padding: 18px; }
dialog h3 { margin: 0 0 12px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

#toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 9px 14px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100vw - 32px); z-index: 20;
}
#toast.show { opacity: 1; }

.login { max-width: 360px; margin: 12vh auto 0; }
.steps { margin: 0; padding-left: 20px; }
.steps li { margin-bottom: 6px; }
code { background: var(--off-bg); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
details summary { cursor: pointer; color: var(--brand); font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 18px 8px; }

@media (min-width: 760px) {
  .tabs { position: sticky; top: 49px; bottom: auto; max-width: 980px; margin: 0 auto; border: 0; border-bottom: 1px solid var(--line); grid-template-columns: repeat(4, 140px); justify-content: center; }
  .tabs button { flex-direction: row; justify-content: center; gap: 6px; font-size: 14px; padding: 10px 0; }
  body { padding-bottom: 24px; }
  #toast { bottom: 24px; }
}
