/* UCB HRMS & Payroll — admin console styles.
   No external fonts or CDNs: everything is served from this origin so the
   strict Content-Security-Policy in src/server.js holds. */

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-alt: #f8fafb;
  --border: #dfe4ea;
  --text: #1b2733;
  --text-muted: #5d6b7a;
  --brand: #0f4c5c;
  --brand-dark: #0a3642;
  --brand-tint: #e6eff1;
  --danger: #a32020;
  --danger-tint: #fceaea;
  --warn: #8a5a00;
  --warn-tint: #fdf3e0;
  --ok: #1c6b3f;
  --ok-tint: #e7f4ec;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(16, 32, 45, .06), 0 4px 12px rgba(16, 32, 45, .05);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12171c;
    --surface: #1a2128;
    --surface-alt: #202931;
    --border: #2e3942;
    --text: #e6ecf1;
    --text-muted: #9aa8b5;
    --brand: #4aa3ba;
    --brand-dark: #3d8ca1;
    --brand-tint: #1d2f36;
    --danger: #f08a8a;
    --danger-tint: #35201f;
    --warn: #e0b055;
    --warn-tint: #332a16;
    --ok: #74c99a;
    --ok-tint: #17301f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 12px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.boot { padding: 3rem; text-align: center; color: var(--text-muted); }

/* ---------- Login ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
}

.login-card h1 { font-size: 1.25rem; margin: 0 0 .25rem; }
.login-card .sub { color: var(--text-muted); font-size: .875rem; margin: 0 0 1.5rem; }
.login-mark {
  width: 40px; height: 40px;
  border-radius: 8px;
  background: var(--brand);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; letter-spacing: .5px;
  margin-bottom: 1rem;
}

/* ---------- App shell ---------- */

.shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .7rem 1.25rem;
  flex-wrap: wrap;
}
.topbar .brand { display: flex; align-items: center; gap: .7rem; color: #fff; text-decoration: none; min-width: 0; }
.topbar .brand-text strong { display: block; font-weight: 600; letter-spacing: .2px; line-height: 1.25; }
.topbar .brand-text small { display: block; font-weight: 400; opacity: .75; font-size: .75rem; }
/* Uploaded logos can be any colour, so they sit on a white tile to stay legible on the brand bar. */
.topbar .brand-logo { height: 36px; max-width: 150px; object-fit: contain; background: #fff; border-radius: 4px; padding: 3px 6px; }
.topbar .brand-mark {
  width: 36px; height: 36px; border-radius: 6px; background: rgba(255, 255, 255, .16);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: .8125rem; letter-spacing: .5px; flex-shrink: 0;
}
button.on-brand { background: #fff; color: var(--brand-dark); border-color: transparent; }
button.on-brand:hover { background: #e9f1f3; }
.topbar .who { display: flex; align-items: center; gap: .85rem; font-size: .8125rem; }
.topbar .who .meta { text-align: right; line-height: 1.3; }
.topbar .who .meta strong { display: block; font-weight: 600; }
.topbar .who .meta span { opacity: .8; }

.body { flex: 1; display: flex; align-items: stretch; }  /* sidebar runs the full page height */

.sidebar {
  width: 210px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 1.25rem .75rem;
  border-right: 1px solid var(--border);
  background: var(--surface);
  min-height: calc(100vh - 56px);
}
.sidebar .label {
  font-size: .6875rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  padding: 0 .65rem;
  margin-bottom: .4rem;
}
.sidebar a {
  display: block;
  padding: .5rem .65rem;
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  font-size: .875rem;
  margin-bottom: .15rem;
}
.sidebar a:hover { background: var(--surface-alt); }
.sidebar a.active { background: var(--brand-tint); color: var(--brand-dark); font-weight: 600; }
.sidebar .label:not(:first-child) { margin-top: 1rem; }

/* "Powered by" + platform favicon — shown on every bank page and bank sign-in page. */
.powered { display: flex; align-items: center; gap: .45rem; font-size: .75rem; color: var(--text-muted); padding: 0 .65rem; }
.powered img { width: 18px; height: 18px; object-fit: contain; border-radius: 3px; }

.main { flex: 1; padding: 1.5rem; min-width: 0; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem;
}
.page-head h2 { margin: 0 0 .2rem; font-size: 1.25rem; }
.page-head p { margin: 0; color: var(--text-muted); font-size: .875rem; max-width: 60ch; }

.breadcrumb { font-size: .8125rem; margin-bottom: .75rem; }
.breadcrumb a { color: var(--brand); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

/* ---------- Cards / panels ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}
.card > h3 {
  margin: 0;
  padding: .85rem 1.1rem;
  border-bottom: 1px solid var(--border);
  font-size: .9375rem;
}
/* Card header with a right-aligned action button (e.g. "Download PDF"),
   used where a plain <h3> isn't enough — see payslipCard(). */
.card > .card-head {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .6rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.card > .card-head h3 { margin: 0; padding: 0; border-bottom: none; font-size: .9375rem; }
.card .card-body { padding: 1.1rem; }
.card .card-body > p:first-child { margin-top: 0; }
.card .card-body > *:last-child { margin-bottom: 0; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: .9rem; }
/* Audit log retention notice (H.auditTable, components.js) — sits between
   the filters row and the table, so it needs the card's usual side padding
   without the card-body's top/bottom padding. */
.au-retention { padding: 0 1.1rem; }
/* Pushes one item to the far end of a flex row (e.g. the "Purge expired
   entries now" button, at the right of the audit log's Newer/Older pager). */
.push-right { margin-left: auto; }

dl.kv { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: .35rem 1.25rem; font-size: .875rem; }
dl.kv dt { color: var(--text-muted); }
dl.kv dd { margin: 0; }

/* ---------- Forms ---------- */

.field { margin-bottom: .9rem; }
.field label { display: block; font-size: .8125rem; font-weight: 600; margin-bottom: .3rem; }
.field .hint, .hint { font-size: .75rem; color: var(--text-muted); margin-top: .25rem; }

input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], input[type=url], select, textarea {
  width: 100%;
  padding: .5rem .6rem;
  font: inherit;
  font-size: .9375rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: -1px;
  border-color: var(--brand);
}
textarea { min-height: 62px; resize: vertical; }

button {
  font: inherit;
  font-size: .875rem;
  font-weight: 600;
  padding: .5rem .95rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
}
button:hover { background: var(--brand-dark); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
button.secondary:hover { background: var(--surface-alt); }
button.danger { background: var(--surface); color: var(--danger); border-color: var(--border); }
button.danger:hover { background: var(--danger-tint); }
button.link {
  background: none; border: none; color: var(--brand);
  padding: 0; font-weight: 500; text-decoration: underline;
}
button.link:hover { background: none; color: var(--brand-dark); }
button.sm { padding: .3rem .6rem; font-size: .8125rem; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.btn-row.spaced { margin-top: 1rem; }

/* Small layout utilities. These exist as classes rather than inline
   style="" attributes on purpose: the Content-Security-Policy set in
   src/server.js is strict (style-src 'self', no 'unsafe-inline'), so the
   browser refuses inline styles outright. */
.block { width: 100%; }
.narrow { max-width: 460px; }
.narrow-wide { max-width: 520px; }
.nav-label-gap { margin-top: 1rem; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th, td { text-align: left; padding: .6rem 1.1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th {
  font-size: .6875rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); background: var(--surface-alt); font-weight: 600;
}
tbody tr:last-child td { border-bottom: none; }
td.actions { white-space: nowrap; text-align: right; }
td.actions button { margin-left: .35rem; }
.empty { padding: 1.75rem 1.1rem; text-align: center; color: var(--text-muted); font-size: .875rem; }

/* ---------- Badges & notices ---------- */

.badge {
  display: inline-block;
  font-size: .6875rem; font-weight: 600;
  letter-spacing: .03em;
  padding: .15rem .45rem;
  border-radius: 3px;
  background: var(--surface-alt);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge.ok { background: var(--ok-tint); color: var(--ok); border-color: transparent; }
.badge.off { background: var(--danger-tint); color: var(--danger); border-color: transparent; }
.badge.warn { background: var(--warn-tint); color: var(--warn); border-color: transparent; }
.badge.role { background: var(--brand-tint); color: var(--brand-dark); border-color: transparent; }

.notice {
  padding: .7rem .9rem;
  border-radius: var(--radius);
  font-size: .875rem;
  margin-bottom: 1rem;
  border: 1px solid transparent;
}
.notice.error { background: var(--danger-tint); color: var(--danger); }
.notice.ok { background: var(--ok-tint); color: var(--ok); }
.notice.warn { background: var(--warn-tint); color: var(--warn); }
.notice:empty { display: none; }

/* One-time credential panel — deliberately loud, it can't be recovered. */
.cred {
  border: 1px solid var(--warn);
  background: var(--warn-tint);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.25rem;
}
.cred h4 { margin: 0 0 .4rem; font-size: .9375rem; color: var(--warn); }
.cred p { margin: 0 0 .7rem; font-size: .8125rem; color: var(--text); }
.cred .pair { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.cred code {
  font-family: var(--mono);
  font-size: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .4rem .7rem;
  user-select: all;
}

code.inline {
  font-family: var(--mono); font-size: .8125rem;
  background: var(--surface-alt); border: 1px solid var(--border);
  border-radius: 3px; padding: .05rem .3rem;
}

/* ---------- MFA setup ---------- */

.mfa-setup { display: flex; gap: 1.5rem; flex-wrap: wrap; align-items: flex-start; }
.mfa-setup .qr {
  flex: 0 0 auto; background: #fff; padding: .6rem; border-radius: var(--radius);
  border: 1px solid var(--border); line-height: 0;
}
.mfa-setup .qr img { display: block; width: 176px; height: 176px; }
.mfa-setup .steps { flex: 1 1 260px; min-width: 240px; }
.mfa-setup .steps ol { margin: 0 0 1rem; padding-left: 1.2rem; font-size: .875rem; }
.mfa-setup .steps li { margin-bottom: .35rem; }
.manual-key {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  margin: .5rem 0 1rem;
}
.manual-key code {
  font-family: var(--mono); font-size: .9375rem; letter-spacing: .04em;
  background: var(--surface-alt); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .35rem .6rem; user-select: all;
}
.otp-input {
  font-family: var(--mono); font-size: 1.375rem; letter-spacing: .35em;
  text-align: center; max-width: 220px;
}
.mfa-status-row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }

.muted { color: var(--text-muted); }
.small { font-size: .8125rem; }

/* ---------- Buttons as links ---------- */

a.button {
  display: inline-block; font-size: .875rem; font-weight: 600; padding: .5rem .95rem;
  border-radius: var(--radius); border: 1px solid transparent; background: var(--brand); color: #fff;
  text-decoration: none; line-height: 1.5;
}
a.button:hover { background: var(--brand-dark); }
a.button.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
a.button.secondary:hover { background: var(--surface-alt); }
a.button.sm { padding: .3rem .6rem; font-size: .8125rem; }
td.actions a.button { margin-left: .35rem; }

/* ---------- Login extras ---------- */

.login-wrap { flex-direction: column; gap: 1rem; }
.login-logo { display: block; max-height: 64px; max-width: 220px; object-fit: contain; margin-bottom: 1rem; }
.login-links { margin-top: 1rem; font-size: .8125rem; text-align: center; }
.login-links a { color: var(--brand); }
.login-foot { display: flex; flex-direction: column; align-items: center; gap: .35rem; text-align: center; }
.notice.info { background: var(--brand-tint); color: var(--brand-dark); }

/* ---------- Layout helpers ---------- */

.licence-banner { margin-bottom: 1.25rem; }
.spaced { margin-top: 1rem; }
.spaced-b { margin-bottom: 1rem; }
.sub-h { margin: 1.1rem 0 .6rem; font-size: .875rem; }
.card-body > .sub-h:first-child, form > .sub-h:first-child { margin-top: 0; }
hr.sep { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }
.bordered-top { border-top: 1px solid var(--border); }
.card-foot { padding: .75rem 1.1rem; border-top: 1px solid var(--border); }
.inline-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.inline-form input, .inline-form select { width: auto; min-width: 12rem; }
.inline-form .otp-input { min-width: 0; width: 11rem; }
.inline-form .year-input { min-width: 0; width: 7rem; }
.filters { display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap; }
.filters .field { margin-bottom: 0; min-width: 14rem; }
.filters input[type=search] { max-width: 22rem; }
.field.wide { grid-column: 1 / -1; }
.field.check { margin-bottom: .9rem; }
.check-label { display: inline-flex; align-items: center; gap: .45rem; font-weight: 500; font-size: .875rem; cursor: pointer; }
.check-label input { width: auto; margin: 0; }
.req { color: var(--danger); }
/* Organisation Profile — branches / board member add-and-edit forms
   (views-org.js branchForm/boardForm), and the small headshot in the board
   members table. */
.inline-form-block { border-top: 1px dashed var(--border); padding-top: 1rem; margin-top: 1rem; }
.board-photo { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; display: block; }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }
code.inline.big { font-size: .9375rem; padding: .3rem .55rem; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 1.25rem; }
dl.kv.cols { grid-template-columns: auto 1fr auto 1fr; }
details summary { cursor: pointer; font-size: .875rem; font-weight: 600; color: var(--brand); }
details[open] summary { margin-bottom: .6rem; }

/* ---------- Tabs ---------- */

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; overflow-x: auto; }
.tab {
  padding: .55rem .9rem; font-size: .875rem; color: var(--text-muted); text-decoration: none;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--brand-dark); border-bottom-color: var(--brand); font-weight: 600; }

/* ---------- Stat tiles ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .9rem; margin-bottom: 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: .9rem 1rem; border-left: 3px solid var(--brand); }
.stat.warn { border-left-color: var(--warn); }
.stat.off { border-left-color: var(--danger); }
.stat-label { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 1.5rem; overflow-wrap: anywhere; font-weight: 650; margin: .15rem 0; line-height: 1.2; }
.stat-sub { font-size: .8125rem; color: var(--text-muted); }
.stat-sub a { color: var(--brand); }

/* ---------- Tables extras ---------- */

table.clickable tbody tr { cursor: pointer; }
table.clickable tbody tr:hover td { background: var(--surface-alt); }
td a { color: var(--brand); text-decoration: none; }
td a:hover { text-decoration: underline; }
tr.row-muted td { color: var(--text-muted); }
tr.row-warn td { background: var(--warn-tint); }
.row-logo { height: 20px; max-width: 40px; object-fit: contain; vertical-align: middle; }
table.stages input { max-width: 11rem; }
.seat { margin: 0 0 1rem; }

/* ---------- Organisation page ---------- */

.usage-row { display: flex; gap: 2rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.usage-row > div > div { margin-top: .2rem; }
.access-row { display: flex; gap: 1rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.access-row > div { flex: 1 1 320px; font-size: .875rem; }

/* ---------- Logo uploader ---------- */

.logo-row { display: flex; gap: 1.5rem; flex-wrap: wrap; align-items: flex-start; }
.logo-preview {
  width: 240px; height: 96px; border: 1px dashed var(--border); border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center; padding: .6rem;
  /* chequerboard shows transparency */
  background-color: #fff;
  background-image: linear-gradient(45deg, #eef1f4 25%, transparent 25%), linear-gradient(-45deg, #eef1f4 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef1f4 75%), linear-gradient(-45deg, transparent 75%, #eef1f4 75%);
  background-size: 16px 16px; background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}
.logo-preview.square { width: 96px; }
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-actions { flex: 1 1 260px; }
.logo-actions input[type=file] { font-size: .875rem; }

/* ---------- SMTP ---------- */

.smtp-last { margin-top: 1rem; font-size: .8125rem; padding: .5rem .7rem; border-radius: var(--radius); }
.smtp-last.ok { background: var(--ok-tint); color: var(--ok); }
.smtp-last.fail { background: var(--danger-tint); color: var(--danger); }
.cred .mail-ok { color: var(--ok); font-weight: 600; }
.cred .mail-fail { color: var(--danger); font-weight: 600; }

/* ---------- Checklist & timeline ---------- */

ol.checklist { list-style: none; margin: 0; padding: 0; }
ol.checklist li { padding: .45rem 0; border-bottom: 1px solid var(--border); font-size: .875rem; }
ol.checklist li:last-child { border-bottom: none; }
ol.checklist li a { color: var(--text); }
ol.checklist li.done a { color: var(--text-muted); }

ol.timeline { list-style: none; margin: 0; padding: .5rem 1.1rem 1rem; }
ol.timeline li { display: flex; gap: 1rem; padding: .7rem 0; border-bottom: 1px solid var(--border); position: relative; }
ol.timeline li:last-child { border-bottom: none; }
.tl-date { flex: 0 0 7.5rem; font-size: .8125rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.tl-body { flex: 1; font-size: .875rem; }
.tl-body > div { margin-top: .15rem; }

@media (max-width: 720px) {
  /* align-items must become `stretch` here: in column direction the
     inherited `flex-start` sizes .main to its content, so a wide table
     pushed the whole page sideways instead of scrolling inside
     .table-wrap. */
  .body { flex-direction: column; align-items: stretch; }
  .sidebar {
    width: 100%; min-height: 0;
    border-right: none; border-bottom: 1px solid var(--border);
    display: flex; flex-wrap: wrap; gap: .25rem; padding: .6rem .75rem;
  }
  .sidebar .label { display: none; }
  .sidebar a { margin: 0; }
  .main { padding: 1rem; width: 100%; max-width: 100%; }
  /* Let wide tables scroll horizontally within their card rather than
     crushing every column down to one word per line. */
  .table-wrap table { min-width: 620px; }
  .topbar .who .meta { text-align: left; }
  .sidebar { flex-direction: row; }
  .sidebar .nav-links { display: flex; flex-wrap: wrap; gap: .25rem; }
  .powered { display: none; }
  dl.kv.cols { grid-template-columns: auto 1fr; }
  .tl-date { flex-basis: 5.5rem; }
  .inline-form input, .inline-form select { min-width: 0; flex: 1 1 10rem; }
}
