/*
 * APEX ERP — the shell.
 *
 * ===========================================================================
 * THE DIRECTION, STATED SO IT IS NOT DRIFTED AWAY FROM
 * ===========================================================================
 * A FINANCIAL DOCUMENT rendered as an application: ink on parchment, a heavy
 * navy rail, rules instead of boxes, and every figure in a monospace so that
 * columns of money line up on the decimal the way a printed ledger does.
 *
 * Deliberately NOT the default admin-panel look — uniform rounded cards on a
 * grey field with one blue accent. A trial balance rendered that way reads
 * like a marketing page, and the people who use this spend their day
 * comparing numbers in columns.
 *
 * RTL IS NATIVE, NOT MIRRORED. `dir="rtl"` on the document plus logical
 * properties (`padding-inline`, `border-inline-start`) throughout, so nothing
 * depends on `left` / `right` and an English build needs no stylesheet change.
 */

:root {
  --ink: #141d2e;
  --ink-soft: #46506a;
  --ink-faint: #7b849c;
  --paper: #f6f3ec;
  --paper-raised: #fffdf8;
  --rule: #ded6c6;
  --rule-strong: #c3b8a2;

  /* One warm accent: identity and current position only. */
  --gold: #a8762a;
  --gold-bright: #e8c37a;

  /* Semantic, never decorative. */
  --good: #1f6b4f;
  --warn: #8a5a10;
  --bad: #97331f;
  --info: #2a5d8a;
  --absent: #5c4a7a;

  --sidebar-w: 16.5rem;
  --topbar-h: 3.75rem;

  --text-h1: clamp(1.35rem, 1.1rem + 1vw, 1.9rem);
  --text-h2: clamp(1.05rem, 0.95rem + 0.5vw, 1.3rem);
  --gutter: clamp(1rem, 0.6rem + 1.6vw, 2.25rem);

  --mono: ui-monospace, 'Cascadia Mono', Consolas, 'Courier New', monospace;
  --sans: 'Segoe UI', system-ui, 'Noto Naskh Arabic', 'Traditional Arabic', Tahoma, sans-serif;
}

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

html,
body {
  margin: 0;
  padding: 0;
  block-size: 100%;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-block-size: 100vh;
}

/* ================================================================= sidebar */

.sidebar {
  background: var(--ink);
  color: var(--paper);
  display: flex;
  flex-direction: column;
  position: sticky;
  inset-block-start: 0;
  block-size: 100vh;
  block-size: 100dvh;
  /* Only the menu scrolls (`.nav`): the mark and the sign-out stay in view. */
  overflow: hidden;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.1rem 1.15rem;
  border-block-end: 1px solid rgb(255 255 255 / 8%);
}

.sidebar__mark {
  display: grid;
  place-items: center;
  inline-size: 2.4rem;
  block-size: 2.4rem;
  border: 2px solid var(--gold);
  border-radius: 4px;
  color: var(--gold-bright);
  font-size: 1.35rem;
  line-height: 1;
  flex: none;
}

.sidebar__name strong {
  display: block;
  font-size: 1.1rem;
  letter-spacing: -0.2px;
}

.sidebar__name small {
  display: block;
  color: var(--gold-bright);
  font-size: 0.7rem;
  letter-spacing: 0.4px;
}

/*
 * THE MENU IS A TREE (26 Sep 2026). Its rows are the sections — a heading
 * button, or the one screen of a section drawn as its link — and under an
 * open heading the screens of that section, set in under its label. Only
 * this part of the rail scrolls: the mark above and the sign-out below stay.
 */
.nav {
  flex: 1;
  min-block-size: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.75rem 0 1.5rem;
  scrollbar-width: thin;
  scrollbar-color: rgb(255 255 255 / 18%) transparent;
}

.nav__tree,
.nav__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav__list {
  padding-block-end: 0.35rem;
}

.nav__list[hidden] {
  display: none;
}

.nav__heading,
.nav__link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  inline-size: 100%;
  padding: 0.5rem 1.15rem;
  background: none;
  border: 0;
  border-inline-start: 3px solid transparent;
  color: rgb(246 243 236 / 78%);
  font: inherit;
  font-size: 0.92rem;
  text-align: start;
  text-decoration: none;
  cursor: pointer;
  transition:
    background-color 120ms ease,
    color 120ms ease;
}

/*
 * The rows of the tree. A heading was 0.68rem with 1.2px of letter-spacing —
 * too small to read, and spacing pulls joined Arabic letters apart; it is a
 * control now, and reads like one.
 */
.nav__heading,
.nav__link--top {
  color: rgb(246 243 236 / 90%);
  font-weight: 600;
}

.nav__list .nav__link {
  padding-inline-start: 2.4rem;
  font-size: 0.88rem;
}

.nav__heading:hover,
.nav__link:hover {
  background: rgb(255 255 255 / 6%);
  color: var(--paper);
}

