/*
 * Admin panel. Desktop: fixed sidebar + content. Below 960px the sidebar
 * becomes a slide-in drawer, a top bar and a bottom tab bar take over, and
 * below 760px every data table reflows into a stack of labelled cards
 * (labels are copied from the column headers by /js/admin.js).
 */
:root {
  --brand: #2563eb; --brand-600: #1d4ed8; --brand-900: #0f2557; --brand-soft: #eff6ff;
  --blue: var(--brand); --blue-600: var(--brand-600); --blue-soft: var(--brand-soft);
  --green: #16a34a; --green-ink: #166534; --green-soft: #dcfce7;
  --red: #dc2626;   --red-ink: #991b1b;   --red-soft: #fee2e2;
  --amber: #d97706; --amber-ink: #92400e; --amber-soft: #fef3c7;
  --bg: #f1f5f9; --panel: #fff; --txt: #0f172a; --txt-2: #334155; --muted: #64748b; --line: #e2e8f0;
  --side: #0f172a;
  --shadow: 0 1px 2px rgba(15,23,42,.05), 0 1px 3px rgba(15,23,42,.06);
  --shadow-lg: 0 24px 60px rgba(15,23,42,.22);
  --radius: 14px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px; line-height: 1.45; background: var(--bg); color: var(--txt);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-600); }
h3 { font-size: 16px; margin: 0; letter-spacing: -.01em; }
code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .92em; background: rgba(15,23,42,.06); padding: 1px 5px; border-radius: 5px; overflow-wrap: anywhere; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

.ico {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- Inputs & buttons ---------- */
.inp {
  width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid #cbd5e1; border-radius: 10px;
  font-size: 14px; background: #fff; color: var(--txt); transition: border-color .15s, box-shadow .15s;
}
.inp::placeholder { color: #94a3b8; }
.inp:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37,99,235,.16); }
.inp.sm { width: auto; min-height: 36px; padding: 6px 10px; }
input[type="checkbox"] { width: 18px; height: 18px; flex: none; accent-color: var(--brand); margin: 0; }

