/* Realgo Payroll — "crisp professional" design system (hand-rolled, no framework,
   I-18). Self-hosted OFL fonts; cool neutral surfaces; one confident blue accent;
   tabular figures for all hours/balances. Employee screens are mobile-responsive
   (single-column below ~640px, min 360px viewport — CL-4/CL-22); admin tables are
   desktop-first and scroll horizontally on narrow screens. */

/* ---- Fonts (self-hosted woff2, embedded; see static/VERSIONS) ---- */
@font-face {
  font-family: "Hanken Grotesk";
  src: url("/static/fonts/hanken-grotesk-var.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  font-style: normal;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("/static/fonts/ibm-plex-mono-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
  font-style: normal;
}

:root {
  --bg: #f3f5f9;
  --bg-tint: #eef2f8;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --fg: #0b1220;
  --muted: #566071;
  --faint: #7a8597;
  --line: #e4e8f0;
  --line-strong: #cfd6e1;

  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #e9f0ff;
  --accent-ring: rgba(37, 99, 235, .32);

  --good: #0f7b4f;
  --good-soft: #e7f6ee;
  --bad: #c62828;
  --bad-soft: #fdecec;
  --warn: #8a6100;
  --warn-soft: #fbf1d8;

  --r: 12px;
  --r-sm: 9px;
  --r-xs: 6px;
  --shadow-sm: 0 1px 2px rgba(11, 18, 32, .06), 0 1px 1px rgba(11, 18, 32, .04);
  --shadow: 0 6px 24px -8px rgba(11, 18, 32, .16), 0 2px 8px -3px rgba(11, 18, 32, .08);

  --font-sans: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-sans);
  font-size: 15.5px;
  line-height: 1.55;
  color: var(--fg);
  background:
    radial-gradient(1100px 480px at 100% -10%, var(--bg-tint), transparent 60%),
    var(--bg);
  margin: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--accent-soft); color: var(--accent-strong); }

main {
  max-width: 980px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); text-decoration: underline; text-underline-offset: 2px; }

/* numeric content lines up */
.num, .amt, td.num, .bcard .val, table tbody td { font-variant-numeric: tabular-nums; }

/* ---- Top bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem .9rem;
  padding: .6rem clamp(.9rem, 3vw, 1.6rem);
  background: rgba(255, 255, 255, .82);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .brand {
  font-weight: 800;
  font-size: 1.02rem;
  letter-spacing: -.02em;
  color: var(--fg);
  margin-right: .4rem;
  display: inline-flex;
  align-items: center;
  gap: .5rem;
}
.topbar .brand::before {
  content: "";
  width: .85rem; height: .85rem;
  border-radius: 4px;
  background: linear-gradient(135deg, var(--accent), #5b8cff);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .55);
}
.topbar .brand:hover { text-decoration: none; }
.topbar nav { display: flex; flex-wrap: wrap; gap: .15rem; align-items: center; margin-left: auto; }
.topbar nav a {
  color: var(--muted);
  font-weight: 550;
  font-size: .92rem;
  padding: .35rem .6rem;
  border-radius: var(--r-xs);
  line-height: 1;
}
.topbar nav a:hover { color: var(--fg); background: var(--bg-tint); text-decoration: none; }
.topbar nav a.active { color: var(--accent-strong); background: var(--accent-soft); }
.topbar nav form { margin: 0 0 0 .25rem; }

/* ---- Cards & layout ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 1.3rem clamp(1rem, 3vw, 1.6rem);
  margin-bottom: 1.1rem;
  box-shadow: var(--shadow-sm);
  animation: rise .42s cubic-bezier(.22, 1, .36, 1) both;
}
.card.login {
  max-width: 23rem;
  margin: clamp(2rem, 9vh, 5rem) auto;
  box-shadow: var(--shadow);
}
.card.login form button[type="submit"] { width: 100%; margin-top: .6rem; }

/* ---- Typography ---- */
h1, h2, h3 { line-height: 1.2; letter-spacing: -.015em; }
h1 { font-size: 1.5rem; font-weight: 750; margin: 0 0 .25rem; }
h2 { font-size: 1.12rem; font-weight: 700; margin: 1.5rem 0 .5rem; }
h3 {
  font-size: .76rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--faint); margin: 1.4rem 0 .5rem;
}
.eyebrow { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .09em; color: var(--faint); }
.muted { color: var(--muted); }
p { margin: .5rem 0; }