.nav__heading:focus-visible,
.nav__link:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: -2px;
}

.nav__link[aria-current='page'] {
  background: rgb(168 118 42 / 18%);
  border-inline-start-color: var(--gold);
  color: #fff;
  font-weight: 600;
}

.nav__icon {
  inline-size: 1.15rem;
  text-align: center;
  opacity: 0.85;
  flex: none;
}

.nav__label {
  flex: 1;
}

/* A closed section that holds the current screen says so with one gold dot. */
.nav__dot {
  display: none;
  inline-size: 0.4rem;
  block-size: 0.4rem;
  border-radius: 50%;
  background: var(--gold-bright);
  flex: none;
}

.nav__section--current > .nav__heading[aria-expanded='false'] .nav__dot {
  display: block;
}

/* Read aloud with the dot; never seen. */
.nav__hint {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/*
 * Closed, the chevron points left — onward, in Arabic; open, it points down.
 * Two sides of a small square, turned: PHYSICAL sides on purpose, because the
 * angle is what draws the glyph. An English build turns it the other way.
 */
.nav__chevron {
  inline-size: 0.42rem;
  block-size: 0.42rem;
  border-left: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  opacity: 0.7;
  flex: none;
  transform: rotate(45deg);
  transition: transform 150ms ease;
}

.nav__heading[aria-expanded='true'] .nav__chevron {
  transform: rotate(-45deg);
}

html[dir='ltr'] .nav__heading[aria-expanded='false'] .nav__chevron {
  transform: rotate(-135deg);
}

.nav__empty {
  margin: 0.9rem 0 0;
  padding: 0.35rem 1.15rem;
  color: var(--ink-faint);
  font-size: 0.82rem;
}

.nav__empty strong {
  display: block;
  margin-block-end: 0.35rem;
  color: rgb(246 243 236 / 78%);
}

.sidebar__foot {
  padding: 0.9rem 1.15rem;
  border-block-start: 1px solid rgb(255 255 255 / 8%);
  color: var(--ink-faint);
  font-size: 0.72rem;
}

/* ================================================================== topbar */

.main {
  display: flex;
  flex-direction: column;
  min-inline-size: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  block-size: var(--topbar-h);
  padding-inline: var(--gutter);
  background: var(--paper-raised);
  border-block-end: 1px solid var(--rule);
  position: sticky;
  inset-block-start: 0;
  z-index: 20;
}

.topbar__toggle {
  display: none;
  background: none;
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  font-size: 1.05rem;
  padding: 0.25rem 0.55rem;
  cursor: pointer;
  color: var(--ink);
}

.topbar__spacer {
  flex: 1;
}

.crumbs {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--ink-faint);
  min-inline-size: 0;
}

.crumbs__item:last-child {
  color: var(--ink);
  font-weight: 600;
}

.crumbs__sep {
  opacity: 0.5;
}

.search__input,
.picker__input,
.field__input {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.38rem 0.6rem;
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  background: var(--paper);
  color: var(--ink);
}

.search__input {
  inline-size: clamp(9rem, 18vw, 17rem);
}

.search__input:focus-visible,
.picker__input:focus-visible,
.field__input:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.picker {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* `display: flex` above would otherwise overrule the `hidden` attribute. */
.picker[hidden] {
  display: none;
}

.picker__label {
  font-size: 0.72rem;
  color: var(--ink-faint);
  white-space: nowrap;
}

/*
 * THE IDENTITY BLOCK MUST NOT PUSH THE PAGE SIDEWAYS.
 *
 * `white-space: nowrap` on a flex item with no `min-width` refuses to shrink
 * below its text, so a long display name pushed the topbar 26px past the
 * viewport and gave EVERY screen a horizontal scrollbar — measured on
 * 22 September 2026 with "لوحة العرض — المالية", which is not a long name.
 *
 * `min-width: 0` is what lets a flex item shrink at all; the name then
 * truncates instead of the document widening. A display name is chrome, and
 * chrome does not get to move the content.
 */
.whoami {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-inline-start: 0.6rem;
  border-inline-start: 1px solid var(--rule);
  white-space: nowrap;
  min-inline-size: 0;
  overflow: hidden;
}

.whoami__avatar {
  display: grid;
  place-items: center;
  inline-size: 2rem;
  block-size: 2rem;
  border-radius: 50%;
  background: var(--ink);
  color: var(--gold-bright);
  font-size: 0.85rem;
  flex: none;
}

.whoami__who {
  font-size: 0.82rem;
  line-height: 1.25;
  min-inline-size: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.whoami__who small {
  display: block;
  color: var(--ink-faint);
  font-size: 0.7rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==================================================================== page */

.page {
  padding: var(--gutter);
  max-inline-size: 1400px;
  inline-size: 100%;
  flex: 1;
}

.page:focus-visible {
  outline: none;
}

.page__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-block-end: 1.5rem;
  padding-block-end: 0.85rem;
  border-block-end: 2px solid var(--ink);
}

h1 {
  font-size: var(--text-h1);
  margin: 0;
  letter-spacing: -0.4px;
}

h2 {
  font-size: var(--text-h2);
  margin: 0 0 0.5rem;
  letter-spacing: -0.2px;
}

.lede {
  color: var(--ink-soft);
  margin: 0.3rem 0 0;
  max-inline-size: 70ch;
  font-size: 0.92rem;
}

.muted {
  color: var(--ink-faint);
}

.section {
  margin-block-start: 2.25rem;
}

code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: rgb(20 29 46 / 6%);
  padding: 0.08em 0.35em;
  border-radius: 3px;
  direction: ltr;
  display: inline-block;
}

/* =================================================================== cards */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
}

