/* PP People — design system.
   Apple/Google-grade: mostly white, generous whitespace, one confident accent,
   purposeful semantic color, subtle depth. Light theme only, self-contained
   (no external fonts/CDN/@import — CSP blocks all of it). */

:root {
  color-scheme: light;

  /* ---- Surfaces ---- */
  --bg: #f7f8fa;
  --card: #ffffff;
  --card-2: #fbfcfd;

  /* ---- Text ---- */
  --ink: #0f172a;
  --ink-2: #475569;
  --muted: #5b6573;
  --faint: #636c7b;

  /* ---- Lines ---- */
  --line: #e6e9ef;
  --line-2: #eef1f5;

  /* ---- Accent (locked brand color, do not change) ---- */
  --accent: #0369a1;
  --accent-ink: #ffffff;
  --accent-weak: #eff6fb;
  --accent-ring: rgba(3, 105, 161, .35);

  /* ---- Semantic ---- */
  --green: #047857;
  --green-weak: #ecfdf5;
  --amber: #b45309;
  --amber-weak: #fffbeb;
  --red: #dc2626;
  --red-weak: #fef2f2;

  /* ---- Radii ---- */
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --r-pill: 999px;

  /* ---- Shadows ---- */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
  --shadow: 0 4px 16px rgba(15, 23, 42, .08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .14);
}

/* ---- Reset & base ---- */

* { box-sizing: border-box; }

/* overflow-x: clip contains the off-screen mobile drawer (translateX(100%))
   without creating a scroll container, so position: sticky keeps working. */
html { color-scheme: light; overflow-x: clip; }

body {
  margin: 0;
  overflow-x: clip;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0 0 12px; font-weight: 600; letter-spacing: -0.01em; text-wrap: balance; }
h2 { font-size: 20px; }
h3 { font-size: 15px; font-weight: 650; }
h4.doc-year { font-size: 12.5px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin: 20px 0 8px; }
p { margin: 0 0 8px; text-wrap: pretty; }

a { color: var(--accent); text-decoration: none; transition: color 150ms ease; }
a:hover { text-decoration: underline; }

code {
  background: var(--card-2); border: 1px solid var(--line-2); border-radius: 5px;
  padding: 1px 6px; font-size: 12.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

::selection { background: var(--accent-ring); }

*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.001ms !important; animation-duration: 0.001ms !important; }
  .skeleton { animation: none; }
}

.boot-loading { padding: 60px 20px; text-align: center; color: var(--muted); }

/* Visually hidden but still announced by screen readers — used for the one
   <h1> each route render carries (the page name), kept off-screen where a
   visible card heading already covers the same ground. */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Skip-to-content: off-screen until focused, then slides into the top-left. */
.skip-link {
  position: fixed; left: 8px; top: -60px; z-index: 100;
  background: var(--accent); color: var(--accent-ink);
  padding: 8px 14px; border-radius: var(--r-sm); font-weight: 600;
  text-decoration: none; transition: top 150ms ease;
}
.skip-link:focus { top: 8px; }

/* =====================================================================
   Top bar
   ===================================================================== */

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.topbar-inner {
  max-width: 1040px; margin: 0 auto;
  display: flex; align-items: center; gap: 18px;
  padding: 0 24px; height: 60px;
}
.topbar-brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 700; font-size: 15px; letter-spacing: -0.01em;
  white-space: nowrap; color: var(--ink); text-decoration: none;
}
.topbar-brand:hover { text-decoration: none; opacity: 0.85; }
.topbar-brand img { height: 30px; width: auto; display: block; }

.topbar-nav { display: flex; align-items: center; gap: 3px; flex: 1; flex-wrap: wrap; }
.topbar-nav a {
  padding: 7px 14px; border-radius: var(--r-pill);
  color: var(--ink-2); font-weight: 550; font-size: 13.5px; white-space: nowrap;
  transition: background-color 150ms ease, color 150ms ease;
}
.topbar-nav a:hover { background: var(--accent-weak); color: var(--ink); text-decoration: none; }
.topbar-nav a.active { background: var(--accent); color: var(--accent-ink); }

/* Admin dropdown (desktop) — groups the 6 admin items into one nav pill. */
.nav-dd { position: relative; }
.nav-dd-toggle {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 14px; border: none; background: transparent; border-radius: var(--r-pill);
  color: var(--ink-2); font: inherit; font-weight: 550; font-size: 13.5px; white-space: nowrap; cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}
