/* =========================================================
   نظام المكافآت — design tokens
   Ink-blue on cool paper. One accent; ochre is reserved for subtotals.
   ========================================================= */
:root {
  --paper: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --line: #e2e5ea;
  --line-strong: #cdd2da;
  --ink: #18202e;
  --ink-2: #3c4657;
  --muted: #6a7384;
  --accent: #24418f;
  --accent-ink: #ffffff;
  --accent-soft: #e9edf7;
  --accent-line: #c5cfe8;
  --sub: #f6e7b8;
  --sub-ink: #5c4300;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --ok: #1f7a4d;

  --t1: #9a6b00; --t2: #4d5a6e; --t3: #a14a1c; --t4: #1f6aa5;

  --font-ui: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  --font-head: "Noto Kufi Arabic", "IBM Plex Sans Arabic", "Segoe UI", sans-serif;

  --r-lg: 12px;   /* panels */
  --r-md: 8px;    /* controls */
  --r-sm: 6px;    /* tags */
  --float: 0 12px 32px rgba(24, 32, 46, .16), 0 2px 6px rgba(24, 32, 46, .08);

  --nav-h: 62px;
  --top-h: 58px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);

  /* legacy aliases used by markup */
  --bg: var(--paper);
  --text: var(--ink);
  --primary: var(--accent);
  --primary-ink: var(--accent-ink);
  --primary-soft: var(--accent-soft);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f141c;
    --surface: #161d28;
    --surface-2: #1b2330;
    --line: #273142;
    --line-strong: #344156;
    --ink: #e7ebf2;
    --ink-2: #c3cad6;
    --muted: #8d97a8;
    --accent: #8ea8f0;
    --accent-ink: #0f1830;
    --accent-soft: #1d2843;
    --accent-line: #33467a;
    --sub: #3a3216;
    --sub-ink: #f1d98e;
    --danger: #f2877d;
    --danger-soft: #3a1d1b;
    --t1: #e0b54a; --t2: #a9b4c6; --t3: #e79a6f; --t4: #79b8e6;
    --float: 0 12px 32px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

/* ============ Base ============ */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { font-family: var(--font-head); font-weight: 600; letter-spacing: 0; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--muted); }
.ico { display: inline-flex; width: 22px; height: 22px; flex: none; }
.ico svg { width: 100%; height: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ============ Layout ============ */
.app { min-height: 100dvh; display: flex; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 6px;
  min-height: calc(var(--top-h) + var(--sat));
  padding: var(--sat) calc(12px + var(--sar)) 0 calc(12px + var(--sal));
  background: var(--paper);
  border-bottom: 1px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--line); background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.topbar-title { flex: 1; margin: 0 6px; font-size: 19px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 2px; }

.view {
  flex: 1; width: 100%; max-width: 1120px; margin: 0 auto;
  padding: 6px calc(16px + var(--sar)) calc(var(--nav-h) + var(--sab) + 32px) calc(16px + var(--sal));
  outline: none;
}
.view.anim-fwd { animation: inFwd .22s ease-out; }
.view.anim-back { animation: inBack .22s ease-out; }
.view.anim-fade { animation: inFade .16s ease-out; }
@keyframes inFwd { from { opacity: 0; transform: translateX(-16px); } }
@keyframes inBack { from { opacity: 0; transform: translateX(16px); } }
@keyframes inFade { from { opacity: 0; } }

/* ---- Bottom tab bar (phones) ---- */
.nav {
  position: fixed; inset: auto 0 0 0; z-index: 30;
  display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + var(--sab));
  padding: 0 var(--sar) var(--sab) var(--sal);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.nav-brand { display: none; }
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; font-weight: 500; color: var(--muted); user-select: none; position: relative;
}
.nav-item .ico { width: 23px; height: 23px; }
.nav-item.active { color: var(--accent); font-weight: 600; }
.nav-item.active::after { content: ""; position: absolute; top: 0; width: 28px; height: 2px; border-radius: 0 0 2px 2px; background: var(--accent); }

