/* Design system for the payroll site. Hand written, RTL first — logical
   properties throughout so nothing needs a left-to-right twin. */

@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/Vazirmatn-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/Vazirmatn-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/Vazirmatn-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --brand: #0f766e;
  --brand-dark: #115e59;
  --brand-soft: #ccfbf1;
  --accent: #b45309;
  --ink: #0f172a;
  --ink-2: #475569;
  --ink-3: #94a3b8;
  --line: #e2e8f0;
  --line-2: #cbd5e1;
  --surface: #ffffff;
  --bg: #f1f5f6;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --info: #1d4ed8;
  --info-soft: #dbeafe;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 8px 24px -12px rgba(15, 23, 42, .18);
  --font: "Vazirmatn", "Segoe UI", Tahoma, "Iranian Sans", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.7;
}

a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0; line-height: 1.4; font-weight: 700; }
.h2 { font-size: 1.2rem; }
.h3 { font-size: 1rem; color: var(--ink); }
.muted { color: var(--ink-2); }
.small { font-size: .82rem; }
.center { text-align: center; }
.wrap { flex-wrap: wrap; }

/* ── chrome ───────────────────────────────────────────────── */
.topbar {
  background: linear-gradient(180deg, var(--brand-dark), var(--brand));
  color: #fff;
  box-shadow: var(--shadow);
}
.bar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: .6rem 1rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}
.brand { display: inline-flex; align-items: center; gap: .6rem; color: #fff; }
.brand:hover { text-decoration: none; opacity: .92; }
.brand-mark {
  width: 34px; height: 34px; flex: none; padding: 3px;
  background: #fff; border-radius: 9px; object-fit: contain;
}
.brand-text { display: grid; line-height: 1.3; }
.brand-name { font-weight: 700; font-size: .95rem; letter-spacing: -.01em; }
.brand-app { font-size: .72rem; font-weight: 500; color: #b6e7e0; }
.nav { display: flex; gap: .25rem; flex: 1 1 auto; }
.nav a {
  color: #e6fffb;
  padding: .35rem .8rem;
  border-radius: 999px;
  font-size: .92rem;
}
.nav a:hover { background: rgba(255, 255, 255, .16); color: #fff; text-decoration: none; }
.nav a.active {
  background: rgba(255, 255, 255, .22);
  color: #fff;
  font-weight: 700;
  box-shadow: inset 0 -2px 0 rgba(255, 255, 255, .75);
}
.who { display: flex; align-items: center; gap: .5rem; font-size: .85rem; }
.who-name { font-weight: 500; }
.who-org { color: #b6e7e0; }
.nav .help-link { margin-inline-start: auto; }
.nav .help-link a { display: inline-flex; align-items: center; gap: .35rem; }
.nav .notice-link { display: inline-flex; }
.nav .notice-link a { display: inline-flex; align-items: center; gap: .35rem; }
.notice-count {
  min-width: 1.2rem; height: 1.2rem; padding: 0 .32rem;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px; background: #fff; color: var(--bad);
  font-size: .7rem; font-weight: 700; line-height: 1;
}

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
  display: grid;
  gap: 1.1rem;
}

/* ── cards ────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: .9rem 1.1rem;
  border-bottom: 1px solid var(--line);
  background: #fbfdfd;
}
.card-body { padding: 1.1rem; display: grid; gap: 1rem; }
/* Grid items default to min-width:auto, which lets a wide table push the whole
   page instead of scrolling inside its wrapper. */
.card-body > *, .card-head > * { min-width: 0; }
.card-foot {
  padding: .9rem 1.1rem;
  border-top: 1px solid var(--line);
  background: #fbfdfd;
}
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 1.1rem; align-items: start; }

/* ── buttons ──────────────────────────────────────────────── */
.row { display: flex; align-items: center; gap: .55rem; }
/* A card header holds the search, the upload and the primary action; let them
   wrap instead of overflowing on a narrow screen. */
.card-head .row { flex-wrap: wrap; justify-content: flex-end; }
.btn {
  font: inherit;
  font-size: .9rem;
  padding: .45rem .95rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-2);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, transform .05s ease;
}
.btn:hover { background: #f8fafc; text-decoration: none; border-color: var(--ink-3); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-danger { background: #fff; border-color: #fca5a5; color: var(--bad); }
.btn-danger:hover { background: var(--bad-soft); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--brand-dark); }
.btn-ghost:hover { background: rgba(15, 118, 110, .08); border-color: transparent; }
/* The navbar is dark teal, so the ghost button needs the inverse treatment or
   it disappears into the bar. */
.topbar .btn-ghost { color: #fff; background: rgba(255, 255, 255, .14); border-color: rgba(255, 255, 255, .5); }
.topbar .btn-ghost:hover { background: rgba(255, 255, 255, .26); border-color: #fff; color: #fff; }
.btn-sm { font-size: .82rem; padding: .28rem .6rem; }
.btn-block { width: 100%; justify-content: center; }
/* Not flex: a <td> turned into a flex box stops filling the row height, so its
   border-bottom draws above the line under the cells beside it. */
.actions { white-space: nowrap; }
.actions > * + * { margin-inline-start: .3rem; }
.inline { display: inline-flex; gap: .3rem; }

/* ── forms ────────────────────────────────────────────────── */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: .85rem 1.1rem; }
.span-2 { grid-column: 1 / -1; }
.field { display: grid; gap: .25rem; min-width: 0; }
.field > label { font-size: .84rem; color: var(--ink-2); font-weight: 500; }
.req { color: var(--accent); margin-inline-start: .15rem; }
input, select, textarea {
  font: inherit;
  font-size: .92rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  padding: .42rem .6rem;
  width: 100%;
  min-width: 0;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand-soft);
  outline-offset: 1px;
  border-color: var(--brand);
}
textarea { resize: vertical; }
input[readonly], select:disabled { background: #f8fafc; color: var(--ink-2); }
.tiny { width: 4.5rem; }
.mini { font-size: .8rem; color: var(--ink-2); }
.year { width: 5.5rem; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .85rem; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--bad); }
.field-error { margin: 0; color: var(--bad); font-size: .8rem; }
.check { display: flex; align-items: center; gap: .45rem; font-size: .9rem; }
.check input { width: auto; }
.suffix-wrap { position: relative; display: block; direction: ltr; }
.suffix-wrap input { padding-inline-end: 2rem; }
.suffix {
  position: absolute;
  inset-inline-end: .6rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-2);
  font-size: .9rem;
  pointer-events: none;
}

