/* ==========================================================================
   Force Conerter Accounting - application stylesheet

   Design goals, in order:
     1. A bookkeeper reads numbers all day: high contrast, tabular figures,
        generous row height, no decorative noise.
     2. Works in English (LTR) and Arabic (RTL) from the same rules, using
        logical properties (inline-start/end) rather than left/right.
     3. Light and dark, honouring the operating system by default.
     4. Prints legibly, because UAE bookkeeping still runs on paper files.
   ========================================================================== */

:root {
  /* Neutrals */
  --c-bg:            #f5f6f8;
  --c-surface:       #ffffff;
  --c-surface-2:     #fafbfc;
  --c-surface-3:     #eef1f4;
  --c-border:        #d8dde3;
  --c-border-strong: #b4bcc6;
  --c-text:          #16202b;
  --c-text-muted:    #5b6775;
  --c-text-faint:    #8a95a3;

  /* Brand: a restrained steel blue. Metal recycling, not fintech neon. */
  --c-brand:         #1f5f8b;
  --c-brand-dark:    #17486a;
  --c-brand-light:   #e7f0f7;
  --c-brand-contrast:#ffffff;

  /* Semantic */
  --c-success:       #15803d;
  --c-success-bg:    #e8f6ed;
  --c-warning:       #a15c07;
  --c-warning-bg:    #fdf3e2;
  --c-danger:        #b3261e;
  --c-danger-bg:     #fdecea;
  --c-info:          #1f5f8b;
  --c-info-bg:       #e7f0f7;
  --c-neutral-bg:    #eef1f4;

  /* Debit and credit are the two colours an accountant actually scans for. */
  --c-debit:         #16202b;
  --c-credit:        #16202b;
  --c-negative:      #b3261e;

  --radius:      8px;
  --radius-sm:   5px;
  --radius-lg:   14px;
  --shadow-1:    0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .10);
  --shadow-2:    0 4px 12px rgba(16, 24, 40, .10);
  --shadow-3:    0 12px 32px rgba(16, 24, 40, .16);

  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;

  --sidebar-w: 248px;
  --topbar-h:  58px;

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
               "Noto Sans", "Noto Sans Arabic", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

:root[data-theme="dark"],
html[data-theme="system"]:where(.theme-dark) {
  --c-bg:            #0f151b;
  --c-surface:       #171f27;
  --c-surface-2:     #1c252e;
  --c-surface-3:     #232d38;
  --c-border:        #2c3742;
  --c-border-strong: #3d4a58;
  --c-text:          #e8edf2;
  --c-text-muted:    #9fadbc;
  --c-text-faint:    #74828f;
  --c-brand:         #63a6d6;
  --c-brand-dark:    #4b8cbb;
  --c-brand-light:   #1b2f3f;
  --c-brand-contrast:#0f151b;
  --c-success:       #5fcf8a;
  --c-success-bg:    #16301f;
  --c-warning:       #e3a951;
  --c-warning-bg:    #332713;
  --c-danger:        #f28b82;
  --c-danger-bg:     #3a1c19;
  --c-info:          #63a6d6;
  --c-info-bg:       #1b2f3f;
  --c-neutral-bg:    #232d38;
  --c-debit:         #e8edf2;
  --c-credit:        #e8edf2;
  --c-negative:      #f28b82;
  --shadow-1: 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 4px 12px rgba(0,0,0,.45);
  --shadow-3: 0 12px 32px rgba(0,0,0,.55);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --c-bg:            #0f151b;
    --c-surface:       #171f27;
    --c-surface-2:     #1c252e;
    --c-surface-3:     #232d38;
    --c-border:        #2c3742;
    --c-border-strong: #3d4a58;
    --c-text:          #e8edf2;
    --c-text-muted:    #9fadbc;
    --c-text-faint:    #74828f;
    --c-brand:         #63a6d6;
    --c-brand-dark:    #4b8cbb;
    --c-brand-light:   #1b2f3f;
    --c-brand-contrast:#0f151b;
    --c-success:       #5fcf8a;
    --c-success-bg:    #16301f;
    --c-warning:       #e3a951;
    --c-warning-bg:    #332713;
    --c-danger:        #f28b82;
    --c-danger-bg:     #3a1c19;
    --c-info:          #63a6d6;
    --c-info-bg:       #1b2f3f;
    --c-neutral-bg:    #232d38;
    --c-debit:         #e8edf2;
    --c-credit:        #e8edf2;
    --c-negative:      #f28b82;
    --shadow-1: 0 1px 2px rgba(0,0,0,.4);
    --shadow-2: 0 4px 12px rgba(0,0,0,.45);
    --shadow-3: 0 12px 32px rgba(0,0,0,.55);
  }
}

