/* EAMAR Manpower & Payroll design system. Owned by the UI/UX session.
   Every class is documented in docs/UI_GUIDE.md and shown at /styleguide/.
   Keep class names stable: other modules depend on them. */

/* ---------- 1. Tokens ---------- */
:root {
  /* Brand */
  --navy: #17365d;
  --navy-900: #0f2542;
  --navy-700: #1f4e78;
  --navy-100: #dbe5f0;
  --navy-50: #eef3f9;
  --gold: #b8912f;        /* decoration only: too light for text on white */
  --gold-400: #d6b24c;    /* button fill and accents on navy */
  --gold-700: #755708;    /* gold text on light backgrounds (AA) */
  --gold-50: #fbf5e6;
  /* Neutrals */
  --ink: #1c2430;
  --muted: #526071;
  --line: #dde3ea;
  --line-strong: #848f9e; /* form control borders (3:1) */
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  /* Status */
  --ok: #17663f;   --ok-50: #e6f4ec;   --ok-line: #b5dfc9;
  --warn: #805300; --warn-50: #fff5dc; --warn-line: #eed28a;
  --bad: #a81f16;  --bad-50: #fdecea;  --bad-line: #f3c0bb;
  --info: #1b5594; --info-50: #e8f1fb; --info-line: #bad3ef;
  /* Shape */
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.07);
  --shadow-lg: 0 12px 32px rgba(16,24,40,.18);
  --focus: 0 0 0 3px rgba(31,78,120,.28);
  /* Space */
  --s1: .25rem; --s2: .5rem; --s3: .75rem; --s4: 1rem; --s5: 1.5rem; --s6: 2rem;
  /* Type */
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
  --text-xs: .75rem; --text-sm: .8125rem; --text-md: 1rem; --text-lg: 1.15rem; --text-xl: 1.5rem; --text-2xl: 1.75rem;
  --sidebar-w: 244px;
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { font-family: var(--font); font-size: 14px; color: var(--ink); background: var(--bg); line-height: 1.5; -webkit-font-smoothing: antialiased; }
img, svg { max-width: 100%; }
a { color: var(--navy-700); text-underline-offset: 2px; }
a:hover { color: var(--navy); }
h1, h2, h3, h4 { color: var(--navy); margin: 0 0 var(--s2); line-height: 1.25; font-weight: 650; }
h1 { font-size: var(--text-xl); letter-spacing: -.01em; }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-md); }
h4 { font-size: .875rem; }
p { margin: 0 0 var(--s3); }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--s4) 0; }
small { font-size: var(--text-sm); }
code, kbd, .mono { font-family: var(--mono); font-size: .92em; }
:focus-visible { outline: 2px solid var(--navy-700); outline-offset: 2px; }