.cards--under {
  border-block-start: 0;
}

.card {
  background: var(--paper-raised);
  padding: 1rem 1.15rem;
  min-inline-size: 0;
}

.card__label {
  display: block;
  font-size: 0.73rem;
  letter-spacing: 0.5px;
  color: var(--ink-faint);
  margin-block-end: 0.3rem;
}

.card__value {
  display: block;
  font-family: var(--mono);
  font-size: 1.35rem;
  font-weight: 700;
  direction: ltr;
  text-align: end;
  font-variant-numeric: tabular-nums;
}

.card__note {
  display: block;
  font-size: 0.75rem;
  color: var(--ink-soft);
  margin-block-start: 0.25rem;
}

/* A value that is words, not a figure: Arabic needs its own font and direction. */
.card__value--text {
  font-family: var(--sans);
  direction: rtl;
  text-align: start;
  letter-spacing: 0;
}

/* A limit and how much of it is used (subscription, 0104). */
.meter {
  display: block;
  block-size: 0.35rem;
  margin-block-start: 0.5rem;
  background: var(--rule);
  overflow: hidden;
}

.meter > span {
  display: block;
  block-size: 100%;
  background: var(--gold);
}

.meter--full > span {
  background: var(--bad);
}

.plan-grid .is-current {
  background: color-mix(in srgb, var(--gold-bright) 18%, transparent);
}

.plan-grid td:not(:first-child),
.plan-grid th:not(:first-child) {
  text-align: center;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.25rem;
  border: 1px solid var(--rule);
  padding: 0.6rem 0.9rem;
  margin-block: 0.6rem;
}

/* The headline band: ink, full width, above the supporting row. */
.band {
  background: var(--ink);
  color: var(--paper);
  border: 1px solid var(--ink);
  border-block-end: 0;
  padding: 1.2rem 1.3rem 1.35rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.4rem 1.5rem;
}

.band .card__label {
  color: var(--gold-bright);
  margin: 0;
}

.band .card__value {
  font-size: clamp(1.6rem, 1.1rem + 1.6vw, 2.4rem);
}

.band .card__note {
  color: var(--paper);
  margin: 0;
  flex-basis: 100%;
}

/* ================================================================== tables */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.6rem;
  padding: 0.85rem 1rem;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-block-end: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.field__label {
  font-size: 0.7rem;
  letter-spacing: 0.5px;
  color: var(--ink-faint);
}

.field__input {
  min-inline-size: 9rem;
}

.toolbar__spacer {
  flex: 1;
}

.count {
  font-size: 0.8rem;
  color: var(--ink-faint);
  align-self: center;
}

.scroll-x {
  overflow-x: auto;
  border: 1px solid var(--rule);
  background: var(--paper-raised);
}

.sheet {
  inline-size: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  min-inline-size: 640px;
}

.sheet caption {
  caption-side: bottom;
  text-align: start;
  padding: 0.55rem 0.85rem;
  color: var(--ink-faint);
  font-size: 0.75rem;
  border-block-start: 1px solid var(--rule);
}

.sheet th,
.sheet td {
  padding: 0.5rem 0.85rem;
  border-block-end: 1px solid var(--rule);
  text-align: start;
  vertical-align: baseline;
}

.sheet thead th {
  background: var(--ink);
  color: var(--paper);
  font-size: 0.74rem;
  letter-spacing: 0.5px;
  font-weight: 600;
  position: sticky;
  inset-block-start: 0;
  white-space: nowrap;
}

.sheet thead th button {
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  gap: 0.25rem;
  align-items: center;
}

.sheet thead th button:hover {
  color: var(--gold-bright);
}

.sheet tbody tr:hover {
  background: rgb(168 118 42 / 7%);
}

.sheet tbody tr:last-child td {
  border-block-end: 0;
}

.sheet tfoot td {
  background: rgb(20 29 46 / 5%);
  font-weight: 700;
  border-block-start: 2px solid var(--ink);
}