/* -------------------------------------------------------------------- base */

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

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0 0 var(--sp-3); line-height: 1.25; font-weight: 650; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
h4 { font-size: .93rem; color: var(--c-text-muted); text-transform: uppercase; letter-spacing: .04em; }
p  { margin: 0 0 var(--sp-3); }

a { color: var(--c-brand); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--c-brand-dark); }

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

/* The application shows and hides whole regions — the boot screen, the shell,
   the notifications drawer, the search results — with the `hidden` attribute.
   The browser's rule for that lives in the user-agent stylesheet, so ANY rule
   in this file that sets `display` on the same element silently beats it and
   the region never goes away. `!important` makes the attribute authoritative
   again. Without it, hiding the boot screen after a successful sign-in fails
   and the user is left staring at the sign-in form. */
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; inset-inline-start: var(--sp-3); top: -60px;
  z-index: 100; background: var(--c-brand); color: var(--c-brand-contrast);
  padding: var(--sp-2) var(--sp-4); border-radius: var(--radius);
  transition: top .15s ease;
}
.skip-link:focus { top: var(--sp-3); }

.noscript {
  margin: var(--sp-6) auto; max-width: 560px; padding: var(--sp-5);
  background: var(--c-warning-bg); color: var(--c-warning);
  border: 1px solid currentColor; border-radius: var(--radius);
}

/* ------------------------------------------------------------------- boot */

.boot {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: var(--c-bg); z-index: 200;
}
.boot__spinner {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid var(--c-border);
  border-top-color: var(--c-brand);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .boot__spinner { animation-duration: 2.4s; }
  * { scroll-behavior: auto !important; }
}

/* ----------------------------------------------------------------- topbar */

.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--sp-3);
  padding-inline: var(--sp-3);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
}
.topbar__menu { display: none; }
.topbar__brand {
  display: flex; align-items: center; gap: var(--sp-2);
  color: inherit; text-decoration: none; font-weight: 650;
  white-space: nowrap; overflow: hidden;
}
.topbar__mark {
  display: grid; place-items: center;
  width: 30px; height: 30px; flex: none;
  background: var(--c-brand); color: var(--c-brand-contrast);
  border-radius: var(--radius-sm); font-size: .78rem; letter-spacing: .02em;
}
.topbar__name { overflow: hidden; text-overflow: ellipsis; max-width: 30ch; }

.topbar__search { position: relative; flex: 1 1 auto; max-width: 520px; margin-inline: auto; }
.topbar__search input {
  width: 100%; height: 36px; padding-inline: var(--sp-3);
  background: var(--c-surface-3); border: 1px solid transparent;
  border-radius: var(--radius); color: inherit; font: inherit;
}
.topbar__search input:focus { background: var(--c-surface); border-color: var(--c-brand); }

.search-results {
  position: absolute; inset-inline: 0; top: calc(100% + 6px);
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius); box-shadow: var(--shadow-3);
  max-height: 60vh; overflow-y: auto; z-index: 50;
}
.search-results__group { padding: var(--sp-2) 0; border-bottom: 1px solid var(--c-border); }
.search-results__group:last-child { border-bottom: 0; }
.search-results__label {
  padding: var(--sp-1) var(--sp-3); font-size: .74rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; color: var(--c-text-faint);
}
.search-results__item {
  display: block; width: 100%; text-align: start;
  padding: var(--sp-2) var(--sp-3); background: none; border: 0;
  color: inherit; font: inherit; cursor: pointer;
}
.search-results__item:hover, .search-results__item:focus { background: var(--c-surface-3); }

