:root {
  --ink: #17233a; --muted: #5d6b82; --line: #e3e8f0; --bg: #f4f6fa; --card: #fff;
  --brand: #14233b; --accent: #2457a6; --accent-soft: #e9f0fb; --danger: #b3261e; --radius: 12px;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Header */
header { background: var(--brand); color: #fff; padding: 14px 24px; font-size: 19px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; position: sticky; top: 0; z-index: 20; }
header b { letter-spacing: .2px; }
header > span { font-size: 13px; color: #aac0e0; }
.userbar { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 14px; }
.userbar .role { background: rgba(255,255,255,.14); color: #dfe9f8; border-radius: 999px; padding: 2px 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.userbar form.logout { margin: 0; }
.userbar form.logout button { background: transparent; border: 1px solid rgba(255,255,255,.35); color: #fff; padding: 6px 12px; }
.userbar form.logout button:hover { background: rgba(255,255,255,.12); }

/* Base layout (also used without JavaScript, on the login page and payslips) */
main { max-width: 1100px; margin: auto; padding: 20px; }
section { background: var(--card); padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); margin: 16px 0; box-shadow: 0 1px 2px rgba(20,35,59,.04); }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.25; }
h1 { font-size: 24px; }
h2 { font-size: 20px; }
h3 { font-size: 15px; margin-top: 22px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
form { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin: 12px 0; }
label { display: flex; flex-direction: column; gap: 5px; flex: 1 1 180px; font-size: 13px; color: var(--muted); }
input, select, textarea, button { font: inherit; border: 1px solid #c4cfdd; border-radius: 8px; padding: 9px 11px; min-width: 0; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(36,87,166,.15); }
select[multiple] { min-height: 110px; }
button { background: var(--accent); color: #fff; border: 0; cursor: pointer; font-weight: 600; padding: 10px 16px; }
button:hover { filter: brightness(1.08); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { white-space: nowrap; }
td { overflow-wrap: break-word; max-width: 320px; min-width: 70px; }
th { background: #f0f3f8; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; position: sticky; top: 0; }
tbody tr:hover { background: #fafbfd; }
.scroll { overflow: auto; max-height: 520px; border: 1px solid var(--line); border-radius: 10px; margin: 10px 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 12px 0; }
.cards article { background: var(--accent-soft); padding: 14px 16px; border-radius: 10px; color: var(--muted); font-size: 13px; }
.cards strong { display: block; font-size: 26px; color: var(--ink); }
.error { color: var(--danger); }
main > p.error, main > p:not([class]) { background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px; padding: 10px 14px; }
main > p.error { border-left-color: var(--danger); background: #fff6f5; }
.qr { width: 140px; height: auto; border: 1px solid var(--line); border-radius: 8px; }
#messages p, #notices p { padding: 10px 12px; margin: 0; border-bottom: 1px solid var(--line); }
#messages, #notices { border: 1px solid var(--line); border-radius: 10px; margin-top: 10px; max-height: 480px; overflow: auto; }
#messages:empty, #notices:empty { display: none; }
code { background: #f0f3f8; padding: 2px 6px; border-radius: 6px; word-break: break-all; }
.payslip { display: inline-block; margin: 8px 8px 0 0; padding: 7px 12px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); text-decoration: none; font-size: 13px; }
.dashboard-nav { display: flex; flex-wrap: wrap; gap: 8px; }
.dashboard-nav a { padding: 8px 12px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); text-decoration: none; }
a:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Login page */
main:has(> form input[name=email]) { max-width: 420px; margin-top: 8vh; }
main > form:has(input[name=email]) { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; flex-direction: column; align-items: stretch; box-shadow: 0 8px 24px rgba(20,35,59,.06); }
main > form:has(input[name=email]) label { flex: none; }
main > form:has(input[name=email])::before { content: "Sign in"; font-size: 20px; font-weight: 700; color: var(--ink); }

/* App shell (enabled by ui.js) */
body.app .shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 0; max-width: 1360px; margin: 0 auto; }
body.app .sidenav { position: sticky; top: 58px; align-self: start; height: calc(100vh - 58px); overflow: auto; padding: 18px 12px; display: flex; flex-direction: column; gap: 2px; border-right: 1px solid var(--line); }
body.app .sidenav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--ink); text-decoration: none; font-size: 14px; }
body.app .sidenav a:hover { background: #e9edf4; }
body.app .sidenav a[aria-current] { background: var(--accent); color: #fff; font-weight: 600; }
body.app .sidenav .icon { width: 20px; text-align: center; opacity: .85; }
body.app .sidenav .badge:not(:empty) { margin-left: auto; background: var(--danger); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
body.app main { max-width: none; margin: 0; padding: 20px 28px 60px; }
body.app main > section.panel { display: none; margin-top: 0; }
body.app main > section.panel.active { display: block; animation: fade .15s ease-out; }
@keyframes fade { from { opacity: .4; transform: translateY(4px); } to { opacity: 1; transform: none; } }
body.app main > section > h2 { font-size: 22px; padding-bottom: 12px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }

/* Collapsible tool forms */
details.tool { display: inline-block; margin: 6px 6px 6px 0; vertical-align: top; }
details.tool > summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid #c9d6ea; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 14px; user-select: none; }
details.tool > summary::-webkit-details-marker { display: none; }
details.tool > summary::before { content: "+"; font-size: 16px; line-height: 1; }
details.tool[open] { display: block; margin: 10px 0 14px; border: 1px solid #c9d6ea; border-radius: 10px; background: #fbfcfe; }
details.tool[open] > summary { border: 0; border-bottom: 1px solid #dbe4f1; border-radius: 10px 10px 0 0; width: 100%; background: var(--accent-soft); }
details.tool[open] > summary::before { content: "−"; }
details.tool > form { margin: 0; padding: 14px; }
.is-empty { display: none; }
p.empty { color: var(--muted); font-style: italic; background: #f8f9fc; border: 1px dashed var(--line); border-radius: 10px; padding: 12px 14px; margin: 10px 0; }

/* Phones and small tablets */
@media (max-width: 860px) {
  header { padding: 12px 14px; font-size: 17px; }
  .userbar > span:first-child, header > span { display: none; }
  header { flex-wrap: nowrap; }
  body.app .shell { display: block; }
  body.app .sidenav { position: sticky; top: 52px; z-index: 15; height: auto; flex-direction: row; overflow-x: auto; padding: 8px 10px; gap: 6px; border-right: 0; border-bottom: 1px solid var(--line); background: var(--bg); scrollbar-width: none; }
  body.app .sidenav a { flex: none; padding: 7px 12px; background: #fff; border: 1px solid var(--line); font-size: 13px; }
  body.app .sidenav .icon { display: none; }
  body.app main { padding: 12px 10px 40px; }
  section { padding: 14px; border-radius: 10px; }
  label { flex-basis: 100%; }
  form > button, details.tool > form > button { width: 100%; }
  details.tool { display: block; }
  details.tool > summary { width: 100%; justify-content: flex-start; }
  .scroll { max-height: none; }
}