.num {
  font-family: var(--mono);
  direction: ltr;
  text-align: end;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.code {
  font-family: var(--mono);
  direction: ltr;
  color: var(--ink-soft);
  white-space: nowrap;
}

tr.is-clickable {
  cursor: pointer;
}

.pager {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1rem;
  border: 1px solid var(--rule);
  border-block-start: 0;
  background: var(--paper-raised);
  font-size: 0.82rem;
}

/* ================================================================== states */

.flag {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 0.15rem 0.55rem;
  border-radius: 2px;
  border-inline-start: 3px solid currentcolor;
  background: rgb(20 29 46 / 5%);
  white-space: nowrap;
}

.flag--good {
  color: var(--good);
}

.flag--bad {
  color: var(--bad);
}

.flag--warn {
  color: var(--warn);
}

.flag--info {
  color: var(--info);
}

.flag--mute {
  color: var(--ink-faint);
}

.banner {
  margin: 0.85rem var(--gutter) 0;
  padding: 0.75rem 1rem;
  border-inline-start: 4px solid var(--bad);
  background: rgb(151 51 31 / 8%);
  color: var(--bad);
  font-size: 0.9rem;
}

.state {
  border: 1px solid var(--rule);
  background: var(--paper-raised);
  padding: 2.25rem 1.5rem;
  text-align: center;
}

.state__icon {
  font-size: 1.6rem;
  opacity: 0.4;
  display: block;
  margin-block-end: 0.5rem;
}

.state__title {
  font-weight: 700;
  margin-block-end: 0.3rem;
}

.state__body {
  color: var(--ink-soft);
  font-size: 0.9rem;
  max-inline-size: 56ch;
  margin-inline: auto;
}

.state--denied {
  border-inline-start: 5px solid var(--warn);
  text-align: start;
}

.state--error {
  border-inline-start: 5px solid var(--bad);
  text-align: start;
}

/*
 * The card that says a screen CANNOT exist yet.
 *
 * Styled to be read, not dismissed: its own colour, the missing route in
 * monospace, and no spinner that would imply something is still loading. An
 * empty table here would say "no data" when the truth is "no way to ask".
 */
.state--absent {
  border: 1px solid var(--absent);
  border-inline-start-width: 5px;
  text-align: start;
  background:
    repeating-linear-gradient(
      135deg,
      transparent,
      transparent 9px,
      rgb(92 74 122 / 4%) 9px,
      rgb(92 74 122 / 4%) 18px
    ),
    var(--paper-raised);
}

.state--absent .state__title {
  color: var(--absent);
}

.state__meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.3rem 1rem;
  font-size: 0.85rem;
  margin-block-start: 0.85rem;
  text-align: start;
}

.state__meta dt {
  color: var(--ink-faint);
}

.state__meta dd {
  margin: 0;
}

.skeleton {
  display: grid;
  gap: 0.5rem;
}

.skeleton__row {
  block-size: 1.05rem;
  background: linear-gradient(90deg, var(--rule) 25%, var(--paper-raised) 50%, var(--rule) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: 2px;
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton__row {
    animation: none;
  }
}

/* ================================================================ controls */

.btn {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.38rem 0.8rem;
  border-radius: 3px;
  border: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition:
    background-color 130ms ease,
    color 130ms ease;
}

.btn:hover,
.btn:focus-visible {
  background: var(--ink);
  color: var(--paper);
}

.btn--ghost {
  border-color: var(--rule-strong);
  color: var(--ink-soft);
}

.btn--ghost:hover,
.btn--ghost:focus-visible {
  background: var(--rule);
  color: var(--ink);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.detail {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.4rem 1.25rem;
  font-size: 0.88rem;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  padding: 1rem 1.15rem;
}

.detail dt {
  color: var(--ink-faint);
}

.detail dd {
  margin: 0;
}

.split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.25rem;
  align-items: start;
}

.scrim {
  position: fixed;
  inset: 0;
  background: rgb(20 29 46 / 45%);
  z-index: 25;
}

/* ============================================================== responsive */

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

  .sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    inline-size: var(--sidebar-w);
    z-index: 30;
    /* RTL: the rail lives at the right edge, so it slides out to the right. */
    transform: translateX(100%);
    transition: transform 180ms ease;
  }

  html[dir='ltr'] .sidebar {
    transform: translateX(-100%);
  }

  .app.is-nav-open .sidebar {
    transform: translateX(0);
  }

  .topbar__toggle {
    display: block;
  }

  .search__input {
    inline-size: 8rem;
  }

  .whoami__who {
    display: none;
  }
}

@media (max-width: 620px) {
  .crumbs,
  .picker__label {
    display: none;
  }
}

/* After the drawer's own transition, so this one wins. */
@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .nav__heading,
  .nav__link,
  .nav__chevron {
    transition: none;
  }
}

/* =========================================================== write forms */

/*
 * The journal form. Everything below exists for one screen, and the screen is
 * a ledger document: the layout follows the shape of a journal voucher rather
 * than a generic web form, because a preparer reads down the amount columns
 * and across the line, not field by field.
 */