.topbar__actions { display: flex; align-items: center; gap: var(--sp-1); flex: none; }

.icon-button {
  display: grid; place-items: center;
  width: 36px; height: 36px; flex: none;
  background: none; border: 1px solid transparent; border-radius: var(--radius);
  color: var(--c-text-muted); font-size: 1.05rem; cursor: pointer;
}
.icon-button:hover { background: var(--c-surface-3); color: var(--c-text); }
.icon-button--badge { position: relative; }
.badge {
  position: absolute; top: 2px; inset-inline-end: 2px;
  min-width: 17px; height: 17px; padding-inline: 4px;
  display: grid; place-items: center;
  background: var(--c-danger); color: #fff;
  border-radius: 9px; font-size: .66rem; font-weight: 700; line-height: 1;
}

.user-menu { position: relative; }
.user-menu__button {
  display: flex; align-items: center; gap: var(--sp-2);
  height: 36px; padding-inline: var(--sp-2);
  background: none; border: 1px solid transparent; border-radius: var(--radius);
  color: inherit; font: inherit; cursor: pointer;
}
.user-menu__button:hover { background: var(--c-surface-3); }
.user-menu__button > span:first-child {
  display: grid; place-items: center; width: 28px; height: 28px;
  background: var(--c-brand-light); color: var(--c-brand);
  border-radius: 50%; font-size: .74rem; font-weight: 700;
}
.user-menu__name { max-width: 16ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu__panel {
  position: absolute; inset-inline-end: 0; top: calc(100% + 6px);
  min-width: 240px; padding: var(--sp-2);
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius); box-shadow: var(--shadow-3); z-index: 50;
}
.user-menu__panel button, .user-menu__panel a {
  display: block; width: 100%; text-align: start;
  padding: var(--sp-2) var(--sp-3); background: none; border: 0;
  border-radius: var(--radius-sm); color: inherit; font: inherit;
  text-decoration: none; cursor: pointer;
}
.user-menu__panel button:hover, .user-menu__panel a:hover { background: var(--c-surface-3); }
.user-menu__meta {
  padding: var(--sp-2) var(--sp-3) var(--sp-3);
  border-bottom: 1px solid var(--c-border); margin-bottom: var(--sp-2);
  font-size: .82rem; color: var(--c-text-muted);
}

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

.layout { display: flex; align-items: flex-start; min-height: calc(100vh - var(--topbar-h)); }

.sidebar {
  position: sticky; top: var(--topbar-h);
  width: var(--sidebar-w); flex: none;
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto; padding: var(--sp-3) var(--sp-2) var(--sp-6);
  background: var(--c-surface); border-inline-end: 1px solid var(--c-border);
}
.nav-group { margin-bottom: var(--sp-4); }
.nav-group__label {
  padding: var(--sp-1) var(--sp-3); margin-bottom: var(--sp-1);
  font-size: .7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--c-text-faint);
}
.nav-link {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3); margin-bottom: 1px;
  border-radius: var(--radius); color: var(--c-text-muted);
  text-decoration: none; font-size: .9rem;
}
.nav-link:hover { background: var(--c-surface-3); color: var(--c-text); }
.nav-link[aria-current="page"] {
  background: var(--c-brand-light); color: var(--c-brand); font-weight: 600;
}
.nav-link__icon { width: 18px; text-align: center; flex: none; opacity: .85; }
.nav-link__count {
  margin-inline-start: auto; min-width: 20px; padding-inline: 5px;
  background: var(--c-surface-3); border-radius: 10px;
  font-size: .72rem; font-weight: 700; text-align: center; color: var(--c-text-muted);
}
.nav-link__count[data-tone="warning"] { background: var(--c-warning-bg); color: var(--c-warning); }
.nav-link__count[data-tone="danger"]  { background: var(--c-danger-bg);  color: var(--c-danger); }