/* ---- Rail (tablets, unfolded foldables) ---- */
@media (min-width: 640px) {
  .nav {
    position: sticky; top: 0; inset: auto; height: 100dvh;
    width: calc(84px + var(--sar));
    flex-direction: column; justify-content: flex-start; gap: 2px;
    padding: calc(var(--sat) + 14px) var(--sar) 16px 0;
    border-top: 0; border-inline-end: 1px solid var(--line);
    background: var(--surface);
  }
  .nav-item { flex: none; height: 62px; font-size: 11.5px; }
  .nav-item.active::after { top: 14px; bottom: 14px; width: 2px; height: auto; inset-inline-start: 0; border-radius: 2px; }
  .view { padding-bottom: calc(var(--sab) + 40px); padding-inline: 28px; }
  .topbar { padding-inline: 24px; }
}

/* ---- Sidebar (desktop) ---- */
@media (min-width: 1100px) {
  .nav { width: 240px; padding: 22px 12px; }
  .nav-brand { display: flex; align-items: center; gap: 12px; padding: 0 10px 24px; margin-bottom: 8px; border-bottom: 1px solid var(--line); }
  .brand-mark { width: 36px; height: 36px; border-radius: 9px; flex: none; background: var(--accent) url("../icons/icon.svg") center / cover; }
  .brand-text { display: flex; flex-direction: column; line-height: 1.35; }
  .brand-text strong { font-family: var(--font-head); font-size: 15px; font-weight: 700; }
  .brand-text small { color: var(--muted); font-size: 12.5px; }
  .nav-item { flex-direction: row; justify-content: flex-start; gap: 12px; height: 42px; padding: 0 12px; border-radius: var(--r-md); font-size: 14.5px; color: var(--ink-2); }
  .nav-item .ico { width: 20px; height: 20px; }
  .nav-item:hover { background: var(--surface-2); }
  .nav-item.active { background: var(--accent-soft); color: var(--accent); }
  .nav-item.active::after { display: none; }
  .view { padding-inline: 40px; }
  .topbar { padding-inline: 40px; min-height: calc(72px + var(--sat)); }
  .topbar-title { font-size: 23px; }
}

/* ============ Controls ============ */
.icon-btn { width: 42px; height: 42px; border-radius: var(--r-md); display: inline-grid; place-items: center; border: 0; background: transparent; color: var(--ink-2); }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn:active { background: var(--line); }
.back-btn .ico { width: 24px; height: 24px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px; border-radius: var(--r-md);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: 14.5px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn .ico { width: 18px; height: 18px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, var(--line)); background: var(--surface); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-primary.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent); padding-inline: 10px; }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-block { width: 100%; }
.btn-lg { min-height: 50px; font-size: 15.5px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.section { margin: 28px 2px 10px; display: flex; align-items: center; gap: 10px; min-height: 32px; }
.section h2 { margin: 0; font-size: 15px; font-weight: 600; color: var(--ink-2); }
.section .spacer { flex: 1; }

/* ---- Tier colors ---- */
.tier-1 { --tc: var(--t1); } .tier-2 { --tc: var(--t2); } .tier-3 { --tc: var(--t3); } .tier-4 { --tc: var(--t4); }
.tier-chip { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.tier-chip::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--tc, var(--muted)); flex: none; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: var(--tc, var(--muted)); margin-inline-end: 9px; vertical-align: 1px; }

/* ============ Overview (home + details) ============ */
.overview {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 20px; display: grid; gap: 18px;
}
.overview-top { display: flex; align-items: flex-start; gap: 12px; }
.overview-top > div { flex: 1; min-width: 0; }
.overview-label { color: var(--muted); font-size: 13.5px; }
.overview-amount { font-family: var(--font-head); font-weight: 700; font-size: clamp(32px, 9vw, 46px); line-height: 1.25; color: var(--ink); margin-top: 2px; }
.overview-amount .cur { font-family: var(--font-ui); font-size: 15px; font-weight: 500; color: var(--muted); margin-inline-start: 6px; }
.overview-stats { display: flex; margin: 0; border-top: 1px solid var(--line); padding-top: 14px; }
.overview-stats div { flex: 1; padding-inline: 14px; border-inline-start: 1px solid var(--line); }
.overview-stats div:first-child { padding-inline-start: 0; border: 0; }
.overview-stats dt { color: var(--muted); font-size: 12.5px; }
.overview-stats dd { margin: 0; font-size: 19px; font-weight: 600; }
.eye-btn { width: 40px; height: 40px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); display: grid; place-items: center; flex: none; }
.eye-btn:hover { background: var(--surface-2); }
.eye-btn .ico { width: 20px; height: 20px; }
.masked { letter-spacing: 3px; color: var(--muted); }
@media (min-width: 900px) {
  .overview { grid-template-columns: 1fr auto; align-items: end; padding: 24px 28px; }
  .overview-stats { grid-column: 1 / -1; }
  .overview > .btn { min-width: 220px; }
}

