/* AlMasria payroll. Ledger-first: quiet chrome, dense tables, figures in tabular numerals. */
:root {
  --paper: #f3f6f7;
  --surface: #ffffff;
  --ink: #13222e;
  --muted: #5a6b77;
  --line: #d6dee3;
  --line-soft: #e8edf0;
  --brand: #0b5c6b;
  --brand-deep: #073f4a;
  --brand-tint: #e3f0f2;
  --ok: #1b6e45;      --ok-tint: #dff3e8;
  --warn: #8a5a00;    --warn-tint: #fff1cf;
  --bad: #a4262c;     --bad-tint: #fbe6e7;
  --info: #1d4e89;    --info-tint: #e2edf9;
  --radius: 6px;
  --font: "IBM Plex Sans", "IBM Plex Sans Arabic", "Segoe UI", Tahoma, Arial, sans-serif;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--font); line-height: 1.45; }
[dir="rtl"] body { font-family: "IBM Plex Sans Arabic", "IBM Plex Sans", "Segoe UI", Tahoma, Arial, sans-serif; }
h1 { font-size: 1.6rem; font-weight: 600; margin: 0 0 .75rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; font-weight: 600; margin: 0; }
h3 { font-size: .95rem; font-weight: 600; margin: .75rem 0 0; color: var(--brand-deep); }
p { margin: 0; }
a { color: var(--brand); }
small { color: var(--muted); font-size: .82em; }
.muted { color: var(--muted); }
.center { text-align: center; justify-content: center; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .9em; direction: ltr; unicode-bidi: plaintext; }
.n { font-variant-numeric: tabular-nums; text-align: end; direction: ltr; unicode-bidi: plaintext; }
table.grid td.n, table.grid th.n { text-align: right; }
[dir="rtl"] table.grid td.n, [dir="rtl"] table.grid th.n { text-align: left; }
.strong { font-weight: 600; }
.up { color: var(--ok); } .down { color: var(--bad); }
.error-text { color: var(--bad); min-height: 1.2em; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---- top bar */
.topbar { display: flex; align-items: center; gap: 1.5rem; padding: 0 1.25rem; height: 56px; background: var(--brand-deep); color: #fff; position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; line-height: 1.15; }
.brand strong { display: block; font-size: 1rem; font-weight: 600; }
.brand small { color: #b7d3d8; font-size: .72rem; }
.brand-mark { width: 26px; height: 26px; border-radius: 50%; background: conic-gradient(from 210deg, #f2c14e 0 25%, #fff 25% 50%, #d64545 50% 75%, #0b5c6b 75%); border: 2px solid #fff; flex: none; }
.topbar nav { display: flex; gap: .25rem; align-self: stretch; }
.topbar nav a { display: flex; align-items: center; padding: 0 .9rem; color: #cfe3e6; text-decoration: none; border-bottom: 3px solid transparent; border-top: 3px solid transparent; }
.topbar nav a:hover { color: #fff; }
.topbar nav a.on { color: #fff; border-bottom-color: #f2c14e; font-weight: 500; }
.top-end { margin-inline-start: auto; display: flex; align-items: center; gap: 1rem; }
.topbar .linkish { color: #cfe3e6; }
.topbar .linkish:hover { color: #fff; }
main { padding: 1.5rem 1.25rem 4rem; max-width: 1500px; margin: 0 auto; }
.view.narrow { max-width: 460px; margin: 0 auto; }
.narrow-wide { max-width: 900px; }
.lede { max-width: 70ch; color: var(--muted); margin-bottom: 1rem; }
.back { display: inline-block; margin-bottom: .5rem; font-size: .9rem; text-decoration: none; }
.back::before { content: "‹ "; }
[dir="rtl"] .back::before { content: "› "; }

/* ---- building blocks */
.row { display: flex; align-items: center; gap: .6rem; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.row.end-align { align-items: flex-end; }
.stack { display: flex; flex-direction: column; gap: .9rem; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; min-width: 0; overflow-x: auto; }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
.cols2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; }
.cols3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .8rem; }
.field { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.label { font-size: .8rem; color: var(--muted); }
.hint { font-size: .75rem; color: var(--muted); }
input[type="text"], input[type="password"], input[type="number"], input[type="month"], input[type="date"], input[type="search"], input[type="file"], select, textarea {
  font: inherit; color: inherit; background: #fff; border: 1px solid #b9c5cc; border-radius: 4px; padding: .42rem .55rem; width: 100%; min-width: 0;
}
input[readonly], textarea[readonly], select:disabled { background: #f1f4f6; color: #3d4c57; }
textarea { resize: vertical; }
.check { display: flex; gap: .5rem; align-items: center; }
.check input { width: 1rem; height: 1rem; }
.btn { font: inherit; font-weight: 500; padding: .45rem .9rem; border-radius: 4px; border: 1px solid #a9b7bf; background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; white-space: nowrap; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-deep); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.quiet { border-color: transparent; background: transparent; }
.btn.small { padding: .2rem .55rem; font-size: .85rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.danger-text { color: var(--bad); }
.linkish { font: inherit; background: none; border: 0; padding: 0; color: var(--brand); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 500; white-space: nowrap; }
.st-draft { background: var(--warn-tint); color: var(--warn); }
.st-submitted { background: var(--info-tint); color: var(--info); }
.st-approved { background: var(--ok-tint); color: var(--ok); }
.es-active { background: var(--ok-tint); color: var(--ok); }
.es-unpaid_leave, .es-suspended { background: var(--warn-tint); color: var(--warn); }
.es-resigned { background: #e9edf0; color: var(--muted); }
.pill { display: inline-block; white-space: nowrap; margin-inline-start: .4rem; padding: 0 .5rem; border-radius: 4px; font-size: .78rem; font-weight: 500; }
.pill.error { background: var(--bad-tint); color: var(--bad); } .pill.warning { background: var(--warn-tint); color: var(--warn); }
.pill.info { background: var(--info-tint); color: var(--info); } .pill.ok { background: var(--ok-tint); color: var(--ok); }
.dot { width: .6rem; height: .6rem; border-radius: 50%; flex: none; display: inline-block; }
.dot.error { background: var(--bad); } .dot.warning { background: #d99a00; } .dot.info { background: #7fa6d6; }
.notice { background: var(--info-tint); border-inline-start: 4px solid var(--info); padding: .6rem .8rem; border-radius: 4px; }
.notice.warning { background: var(--warn-tint); border-color: #d99a00; }
.empty { background: var(--surface); border: 1px dashed #b9c5cc; border-radius: var(--radius); padding: 3rem 1.5rem; text-align: center; display: flex; flex-direction: column; gap: .8rem; align-items: center; }
.empty p { max-width: 60ch; color: var(--muted); }
.starter { margin-bottom: 1rem; align-items: flex-end; }
.starter strong { align-self: center; margin-inline-end: .5rem; }
.starter .field { width: 190px; }

/* ---- tables */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
.table-wrap.tall { max-height: calc(100vh - 150px); }
table.grid { border-collapse: collapse; width: 100%; font-size: .92rem; }
table.grid th { position: sticky; top: 0; background: #eef2f4; text-align: start; font-weight: 600; font-size: .8rem; color: #3d4c57; padding: .5rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; z-index: 2; }
table.grid td { padding: .42rem .6rem; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.grid tbody tr:last-child td { border-bottom: 0; }
table.grid tr.clickable { cursor: pointer; }
table.grid tr.clickable:hover td { background: var(--brand-tint); }
table.grid tr.zero td { color: #8696a1; }
table.grid tr.review td { background: #f7fafd; }
table.grid.compact td, table.grid.compact th { padding: .32rem .5rem; }
table.grid input, table.grid select { padding: .25rem .4rem; }
td.flag { color: var(--warn); font-weight: 600; }
td.note { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: .85rem; }
td.detail { max-width: 560px; overflow-wrap: anywhere; font-size: .8rem; color: var(--muted); }
td.small-col { font-size: .82rem; }
.who { display: flex; align-items: center; gap: .5rem; }
.who strong { display: block; font-weight: 500; }
.who strong, .who small { text-align: left; }
[dir="rtl"] .who strong, [dir="rtl"] .who small { text-align: right; }
.who small { display: block; }
.route { font-size: .8rem; padding: .05rem .45rem; border-radius: 4px; background: #eef2f4; white-space: nowrap; }
.r-bank { background: var(--brand-tint); color: var(--brand-deep); }
.r-hold, .r-split { background: var(--warn-tint); color: var(--warn); }
.r-none { background: transparent; color: #8696a1; }

/* ---- payroll page */
.run-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.run-head h1 { margin-bottom: .3rem; }
.meta { font-size: .85rem; }
.equation { display: flex; align-items: stretch; flex-wrap: wrap; gap: .25rem .9rem; background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--brand); border-radius: var(--radius); padding: .9rem 1.25rem; margin-bottom: .8rem; }
.term { display: flex; flex-direction: column; justify-content: flex-start; min-width: 0; }
.term-label { font-size: .78rem; color: var(--muted); white-space: nowrap; }
.term-value { font-size: 1.25rem; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: plaintext; white-space: nowrap; }
.term-sub { font-size: .75rem; color: var(--muted); }
.term-sub.up { color: var(--ok); } .term-sub.down { color: var(--bad); }
.term.strong .term-value { font-weight: 600; font-size: 1.5rem; color: var(--brand-deep); }
.term.bank .term-value { font-weight: 600; }
.term.prev { margin-inline-start: auto; padding-inline-start: 1rem; border-inline-start: 1px solid var(--line); }
.op { align-self: center; font-size: 1.3rem; color: #93a3ad; padding-top: .5rem; }
.split-mark { width: 1px; background: var(--line); margin: 0 .4rem; }
.checks { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem 1rem; margin-bottom: .8rem; }
.checks.has-error { border-color: #e2a9ac; } .checks.has-warning { border-color: #e6c877; }
.checks summary { cursor: pointer; }
.checks ul, .issue-list { list-style: none; margin: .5rem 0 0; padding: 0; max-height: 240px; overflow: auto; display: flex; flex-direction: column; gap: .25rem; }
.issue { display: flex; align-items: center; gap: .5rem; font-size: .9rem; flex-wrap: wrap; }
.issue-list { background: #f8fafb; border: 1px solid var(--line-soft); border-radius: 4px; padding: .5rem .7rem; margin: 0; }
.toolbar { margin-bottom: .6rem; }
.toolbar input[type="search"] { width: 240px; }
.toolbar select { width: auto; }
.chip { font: inherit; font-size: .88rem; padding: .28rem .8rem; border-radius: 999px; border: 1px solid #b9c5cc; background: #fff; cursor: pointer; color: var(--ink); }
.chip.on { background: var(--brand-deep); border-color: var(--brand-deep); color: #fff; }

/* ---- drawer and dialogs */
.overlay, .drawer-overlay { position: fixed; inset: 0; background: rgba(13, 34, 46, .45); z-index: 50; display: flex; }
.overlay { align-items: center; justify-content: center; padding: 1rem; }
.dialog { background: #fff; border-radius: 8px; padding: 1.25rem; width: min(460px, 100%); display: flex; flex-direction: column; gap: 1rem; }
.drawer-overlay { justify-content: flex-end; }
.drawer { background: #fff; width: min(620px, 100%); height: 100%; display: flex; flex-direction: column; box-shadow: -8px 0 24px rgba(13, 34, 46, .18); }
[dir="rtl"] .drawer { box-shadow: 8px 0 24px rgba(13, 34, 46, .18); }
.drawer header { display: flex; justify-content: space-between; gap: 1rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); }
.drawer-body { padding: 1rem 1.25rem; overflow: auto; flex: 1; display: flex; flex-direction: column; gap: .8rem; }
.drawer footer { display: flex; justify-content: space-between; gap: .75rem; flex-wrap: wrap; padding: .8rem 1.25rem; border-top: 1px solid var(--line); background: #f8fafb; }
.facts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .6rem; background: #f8fafb; border: 1px solid var(--line-soft); border-radius: 4px; padding: .6rem .8rem; }
.facts > div { display: flex; flex-direction: column; }
.facts strong { text-align: start; font-weight: 500; }
.standing { background: var(--warn-tint); border-radius: 4px; padding: .5rem .7rem; display: flex; flex-direction: column; font-size: .9rem; }
.calc { display: grid; grid-template-columns: 1fr auto; gap: .2rem 1rem; margin: 0; background: #f8fafb; border: 1px solid var(--line-soft); border-radius: 4px; padding: .7rem .9rem; }
.calc dt { color: var(--muted); } .calc dd { margin: 0; }
.calc .total { font-weight: 600; color: var(--brand-deep); border-top: 1px solid var(--line); padding-top: .3rem; margin-top: .2rem; }
.calc .total.bad { color: var(--bad); }
.big-number { font-size: 1.7rem; font-weight: 600; color: var(--brand-deep); }
.big-number .n { display: inline; }
.big-number small { font-size: .85rem; font-weight: 400; }

/* ---- sign in */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: linear-gradient(180deg, var(--brand-deep) 0 38%, var(--paper) 38%); }
.login-card { background: #fff; border-radius: 8px; padding: 1.75rem; width: min(400px, 100%); display: flex; flex-direction: column; gap: 1rem; box-shadow: 0 12px 32px rgba(13, 34, 46, .18); }
.login-brand { display: flex; gap: .8rem; align-items: center; }
.login-brand h1 { margin: 0; }
.login-brand .brand-mark { width: 40px; height: 40px; border-color: var(--line); }

.toast { position: fixed; bottom: 1.25rem; inset-inline-start: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: .6rem 1rem; border-radius: 6px; opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; z-index: 100; max-width: 90vw; }
[dir="rtl"] .toast { transform: translateX(50%) translateY(20px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
[dir="rtl"] .toast.show { transform: translateX(50%) translateY(0); }
.toast.error { background: var(--bad); }

@media (max-width: 900px) {
  .two-col, .cols3, .cols2, .facts { grid-template-columns: minmax(0, 1fr); }
  .topbar { height: auto; flex-wrap: wrap; padding: .5rem .8rem; gap: .5rem 1rem; }
  .topbar nav { order: 3; width: 100%; overflow-x: auto; }
  .topbar nav a { padding: .4rem .7rem; }
  main { padding: 1rem .8rem 3rem; }
  .term.prev { margin-inline-start: 0; border: 0; padding: 0; }
  .toolbar input[type="search"] { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
@media print { .topbar, .toolbar, .actions, .back { display: none; } .table-wrap.tall { max-height: none; } }

/* Mixed Arabic / English cell text follows the page direction, not the text's own. */
td[dir="auto"] { text-align: left; }
[dir="rtl"] td[dir="auto"] { text-align: right; }
td.n { white-space: nowrap; }

.subpanel { background: #f8fafb; border: 1px solid var(--line-soft); border-radius: 4px; padding: .8rem 1rem; }
.subpanel h3 { margin: 0; }
.subpanel input[type="file"] { width: auto; flex: 1; min-width: 220px; }
.notice ul { margin: 0; padding-inline-start: 1.2rem; }
[hidden] { display: none !important; }
