:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1c2530;
  --muted: #667380;
  --line: #dde3e9;
  --primary: #0b6e6e;
  --primary-ink: #ffffff;
  --draft: #8a96a3;
  --submitted: #2563c9;
  --approved: #1e8a4c;
  --rejected: #c93030;
  --late: #b45309;
  --c-present: #2a9d56;
  --c-halfday: #f7d43c;
  --c-off: #1a1a1a;
  --c-ph: repeating-linear-gradient(45deg, #1a1a1a 0 9px, #d63232 9px 13px);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; }
h2 { font-size: 1.15rem; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* Shown while waiting for the database */
body.busy { cursor: progress; }
body.busy::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 40%;
  background: #f5b942;
  z-index: 30;
  animation: busy 1s linear infinite;
}
@keyframes busy { from { left: -40%; } to { left: 100%; } }

/* Header */
.top {
  background: var(--primary);
  color: var(--primary-ink);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.top h1 { font-size: 1.1rem; }
.top .who { font-size: 0.85rem; opacity: 0.9; }
.top .right { display: flex; gap: 6px; align-items: center; }
.top button { background: rgba(255, 255, 255, 0.15); color: #fff; border: 0; }
.tabs { background: #fff; border-bottom: 1px solid var(--line); display: flex; overflow-x: auto; padding: 0 8px; }
.tabs button { border: 0; background: none; border-radius: 0; padding: 12px 14px; color: var(--muted); border-bottom: 3px solid transparent; }
.tabs button.on { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

main { max-width: 960px; margin: 0 auto; padding: 16px; }
main.narrow { max-width: 560px; }

/* Controls */
button, .btn {
  font: inherit;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  min-height: 42px;
}
button.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); font-weight: 600; }
button.danger { color: var(--rejected); border-color: var(--rejected); }
button.ok { color: var(--approved); border-color: var(--approved); }
button.fill-blue { background: #a8d4f7; border-color: #8ec3ee; color: #12314d; }
button.fill-red { background: var(--rejected); border-color: var(--rejected); color: #fff; }
button.sm { padding: 6px 10px; min-height: 34px; font-size: 0.85rem; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.block { display: block; width: 100%; }
input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
label { display: block; font-size: 0.85rem; color: var(--muted); margin: 10px 0 4px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.card + .card { margin-top: 12px; }
.error { color: var(--rejected); font-size: 0.9rem; min-height: 1.2em; }
.banner { border-radius: 10px; padding: 10px 12px; font-size: 0.9rem; background: #e8eef5; }
/* Label and number in two columns so the numbers line up */
.tally { display: inline-grid; grid-template-columns: auto auto; column-gap: 14px; font-variant-numeric: tabular-nums; }
.tally span:nth-child(even) { text-align: right; }
.countdown { color: var(--rejected); white-space: nowrap; font-variant-numeric: tabular-nums; }
.banner.late { background: #fdf0dc; color: #7a3d05; }
.banner.rejected { background: #fde8e8; color: #8f1d1d; }
.banner.approved { background: #e3f4ea; color: #14633a; }

/* Login */
.login { max-width: 400px; margin: 8vh auto 0; padding: 16px; }
.login h1 { margin-bottom: 4px; }
.demo button { text-align: left; }

/* Month nav */
.monthnav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.monthnav h2 { text-align: center; flex: 1; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.chip { background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: 0.82rem; }

.chip.alert { background: var(--rejected); border-color: var(--rejected); color: #fff; }
.chip.clear { background: var(--approved); border-color: var(--approved); color: #fff; }

/* Calendar */
/* Five weekday columns, a narrow divider column, then the two weekend columns */
.cal { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)) 9px repeat(2, minmax(0, 1fr)); gap: 3px; }
.cal .wkline { grid-column: 6; justify-self: center; width: 2px; border-radius: 1px; background: #b6bec7; }
.cal .dow { text-align: center; font-size: 0.72rem; color: var(--muted); padding: 2px 0; }
.day {
  min-height: 64px;
  padding: 4px 0;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  border: 1px solid var(--line);
  background: #fff;
  overflow: hidden;
}
.day .n { font-size: 0.75rem; color: var(--muted); }
/* Sized so the full word (PRESENT, HALFDAY) fits a phone-width cell */
.day .st { font-weight: 700; font-size: clamp(7px, 2.3vw, 0.85rem); white-space: nowrap; }
.day .pj { font-size: 0.62rem; color: var(--muted); line-height: 1.1; text-align: center; word-break: break-all; }
.cal .dow, .day .n, .day .pj, .day .hn, .legend { font-weight: 700; }
/* Days picked while selecting several to fill at once */
.day { position: relative; }
.day.picked { outline: 3px solid #2563c9; outline-offset: -3px; box-shadow: 0 0 0 2px #2563c9; }
.day .tick {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 1.3em;
  height: 1.3em;
  border-radius: 50%;
  background: #2563c9;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 800;
  line-height: 1.3em;
  text-align: center;
  text-shadow: none;
  z-index: 1;
}
.selbar { background: #e8f0fc; border: 1px solid #b9d0f5; border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
/* Caution mark on days that have not been filled in */
.day .warn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.4em;
  height: 1.4em;
  border-radius: 50%;
  background: #f5b942;
  color: #1c2530;
  font-weight: 800;
  font-size: 0.72rem;
}
.tag.e-contract { background: #2a9d56; color: #fff; }
.tag.e-freelance { background: #f7d43c; color: #1c2530; }
.tag.e-perm { background: #2563c9; color: #fff; }
/* Holiday name under PH: wraps between words so long names stay inside the cell */
.day .hn { display: block; font-size: clamp(6px, 1.9vw, 0.62rem); line-height: 1.15; text-align: center; padding: 0 1px 2px; word-break: normal; overflow-wrap: anywhere; }
.day.today { outline: 2px solid var(--primary); outline-offset: -2px; }
.day.hol .n { color: var(--rejected); font-weight: 700; }
/* A ribbon across the top of each filled day says whether it is draft, submitted, approved or rejected */
.rib {
  align-self: stretch;
  margin-top: -4px;
  color: #fff;
  font-weight: 700;
  font-size: clamp(6px, 1.9vw, 0.62rem);
  line-height: 1.6;
  text-align: center;
  text-shadow: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.7);
}
.rib.r-draft { background: var(--draft); }
.rib.r-submitted { background: #a8d4f7; color: #12314d; }
.rib.r-approved { background: #0b6b33; }
.rib.r-rejected { background: var(--rejected); }
.day.s-rejected { outline: 3px solid var(--rejected); outline-offset: -3px; }

/* Fill colour shows the attendance status */
.day.na { background: #c5ccd3; color: #56616c; }
.day.na .n { color: inherit; }
.day.d-P { background: var(--c-present); color: #fff; }
.day.d-H { background: var(--c-halfday); color: #1c2530; }
.day.d-O { background: var(--c-off); color: #fff; }
.day.d-PH { background: var(--c-ph); color: #fff; text-shadow: 0 0 3px #000, 0 0 2px #000; }
.day.d-P .n, .day.d-H .n, .day.d-O .n, .day.d-PH .n,
.day.d-P .pj, .day.d-H .pj, .day.d-O .pj, .day.d-PH .pj { color: inherit; }
.day.d-P.today, .day.d-H.today, .day.d-O.today, .day.d-PH.today { outline-color: #f5b942; }
.day.locked { cursor: default; }
.day.future { opacity: 0.4; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 0.78rem; color: var(--muted); margin: 10px 0; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; }

/* Badges */
.badge { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 0.78rem; font-weight: 600; color: #fff; background: var(--draft); white-space: nowrap; }
.badge.pending, .badge.submitted { background: var(--submitted); }
.badge.approved { background: var(--approved); }
.badge.rejected { background: var(--rejected); }
.badge.late { background: var(--late); }
.badge.off { background: #b6bec7; }

/* Lists and tables */
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  width: 100%;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.item .name { font-weight: 600; }
/* Engagement type next to a name */
.tag { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px; background: #e8eef5; color: #3d4b59; font-size: 0.75rem; font-weight: 600; vertical-align: middle; white-space: nowrap; }
.ld { display: grid; grid-template-columns: 3.7em 0.9em auto; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ldnote { display: block; font-size: 0.75rem; color: var(--rejected); line-height: 1.2; }
.chk { width: 20px; height: 20px; margin: 0; accent-color: var(--primary); cursor: pointer; }
.dayrow { display: grid; grid-template-columns: 20px 7.6em 1fr auto; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.dayrow:last-child { border-bottom: 0; }
.dayrow .acts { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; }
tr.inactive td { color: var(--muted); }
td.nw, span.nw { white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
/* Compact month summary at the top of Monthly Attendance */
.summary { padding: 10px 14px; margin-bottom: 14px; }
.sumrow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.sumrow + .sumrow { margin-top: 8px; }
.summary .chip { background: #f1f5f9; }
tr.total td { font-weight: 700; border-top: 2px solid var(--line); background: #f8fafc; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f1f5f9; }
/* Status label on the Daily attendance tab, in the same colours as the calendar */
.pill { display: inline-block; border-radius: 6px; padding: 2px 10px; font-size: 0.78rem; font-weight: 700; white-space: nowrap; }
.pill.d-P { background: var(--c-present); color: #fff; }
.pill.d-H { background: var(--c-halfday); color: #1c2530; }
.pill.d-O { background: var(--c-off); color: #fff; }
.pill.d-PH { background: var(--c-ph); color: #fff; text-shadow: 0 0 3px #000, 0 0 2px #000; }
.pill.blank { background: #fff; color: var(--late); border: 1px solid #f5b942; }

/* Status picker */
.pick { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.pick.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.pick button { padding: 10px 2px; font-size: clamp(11px, 3.4vw, 1rem); }
.pick button.on { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 10px; color: var(--ink); font-size: 0.95rem; }
.check input { width: auto; }

/* Tick list of admins when choosing backup admins */
.bklist { border: 1px solid var(--line); border-radius: 8px; padding: 2px 10px 10px; max-height: 220px; overflow-y: auto; }

/* Modal and toast */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 32, 0.5); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet { background: #fff; width: 100%; max-width: 480px; max-height: 92vh; overflow-y: auto; border-radius: 16px 16px 0 0; padding: 18px 16px 22px; }
@media (min-width: 600px) {
  .modal { align-items: center; }
  .sheet { border-radius: 16px; }
}
.sheet h2 { margin-bottom: 8px; }
.sheet .foot { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.sheet .foot button { flex: 1; }
.temp { font: 600 1.3rem ui-monospace, Consolas, monospace; background: #f1f4f7; padding: 10px; border-radius: 8px; text-align: center; letter-spacing: 1px; user-select: all; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1c2530; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 0.9rem; z-index: 20; max-width: 90vw; }
