/*
 * openSIF
 *
 * A calm white utility page wrapped around one opinionated thing: the ledger.
 * The employee list is a table, not a stack of cards, because the file this
 * tool produces is a table and the row numbers it prints are the row numbers
 * the bank's error report will cite. Amounts are set in tabular figures with
 * the baisa (the three decimals of the rial) held back a step, so decimal
 * points stack down the column and a mistyped 9440.000 is visible at a glance
 * instead of hiding among its neighbours.
 *
 * Two constraints shaped the rest:
 *
 *   RTL is not a skin. Every box uses logical properties - inline-start rather
 *   than left - so the whole page mirrors from one dir attribute. Nothing is
 *   positioned with left/right anywhere in this file.
 *
 *   Arabic has no letter case, so no label may lean on capitalisation to read
 *   as a label. There is no text-transform in this stylesheet; hierarchy comes
 *   from size, weight, colour and space, all of which survive the switch.
 *
 * Validation state is never carried by colour alone: every flag prints a word.
 */

/* ------------------------------------------------------------------ tokens */

:root {
  --paper:        #ffffff;
  --ground:       #f6f8f6;
  --ink:          #14231e;
  --ink-2:        #59685f;
  --ink-3:        #6c746e;
  --rule:         #e3e8e4;
  --rule-firm:    #ccd5cd;
  /* A control identified only by its outline needs a 3:1 boundary
     (WCAG 1.4.11); a decorative rule does not. Two tokens, so the
     inputs can be legible without the hairlines turning heavy. */
  --control-line: #8b918b;

  --accent:       #0e6b57;
  --accent-hover: #0a5745;
  --accent-on:    #ffffff;
  --accent-wash:  #e9f2ee;

  --flag:         #a4331f;
  --flag-wash:    #fbeeeb;
  --watch:        #7d5310;
  --watch-wash:   #fbf4e6;

  --sans: 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'Cascadia Mono', 'Consolas', monospace;

  --radius: 8px;
  --radius-sm: 5px;

  /* 4/8 rhythm */
  --s1: 0.25rem; --s2: 0.5rem;  --s3: 0.75rem; --s4: 1rem;
  --s5: 1.5rem;  --s6: 2rem;    --s7: 3rem;    --s8: 4rem;

  --measure: 62rem;
  --ease: cubic-bezier(0.2, 0, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:        #171c19;
    --ground:       #0f1311;
    --ink:          #e6ece8;
    --ink-2:        #a2afa7;
    --ink-3:        #7a857f;
    --rule:         #29302c;
    --rule-firm:    #3b443f;
    --control-line: #606863;

    --accent:       #4cbd9c;
    --accent-hover: #66cfb0;
    --accent-on:    #08130f;
    --accent-wash:  #16261f;

    --flag:         #ea8871;
    --flag-wash:    #2a1a16;
    --watch:        #d7ad63;
    --watch-wash:   #26200f;
  }
}

/* ------------------------------------------------------------------- reset */

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

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

body {
  margin: 0;
  padding: 0 var(--s4) var(--s8);
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, p, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }

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

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

[hidden], .hidden { display: none !important; }

/* --------------------------------------------------------- bidi isolation */

/*
 * Account numbers, civil IDs and amounts read left-to-right in every language.
 * Left to itself the bidi algorithm will reorder an IBAN inside an Arabic
 * sentence and hand the bank a number that never existed, so anything that is
 * an identifier or a figure is pinned and isolated regardless of page dir.
 */
.ltr,
input[inputmode="numeric"],
input[type="number"],
.omr, .mono {
  direction: ltr;
  unicode-bidi: isolate;
}

.mono, .omr {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}

/*
 * The signature: the rial reads at full weight, the baisa a step back. Both are
 * tabular and the fraction is always exactly four glyphs, so end-aligning the
 * span lands every decimal point on the same vertical.
 */
.omr { white-space: nowrap; }
.omr .rial  { font-weight: 500; }
.omr .baisa { font-size: 0.82em; color: var(--ink-3); font-style: normal; }
.omr.is-negative .rial { color: var(--flag); }

/* ---------------------------------------------------------------- masthead */

/*
 * The top bar carries the language toggle and nothing else. The wordmark moved
 * down into the hero, where it can be the size it deserves: two of them a few
 * lines apart was one identity too many.
 */
