:root {
  --bg: #f4f6f3;
  --card: #ffffff;
  --text: #1d2420;
  --muted: #5f6b64;
  --line: #e2e7e3;
  --brand: #0f5132;
  --brand-2: #198754;
  --good: #198754;
  --mid: #e0a100;
  --bad: #d63333;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans Arabic", "Noto Naskh Arabic", Tahoma, sans-serif;
}

/* الداكن لما المستخدم يختاره من الزرار فوق؛ الافتراضي فاتح */
:root[data-theme="dark"] {
  --bg: #111613;
  --card: #1a211d;
  --text: #e8eee9;
  --muted: #9aa7a0;
  --line: #2b3530;
  --brand: #2fa36b;
  --brand-2: #3cbf7f;
  --bad: #f05252;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}

button, input, select { font: inherit; color: inherit; }

/* الشريط العلوي */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--brand); color: #fff;
}
.topbar > button:last-child { justify-self: end; }
.brand { display: flex; align-items: center; gap: 10px; line-height: 1.2; }
.brand-logo { width: 40px; height: 40px; border-radius: 10px; box-shadow: 0 0 0 2px rgba(255,255,255,.25); }
.brand-name { display: block; font-size: 22px; font-weight: 800; }
.brand-sub { font-size: 12px; opacity: .85; }
.icon-btn { position: relative; background: rgba(255,255,255,.15); border: 0; border-radius: 10px; width: 40px; height: 40px; font-size: 18px; cursor: pointer; }
.icon-btn.has-dot::after { content: ''; position: absolute; top: 5px; inset-inline-end: 5px; width: 9px; height: 9px; border-radius: 50%; background: var(--bad); border: 2px solid var(--brand); }
.top-actions { display: flex; gap: 8px; }

main { max-width: 720px; margin: 0 auto; padding: 12px 16px 96px; }

/* شريط التنقل */
.tabbar {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  background: none; border: 0; padding: 6px 0 8px; font-size: 12px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; cursor: pointer;
}
.tabbar button span { font-size: 20px; }
.tabbar button.active { color: var(--brand); font-weight: 700; }
.tabbar button { position: relative; }
.tabbar button.has-dot::after { content: ''; position: absolute; top: 6px; inset-inline-start: calc(50% + 10px); width: 9px; height: 9px; border-radius: 50%; background: var(--bad); }

.page-title { margin: 6px 0 4px; font-size: 22px; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 10px; }
.center { text-align: center; }

.card {
  background: var(--card); border-radius: var(--radius); padding: 14px;
  margin-bottom: 12px; border: 1px solid var(--line);
}
.card h3 { margin: 0 0 10px; font-size: 17px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.card-head h3 { margin: 0; }
.card-foot { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; }
.card-sep { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.status-pill {
  font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 99px;
  background: var(--bg); color: var(--muted); border: 1px solid var(--line); white-space: nowrap;
}
.status-pill.ok { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, var(--line)); }
.status-pill.warn { color: var(--mid); border-color: color-mix(in srgb, var(--mid) 40%, var(--line)); }
.status-pill.err { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
.status-box {
  font-size: 13px; padding: 10px 12px; border-radius: 10px; margin: 8px 0 12px;
  border: 1px solid var(--line); background: var(--bg);
}
.status-box.err {
  color: var(--bad);
  border-color: color-mix(in srgb, var(--bad) 45%, var(--line));
  background: color-mix(in srgb, var(--bad) 8%, var(--card));
}
.sync-meta { margin-bottom: 12px; }
.card.empty { text-align: center; font-size: 18px; padding: 32px 14px; }

/* الأزرار */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; cursor: pointer; text-decoration: none; min-height: 44px;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.ghost { background: transparent; border-style: dashed; }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: 14px; }
.btn.wide { display: flex; width: 100%; margin-bottom: 10px; }
.version-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.version-row .version { margin: 0; }
.app-version { margin: 18px 0 0; opacity: .8; }
.app-version a { color: var(--brand-2); }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; }

/* صفحتا الخصوصية والشروط */
.legal { max-width: 720px; margin: 0 auto; padding: 24px 16px 64px; }
.legal h1 { font-size: 26px; margin: 12px 0 4px; }
.legal h2 { font-size: 19px; margin: 22px 0 6px; }
.legal a { color: var(--brand-2); }
.legal ul { padding-inline-start: 20px; }

/* تبويبات الإعدادات */
.settings-tabs { display: flex; gap: 6px; margin: 12px 0; }
.settings-tabs .btn { position: relative; flex: 1; padding-inline: 4px; font-size: 13px; text-align: center; }
.settings-tabs .btn.has-dot::after { content: ''; position: absolute; top: 5px; inset-inline-end: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); }
.settings-tabs .btn.active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
.settings-panel[hidden] { display: none; }
.warn { color: var(--bad); font-size: 13px; margin: 6px 0 10px; }
.restore-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.restore-row:last-of-type { border-bottom: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.card .grid2 { margin-bottom: 0; }

/* الرئيسية */
.hero { display: flex; align-items: center; gap: 16px; }
.ring {
  --c: var(--good);
  flex: none; width: 112px; height: 112px; border-radius: 50%;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--line) 0);
  display: grid; place-items: center;
}
.ring.mid { --c: var(--mid); }
.ring.bad { --c: var(--bad); }
.ring > div {
  width: 88px; height: 88px; border-radius: 50%; background: var(--card);
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1;
}
.ring b { font-size: 26px; }
.ring small { color: var(--muted); font-size: 12px; }
.hero-text p { margin: 2px 0; }