/* Utilities */
.muted { color: var(--muted); }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.inline { display: inline; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-ok { color: var(--ok); } .text-warn { color: var(--warn); } .text-bad { color: var(--bad); }
.stack > * + * { margin-top: var(--s3); }
.row { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.icon { width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.print-only { display: none !important; }

/* ---------- 3. Layout ---------- */
.skip-link { position: absolute; left: var(--s3); top: -4rem; z-index: 50; background: var(--surface); color: var(--navy); padding: .5rem .9rem; border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); }
.skip-link:focus { top: var(--s3); }
.layout { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: linear-gradient(180deg, var(--navy) 0%, var(--navy-900) 100%); color: #fff; flex-shrink: 0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar :focus-visible { outline-color: var(--gold-400); outline-offset: -2px; }
.brand { display: flex; align-items: center; gap: .7rem; padding: 1rem 1.1rem; color: #fff; text-decoration: none; border-bottom: 1px solid rgba(214,178,76,.35); }
.brand:hover { color: #fff; }
.brand img { width: 46px; height: 46px; object-fit: contain; flex-shrink: 0; }
.brand-text { font-weight: 650; font-size: .95rem; line-height: 1.25; letter-spacing: .06em; }
.brand-text small { display: block; font-weight: 400; font-size: var(--text-xs); letter-spacing: .02em; color: #c3d0e0; }
.nav { padding: var(--s2) .6rem var(--s5); display: flex; flex-direction: column; gap: 2px; }
.nav-section { font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; color: #a9bcd4; padding: 1.1rem .75rem .35rem; }
.nav-link { display: flex; align-items: center; gap: .65rem; color: #e3eaf3; text-decoration: none; padding: .55rem .75rem; border-radius: var(--radius-sm); }
.nav-link .icon { opacity: .8; }
.nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-link.active { background: rgba(255,255,255,.13); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 var(--gold-400); }
.nav-link.active .icon { color: var(--gold-400); opacity: 1; }
.sidebar-foot { margin-top: auto; padding: .9rem 1.1rem; font-size: var(--text-xs); color: #a9bcd4; letter-spacing: .08em; text-transform: uppercase; }
.sidebar-backdrop { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: var(--s3); background: var(--surface); border-bottom: 1px solid var(--line); padding: .55rem var(--s5); min-height: 57px; position: sticky; top: 0; z-index: 10; }
.topbar-title { font-weight: 650; font-size: var(--text-md); color: var(--navy); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-user { display: flex; align-items: center; gap: var(--s2); }
.btn.sidebar-toggle { display: none; }
.content { padding: var(--s5); max-width: 1400px; width: 100%; flex: 1; }
.content:focus { outline: none; }
.footer { padding: var(--s3) var(--s5) var(--s4); font-size: var(--text-xs); color: var(--muted); border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: var(--s2); justify-content: space-between; }

/* Role badges + user menu */
.role-badges { display: flex; gap: var(--s1); flex-wrap: wrap; }
.user-menu { position: relative; }
.user-menu > summary { list-style: none; display: flex; align-items: center; gap: var(--s2); cursor: pointer; padding: .25rem .5rem .25rem .25rem; border-radius: 999px; border: 1px solid transparent; }
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary:hover, .user-menu[open] > summary { background: var(--navy-50); border-color: var(--line); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--navy); color: #fff; display: grid; place-items: center; font-weight: 650; font-size: var(--text-sm); text-transform: uppercase; box-shadow: 0 0 0 2px var(--gold-400); flex-shrink: 0; }
.user-name { font-weight: 600; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu-panel { position: absolute; right: 0; top: calc(100% + 6px); width: 240px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: var(--s2); z-index: 30; }
.user-menu-head { padding: var(--s2) var(--s2) var(--s3); border-bottom: 1px solid var(--line); margin-bottom: var(--s2); }
.user-menu-head strong { display: block; margin-bottom: var(--s1); overflow-wrap: anywhere; }
.menu-item { display: flex; align-items: center; gap: var(--s2); width: 100%; padding: .5rem; border: 0; background: none; font: inherit; color: var(--ink); text-align: left; text-decoration: none; border-radius: var(--radius-sm); cursor: pointer; }
.menu-item:hover { background: var(--navy-50); }

/* ---------- 4. Page header ---------- */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-header h1 { margin: 0; }
.page-header p { margin: var(--s1) 0 0; color: var(--muted); }
.actions { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; }
.breadcrumbs { font-size: var(--text-sm); color: var(--muted); margin-bottom: var(--s2); display: flex; gap: var(--s2); flex-wrap: wrap; }

/* ---------- 5. Cards, grid, stats ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.25rem; margin-bottom: var(--s4); min-width: 0; }
.card > :last-child, .card form > :last-child { margin-bottom: 0; }
.card-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: var(--s2); margin-bottom: var(--s3); }
.card-header h2, .card-header h3, .card-header p { margin: 0; }
.card-accent { border-top: 3px solid var(--gold-400); }
.grid { display: grid; gap: var(--s4); margin-bottom: var(--s4); }
.grid > * { min-width: 0; }
.grid > .card, .grid > .stat { margin-bottom: 0; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1.1rem; box-shadow: var(--shadow); margin-bottom: var(--s4); min-width: 0; color: var(--ink); text-decoration: none; }
.stat-label { color: var(--muted); font-size: var(--text-sm); font-weight: 600; }
.stat-value { font-size: var(--text-2xl); font-weight: 650; line-height: 1.25; color: var(--navy); font-variant-numeric: tabular-nums; margin-top: var(--s1); overflow-wrap: anywhere; }
.stat-sub { font-size: var(--text-sm); color: var(--muted); }
a.stat:hover { border-color: var(--navy-700); color: var(--ink); }
.stat-ok { border-left: 4px solid var(--ok); }
.stat-warn { border-left: 4px solid #c58a0a; }
.stat-bad { border-left: 4px solid var(--bad); }
.quick-links { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); gap: var(--s4); margin-bottom: var(--s5); }
.quick-link { display: flex; align-items: flex-start; gap: var(--s3); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: var(--s4); text-decoration: none; color: var(--ink); }
.quick-link:hover { border-color: var(--gold); color: var(--ink); box-shadow: 0 4px 14px rgba(16,24,40,.1); }
.quick-link .icon { width: 38px; height: 38px; padding: 8px; border-radius: var(--radius-sm); background: var(--navy); color: var(--gold-400); }
.quick-link strong { display: block; color: var(--navy); }
.quick-link span > span { display: block; font-size: var(--text-sm); color: var(--muted); }

/* ---------- 6. Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 38px; border: 1px solid #c6cfda; background: var(--surface); color: var(--navy); padding: .45rem .95rem; border-radius: var(--radius-sm); font: inherit; font-weight: 600; line-height: 1.3; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background-color .12s, border-color .12s; }
.btn:hover { background: var(--navy-50); color: var(--navy); border-color: var(--navy-700); }
.btn:focus-visible { box-shadow: var(--focus); }
.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-700); border-color: var(--navy-700); color: #fff; }
.btn-gold { background: var(--gold-400); border-color: var(--gold); color: #1d1603; }
.btn-gold:hover { background: #c9a23a; border-color: var(--gold-700); color: #1d1603; }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger:hover { background: #8c1911; border-color: #8c1911; color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--navy-50); border-color: transparent; }
.btn-sm { min-height: 30px; padding: .22rem .65rem; font-size: var(--text-sm); }
.btn-block { width: 100%; }
.btn[disabled], .btn.disabled { opacity: .55; cursor: not-allowed; pointer-events: none; }

/* ---------- 7. Tables ---------- */
.table-wrap { position: relative; /* keeps .sr-only cells inside the scroll area */ overflow-x: auto;border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin-bottom: var(--s4); max-width: 100%; }
.table { width: 100%; border-collapse: collapse; }
.table th { background: var(--navy-50); color: var(--navy); text-align: left; font-weight: 650; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .035em; padding: .6rem .75rem; border-bottom: 1px solid var(--navy-100); white-space: nowrap; }
.table td { padding: .6rem .75rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th.num, .table td.num { text-align: right; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody th { background: transparent; text-transform: none; letter-spacing: 0; font-size: inherit; border-bottom: 1px solid var(--line); }
.table tfoot td, .table tfoot th { font-weight: 700; background: var(--navy-50); border-top: 2px solid var(--navy-100); border-bottom: 0; }
.table-compact td, .table-compact th { padding: .35rem .55rem; }
.table input, .table select { min-width: 5.5rem; padding-top: .3rem; padding-bottom: .3rem; min-height: 32px; }
.table input[type=number] { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.row-warn { background: var(--warn-50); }
.table tr.row-bad { background: var(--bad-50); }
.table tr.row-muted td { color: var(--muted); }
.table-actions { text-align: right; white-space: nowrap; }
.card > .table-wrap:last-child { margin-bottom: 0; }

/* ---------- 8. Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)); gap: var(--s4); align-items: start; }
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field + .field { margin-top: var(--s3); }
.form-grid > .field + .field { margin-top: 0; }
.field-wide { grid-column: 1 / -1; }
.field label, .field legend { font-weight: 600; font-size: var(--text-sm); color: var(--ink); }
.field .help { color: var(--muted); font-size: var(--text-xs); }
.field .help ul { margin: var(--s1) 0 0; padding-left: 1.1rem; }
.field .error, .errorlist { color: var(--bad); font-size: var(--text-sm); font-weight: 600; margin: 0; padding: 0; list-style: none; }
.req { color: var(--bad); margin-left: .15rem; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset.field legend { padding: 0; margin-bottom: .3rem; }
input:where(:not([type=checkbox], [type=radio], [type=submit], [type=button], [type=reset], [type=hidden], [type=image], [type=range], [type=color])),
select, textarea {
  font: inherit; line-height: 1.4; width: 100%; max-width: 100%; min-height: 38px; padding: .45rem .65rem;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background-color: var(--surface); color: var(--ink);
}
select { padding-right: 1.8rem; }
select[multiple] { padding-right: .65rem; min-height: 7rem; }
textarea { min-height: 5.5rem; resize: vertical; }
input[type=file] { padding: .3rem; cursor: pointer; }
input[type=file]::file-selector-button { font: inherit; font-weight: 600; color: var(--navy); background: var(--navy-50); border: 0; border-radius: 5px; padding: .25rem .7rem; margin-right: .6rem; cursor: pointer; }
input[type=checkbox], input[type=radio] { width: 17px; height: 17px; margin: 0; flex-shrink: 0; accent-color: var(--navy); cursor: pointer; vertical-align: middle; }
input:hover:not(:disabled), select:hover:not(:disabled), textarea:hover:not(:disabled) { border-color: var(--navy-700); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--navy-700); outline-offset: 0; border-color: var(--navy-700); box-shadow: var(--focus); }
input:disabled, select:disabled, textarea:disabled, input[readonly], textarea[readonly] { background-color: #edf0f4; color: var(--muted); cursor: not-allowed; }
input[readonly], textarea[readonly] { cursor: default; }
::placeholder { color: #66717f; opacity: 1; }
[aria-invalid="true"], .has-error input, .has-error select, .has-error textarea { border-color: var(--bad) !important; }
/* Checkbox / radio rows (field.html and Django's default widgets) */
.field-check .check-row { display: flex; align-items: center; gap: var(--s2); min-height: 28px; }
.field-check label { font-size: .875rem; cursor: pointer; }
.field label:has(> input[type=checkbox]), .field label:has(> input[type=radio]) { display: inline-flex; align-items: center; gap: var(--s2); font-weight: 400; font-size: .875rem; min-height: 28px; cursor: pointer; }
.choices > div { display: flex; flex-wrap: wrap; gap: .15rem var(--s4); }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: 1.25rem; padding-top: var(--s4); border-top: 1px solid var(--line); }
.form-section { margin: var(--s5) 0 var(--s3); padding-bottom: var(--s1); border-bottom: 2px solid var(--navy-50); }
.toolbar { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; margin-bottom: var(--s3); }
.toolbar input:where(:not([type=checkbox], [type=radio])), .toolbar select { width: auto; min-width: 180px; }
.toolbar input[type=search] { min-width: min(280px, 100%); }
.toolbar label:has(> input[type=checkbox]) { display: inline-flex; align-items: center; gap: var(--s2); }
.toolbar form { display: contents; }

/* ---------- 9. Badges, alerts, empty ---------- */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .1rem .55rem; border-radius: 999px; font-size: var(--text-xs); font-weight: 650; line-height: 1.6; background: var(--navy-50); color: var(--navy); border: 1px solid var(--navy-100); white-space: nowrap; }
.badge-ok { background: var(--ok-50); color: var(--ok); border-color: var(--ok-line); }
.badge-warn { background: var(--warn-50); color: var(--warn); border-color: var(--warn-line); }
.badge-bad { background: var(--bad-50); color: var(--bad); border-color: var(--bad-line); }
.badge-info { background: var(--info-50); color: var(--info); border-color: var(--info-line); }
.badge-gold { background: var(--gold-50); color: var(--gold-700); border-color: #e8d59f; }
.badge-muted { background: #edf0f4; color: #465263; border-color: #d5dbe3; }
.messages { margin-bottom: var(--s4); }
.alert { padding: .75rem 1rem; border-radius: var(--radius-sm); margin-bottom: var(--s3); border: 1px solid var(--info-line); border-left-width: 4px; background: var(--info-50); color: var(--info); }
.alert > :last-child { margin-bottom: 0; }
.alert a { color: inherit; font-weight: 650; }
.alert ul { margin: var(--s1) 0 0; padding-left: 1.2rem; }
.alert-title { display: block; font-weight: 700; }
.alert-success { background: var(--ok-50); color: var(--ok); border-color: var(--ok-line); border-left-color: var(--ok); }
.alert-warning { background: var(--warn-50); color: var(--warn); border-color: var(--warn-line); border-left-color: #c58a0a; }
.alert-error, .alert-danger { background: var(--bad-50); color: var(--bad); border-color: var(--bad-line); border-left-color: var(--bad); }
.alert-info { border-left-color: var(--info); }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.empty > .icon { width: 40px; height: 40px; stroke-width: 1.4; color: var(--gold); margin-bottom: var(--s2); }
.empty h2, .empty h3 { margin-bottom: var(--s1); }
.empty p { max-width: 46ch; margin: 0 auto var(--s3); }

/* ---------- 10. Detail lists, tabs, pagination ---------- */
.dl { display: grid; grid-template-columns: minmax(140px, max-content) minmax(0, 1fr); gap: .5rem var(--s5); margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.tabs { display: flex; gap: var(--s1); border-bottom: 1px solid var(--line); margin-bottom: var(--s4); flex-wrap: wrap; }
.tab { padding: .55rem .9rem; margin-bottom: -1px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; }
.tab:hover { color: var(--navy); border-bottom-color: var(--navy-100); }
.tab.active { color: var(--navy); border-bottom-color: var(--gold); }
.pagination { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s2); margin: var(--s3) 0 var(--s4); }
.pagination-info { color: var(--muted); font-size: var(--text-sm); }

/* ---------- 11. Sign-in ---------- */
.auth-page { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: var(--s5) var(--s4);
  background: radial-gradient(900px 500px at 50% -10%, rgba(214,178,76,.22), transparent 70%), linear-gradient(160deg, var(--navy) 0%, var(--navy-900) 60%, #08182d 100%); }
.auth-card { width: min(420px, 100%); background: var(--surface); border-radius: 16px; padding: 2rem 2rem 1.75rem; box-shadow: 0 30px 70px rgba(0,0,0,.4); border-top: 4px solid var(--gold-400); }
.auth-card .auth-logo { display: block; width: 190px; height: auto; margin: 0 auto 1.25rem; }
.auth-card h1 { text-align: center; font-size: 1.35rem; margin-bottom: var(--s1); }
.auth-sub { text-align: center; color: var(--muted); margin-bottom: var(--s5); }
.auth-card .field input { min-height: 44px; }
.auth-card .btn-block { min-height: 44px; margin-top: var(--s5); }
.input-group { display: flex; gap: var(--s2); }
.input-group > input { flex: 1; min-width: 0; }
.input-group > .btn { min-width: 4.5rem; }
.auth-help { text-align: center; font-size: var(--text-sm); color: var(--muted); margin: var(--s4) 0 0; }
.auth-foot { color: #b7c6da; font-size: var(--text-xs); margin-top: var(--s5); text-align: center; }

/* ---------- 12. Responsive ---------- */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .role-badges.topbar-roles { display: none; }
}
@media (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; height: 100%; width: min(280px, 85vw); z-index: 40; transform: translateX(-100%); visibility: hidden; transition: transform .2s ease, visibility 0s linear .2s; }
  .sidebar.open { transform: none; visibility: visible; transition: transform .2s ease; box-shadow: var(--shadow-lg); }
  .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(8,20,38,.5); opacity: 0; pointer-events: none; transition: opacity .2s; }
  .nav-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .nav-open { overflow: hidden; }
  .nav-link { padding-top: .7rem; padding-bottom: .7rem; }
  .btn.sidebar-toggle { display: inline-flex; padding-left: .5rem; padding-right: .5rem; }
  .sidebar-toggle .icon { width: 22px; height: 22px; }
  .topbar { padding-left: var(--s3); padding-right: var(--s3); }
  .content { padding: var(--s4); }
  .footer { padding-left: var(--s4); padding-right: var(--s4); }
}
@media (max-width: 600px) {
  .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .user-name, .user-menu > summary > .icon { display: none; }
  .user-menu > summary { padding: .25rem; }
  .card { padding: var(--s4); }
  .dl { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .dl dd { margin-bottom: var(--s3); }
  .toolbar input:where(:not([type=checkbox], [type=radio])), .toolbar select { width: 100%; min-width: 0; }
  .form-actions > .btn { flex: 1 1 auto; }
  .page-header > .actions { width: 100%; }
  .auth-card { padding: 1.5rem 1.25rem; }
  .auth-card .auth-logo { width: 160px; }
  /* 16px stops iOS zooming into focused fields */
  input, select, textarea { font-size: 16px !important; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* ---------- 13. Print (reports, payslips) ---------- */
@page { size: A4; margin: 12mm; }
@page landscape { size: A4 landscape; margin: 10mm; }
@media print {
  :root { --bg: #fff; --shadow: none; }
  body { font-size: 10.5pt; background: #fff; color: #000; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sidebar, .sidebar-backdrop, .topbar, .footer, .skip-link, .actions, .toolbar, .pagination, .form-actions, .messages, .tabs, .btn, .no-print { display: none !important; }
  .print-only { display: block !important; }
  .print-landscape { page: landscape; }
  .page-break { break-before: page; }
  .avoid-break, .stat, tr, .alert { break-inside: avoid; }
  .layout, .main { display: block; min-height: 0; }
  .content { padding: 0; max-width: none; }
  a { color: inherit; text-decoration: none; }
  h1, h2, h3 { break-after: avoid; }
  .card { box-shadow: none; border-color: #bbb; padding: 8pt 10pt; }
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .dl { grid-template-columns: max-content minmax(0, 1fr); gap: 2pt 12pt; }
  .dl dd { margin: 0; }
  .table-wrap { overflow: visible; border-color: #bbb; border-radius: 0; }
  .table { font-size: 9pt; }
  .table thead { display: table-header-group; }
  .table tfoot { display: table-row-group; }
  .table th, .table td { padding: 3pt 5pt; border-bottom: 1px solid #ccc; }
  .table th { white-space: normal; }
  .print-header { display: flex !important; align-items: center; gap: 12pt; border-bottom: 2pt solid var(--gold); padding-bottom: 6pt; margin-bottom: 10pt; }
  .print-header img { height: 48pt; width: auto; }
}

/* ---------- 14. Page patterns ---------- */
.breadcrumbs a { text-decoration: none; font-weight: 600; }
.breadcrumbs a:hover { text-decoration: underline; }
.page-header h1 .badge { vertical-align: middle; margin-left: var(--s1); }
.section-title { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); flex-wrap: wrap; margin: var(--s5) 0 var(--s3); }
.section-title:first-child { margin-top: 0; }
.section-title h2 { margin: 0; }
.card-title-row { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.card-title-row h2 { margin: 0; }
.hint { color: var(--muted); font-size: var(--text-sm); }

/* Pay ledger: the payroll sum read left to right (gross, less deductions, equals pay) */
.ledger { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto minmax(0, 1.15fr); align-items: stretch; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: var(--s4); }
.ledger-item { padding: 1rem 1.25rem; min-width: 0; }
.ledger-label { display: block; color: var(--muted); font-size: var(--text-sm); font-weight: 600; }
.ledger-value { display: block; font-size: var(--text-2xl); font-weight: 700; line-height: 1.3; color: var(--navy); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.ledger-sub { display: block; color: var(--muted); font-size: var(--text-sm); }
.ledger-op { align-self: center; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; border: 1px solid var(--gold); color: var(--gold-700); font-weight: 700; font-size: 1.1rem; line-height: 1; }
.ledger-total { background: var(--navy); }
.ledger-total .ledger-value { color: #fff; }
.ledger-total .ledger-label { color: var(--gold-400); }
.ledger-total .ledger-sub { color: #c9d6e6; }
.ledger-op + .ledger-total { margin-left: var(--s4); }

/* Month progress: the steps a payroll month goes through, in order */
.steps { display: flex; flex-wrap: wrap; gap: var(--s2); list-style: none; padding: 0; margin: 0 0 var(--s4); counter-reset: step; }
.step { counter-increment: step; flex: 1 1 190px; display: flex; align-items: center; gap: var(--s3); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem .8rem; }
.step::before { content: counter(step); width: 28px; height: 28px; flex-shrink: 0; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: var(--text-sm); border: 1px solid var(--line-strong); color: var(--muted); }
.step strong { display: block; font-size: .875rem; color: var(--ink); }
.step small { display: block; color: var(--muted); font-size: var(--text-xs); }
.step.is-current { border-color: var(--gold); box-shadow: inset 0 -3px 0 var(--gold); }
.step.is-current::before { background: var(--navy); border-color: var(--navy); color: #fff; }
.step.is-done::before { content: "\2713"; background: var(--ok-50); border-color: var(--ok); color: var(--ok); }

/* Wide tables: first column stays in view; optional height limit keeps headings in view */
.table-sticky th:first-child, .table-sticky td:first-child { position: sticky; left: 0; box-shadow: 1px 0 0 var(--line); }
.table-sticky td:first-child { background: var(--surface); z-index: 1; }
.table-sticky th:first-child { z-index: 3; }
.table-sticky tfoot td:first-child { background: var(--navy-50); }
.table-sticky tbody tr:hover td:first-child { background: var(--surface-2); }
.table-wrap.table-scroll { max-height: 70vh; overflow: auto; }
.table-scroll thead th { position: sticky; top: 0; z-index: 2; }
.table-scroll thead th:first-child { z-index: 3; }
.cell-name { min-width: 10rem; }
.cell-name > a, .cell-name > strong { display: block; font-weight: 600; white-space: nowrap; }
.cell-sub { display: block; color: var(--muted); font-size: var(--text-xs); white-space: nowrap; }
.table .actions { flex-wrap: nowrap; justify-content: flex-end; }
.table .table-actions .btn + .btn, .table .table-actions form { margin-left: var(--s1); }
.table-text td { vertical-align: top; }

/* Profile header (worker page) */
.profile { display: flex; flex-wrap: wrap; gap: var(--s4) var(--s6); align-items: center; }
.profile-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(170px, 100%), 1fr)); gap: var(--s4); flex: 1 1 260px; margin: 0; }
.profile-facts dt { color: var(--muted); font-size: var(--text-sm); font-weight: 600; }
.profile-facts dd { margin: 0; font-size: var(--text-lg); font-weight: 700; color: var(--navy); overflow-wrap: anywhere; }
.profile-facts dd small { display: block; font-weight: 400; color: var(--muted); font-size: var(--text-xs); }
.avatar.avatar-lg { width: 60px; height: 60px; font-size: 1.5rem; }

/* Show / hide sections */
details.disclosure > summary { cursor: pointer; font-weight: 650; color: var(--navy); list-style: none; display: flex; align-items: center; gap: var(--s2); min-height: 32px; }
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary .icon { transition: transform .15s; transform: rotate(-90deg); }
details.disclosure[open] > summary .icon { transform: none; }
details.disclosure[open] > summary { margin-bottom: var(--s3); }
.filters-more > summary { cursor: pointer; color: var(--navy-700); font-weight: 600; min-height: 38px; line-height: 38px; padding: 0 var(--s2); }
.filters-more[open] { flex-basis: 100%; order: 10; }
.filters-body { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); align-items: center; padding: var(--s3); margin-top: var(--s1); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.toolbar label.date-filter { display: inline-flex; align-items: center; gap: var(--s2); font-weight: 600; font-size: var(--text-sm); }
.tabs.tabs-sub { border: 0; gap: var(--s1); }
.tabs-sub .tab { border: 1px solid var(--line); border-radius: 999px; padding: .3rem .9rem; background: var(--surface); margin: 0; }
.tabs-sub .tab.active { background: var(--navy); border-color: var(--navy); color: #fff; }

/* Report cards: actions sit at the bottom so cards line up */
.card.report-card { display: flex; flex-direction: column; margin-bottom: 0; }
.report-card .report-actions { margin-top: auto; padding-top: var(--s3); display: grid; gap: var(--s2); }
.report-actions p { margin: 0; }
.report-total { font-size: var(--text-lg); font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }

/* Payslip on screen and paper */
.payslip { max-width: 900px; }
.payslip-head { display: flex; align-items: center; gap: var(--s5); flex-wrap: wrap; border-bottom: 3px solid var(--gold); padding-bottom: var(--s3); margin-bottom: var(--s4); }
.payslip-head img { height: 72px; width: auto; }
.payslip-head h1 { margin: 0; }
.payslip-head p { margin: 0; color: var(--muted); }
.net-band { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: var(--s2); background: var(--navy); color: #fff; border-radius: var(--radius); padding: .9rem 1.25rem; margin-bottom: var(--s4); }
.net-band span { color: var(--gold-400); font-weight: 700; letter-spacing: .08em; }
.net-band strong { font-size: var(--text-2xl); font-variant-numeric: tabular-nums; }

.payslip-actions { margin-bottom: var(--s3); }
.btn-danger-outline { background: var(--surface); border-color: var(--bad); color: var(--bad); }
.btn-danger-outline:hover { background: var(--bad); border-color: var(--bad); color: #fff; }
/* The encrypted document number is drawn as a text area by the model field; show it as one line. */
.field textarea[name="number"] { min-height: 0; height: 40px; resize: none; overflow: hidden; }

/* Error pages */
.card.error-page { text-align: center; padding: 3rem var(--s4); }

/* Busy button while a form is being sent */
.btn.is-busy { opacity: .7; cursor: progress; }
.btn.is-busy::after { content: ""; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 800px) {
  .ledger { grid-template-columns: minmax(0, 1fr); }
  .ledger-op { justify-self: start; margin: -15px 0 -15px 1.25rem; background: var(--surface); position: relative; z-index: 1; }
  .ledger-op + .ledger-item { border-top: 1px solid var(--line); }
  .ledger-op + .ledger-total { margin-left: 0; }
}
@media (max-width: 600px) {
  .btn-sm { min-height: 36px; }
  .table-sticky th:first-child, .table-sticky td:first-child { min-width: 8.5rem; max-width: 10rem; }
  .table-sticky .cell-name > a, .table-sticky .cell-name > strong, .table-sticky .cell-sub { white-space: normal; }
  .step { flex-basis: 100%; }
}
@media print {
  .breadcrumbs, .steps, .filters-more { display: none !important; }
  .ledger { box-shadow: none; grid-template-columns: 1fr auto 1fr auto 1fr; break-inside: avoid; }
  .ledger-item { padding: 6pt 8pt; }
  .table-wrap.table-scroll { max-height: none; }
  .table-sticky th:first-child, .table-sticky td:first-child { position: static; box-shadow: none; }
  .payslip { font-size: 9.5pt; max-width: none; }
  .payslip .card { margin-bottom: 4pt; padding: 5pt 8pt; }
  .payslip .table td { padding: 1.5pt 4pt; }
  .payslip-head img { height: 48pt; }
  .net-band { padding: 6pt 10pt; }
}

/* Site-wide notice (SITE_BANNER), e.g. on the pilot copy */
.site-banner { margin: 0; border-radius: 0; text-align: center; font-weight: 600; }

/* Two-step login pages */
.two-step-steps { text-align: left; margin: 0 0 var(--s3); padding-left: 1.25rem; }
.two-step-qr { display: block; margin: 0 auto var(--s3); background: #fff; padding: 8px; border-radius: var(--radius-sm); }
.two-step-key { text-align: left; margin-bottom: var(--s3); }
.two-step-key code, .two-step-codes code { font-size: 1.05rem; letter-spacing: .05em; }
.two-step-codes { list-style: none; padding: 0; margin: 0 0 var(--s3); display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