.masthead {
  display: flex;
  align-items: center;
  gap: var(--s4);
  max-width: var(--measure);
  margin-inline: auto;
  padding-block: var(--s4) 0;
}
/*
 * An auto margin rather than justify-content: the wizard's bar holds only the
 * toggle and the static pages hold a back link beside it. space-between would
 * shove a lone toggle to the wrong end; this puts it at the end either way.
 */
.masthead .lang-toggle { margin-inline-start: auto; }

.lang-toggle {
  border: 1px solid var(--control-line);
  background: var(--paper);
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 0.875rem;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  min-height: 38px;
  transition: color 160ms var(--ease), border-color 160ms var(--ease);
}
.lang-toggle:hover { color: var(--ink); border-color: var(--ink-3); }

/* ------------------------------------------------------------------- intro */

.intro {
  max-width: var(--measure);
  margin-inline: auto;
  padding-block: var(--s5) var(--s6);
  text-align: center;
}

/*
 * The name, set as one lockup: `open` in the text face, `SIF` in the mono face
 * the ledger uses for every figure. Same superfamily, so they share a skeleton
 * and the join does not read as two fonts - but the mono's fixed advance widens
 * SIF just enough to give the name a stress of its own.
 */
.lockup {
  font-size: clamp(2.75rem, 2rem + 3.4vw, 4.25rem);
  line-height: 1;
  font-weight: 600;
  margin-block-end: var(--s3);
}
.lockup .mark-open {
  color: var(--ink);
  /* Latin only: letter-spacing breaks the joins in Arabic script, and this
     lockup stays Latin in both languages anyway. */
  letter-spacing: -0.035em;
}
.lockup .mark-sif {
  font-family: var(--mono);
  font-weight: 500;
  color: var(--accent);
  letter-spacing: -0.01em;
}

/*
 * Three sizes, descending: the name, what it is, how it works. The role line
 * used to be smaller than the sentence it introduces, which read backwards -
 * a label should not be quieter than its own explanation.
 */
.intro .role {
  font-size: 1.125rem;
  color: var(--ink-2);
  margin-block-end: var(--s4);
}

.intro .tagline {
  max-width: 48ch;
  margin-inline: auto;
  color: var(--ink-3);
  font-size: 0.9375rem;
  line-height: 1.65;
}

/*
 * The privacy claims are the product's entire pitch, so they are set as three
 * separate facts in three cells rather than one sentence in a badge - each with
 * its own icon, each short enough never to break mid-phrase. It reads as a spec
 * strip, which is the right register: these are properties of the tool, not
 * promises about it.
 */
.assurances {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  margin-block-start: var(--s5);
  border: 1px solid var(--rule-firm);
  border-radius: 999px;
  background: var(--paper);
  overflow: hidden;
}

.assurances li {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: 0.5rem 1.1rem;
  font-size: 0.875rem;
  color: var(--ink-2);
  white-space: nowrap;
}
.assurances li svg { flex: none; color: var(--accent); }

/* A divider between cells, not an edge on a block. */
.assurances li + li { border-inline-start: 1px solid var(--rule); }

/* --------------------------------------------------------------- step line */

.steps {
  max-width: var(--measure);
  margin-inline: auto;
  border-block-end: 1px solid var(--rule);
}

.steps ol {
  display: flex;
  gap: var(--s5);
  overflow-x: auto;
  scrollbar-width: none;
}
.steps ol::-webkit-scrollbar { display: none; }

.steps li {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding-block: var(--s3);
  color: var(--ink-3);
  font-size: 0.9375rem;
  white-space: nowrap;
  /* The underline sits under the label, not down the side of a block. */
  border-block-end: 2px solid transparent;
  margin-block-end: -1px;
  transition: color 160ms var(--ease);
}
.steps li .n {
  font-family: var(--mono);
  font-size: 0.8125rem;
  min-width: 1.35rem; height: 1.35rem;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid currentColor;
  border-radius: 50%;
  opacity: 0.75;
}
.steps li.is-done { color: var(--ink-2); }
.steps li.is-current {
  color: var(--accent);
  font-weight: 500;
  border-block-end-color: var(--accent);
}

/* ------------------------------------------------------------ control line */

