:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #1e5fa8;
  --brand-dark: #164a83;
  --ok-bg: #e7f6ec;
  --ok-ink: #12633a;
  --err-bg: #fdecec;
  --err-ink: #b0271f;
  --warn-bg: #fff6e5;
  --warn-ink: #8a5a00;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 54px;
}
.topbar .brand { font-weight: 600; font-size: 16px; color: #fff; letter-spacing: .2px; }
.topbar .brand small { display: block; font-weight: 400; font-size: 11px; opacity: .8; }
.topbar nav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.topbar nav a {
  color: #eaf1f9; padding: 7px 11px; border-radius: var(--radius); font-size: 13px;
}
.topbar nav a:hover, .topbar nav a.active { background: rgba(255,255,255,.16); text-decoration: none; }
.topbar form { margin: 0; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 22px 20px 60px; }
/* Wide screens (e.g. the monthly entry grid) get the full browser width. */
.wrap.wide { max-width: none; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin: 0; font-size: 22px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.card h2 { margin: 0 0 12px; font-size: 16px; }
.card h3 { margin: 18px 0 8px; font-size: 14px; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
@media (max-width: 900px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
}

table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
th { background: #f1f5f9; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
td.num, th.num { text-align: right; }
tbody tr:hover { background: #f8fafc; }
tr.total-row td { font-weight: 600; background: #f1f5f9; border-top: 2px solid var(--line); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.table-wrap table { min-width: 640px; }/* Security-deposit register: 15 columns, so the page renders in the wide layout
   (.wrap.wide). The figures and statuses are compacted - tighter padding, a
   smaller figure font and always-on-one-line cells and badges - so the whole
   row (through Held / Target / Next run / the Opening-balance editor) fits the
   window instead of scrolling sideways inside the card. */
.sec-table { width: 100%; min-width: 0; font-size: 12.5px; }
.sec-table th, .sec-table td { padding: 5px 6px; white-space: nowrap; }
.sec-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.sec-table td.sec-edit { white-space: nowrap; }
.sec-table td.sec-edit form { display: inline-flex; align-items: center; gap: 4px; margin: 0 0 0 6px; }
.sec-table td.sec-edit form:first-of-type { margin-left: 0; }
.sec-table td.sec-edit input[name=opening] { width: 64px; padding: 3px 5px; font-size: 12.5px; }
.sec-table .badge { white-space: nowrap; }

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input[type=text], input[type=number], input[type=password], input[type=email], input[type=date], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bcd4ee; border-color: var(--brand); }
.field { margin-bottom: 12px; }
.field .hint { font-size: 11px; color: var(--muted); margin-top: 3px; font-weight: 400; }
.check { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.check input { width: auto; }
.check label { margin: 0; font-size: 13px; color: var(--ink); font-weight: 500; }

.btn {
  display: inline-block; padding: 8px 15px; border-radius: 6px; border: 1px solid transparent;
  background: #1e5fa8; background: var(--brand); color: #fff; font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { background: #164a83; background: var(--brand-dark); text-decoration: none; }
.btn.ghost { background: #fff; color: var(--brand); border-color: var(--line); }
.btn.ghost:hover { background: #f1f5f9; }
.btn.danger { background: #b0271f; }
.btn.danger:hover { background: #8f1f18; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.flash { padding: 11px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13px; }
.flash.ok { background: var(--ok-bg); color: var(--ok-ink); }
.flash.err { background: var(--err-bg); color: var(--err-ink); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge.draft { background: var(--warn-bg); color: var(--warn-ink); }
.badge.finalized { background: var(--ok-bg); color: var(--ok-ink); }
.badge.muted { background: #eef2f7; color: var(--muted); }

.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.stat .value { font-size: 20px; font-weight: 700; margin-top: 5px; font-variant-numeric: tabular-nums; }
.stat .value.small { font-size: 16px; }

.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 14px; }
.empty { text-align: center; padding: 34px; color: var(--muted); }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 6px 12px; border: 1px solid var(--line); border-radius: 20px; font-size: 13px; background: #fff; }
.tabs a.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* Inline buttons that read as links inside a table cell */
.linkbtn { background: none; border: none; color: var(--brand); cursor: pointer; font: inherit; padding: 0; }
.linkbtn.danger { color: #b91c1c; }
form.inline { display: inline; }
.center { text-align: center; }

/* Monthly data-entry grid */
.grid-table { font-size: 12.5px; }
.grid-table input.cell { width: 52px; padding: 3px 4px; font-size: 12.5px; text-align: right; }
.grid-table input.cell.wide { width: 120px; text-align: left; }
.grid-table th, .grid-table td { padding: 4px 6px; vertical-align: middle; }

/* Service / leave tier bands. One colour per band, used consistently on the
   employee list, the employee page, the input sheet and the grid so a slip in
   service length is obvious at a glance:
     0 - under 6 months (probation) - red
     1 - 6 to 12 months             - amber
     2 - over 1 year                - purple (matched to the office workbook) */
.tier { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.tier0 { background: #fee2e2; color: #b91c1c; }
.tier1 { background: #fef3c7; color: #92400e; }
.tier2 { background: #ede9fe; color: #5b21b6; }

/* Whole-row banding + a left accent stripe, so the tier reads even when the
   badge is off-screen in a wide table. */
.tier-row-0 { background: #fef2f2; box-shadow: inset 3px 0 0 #dc2626; }
.tier-row-1 { background: #fffbeb; box-shadow: inset 3px 0 0 #d97706; }
.tier-row-2 { background: #faf5ff; box-shadow: inset 3px 0 0 #7c3aed; }

/* Compact dot indicator (lists, headings). */
.tier-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.tier-dot.tier0 { background: #dc2626; }
.tier-dot.tier1 { background: #d97706; }
.tier-dot.tier2 { background: #7c3aed; }

/* Legend key: the three bands in one strip. */
.tier-legend { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; font-size: 12px; color: var(--muted); margin: 4px 0 14px; }
.tier-legend .key { display: inline-flex; align-items: center; gap: 6px; }

/* Payslip */
.payslip { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 26px 28px; max-width: 860px; margin: 0 auto; }
.payslip-head { display: flex; justify-content: space-between; gap: 18px; border-bottom: 2px solid var(--ink); padding-bottom: 12px; margin-bottom: 14px; }
.payslip-head h2 { margin: 0; font-size: 19px; }
.payslip-entity { display: flex; align-items: center; gap: 14px; }
.payslip-logo { max-height: 64px; max-width: 150px; object-fit: contain; }
.doc-letterhead { display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 14px; }
.doc-letterhead img { max-height: 56px; max-width: 140px; object-fit: contain; }
/* A "letter pad" print lands on the company's own pre-printed stationery, so the
   logos carried by the digital letterhead are dropped for that print only. */
@media print {
  body[data-letterpad] .payslip-logo,
  body[data-letterpad] .doc-letterhead img { display: none !important; }
}

/* Employee profile photo */
.profile-head { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.profile-photo { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; border: 1px solid var(--line); }
.profile-photo.placeholder { display: flex; align-items: center; justify-content: center; background: #eef2f7; color: var(--muted); font-size: 30px; font-weight: 600; }
.profile-photo-actions { display: flex; flex-direction: column; gap: 6px; font-size: 12px; }
.is-hidden { display: none !important; }
/* The file control is dressed as a button: a bare <input type=file> reads as a
   stray "Choose file" on the office's screen and hides the real action. */
.photo-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.photo-pick { cursor: pointer; margin: 0; }
.photo-pick input[type="file"] { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.photo-form .hint { flex-basis: 100%; }
.payslip-head .meta { text-align: right; font-size: 13px; }
.payslip .emp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 20px; margin-bottom: 16px; font-size: 13px; }
.payslip .emp-grid div span { color: var(--muted); display: inline-block; min-width: 96px; }
.payslip-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.payslip-cols table { min-width: 0; }
.payslip-cols th { background: #eef2f7; }
.net-band { margin-top: 14px; padding: 14px 16px; background: #f1f5f9; border-radius: 6px; display: flex; justify-content: space-between; align-items: center; }
.net-band .amount { font-size: 22px; font-weight: 700; }
.words { font-size: 12px; color: var(--muted); margin-top: 6px; }
.payslip-foot { margin-top: 26px; display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }

@media print {
  .topbar, .no-print, .flash { display: none !important; }
  body { background: #fff; }
  .wrap { padding: 0; max-width: none; }
  .payslip { border: none; padding: 0; max-width: none; }
  a { color: inherit; text-decoration: none; }
}
/* --- print preview: stack several payslips on one page, one page per slip --- */
.print-stack .payslip { margin-bottom: 26px; }
.print-stack .page-break { break-after: page; page-break-after: always; }
@media print {
  .print-stack .payslip { margin-bottom: 0; }
  .print-stack .payslip { break-inside: avoid; page-break-inside: avoid; }
}
/* --- nav dropdowns: keep the top bar on one line as items grow --- */
.topbar nav { flex-wrap: nowrap; }
.nav-drop { position: relative; }
.nav-drop-label { display: block; color: #eaf1f9; padding: 7px 11px; border-radius: var(--radius); font-size: 13px; cursor: default; user-select: none; }
.nav-drop:hover .nav-drop-label, .nav-drop.active .nav-drop-label { background: rgba(255,255,255,.16); }
.nav-drop .caret { font-size: 10px; opacity: .85; }
.nav-drop-menu {
  display: none; position: absolute; top: 100%; left: 0; z-index: 40; min-width: 200px;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(15,23,42,.18); padding: 6px; margin-top: 4px;
}
/* The menu sits a few px below the label; without this transparent bridge the
   pointer leaves the hover area crossing that gap and the menu snaps shut. */
.nav-drop-menu::before { content: ''; position: absolute; top: -8px; left: 0; right: 0; height: 8px; }
.nav-drop:hover .nav-drop-menu, .nav-drop:focus-within .nav-drop-menu { display: block; }
.topbar nav .nav-drop-menu a { display: block; color: var(--ink); padding: 8px 10px; border-radius: 6px; white-space: nowrap; }
.topbar nav .nav-drop-menu a:hover, .topbar nav .nav-drop-menu a.active { background: #eef4fb; color: var(--brand); }
/* --- sticky grid header + frozen identity columns, so scrolling wide tables keeps context --- */
.table-wrap { max-width: 100%; }
.grid-table thead th { position: sticky; top: 0; z-index: 5; background: #f1f5f9; }
.grid-table td.col-code, .grid-table th.col-code, .grid-table td.col-name, .grid-table th.col-name { position: sticky; background: #fff; }
.grid-table td.col-code, .grid-table th.col-code { left: 0; z-index: 4; }
.grid-table td.col-name, .grid-table th.col-name { left: 84px; z-index: 4; }
.grid-table thead th.col-code, .grid-table thead th.col-name { z-index: 6; background: #f1f5f9; }
/* --- print: bank transfer sheet --- */
.bank-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.bank-head h2 { margin: 0; }
.bank-name { margin: 16px 0 8px; font-size: 14px; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.bank-company-total { margin-top: 12px; text-align: right; font-weight: 600; }
@media print {
  .topbar, .no-print, .btn-row { display: none !important; }
  .card { break-inside: avoid; border: none; }
  .wrap { max-width: none; padding: 0; }
}
.grid-table th.col-code, .grid-table td.col-code { min-width: 84px; max-width: 84px; }
.grid-table th.col-name, .grid-table td.col-name { min-width: 190px; max-width: 190px; overflow: hidden; text-overflow: ellipsis; }
.grid-table td.col-name { background: #fff; }
.grid-table thead th.col-name { background: #f1f5f9; }

.grid-wrap { max-height: 74vh; overflow: auto; }
.grid-wrap .grid-table thead th { box-shadow: inset 0 -1px 0 var(--line); }
.grid-wrap .grid-table tfoot td { position: sticky; bottom: 0; background: #f1f5f9; z-index: 5; }

/* ---- Yearly input sheet: employees down, 12 months across ----
   Two frozen left columns (employee, then field) and a sticky month header.
   The left offsets are fixed here; keep them in sync with the widths below. */
.wp-table { border-collapse: separate; border-spacing: 0; font-size: 12.5px; }
.wp-table th, .wp-table td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 2px 4px; white-space: nowrap; }
.wp-table thead th { position: sticky; top: 0; z-index: 7; background: #eef2f7; text-align: center; padding: 4px; }
.wp-table thead th.wp-emp { left: 0; z-index: 9; min-width: 190px; max-width: 190px; text-align: left; }
.wp-table thead th.wp-field { left: 190px; z-index: 9; min-width: 96px; max-width: 96px; text-align: left; background: #e2e8f0; }
.wp-table tbody th.wp-emp {
  position: sticky; left: 0; z-index: 5; background: #fff; text-align: left;
  min-width: 190px; max-width: 190px; overflow: hidden; text-overflow: ellipsis;
  border-left: 3px solid transparent;
}
.wp-table tbody th.wp-field { position: sticky; left: 190px; z-index: 5; background: #f8fafc; text-align: left; font-weight: 500; min-width: 96px; max-width: 96px; }
.wp-table tbody tr:first-child th.wp-emp { border-top: 1px solid var(--line); }
.wp-table .wp-input { width: 58px; padding: 2px 4px; text-align: right; border: 1px solid transparent; background: transparent; font-size: 12.5px; }
.wp-table .wp-input:focus { border-color: var(--accent); background: #fff; outline: none; }
.wp-table .wp-input:disabled { color: #94a3b8; }
.wp-table .wp-month-head a { display: block; font-size: 11px; font-weight: 400; text-decoration: none; }
.wp-table .wp-run-link { color: #14883c; }
.wp-table .wp-run-new { color: var(--muted); }
.wp-table td.wp-norun { background: #fffbeb; }
.wp-table td.wp-calc { background: #f1f5f9; color: #334155; text-align: right; font-variant-numeric: tabular-nums; }
.wp-table thead th.wp-calc { background: #dbe4ee; }
/* The input sheet is long (one row per employee), so cap the wrapper's height and
   let it scroll: that makes the sticky `top: 0` header actually stick while the
   rows scroll under it, instead of scrolling away with the page. */
.wp-wrap { max-height: 74vh; overflow: auto; }
.wp-wrap .wp-table thead th { box-shadow: inset 0 -1px 0 var(--line); }
.wp-table tr.wp-probation th.wp-emp { border-left-color: #d97706; }
.wp-table tr.wp-left th.wp-emp { border-left-color: #b91c1c; }
/* ---- In-app documentation ---- */
.doc-card { display: block; text-decoration: none; color: inherit; }
.doc-card h3 { margin: 0 0 4px; }
.doc-card .doc-file { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--muted); }
.docs-nav { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 14px; }
.chip { padding: 4px 12px; border: 1px solid var(--line); border-radius: 999px; font-size: 13px; text-decoration: none; color: var(--ink); background: #fff; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.doc-body { line-height: 1.6; }
.doc-h1 { font-size: 24px; margin: 8px 0 12px; }
.doc-h2 { font-size: 19px; margin: 22px 0 8px; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.doc-h3 { font-size: 16px; margin: 18px 0 6px; }
.doc-h4, .doc-h5, .doc-h6 { font-size: 14px; margin: 14px 0 4px; }
.doc-list { margin: 6px 0 10px 20px; }
.doc-task { list-style: none; margin-left: -14px; }
.doc-box { display: inline-block; width: 16px; color: var(--muted); }
.doc-box.on { color: #14883c; }
.doc-quote { margin: 10px 0; padding: 8px 14px; border-left: 3px solid var(--accent); background: #f7f9fc; color: #33475b; }
.doc-hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.doc-code { background: #0f172a; color: #e2e8f0; padding: 12px 14px; border-radius: 8px; overflow: auto; font-size: 12.5px; }
.doc-table-wrap { overflow: auto; margin: 10px 0; }
.doc-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.doc-table th, .doc-table td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.doc-table th { background: #f1f5f9; }
.doc-body code { background: #eef2f7; padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
/* ---- Attendance sheet: reuses the wp-table grid ---- */
details.card > summary { cursor: pointer; font-size: 14px; }
details.card > summary::marker { color: var(--muted); }
.wp-table td.wp-absent { color: #b45309; font-weight: 600; }
.wp-table td.wp-absent[data-zero="1"] { color: #94a3b8; font-weight: 400; }
/* ---- Employee form: keep the save control in view on a long form ---- */
.form-actions { position: sticky; bottom: 0; z-index: 20; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; box-shadow: 0 -1px 0 var(--line); }
.form-actions-hint { flex: 1 1 100%; font-size: 12px; }
@media print { .form-actions { display: none !important; } }
/* ---- Employee finder above the wide sheets ---- */
.grid-filter { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; flex-wrap: wrap; }
.grid-filter label { font-size: 13px; font-weight: 600; }
.grid-filter input[type="search"] { width: 240px; max-width: 60vw; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; }
.grid-filter input[type="search"]:focus { border-color: var(--brand); outline: none; }
.grid-filter .muted { font-size: 12px; }
@media print { .grid-filter { display: none !important; } }
/* ---- Inline delete control (list rows): reads as a link, acts as a button ---- */
.linklike { background: none; border: 0; padding: 0; margin: 0; font: inherit; color: var(--brand); cursor: pointer; }
.linklike:hover { text-decoration: underline; }
.linklike.danger { color: #b0271f; }
/* ---- Attendance / sheet print view ---- */
.print-head { margin-bottom: 10px; }
.print-head h2 { margin: 0 0 2px; font-size: 16px; }
@media print {
  /* The on-screen grid scrolls and sticks its header; on paper it must be the
     whole sheet, not a clipped window. */
  .wp-wrap { max-height: none !important; overflow: visible !important; }
  .wp-table { font-size: 11px; }
  .wp-table thead th,
  .wp-table tbody th.wp-emp { position: static; }
  .card { border: 0; box-shadow: none; padding: 0; }
  .print-head { margin-bottom: 12px; }
}

/* ---- Online attendance tracker ---- */
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.punch-head { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.punch-head .stat { flex: 1 1 160px; }
.punch-msg { min-height: 20px; margin-top: 10px; font-size: 14px; font-weight: 600; }
.punch-msg.ok { color: var(--ok-ink); }
.punch-msg.err { color: #b0271f; }
.flagged-row { background: #fff7ed; }
.flagged-row td { background: transparent; }
.site-code { text-align: center; padding: 26px 10px; }
.site-code .code {
  font-size: 72px; font-weight: 800; letter-spacing: 12px;
  font-variant-numeric: tabular-nums; color: var(--brand);
  line-height: 1.1; word-break: break-all;
}
.site-code .hint { font-size: 14px; margin-top: 10px; }
@media (max-width: 720px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .site-code .code { font-size: 52px; letter-spacing: 8px; }
}