/* ---- Tags & pills ---- */
.tag {
  display: inline-block;
  font-size: .72rem; font-weight: 650; letter-spacing: .02em;
  background: var(--accent-soft); color: var(--accent-strong);
  padding: .12rem .5rem; border-radius: 999px; vertical-align: middle;
}
.pill {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .76rem; font-weight: 650;
  padding: .15rem .55rem; border-radius: 999px;
}
.pill::before { content: ""; width: .42rem; height: .42rem; border-radius: 999px; background: currentColor; }
.pill-open { background: var(--accent-soft); color: var(--accent-strong); }
.pill-done { background: var(--good-soft); color: var(--good); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }

/* ---- Forms ---- */
label { display: block; margin: .55rem 0; font-weight: 550; }
.field { display: flex; flex-direction: column; gap: .3rem; margin: 0; }
.field > .lbl, label > .lbl { font-size: .78rem; font-weight: 600; color: var(--muted); }
input, select, textarea, button { font: inherit; }
input, select, textarea {
  width: 100%;
  padding: .5rem .6rem;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-xs);
  min-height: 2.4rem;
  transition: border-color .15s, box-shadow .15s;
}
label > input, label > select { margin-top: .25rem; }
input::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus,
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
input[type="checkbox"] { width: auto; min-height: 0; accent-color: var(--accent); margin-right: .4rem; }
input[type="date"], input[type="number"] { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Buttons ---- */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font-weight: 600; font-size: .92rem;
  background: var(--accent); color: #fff;
  border: 1px solid transparent; border-radius: var(--r-xs);
  padding: .5rem .9rem; min-height: 2.4rem;
  cursor: pointer; white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: background .15s, box-shadow .15s, transform .08s, border-color .15s, color .15s;
}
button:hover, .btn:hover { background: var(--accent-strong); text-decoration: none; }
a.btn:hover { text-decoration: none; }
button:active, .btn:active { transform: translateY(1px); }
button:focus-visible, .btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }

.btn-ghost, button.btn-ghost {
  background: var(--surface); color: var(--fg);
  border-color: var(--line-strong); box-shadow: none;
}
.btn-ghost:hover, button.btn-ghost:hover { background: var(--bg-tint); color: var(--fg); }

