/* Layout: sidebar on the reading side (left in English, right in Arabic), shared filter strip, one working view.
   Slate neutrals with the SGB scaffold-yellow as accent. Spacing uses logical properties so both directions work. */
:root {
  --bg: #f4f5f2;
  --panel: #ffffff;
  --ink: #1d232b;
  --muted: #5d6672;
  --line: #dfe2dc;
  --side: #1f2a33;
  --side-ink: #e7ebee;
  --accent: #e3a812;
  --accent-ink: #1d232b;
  --bar: #2f5d7c;
  --bar-2: #c7871a;
  --bar-muted: #c3c9cf;
  --ok: #1d7a46;
  --warn: #a5610a;
  --bad: #b3261e;
  --chip: #eef0ea;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "SF Arabic", "Geeza Pro", Tahoma, "Noto Naskh Arabic", sans-serif;
  --num: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --r: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14191e; --panel: #1b2229; --ink: #e6e9ec; --muted: #9aa4ae; --line: #2c353e; --side: #0f1418; --side-ink: #dfe4e8;
    --accent: #f0b829; --accent-ink: #14191e; --bar: #6aa4c8; --bar-2: #e0a640; --bar-muted: #3a454f; --ok: #5cc28a; --warn: #e9a94b;
    --bad: #f07a72; --chip: #242d35; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 14px; line-height: 1.5; }
a { color: inherit; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
[hidden] { display: none !important; }

.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100%; }
.side { background: var(--side); color: var(--side-ink); padding: 18px 14px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; }
.brand-mark { background: var(--accent); color: var(--accent-ink); font-weight: 800; letter-spacing: .04em; padding: 6px 8px; border-radius: 6px; font-family: var(--num); }
.brand small { display: block; opacity: .7; font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { text-decoration: none; padding: 9px 12px; border-radius: 6px; opacity: .85; display: flex; justify-content: space-between; align-items: center; }
.nav a:hover { background: rgba(255,255,255,.06); opacity: 1; }
.nav a.on { background: rgba(255,255,255,.1); opacity: 1; box-shadow: inset 3px 0 0 var(--accent); }
[dir=rtl] .nav a.on { box-shadow: inset -3px 0 0 var(--accent); }
.badge { background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 0 7px; font-size: 12px; font-weight: 700; }
.side-foot { margin-top: auto; font-size: 12px; opacity: .7; line-height: 1.8; }

.main { min-width: 0; padding: 18px 22px 40px; display: flex; flex-direction: column; gap: 16px; }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
.filters .wide { grid-column: span 2; }
.f { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.f label { font-size: 12px; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; min-width: 0; width: 100%; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.f-actions { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 13px; }

.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 6px; padding: 7px 14px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 3px 9px; font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.row > select { width: auto; min-width: 170px; }

h1 { font-size: 22px; margin: 0; font-weight: 700; }
h2 { font-size: 15px; margin: 0; font-weight: 700; }
h3 { font-size: 13px; margin: 0; color: var(--muted); font-weight: 600; }
.view { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.lede { margin: 0; color: var(--muted); max-width: 80ch; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.kpi span { font-size: 12px; color: var(--muted); }
.kpi b { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; unicode-bidi: isolate; text-align: start; }
.kpi small { color: var(--muted); font-size: 12px; unicode-bidi: isolate; text-align: start; font-variant-numeric: tabular-nums; }
.kpi.ok b { color: var(--ok); }
.kpi.warn b { color: var(--warn); }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.card .note { margin: 0; font-size: 12px; color: var(--muted); }
.chart { position: relative; min-height: 120px; }
.chart svg { display: block; width: 100%; direction: ltr; overflow: visible; }
.chart text { font-family: var(--font); font-size: 12px; fill: var(--muted); }
.chart text.lbl { fill: var(--ink); }
.chart .bar { cursor: pointer; }
.chart .bar:hover { opacity: .8; }
.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 6px 20px rgba(0,0,0,.14); border-radius: 6px; padding: 6px 10px; font-size: 12px; }
.tip b { display: block; }

.tablebox { overflow: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); max-height: 70vh; }
.tablebox.short { max-height: 420px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th { position: sticky; top: 0; background: var(--panel); text-align: start; color: var(--muted); font-weight: 600; font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; z-index: 1; }
th.sort { cursor: pointer; user-select: none; }
th.sort:hover { color: var(--ink); }
th[aria-sort="ascending"]::after { content: " ▲"; font-size: 9px; }
th[aria-sort="descending"]::after { content: " ▼"; font-size: 9px; }
td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
td.n { direction: ltr; text-align: end; white-space: nowrap; font-variant-numeric: tabular-nums; }
[dir=rtl] td.n { text-align: left; }
td.desc { min-width: 260px; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--chip); }
tfoot td { font-weight: 700; background: var(--chip); position: sticky; bottom: 0; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; font-size: 13px; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; white-space: nowrap; border: 1px solid transparent; }
.pill.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.pill.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.pill.xl { border-color: var(--line); }
.pill.pdf { border-color: var(--line); border-style: dashed; color: var(--muted); }
.pill.bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.pill.mute { color: var(--muted); background: var(--chip); }

.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.form .f.full { grid-column: 1 / -1; }
.check { display: flex; gap: 6px; align-items: center; }
.check input { width: auto; }
.compare { display: grid; grid-template-columns: auto 1fr 1fr; gap: 4px 16px; font-size: 13px; align-items: baseline; }
.compare b { font-weight: 600; }
.notes { margin: 0; padding-inline-start: 18px; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.alert { border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); background: color-mix(in srgb, var(--warn) 8%, transparent); padding: 8px 12px; border-radius: 6px; font-size: 13px; }
.doc-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.doc-tabs .btn.on { border-color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }
.viewer { width: 100%; height: 78vh; border: 1px solid var(--line); border-radius: var(--r); background: #fff; }
.items-edit input, .items-edit textarea { padding: 4px 6px; }
.items-edit textarea { resize: vertical; min-height: 30px; font-size: 13px; }
.items-edit td { padding: 4px 6px; }

.drop { border: 2px dashed var(--line); border-radius: var(--r); padding: 36px 16px; text-align: center; background: var(--panel); display: flex; flex-direction: column; gap: 8px; align-items: center; transition: border-color .15s; }
.drop.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, var(--panel)); }
.drop strong { font-size: 16px; }
.job { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.job:last-child { border-bottom: 0; }
.job ul { margin: 4px 0 0; padding-inline-start: 18px; font-size: 13px; }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }
.cat-row { display: grid; grid-template-columns: 220px 1fr auto; gap: 8px; align-items: start; }
.cat-row textarea { min-height: 54px; resize: vertical; font-size: 12px; }
.toast { position: fixed; bottom: 18px; inset-inline-end: 18px; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 6px; z-index: 60; font-size: 13px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.print-head { display: none; }
.print-brand { display: none; }

/* company logo, signed-in user, dialogs */
.brand:has(.logo:not([hidden])) { flex-direction: column; align-items: flex-start; gap: 8px; }
.brand .logo { max-height: 56px; max-width: 100%; object-fit: contain; background: #fff; border-radius: 6px; padding: 4px 6px; }
.side-user { border-top: 1px solid rgba(255,255,255,.12); padding-top: 12px; font-size: 13px; display: flex; flex-direction: column; gap: 6px; }
.side-user b { display: block; }
.side-user small { opacity: .7; }
.side-user .btn { color: var(--side-ink); border-color: rgba(255,255,255,.18); }
.side-user .link { color: var(--accent); }
.role-viewer .needs-edit, .role-viewer .nav [data-route=upload], body:not(.role-admin) .nav [data-route=settings] { display: none !important; }
.dlg { border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); color: var(--ink); padding: 18px; width: min(380px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(0,0,0,.35); }
.dlg-form { display: flex; flex-direction: column; gap: 12px; }
.dlg-form h2 { margin: 0; font-size: 16px; }
.acts { white-space: nowrap; }
.logo-preview { max-height: 64px; max-width: 220px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 4px; }

.login-body { display: grid; place-items: center; min-height: 100%; padding: 16px; }
.login { width: min(360px, 100%); }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.login-brand:has(.logo:not([hidden])) { flex-direction: column; text-align: center; }
.login-brand .logo { max-height: 80px; max-width: 220px; object-fit: contain; }
.login-brand strong { font-size: 18px; display: block; }
.login-brand small { color: var(--muted); }
.login-card .btn.primary { justify-content: center; padding: 9px 14px; }
.login-error { margin: 0; color: var(--bad); font-size: 13px; }
.show-pw { display: flex; align-items: center; justify-content: flex-start; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; margin-top: 4px; }
.show-pw input[type=checkbox] { width: auto; height: auto; margin: 0; padding: 0; flex: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .filters .wide { grid-column: span 1; }
  .grid2 { grid-template-columns: 1fr; }
}
@media print {
  .side, .filters, .no-print, .pager { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
  body { background: #fff; color: #000; font-size: 11px; }
  .card, .tablebox { border: 0; max-height: none; overflow: visible; }
  th { position: static; }
  .print-head { display: block; margin-bottom: 8px; }
  .print-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
  .print-brand .logo { max-height: 48px; max-width: 180px; object-fit: contain; }
}

.lang-btn { font-weight: 600; }
.side .lang-btn { color: var(--side-ink); border-color: rgba(255,255,255,.18); align-self: flex-start; }
.login-lang { position: fixed; top: 14px; inset-inline-end: 14px; }

/* change log */
table.changes td { vertical-align: top; }
table.changes td:first-child { white-space: nowrap; }
table.changes td.chg-details { min-width: 280px; font-size: 13px; }
table.changes .chg-del { color: var(--bad); }
table.changes .chg-add { color: var(--ok); }
table.changes tr.chg-alert td:nth-child(3) { color: var(--bad); font-weight: 600; }