/*
 * Row one of the file it is about to write, kept in view while you work.
 * It answers "what am I making?" without you having to scroll back.
 */
.control {
  position: sticky;
  inset-block-start: 0;
  z-index: 10;
  max-width: var(--measure);
  margin-inline: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s2) var(--s4);
  padding-block: var(--s3);
  background: var(--ground);
  border-block-end: 1px solid var(--rule);
  font-size: 0.875rem;
  color: var(--ink-2);
}
.control .facts { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: baseline; }
.control .fact { color: var(--ink); }
.control .sep { color: var(--ink-3); }
.control .tally { display: flex; gap: var(--s3); align-items: baseline; }

/* ------------------------------------------------------------------ layout */

main.wizard {
  max-width: var(--measure);
  margin-inline: auto;
  padding-block-start: var(--s6);
}

.panel {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: var(--s5);
  margin-block-end: var(--s5);
}

.panel > h2 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-block-end: var(--s1);
}
.panel > h2 + .lede { color: var(--ink-2); font-size: 0.9375rem; margin-block-end: var(--s5); }

/* ------------------------------------------------------------------- forms */

.field { margin-block-end: var(--s4); }

.field > label,
fieldset > legend {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink);
  margin-block-end: var(--s1);
  padding: 0;
}

.field .hint {
  display: block;
  font-size: 0.8125rem;
  color: var(--ink-3);
  margin-block-end: var(--s2);
}

input, select, button, textarea { font: inherit; }

input[type="text"],
input[type="number"],
select {
  inline-size: 100%;
  min-height: 46px;              /* comfortable touch target */
  padding: 0.5rem 0.75rem;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--control-line);
  border-radius: var(--radius-sm);
  font-size: 1rem;               /* 16px stops iOS zooming the page on focus */
  transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease);
}

input::placeholder { color: var(--ink-3); }

input:focus-visible,
select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-wash);
}

input[aria-invalid="true"] { border-color: var(--flag); }
input[aria-invalid="true"]:focus-visible { box-shadow: 0 0 0 3px var(--flag-wash); }

/*
 * The caret is an inline SVG data URI, not a pair of clipped gradients: it is
 * an actual chevron at any zoom, and being vertically symmetric it needs no
 * mirroring for RTL - only repositioning, which is the one thing
 * background-position cannot express logically.
 */
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none' stroke='%2359685f' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m1 1 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: 10px 6px;
  background-position: right 0.85rem center;
  padding-inline-end: 2.25rem;
}
[dir="rtl"] select {
  background-position: left 0.85rem center;
  padding-inline-end: 0.75rem;
  padding-inline-start: 2.25rem;
}
@media (prefers-color-scheme: dark) {
  select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none' stroke='%23a2afa7' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m1 1 4 4 4-4'/%3E%3C/svg%3E");
  }
}

/* ------------------------------------------------------------------- combo */

/*
 * The bank picker. It looks like the other inputs on purpose - it is one, with
 * a list attached - so the form reads as one kind of control rather than two.
 */
.combo { position: relative; }