.date3 { display: grid; grid-template-columns: 1fr 1.2fr .8fr; gap: .35rem; }
.group { border: 0; margin: 0; padding: 0; }
.group > legend, .group > .h3 {
  font-weight: 700;
  font-size: .95rem;
  padding: 0 0 .45rem;
  margin: 0 0 .65rem;
  border-bottom: 1px solid var(--line);
  width: 100%;
}
fieldset.group, form.group { display: grid; gap: .6rem; padding-top: .6rem; }
.search { display: flex; gap: .35rem; }
.search input { width: 15rem; }
.import { display: flex; align-items: center; gap: .35rem; }
.import input[type="file"] { width: 12.5rem; font-size: .78rem; padding: .2rem .35rem; }
.import-hint { margin: 0; padding: .7rem 1.1rem 0; }
.picker { display: flex; align-items: center; gap: .45rem; }
.picker-label { font-size: .85rem; color: var(--ink-2); }
.picker select { width: auto; }
.organization-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr));
  gap: .75rem;
  margin-bottom: 1rem;
  align-items: end;
}
.organization-filters .field { min-width: 0; }
.filter-actions { grid-column: 1 / -1; }

.login-wrap { display: grid; place-items: center; min-height: 60vh; }
.login-card { width: min(380px, 100%); display: grid; gap: 1rem; padding: 1.6rem; }
.login-card .h2 { text-align: center; margin-bottom: .3rem; }
.login-brand { display: grid; justify-items: center; gap: .35rem; padding-bottom: .9rem; border-bottom: 1px solid var(--line); }
.login-brand img { width: 70px; height: auto; }
.login-brand .firm { font-weight: 700; font-size: 1rem; text-align: center; line-height: 1.5; }
.login-brand .firm-alt { font-size: .85rem; color: var(--ink-2); text-align: center; line-height: 1.5; }