.sidebar-scrim { display: none; }

.main { flex: 1 1 auto; min-width: 0; padding: var(--sp-4) var(--sp-5) var(--sp-7); }
.main:focus { outline: none; }

.breadcrumbs { display: flex; flex-wrap: wrap; gap: var(--sp-1); font-size: .82rem; margin-bottom: var(--sp-3); color: var(--c-text-faint); }
.breadcrumbs a { color: var(--c-text-muted); text-decoration: none; }
.breadcrumbs a:hover { text-decoration: underline; }
.breadcrumbs span[aria-hidden] { opacity: .5; }

/* ---------------------------------------------------------------- pieces */

.page-header {
  display: flex; flex-wrap: wrap; align-items: flex-start;
  gap: var(--sp-3); margin-bottom: var(--sp-4);
}
.page-header__text { flex: 1 1 320px; min-width: 0; }
.page-header__text p { color: var(--c-text-muted); margin: 0; font-size: .9rem; }
.page-header__actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

.card {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-1);
  margin-bottom: var(--sp-4); overflow: hidden;
}
.card__header {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--c-border); background: var(--c-surface-2);
}
.card__header h2, .card__header h3 { margin: 0; flex: 1 1 auto; }
.card__body { padding: var(--sp-4); }
.card__body--flush { padding: 0; }
.card__footer {
  padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--c-border);
  background: var(--c-surface-2);
  display: flex; flex-wrap: wrap; gap: var(--sp-2); justify-content: flex-end;
}

.grid { display: grid; gap: var(--sp-4); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid--4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.stat {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius-lg); padding: var(--sp-4); box-shadow: var(--shadow-1);
}
.stat__label { font-size: .78rem; color: var(--c-text-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: var(--sp-1); }
.stat__value { font-size: 1.55rem; font-weight: 680; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat__value--negative { color: var(--c-negative); }
.stat__meta { font-size: .8rem; color: var(--c-text-muted); margin-top: var(--sp-1); }
.stat--clickable { cursor: pointer; text-align: start; width: 100%; font: inherit; color: inherit; }
.stat--clickable:hover { border-color: var(--c-brand); }

/* ---------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table.data {
  width: 100%; border-collapse: collapse; font-size: .88rem;
}
table.data th, table.data td {
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--c-border);
  text-align: start; vertical-align: top;
}
table.data thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--c-surface-2); color: var(--c-text-muted);
  font-size: .76rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  white-space: nowrap;
}
table.data tbody tr:hover { background: var(--c-surface-2); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tfoot td { font-weight: 680; background: var(--c-surface-2); border-top: 2px solid var(--c-border-strong); }

.num {
  text-align: end; font-variant-numeric: tabular-nums;
  font-family: var(--font-mono); font-size: .86em; white-space: nowrap;
}
.num--negative { color: var(--c-negative); }
.mono { font-family: var(--font-mono); font-size: .86em; }
.nowrap { white-space: nowrap; }
.truncate { max-width: 34ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

th[aria-sort] { cursor: pointer; user-select: none; }
th[aria-sort]::after { content: " ⇅"; opacity: .35; }
th[aria-sort="ascending"]::after  { content: " ↑"; opacity: 1; }
th[aria-sort="descending"]::after { content: " ↓"; opacity: 1; }

.row-link { cursor: pointer; }

/* --------------------------------------------------------------- badges */

.badge-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 99px;
  font-size: .74rem; font-weight: 650; white-space: nowrap;
  background: var(--c-neutral-bg); color: var(--c-text-muted);
}
.badge-pill[data-tone="success"] { background: var(--c-success-bg); color: var(--c-success); }
.badge-pill[data-tone="warning"] { background: var(--c-warning-bg); color: var(--c-warning); }
.badge-pill[data-tone="danger"]  { background: var(--c-danger-bg);  color: var(--c-danger); }
.badge-pill[data-tone="info"]    { background: var(--c-info-bg);    color: var(--c-info); }
.badge-pill[data-tone="brand"]   { background: var(--c-brand-light);color: var(--c-brand); }

.confidence {
  display: inline-flex; align-items: center; gap: 6px; font-size: .76rem; color: var(--c-text-muted);
}
.confidence__bar {
  width: 44px; height: 5px; border-radius: 3px; background: var(--c-surface-3); overflow: hidden;
}
.confidence__fill { height: 100%; background: var(--c-success); }
.confidence__fill[data-level="medium"] { background: var(--c-warning); }
.confidence__fill[data-level="low"]    { background: var(--c-danger); }

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

.field { margin-bottom: var(--sp-3); }
.field > label, .field__label {
  display: block; margin-bottom: 4px;
  font-size: .82rem; font-weight: 600; color: var(--c-text-muted);
}
.field__hint  { margin-top: 4px; font-size: .78rem; color: var(--c-text-faint); }
.field__error { margin-top: 4px; font-size: .78rem; color: var(--c-danger); font-weight: 600; }
.field__required { color: var(--c-danger); margin-inline-start: 2px; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="search"], input[type="tel"], input[type="url"],
select, textarea {
  width: 100%; min-height: 38px; padding: 7px var(--sp-3);
  background: var(--c-surface); color: var(--c-text);
  border: 1px solid var(--c-border-strong); border-radius: var(--radius);
  font: inherit; font-size: .9rem;
}
input:disabled, select:disabled, textarea:disabled {
  background: var(--c-surface-3); color: var(--c-text-faint); cursor: not-allowed;
}
input:focus, select:focus, textarea:focus { border-color: var(--c-brand); outline-offset: 0; }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--c-danger); }
textarea { min-height: 88px; resize: vertical; }
/* Wide enough for a seven-figure amount with decimals and the number spinner.
   At the old width "1,847.25" displayed as "1847" and "412500.00" as "412",
   so the figure being committed could not be read without clicking into it. */