.btn--primary {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
  font-weight: 600;
}

.btn--primary:hover:not(:disabled),
.btn--primary:focus-visible:not(:disabled) {
  background: #000;
  border-color: #000;
}

.grid-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 0.9rem 1.1rem;
}

.grid-fields > label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--ink-soft);
  letter-spacing: 0.01em;
}

.grid-fields > label.wide {
  grid-column: 1 / -1;
}

.grid-fields input,
.grid-fields select,
.sheet--form input,
.sheet--form select {
  font: inherit;
  font-size: 0.88rem;
  color: var(--ink);
  background: var(--paper-raised);
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  padding: 0.4rem 0.55rem;
  width: 100%;
  min-width: 0;
}

.grid-fields input:focus-visible,
.grid-fields select:focus-visible,
.sheet--form input:focus-visible,
.sheet--form select:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: -1px;
}

.grid-fields input[readonly] {
  background: var(--paper);
  color: var(--ink-soft);
}

.sheet--form td {
  vertical-align: top;
  padding-block: 0.35rem;
}

/*
 * Amounts are typed and read as numbers, so they are LTR and tabular even on
 * an RTL page. A right-to-left "1,200.00" puts the decimal on the wrong side
 * of the eye and two of them cannot be compared down a column.
 */
.sheet--form input.num {
  text-align: end;
  direction: ltr;
  font-variant-numeric: tabular-nums;
  font-family: var(--mono, ui-monospace, 'SFMono-Regular', Menlo, monospace);
}

.sheet--form tr.is-bad td {
  background: color-mix(in oklab, var(--bad) 7%, transparent);
}

.field-error {
  margin-block-start: 0.3rem;
  font-size: 0.76rem;
  line-height: 1.5;
  color: var(--bad);
}

.icon-btn {
  font: inherit;
  line-height: 1;
  padding: 0.35rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: var(--ink-faint);
  cursor: pointer;
}

.icon-btn:hover:not(:disabled),
.icon-btn:focus-visible:not(:disabled) {
  color: var(--bad);
  border-color: var(--rule-strong);
}

.icon-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* The difference card, when there is one. Red is the point, not decoration. */
.card--bad {
  border-color: color-mix(in oklab, var(--bad) 45%, var(--rule));
  background: color-mix(in oklab, var(--bad) 5%, var(--paper-raised));
}

.card--bad .card__value {
  color: var(--bad);
}

.actions {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  flex-wrap: wrap;
  margin-block-start: 1.1rem;
}

.actions .muted {
  font-size: 0.78rem;
}

/*
 * The refusal banner. It sits at the top of the form and carries the API's own
 * words, so it must be readable as prose rather than as a coloured strip.
 */
.notice {
  border: 1px solid color-mix(in oklab, var(--bad) 40%, var(--rule));
  border-inline-start: 3px solid var(--bad);
  background: color-mix(in oklab, var(--bad) 5%, var(--paper-raised));
  padding: 0.85rem 1rem;
  margin-block-end: 1.2rem;
  font-size: 0.88rem;
  line-height: 1.7;
}

.notice ul {
  margin: 0.5rem 0 0;
  padding-inline-start: 1.2rem;
}

.notice code {
  font-size: 0.8em;
}

/* Checkboxes that carry a rule, not a preference. */
.checks {
  margin-block-start: 1rem;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.88rem;
  cursor: pointer;
}

.check input {
  inline-size: 1rem;
  block-size: 1rem;
  accent-color: var(--ink);
  cursor: pointer;
}

.check__note {
  margin-block-start: 0.35rem;
  margin-inline-start: 1.55rem;
  font-size: 0.78rem;
  line-height: 1.65;
  max-inline-size: 46rem;
}

.btn--danger {
  border-color: color-mix(in oklab, var(--bad) 55%, var(--rule));
  color: var(--bad);
}

.btn--danger:hover:not(:disabled),
.btn--danger:focus-visible:not(:disabled) {
  background: var(--bad);
  border-color: var(--bad);
  color: var(--paper);
}

/* The page head can carry several actions on a lifecycle screen. */
.page__head > div:last-child {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

/* ===========================================================================
   Tax codes — a rate is a timeline, so it is drawn as one
   =========================================================================== */
/*
 * The succession is the substance of this screen. A code's current rate is one
 * number; WHICH rate applied on a document's date is the question somebody
 * actually arrives with, and a list of one-line periods answers it at a glance
 * in a way a single figure never can.
 */

.actions--page {
  margin-block-end: 1.25rem;
}

.tag {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  font-size: 0.75rem;
  line-height: 1.6;
}

.tag--muted {
  color: var(--ink-faint);
  background: var(--paper);
}

.notice--warn {
  border-inline-start: 3px solid var(--warn);
  color: var(--warn);
}

.tax-codes {
  display: grid;
  gap: 1rem;
}

.tax-code {
  padding: 1rem 1.15rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--paper-raised);
}