.good-t { color: var(--good); }
.mid-t { color: var(--mid); }
.bad-t { color: var(--bad); }

.cat-row {
  display: grid; grid-template-columns: 1fr 90px 44px; align-items: center; gap: 8px;
  padding: 8px 0; border-bottom: 1px solid var(--line); cursor: pointer;
}
.cat-row:last-child { border-bottom: 0; }
.cat-pct { font-weight: 700; text-align: left; font-size: 14px; }

.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 99px; }
.bar i.good, .dot.good { background: var(--good); }
.bar i.mid, .dot.mid { background: var(--mid); }
.bar i.bad, .dot.bad { background: var(--bad); }

.alert-row, .task-row, .shop-row {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 8px 0; border-bottom: 1px solid var(--line);
}
.alert-row:last-child, .task-row:last-child, .shop-row:last-child { border-bottom: 0; }
.shop-row.bought, .shop-row.bought .item-sub { color: var(--brand-2); }
.shop-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.bought-mark { color: var(--brand-2); font-weight: 800; font-size: 18px; }
.alert-row { cursor: pointer; }
.alert-row.bad span:last-child { color: var(--bad); font-weight: 700; }
.alert-row.mid span:last-child { color: var(--mid); font-weight: 700; }

/* المخزون */
.cat-head { display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 700; font-size: 17px; }
.cat-head span:first-child { flex: 1; }
.chev { color: var(--muted); }
.cat.open .bar { margin: 10px 0 4px; }

.item { border-bottom: 1px solid var(--line); padding: 10px 0; }
.item:last-of-type { border-bottom: 0; }
.item-main { display: flex; align-items: center; gap: 10px; }
.item-info { flex: 1; min-width: 0; cursor: pointer; }
.item-name { font-weight: 600; }
.item-sub { color: var(--muted); font-size: 13px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-inline-end: 6px; vertical-align: middle; }
.badge { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 6px; background: var(--line); color: var(--muted); font-weight: 600; vertical-align: middle; }
.badge.bad { background: var(--bad); color: #fff; }
.badge.mid { background: var(--mid); color: #fff; }

.stepper { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; flex: none; }
.stepper button { width: 38px; height: 40px; border: 0; background: var(--bg); font-size: 20px; cursor: pointer; }
.stepper input { width: 56px; height: 40px; border: 0; text-align: center; background: var(--card); -moz-appearance: textfield; }
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }

.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; transition: .2s; cursor: pointer; }
.switch span::before { content: ''; position: absolute; width: 24px; height: 24px; top: 3px; right: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::before { transform: translateX(-22px); }

.item-more { margin-top: 10px; padding: 10px; background: var(--bg); border-radius: 10px; }
.item-more label, .form label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.row-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.filter-bar { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.filter-bar .btn { flex: 1; font-size: 13px; padding-inline: 6px; }
.filter-bar .btn.active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
.saved-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.saved-row:last-of-type { border-bottom: 0; }
.saved-info { flex: 1; min-width: 0; }
.saved-title { font-weight: 600; }
.embassy-link { width: 100%; margin-bottom: 10px; }
.quick-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 99px; padding: 6px 12px; font-size: 13px; cursor: pointer;
}
.chip:active { border-color: var(--brand); color: var(--brand); }

input[type=text], input[type=tel], input[type=number], input[type=date], input[type=password], select {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; min-height: 44px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text);
}
select { line-height: 1.2; }
.pw-wrap { position: relative; margin-bottom: 8px; }
.pw-wrap input { margin: 0; padding-inline-end: 44px; }
.pw-eye {
  position: absolute; inset-inline-end: 4px; top: 50%; transform: translateY(-50%);
  width: 36px; height: 36px; border: 0; background: transparent; cursor: pointer; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
}
.storage-list { display: grid; gap: 6px; margin: 10px 0; }
.storage-item {
  display: flex; justify-content: space-between; gap: 8px; font-size: 13px;
  padding: 6px 10px; background: var(--bg); border-radius: 8px;
}
.storage-item span { color: var(--muted); }
.storage-item b { font-weight: 600; direction: ltr; text-align: end; }
.info-list { display: grid; gap: 6px; }
.info-row {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px;
}
.info-row:last-child { border-bottom: 0; }
.info-row span { color: var(--muted); }
.info-row b { font-weight: 600; text-align: end; }
.member-view { padding: 8px 0; border-bottom: 1px solid var(--line); }
.member-view:last-child { border-bottom: 0; }
.member-view-head { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; }
.member-view-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.stepper input[type=number] { width: 56px; margin: 0; display: inline-block; border-radius: 0; min-height: 0; padding: 0; }