input.num-input {
  text-align: end;
  font-family: var(--font-mono);
  min-width: 11ch;
}

.checkbox { display: flex; align-items: flex-start; gap: var(--sp-2); font-size: .88rem; }
.checkbox input { width: 17px; height: 17px; min-height: 0; margin-top: 2px; flex: none; }

.form-grid { display: grid; gap: var(--sp-3) var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.form-grid--wide { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.span-all { grid-column: 1 / -1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 38px; padding: 0 var(--sp-4);
  background: var(--c-surface); color: var(--c-text);
  border: 1px solid var(--c-border-strong); border-radius: var(--radius);
  font: inherit; font-size: .89rem; font-weight: 600;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--c-surface-3); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn--primary { background: var(--c-brand); border-color: var(--c-brand); color: var(--c-brand-contrast); }
.btn--primary:hover:not(:disabled) { background: var(--c-brand-dark); border-color: var(--c-brand-dark); }
.btn--danger  { background: var(--c-danger); border-color: var(--c-danger); color: #fff; }
.btn--danger:hover:not(:disabled) { filter: brightness(.92); }
.btn--ghost { border-color: transparent; background: transparent; }
.btn--ghost:hover:not(:disabled) { background: var(--c-surface-3); }
.btn--sm { min-height: 30px; padding: 0 var(--sp-3); font-size: .82rem; }
.btn--block { width: 100%; }

.link-button {
  background: none; border: 0; padding: 0; color: var(--c-brand);
  font: inherit; font-size: .85rem; cursor: pointer; text-decoration: underline;
}

.button-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

/* ---------------------------------------------------------------- alerts */

.alert {
  display: flex; gap: var(--sp-3); align-items: flex-start;
  padding: var(--sp-3) var(--sp-4); margin-bottom: var(--sp-3);
  border: 1px solid; border-radius: var(--radius); font-size: .89rem;
}
.alert__icon { flex: none; font-size: 1.1rem; line-height: 1.3; }
.alert__body { flex: 1 1 auto; min-width: 0; }
.alert__body > :last-child { margin-bottom: 0; }
.alert[data-tone="info"]    { background: var(--c-info-bg);    border-color: var(--c-info);    color: var(--c-info); }
.alert[data-tone="success"] { background: var(--c-success-bg); border-color: var(--c-success); color: var(--c-success); }
.alert[data-tone="warning"] { background: var(--c-warning-bg); border-color: var(--c-warning); color: var(--c-warning); }
.alert[data-tone="danger"]  { background: var(--c-danger-bg);  border-color: var(--c-danger);  color: var(--c-danger); }
.alert strong { font-weight: 700; }

/* A plain-language explanation panel for people who are not accountants. */
.explainer {
  background: var(--c-brand-light); border-inline-start: 3px solid var(--c-brand);
  border-radius: var(--radius-sm); padding: var(--sp-3) var(--sp-4);
  font-size: .86rem; color: var(--c-text); margin-bottom: var(--sp-3);
}
.explainer h4 { color: var(--c-brand); margin-bottom: var(--sp-1); }
.explainer > :last-child { margin-bottom: 0; }

.empty {
  padding: var(--sp-7) var(--sp-4); text-align: center; color: var(--c-text-muted);
}
.empty__icon { font-size: 2.4rem; opacity: .35; margin-bottom: var(--sp-2); }

/* ---------------------------------------------------------------- toasts */

.toasts {
  position: fixed; inset-block-end: var(--sp-4); inset-inline-end: var(--sp-4);
  display: flex; flex-direction: column; gap: var(--sp-2);
  z-index: 300; max-width: min(420px, calc(100vw - 32px));
}
.toast {
  display: flex; gap: var(--sp-3); align-items: flex-start;
  padding: var(--sp-3) var(--sp-4);
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-inline-start-width: 4px; border-radius: var(--radius);
  box-shadow: var(--shadow-3); font-size: .88rem;
  animation: toast-in .18s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.toast[data-tone="success"] { border-inline-start-color: var(--c-success); }
.toast[data-tone="warning"] { border-inline-start-color: var(--c-warning); }
.toast[data-tone="danger"]  { border-inline-start-color: var(--c-danger); }
.toast[data-tone="info"]    { border-inline-start-color: var(--c-info); }
.toast__body { flex: 1 1 auto; min-width: 0; }
.toast__close { background: none; border: 0; color: var(--c-text-faint); cursor: pointer; font-size: 1.1rem; }

/* ---------------------------------------------------------------- modals */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 250;
  background: rgba(16, 24, 40, .55);
  display: grid; place-items: center; padding: var(--sp-4);
  overflow-y: auto;
}
.modal {
  width: min(680px, 100%); max-height: calc(100vh - 48px);
  display: flex; flex-direction: column;
  background: var(--c-surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3); overflow: hidden;
}
.modal--wide { width: min(1040px, 100%); }
.modal__header {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-4); border-bottom: 1px solid var(--c-border);
}
.modal__header h2 { margin: 0; flex: 1 1 auto; font-size: 1.08rem; }
.modal__body { padding: var(--sp-4); overflow-y: auto; flex: 1 1 auto; }
.modal__footer {
  padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--c-border);
  background: var(--c-surface-2);
  display: flex; flex-wrap: wrap; gap: var(--sp-2); justify-content: flex-end;
}

/* --------------------------------------------------------------- drawer */

.drawer {
  position: fixed; inset-block: 0; inset-inline-end: 0; z-index: 260;
  width: min(400px, 100vw); display: flex; flex-direction: column;
  background: var(--c-surface); border-inline-start: 1px solid var(--c-border);
  box-shadow: var(--shadow-3);
}
.drawer__header {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-4); border-bottom: 1px solid var(--c-border);
}
.drawer__header h2 { margin: 0; flex: 1 1 auto; font-size: 1.05rem; }
.drawer__body { flex: 1 1 auto; overflow-y: auto; padding: var(--sp-2); }