/* A stopped code is legible and visibly not in play — never hidden. */
.tax-code.is-inactive {
  background: var(--paper);
  border-style: dashed;
}

.tax-code__head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: baseline;
  justify-content: space-between;
  padding-block-end: 0.6rem;
  border-block-end: 1px solid var(--rule);
}

.tax-code__code {
  margin: 0;
  font: 600 1.05rem/1.4 var(--mono);
  /* The code is an identifier; it reads left-to-right inside an RTL page. */
  direction: ltr;
  unicode-bidi: isolate;
}

.tax-code__name {
  margin: 0.15rem 0 0;
  color: var(--ink-soft);
}

.tax-code__now {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  /* Without this the rate can push the header wider than the card on a phone. */
  min-inline-size: 0;
}

.tax-code__rate {
  font: 600 1.35rem/1 var(--mono);
  color: var(--gold);
  direction: ltr;
  unicode-bidi: isolate;
}

.tax-code__meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.6rem 1.25rem;
  margin: 0.85rem 0 0;
}

.tax-code__meta dt {
  font-size: 0.78rem;
  color: var(--ink-faint);
}

.tax-code__meta dd {
  margin: 0.1rem 0 0;
}

.tax-code__rates {
  margin-block-start: 1rem;
}

.tax-code__rates h3 {
  margin: 0 0 0.4rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-faint);
}

.rate-history {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.25rem;
}

.rate-history__item {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  align-items: baseline;
  padding: 0.3rem 0.55rem;
  border-inline-start: 2px solid var(--rule-strong);
  background: var(--paper);
}

/* The rate in force is the one a reader is usually looking for. */
.rate-history__item.is-open {
  border-inline-start-color: var(--gold);
  background: var(--paper-raised);
}

.rate-history__rate {
  min-inline-size: 4rem;
  font: 600 0.95rem/1.4 var(--mono);
  direction: ltr;
  unicode-bidi: isolate;
}

.rate-history__span {
  color: var(--ink-soft);
  font-size: 0.85rem;
}

/* -------------------------------------------------- tax registration (0074) --
 * The position block is deliberately the loudest thing on the page. The number
 * a document carries is the answer somebody came for; the registrations below
 * it are the evidence for that answer, and are styled as the quieter thing.
 */
.position {
  margin-block: 1.5rem;
}

.position__title,
.regs__title,
.codes__title,
.section-title {
  margin: 0 0 0.75rem;
  font-size: var(--text-h2);
}

.section-title {
  margin-block-start: 1.75rem;
}

/* The entity the dashboard is currently reading, in the entities list. */
.sheet tr.is-current td {
  font-weight: 600;
}

.position__card {
  padding: 1rem 1.15rem;
  margin-block-end: 0.75rem;
  border: 1px solid var(--rule);
  /* The one warm accent, used for current position exactly as the tokens say. */
  border-inline-start: 3px solid var(--gold);
  border-radius: 4px;
  background: var(--paper-raised);
}

/* A registration number is an identifier: it reads LTR inside an RTL page. */
.position__number {
  margin: 0 0 0.85rem;
  font: 600 1.5rem/1.2 var(--mono);
  letter-spacing: 0.04em;
  direction: ltr;
  unicode-bidi: isolate;
  /* Without this a long number pushes the card wider than the page on a phone. */
  overflow-wrap: anywhere;
}

.position__meta,
.reg__meta,
.meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.6rem 1.25rem;
  margin: 0;
}

.position__meta dt,
.reg__meta dt,
.meta dt {
  font-size: 0.78rem;
  color: var(--ink-faint);
}

.position__meta dd,
.reg__meta dd,
.meta dd {
  margin: 0.1rem 0 0;
}

/* A member's invoice carries somebody else's number. Say so, every time. */
.position__note {
  margin: 0.85rem 0 0;
  padding-inline-start: 0.75rem;
  border-inline-start: 2px solid var(--rule-strong);
  color: var(--ink-soft);
}

/* A gap is a FINDING, not an empty state, and is coloured as one. */
.position__gap {
  padding: 0.75rem 1rem;
  margin-block-end: 0.75rem;
  border: 1px solid var(--warn);
  border-inline-start: 3px solid var(--warn);
  border-radius: 4px;
  color: var(--ink);
}

.regs,
.codes {
  margin-block: 1.5rem;
}

.reg {
  padding: 1rem 1.15rem;
  margin-block-end: 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--paper-raised);
}

/* A closed registration stays legible and visibly out of play — never hidden. */
.reg.is-closed {
  background: var(--paper);
  border-style: dashed;
}

.reg__head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: baseline;
  justify-content: space-between;
  padding-block-end: 0.6rem;
  border-block-end: 1px solid var(--rule);
}

.reg__number {
  margin: 0;
  font: 600 1.05rem/1.4 var(--mono);
  direction: ltr;
  unicode-bidi: isolate;
  overflow-wrap: anywhere;
}