.nav-dd-toggle:hover { background: var(--accent-weak); color: var(--ink); }
.nav-dd-toggle.active { background: var(--accent); color: var(--accent-ink); }
.nav-dd-caret { font-size: 10px; transition: transform 150ms ease; }
.nav-dd-toggle[aria-expanded="true"] .nav-dd-caret { transform: rotate(180deg); }
.nav-dd-menu {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 40;
  min-width: 190px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow-lg); padding: 6px;
  display: none; flex-direction: column; gap: 2px;
}
.nav-dd-menu.is-open { display: flex; }
.nav-dd-menu a {
  display: block; padding: 9px 12px; border-radius: var(--r-sm);
  color: var(--ink-2); font-weight: 550; font-size: 13.5px; white-space: nowrap;
  transition: background-color 150ms ease, color 150ms ease;
}
.nav-dd-menu a:hover { background: var(--card-2); color: var(--ink); text-decoration: none; }
.nav-dd-menu a.active { background: var(--accent-weak); color: var(--accent); }

.topbar-user {
  display: flex; align-items: center; gap: 12px;
  color: var(--muted); font-size: 13px; white-space: nowrap;
}
.btn-logout {
  color: var(--ink-2); font-weight: 550; font-size: 13px;
  padding: 6px 10px; border-radius: var(--r-sm);
  transition: background-color 150ms ease, color 150ms ease;
}
.btn-logout:hover { background: var(--accent-weak); color: var(--accent); text-decoration: none; }

/* Hamburger (mobile only) */
.nav-toggle {
  display: none; flex-direction: column; align-items: center; justify-content: center;
  gap: 5px; width: 40px; height: 40px; margin-left: auto;
  border: none; background: transparent; border-radius: var(--r-sm); padding: 0;
  cursor: pointer; flex-shrink: 0;
  transition: background-color 150ms ease;
}
.nav-toggle:hover { background: var(--accent-weak); }
.nav-toggle-bar {
  width: 20px; height: 2px; border-radius: 2px; background: var(--ink);
  transition: transform 180ms ease, opacity 180ms ease;
}
.nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ---- Drawer (mobile nav) ---- */

.drawer-scrim {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .4);
  opacity: 0; pointer-events: none; z-index: 30;
  transition: opacity 180ms ease;
}
.drawer-scrim.is-open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 31;
  width: 280px; max-width: 85vw;
  background: var(--card); box-shadow: var(--shadow-lg);
  /* Closed = display:none so the off-screen fixed panel creates NO horizontal
     overflow. (Mobile viewports auto-expand to contain an overflowing fixed
     element, which would push the hamburger off-screen.) It slides in on open;
     body.drawer-open clips the transient overflow during the animation. */
  display: none; flex-direction: column; padding: 18px;
  overflow-y: auto;
}
.drawer.is-open { display: flex; animation: drawer-in 180ms ease; }
@keyframes drawer-in { from { transform: translateX(100%); } to { transform: translateX(0); } }

.drawer-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 10px; padding-bottom: 16px; margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.drawer-user { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.drawer-user strong { font-size: 14.5px; font-weight: 650; color: var(--ink); }
.drawer-user .muted { font-size: 12.5px; overflow-wrap: anywhere; }
.drawer-close {
  width: 32px; height: 32px; flex-shrink: 0; border: none; background: transparent;
  border-radius: var(--r-sm); font-size: 20px; line-height: 1; color: var(--muted);
  cursor: pointer; transition: background-color 150ms ease, color 150ms ease;
}
.drawer-close:hover { background: var(--card-2); color: var(--ink); }

.drawer-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.drawer-nav a {
  display: flex; align-items: center; min-height: 44px; padding: 0 14px;
  border-radius: var(--r-sm); color: var(--ink-2); font-weight: 550; font-size: 14.5px;
  transition: background-color 150ms ease, color 150ms ease;
}
.drawer-nav a:hover { background: var(--card-2); text-decoration: none; }
.drawer-nav a.active { background: var(--accent-weak); color: var(--accent); font-weight: 650; }

.drawer-logout {
  display: flex; align-items: center; min-height: 44px; padding: 0 14px;
  margin-top: 8px; border-top: 1px solid var(--line);
  color: var(--red); font-weight: 550; font-size: 14.5px;
}
.drawer-logout:hover { background: var(--red-weak); border-radius: var(--r-sm); text-decoration: none; }

body.drawer-open { overflow: hidden; }

@media (max-width: 768px) {
  .topbar-inner { padding: 0 16px; }
  .topbar-nav, .topbar-user { display: none; }
  .nav-toggle { display: flex; }
}

/* =====================================================================
   Layout
   ===================================================================== */

.container { max-width: 1040px; margin: 0 auto; padding: 24px 24px 64px; }
/* Founder sandbox: a slim, unobtrusive notice that writes here are not saved. */
.preview-banner { max-width: 1040px; margin: 16px auto -8px; padding: 9px 16px; background: #fffbeb; border: 1px solid #fcd34d; color: #92400e; border-radius: 10px; font-size: 13px; line-height: 1.4; text-align: center; }
@media (max-width: 640px) { .preview-banner { margin: 12px 16px -4px; } }

.grid-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 16px; }

@media (max-width: 768px) {
  .container { padding: 16px 16px 64px; }
}
@media (max-width: 720px) {
  .grid-cards { grid-template-columns: 1fr; }
}

/* =====================================================================
   Card
   ===================================================================== */

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px 22px; margin-bottom: 16px;
}
.card > summary {
  cursor: pointer; font-weight: 650; color: var(--ink); list-style: none;
  display: flex; align-items: center; gap: 8px;
}
.card > summary::-webkit-details-marker { display: none; }
.card > summary::before {
  content: '▸'; display: inline-block; color: var(--faint); font-size: 11px;
  transition: transform 150ms ease;
}
.card[open] > summary::before { transform: rotate(90deg); }
.card > summary ~ * { margin-top: 14px; }