.btn {
  border: 1px solid transparent; border-radius: 10px; min-height: 40px; padding: 8px 16px;
  font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform .05s, box-shadow .15s, background .15s, border-color .15s;
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .link:focus-visible, .side a:focus-visible, .tabbar a:focus-visible, .tabbar button:focus-visible, .iconbtn:focus-visible { outline: 3px solid rgba(37,99,235,.45); outline-offset: 2px; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 13px; }
.btn.big { min-height: 48px; padding: 12px 18px; font-size: 16px; width: 100%; }
.btn.primary { background: var(--brand); color: #fff; box-shadow: 0 1px 2px rgba(37,99,235,.3); }
.btn.primary:hover { background: var(--brand-600); }
.btn.ghost { background: #fff; border-color: #cbd5e1; color: var(--txt-2); }
.btn.ghost:hover { background: #f8fafc; border-color: #94a3b8; }
.btn.danger { background: var(--red); color: #fff; }
.btn.danger:hover { background: #b91c1c; }
.btn.ghost.danger { background: #fff; color: var(--red); border-color: #fecaca; }
.btn.ghost.danger:hover { background: #fef2f2; border-color: #fca5a5; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; box-shadow: none; transform: none; }
.iconbtn { width: 40px; height: 40px; flex: none; border: 0; border-radius: 10px; background: transparent; display: grid; place-items: center; cursor: pointer; color: inherit; }
.iconbtn:hover { background: rgba(15,23,42,.06); }

.msg { font-size: 13px; color: var(--red); min-height: 16px; margin: 8px 0 0; }
.msg.ok { color: var(--green); }

/* ---------- Shell ---------- */
.wrap { display: grid; grid-template-columns: 256px minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.side {
  background: var(--side); color: #cbd5e1; padding: 18px 12px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto;
}
.side-brand { display: flex; align-items: center; gap: 10px; margin: 0 0 18px; padding: 0 8px; color: #fff; font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.side-brand .iconbtn { margin-left: auto; display: none; color: #cbd5e1; }
.side-brand .iconbtn:hover { background: rgba(255,255,255,.08); }
.logo-dot {
  width: 34px; height: 34px; flex: none; border-radius: 10px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--brand-900), var(--brand));
}
.side nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side nav a, .side-link {
  min-height: 42px; padding: 9px 12px; border-radius: 10px; color: #cbd5e1; font-size: 14px; font-weight: 500;
  display: flex; align-items: center; gap: 12px; text-decoration: none; cursor: pointer;
  transition: background .15s, color .15s; width: 100%; background: none; border: 0; text-align: left;
}
.side nav a:hover, .side-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.side nav a.active { background: var(--brand); color: #fff; }
.nav-ico { display: grid; place-items: center; width: 20px; flex: none; }
.nav-sep { margin: 12px 12px 4px; padding-top: 10px; border-top: 1px solid rgba(255,255,255,.1); color: #64748b; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.side-foot { display: flex; flex-direction: column; gap: 2px; padding-top: 10px; margin-top: 10px; border-top: 1px solid rgba(255,255,255,.1); }
.side form { margin: 0; }
.side-who { color: #94a3b8; font-size: 12px; padding: 10px 12px 0; overflow-wrap: anywhere; }
.side-who strong { color: #e2e8f0; }

.main { padding: 26px 30px 60px; min-width: 0; }
.main > h3 { font-size: 16px; margin: 28px 0 12px; }
.main > h3.set-title, .main > h3[id] { scroll-margin-top: 72px; }
.main > h3.set-title { font-size: 17px; }

/* Mobile chrome: hidden on desktop. */
.mbar, .tabbar, .scrim { display: none; }

.head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; gap: 12px 16px; flex-wrap: wrap; }
.head h3 { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.head form { margin: 0; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin: 0; }

/* ---------- Flash + notes ---------- */
.flash { padding: 12px 14px; border-radius: 12px; margin: 0 0 16px; font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.flash.ok  { background: var(--green-soft); color: var(--green-ink); border: 1px solid #86efac; }
.flash.bad { background: var(--red-soft);   color: var(--red-ink);   border: 1px solid #fca5a5; }
.note { background: var(--brand-soft); border: 1px solid #bfdbfe; color: #1e3a8a; padding: 12px 14px; border-radius: 12px; font-size: 13px; line-height: 1.5; margin: 0 0 16px; }
/* A <small class="note"> under a field is a hint, not a callout. */
small.note { display: block; background: none; border: 0; padding: 0; color: var(--muted); font-size: 12.5px; margin: -6px 0 0; }

/* ---------- Stat tiles ---------- */
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; min-width: 0; box-shadow: var(--shadow); }
.stat-lbl { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-val { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat-val.sm { font-size: 16px; letter-spacing: 0; padding: 5px 0; }
.stat.ok .stat-val { color: var(--green); }
.stat.no .stat-val { color: var(--red); }
.stat.amber .stat-val { color: var(--amber); }

/* ---------- Dashboard ----------
   Chart colours are a fixed, colour-blind-checked set: c1 blue = the main
   series (present / on time), c2 orange = late, c3 violet = on leave,
   c0 grey = absent. Text never takes these colours; a swatch beside it does. */
:root { --c1: #2a78d6; --c2: #eb6834; --c3: #6250d6; --c0: #c3c8d2; --grid: #e6e9ef; }
.c1 { background: var(--c1); } .c2 { background: var(--c2); } .c3 { background: var(--c3); } .c0 { background: var(--c0); }
/* Projects in the manpower chart, in fixed order (also colour-blind-checked as a set). */
.s1 { background: #2a78d6; } .s2 { background: #eb6834; } .s3 { background: #1baf7a; } .s4 { background: #eda100; } .s5 { background: #e87ba4; }
.legend.multi { flex-wrap: wrap; gap: 6px 14px; }
details.numbers { margin-top: 12px; }
details.numbers > summary { cursor: pointer; color: var(--brand-600); font-size: 13px; font-weight: 600; }
details.numbers .tbl { margin-top: 8px; }
.panel-card h4 .count { display: inline-block; min-width: 24px; margin-left: 6px; padding: 1px 8px; border-radius: 999px; background: var(--bg); color: var(--txt-2); font-size: 12px; text-align: center; }
.people { list-style: none; margin: 0; padding: 0; }
.people li { display: flex; align-items: baseline; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.people li:last-child { border-bottom: 0; }
.people-end { margin-left: auto; color: var(--txt-2); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.head .sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.kpi-lbl { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi-val { font-size: 30px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-val small { font-size: 15px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.kpi-note { font-size: 12.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 2px 10px; }
.kpi-note .up { color: var(--green-ink); font-weight: 600; }
.kpi-note .down { color: var(--red-ink); font-weight: 600; }
.meter { height: 8px; border-radius: 999px; background: #dbe7f8; overflow: hidden; }
.meter-fill { height: 100%; border-radius: 999px; background: var(--c1); }

.dash-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.dash-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dash-grid .span-2 { grid-column: span 2; }
.panel-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; min-width: 0; }
.main > .panel-card { margin-bottom: 16px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px 16px; flex-wrap: wrap; margin-bottom: 16px; }
.panel-card h4 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.panel-card h5 { margin: 18px 0 8px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.panel-card .empty { margin: 0; padding: 22px 0; color: var(--muted); font-size: 13px; text-align: center; }
.foot-note { margin: 12px 0 0; color: var(--muted); font-size: 12px; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--txt-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 3px; flex: none; display: inline-block; }

/* Vertical bars (trend, arrival times). Bars stand on the baseline; a stacked
   bar keeps a 2px gap between its parts and rounds only its top end. */
.vchart { display: flex; gap: 10px; }
.vaxis { display: flex; flex-direction: column; justify-content: space-between; height: 180px; font-size: 11px; color: var(--muted); text-align: right; min-width: 18px; font-variant-numeric: tabular-nums; }
.vbars { flex: 1; min-width: 0; display: flex; align-items: stretch; gap: 6px; height: 204px; overflow-x: auto;
  background: linear-gradient(var(--grid), var(--grid)) 0 0 / 100% 1px no-repeat, linear-gradient(var(--grid), var(--grid)) 0 90px / 100% 1px no-repeat, linear-gradient(#c3c8d2, #c3c8d2) 0 180px / 100% 1px no-repeat; }
.vcol { flex: 1 0 16px; min-width: 16px; display: flex; flex-direction: column; align-items: center; outline: none; cursor: default; }
.vstack { height: 180px; width: 100%; max-width: 34px; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; }
.vseg { width: 100%; min-height: 3px; }
.vseg:first-child { border-radius: 4px 4px 0 0; }
.vcol:hover .vseg, .vcol:focus-visible .vseg { filter: brightness(.9); }
.vlbl { height: 24px; line-height: 24px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.vbars.wide .vcol { flex-basis: 34px; min-width: 34px; }
/* the 14-day trend is the main chart, so it gets more height */
.vchart.tall .vaxis { height: 240px; }
.vchart.tall .vbars { height: 264px; background-position: 0 0, 0 120px, 0 240px; }
.vchart.tall .vstack { height: 240px; }

/* One bar split into parts (today at a glance) */
.split { display: flex; gap: 2px; height: 22px; border-radius: 6px; overflow: hidden; }
.split-seg { min-width: 4px; }
.keylist { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 8px; font-size: 13.5px; color: var(--txt-2); }
.keylist li { display: flex; align-items: center; gap: 8px; }
.keylist b { margin-left: auto; color: var(--txt); font-variant-numeric: tabular-nums; }
.keylist.plain { margin-top: 0; }

/* Horizontal bars (by project, by site, hours) with the value written at the end */
.hbars { display: grid; gap: 12px; }
.hrow-lbl { display: block; margin-bottom: 5px; font-size: 13px; font-weight: 600; color: var(--txt-2); overflow-wrap: anywhere; }
.hbar { display: flex; align-items: center; gap: 10px; min-width: 0; }
.hbar-track { flex: 1; min-width: 40px; height: 12px; }
.hbar-fill { height: 100%; min-width: 3px; border-radius: 0 4px 4px 0; }
.hbar b { min-width: 34px; font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hrow:hover .hbar-fill, .hbar:hover .hbar-fill { filter: brightness(.9); }

.tbl-wrap.flat { border: 0; box-shadow: none; border-radius: 0; }
.tbl.dash-tbl { min-width: 0; }
.tbl.dash-tbl th, .tbl.dash-tbl td { padding: 10px 12px; vertical-align: middle; }
.tbl.dash-tbl th { background: none; border-bottom: 1px solid var(--line); }
.tbl.dash-tbl th:first-child, .tbl.dash-tbl td:first-child { padding-left: 0; }
.tbl.dash-tbl .grow { width: 45%; }
.feed.flat { border: 0; box-shadow: none; border-radius: 0; }
.feed.flat .feed-row { padding: 10px 0; }
.feed-time { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 42px; }
.feed-where { margin-left: auto; text-align: right; }

.tip { position: fixed; z-index: 90; pointer-events: none; max-width: 240px; padding: 8px 10px; border-radius: 8px; background: #0f172a; color: #e2e8f0; font-size: 12px; line-height: 1.5; box-shadow: 0 8px 20px rgba(15,23,42,.3); }
.tip strong { display: block; color: #fff; font-size: 12.5px; }

@media (max-width: 1099.98px) {
  .dash-grid, .dash-grid.two { grid-template-columns: minmax(0, 1fr); }
  .dash-grid .span-2 { grid-column: auto; }
}
@media (max-width: 759.98px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 14px; }
  .kpi-val { font-size: 24px; }
  .panel-card { padding: 16px 14px; }
  .feed-where { margin-left: 0; flex: 1 1 100%; text-align: left; }
  /* the project table keeps its bar; the row becomes a card like every other table */
  .tbl.dash-tbl .grow { width: auto; }
  .tbl.dash-tbl td:first-child { padding-left: 0; }
  .tbl.dash-tbl td:first-child::before { content: none; }
}

/* ---------- Badges ---------- */
.badge { padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; display: inline-block; background: #e2e8f0; color: var(--txt-2); white-space: nowrap; }
.badge.ok { background: var(--green-soft); color: var(--green-ink); }
.badge.no { background: var(--red-soft); color: var(--red-ink); }
.badge.amber { background: var(--amber-soft); color: var(--amber-ink); }

/* ---------- Table ---------- */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow); background: #fff; }
.tbl { width: 100%; border-collapse: collapse; background: #fff; min-width: 640px; }
.tbl th, .tbl td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: top; }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover { background: #f8fafc; }
.tbl th { background: #f8fafc; color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: .05em; white-space: nowrap; }
.actions { white-space: nowrap; }
.actions > * { margin-right: 12px; vertical-align: top; }
.actions > *:last-child { margin-right: 0; }
.actions form { display: inline-block; margin: 0; }
.actions details { display: inline-block; white-space: normal; }
.link { background: none; border: none; color: var(--brand-600); cursor: pointer; font-size: 13px; padding: 0; font-weight: 600; text-decoration: none; }
.link:hover { text-decoration: underline; }
.link.danger { color: var(--red); }
summary.link { list-style: none; display: inline-block; }
summary.link::-webkit-details-marker { display: none; }

.row-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; padding: 12px; margin-top: 8px; background: #f8fafc; border: 1px solid var(--line); border-radius: 12px; }
.row-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.row-form label.check { flex-direction: row; align-items: center; gap: 8px; min-height: 36px; color: var(--txt); font-size: 14px; font-weight: 500; }
.row-form .inp { width: auto; max-width: 180px; }

/* A row's Edit / Correct / Reject form, shown as a centred dialog (see admin.js).
   The summary's ::before is the dimmed backdrop; clicking it closes the dialog. */
td.actions details[open] > summary::before { content: ""; position: fixed; inset: 0; z-index: 70; background: rgba(15,23,42,.55); cursor: default; }
td.actions details[open] > .row-form {
  position: fixed; z-index: 71; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(460px, calc(100vw - 32px)); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: auto;
  margin: 0; padding: 22px; gap: 14px; flex-direction: column; flex-wrap: nowrap; align-items: stretch;
  background: #fff; border: 0; border-radius: 18px; box-shadow: var(--shadow-lg); white-space: normal; text-align: left;
}
td.actions details[open] > .row-form label { font-size: 13px; color: var(--txt-2); gap: 6px; flex: none; }
td.actions details[open] > .row-form label.check { font-size: 14px; color: var(--txt); min-height: 28px; }
td.actions details[open] > .row-form .inp { width: 100%; max-width: none; min-height: 42px; font-size: 15px; }
.dlg-title { margin-bottom: 4px; font-size: 18px; font-weight: 700; letter-spacing: -.01em; color: var(--txt); overflow-wrap: anywhere; }
.dlg-buttons { display: flex; gap: 10px; margin-top: 4px; }
.dlg-buttons .btn { flex: 1 1 0; min-height: 44px; font-size: 14px; }
details:not([open]) > .row-form .dlg-title, details:not([open]) > .row-form .dlg-buttons { display: none; }

/* Employee list: photo or initials, with the name, code and email together */
.person { display: flex; align-items: center; gap: 12px; min-width: 0; }
.avatar { width: 40px; height: 40px; flex: none; border-radius: 50%; object-fit: cover; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-600); font-size: 14px; font-weight: 700; letter-spacing: .02em; }
.person-txt { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.person-txt strong { font-size: 14px; }
.person-txt small { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.tbl.emp-list td { vertical-align: middle; }
.tbl tr.is-off .person { opacity: .6; }
.badge.blue { background: #dbeafe; color: #1e40af; }
.tbl td .badge + .badge { margin-left: 4px; }

/* Sortable column headers */
.th-sort { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 5px; }
.th-sort:hover { color: var(--txt); }
.th-sort .sort-ind { opacity: .4; font-size: 11px; }
.th-sort.active { color: var(--brand-600); }
.th-sort.active .sort-ind { opacity: 1; }

/* Pager */
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 16px 0 4px; flex-wrap: wrap; }
.pager-info { color: var(--muted); font-size: 13px; font-weight: 600; }
.pager-size { margin: 0; }
.pager-size label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 600; white-space: nowrap; }
.pager-size .inp { width: auto; min-width: 76px; }

/* ---------- Trend chart ---------- */
.chart-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 18px; }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.chart { width: 100%; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 150px; overflow-x: auto; padding-bottom: 2px; }
.bars > .note { margin: auto; }
.bar-col { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: 1 0 18px; min-width: 18px; height: 100%; }
.bar-stack { flex: 1; width: 100%; max-width: 44px; display: flex; align-items: flex-end; }
.bar { width: 100%; background: var(--brand); border-radius: 6px 6px 0 0; min-height: 2px; position: relative; overflow: hidden; }
.bar-late { position: absolute; left: 0; right: 0; bottom: 0; background: var(--amber); }
.bar-lbl { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Feed + punch logs ---------- */
.feed { display: flex; flex-direction: column; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.feed-row { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 14px; }
.feed-row:last-child { border-bottom: none; }
.feed .muted { font-size: 13px; }
.logs { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); gap: 12px; margin-top: 12px; }
.logs > .note { grid-column: 1 / -1; margin: 0; }
.log { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; gap: 12px; box-shadow: var(--shadow); min-width: 0; line-height: 1.6; }
.log > div:last-child { min-width: 0; overflow-wrap: anywhere; }
.log-selfie { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; background: #e2e8f0; flex: none; }
.log small { color: var(--muted); }

/* ---------- Forms / panels ---------- */
.set-form { max-width: 640px; background: #fff; border: 1px solid var(--line); padding: 22px; border-radius: var(--radius); display: flex; flex-direction: column; gap: 16px; box-shadow: var(--shadow); }
.set-form label { font-size: 13px; color: var(--txt-2); display: flex; flex-direction: column; gap: 6px; font-weight: 600; min-width: 0; }
.set-form label small { font-weight: 400; }
.set-form .row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.set-form h3 { padding-top: 14px; border-top: 1px solid var(--line); }
.set-form .note { margin-bottom: 0; }
.check, .set-form label.check { flex-direction: row; display: flex; align-items: center; gap: 10px; color: var(--txt); font-size: 14px; font-weight: 500; min-height: 28px; }
.set-form > .btn { align-self: flex-start; }
.set-form h3.sec { font-size: 15px; }
.set-form h3.sec:first-of-type { padding-top: 0; border-top: 0; }

/* On/off switches with their explanation (employee form) */
.opts { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.set-form label.opt { flex-direction: row; align-items: center; justify-content: space-between; gap: 18px; padding: 14px 16px; cursor: pointer; background: #fff; }
.opt + .opt { border-top: 1px solid var(--line); }
.opt:hover { background: #f8fafc; }
.opt-txt { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.opt-txt strong { font-size: 14px; color: var(--txt); }
.opt-txt small { font-size: 12.5px; font-weight: 400; color: var(--muted); line-height: 1.45; }
.opt-txt b { color: var(--txt-2); font-weight: 600; }
input.switch {
  appearance: none; -webkit-appearance: none; flex: none; width: 46px; height: 28px; margin: 0; border-radius: 999px;
  background: #cbd5e1; position: relative; cursor: pointer; transition: background .15s;
}
input.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(15,23,42,.3); transition: transform .15s; }
input.switch:checked { background: var(--brand); }
input.switch:checked::after { transform: translateX(18px); }
input.switch:focus-visible { outline: 3px solid rgba(37,99,235,.45); outline-offset: 2px; }

/* A folded-away group of rarely used fields inside a form */
.set-form details.sub { border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; }
.set-form details.sub > summary { cursor: pointer; font-size: 14px; font-weight: 600; color: var(--txt-2); }
.set-form details.sub[open] > summary { margin-bottom: 4px; }
.set-form details.sub .row, .set-form details.sub .hint { margin-top: 12px; }
.set-form details.sub .hint { margin-bottom: 0; color: var(--muted); font-size: 12.5px; }

.set-form.wide { max-width: 1040px; }
.inline-form { margin: 0; display: inline-flex; gap: 6px; align-items: center; }
/* Permission grid on the Roles screen: a tick box with what it means beside it. */
.tbl.perm td { vertical-align: top; }
.tbl.perm .check { align-items: flex-start; min-height: 0; font-size: 13px; font-weight: 400; color: var(--txt-2); line-height: 1.4; }
.tbl.perm .check input { margin-top: 1px; }
.loc-pick { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; }
.loc-msg { color: var(--green-ink); font-size: 12.5px; font-weight: 500; }
.loc-msg.bad { color: var(--amber-ink); }
.loc-msg:empty { display: none; }
details.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 18px; max-width: 640px; }
details.panel > summary { cursor: pointer; font-weight: 700; }
details.panel[open] > summary { margin-bottom: 16px; }
details.panel .set-form { border: 0; box-shadow: none; padding: 0; max-width: none; }

.emp-photo { display: flex; align-items: center; gap: 14px; padding: 12px; background: #f8fafc; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 16px; }
.emp-photo-img { width: 72px; height: 72px; border-radius: 12px; object-fit: cover; background: #e2e8f0; flex: none; }
.geo-assign { max-height: 190px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; display: grid; gap: 4px; }
.enroll-media { display: flex; justify-content: center; margin-bottom: 4px; }
.enroll-media video { transform: scaleX(-1); aspect-ratio: 4/3; object-fit: cover; }
.modal-actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.modal-actions .btn { flex: 1 1 140px; }
.import-result { font-size: 13px; margin: 0 0 16px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; max-width: 640px; overflow-wrap: anywhere; }
.import-result ul { margin: 10px 0 14px; padding-left: 20px; color: var(--red-ink); }

/* ---------- Public pages (landing, sign in, errors) ---------- */
body.centered {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center;
  grid-template-columns: minmax(0, 1fr); /* or the card's own width sizes the track and it overflows a phone */
  background: var(--brand-900) radial-gradient(900px 520px at 50% -8%, #2563eb 0%, #17389a 45%, var(--brand-900) 100%) no-repeat;
  padding: calc(18px + var(--safe-t)) calc(18px + var(--safe-r)) calc(18px + var(--safe-b)) calc(18px + var(--safe-l));
}
.login-card { background: #fff; padding: 30px 26px; border-radius: 20px; width: 100%; max-width: 380px; box-shadow: var(--shadow-lg); }
.login-card h2 { font-size: 21px; margin: 0 0 16px; display: flex; align-items: center; gap: 10px; letter-spacing: -.01em; }
.login-card .inp { min-height: 46px; font-size: 16px; }
.login-card .btn { width: 100%; margin-top: 12px; min-height: 48px; }
.login-card .btn.big { margin-top: 18px; }
.login-card .punch-link { display: block; text-align: center; margin-top: 16px; font-size: 13px; font-weight: 600; text-decoration: none; }
.login-card .punch-link:hover { text-decoration: underline; }
.lbl { display: block; font-size: 13px; color: var(--txt-2); font-weight: 600; margin: 14px 0 0; }
.lbl .inp { margin-top: 6px; }

/* ===================================================================
   Tablet and below: drawer navigation, top bar, bottom tab bar
   =================================================================== */
@media (max-width: 959.98px) {
  .wrap { display: block; }
  .mbar {
    display: flex; align-items: center; gap: 6px; position: sticky; top: 0; z-index: 30;
    min-height: calc(56px + var(--safe-t)); padding: var(--safe-t) calc(8px + var(--safe-r)) 0 calc(8px + var(--safe-l));
    background: rgba(255,255,255,.94); backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
    border-bottom: 1px solid var(--line);
  }
  .mbar-title { flex: 1; min-width: 0; font-size: 16px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mbar .logo-dot { width: 30px; height: 30px; border-radius: 9px; margin-right: 6px; }
  .mbar .logo-dot .ico { width: 18px; height: 18px; }

  .side {
    position: fixed; z-index: 60; top: 0; bottom: 0; left: 0; height: auto;
    width: min(86vw, 300px);
    padding: calc(16px + var(--safe-t)) 12px calc(16px + var(--safe-b)) calc(12px + var(--safe-l));
    transform: translateX(-102%); visibility: hidden;
    transition: transform .22s ease, visibility 0s linear .22s;
    box-shadow: var(--shadow-lg);
  }
  .nav-open .side { transform: none; visibility: visible; transition: transform .22s ease; }
  .side-brand .iconbtn { display: grid; }
  .side nav a, .side-link { min-height: 46px; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 50; background: rgba(15,23,42,.5); opacity: 0; pointer-events: none; transition: opacity .22s; border: 0; padding: 0; width: 100%; }
  .nav-open .scrim { opacity: 1; pointer-events: auto; }
  .nav-open body { overflow: hidden; }

  .tabbar {
    display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
    position: fixed; z-index: 40; left: 0; right: 0; bottom: 0;
    padding: 4px calc(4px + var(--safe-r)) calc(4px + var(--safe-b)) calc(4px + var(--safe-l));
    background: rgba(255,255,255,.96); backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
    border-top: 1px solid var(--line);
  }
  .tabbar a, .tabbar button {
    min-height: 52px; padding: 6px 2px; border: 0; background: none; border-radius: 10px; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    color: var(--muted); font-size: 11px; font-weight: 600; text-decoration: none; min-width: 0;
  }
  .tabbar .ico { width: 22px; height: 22px; }
  .tabbar a.active { color: var(--brand-600); }

  .main { padding: 18px calc(16px + var(--safe-r)) calc(92px + var(--safe-b)) calc(16px + var(--safe-l)); }
  .head h3 { font-size: 20px; }

  /* 16px inputs stop iOS Safari zooming the page on focus; bigger tap targets. */
  .inp, .inp.sm { font-size: 16px; min-height: 44px; }
  .btn { min-height: 44px; }
  .btn.sm { min-height: 40px; }
}

/* ===================================================================
   Phones: tables become cards, toolbars stack
   =================================================================== */
@media (max-width: 759.98px) {
  .head { align-items: stretch; flex-direction: column; }
  .head > .btn, .head > form > .btn { width: 100%; }
  .head-actions, .filters { width: 100%; }
  .filters .inp { flex: 1 1 150px; min-width: 0; width: auto; }
  .head-actions > .btn { flex: 1 1 auto; }

  .tbl-wrap { overflow: visible; background: none; border: 0; box-shadow: none; border-radius: 0; }
  .tbl, .tbl tbody { display: block; min-width: 0; background: none; }
  .tbl thead { display: none; }
  .tbl tr { display: block; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px 14px; margin-bottom: 10px; }
  .tbl tbody tr:hover { background: #fff; }
  .tbl td { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
  .tbl tr td:last-child { border-bottom: 0; }
  .tbl td[data-label] { position: relative; padding-left: 38%; min-height: 41px; }
  .tbl td[data-label]::before {
    content: attr(data-label); position: absolute; left: 0; top: 12px; width: 34%;
    color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  }
  .tbl td:empty, .tbl td.td-empty { display: none; }
  .tbl td[data-label] { padding-top: 8px; padding-bottom: 8px; min-height: 36px; }
  .tbl td[data-label]::before { top: 10px; }
  .tbl td.who { padding: 12px 0 10px; min-height: 0; }
  .tbl td.who::before { content: none; }
  .tbl td.who .avatar { width: 44px; height: 44px; font-size: 15px; }
  .tbl td.who .person-txt strong { font-size: 15px; }
  .tbl td.actions { padding-top: 10px; padding-bottom: 10px; }
  .set-form label.opt { padding: 12px 14px; gap: 12px; }
  .tbl td.actions { white-space: normal; display: flex; flex-wrap: wrap; gap: 8px; }
  .tbl td.actions > * { margin: 0; }
  .tbl td.actions details[open] { flex: 1 1 100%; }
  .tbl td.actions .link { display: inline-flex; align-items: center; min-height: 38px; padding: 0 14px; border: 1px solid #cbd5e1; border-radius: 10px; background: #fff; }
  .tbl td.actions .link:hover { text-decoration: none; background: #f8fafc; }
  .tbl td.actions .link.danger { border-color: #fecaca; }

  .row-form { align-items: stretch; }
  .row-form label { flex: 1 1 130px; }
  .row-form label.check { flex: 1 1 100%; }
  .row-form .inp { width: 100%; max-width: none; }
  .row-form .btn { flex: 1 1 100%; }

  .set-form { padding: 18px 16px; }
  .set-form > .btn { align-self: stretch; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat-val { font-size: 22px; }
  .pager .btn { flex: 1 1 0; }
  .pager-info { order: -1; flex: 1 1 100%; text-align: center; }
  .pager-size { flex: 1 1 100%; display: flex; justify-content: center; }
  .login-card { padding: 26px 20px; }
}

@media (max-width: 479.98px) {
  .set-form .row { grid-template-columns: minmax(0, 1fr); }
  .bars { gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media print {
  .side, .mbar, .tabbar, .scrim, .head-actions, .pager { display: none !important; }
  .wrap { display: block; }
  .main { padding: 0; }
}
