:root {
  --brand: #0f766e;
  --brand-2: #14b8a6;
  --brand-soft: #e6f4f2;
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #6b7785;
  --line: #e3e8ee;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --bad: #b91c1c;
  --bad-soft: #fdecec;
  --radius: 14px;
  --nav-h: 64px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
#app { max-width: 560px; margin: 0 auto; min-height: 100vh; background: var(--bg); }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 12px; }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }
.ic { width: 22px; height: 22px; flex: none; }
[dir="rtl"] .flip { transform: scaleX(-1); }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: var(--brand); color: #fff;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.net { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: rgba(255,255,255,.18); }
.net::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-inline-end: 5px; background: #86efac; }
.net.off::before { background: #fca5a5; }
.chip { border: 1px solid rgba(255,255,255,.5); background: transparent; color: #fff; border-radius: 99px; padding: 3px 10px; font: inherit; font-size: 13px; cursor: pointer; }

.main { padding: 16px 16px calc(var(--nav-h) + 24px); display: flex; flex-direction: column; gap: 12px; }

/* Bottom nav */
.bottomnav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 560px; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: #fff; border-top: 1px solid var(--line); z-index: 5;
}
.bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 11px; }
.bottomnav a.active { color: var(--brand); font-weight: 600; }

/* Cards & lists */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; border: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.hero { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border-radius: var(--radius); padding: 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.hero .muted { color: rgba(255,255,255,.85); }
.hero .btn.primary { background: #fff; color: var(--brand); }
.sec { margin-top: 6px; color: var(--muted); font-weight: 600; font-size: 13px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.stat .v { font-size: 22px; font-weight: 700; }
.stat .v small { font-size: 12px; font-weight: 400; color: var(--muted); margin-inline-start: 4px; }
.stat.warn { border-color: #f5c77e; background: var(--warn-soft); }
a.stat:active, a.item:active { opacity: .75; }

.list { display: flex; flex-direction: column; gap: 8px; }
.item { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; align-items: center; gap: 12px; }
.item.col { flex-direction: column; align-items: stretch; }
.item-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.item .end { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.note { font-size: 13px; background: var(--bg); border-radius: 8px; padding: 6px 8px; margin-top: 6px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; flex: none; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); }

.badge { font-size: 12px; padding: 2px 10px; border-radius: 99px; white-space: nowrap; font-weight: 600; }
.badge.pending, .badge.draft, .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.approved, .badge.published { background: var(--ok-soft); color: var(--ok); }
.badge.rejected { background: var(--bad-soft); color: var(--bad); }
.alert { border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
a.alert { display: block; border: 1px solid #f5c77e; }
.doc-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 0; border-bottom: 1px solid var(--line); }
.doc-row:last-child { border-bottom: 0; }
.doc-row .row-actions .btn { flex: none; }
.doc-row .badge { margin-inline-start: 4px; }
.form-l { display: flex; flex-direction: column; gap: 4px; }

.pagehead { display: flex; align-items: center; gap: 10px; }
.pagehead h2 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--card); border: 1px solid var(--line); }

.tabs { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.tabs a { flex: 1; text-align: center; padding: 8px; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: 14px; }
.tabs a.active { background: var(--brand); color: #fff; }
.dot { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 99px; background: var(--bad); color: #fff; font-size: 11px; }

.seg { display: flex; gap: 8px; }
.seg button { flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font: inherit; cursor: pointer; }
.seg button.active { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); font-weight: 700; }

dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; text-align: end; word-break: break-word; }

/* Forms */
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 15px; }
input, select, textarea {
  font: inherit; color: var(--text); background: #fff;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; min-height: 44px;
}
input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; accent-color: var(--brand); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: -1px; border-color: transparent; }
.search { background: var(--card); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.align-end { align-items: end; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; border: 1px solid var(--line); background: #fff; color: var(--text);
  border-radius: 10px; padding: 10px 14px; min-height: 44px; cursor: pointer; white-space: nowrap;
}
.btn .ic { width: 18px; height: 18px; }
.btn.sm { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.success { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger.ghost { color: var(--bad); border-color: #f3b4b4; }
.link { background: none; border: none; color: var(--brand); font: inherit; cursor: pointer; text-decoration: underline; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.row-actions .btn { flex: 1; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--brand), var(--brand-2)); }
.login-card { background: #fff; border-radius: 20px; padding: 24px; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.login-card .form { text-align: start; }
.login-logo { width: 64px; height: 64px; border-radius: 18px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; margin: 0 auto; }
.login-logo .ic { width: 34px; height: 34px; }
.hint { font-size: 12px; color: var(--muted); background: var(--bg); border-radius: 10px; padding: 8px; margin: 0; direction: ltr; }

/* Payslip */
.slip-head { display: flex; justify-content: space-between; align-items: flex-start; }
.slip-emp { border-top: 1px solid var(--line); padding-top: 10px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: start; background: var(--bg); padding: 6px 8px; font-size: 13px; color: var(--muted); }
.tbl td { padding: 6px 8px; border-bottom: 1px solid var(--line); }
.tbl td.num { text-align: end; font-variant-numeric: tabular-nums; direction: ltr; }
[dir="rtl"] .tbl td.num { text-align: left; }
.tbl tr.sum td { font-weight: 700; }
.net-row { display: flex; justify-content: space-between; align-items: center; background: var(--brand-soft); color: var(--brand); border-radius: 10px; padding: 12px; font-size: 16px; }

.toast {
  position: fixed; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: #1f2933; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 20; max-width: 90vw;
}

@media print {
  .topbar, .bottomnav, .noprint, .back, .pagehead .btn { display: none !important; }
  .main { padding: 0; }
  body, #app { background: #fff; }
}