.reg__holder {
  margin: 0.15rem 0 0;
  color: var(--ink-soft);
}

.reg__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  min-inline-size: 0;
}

.reg__coverage {
  margin-block-start: 1rem;
}

.reg__coverage h3 {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: var(--ink-faint);
}

.reg__empty,
.codes__none {
  margin: 0;
  color: var(--ink-soft);
}

.hint {
  margin-block: 1.25rem;
  color: var(--ink-soft);
}

/* ==========================================================================
   Printable documents (views-print.js)
   ==========================================================================
   A document is laid out on a sheet that looks the same on screen and on
   paper. Printing — or "Save as PDF" in the same dialog — hides everything
   that is application rather than document. */
.doc {
  max-width: 52rem;
  margin: 0 auto;
  padding: 2rem 2.25rem;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  color: var(--ink);
}

.doc__actions {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1.5rem;
}

.doc__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1.5rem;
  padding-bottom: 1rem;
  margin-bottom: 1.25rem;
  border-bottom: 2px solid var(--ink);
}

.doc__company {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.doc__small {
  margin: 0.3rem 0 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.doc__title {
  text-align: end;
}

.doc__title h1 {
  margin: 0;
  font-size: var(--text-h1);
}

.doc__title p {
  margin: 0.25rem 0 0;
  font-family: var(--mono);
}

.doc__meta {
  margin-bottom: 1.25rem;
}

.doc__lines,
.doc__totals {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.25rem;
}

.doc__lines th,
.doc__lines td {
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid var(--rule);
  text-align: start;
}

/* Numbers, dates and document numbers never break mid-token; the text columns wrap instead. */
.doc__lines td[dir='ltr'] {
  white-space: nowrap;
}

.doc__lines th {
  font-size: 0.8rem;
  color: var(--ink-soft);
  border-bottom-color: var(--rule-strong);
}

.doc__totals {
  max-width: 22rem;
  margin-inline-start: auto;
}

.doc__totals th,
.doc__totals td {
  padding: 0.35rem 0.5rem;
  text-align: start;
}

.doc__totals td {
  text-align: end;
  font-family: var(--mono);
}

.doc__foot {
  margin-top: 1.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--rule);
  font-size: 0.78rem;
  color: var(--ink-faint);
}

@media print {
  .sidebar,
  .topbar,
  .no-print {
    display: none !important;
  }

  body,
  .app,
  .main,
  .page {
    background: #fff !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
  }

  .doc {
    border: none;
    max-width: none;
    padding: 0;
  }
}

/* -- AP aging: one strip, each bucket's share of what is owed, oldest darkest */
.aging {
  display: flex;
  gap: 2px;
  block-size: 0.9rem;
  margin-block: 0.75rem 1.5rem;
  border-radius: 3px;
  overflow: hidden;
  background: var(--rule);
}
.aging__cell {
  background: var(--good);
}
.aging__cell:nth-child(2) {
  background: var(--gold);
}
.aging__cell:nth-child(3) {
  background: var(--warn);
}
.aging__cell:nth-child(n + 4) {
  background: var(--bad);
}
@media print {
  .aging {
    display: none;
  }
}

/* -- Fiscal calendar: one tile per period, coloured by what it allows ------ */
.periods {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.6rem;
}
.period {
  border: 1px solid var(--rule);
  border-inline-start: 4px solid var(--ink-faint);
  border-radius: 4px;
  padding: 0.6rem 0.7rem;
  background: var(--paper-raised);
}
.period--open {
  border-inline-start-color: var(--good);
}
.period--soft_closed {
  border-inline-start-color: var(--gold);
}
.period--closed {
  border-inline-start-color: var(--warn);
}
.period--locked {
  border-inline-start-color: var(--bad);
}
.period__head {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}
.period__status {
  margin-block: 0.25rem;
}
.period__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-block-start: 0.4rem;
}

/* -- Financial statements ------------------------------------------------- */
.statement-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr));
  gap: 1rem;
}
.statement {
  margin-block-end: 1rem;
}
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-block-end: 1rem;
}

/* =============================================================== sign-in */
/* Session mode (24 Sep 2026): before sign-in there is nothing to navigate. */

/* No sidebar column: the page takes the whole width. */
.app.is-signed-out {
  grid-template-columns: 1fr;
}

.is-signed-out .sidebar,
.is-signed-out .search,
.is-signed-out .picker,
.is-signed-out .topbar__toggle {
  display: none;
}

.login {
  max-inline-size: 30rem;
  margin: clamp(2rem, 8vh, 6rem) auto;
  padding: 2rem 2.25rem 2.25rem;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-block-start: 4px solid var(--gold);
}

.login__brand {
  font-size: 0.8rem;
  letter-spacing: 1px;
  color: var(--gold);
  margin: 0 0 0.5rem;
}

.login h1 {
  margin: 0 0 0.6rem;
}