input.combo-input {
  /* Same chevron as a <select>, since it opens the same way. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none' stroke='%2359685f' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m1 1 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: 10px 6px;
  background-position: right 0.85rem center;
  padding-inline-end: 2.25rem;
}
[dir="rtl"] input.combo-input {
  background-position: left 0.85rem center;
  padding-inline-end: 0.75rem;
  padding-inline-start: 2.25rem;
}
@media (prefers-color-scheme: dark) {
  input.combo-input {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none' stroke='%23a2afa7' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m1 1 4 4 4-4'/%3E%3C/svg%3E");
  }
}

.combo-list {
  position: absolute;
  inset-inline: 0;
  inset-block-start: calc(100% + 4px);
  z-index: 30;
  max-block-size: 17rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--paper);
  border: 1px solid var(--control-line);
  border-radius: var(--radius-sm);
  box-shadow: 0 6px 20px rgb(20 35 30 / 0.10);
  padding-block: var(--s1);
}

.combo-list [role="option"] {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  line-height: 1.35;
}
.combo-list [role="option"] .opt-name { font-size: 0.9375rem; color: var(--ink); }
.combo-list [role="option"] .opt-meta { font-size: 0.75rem; color: var(--ink-3); }
.combo-list [role="option"].is-active { background: var(--accent-wash); }
.combo-list [role="option"].is-active .opt-meta { color: var(--ink-2); }
.combo-list [role="option"][aria-selected="true"] .opt-name { font-weight: 500; }
.combo-list .opt-custom .opt-name { color: var(--accent); }
.combo-list .opt-empty {
  padding: 0.6rem 0.8rem;
  font-size: 0.875rem;
  color: var(--ink-3);
}

/*
 * Fields in a row share one grid rather than sitting side by side as boxes.
 * Labels occupy row 1, hints row 2, controls row 3, validation messages row 4 -
 * so every control in a row lines up whether or not its neighbour has a hint,
 * and a message appearing under one field grows only the message row, which is
 * beneath every control and therefore moves nothing.
 *
 * The previous attempt bottom-aligned the controls instead. That aligned them
 * right up until a field showed an error, at which point that field's control
 * was pushed up to make room for the message and its neighbour was left with a
 * hole above it. Rows that share rows cannot drift apart like that.
 */
.row {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto auto auto auto;
  align-items: start;
  column-gap: var(--s4);
}
.row > .field { display: contents; }

.row > .field > label                { grid-row: 1; }
.row > .field > .hint                { grid-row: 2; }
.row > .field > input,
.row > .field > select,
.row > .field > textarea,
.row > .field > .combo,
.row > .field > .check,
.row > .field > button               { grid-row: 3; }
.row > .field > .msg                 { grid-row: 4; }

/*
 * Pin each field's parts to its own column. Auto-placement alone is not enough:
 * a field with no message leaves its cell in the message row free, and the next
 * field's message slides into it - so a CR error appeared under the company
 * name. The field is still a DOM child even though `display: contents` stops it
 * being a box, so it can be counted.
 */
.row > .field:nth-child(1) > * { grid-column: 1; }
.row > .field:nth-child(2) > * { grid-column: 2; }
.row > .field:nth-child(3) > * { grid-column: 3; }
.row > .field:nth-child(4) > * { grid-column: 4; }

/* Column shapes. Named for what they hold, since `display: contents` means the
   field itself is no longer a box that could carry its own width. */
.row.split      { grid-template-columns: 2fr 1fr; }
.row.split-end  { grid-template-columns: 1fr 2fr; }
.row.thirds     { grid-template-columns: 1fr 1fr 1fr; }
.row.lead-pair  { grid-template-columns: 2fr 1fr 1fr; }
.row.with-action{ grid-template-columns: 1fr auto; }


.row + .row, .row + .field, .field + .row { margin-block-start: var(--s4); }

.check {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: 0.9375rem;
  cursor: pointer;
  min-height: 44px;
}
.check input { inline-size: 1.05rem; block-size: 1.05rem; accent-color: var(--accent); margin: 0; }
.check + .hint { margin-block-start: calc(var(--s1) * -1); }

/* A disclosure group. Indentation alone shows that these belong to the
   checkbox above - no edge rail, which is the idiom this design avoids. */
#payer-fields {
  padding-inline-start: var(--s5);
  margin-block-end: var(--s4);
}

fieldset {
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: var(--s4);
  margin: var(--s5) 0;
  min-inline-size: 0;
}
fieldset > legend { margin: 0; padding-inline: var(--s2); }

/* Field-level messages: an inline glyph plus the sentence, never colour alone. */
.msg {
  display: none;
  align-items: flex-start;
  gap: 0.4rem;
  margin-block-start: var(--s2);
  font-size: 0.8125rem;
  line-height: 1.45;
}
.msg.warn, .msg.error { display: flex; }
.msg.warn  { color: var(--watch); }
.msg.error { color: var(--flag); }
.msg svg { flex: none; margin-block-start: 0.18em; }

/* ---------------------------------------------------------- net read-out */

/*
 * The largest figure on the page, because it is the number the user is
 * actually checking. It is not a heading, so it is not sized like one.
 */
.readout {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s2) var(--s4);
  padding: var(--s4) 0 0;
  border-block-start: 1px solid var(--rule);
  margin-block-start: var(--s5);
}
.readout .label { font-size: 0.875rem; color: var(--ink-2); }
.readout .value { font-size: clamp(1.5rem, 1.1rem + 1.6vw, 2rem); line-height: 1.1; }
.readout .value .baisa { font-size: 0.6em; }
.readout .breakdown { font-size: 0.8125rem; color: var(--ink-3); inline-size: 100%; }