.stat { font-size: 26px; font-weight: 700; margin: 4px 0; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }

.no-access {
  max-width: 420px; margin: 80px auto 0; text-align: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow); padding: 40px 32px;
}
.no-access img { height: 40px; margin-bottom: 16px; }

/* =====================================================================
   Forms
   ===================================================================== */

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px 16px; margin-top: 8px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); font-weight: 550; }
.form-grid label.full { grid-column: 1 / -1; }
.form-grid > button { grid-column: 1 / -1; justify-self: start; margin-top: 4px; }

input, select, textarea {
  font: inherit; padding: 9px 12px; min-height: 40px; border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--card); color: var(--ink); width: 100%;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring);
}
input[type="checkbox"] { width: auto; min-height: auto; }
textarea { min-height: 76px; resize: vertical; }
.input-sm { width: 90px; min-height: 34px; padding: 6px 8px; font-variant-numeric: tabular-nums; }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
}

/* =====================================================================
   Buttons
   ===================================================================== */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; min-height: 38px; border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font: inherit; font-weight: 550; cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease, transform 150ms ease;
  text-decoration: none;
}
.btn:hover { background: var(--card-2); border-color: var(--faint); text-decoration: none; }
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow-sm); }
.btn-primary:hover { filter: brightness(.95); background: var(--accent); border-color: var(--accent); }

.btn-danger { background: var(--card); border-color: var(--line); color: var(--red); }
.btn-danger:hover { background: var(--red-weak); border-color: var(--red); }

.btn-sm { padding: 5px 12px; min-height: 30px; font-size: 13px; }

/* =====================================================================
   Table
   ===================================================================== */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
table td { font-variant-numeric: tabular-nums; }
th {
  color: var(--muted); font-weight: 650; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em;
  background: var(--card-2); border-bottom: 1px solid var(--line);
}
tbody tr.row-link { cursor: pointer; transition: background-color 150ms ease; }
tbody tr.row-link:hover { background: var(--accent-weak); }
/* Keep the payroll actions reachable on the wide grid: pin the last column to the
   right edge so Save/Preview/Reopen stay visible while the table scrolls. */
td.row-actions {
  display: flex; gap: 6px; white-space: nowrap; align-items: center;
  position: sticky; right: 0; background: var(--card);
  box-shadow: -8px 0 8px -8px rgba(15, 23, 42, .12);
}

@media (max-width: 640px) {
  .table-wrap table, .table-wrap thead, .table-wrap tbody, .table-wrap th, .table-wrap td, .table-wrap tr {
    display: block;
  }
  .table-wrap thead { display: none; }
  .table-wrap tbody tr {
    border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 10px; padding: 6px 12px;
    background: var(--card);
  }
  .table-wrap tbody tr:last-child { margin-bottom: 0; }
  .table-wrap td {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 8px 0; border-bottom: 1px solid var(--line-2); white-space: normal; text-align: right;
  }
  .table-wrap td:last-child { border-bottom: none; }
  .table-wrap td.row-actions { justify-content: flex-end; padding-top: 10px; }
  .table-wrap td::before { content: attr(data-label); font-weight: 650; color: var(--muted); margin-right: auto; }
}

/* =====================================================================
   Chips
   ===================================================================== */