.login .notice {
  margin-block: 1rem;
}

.login__go {
  display: inline-block;
  margin-block-start: 1rem;
}

.signout {
  margin-block-start: 0.6rem;
}

/* ==================================================== users screen (pilot-r3) */
/*
 * The member lifecycle and the second person's decision (26 Sep 2026). A
 * waiting request is a card, not a table row: a decision is read field by
 * field, and at 375px a row of nine operations' worth of fields would be a
 * page-wide scroll with the decision off screen.
 */

/* An action that went through. Green is the outcome, not decoration. */
.notice--good {
  border-color: color-mix(in oklab, var(--good) 40%, var(--rule));
  border-inline-start-color: var(--good);
  background: color-mix(in oklab, var(--good) 5%, var(--paper-raised));
}

/* A member row's lifecycle buttons wrap inside their cell rather than widen the table. */
.row-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.row-actions .btn {
  font-size: 0.78rem;
  padding: 0.25rem 0.6rem;
  white-space: nowrap;
}

.requests {
  display: grid;
  gap: 1rem;
}

.request {
  min-inline-size: 0;
  padding: 1rem 1.15rem;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-inline-start: 3px solid var(--warn);
}

.request__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.35rem 1rem;
  margin-block-end: 0.6rem;
  padding-block-end: 0.5rem;
  border-block-end: 1px solid var(--rule);
}

.request__head h3 {
  margin: 0;
  font-size: 1rem;
}

.request__fields {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.35rem 1.25rem;
  margin: 0;
  font-size: 0.88rem;
}

.request__fields dt {
  color: var(--ink-faint);
}

.request__fields dd {
  margin: 0;
  min-inline-size: 0;
  overflow-wrap: anywhere;
}

/*
 * A payload hash is one 64-character token. `code` is inline-block, so it
 * would hold the token whole and push a 375px page sideways; this lets it
 * break anywhere instead. The request number is the same kind of token.
 */
.hash {
  display: inline;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-all;
}

.request details {
  margin-block-start: 0.75rem;
  font-size: 0.85rem;
}

.request summary {
  inline-size: fit-content;
  color: var(--ink-soft);
  cursor: pointer;
}

.request summary:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.request__raw pre {
  margin: 0.5rem 0 0;
  padding: 0.75rem;
  max-block-size: 20rem;
  overflow: auto;
  background: var(--paper);
  border: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 0.78rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.request__list code {
  margin: 0.15rem;
}

.request__why {
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
}

/*
 * The decision: a note that is recorded, then approve or reject. The note is a
 * textarea, so Enter is a new line and never a decision (pilot-r3 review).
 */
.decide {
  margin-block-start: 0.9rem;
  padding-block-start: 0.75rem;
  border-block-start: 1px dashed var(--rule-strong);
}

.decide__note {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  max-inline-size: 40rem;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.decide__note textarea {
  font: inherit;
  font-size: 0.88rem;
  color: var(--ink);
  background: var(--paper-raised);
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  padding: 0.4rem 0.55rem;
  inline-size: 100%;
  min-inline-size: 0;
  resize: vertical;
}

.decide__note textarea:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: -1px;
}

.decide p {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
}

.decide .actions {
  margin-block-start: 0.6rem;
}

/* «إزالة موظف»: each step says how far it got, coloured by its outcome. */
.steps {
  margin: 0.5rem 0;
  padding: 0;
  list-style: none;
}

.steps__item {
  padding-inline-start: 0.6rem;
  border-inline-start: 2px solid var(--rule-strong);
}

.steps__item + .steps__item {
  margin-block-start: 0.35rem;
}

.steps__item--done,
.steps__item--skipped {
  border-inline-start-color: var(--good);
}

.steps__item--pending {
  border-inline-start-color: var(--warn);
}

.steps__item--refused {
  border-inline-start-color: var(--bad);
}

.steps__n {
  font-family: var(--mono);
  color: var(--ink-faint);
}

.steps .notice {
  margin: 0.4rem 0 0;
}

/* A role listed for someone whose membership is revoked or suspended does nothing meanwhile. */
.role-inert {
  margin-block-start: 0.15rem;
  font-size: 0.78rem;
  color: var(--warn);
}

/* Why a governance role's scope was switched to the whole tenant. */
.scope-note {
  margin: 0.6rem 0 0;
  max-inline-size: 60ch;
  font-size: 0.8rem;
  color: var(--warn);
}

@media (max-width: 620px) {
  .request {
    padding: 0.85rem 0.9rem;
  }

  .request__fields {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.1rem;
  }

  .request__fields dd {
    margin-block-end: 0.45rem;
  }
}

/* r22 — the period VAT summary: a total row reads as one, and the print says what it is. */
.sheet tr.is-total td {
  font-weight: 600;
  border-block-start: 1px solid var(--rule-strong);
}

.print-only {
  display: none;
}

@media print {
  .print-only {
    display: block;
  }
}