/* ----------------------------------------------------------------- buttons */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s3);
  margin-block-start: var(--s5);
}
.actions.end { justify-content: flex-end; }
.actions.split { justify-content: space-between; }

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: 46px;
  padding: 0.55rem 1.15rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 500;
  transition: background-color 150ms var(--ease), border-color 150ms var(--ease), color 150ms var(--ease);
}

button.primary { background: var(--accent); color: var(--accent-on); }
button.primary:hover:not(:disabled) { background: var(--accent-hover); }

button.quiet { border-color: var(--control-line); color: var(--ink-2); }
button.quiet:hover:not(:disabled) { border-color: var(--ink-3); color: var(--ink); }

button.plain { color: var(--ink-2); padding-inline: var(--s2); min-height: 40px; }
button.plain:hover:not(:disabled) { color: var(--ink); }

button.danger { color: var(--flag); }
button.danger:hover:not(:disabled) { background: var(--flag-wash); }

button.small { min-height: 34px; padding: 0.2rem 0.55rem; font-size: 0.8125rem; }

button:disabled { opacity: 0.45; cursor: not-allowed; }

/* Directional arrows must point the way the reader is going. */
.arrow { transition: transform 160ms var(--ease); }
[dir="rtl"] .arrow { transform: scaleX(-1); }

/* ---------------------------------------------------------------- banners */

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  margin-block-end: var(--s4);
  border: 1px solid var(--control-line);
  border-radius: var(--radius-sm);
  background: var(--paper);
  font-size: 0.9375rem;
}
.banner.warn { border-color: var(--watch); background: var(--watch-wash); color: var(--watch); }
.banner .banner-actions { display: flex; gap: var(--s2); }

/* ------------------------------------------------------------------ ledger */

.ledger-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s3);
  flex-wrap: wrap;
  margin-block-end: var(--s3);
}
.ledger-head h3 { font-size: 1rem; font-weight: 600; }
.ledger-head .count { font-size: 0.875rem; color: var(--ink-2); }

/*
 * contain: paint, not just overflow-x: auto.
 *
 * An auto-layout table wider than its scroll frame leaks its intrinsic width
 * past that frame: overflow alone does not stop it. Under LTR the leak is
 * invisible (the page still cannot be scrolled), but under RTL it moves the
 * root scroll origin and parks the whole page ~150px off-screen on a phone.
 * Paint containment says outright that nothing inside this box affects
 * anything outside it, which is what the frame meant all along.
 */
.ledger-scroll {
  overflow-x: auto;
  contain: paint;
}

table.ledger {
  inline-size: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

table.ledger th {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--ink-3);
  text-align: start;
  padding: 0 var(--s3) var(--s2);
  border-block-end: 1px solid var(--rule-firm);
  white-space: nowrap;
}

table.ledger td {
  padding: var(--s3);
  border-block-end: 1px solid var(--rule);
  vertical-align: baseline;
}

table.ledger tbody tr:hover { background: var(--ground); }

/* The row number is the SIF row number every error message cites. */
table.ledger .c-row {
  inline-size: 2.5rem;
  font-family: var(--mono);
  font-size: 0.8125rem;
  color: var(--ink-3);
  text-align: end;
  padding-inline-end: var(--s2);
}
table.ledger .c-name { font-weight: 500; min-inline-size: 10rem; }
table.ledger .c-id,
table.ledger .c-bank { font-family: var(--mono); font-size: 0.8125rem; color: var(--ink-2); white-space: nowrap; }
table.ledger .c-net { text-align: end; white-space: nowrap; }
table.ledger .c-flag { inline-size: 4.5rem; }
table.ledger .c-do { inline-size: 1%; white-space: nowrap; text-align: end; }
table.ledger .c-do button + button { margin-inline-start: var(--s1); }

table.ledger tfoot td {
  border-block-end: none;
  border-block-start: 2px solid var(--rule-firm);
  padding-block-start: var(--s3);
  font-weight: 500;
}
table.ledger tfoot .c-net { font-size: 1.0625rem; }

/* A word, not a swatch: readable in greyscale and to a screen reader alike. */
.flag {
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
}
.flag.ok    { color: var(--ink-3); }
.flag.warn  { color: var(--watch); }
.flag.error { color: var(--flag); }