/* الأرقام */
.num-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 0;
  border-bottom: 1px solid var(--line); color: inherit; text-decoration: none;
}
.num-row:last-child { border-bottom: 0; }
.num { font-size: 24px; min-width: 56px; color: var(--brand); direction: ltr; text-align: center; }
.num-row span:nth-child(2) { flex: 1; }
.num-row small { display: block; color: var(--muted); font-size: 12px; }
.call { font-size: 20px; }

.contact, .member { padding: 10px 0; border-bottom: 1px solid var(--line); }
.contact-line, .member-line { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.contact-line input, .member-line input, .member-line select { margin-top: 0; }
.member > input { margin: 6px 0; }
.member-dob-label { font-size: 12px; color: var(--muted); margin-top: 8px; }
.member .dob-year { flex: 1; min-width: 110px; }
.member .dob-day { width: 72px; flex: none; }
.member-line select { width: auto; flex: none; }
.member-line input[type=tel] { flex: 1; }

input[type=search].search { display: block; width: 100%; margin-bottom: 12px; padding: 10px 14px; min-height: 44px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text); }
.debt-total { color: var(--bad); font-size: 14px; font-weight: 700; text-align: end; }
.debt-form {
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; margin: 10px 0; border-bottom: 1px solid var(--line);
}
.debt-form .grid2 { margin-bottom: 0; }
.debt-actions {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line);
}
.debt-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.debt-amt { color: var(--brand); font-size: 15px; white-space: nowrap; }
.contact-line .amount { width: 96px; flex: none; }
.contact-line .currency { width: auto; flex: none; }
.contact label.due { display: block; font-size: 13px; color: var(--muted); margin-top: 6px; }
.notice { border-color: var(--mid); }
.notice .hint { margin: 4px 0 8px; }
.steps { margin: 0 0 8px; padding-inline-start: 22px; }
.steps li { margin-bottom: 4px; }

/* نافذة */
.modal { border: 0; border-radius: var(--radius); padding: 18px; width: min(92vw, 420px); background: var(--card); color: var(--text); }
.modal::backdrop { background: rgba(0,0,0,.5); }
.modal h3 { margin: 0 0 8px; }
.modal p { margin: 0 0 10px; font-size: 14px; }
.modal input { margin-bottom: 8px; }
.modal .warn { color: var(--bad); font-size: 13px; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }

/* الدليل */
.guide summary { cursor: pointer; font-weight: 700; font-size: 17px; list-style: none; }
.guide summary::-webkit-details-marker { display: none; }
.guide summary::after { content: '▾'; float: left; color: var(--muted); }
.guide[open] summary::after { content: '▴'; }
.guide ul { margin: 10px 0 0; padding-inline-start: 20px; }
.guide li { margin-bottom: 6px; }

.welcome { background: var(--brand); color: #fff; border: 0; }
.welcome h2 { margin-top: 0; }
.file-btn { margin: 0; }

/* التقارير */
.report-bar { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.paper { background: #fff; color: #000; padding: 20px; border-radius: 8px; border: 1px solid var(--line); }
.paper-head { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 3px solid #0f5132; margin-bottom: 10px; flex-wrap: wrap; }
.paper h1 { font-size: 22px; margin: 0; color: #0f5132; }
.paper-head span { font-size: 12px; color: #555; }
.paper h2 { font-size: 16px; margin: 16px 0 6px; color: #0f5132; }
.paper table { width: 100%; border-collapse: collapse; font-size: 13px; }
.paper th, .paper td { border: 1px solid #ccc; padding: 4px 6px; text-align: right; vertical-align: top; }
.paper th { background: #eef5f0; }
.paper tr.miss td:first-child { color: #b00020; }
.paper .nums td.big { font-size: 18px; font-weight: 800; width: 70px; text-align: center; }
.paper .summary { background: #eef5f0; padding: 8px; border-radius: 6px; }
.paper ul { margin: 4px 0; padding-inline-start: 20px; font-size: 13px; }
.paper .g { break-inside: avoid; }
.paper .paper-hint { font-size: 12px; color: #555; margin: 6px 0; }
.paper .track td.blank, .paper .track th.blank { width: 64px; background: #fff; }
.paper .track th.blank { font-weight: 400; color: #777; font-size: 11px; }
.paper .track td { height: 22px; }
.paper .lines div { border-bottom: 1px solid #bbb; height: 26px; }
body.report-mode .tabbar { display: none; }

#update-bar {
  position: fixed; inset-inline: 12px; bottom: 80px; z-index: 40;
  background: var(--brand); color: #fff; border: 0; border-radius: 12px;
  padding: 12px 16px; font-weight: 700; box-shadow: 0 4px 16px rgba(0,0,0,.3); cursor: pointer;
}

/* رسالة سريعة */
#toast {
  position: fixed; bottom: 84px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #222; color: #fff; padding: 10px 18px; border-radius: 99px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 50;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  .topbar, .tabbar, .no-print, #toast, .app-version, .legal .back-link { display: none !important; }
  main { padding: 0; max-width: none; }
  .paper { border: 0; padding: 0; }
  .paper h2 { break-after: avoid; }
  .paper tr { break-inside: avoid; }
}
