/* Smart Audit (NSwise). Navy #0b1f3a + teal #2dd4bf. Light and dark (theme.js), Arabic right to left (logical properties),
   no italics anywhere, works from phone width up. Printed documents (body.printing) drop the frame. */
:root {
  --bg: #f4f6f9; --panel: #ffffff; --ink: #0f1b2d; --muted: #5b6b80; --line: #dfe5ec;
  --brand: #0b1f3a; --brand-ink: #ffffff; --accent: #0b7a6d; --accent-soft: #e0f7f3;
  --warn: #a15c07; --warn-soft: #fef3c7; --bad: #b91c1c; --bad-soft: #fee2e2; --ok: #15803d; --ok-soft: #dcfce7; --info: #1d4ed8; --info-soft: #dbeafe;
  --side: #0b1f3a; --side-ink: #c9d6e6; --side-active: #16335c;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a1220; --panel: #111c2e; --ink: #e6edf6; --muted: #93a3b8; --line: #23324a;
    --brand: #2dd4bf; --brand-ink: #062a26; --accent: #2dd4bf; --accent-soft: #0f2f2c;
    --warn: #fbbf24; --warn-soft: #3a2e0f; --bad: #f87171; --bad-soft: #3b1414; --ok: #4ade80; --ok-soft: #12321e; --info: #93c5fd; --info-soft: #172a4a;
    --side: #07101d; --side-ink: #b4c2d4; --side-active: #16294a; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a1220; --panel: #111c2e; --ink: #e6edf6; --muted: #93a3b8; --line: #23324a;
  --brand: #2dd4bf; --brand-ink: #062a26; --accent: #2dd4bf; --accent-soft: #0f2f2c;
  --warn: #fbbf24; --warn-soft: #3a2e0f; --bad: #f87171; --bad-soft: #3b1414; --ok: #4ade80; --ok-soft: #12321e; --info: #93c5fd; --info-soft: #172a4a;
  --side: #07101d; --side-ink: #b4c2d4; --side-active: #16294a; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", Tahoma, sans-serif; min-height: 100vh; }
em, i, cite, address, dfn, var { font-style: normal; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; } h2 { font-size: 16px; margin: 0; } h3 { font-size: 14px; margin: 16px 0 8px; }
.muted, small { color: var(--muted); } small { font-size: 12px; }
.hidden { display: none !important; }
.error, .bad { color: var(--bad); }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; white-space: nowrap; }
.skip { position: absolute; inset-inline-start: -999px; top: 0; background: var(--panel); padding: 8px 12px; z-index: 50; }
.skip:focus { inset-inline-start: 8px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- frame ---- */
.top { display: flex; align-items: center; gap: 12px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand span, .brand div { display: flex; flex-direction: column; line-height: 1.2; }
.brand small { font-size: 11px; }
.brand.big b { font-size: 20px; }
.top-tools { margin-inline-start: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.who { display: flex; flex-direction: column; line-height: 1.2; text-align: end; }
.layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 57px); }
.side { background: var(--side); padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; }
.side a { color: var(--side-ink); padding: 9px 12px; border-radius: 8px; }
.side a:hover { background: var(--side-active); color: #fff; text-decoration: none; }
.side a[aria-current="page"] { background: var(--side-active); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 #2dd4bf; }
[dir="rtl"] .side a[aria-current="page"] { box-shadow: inset -3px 0 0 #2dd4bf; }
main#main { padding: 22px; min-width: 0; max-width: 1320px; outline: none; }
.btn.menu-btn { display: none; }
.page-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.tools { display: flex; gap: 8px; flex-wrap: wrap; }
.flags { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 0 0 12px; }
.loading { color: var(--muted); }
.banner { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 10px 12px; margin: 0 0 12px; }
.banner.demo { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; border-radius: 0; margin: 0; }
.banner.demo a { color: inherit; text-decoration: underline; }
.banner.demo .demo-roles a, .banner.demo .demo-roles b { margin-inline-start: 8px; }
.banner.demo .sep { margin: 0 6px; }
.banner.demo .demo-reset { margin-inline-start: auto; }
.demo-try { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin: 0 0 18px; }
.demo-try p { margin: 0 0 10px; }

/* ---- cards and grids ---- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; min-width: 0; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
details.card > summary { cursor: pointer; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
details.card[open] > summary { margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 16px; }
.stats { display: flex; gap: 10px; flex-wrap: wrap; }
.stat { flex: 1 1 90px; background: var(--bg); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; }
.stat b { font-size: 20px; } .stat span { color: var(--muted); font-size: 12px; }
.stat.high b { color: var(--bad); } .stat.medium b { color: var(--warn); } .stat.low b { color: var(--ok); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .date { font-variant-numeric: tabular-nums; color: var(--muted); margin-inline-end: 6px; }
.list.bad .date { color: var(--bad); font-weight: 600; }
.empty { color: var(--muted); }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
.dl dt { color: var(--muted); } .dl dd { margin: 0; }
.gates { list-style: none; padding: 0; margin: 0 0 12px; }
.gates li { padding: 4px 0; } .gates li.ok { color: var(--ok); } .gates li.no { color: var(--muted); }
.totals { margin: 10px 0 0; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
meter { width: 100%; height: 10px; margin-bottom: 10px; }
blockquote { margin: 8px 0; padding: 10px 14px; background: var(--bg); border-inline-start: 3px solid var(--accent); border-radius: 6px; }

/* ---- chips, buttons ---- */
.chip { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.chip.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 7px 14px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 500; text-decoration: none; }
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.sm { padding: 3px 10px; font-size: 12px; }
.btn.wide { width: 100%; }
.btn.icon { padding: 4px 10px; font-size: 18px; line-height: 1; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.file { position: relative; overflow: hidden; }
.btn.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
td .btn + .btn { margin-inline-start: 4px; }
.theme-switch svg { width: 16px; height: 16px; }
.nsw-lang { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.nsw-lang button { border: 0; background: var(--panel); color: var(--ink); padding: 4px 10px; cursor: pointer; font: inherit; font-size: 12px; }
.nsw-lang button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }

/* ---- forms ---- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; min-width: 0; }
.field > span, legend { font-size: 12px; color: var(--muted); font-weight: 600; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0; max-width: 100%; }
textarea { resize: vertical; width: 100%; }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; accent-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.form-grid .field.wide, .form-grid .check, .form-grid .form-actions, .form-grid fieldset, .form-grid > div.field:has(textarea) { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
.form-actions.sticky { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; }
.check { display: flex; gap: 8px; align-items: center; margin: 4px 0 8px; }
.check.inline { display: inline-flex; margin-inline-end: 14px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin: 0 0 10px; }
fieldset.q legend { color: var(--ink); font-weight: 500; font-size: 13px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.inline-form input:not([type]), .inline-form input[type="text"] { flex: 1 1 160px; }
.inline-form .grow { flex: 3 1 220px; } .inline-form .short { flex: 0 1 110px; }
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 10px; }
.filters .field { margin: 0; }
.adj-line { display: flex; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.adj-line select { flex: 2 1 200px; } .adj-line input { flex: 1 1 100px; }
.step { border-bottom: 1px solid var(--line); padding: 10px 0; display: grid; gap: 6px; }
.step:last-child { border-bottom: 0; }
.step .xref { max-width: 180px; }
.reqs .req { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.req-act { display: flex; gap: 6px; align-items: flex-start; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: start; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr.unmapped td { background: var(--warn-soft); }
tr.over td { background: var(--bad-soft); }
table.fs tr.grp th { color: var(--ink); font-size: 13px; padding-top: 14px; }
table.fs tr.sub td { font-weight: 600; border-top: 1px solid var(--ink); }
table.fs td:not(:first-child), table.fs th:not(:first-child) { text-align: end; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; scrollbar-width: thin; }
.tabs a { padding: 8px 12px; color: var(--muted); white-space: nowrap; border-bottom: 2px solid transparent; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

/* ---- sign-in ---- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #0b1f3a 0%, #12305a 60%, #0f9e8c 140%); }
.auth-box { width: 100%; max-width: 400px; background: var(--panel); border-radius: 14px; padding: 26px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.auth-box h1 { margin: 18px 0 6px; }
.auth-tools { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 18px; }

/* ---- modal, toast ---- */
.modal-bg { position: fixed; inset: 0; background: rgba(5, 12, 24, .55); z-index: 40; }
.modal { position: fixed; z-index: 41; top: 5vh; inset-inline: 0; margin: 0 auto; width: min(560px, calc(100vw - 32px)); max-height: 90vh; overflow: auto; background: var(--panel); border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { width: min(860px, calc(100vw - 32px)); }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
.modal-body { padding: 16px 18px; }
#toast-root { position: fixed; bottom: 16px; inset-inline-end: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: calc(100vw - 32px); }
.toast { background: var(--brand); color: var(--brand-ink); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); }
.toast.bad { background: var(--bad); color: #fff; }

/* ---- documents (invoice, letters, statements, binder) ---- */
.doc { background: #fff; color: #111; border: 1px solid var(--line); border-radius: 8px; padding: 28px; max-width: 900px; margin: 0 auto 16px; }
.doc a { color: #111; }
.doc h1 { font-size: 20px; } .doc h2 { font-size: 16px; margin: 18px 0 8px; }
.doc table th, .doc table td { border-bottom: 1px solid #ddd; color: #111; }
.doc-h { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; border-bottom: 2px solid #0b1f3a; padding-bottom: 12px; margin-bottom: 14px; }
.doc-title { text-align: end; }
.doc p { margin: 4px 0; }
.lines td.num, .lines th:nth-child(n+2) { text-align: end; }
.lines tfoot td { font-weight: 600; } .lines tr.grand td { font-size: 15px; border-top: 2px solid #111; }
.void { color: #b91c1c; font-size: 28px; font-weight: 700; text-align: center; border: 3px solid #b91c1c; padding: 6px; }
.letter-body { white-space: pre-wrap; font: 14px/1.6 Georgia, "Times New Roman", "Noto Naskh Arabic", serif; margin: 0; }
.sig { margin-top: 20px; padding-top: 10px; border-top: 1px solid #ccc; font-size: 12px; word-break: break-all; }
.binder-sec { break-inside: avoid-page; }
.binder .wp { border-top: 1px solid #ddd; padding-top: 8px; }
.print-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; max-width: 900px; margin: 16px auto; padding: 0 16px; }
body.printing { background: var(--bg); }

/* ---- phone ---- */
@media (max-width: 900px) {
  .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; position: fixed; top: 57px; inset-inline-start: 0; bottom: 0; width: 240px; z-index: 30; overflow-y: auto; }
  body.nav-open .side { display: flex; }
  .btn.menu-btn { display: inline-flex; }
  .top { padding: 8px 12px; gap: 8px; }
  .who, .theme-switch .btn-word { display: none; }
  main#main { padding: 16px; }
}
@media (max-width: 560px) {
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .brand small { display: none; }
  .doc { padding: 16px; }
  .top-tools { gap: 6px; }
}

@media print {
  .no-print, .top, .side, #toast-root, #modal-root { display: none !important; }
  body, body.printing { background: #fff; }
  .doc { border: 0; padding: 0; max-width: none; margin: 0; }
  main#main { padding: 0; }
}