.chip {
  display: inline-block; padding: 3px 11px; border-radius: var(--r-pill);
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: #f1f5f9; color: var(--muted);
}
.chip-draft, .chip-cancelled, .chip-inactive { background: #f1f5f9; color: var(--muted); }
.chip-sent, .chip-approved, .chip-active { background: var(--green-weak); color: var(--green); }
.chip-pending { background: var(--amber-weak); color: var(--amber); }
.chip-rejected { background: var(--red-weak); color: #c81e1e; }

/* =====================================================================
   Toasts
   ===================================================================== */

.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: calc(100vw - 40px); }
.toast {
  background: var(--ink); color: #fff; padding: 12px 16px; border-radius: var(--r); max-width: 320px;
  font-size: 13px; box-shadow: var(--shadow-lg); border-left: 3px solid var(--green);
  animation: toast-in 200ms ease;
  display: flex; align-items: flex-start; gap: 10px;
}
.toast-error { border-left-color: var(--red); }
.toast-dismiss {
  margin-left: auto; flex-shrink: 0; border: none; background: transparent; color: inherit;
  font-size: 16px; line-height: 1; cursor: pointer; padding: 0 2px; opacity: 0.75;
}
.toast-dismiss:hover { opacity: 1; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* =====================================================================
   Tabs
   ===================================================================== */

.tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tab {
  padding: 9px 14px; border: none; background: none; font: inherit; font-size: 13.5px;
  color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent;
  margin-bottom: -1px; transition: color 150ms ease, border-color 150ms ease;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 650; }

.person-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.person-actions { display: flex; gap: 8px; flex-wrap: wrap; }

@media (max-width: 640px) {
  .person-header { flex-direction: column; align-items: flex-start; }
}

/* =====================================================================
   Calendar
   ===================================================================== */

.cal-nav { display: flex; align-items: center; justify-content: center; gap: 16px; margin-bottom: 12px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-cell {
  min-height: 64px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 5px 7px; font-size: 12px;
}
.cal-cell.cal-head { min-height: auto; border: none; background: none; text-align: center; color: var(--muted); font-weight: 650; padding: 2px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .02em; }
.cal-cell.cal-empty { border-color: transparent; background: none; }
.cal-day { font-weight: 650; }
.cal-badge { display: block; margin-top: 3px; padding: 2px 6px; border-radius: 5px; font-size: 11px; font-weight: 550; }
.cal-holiday { background: var(--amber-weak); color: var(--amber); }
.cal-leave { background: var(--accent-weak); color: var(--accent); }

@media (max-width: 640px) {
  .cal-cell { min-height: 48px; font-size: 10px; padding: 4px; }
  .cal-badge { font-size: 9.5px; padding: 1px 4px; }
}

/* =====================================================================
   Lists
   ===================================================================== */

.doc-list { list-style: none; margin: 0; padding: 0; }
.doc-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line-2); }
.doc-list li:last-child { border-bottom: none; }

/* Documents tab table: Download column shrinks to content + right-aligns, so the
   filename column takes the width and the Type column lines up across rows. */
.doc-dl { width: 1px; white-space: nowrap; text-align: right; }

.upcoming-list { list-style: none; margin: 0; padding: 0; font-size: 13.5px; }
.upcoming-list li { padding: 5px 0; }

.approval-list { display: flex; flex-direction: column; gap: 12px; }
.approval-item {
  display: flex; justify-content: space-between; gap: 16px; padding: 16px;
  border: 1px solid var(--line); border-radius: var(--r); flex-wrap: wrap;
  background: var(--card);
}
.approval-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.approval-actions input { width: 200px; }

@media (max-width: 640px) {
  .approval-item { flex-direction: column; }
  .approval-actions input { width: 100%; }
}

.dl-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 20px; margin: 0; }
.dl-row dt { font-size: 12.5px; color: var(--muted); margin-bottom: 3px; }
.dl-row dd { margin: 0; font-weight: 550; }

@media (max-width: 640px) {
  .dl-grid { grid-template-columns: 1fr; }
}

.payroll-toolbar { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.payroll-toolbar label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); font-weight: 550; }
.payroll-toolbar input { width: 100px; }

/* =====================================================================
   Utility
   ===================================================================== */

.muted { color: var(--muted); }
.cap { text-transform: capitalize; }
.text-red { color: var(--red); font-weight: 550; }
.link { font-size: 13.5px; font-weight: 550; }
.badgerow { margin-bottom: 10px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.tabular { font-variant-numeric: tabular-nums; }

/* Loading skeleton block (see skeleton() in app.js). */
.skeleton {
  background: linear-gradient(90deg, var(--line-2) 25%, var(--card-2) 37%, var(--line-2) 63%);
  background-size: 400% 100%;
  animation: sk 1.4s ease infinite;
  border-radius: var(--r-sm);
}
@keyframes sk { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* Inline form-field error (see setFieldError() in app.js). */
.field-error { color: var(--red); font-size: 12.5px; margin-top: 4px; }