.btn-danger, button.btn-danger {
  background: var(--surface); color: var(--bad);
  border-color: #f0c9c9; box-shadow: none;
}
.btn-danger:hover, button.btn-danger:hover { background: var(--bad); color: #fff; border-color: var(--bad); }

.btn-sm, button.btn-sm { padding: .32rem .6rem; min-height: 2rem; font-size: .85rem; }

/* ---- Notices ---- */
.notice, .error, .warnings, .locked {
  border-radius: var(--r-sm);
  padding: .65rem .85rem;
  margin: .8rem 0;
  border: 1px solid transparent;
}
.notice { background: var(--good-soft); border-color: #c7e8d5; color: var(--good); font-weight: 600; }
.error { background: var(--bad-soft); border-color: #f3cfcf; color: var(--bad); font-weight: 600; }
.warnings { background: var(--warn-soft); border-color: #ecd9a6; color: #6b4e00; }
.warnings strong { color: #5a4200; }
.warnings ul { margin: .35rem 0 0; padding-left: 1.1rem; }
.warnings li { margin: .15rem 0; }
.locked { background: var(--warn-soft); border-color: #ecd9a6; color: #6b4e00; }

/* ---- Period navigation ---- */
.periodnav {
  display: flex; flex-wrap: wrap; gap: .5rem .9rem; align-items: center;
  margin: .25rem 0 1rem; font-weight: 600; font-size: .94rem;
}
.periodnav a { padding: .25rem .1rem; }
.periodnav .muted { font-weight: 500; }
.periodnav > span { color: var(--faint); }

/* ---- Balance cards ---- */
.balance-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: .7rem;
  margin: .6rem 0 1rem;
}
.bcard {
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: .7rem .85rem;
  background: var(--surface-2);
}
.bcard .lbl { font-size: .76rem; font-weight: 650; color: var(--muted); }
.bcard .val { font-size: 1.5rem; font-weight: 750; letter-spacing: -.02em; margin: .1rem 0 0; }
.bcard .val .u { font-size: .85rem; font-weight: 600; color: var(--faint); margin-left: .1rem; }
.bcard .sub { font-size: .76rem; color: var(--faint); }
.bcard.neg { background: var(--bad-soft); border-color: #f1cccc; }
.bcard.neg .val { color: var(--bad); }
.bcard.neg .lbl { color: #9a3b3b; }

/* ---- Entry lists ---- */
ul.entries { list-style: none; padding: 0; margin: .4rem 0; }
ul.entries .entry {
  display: flex; flex-wrap: wrap; gap: .55rem; align-items: center;
  padding: .55rem .2rem; border-bottom: 1px solid var(--line);
}
ul.entries .entry:last-child { border-bottom: 0; }
.entry .when { min-width: 6.5rem; font-family: var(--font-mono); font-size: .82rem; color: var(--muted); }
.entry .amt { font-weight: 700; min-width: 3.6rem; }
.entry .note { color: var(--muted); }
.entry.adj { background: var(--accent-soft); border-radius: var(--r-xs); padding-left: .6rem; border-bottom-color: transparent; box-shadow: inset 3px 0 0 var(--accent); }

/* ---- Add forms ---- */
.addform { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; }
.addform .field { flex: 1 1 9rem; }
.addform .addbtns { display: inline-flex; gap: .45rem; align-items: center; }
.addform input[type="number"] { font-variant-numeric: tabular-nums; }
form.inline, .inline { display: inline-flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin: 0; }
form.inline input, form.inline select { width: auto; }
form.inline input[type="number"] { max-width: 6rem; }
form.inline input[type="text"] { max-width: 11rem; }
.field-sm { flex: 0 1 8rem; }
.filter { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .4rem 0 1.2rem; }
.filter select, .filter input { width: auto; }

.actions { margin-top: 1.1rem; display: flex; flex-wrap: wrap; gap: .65rem .9rem; align-items: center; }
.actions a { font-weight: 600; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); margin: .75rem 0; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; }
.table-wrap table { margin: 0; }
caption { text-align: left; font-size: .76rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); padding: .6rem .75rem 0; }
thead th {
  position: sticky; top: 0;
  background: var(--surface-2);
  font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); text-align: left;
  padding: .55rem .75rem; border-bottom: 1px solid var(--line-strong); white-space: nowrap;
}
tbody td { padding: .55rem .75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
tr.neg td { background: var(--bad-soft); color: var(--bad); }
tr.neg:hover td { background: #fbe2e2; }
td code, code { font-family: var(--font-mono); font-size: .85em; background: var(--bg-tint); padding: .05rem .3rem; border-radius: 4px; }

/* ---- Disclosure (admin edit rows) ---- */
details { margin: 0; }
details summary {
  cursor: pointer; color: var(--accent); font-weight: 600; list-style: none;
  display: inline-flex; align-items: center; gap: .3rem; user-select: none;
}
details summary::-webkit-details-marker { display: none; }
details summary::before { content: "▸"; font-size: .8em; transition: transform .15s; }
details[open] summary::before { transform: rotate(90deg); }
details[open] > .editpanel {
  margin-top: .7rem; padding: .85rem; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--r-sm);
}
.editpanel > * + * { margin-top: .8rem; }
.editgrid { display: grid; gap: .55rem; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); align-items: end; }
.editgrid button { align-self: end; }
.rowforms { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; padding-top: .7rem; border-top: 1px dashed var(--line-strong); }
.rowforms .inline { gap: .35rem; }

/* ---- Monospace export blocks (content kept byte-exact) ---- */
pre.summary, textarea.copyable {
  width: 100%;
  white-space: pre;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: .82rem; line-height: 1.5;
  background: var(--surface-2);
  color: #1c2433;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  padding: .85rem 1rem;
  margin: .4rem 0;
}
pre.summary { white-space: pre-wrap; }
textarea.copyable { resize: vertical; }

/* ---- Empty states ---- */
.empty { color: var(--faint); padding: .9rem 0; font-style: italic; }

/* ---- Motion ---- */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.balance-cards .bcard { animation: rise .42s cubic-bezier(.22, 1, .36, 1) both; }
.balance-cards .bcard:nth-child(2) { animation-delay: .04s; }
.balance-cards .bcard:nth-child(3) { animation-delay: .08s; }
.balance-cards .bcard:nth-child(4) { animation-delay: .12s; }
.balance-cards .bcard:nth-child(n+5) { animation-delay: .16s; }

/* htmx swap fade on the period grid */
#period-content.htmx-swapping { opacity: 0; transition: opacity .12s ease-out; }
#period-content.htmx-settling { opacity: 0; }
#period-content { transition: opacity .18s ease-in; }

/* ---- Responsive ---- */
@media (max-width: 640px) {
  main { padding: 1rem .8rem 2.5rem; }
  .topbar nav { margin-left: 0; width: 100%; }
  .addform { flex-direction: column; align-items: stretch; }
  .addform .field, .addform input, .addform select, .addform button { width: 100%; }
  .addform .addbtns { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .addform .addbtns button { width: 100%; }
  .addform .addbtns button[type="submit"] { grid-column: 1 / -1; }
  ul.entries .entry { flex-direction: column; align-items: stretch; gap: .25rem; }
  .editgrid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-delay: 0s !important; transition-duration: .001ms !important; }
}