.notification {
  display: block; width: 100%; text-align: start;
  padding: var(--sp-3); border: 0; border-radius: var(--radius);
  background: none; color: inherit; font: inherit; cursor: pointer;
  border-inline-start: 3px solid transparent;
}
.notification:hover { background: var(--c-surface-3); }
.notification[data-unread="1"] { background: var(--c-brand-light); border-inline-start-color: var(--c-brand); }
.notification__title { font-weight: 640; font-size: .9rem; }
.notification__body  { font-size: .82rem; color: var(--c-text-muted); }
.notification__time  { font-size: .74rem; color: var(--c-text-faint); margin-top: 2px; }

/* ----------------------------------------------------- filters & toolbar */

.toolbar {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--c-surface-2); border-bottom: 1px solid var(--c-border);
}
.toolbar .field { margin-bottom: 0; min-width: 150px; }
.toolbar__spacer { flex: 1 1 auto; }

.pagination {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--c-border);
  font-size: .85rem; color: var(--c-text-muted);
}
.pagination__spacer { flex: 1 1 auto; }

.tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--c-border); margin-bottom: var(--sp-4); }
.tab {
  padding: var(--sp-2) var(--sp-4); background: none; border: 0;
  border-bottom: 2px solid transparent; color: var(--c-text-muted);
  font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer;
}
.tab:hover { color: var(--c-text); }
.tab[aria-selected="true"] { color: var(--c-brand); border-bottom-color: var(--c-brand); }