.home-layout { display: grid; gap: 4px; }
@media (min-width: 1100px) { .home-layout { grid-template-columns: 1.15fr .85fr; column-gap: 28px; align-items: start; } }

/* ---- Levels table ---- */
.levels { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.levels th { text-align: start; font-weight: 500; font-size: 12.5px; color: var(--muted); padding: 10px 16px; border-bottom: 1px solid var(--line); }
.levels td { padding: 13px 16px; border-bottom: 1px solid var(--line); }
.levels tr:last-child td { border-bottom: 0; }
.levels th:not(:first-child), .levels td:not(:first-child) { text-align: left; white-space: nowrap; }
.levels td:first-child { font-weight: 600; }
.levels tfoot td { font-weight: 700; border-top: 1px solid var(--line-strong); border-bottom: 0; background: var(--surface-2); }
@media (max-width: 420px) { .levels th, .levels td { padding-inline: 10px; } .levels { font-size: 13.5px; } }

/* ---- Generic panel used on department page ---- */
.tier-card { padding: 18px; }
.tier-card .amt { font-family: var(--font-head); font-size: 26px; font-weight: 700; margin-top: 8px; }
.tier-card .amt small { font-family: var(--font-ui); font-size: 13px; font-weight: 500; }
.tier-card .meta { color: var(--muted); font-size: 13.5px; display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.bar { display: none; }

/* ============ Lists ============ */
.list { padding: 0; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 16px; min-height: 58px;
  border: 0; border-bottom: 1px solid var(--line);
  background: transparent; width: 100%; text-align: start;
}
.list > .row:last-child, .list > :last-child.row { border-bottom: 0; }
button.row:active, a.row:active, .row.person:active { background: var(--surface-2); }
@media (hover: hover) { button.row:hover, a.row:hover, .row.person:hover { background: var(--surface-2); } }
.row-main { flex: 1; min-width: 0; }
.row-title { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { color: var(--muted); font-size: 13px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-end { text-align: end; flex: none; }
.row-end .num { font-weight: 600; }
.row-end .cur { display: block; color: var(--muted); font-size: 11.5px; }
.chev { color: var(--line-strong); width: 18px; height: 18px; }
.avatar { width: 38px; height: 38px; border-radius: var(--r-md); flex: none; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }
.avatar .ico { width: 20px; height: 20px; }
.date-tile { width: 46px; flex: none; text-align: center; border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; line-height: 1.2; }
.date-tile b { display: block; font-family: var(--font-head); font-size: 17px; padding: 4px 0 2px; }
.date-tile small { display: block; font-size: 10.5px; background: var(--surface-2); color: var(--muted); padding: 2px 0; border-top: 1px solid var(--line); }
.badge { font-size: 11.5px; font-weight: 600; padding: 0 7px; border-radius: var(--r-sm); background: var(--accent-soft); color: var(--accent); line-height: 20px; }
.badge.warn { background: var(--danger-soft); color: var(--danger); }
.strike { text-decoration: line-through; opacity: .6; }

.dept-group { margin-bottom: 12px; overflow: hidden; }
.dept-group-head { display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.dept-group-head h3 { margin: 0; font-size: 14.5px; flex: 1; }
.dept-group-head h3 small { font-family: var(--font-ui); font-weight: 500; }
.dept-group-head .tier-chip { font-weight: 500; color: var(--muted); }

/* ---- Search / filters ---- */
.search { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-md); padding: 0 12px; height: 46px; }
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input { flex: 1; border: 0; background: transparent; outline: none; font-size: 16px; min-width: 0; }
.search .ico { color: var(--muted); width: 19px; height: 19px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 12px 16px 6px; scrollbar-width: none; margin-inline: -16px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 34px; padding: 0 12px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--surface); font-size: 13.5px; color: var(--ink-2); }
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.chip .num { opacity: .7; margin-inline-start: 4px; }

/* ---- Floating add button ---- */
.fab {
  position: fixed; z-index: 25; inset-inline-end: calc(16px + var(--sal));
  bottom: calc(var(--nav-h) + var(--sab) + 14px);
  height: 50px; padding: 0 18px; border-radius: var(--r-lg); border: 0;
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; box-shadow: var(--float);
}
.fab .ico { width: 20px; height: 20px; }
.fab:active { transform: translateY(1px); }
@media (min-width: 640px) { .fab { bottom: calc(24px + var(--sab)); inset-inline-end: 32px; } }

/* ---- Forms ---- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 13.5px; font-weight: 500; color: var(--ink-2); }
.input, select.input { height: 46px; border-radius: var(--r-md); border: 1px solid var(--line-strong); background: var(--surface); padding: 0 12px; font-size: 16px; outline: none; width: 100%; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.num-input { direction: ltr; text-align: right; font-variant-numeric: tabular-nums; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--line-strong); border-radius: var(--r-md); overflow: hidden; }
.seg button { border: 0; border-inline-start: 1px solid var(--line); background: var(--surface); min-height: 46px; font-weight: 600; font-size: 13.5px; line-height: 1.3; padding: 5px 4px; color: var(--ink-2); }
.seg button:first-child { border-inline-start: 0; }
.seg button.on { background: var(--accent-soft); color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }
.seg button small { display: block; font-weight: 500; color: var(--muted); font-size: 11.5px; }
.switch-row { display: flex; align-items: center; gap: 12px; padding: 10px 0 14px; }
.switch-row .row-main { font-weight: 600; }
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; z-index: 1; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 14px; background: var(--line-strong); transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(-18px); }

/* ---- Bottom sheet / dialog ---- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(15, 20, 28, .42); display: flex; align-items: flex-end; justify-content: center; animation: fadeIn .18s; }
.overlay.closing { animation: fadeOut .18s forwards; }
.sheet { width: 100%; max-height: 92dvh; overflow: auto; background: var(--surface); border-radius: 16px 16px 0 0; padding: 6px 20px calc(20px + var(--sab)); animation: sheetUp .26s cubic-bezier(.2, .8, .2, 1); overscroll-behavior: contain; }
.overlay.closing .sheet { animation: sheetDown .18s forwards; }
.sheet-grip { width: 36px; height: 4px; border-radius: 2px; background: var(--line-strong); margin: 6px auto 14px; }
.sheet h2 { margin: 0 0 4px; font-size: 18px; }
.sheet .sheet-sub { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 10px; }
.sheet-actions .btn { flex: 1; }
@media (min-width: 640px) {
  .overlay { align-items: center; padding: 24px; }
  .sheet { max-width: 460px; border-radius: var(--r-lg); padding: 22px 24px; box-shadow: var(--float); animation: popIn .18s ease-out; }
  .overlay.closing .sheet { animation: fadeOut .12s forwards; }
  .sheet-grip { display: none; }
}
@keyframes fadeIn { from { opacity: 0; } }
@keyframes fadeOut { to { opacity: 0; } }
@keyframes sheetUp { from { transform: translateY(100%); } }
@keyframes sheetDown { to { transform: translateY(100%); } }
@keyframes popIn { from { opacity: 0; transform: scale(.98); } }
.pick-list .row { border: 1px solid var(--line); border-radius: var(--r-md); margin-bottom: 6px; min-height: 52px; }
.pick-list h4 { margin: 16px 2px 8px; font-size: 13px; color: var(--muted); font-family: var(--font-ui); font-weight: 600; }

/* ---- Toast ---- */
.toast {
  position: fixed; z-index: 60; left: 50%; transform: translate(-50%, 16px);
  bottom: calc(var(--nav-h) + var(--sab) + 16px);
  display: flex; align-items: center; gap: 14px;
  background: var(--ink); color: var(--surface); padding: 11px 16px; border-radius: var(--r-md);
  font-weight: 500; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100% - 32px);
  box-shadow: var(--float);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.show.has-action { pointer-events: auto; }
.toast button { border: 0; background: transparent; color: #9db4f5; font-weight: 700; padding: 2px 4px; }
@media (min-width: 640px) { .toast { bottom: 28px; } }

/* ---- iOS edge swipe indicator ---- */
.edge-swipe { position: fixed; z-index: 70; top: 50%; left: 0; width: 42px; height: 42px; margin-top: -21px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); color: var(--accent); box-shadow: var(--float); transform: translateX(-60px); opacity: 0; pointer-events: none; }
.edge-swipe .ico { transform: scaleX(-1); }

/* ============ Distribution sheet (on screen) ============ */
.sheet-head { padding: 18px 20px; display: flex; flex-wrap: wrap; gap: 16px; align-items: center; }
.sheet-head .title-block { flex: 1; min-width: 200px; }
.sheet-head h2 { margin: 0; font-size: 19px; }
.sheet-totals { display: flex; gap: 0; border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.kpi { padding: 8px 16px; min-width: 104px; border-inline-start: 1px solid var(--line); background: var(--surface); }
.kpi:first-child { border-inline-start: 0; }
.kpi small { color: var(--muted); display: block; font-size: 12px; }
.kpi b { font-size: 18px; font-weight: 600; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0 18px; }
.toolbar .btn { flex: 0 0 auto; }
@media (max-width: 639px) { .toolbar .btn { flex: 1 1 calc(50% - 8px); } }

.table-wrap { overflow-x: auto; }
table.dist { width: 100%; border-collapse: collapse; font-size: 14.5px; }
table.dist th, table.dist td { padding: 9px 16px; border-bottom: 1px solid var(--line); text-align: start; }
table.dist th { color: var(--muted); font-weight: 500; font-size: 12.5px; }
table.dist td.c-num { width: 48px; color: var(--muted); }
table.dist td.c-amt { width: 170px; }
table.dist tr.sub td { background: var(--sub); color: var(--sub-ink); font-weight: 700; border-bottom: 0; }
table.dist tr.clickable { cursor: pointer; }
@media (hover: hover) { table.dist tr.clickable:hover td { background: var(--surface-2); } }
.amt-input { width: 100%; max-width: 140px; height: 38px; border-radius: var(--r-sm); border: 1px solid transparent; background: transparent; direction: ltr; text-align: right; padding: 0 10px; font-weight: 600; font-variant-numeric: tabular-nums; }
.amt-input:hover { border-color: var(--line); }
.amt-input:focus { outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
@media (max-width: 639px) {
  table.dist th, table.dist td { padding: 8px 10px; }
  table.dist td.c-num { width: 30px; }
  table.dist td.c-amt { width: 112px; }
  .amt-input { max-width: 104px; }
}
.grand { padding: 16px 20px; display: flex; align-items: center; justify-content: space-between; font-family: var(--font-head); font-size: 18px; font-weight: 700; background: var(--ink); color: var(--surface); border-color: var(--ink); }

/* ---- Login / change password ---- */
body.booting .app, body.auth-open .app, body.auth-open .fab { visibility: hidden; }
#auth {
  position: fixed; inset: 0; z-index: 90; overflow: auto;
  background: var(--paper);
  display: grid; place-items: center;
  padding: calc(24px + var(--sat)) 16px calc(24px + var(--sab));
}
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 28px 24px 24px; }
.auth-brand { display: flex; align-items: center; gap: 12px; padding-bottom: 20px; margin-bottom: 22px; border-bottom: 1px solid var(--line); }
.auth-brand .brand-mark { display: block; width: 40px; height: 40px; border-radius: 10px; flex: none; background: var(--accent) url("../icons/icon.svg") center / cover; }
.auth-brand strong { display: block; font-family: var(--font-head); font-size: 16px; }
.auth-brand small { color: var(--muted); font-size: 12.5px; }
.auth-card h1 { margin: 0 0 6px; font-size: 21px; }
.auth-sub { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
.auth-card form { margin-top: 16px; }
.auth-card .input[dir="ltr"] { text-align: left; }
.auth-card .field small { font-size: 12px; }
.auth-error { min-height: 22px; margin: -4px 0 12px; color: var(--danger); font-size: 13.5px; font-weight: 500; }

/* ---- Sheet ledger ---- */
:root { --sticky-top: calc(var(--top-h) + var(--sat)); }
@media (min-width: 1100px) { :root { --sticky-top: calc(72px + var(--sat)); } }

.sheet-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.sheet-side, .sheet-body { min-width: 0; }
@media (min-width: 1100px) {
  .sheet-layout { grid-template-columns: 290px minmax(0, 1fr); gap: 24px; align-items: start; }
  .sheet-side { position: sticky; top: calc(var(--sticky-top) + 4px); display: grid; gap: 14px; }
}
.sheet-summary { padding: 18px 20px; }
.sheet-total { font-family: var(--font-head); font-weight: 700; font-size: 32px; line-height: 1.3; }
.sheet-total .cur { font-family: var(--font-ui); font-size: 14px; font-weight: 500; color: var(--muted); margin-inline-start: 6px; }
.sheet-facts { display: flex; margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--line); }
.sheet-facts div { flex: 1 1 auto; padding-inline: 12px; border-inline-start: 1px solid var(--line); }
.sheet-facts div:first-child { padding-inline-start: 0; border: 0; }
.sheet-facts dt { color: var(--muted); font-size: 12px; }
.sheet-facts dd { margin: 0; font-weight: 600; font-size: 14.5px; white-space: nowrap; }
.sheet-edited { margin: 10px 0 0; color: var(--muted); font-size: 12.5px; }
.sheet-main-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }

.dept-index { display: none; padding: 8px; max-height: calc(100dvh - var(--sticky-top) - 330px); overflow: auto; }
.dept-index-title { font-size: 12.5px; color: var(--muted); padding: 6px 10px 8px; }
.dept-index-item { display: flex; align-items: center; width: 100%; gap: 4px; border: 0; background: transparent; padding: 7px 10px; border-radius: var(--r-sm); text-align: start; font-size: 13.5px; }
.dept-index-item:hover { background: var(--surface-2); }
.dept-index-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dept-index-item .num { color: var(--muted); font-size: 12.5px; }
@media (min-width: 1100px) { .dept-index { display: block; } .jump-bar { display: none !important; } }

.jump-bar { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px 12px; padding: 0 16px; }
.jump-bar::-webkit-scrollbar { display: none; }
@media (min-width: 640px) { .jump-bar { margin-inline: 0; padding: 0; flex-wrap: wrap; } }

.ledger { overflow: clip; }
.ledger-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14.5px; }
.ledger-table thead th {
  position: sticky; top: var(--sticky-top); z-index: 5;
  background: var(--surface); color: var(--muted); font-weight: 500; font-size: 12.5px;
  text-align: start; padding: 10px 16px; border-bottom: 1px solid var(--line-strong);
}
.ledger-table td { padding: 8px 16px; border-bottom: 1px solid var(--line); }
.ledger-table .c-num { width: 52px; color: var(--muted); text-align: center; }
.ledger-table .c-amt { width: 168px; text-align: left; }
.ledger-table th.c-amt { text-align: left; padding-inline-end: 26px; }
.ledger-table tr.grp { scroll-margin-top: calc(var(--sticky-top) + 46px); }
.ledger-table tr.grp td { padding: 0; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.grp-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px 10px 8px; border-inline-start: 3px solid var(--tc, var(--accent)); }
.grp-name { font-family: var(--font-head); font-weight: 600; font-size: 15px; }
.grp-meta { color: var(--muted); font-size: 12.5px; }
.grp-head .tier-chip { margin-inline-start: auto; font-weight: 500; color: var(--muted); font-size: 12.5px; }
.grp-edit { width: 34px; height: 34px; color: var(--muted); }
.grp-edit .ico { width: 18px; height: 18px; }
.ledger-table tbody:first-of-type tr.grp td { border-top: 0; }
.ledger-table tr.clickable { cursor: pointer; }
@media (hover: hover) { .ledger-table tr.clickable:hover td { background: var(--surface-2); } }
.ledger-table tr.sub td { background: var(--sub); color: var(--sub-ink); font-weight: 700; border-bottom: 1px solid color-mix(in srgb, var(--sub-ink) 25%, transparent); }
.ledger-table tr.sub .c-amt { padding-inline-end: 26px; }
.ledger-table tr.grand-row td { background: var(--ink); color: var(--surface); font-family: var(--font-head); font-weight: 700; font-size: 16.5px; padding-top: 14px; padding-bottom: 14px; border: 0; }
.ledger-table tr.grand-row .c-amt { padding-inline-end: 26px; }
.ledger .amt-input { border-bottom: 1px dashed var(--line-strong); border-radius: 0; height: 34px; text-align: left; padding: 0 10px; }
.ledger .amt-input:hover { border-color: transparent; border-bottom-color: var(--accent); }
.ledger .amt-input:focus { border-radius: var(--r-sm); border-color: var(--accent); }
@media (max-width: 639px) {
  .ledger-table td { padding: 8px 10px; }
  .ledger-table thead th { padding: 9px 10px; }
  .ledger-table .c-num { width: 30px; padding-inline: 4px; }
  .ledger-table .c-amt { width: 112px; }
  .ledger-table th.c-amt, .ledger-table tr.sub .c-amt, .ledger-table tr.grand-row .c-amt { padding-inline-end: 18px; }
  .grp-head { padding-inline: 10px 4px; gap: 8px; }
  .ledger .amt-input { max-width: 100px; padding: 0 8px; }
  .sheet-total { font-size: 28px; }
}

/* ---- Sheets tab: latest reward ---- */
.current-card { padding: 18px 20px; }
.current-head { display: flex; align-items: center; gap: 14px; }
.current-head .row-title { font-family: var(--font-head); font-size: 17px; }
.current-kpis { display: grid; grid-template-columns: repeat(3, 1fr); margin: 16px 0; border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.current-kpis .kpi { min-width: 0; padding: 10px 14px; }
.current-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (max-width: 420px) { .current-actions { grid-template-columns: 1fr; } .current-kpis .kpi { padding: 8px 10px; } }

.summary-table td:nth-child(n+2), .summary-table th:nth-child(n+2) { text-align: left; white-space: nowrap; }
.summary-table tfoot td { font-weight: 700; background: var(--ink); color: var(--surface); border: 0; }

.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty .ico { width: 40px; height: 40px; margin-bottom: 8px; color: var(--line-strong); }

.settings-row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.settings-row:last-child { border-bottom: 0; }
.settings-row .input { height: 42px; max-width: 170px; }

/* ---- Person rows: grip, select, drag ---- */
.row.person { min-height: 52px; cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.grip { width: 36px; height: 42px; margin-inline-end: -8px; flex: none; display: grid; place-items: center; color: var(--line-strong); touch-action: none; cursor: grab; border-radius: var(--r-sm); }
.grip .ico { width: 18px; height: 18px; }
.grip:hover { background: var(--surface-2); color: var(--accent); }
.check { width: 22px; height: 22px; border-radius: 5px; flex: none; margin: 4px; border: 1.5px solid var(--line-strong); display: grid; place-items: center; color: transparent; background: var(--surface); }
.check .ico { width: 14px; height: 14px; }
.check.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.row.selected { background: var(--accent-soft); }
.group-check { background: transparent; border: 0; padding: 0; display: inline-flex; }
.drop-empty { padding: 16px; text-align: center; color: var(--muted); font-size: 13.5px; }
body.dragging { user-select: none; -webkit-user-select: none; cursor: grabbing; }
.row.drag-src { opacity: .35; }
.dept-group.drop-over { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.dept-group.drop-over .dept-group-head { background: var(--accent-soft); }
.drag-ghost { position: fixed; z-index: 80; left: 0; top: 0; pointer-events: none; transform: translate(-50%, -130%); display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--accent-line); border-radius: var(--r-md); padding: 8px 14px; box-shadow: var(--float); max-width: 80vw; }
.drag-ghost b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.drag-ghost small { display: block; color: var(--accent); font-size: 12px; font-weight: 600; }
.drag-hint { font-size: 12.5px; color: var(--muted); margin: 0 2px 12px; }
.drag-hint .ico { display: none; }

/* ---- Multi-select action bar ---- */
.select-bar { position: fixed; z-index: 35; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 10px calc(12px + var(--sar)) calc(10px + var(--sab)) calc(12px + var(--sal)); background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -8px 24px rgba(24, 32, 46, .08); animation: sheetUp .22s ease-out; }
.select-bar .btn { flex-direction: column; gap: 2px; min-height: 54px; padding: 4px; font-size: 12px; }
.select-bar .btn:disabled { opacity: .45; }
body.selecting .nav { visibility: hidden; }
@media (min-width: 640px) {
  .select-bar { left: 50%; right: auto; bottom: 20px; transform: translateX(-50%); width: min(540px, calc(100% - 140px)); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--float); animation: popIn .18s; }
  body.selecting .nav { visibility: visible; }
}

.print-only { display: none; }

/* ---- Foldables: dual-screen spanning ---- */
@media (horizontal-viewport-segments: 2) {
  .home-layout { grid-template-columns: env(viewport-segment-width 0 0, 1fr) env(viewport-segment-width 1 0, 1fr); column-gap: calc(env(viewport-segment-left 1 0, 0px) - env(viewport-segment-right 0 0, 0px) + 16px); }
}

/* ============ PDF table (A4 landscape) ============ */
.print-area { display: none; color: #18202e; background: #fff; font-family: var(--font-ui); }
.pt { width: 100%; border-collapse: collapse; font-size: 10.5pt; line-height: 1.35; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.pt th { background: #18202e; color: #fff; font-weight: 600; padding: 7px 10px; text-align: right; }
.pt th.n { color: #fff; }
.pt td { padding: 3.5px 10px; border-bottom: .6pt solid #dde1e7; }
.pt .n { width: 11mm; text-align: center; color: #7a8292; }
.pt .a { width: 36mm; text-align: left; direction: ltr; font-variant-numeric: tabular-nums; font-weight: 600; }
.pt tr.g td { background: #e9edf7; color: #24418f; font-family: var(--font-head); font-weight: 700; font-size: 10.5pt; padding-top: 6px; border-bottom: 1pt solid #24418f; }
.pt tr.g td span { display: inline-block; margin-inline-start: 8px; padding: 0 6px; border-radius: 4px; background: #24418f; color: #fff; font-family: var(--font-ui); font-size: 8.5pt; font-weight: 600; }
.pt tr.s td { background: #f6e7b8; color: #5c4300; font-weight: 700; border-bottom: 1.2pt solid #c9a63d; padding-top: 5px; padding-bottom: 5px; }
.pt tr.total td { background: #18202e; color: #fff; font-family: var(--font-head); font-weight: 700; font-size: 12pt; padding: 9px 10px; border: 0; }
.pt thead { display: table-header-group; }
.pt tr { break-inside: avoid; page-break-inside: avoid; }
.pt tr.g { break-after: avoid; page-break-after: avoid; }

/* ============ Print ============ */
@media print {
  @page { size: A4 landscape; margin: 10mm 12mm 12mm; }
  body.printing-table > *:not(.print-area) { display: none !important; }
  body.printing-table .print-area { display: block; }
  :root { --paper: #fff; --surface: #fff; --surface-2: #f4f4f4; --line: #bbb; --ink: #000; --muted: #444; }
  body { background: #fff; font-size: 11pt; }
  .nav, .topbar, .toolbar, .fab, .no-print, .toast, .edge-swipe, .eye-btn { display: none !important; }
  .view { padding: 0 !important; max-width: none; }
  .card, .overview { border-color: #999; }
  .print-only { display: block; }
  table.dist th, table.dist td, .levels th, .levels td { padding: 6px 8px; border: 1px solid #999; }
  table.dist tr, .levels tr { break-inside: avoid; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