.payslip .payslip-brand {
  display: flex; align-items: center; gap: .55rem;
  padding-bottom: .7rem; margin-bottom: .9rem;
  border-bottom: 1px solid var(--line); font-weight: 700;
}
.payslip .payslip-brand img { width: 34px; height: 34px; }
.login-roles .btn { flex: 1; text-align: center; }
.payslip .fact { flex-wrap: wrap; }
.payslip .fact dd { min-width: 0; overflow-wrap: anywhere; }
.error-card { text-align: center; padding: 2.5rem 1rem; display: grid; gap: .6rem; justify-items: center; }
.error-code { font-size: 3rem; font-weight: 700; color: var(--line-2); margin: 0; line-height: 1; }

/* ── tables ───────────────────────────────────────────────── */
/* The karkard table is the page: it grows with its rows and the page scrolls,
   like the firm's review grid — no second scroll box inside the card. Only a
   narrow window scrolls sideways, to keep every figure whole. */
.table-wrap { overflow-x: auto; }
.table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .9rem; }
.table th, .table td {
  padding: .5rem .6rem;
  border-bottom: 1px solid var(--line);
  text-align: start;
  vertical-align: middle;
  white-space: nowrap;
}
.table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8fafc;
  color: var(--ink-2);
  font-weight: 500;
  font-size: .82rem;
  border-bottom: 1px solid var(--line-2);
}
.table tbody tr:hover { background: #f8fdfc; }
.table tfoot th, .table tfoot td {
  position: sticky;
  bottom: 0;
  background: #f1f5f6;
  border-top: 1px solid var(--line-2);
  font-weight: 700;
}
.table.compact th, .table.compact td { padding: .3rem .5rem; }
.num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
/* Codes and phone numbers are identifiers, not quantities: never grouped. */
.idcode { font-variant-numeric: tabular-nums; letter-spacing: .05em; white-space: nowrap; }
.is-minus { color: var(--bad); }
.is-off { opacity: .45; }
.pin { position: sticky; inset-inline-start: 0; background: var(--surface); z-index: 1; }
thead .pin { z-index: 3; background: #f8fafc; }
tfoot .pin { background: #f1f5f6; }
/* The second pinned column's offset must match the first column's real width,
   or it floats over the numbers beside it. */
/* Fixed layout: a recalculated amount must never resize its column, or every
   row shifts sideways while the employer types. The table fills the desktop
   card — no horizontal scrolling there — and every numeric column is wide
   enough for a full twelve-digit rial amount, so no figure is ever truncated.
   Narrow screens keep a minimum and scroll inside the wrapper instead. */
.grid-table { table-layout: fixed; width: 100%; font-size: .7rem; }
.grid-table th, .grid-table td { padding: .3rem .2rem; }
.grid-table thead th { font-size: .7rem; white-space: normal; line-height: 1.25; }
.grid-table .pin:not(.pin-2) { width: 2.5%; }
.grid-table .pin-2 { width: 12%; white-space: normal; padding-inline-end: .6rem; }
.grid-table td, .grid-table th { border-inline-start: 1px solid var(--line); }
/* A twelve-digit rial figure fits every amount column at a full desktop page. */
.grid-table th.num, .grid-table td.num { width: 9.2%; }
.grid-table th.col-days, .grid-table td.col-days { width: 4.5%; }
.grid-table th.col-contract, .grid-table td.col-contract { width: 10.5%; }
/* The inputs follow the table's own type scale, so a grouped figure fits the
   cell instead of scrolling inside a 0.92rem field. */
.grid-table .col-contract input, .grid-table .col-extra input,
.grid-table .col-days input {
  width: 100%; min-width: 0; font-size: .74rem; padding: .25rem .3rem;
  font-variant-numeric: tabular-nums;
}
.grid-table .col-contract input, .grid-table .col-extra input { text-align: end; }
.grid-table .col-days input { text-align: center; }
.grid-table tr.is-busy td { opacity: .55; }
/* The leaving cross: a quiet red mark beside the name, solid on hover. */
.leave-cross { background: none; border: 0; cursor: pointer; font-family: inherit; color: var(--bad); font-weight: 700; font-size: 1.05rem; line-height: 1; padding: .1rem .35rem; border-radius: 5px; vertical-align: middle; }
.leave-cross:hover, .leave-cross:focus-visible { background: var(--bad); color: #fff; }
/* The special-bonus gift mark: quiet beside the cross, accent-coloured once
   the row carries a bonus. */
.bonus-mark { display: inline-flex; align-items: center; vertical-align: middle; color: var(--ink-3); padding: .1rem .3rem; border-radius: 5px; }
.bonus-mark:hover, .bonus-mark:focus-visible { background: var(--brand); color: #fff; text-decoration: none; }
.bonus-mark.is-set { color: var(--accent); }
/* A filed leaving tints the whole row and drops the chip below the name. */
.grid-table tr.is-leaver td { background: var(--bad-soft); }
.leave-chip { display: inline-block; margin-top: .3rem; margin-inline-start: 0; }
#leave-dialog { border: 1px solid var(--line-2); border-radius: 12px; padding: 1.2rem; width: min(26rem, calc(100vw - 2rem)); }
#leave-dialog::backdrop { background: rgb(15 23 42 / .45); }
#leave-dialog .field input { width: 5.5rem; }
#bonus-dialog { border: 1px solid var(--line-2); border-radius: 12px; padding: 1.2rem; width: min(24rem, calc(100vw - 2rem)); }
#bonus-dialog::backdrop { background: rgb(15 23 42 / .45); }
#bonus-dialog .field input { width: 9rem; }
@media (max-width: 1260px) {
  /* No desktop room for twelve full-width columns: keep every figure whole
     and scroll the wrapper instead of clipping a number. */
  .grid-table { min-width: 78rem; }
  .grid-table th, .grid-table td { padding: .25rem .3rem; }
  .grid-table .pin-2 { min-width: 7rem; }
}
.kind-aggregate { color: var(--ink-2); }
.total-row th, .total-row td { font-weight: 700; }

/* organisation tree: depth is a variable, not a class per level, because a
   group may nest arbitrarily deep */
.table .org-cell, .table .group-row th {
  padding-inline-start: calc(.6rem + var(--depth, 0) * 1.1rem);
}
.table .group-row th, .table .group-row td {
  background: #f8fafc;
  border-top: 1px dashed var(--line-2);
  font-weight: 600;
}

/* ── organisation list navigation ─────────────────────────── */
/* The list scrolls inside its own box so the column header and the grand total
   stay pinned while a long branch is read; the toolbar stays above it. */
.org-table-wrap { max-height: 70vh; }
.org-nav {
  position: sticky; top: 0; z-index: 6;
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  padding: .55rem .2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 8px 14px -12px rgba(15, 23, 42, .35);
}
.org-nav-search { flex: 1 1 14rem; min-width: 10rem; }
.org-nav-jump { flex: 0 1 16rem; }
.org-nav-actions { gap: .35rem; }
.org-nav-count { margin-inline-start: auto; white-space: nowrap; }
.table tr[hidden] { display: none; }
.group-row { scroll-margin-top: 3rem; }
.group-toggle {
  display: flex; align-items: center; gap: .5rem;
  width: 100%; padding: .15rem 0;
  background: none; border: 0; cursor: pointer;
  font: inherit; font-weight: 600; color: var(--ink); text-align: start;
}
.group-toggle:hover .group-name { color: var(--brand-dark); }
.group-toggle:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
.group-toggle .chev { flex: none; color: var(--brand); transition: transform .18s ease; }
.group-toggle[aria-expanded="false"] .chev { transform: rotate(90deg); }
.group-count {
  flex: none; min-width: 1.7rem; padding: 0 .45rem;
  border-radius: 999px; background: var(--brand-soft); color: var(--brand-dark);
  font-size: .74rem; font-weight: 700; text-align: center;
  font-variant-numeric: tabular-nums;
}
.group-toggle[aria-expanded="false"] .group-count { background: var(--warn-soft); color: var(--warn); }
tr.is-flash > th, tr.is-flash > td { animation: org-flash 1.2s ease; }
@keyframes org-flash { from { background: var(--brand-soft); } to { background: transparent; } }
/* Scrollbars in the palette rather than the browser default grey. */
.table-wrap { scrollbar-width: thin; scrollbar-color: var(--line-2) var(--bg); }
.table-wrap::-webkit-scrollbar { width: 10px; height: 10px; }
.table-wrap::-webkit-scrollbar-track { background: var(--bg); }
.table-wrap::-webkit-scrollbar-thumb {
  background: var(--line-2); border-radius: 999px; border: 2px solid var(--bg);
}
.table-wrap::-webkit-scrollbar-thumb:hover { background: var(--brand); }
.signoff {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  border-top: 1px dashed var(--line-2);
  padding-top: .9rem;
  font-size: .88rem;
}
.signoff > div { display: flex; gap: .6rem; }
.signoff-label { color: var(--ink-2); min-width: 6.5rem; }
.note { margin: 0; }

/* editor table (rules) */
.editor input, .editor select { font-size: .86rem; }
.editor .wide { min-width: 18rem; }
.editor .new-row { background: #fcfffe; }
.editor .error-row td, .editor .note-row td, .table .note-row td { padding-top: 0; padding-bottom: .2rem; border-bottom: 0; }
.vars { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .35rem; }
.vars li { background: #f1f5f9; border: 1px solid var(--line); border-radius: 6px; padding: .1rem .45rem; }
code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .82rem; }
.tag { background: #f1f5f9; border-radius: 6px; padding: .05rem .4rem; font-size: .8rem; margin-inline-end: .25rem; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .5rem 1.2rem; margin: 0; }
.fact { display: flex; gap: .5rem; border-bottom: 1px dotted var(--line); padding-bottom: .2rem; min-width: 0; }
.fact dt { color: var(--ink-2); font-size: .84rem; min-width: 7.5rem; }
.fact dd { margin: 0; font-weight: 500; min-width: 0; overflow-wrap: anywhere; }

/* ── status ───────────────────────────────────────────────── */
.chip {
  display: inline-block;
  font-size: .76rem;
  padding: .08rem .5rem;
  border-radius: 999px;
  border: 1px solid transparent;
  margin-inline-start: .35rem;
  white-space: nowrap;
}
.chip-ok { background: var(--ok-soft); color: var(--ok); border-color: #bbf7d0; }
.chip-warn { background: var(--warn-soft); color: var(--warn); border-color: #fde68a; }
.chip-bad { background: var(--bad-soft); color: var(--bad); border-color: #fecaca; }
.chip-info { background: var(--info-soft); color: var(--info); border-color: #bfdbfe; }
.chip-idle { background: #f1f5f9; color: var(--ink-2); border-color: var(--line); }

.lock { display: inline-flex; align-items: center; }
.lock-open { color: var(--ok); }
.lock-shut { color: var(--ink-3); }
.state-open .lock-open, .state-returned .lock-open { color: var(--ok); }

.banner { margin: 0; padding: .6rem .85rem; border-radius: var(--radius-sm); font-size: .9rem; border: 1px solid transparent; }
.banner-ok { background: var(--ok-soft); color: #14532d; border-color: #bbf7d0; }
.banner-warn { background: var(--warn-soft); color: #78350f; border-color: #fde68a; }
.banner-bad { background: var(--bad-soft); color: #7f1d1d; border-color: #fecaca; }
.banner-info { background: var(--info-soft); color: #1e3a8a; border-color: #bfdbfe; }

/* ── notices ─────────────────────────────────────────────── */
.notice-list { display: grid; }
.notice-item { padding: 1rem 0; border-top: 1px solid var(--line); }
.notice-item:first-child { border-top: 0; padding-top: 0; }
.notice-item:last-child { padding-bottom: 0; }
.notice-head { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.notice-head .btn { margin-inline-start: auto; }
.notice-dot { width: .58rem; height: .58rem; border-radius: 50%; background: var(--line-2); flex: none; }
.notice-bad .notice-dot { background: var(--bad); }
.notice-warn .notice-dot { background: var(--warn); }
.notice-info .notice-dot { background: var(--info); }
.notice-detail { margin: .3rem 0 0; }
.notice-table { margin-top: .55rem; }
.notice-table th:first-child, .notice-table td:first-child { width: 14rem; }
.notice-table td { white-space: normal; }

/* ── missing data ────────────────────────────────────────── */
.is-missing > label { color: var(--bad); }
.is-missing :is(input, select, textarea),
input.is-missing, select.is-missing, textarea.is-missing {
  border-color: var(--bad);
  background: #fff7f7;
}
.is-missing :is(input, select, textarea):focus,
input.is-missing:focus, select.is-missing:focus, textarea.is-missing:focus {
  border-color: var(--bad);
  outline-color: var(--bad-soft);
}
.miss-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1rem; height: 1rem; margin-inline-start: .3rem;
  border-radius: 50%; background: var(--bad); color: #fff;
  font-size: .68rem; font-weight: 700; line-height: 1;
  vertical-align: middle;
}
.miss-flag {
  display: inline-flex; align-items: center; gap: .2rem;
  padding: 0 .45rem; border-radius: 999px;
  background: var(--bad-soft); color: var(--bad); border: 1px solid #fecaca;
  font-size: .72rem; font-weight: 600; line-height: 1.5;
  margin-inline-start: .35rem; vertical-align: middle; cursor: help;
}
.fact.is-missing { border-bottom-color: #fecaca; }
.fact.is-missing dt, .fact.is-missing dd, .missing-value { color: var(--bad); }
.missing-value { font-weight: 600; }

/* The thought bubble behind every red mark: hover or keyboard focus reveals it. */
.has-tip { position: relative; }
.has-tip::after {
  content: attr(data-tip);
  position: absolute; top: calc(100% + .5rem); inset-inline-start: 0;
  z-index: 30; width: max-content; max-width: min(18rem, 70vw);
  padding: .45rem .65rem; border-radius: var(--radius-sm);
  background: #7f1d1d; color: #fff;
  font-size: .78rem; font-weight: 400; line-height: 1.55; text-align: start;
  white-space: normal; box-shadow: var(--shadow);
  opacity: 0; visibility: hidden; transform: translateY(-.15rem);
  transition: opacity .12s ease, transform .12s ease, visibility .12s;
  pointer-events: none;
}
.has-tip::before {
  content: ""; position: absolute; top: calc(100% + .28rem); inset-inline-start: .8rem;
  z-index: 31; width: .5rem; height: .5rem; background: #7f1d1d;
  transform: rotate(45deg); opacity: 0; visibility: hidden;
  transition: opacity .12s ease, visibility .12s;
}
.has-tip:hover::after, .has-tip:focus-visible::after, .has-tip:focus-within::after {
  opacity: 1; visibility: visible; transform: none;
}
.has-tip:hover::before, .has-tip:focus-visible::before, .has-tip:focus-within::before {
  opacity: 1; visibility: visible;
}

.flashes { max-width: 1280px; margin: .9rem auto 0; padding: 0 1rem; display: grid; gap: .4rem; }
.flash { margin: 0; padding: .55rem .85rem; border-radius: var(--radius-sm); font-size: .9rem; border: 1px solid; }
.flash-ok { background: var(--ok-soft); color: #14532d; border-color: #bbf7d0; }
.flash-warn { background: var(--warn-soft); color: #78350f; border-color: #fde68a; }
.flash-bad { background: var(--bad-soft); color: #7f1d1d; border-color: #fecaca; }
.flash-info { background: var(--info-soft); color: #1e3a8a; border-color: #bfdbfe; }
/* With JS the flashes become toasts pinned to the viewport, not the page;
   without it they stay in-flow banners and the close button stays hidden. */
.flashes.as-toasts {
  position: fixed; top: .8rem; inset-inline: 0; z-index: 80;
  max-width: none; margin: 0;
  justify-items: center; pointer-events: none;
}
.flashes.as-toasts .flash {
  pointer-events: auto; cursor: pointer;
  max-width: min(42rem, 100%);
  display: flex; align-items: center; gap: .6rem;
  box-shadow: var(--shadow);
  transition: opacity .25s ease, transform .25s ease;
}
.flash.is-hiding { opacity: 0; transform: translateY(-8px); }
.flash-x { display: none; }
.as-toasts .flash-x {
  display: inline-flex; align-items: center;
  border: 0; background: none; padding: 0 .1rem; cursor: pointer;
  font: inherit; font-size: 1.05rem; line-height: 1; color: inherit; opacity: .55;
}
.as-toasts .flash-x:hover, .as-toasts .flash-x:focus-visible { opacity: 1; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; }
.stat { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .6rem .8rem; background: #fbfdfd; display: grid; }
.stat-num { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-cap { font-size: .8rem; color: var(--ink-2); }

.sticky-actions { position: sticky; bottom: 0; z-index: 4; }

/* Settings: a pinned section nav; anchors clear it when jumping. */
.settings-nav { position: sticky; top: .5rem; z-index: 5; }
.settings-nav nav { padding: .6rem 1rem; }
.settings-section { scroll-margin-top: 7rem; }

/* ── handbook ─────────────────────────────────────────────── */
.help-head { display: grid; gap: .3rem; }
.help-back { font-size: .85rem; color: var(--ink-2); }
.help-back:hover { color: var(--brand-dark); }
.help-lede { margin: 0; max-width: 72ch; color: var(--ink-2); }
.help-note { margin: 0; max-width: 72ch; color: var(--ink-3); font-size: .84rem; }

.help-hero { background: linear-gradient(150deg, #ffffff, #f0fdfa); }
.help-hero > .card-body { grid-template-columns: minmax(0, 1.5fr) minmax(0, .8fr); align-items: center; }
.help-hero-copy { display: grid; gap: .6rem; justify-items: start; }
.help-kicker { color: var(--brand-dark); font-weight: 700; font-size: .8rem; }
.help-art { display: grid; place-items: center; }
.help-art svg { width: min(100%, 230px); height: auto; }

.help-section-head { align-items: baseline; }
.help-role-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .9rem; }
.role-card { display: grid; gap: .35rem; align-content: start; padding: 1.1rem; color: inherit; }
.role-card:hover, .role-card:focus-visible { border-color: var(--brand); text-decoration: none; }
.role-card:focus-visible { outline: 3px solid var(--brand-soft); outline-offset: 2px; }
.role-icon {
  width: 2.4rem; height: 2.4rem; margin-bottom: .2rem; border-radius: 12px;
  background: var(--brand-soft); color: var(--brand-dark); display: grid; place-items: center;
}
.role-name { font-weight: 700; font-size: 1.05rem; }
.role-card .muted { font-size: .9rem; }
.role-go { margin-top: .3rem; color: var(--brand-dark); font-size: .85rem; font-weight: 500; }

.guide { display: grid; grid-template-columns: minmax(0, 16rem) minmax(0, 1fr); gap: 1.1rem; align-items: start; }
.guide-toc { position: sticky; top: 1rem; padding: 1rem; max-height: calc(100vh - 2rem); overflow: auto; }
.toc-title { margin: 0 0 .5rem; font-weight: 700; font-size: .9rem; }
.guide-toc .toc > ul { list-style: none; margin: 0; padding: 0; display: grid; gap: .1rem; }
.guide-toc .toc > ul > li > a { font-weight: 600; }
/* Topics under a screen: the second level of the index, so they stay readable
   but never compete with the screen names for attention. */
.guide-toc .toc ul ul {
  list-style: none; margin: .1rem 0 .4rem; padding-inline-start: .6rem;
  border-inline-start: 2px solid var(--line); display: grid; gap: .05rem;
}
.guide-toc .toc a {
  display: block; padding: .25rem .45rem; border-radius: 6px;
  color: var(--ink-2); font-size: .88rem; line-height: 1.5;
}
.guide-toc .toc ul ul a { padding: .12rem .45rem; font-size: .8rem; }
.guide-toc .toc a:hover { background: #f1f5f9; color: var(--brand-dark); text-decoration: none; }
.guide-body { display: grid; gap: 1.1rem; min-width: 0; }
.help-pager { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; padding: .8rem 1rem; }

/* Markdown prose: one flow inside the card so tables and lists keep their own rhythm. */
.help-prose { display: block; }
.help-prose > * + * { margin-top: .85rem; }
.help-prose h2 {
  margin-top: 1.9rem; padding-top: 1.1rem; border-top: 1px solid var(--line);
  font-size: 1.15rem; scroll-margin-top: 1rem;
}
.help-prose > h2:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.help-prose h3 { margin-top: 1.1rem; font-size: 1rem; scroll-margin-top: 1rem; }
.help-prose p { margin: 0; color: var(--ink-2); }
.help-prose strong { color: var(--ink); }
.help-prose ul, .help-prose ol { margin: 0; padding-inline-start: 1.5rem; color: var(--ink-2); }
.help-prose li + li { margin-top: .35rem; }
.help-prose li > ul, .help-prose li > ol { margin-top: .35rem; }
.help-prose ol { list-style-type: persian; }
.help-prose li::marker { color: var(--brand); font-weight: 700; }
.help-prose a { color: var(--brand-dark); }
.help-prose .chip { margin: 0; }
.help-prose .table { margin: 0; }
.help-prose .table-wrap { margin-top: .85rem; }
.help-quick th, .help-quick td { white-space: normal; vertical-align: top; }

.help-prose .admonition {
  margin: 0; padding: .7rem .9rem; display: grid; gap: .25rem;
  border: 1px solid transparent; border-inline-start-width: 4px;
  border-radius: var(--radius-sm);
}
.help-prose .admonition-title { margin: 0; font-weight: 700; }
.help-prose .admonition p { margin: 0; color: inherit; }
.help-prose .admonition.tip {
  background: var(--brand-soft); border-color: #99f6e4; border-inline-start-color: var(--brand); color: #134e4a;
}
.help-prose .admonition.info {
  background: var(--info-soft); border-color: #bfdbfe; border-inline-start-color: var(--info); color: #1e3a8a;
}
.help-prose .admonition.warning {
  background: var(--warn-soft); border-color: #fde68a; border-inline-start-color: var(--warn); color: #78350f;
}

/* ── narrow screens ───────────────────────────────────────── */
@media (max-width: 780px) {
  body { font-size: 14px; }
  .bar-inner { gap: .6rem; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; }
  .who { margin-inline-start: auto; }
  .who-org { display: none; }
  .split { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; }
  .search input { width: 100%; }
  .card-head { align-items: flex-start; }
  .signoff { grid-template-columns: 1fr; }
  .help-hero > .card-body { grid-template-columns: 1fr; }
  .help-art { display: none; }
  .guide { grid-template-columns: 1fr; }
  /* A full two-level index would push the page itself off the screen. */
  .guide-toc { position: static; max-height: 40vh; }
}

@media print {
  .topbar, .card-foot, .btn, .picker, .flashes, .org-nav { display: none !important; }
  .guide-toc, .help-pager, .help-art, .help-roles { display: none !important; }
  .guide { grid-template-columns: 1fr; }
  .help-prose h2 { break-after: avoid; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #999; }
  /* The printed karkard sheet is the table, its totals and the signoff only. */
  .lock, .banner, .note { display: none !important; }
  .grid-page { border: 0; }
  .grid-page .card-head { padding: 0 0 .5rem; }
  .table-wrap { max-height: none; overflow: visible; }
  /* A printed organisation list is the whole list, not the folded view. */
  .org-table-wrap tr[hidden] { display: table-row; }
  .group-toggle .chev { display: none; }
  .table thead th, .table tfoot th, .table tfoot td, .pin { position: static; }
  .grid-table { table-layout: auto; min-width: 0; font-size: .72rem; }
  .grid-table th, .grid-table td { white-space: normal; padding: .25rem .35rem; }
  .grid-table a { color: inherit; text-decoration: none; }
  .grid-table input { border: 0; background: none; padding: 0; font: inherit; min-width: 0; width: auto; }
  .signoff { break-before: avoid; }
}
/* Named page: only the karkard sheet turns landscape; the handbook keeps portrait. */
.grid-page { page: grid; }
@page grid { size: A4 landscape; margin: 10mm; }
