/* Staff Attendance Portal - red & white theme. All same-origin, no inline styles (CSP-safe). */
:root {
  --red: #B91C1C; --red-dark: #991B1B; --red-deep: #7F1D1D; --red-tint: #FEF2F2; --red-line: #FECACA;
  --bg: #F6F6F7; --card: #FFFFFF; --line: #E6E7EA; --text: #1B1D21; --muted: #666B75;
  --ok: #138A4B; --ok-bg: #E3F5EB; --warn: #9A6200; --warn-bg: #FFF0CF; --bad: #B4171C; --bad-bg: #FDE4E4; --off-bg: #ECEDF0;
  --side-w: 244px; --av: 40px; --radius: 12px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
a { color: var(--red-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
:focus-visible { outline: 3px solid rgba(185,28,28,.35); outline-offset: 2px; }

/* ---------- layout: fixed sidebar, scrolling content ---------- */
.side { position: fixed; top: 0; left: 0; bottom: 0; width: var(--side-w); background: var(--red); color: #fff; display: flex; flex-direction: column; padding: 22px 14px 16px; overflow-y: auto; z-index: 30; }
.brand { font-weight: 700; font-size: 18px; line-height: 1.25; padding: 2px 10px 20px; letter-spacing: .1px; }
.brand small { display: block; font-weight: 500; font-size: 12.5px; color: rgba(255,255,255,.88); margin-top: 3px; }
.side nav { display: flex; flex-direction: column; gap: 3px; }
.side nav a { display: block; color: #fff; font-weight: 500; padding: 10px 12px; border-radius: 9px; text-decoration: none; }
.side nav a:hover { background: rgba(0,0,0,.14); }
.side nav a.on { background: #fff; color: var(--red-dark); font-weight: 700; }
.side nav .sec { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .09em; color: rgba(255,255,255,.9); margin: 18px 12px 6px; }
.side nav .sec:first-child { margin-top: 0; }
.side .me { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid rgba(255,255,255,.3); font-size: 13.5px; }
.side .me b { display: block; font-weight: 600; }
.side .me .role { color: rgba(255,255,255,.88); }
.logout { margin-top: 10px; }
/* ---------- icons ---------- */
.ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.side nav a { display: flex; align-items: center; gap: 12px; }
.side nav a .ic { opacity: .92; }
.side nav a.on .ic { opacity: 1; }
.side .btn.sec .ic { width: 16px; height: 16px; margin: -3px 6px -3px -2px; vertical-align: middle; }

/* ---------- mobile top bar + drawer pieces (hidden on desktop; enabled in the max-width:900px block) ---------- */
.topbar { display: none; position: sticky; top: 0; z-index: 40; height: 56px; align-items: center; gap: 6px; padding: 0 14px 0 6px; background: var(--red); color: #fff; box-shadow: 0 1px 0 rgba(0,0,0,.15); }
.topbar-title { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 10px; background: transparent; color: #fff; cursor: pointer; flex: none; }
.icon-btn:hover { background: rgba(0,0,0,.16); }
.icon-btn .ic { width: 24px; height: 24px; }
.icon-btn:focus-visible, .side a:focus-visible, .side button:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.side-close { display: none; position: absolute; top: 10px; right: 10px; }
.scrim { display: none; position: fixed; inset: 0; z-index: 50; background: rgba(15, 5, 5, .6); opacity: 0; visibility: hidden; transition: opacity .26s ease, visibility 0s linear .26s; }
@media (prefers-reduced-motion: reduce) { .js .side, .scrim { transition: none !important; } }

.side .btn.sec { background: transparent; color: #fff; border-color: rgba(255,255,255,.7); }
.side .btn.sec:hover { background: rgba(0,0,0,.14); }
.main { margin-left: var(--side-w); min-height: 100vh; display: flex; flex-direction: column; min-width: 0; }
.content { padding: 30px 36px 24px; flex: 1; width: 100%; max-width: 1280px; }
.footer { text-align: center; color: var(--muted); font-size: 12.5px; padding: 16px; border-top: 1px solid var(--line); background: #fff; }
.footer b { color: var(--red-dark); letter-spacing: .03em; }

/* ---------- type & cards ---------- */
h1 { margin: 0 0 4px; font-size: 26px; line-height: 1.2; letter-spacing: -.2px; }
.sub { color: var(--muted); margin: 0 0 22px; }
.muted { color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 20px; box-shadow: 0 1px 2px rgba(20,20,30,.04); }
.card h2 { margin: 0 0 14px; font-size: 16px; }
.card.flush { padding: 0; overflow-x: auto; }
.grid { display: grid; gap: 16px; }
.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 22px; }
.stat { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px 16px; overflow: hidden; box-shadow: 0 1px 2px rgba(20,20,30,.04); }
.stat::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px; background: var(--line); }
.stat .l { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .n { font-size: 34px; font-weight: 700; line-height: 1.15; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .s { color: var(--muted); font-size: 12.5px; min-height: 18px; }
.stat.tot::before { background: var(--red); } .stat.ok::before { background: #1FAE67; } .stat.warn::before { background: #F0A30A; } .stat.bad::before { background: var(--bad); }
.stat.ok .n { color: var(--ok); } .stat.warn .n { color: var(--warn); } .stat.bad .n { color: var(--bad); }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 12px 16px; background: #FAFAFB; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 0 16px; height: 60px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #FFF8F8; }
tfoot th { background: #FAFAFB; border-top: 1px solid var(--line); border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.actions { white-space: nowrap; }
.who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.who b { font-weight: 600; white-space: nowrap; }
.card.flush > table { min-width: 640px; }

/* ---------- avatars: one size, round, photo or initials ---------- */
.avatar { width: var(--av); height: var(--av); min-width: var(--av); border-radius: 50%; flex: none; display: inline-flex; align-items: center; justify-content: center;
  object-fit: cover; font-size: 14px; font-weight: 700; line-height: 1; color: #fff; background: #8B93A1; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); user-select: none; overflow: hidden; }
.avatar.xl { --av: 88px; font-size: 28px; }
.avatar[hidden] { display: none; }
.avatar.c0, .pcard-ph.c0 { background: #9F1239; } .avatar.c1, .pcard-ph.c1 { background: #1F8A5B; } .avatar.c2, .pcard-ph.c2 { background: #B7791F; }
.avatar.c3, .pcard-ph.c3 { background: #6B4FB8; } .avatar.c4, .pcard-ph.c4 { background: #2D6CC0; } .avatar.c5, .pcard-ph.c5 { background: #4A5568; }
.photo-row { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }

/* ---------- badges ---------- */
.pill { display: inline-block; padding: 3px 12px; border-radius: 99px; font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.pill.Present, .pill.on { background: var(--ok-bg); color: var(--ok); }
.pill.Late { background: var(--warn-bg); color: var(--warn); }
.pill.Absent, .pill.off { background: var(--bad-bg); color: var(--bad); }
.pill.Off { background: var(--off-bg); color: var(--muted); }

/* ---------- forms & buttons ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar .sp { flex: 1; }
input[type=text], input[type=password], input[type=date], input[type=month], input[type=time], input[type=number], select, input[type=file] {
  padding: 9px 11px; border: 1px solid #CDD0D6; border-radius: 9px; font: inherit; background: #fff; color: var(--text); max-width: 100%; }
input:focus, select:focus { outline: 0; border-color: var(--red); box-shadow: 0 0 0 3px rgba(185,28,28,.18); }
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
.field { margin-bottom: 16px; }
.field input[type=text], .field input[type=password], .field input[type=time], .field input[type=number], .field select { width: 100%; max-width: 420px; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.chk { display: inline-flex; align-items: center; gap: 6px; margin-right: 14px; font-weight: 500; }
.btn { display: inline-block; background: var(--red); color: #fff; border: 1px solid var(--red); padding: 9px 16px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1.3; }
.btn:hover { background: var(--red-dark); border-color: var(--red-dark); text-decoration: none; }
.btn.sec { background: #fff; color: var(--text); border-color: #CDD0D6; } .btn.sec:hover { background: #F4F4F6; }
.btn.sm { padding: 5px 11px; font-size: 13px; }
.btn.danger { background: #fff; color: var(--bad); border-color: var(--red-line); } .btn.danger:hover { background: var(--red-tint); }
.btn.block { width: 100%; }
.inline { display: inline; }
.pw-input { width: 140px; padding: 5px 8px !important; }
.alert { padding: 12px 16px; border-radius: 9px; margin-bottom: 18px; border: 1px solid transparent; }
.alert.ok { background: var(--ok-bg); color: #0B5F33; border-color: #BFE6CF; } .alert.err { background: var(--bad-bg); color: #8C1115; border-color: var(--red-line); }
.sum { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin: 14px 0; }
.sum div { background: #FAFAFB; border: 1px solid var(--line); border-radius: 10px; padding: 14px; color: var(--muted); font-size: 13px; }
.sum b { display: block; font-size: 28px; color: var(--text); line-height: 1.2; }
.sum .a b { color: var(--ok); } .sum .d b { color: var(--warn); } .sum .i b { color: var(--bad); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; flex-direction: column; background: var(--red); }
.login-box { margin: auto; width: calc(100% - 32px); max-width: 390px; background: #fff; border-radius: 14px; padding: 34px 30px; box-shadow: 0 20px 50px rgba(60,0,0,.4); border-top: 6px solid var(--red-deep); }
.login-box h1 { font-size: 22px; } .login-box .field input { max-width: none; }
.login-wrap .footer { background: transparent; border: 0; color: rgba(255,255,255,.9); } .login-wrap .footer b { color: #fff; }

/* ---------- tablet ---------- */
@media (max-width: 1100px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } .sum { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---------- phone / small tablet: top bar + stacked-card tables ---------- */
@media (max-width: 900px) {
  /* Without JS the sidebar just stacks above the content (still usable). */
  .side { position: static; width: auto; bottom: auto; overflow: visible; }
  .side nav { flex-direction: row; flex-wrap: wrap; }
  .main { margin-left: 0; min-height: 0; }
  /* With JS: slim top bar + slide-in drawer + dimmed overlay. */
  .js .topbar { display: flex; }
  .js .side { position: fixed; top: 0; bottom: 0; left: 0; width: min(84vw, 310px); overflow-y: auto; z-index: 60; transform: translateX(-100%); visibility: hidden;
    transition: transform .26s ease, visibility 0s linear .26s; }
  .js .side nav { flex-direction: column; flex-wrap: nowrap; }
  .js .side nav a { padding: 13px 14px; }
  .js .side .brand { padding-right: 52px; }
  .js .side-close { display: inline-flex; }
  .js .scrim { display: block; }
  .js body.nav-open .side { transform: none; visibility: visible; transition: transform .26s ease, visibility 0s; box-shadow: 8px 0 40px rgba(0,0,0,.45); }
  .js body.nav-open .scrim { opacity: 1; visibility: visible; transition: opacity .26s ease, visibility 0s; }
  .js body.nav-open { overflow: hidden; }
  .content { padding: 20px 16px 16px; }
  h1 { font-size: 22px; }
}
@media (max-width: 720px) {
  .toolbar > * { flex: 0 1 auto; } .toolbar .sp { display: none; }
  .toolbar select, .toolbar input[type=date], .toolbar input[type=month] { flex: 1 1 140px; }
  .card.flush { background: transparent; border: 0; box-shadow: none; overflow: visible; }
  .card.flush > table { min-width: 0; }
  table.stack, table.stack tbody, table.stack tfoot { display: block; }
  table.stack thead { display: none; }
  table.stack tr { display: flex; flex-direction: column; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 14px 8px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(20,20,30,.04); }
  table.stack td { display: flex; justify-content: space-between; align-items: center; gap: 12px; height: auto; min-height: 36px; padding: 6px 0; border-bottom: 1px dashed var(--line); text-align: right; }
  table.stack td:last-child { border-bottom: 0; }
  table.stack td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; text-align: left; flex: none; }
  table.stack td.name-cell { display: block; order: -1; padding: 8px 0 10px; border-bottom: 1px solid var(--line); text-align: left; }
  table.stack td.name-cell::before { content: none; }
  table.stack td.name-cell .who b { font-size: 16px; white-space: normal; }
  table.stack td.actions { flex-wrap: wrap; justify-content: flex-end; }
  table.stack tfoot tr { display: flex; flex-wrap: wrap; gap: 6px 16px; background: var(--red-tint); border-color: var(--red-line); padding: 10px 14px; }
  table.stack tfoot th { display: block; background: transparent; border: 0; padding: 0; }
  table.stack tfoot th[colspan] { flex: 1 0 100%; }
  tbody tr:hover { background: #fff; }
  .stat .n { font-size: 28px; }
}
@media (max-width: 420px) { .stats { gap: 10px; } .stat { padding: 14px; } .stat .l { font-size: 11.5px; } .sum { gap: 10px; } .login-box { padding: 28px 22px; } }
.photo-row > div { min-width: 0; flex: 1 1 200px; }
.photo-row input[type=file] { width: 100%; }

/* ---------- clickable people, late-deduction tags, the "Adjust" panel ---------- */
a.person-link { color: inherit; cursor: zoom-in; border-radius: 8px; }
a.person-link:hover { text-decoration: none; }
a.person-link:hover b { text-decoration: underline; text-decoration-color: var(--red); text-underline-offset: 3px; }
.ded { color: var(--bad); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ded.waived { color: var(--ok); }
.ded.zero { color: var(--muted); font-weight: 600; }
.adj { display: inline-block; margin-left: 8px; vertical-align: middle; }
.adj > summary { display: inline-block; cursor: pointer; list-style: none; user-select: none; font-size: 12.5px; font-weight: 600; color: var(--red-dark); padding: 2px 10px; border: 1px solid var(--red-line); border-radius: 99px; background: #fff; }
.adj > summary::-webkit-details-marker { display: none; }
.adj > summary:hover, .adj[open] > summary { background: var(--red-tint); }
.adj form { margin-top: 8px; padding: 10px 12px 12px; background: #FAFAFB; border: 1px solid var(--line); border-radius: 10px; width: min(300px, calc(100vw - 72px)); text-align: left; white-space: normal; }
.adj label { font-size: 12.5px; margin: 8px 0 0; }
.adj input[type=text] { display: block; width: 100%; margin-top: 3px; }
.adj-title { margin: 0; font-size: 12.5px; color: var(--muted); }
.adj-note, .adj-who { margin: 6px 0 0; font-size: 12.5px; color: var(--warn); line-height: 1.35; }
.adj-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
td.ded-cell { padding-top: 8px; padding-bottom: 8px; }

/* ---------- the person popup (lightbox): X button, Esc or a click outside closes it; a bottom sheet on a phone ---------- */
.pmodal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(15, 5, 5, .62); }
.pmodal[hidden] { display: none; }
.pmodal-box { position: relative; display: flex; flex-direction: column; width: min(560px, 100%); max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px); overflow: hidden; background: #fff; border-radius: 16px; box-shadow: 0 24px 60px rgba(0, 0, 0, .45); outline: 0; }
.pmodal-body { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.pmodal-x { position: absolute; top: 10px; right: 10px; z-index: 3; display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .94); color: var(--text); box-shadow: 0 1px 5px rgba(0, 0, 0, .35); cursor: pointer; }
.pmodal-x:hover { background: var(--red-tint); color: var(--red-dark); }
.pmodal-x .ic { width: 22px; height: 22px; }
.pmodal-loading { padding: 70px 20px; text-align: center; color: var(--muted); }
.pmodal-notice { margin: 0; border-radius: 0; padding-right: 64px; }
body.pmodal-open { overflow: hidden; }

.pcard-top { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; padding: 30px 20px 16px; background: linear-gradient(var(--red-tint), #fff); }
.pcard-photo { display: block; width: min(256px, 64vw); height: min(256px, 64vw); border-radius: 18px; object-fit: cover; background: #ECEDF0; box-shadow: 0 0 0 1px var(--line), 0 8px 24px rgba(0, 0, 0, .18); }
.pcard-ph { display: flex; align-items: center; justify-content: center; font-size: clamp(54px, 17vw, 88px); font-weight: 700; letter-spacing: 2px; color: #fff; user-select: none; }
.pcard-id h2 { margin: 0 0 6px; font-size: 22px; line-height: 1.2; overflow-wrap: anywhere; }
.pcard-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; margin: 0; padding: 8px 22px 6px; }
.pcard-facts > div { min-width: 0; }
.pcard-facts dt { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.pcard-facts dd { margin: 2px 0 0; font-weight: 600; overflow-wrap: anywhere; }
.pcard-sec { margin-top: 12px; padding: 14px 22px 6px; border-top: 1px solid var(--line); }
.pcard-sec h3 { margin: 0 0 10px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text); }
.pcard-sec h3 .muted { text-transform: none; letter-spacing: 0; font-weight: 500; }
.pcard-day { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; }
.pcard-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.pcard-stats > div { background: #FAFAFB; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.pcard-stats b { display: block; font-size: 21px; line-height: 1.2; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.pcard-stats span { font-size: 12px; color: var(--muted); }
.pcard-late { list-style: none; margin: 12px 0 0; padding: 0; }
.pcard-late > li { padding: 9px 0; border-bottom: 1px dashed var(--line); }
.pcard-late > li:last-child { border-bottom: 0; }
.pcard-late-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
.pcard-late-row .adj { margin-left: auto; }
.pcard-late-row .adj[open] { flex: 1 0 100%; margin-left: 0; }
.pcard-date { font-weight: 700; min-width: 86px; }
.trail { margin: 12px 0 6px; font-size: 13px; }
.trail > summary { cursor: pointer; color: var(--red-dark); font-weight: 600; }
.trail ul { margin: 8px 0 0; padding-left: 18px; color: var(--muted); }
.trail li { margin-bottom: 4px; }
.pcard-page { max-width: 560px; padding: 0; overflow: hidden; }

@media (max-width: 720px) {
  table.stack td.ded-cell { flex-wrap: wrap; justify-content: flex-end; }
  table.stack td.ded-cell .adj[open] { flex: 1 0 100%; margin-left: 0; }
}
@media (max-width: 560px) {
  .pmodal { padding: 0; align-items: flex-end; }
  .pmodal-box { width: 100%; max-height: 94vh; max-height: 94dvh; border-radius: 18px 18px 0 0; }
  .pcard-facts { padding-left: 16px; padding-right: 16px; }
  .pcard-sec { padding-left: 16px; padding-right: 16px; }
  .pcard-stats b { font-size: 18px; }
}

/* Tables with many columns (dashboard, report, staff): a little less side padding so everything fits a laptop screen without a sideways scroll. */
@media (min-width: 721px) { table.tight th { white-space: normal; line-height: 1.25; } table.tight .hm { display: block; font-size: 12px; } table.tight th, table.tight td { padding-left: 10px; padding-right: 10px; } table.tight th:first-child, table.tight td:first-child { padding-left: 16px; } table.tight th:last-child, table.tight td:last-child { padding-right: 16px; } }