/* --------------------------------------------------- document review UI */

.review-layout { display: grid; gap: var(--sp-4); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1100px) { .review-layout { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); } }

.preview-frame {
  width: 100%; height: min(72vh, 780px);
  border: 1px solid var(--c-border); border-radius: var(--radius); background: var(--c-surface-3);
}

.field-row {
  display: grid; gap: var(--sp-2); align-items: start;
  grid-template-columns: minmax(130px, 210px) minmax(0, 1fr);
  padding: var(--sp-2) 0; border-bottom: 1px solid var(--c-border);
}
.field-row:last-child { border-bottom: 0; }
.field-row__label { font-size: .84rem; font-weight: 600; color: var(--c-text-muted); padding-top: 9px; }
.field-row__value { min-width: 0; }
.field-row__source {
  font-size: .74rem; color: var(--c-text-faint); margin-top: 3px;
  display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center;
}
.field-row__snippet {
  font-family: var(--font-mono); font-size: .74rem;
  background: var(--c-surface-3); padding: 2px 6px; border-radius: var(--radius-sm);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
@media (max-width: 640px) { .field-row { grid-template-columns: 1fr; } .field-row__label { padding-top: 0; } }

.entry-lines { width: 100%; border-collapse: collapse; font-size: .86rem; }
.entry-lines th, .entry-lines td { padding: var(--sp-2); border-bottom: 1px solid var(--c-border); }
.entry-lines th { font-size: .74rem; text-transform: uppercase; color: var(--c-text-muted); text-align: start; }
.entry-lines td.num input { min-height: 32px; }

/* An amount field must show the whole amount. These inputs were narrow enough
   to clip 412,500.00 down to "412", so the figure being committed permanently
   to the ledger could not be read without clicking into the box. Wide enough
   here for a nine-figure amount with decimals, right-aligned and tabular so
   the columns line up and a misplaced digit is obvious. */
/* min-width, not width: in a narrow column the browser treats a column width
   as a suggestion and crushes it anyway. Below this the wrapper scrolls
   sideways instead, which is the right trade — an amount you cannot read is
   worse than a table you have to scroll. */
.entry-lines { min-width: 620px; table-layout: fixed; }
.entry-lines td.num, .entry-lines th.num { width: 150px; }
.entry-lines td.num input {
  width: 100%;
  min-width: 0;
  text-align: end;
  font-variant-numeric: tabular-nums;
}
.entry-lines tfoot td { font-weight: 700; background: var(--c-surface-2); }
.balance-indicator { font-weight: 700; }
.balance-indicator[data-balanced="true"]  { color: var(--c-success); }
.balance-indicator[data-balanced="false"] { color: var(--c-danger); }

.dropzone {
  display: grid; place-items: center; gap: var(--sp-2);
  padding: var(--sp-7) var(--sp-4); text-align: center;
  border: 2px dashed var(--c-border-strong); border-radius: var(--radius-lg);
  background: var(--c-surface-2); color: var(--c-text-muted); cursor: pointer;
}
.dropzone:hover, .dropzone[data-dragover="true"] { border-color: var(--c-brand); background: var(--c-brand-light); color: var(--c-brand); }
.dropzone__icon { font-size: 2.2rem; }

.progress { height: 6px; background: var(--c-surface-3); border-radius: 3px; overflow: hidden; }
.progress__bar { height: 100%; background: var(--c-brand); transition: width .2s ease; }

.kv { display: grid; gap: var(--sp-1) var(--sp-4); grid-template-columns: auto 1fr; font-size: .88rem; }
.kv dt { color: var(--c-text-muted); }
.kv dd { margin: 0; font-weight: 600; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  position: relative; padding-inline-start: var(--sp-5); padding-bottom: var(--sp-3);
  border-inline-start: 2px solid var(--c-border); margin-inline-start: 6px;
}
.timeline li::before {
  content: ""; position: absolute; inset-inline-start: -7px; top: 4px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--c-surface); border: 2px solid var(--c-brand);
}
.timeline li:last-child { border-inline-start-color: transparent; padding-bottom: 0; }