.empty {
  padding: var(--s6) var(--s4);
  text-align: center;
  color: var(--ink-2);
  border: 1px dashed var(--rule-firm);
  border-radius: var(--radius-sm);
}
.empty p { font-size: 0.9375rem; }
.empty p + p { color: var(--ink-3); font-size: 0.8125rem; margin-block-start: var(--s1); }

/* ------------------------------------------------------------------ review */

table.summary { inline-size: 100%; border-collapse: collapse; font-size: 0.9375rem; }
table.summary th {
  text-align: start;
  font-weight: 400;
  color: var(--ink-2);
  padding: var(--s2) 0;
}
table.summary td { text-align: end; padding: var(--s2) 0; }
table.summary tr.total th,
table.summary tr.total td {
  border-block-start: 2px solid var(--rule-firm);
  padding-block-start: var(--s3);
  color: var(--ink);
  font-weight: 500;
}
table.summary tr.total td { font-size: 1.25rem; }

.report { margin-block: var(--s5); }
.report h4 {
  font-size: 0.9375rem;
  font-weight: 600;
  margin-block-end: var(--s2);
  display: flex;
  align-items: center;
  gap: var(--s2);
}
.report ul { display: grid; gap: var(--s2); }
.report li {
  font-size: 0.875rem;
  color: var(--ink-2);
  padding-inline-start: 1.1rem;
  position: relative;
  line-height: 1.5;
}
.report li::before {
  content: '';
  position: absolute;
  inset-inline-start: 0;
  inset-block-start: 0.6em;
  inline-size: 4px; block-size: 4px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
}
.report-block + .report-block { margin-block-start: var(--s5); }
.report-block.error h4 { color: var(--flag); }
.report-block.warn h4  { color: var(--watch); }
.report-block.ok h4    { color: var(--accent); }
.report-block.ok p     { font-size: 0.875rem; color: var(--ink-2); }

/* --------------------------------------------------------------- templates */

details.store { margin-block-start: var(--s6); }
details.store > summary {
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 500;
  padding-block: var(--s2);
  color: var(--ink-2);
  list-style: none;
}
details.store > summary::-webkit-details-marker { display: none; }
details.store > summary::before {
  content: '+';
  display: inline-block;
  inline-size: 1rem;
  font-family: var(--mono);
  color: var(--ink-3);
}
details.store[open] > summary::before { content: '\2013'; }
details.store > summary:hover { color: var(--ink); }
.store-body { padding-block-start: var(--s3); }

.template-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding-block: var(--s3);
  border-block-end: 1px solid var(--rule);
  font-size: 0.9375rem;
}
.template-row:last-child { border-block-end: none; }
.template-row .meta { display: block; font-size: 0.8125rem; color: var(--ink-3); }

/* ----------------------------------------------------------------- success */

/*
 * Named .file-ready, not .done: a completed step in the rail also wants to be
 * "done", and a bare .done here silently painted this panel's border, radius
 * and tint onto every finished step marker. Component classes describe the
 * thing; state classes are prefixed is- and can never reach a component.
 */
.file-ready {
  margin-block-start: var(--s6);
  padding: var(--s5);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent-wash);
}
.file-ready h3 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-block-end: var(--s2);
  display: flex; align-items: center; gap: var(--s2);
  color: var(--accent);
}
.file-ready .file { font-size: 0.9375rem; }
.file-ready .hint { font-size: 0.875rem; color: var(--ink-2); margin-block-start: var(--s2); }
.file-ready .coffee {
  margin-block-start: var(--s4);
  padding-block-start: var(--s4);
  border-block-start: 1px solid var(--rule-firm);
  font-size: 0.875rem;
  color: var(--ink-2);
}
a { color: var(--accent); text-underline-offset: 3px; }

/* ------------------------------------------------------------------ footer */

.app-footer {
  max-width: var(--measure);
  margin: var(--s8) auto 0;
  padding-block-start: var(--s4);
  border-block-start: 1px solid var(--rule);
  font-size: 0.8125rem;
  color: var(--ink-3);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--s3) var(--s5);
  flex-wrap: wrap;
}
.foot-brand span { color: var(--ink-3); }
.foot-brand > span:first-child { color: var(--accent); }
.foot-links { display: flex; gap: var(--s4); flex-wrap: wrap; }
.app-footer a { color: var(--ink-2); text-decoration: none; }
.app-footer a:hover { color: var(--accent); text-decoration: underline; }