/* ------------------------------------------------------------- responsive */

@media (max-width: 960px) {
  .topbar__menu { display: grid; }
  .topbar__search { max-width: none; }
  .sidebar {
    position: fixed; inset-block: var(--topbar-h) 0; inset-inline-start: 0;
    z-index: 45; transform: translateX(-100%); transition: transform .18s ease;
    box-shadow: var(--shadow-3);
  }
  html[dir="rtl"] .sidebar { transform: translateX(100%); }
  .sidebar[data-open="true"] { transform: translateX(0); }
  .sidebar-scrim {
    display: block; position: fixed; inset-block: var(--topbar-h) 0; inset-inline: 0;
    background: rgba(16,24,40,.45); z-index: 44;
  }
  .main { padding: var(--sp-3) var(--sp-3) var(--sp-7); }
}

@media (max-width: 620px) {
  .topbar__name { display: none; }
  .user-menu__name { display: none; }
  .stat__value { font-size: 1.3rem; }
  table.data { font-size: .82rem; }
  table.data th, table.data td { padding: var(--sp-2); }
  .toasts { inset-inline: var(--sp-3); inset-block-end: var(--sp-3); max-width: none; }
}

/* ------------------------------------------------------------------- RTL */

html[dir="rtl"] { direction: rtl; }
html[dir="rtl"] .num { font-family: var(--font-mono); direction: ltr; text-align: end; }
html[dir="rtl"] .mono { direction: ltr; display: inline-block; }
/* Latin identifiers and amounts stay left-to-right inside Arabic text. */
html[dir="rtl"] .ltr { direction: ltr; display: inline-block; }

/* ----------------------------------------------------------------- print */

@media print {
  :root { --c-bg: #fff; --c-surface: #fff; --c-surface-2: #fff; --c-surface-3: #fff;
          --c-border: #999; --c-text: #000; --c-text-muted: #333; }
  body { background: #fff; font-size: 11pt; }
  .topbar, .sidebar, .sidebar-scrim, .breadcrumbs, .toasts, .drawer,
  .page-header__actions, .toolbar, .pagination, .btn, .icon-button,
  .link-button, .skip-link, .tabs { display: none !important; }
  .layout { display: block; }
  .main { padding: 0; }
  .card { border: 1px solid #999; box-shadow: none; break-inside: avoid; margin-bottom: 12pt; }
  .card__header { background: #fff; }
  table.data { font-size: 9.5pt; }
  table.data thead { display: table-header-group; }
  table.data tr { break-inside: avoid; }
  .print-only { display: block !important; }
  .print-header { display: block !important; margin-bottom: 12pt; border-bottom: 2px solid #000; padding-bottom: 6pt; }
  a[href]::after { content: ""; }
  @page { margin: 14mm; }
}
.print-only, .print-header { display: none; }