/* ------------------------------------------------------------------- legal */

/*
 * Both languages are in the markup; only the one matching the document shows.
 * No script decides this, so a legal document is correct in the right language
 * from the first paint, and stays correct if scripts never run at all.
 */
[data-lang] { display: none; }
html[lang="en"] [data-lang="en"],
html[lang="ar"] [data-lang="ar"] { display: block; }

.masthead .back {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  color: var(--ink-2);
  font-size: 0.9375rem;
  text-decoration: none;
}
.masthead .back:hover { color: var(--accent); }
/* Points back the way the reader came, in either direction. */
.arrow.flip { transform: scaleX(-1); }
[dir="rtl"] .arrow.flip { transform: none; }

.legal {
  max-width: 40rem;
  margin-inline: auto;
  padding-block: var(--s6) var(--s7);
}
.legal h1 {
  font-size: clamp(1.75rem, 1.4rem + 1.4vw, 2.25rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
}
.legal .updated {
  margin-block: var(--s2) var(--s6);
  font-size: 0.875rem;
  color: var(--ink-3);
}
.legal h2 {
  font-size: 1.0625rem;
  font-weight: 600;
  margin-block: var(--s6) var(--s3);
}
.legal p, .legal li {
  color: var(--ink-2);
  line-height: 1.7;
  margin-block-end: var(--s3);
}
.legal ul {
  list-style: disc;
  padding-inline-start: 1.4rem;
  margin-block-end: var(--s3);
}
.legal li { margin-block-end: var(--s1); }
.legal strong { color: var(--ink); font-weight: 500; }
.legal code {
  font-family: var(--mono);
  font-size: 0.875em;
  color: var(--ink);
  background: var(--ground);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}
/* A placeholder nobody has filled in should look like one. */
.legal .unset {
  color: var(--watch);
  background: var(--watch-wash);
  padding: var(--s3) var(--s4);
  border-radius: var(--radius-sm);
}
.legal .unset code { background: transparent; color: inherit; }
/* Direction-pinned, and not a mailto: the address is deliberately unlinkable. */
.legal .contact { display: inline-block; color: var(--ink); }

/* -------------------------------------------------------------- transitions */

/*
 * One motion cue, and it carries meaning: a row that has just landed in the
 * file fades up, so you can see where the thing you typed went.
 */
@keyframes settle {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}
tr.just-added { animation: settle 220ms var(--ease); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ------------------------------------------------------------------ narrow */

@media (max-width: 40rem) {
  body { padding-inline: var(--s3); }

  /* Three cells side by side would force the page wider than the phone, so
     they stack and the dividers turn with them. */
  .assurances {
    display: grid;
    inline-size: 100%;
    border-radius: var(--radius);
    text-align: start;
  }
  .assurances li { padding: 0.55rem 0.9rem; }
  .assurances li + li {
    border-inline-start: none;
    border-block-start: 1px solid var(--rule);
  }
  .panel { padding: var(--s4); }
  .row {
    display: block;
  }
  .row > .field { display: block; }
  .row > .field + .field { margin-block-start: var(--s4); }
  .intro { text-align: start; padding-block: var(--s5) var(--s6); }
  .intro .tagline { margin-inline: 0; }
  .masthead { padding-block-start: var(--s3); }
  .control { font-size: 0.8125rem; }

  /*
   * The ledger keeps its shape and scrolls inside its own frame, rather than
   * collapsing into cards and losing the decimal alignment that makes it worth
   * reading.
   *
   * No edge-to-edge bleed here: pulling the scroller out past the panel with
   * negative inline margins looked better by a hair and cost a real bug -
   * under RTL the clipped overflow shifted the root scroll origin and parked
   * the whole page ~150px off-screen on a phone. The frame stays inside the
   * panel, where its width is unambiguous in both directions.
   */
  table.ledger { min-inline-size: 32rem; }
}

@media print {
  body { background: #fff; padding: 0; }
  .masthead, .steps, .actions, details.store, .lang-toggle, .banner { display: none; }
  .panel { border: none; padding: 0; }
}
