/* H.Safy — ستايل التطبيق
   براند: navy #12304F / أخضر #0B7A5A / أحمر ديون #C2412D */

:root {
  --navy: #12304F;
  --navy-dark: #0C2137;
  --green: #0B7A5A;
  --red: #C2412D;
  --bg: #F4F6F8;
  --card: #FFFFFF;
  --text: #1A2430;
  --muted: #6B7684;
  --line: #E4E9EF;
  --radius: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { direction: rtl; }
html.en { direction: ltr; }

body {
  font-family: 'Noto Sans Arabic', system-ui, 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, .login-brand, .stat-value {
  font-family: 'Noto Kufi Arabic', 'Noto Sans Arabic', system-ui, sans-serif;
}

a { color: var(--green); text-decoration: none; }

/* ---------- شريط علوي ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--navy);
  color: #fff;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
}
.topbar-title { font-size: 19px; font-weight: 600; flex: 1; }
.icon-btn {
  background: rgba(255,255,255,.12);
  color: #fff;
  border: 0;
  border-radius: 10px;
  width: 38px;
  height: 38px;
  font-size: 20px;
  cursor: pointer;
  transform: scaleX(-1); /* السهم للخلف في RTL */
}
.icon-btn-spacer { width: 38px; }

/* ---------- الصفحات ---------- */
.page {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
}
.page.with-nav { padding-bottom: 96px; }

/* ---------- ناف سفلي ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  background: #fff;
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 0 8px;
  color: var(--muted);
  font-size: 12px;
}
.nav-item.active { color: var(--green); font-weight: 700; }
.nav-icon { font-size: 20px; }

/* ---------- اللوج إن ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-dark) 100%);
  padding: 24px;
}
.login-card {
  background: #fff;
  border-radius: 24px;
  padding: 32px 24px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-logo { width: 84px; height: 84px; border-radius: 20px; }
.login-brand { font-size: 30px; color: var(--navy); margin-top: 10px; }
.login-tagline { color: var(--muted); margin-bottom: 24px; }

.field { display: block; text-align: right; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field input {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px;
  font-family: inherit;
  background: #FAFBFC;
}
.field input:focus { outline: 2px solid var(--green); border-color: var(--green); }

.form-error { color: var(--red); font-size: 14px; margin: 4px 0 10px; }
.demo-hint { margin-top: 16px; font-size: 13px; color: var(--muted); }

/* ---------- أزرار ---------- */
.btn {
  display: inline-block;
  border: 0;
  border-radius: 12px;
  padding: 12px 20px;
  font-size: 16px;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
}
.btn.primary { background: var(--green); color: #fff; width: 100%; }
.btn.primary:disabled { opacity: .6; }
.btn.big { padding: 14px 20px; font-size: 17px; }
.btn.block { display: block; width: 100%; margin-top: 16px; }
.btn.ghost {
  background: transparent;
  border: 1.5px solid var(--green);
  color: var(--green);
  width: 100%;
  margin-top: 12px;
}
.btn.danger { background: var(--red); color: #fff; }

/* ---------- الرئيسية ---------- */
.hello { font-size: 18px; font-weight: 600; margin-bottom: 14px; }
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: 1px solid var(--line);
}
.stat-label { font-size: 12.5px; color: var(--muted); }
.stat-value { font-size: 20px; font-weight: 700; }
.stat-value.debt { color: var(--red); }
.stat-value.credit { color: var(--green); }

.section-title { font-size: 16px; margin: 18px 0 10px; }

/* ---------- كروت وقوائم ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  overflow: hidden;
}
.list { display: flex; flex-direction: column; }
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
}
.list-row:last-child { border-bottom: 0; }
a.list-row:active { background: #F0F4F0; }
.row-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.row-main b { font-size: 15px; }
.row-main small { color: var(--muted); font-size: 12.5px; }
.row-figures { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }

.money { font-weight: 700; font-size: 15px; white-space: nowrap; }
.money.debt { color: var(--red); }
.money.credit { color: var(--green); }
.money.zero { color: var(--muted); }
.muted { color: var(--muted); font-size: 13px; }

.totals-row { background: #FAFBFC; }
.totals-row.grand { background: #EEF6F2; }
.totals-row.grand .money { color: var(--green); font-size: 17px; }

/* ---------- رأس العميل ---------- */
.customer-head { padding: 16px; margin-bottom: 8px; }
.customer-head h2 { font-size: 19px; }
.balance-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 15px;
}
.balance-row strong { font-size: 18px; }
.mini-stats {
  display: flex;
  gap: 16px;
  margin-top: 10px;
  font-size: 13.5px;
  color: var(--muted);
}
.mini-stats .credit { color: var(--green); }
.hint { margin-top: 10px; font-size: 13px; color: var(--green); word-break: break-all; }

/* ---------- بحث ---------- */
.search-box { margin-bottom: 14px; }
.search-box input {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px;
  font-family: inherit;
  background: #fff;
}
.search-box input:focus { outline: 2px solid var(--green); border-color: var(--green); }

/* ---------- حالات ---------- */
.loading { text-align: center; padding: 48px 0; color: var(--muted); }
.spinner {
  width: 34px;
  height: 34px;
  border: 3.5px solid var(--line);
  border-top-color: var(--green);
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty-title { font-size: 17px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.empty-line { text-align: center; color: var(--muted); padding: 18px; }

@media (min-width: 700px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ======== v2 ======== */
body { min-height: 100vh; -webkit-font-smoothing: antialiased; }
input, select, button { font-family: inherit; }
.ic { display: inline-block; vertical-align: middle; flex: none; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; transform: none; }
.icon-btn svg { transform: scaleX(-1); }
.icon-btn.light { background: #EEF2F6; color: var(--navy); width: 38px; height: 38px; text-decoration: none; margin-inline-start: auto; }
.icon-btn.light svg { transform: none; }
.topbar { box-shadow: 0 2px 10px rgba(12,33,55,.18); }
.pill { font-size: 12px; font-weight: 700; padding: 5px 10px; border-radius: 999px; background: rgba(255,255,255,.16); color: #fff; white-space: nowrap; }
.pill.ok { background: #1c8e6d; } .pill.wait { background: #c98a14; } .pill.bad { background: var(--red); } .pill.busy { background: #2c5f8f; } .pill.demo { background: #6f4fb0; } .pill.local { background: rgba(255,255,255,.2); }
.field input, .field select { width: 100%; }
.field select, .two select { padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 12px; font-size: 16px; background: #fff; color: var(--text); }
.field select:focus { outline: 2px solid var(--green); border-color: transparent; }
.form { padding: 16px; }
.card.form { margin-bottom: 12px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn { transition: transform .08s, opacity .15s; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:active { transform: scale(.97); }
.btn.wide { width: 100%; margin: 8px 0; }
.btn.plain { background: transparent; color: var(--muted); }
.btn.ghost2 { background: #fff; border: 1.5px solid var(--line); color: var(--navy); padding: 11px 14px; font-size: 15px; }
.btn.dangerline { width: 100%; background: #fff; border: 1.5px solid var(--red); color: var(--red); margin-top: 14px; }
.btn.primary { display: flex; }
.btn:disabled { opacity: .55; }
.auth-title { font-size: 19px; margin-bottom: 12px; color: var(--navy); }
.auth-links { display: flex; justify-content: space-between; margin: 14px 2px 10px; font-size: 14px; }
.login-card .btn.ghost { margin-top: 6px; }
.code-box { font-family: ui-monospace, Menlo, monospace; direction: ltr; font-size: 26px; font-weight: 700; letter-spacing: 3px; background: #EEF6F2; color: var(--green); border-radius: 14px; padding: 18px 8px; margin: 14px 0; user-select: all; }
.check { display: flex; gap: 8px; align-items: center; margin: 4px 0 14px; text-align: right; font-size: 15px; }
.pre { white-space: pre-line; line-height: 1.7; }
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 6px 0 4px; }
.quick .btn { width: 100%; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: #E4EEF7; color: var(--navy); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 17px; flex: none; margin-inline-end: 10px; font-family: 'Noto Kufi Arabic', sans-serif; }
.avatar.big { width: 52px; height: 52px; font-size: 21px; margin: 0; }
.ch-top { display: flex; align-items: center; gap: 12px; }
.ch-top > div { flex: 1; min-width: 0; }
.ch-top h2 { overflow: hidden; text-overflow: ellipsis; }
.actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 14px; }
.actions .btn { padding: 11px 6px; font-size: 14px; width: 100%; margin: 0; }
.list-row { position: relative; color: inherit; transition: background .12s; }
a.list-row:active { background: #F1F5F9; }
.tag { font-style: normal; font-size: 11px; background: #FFF3D6; color: #8a5a00; padding: 2px 7px; border-radius: 8px; font-weight: 600; margin-inline-start: 4px; }
.tag.red { background: #FBE3DE; color: var(--red); }
.mini-x { background: #F1F5F9; border: 0; border-radius: 50%; width: 30px; height: 30px; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; margin-inline-start: 8px; flex: none; }
.search-box { position: relative; }
.search-box > svg { position: absolute; top: 50%; transform: translateY(-50%); inset-inline-start: 14px; color: var(--muted); }
.search-box input { padding-inline-start: 44px; }
.count-line { text-align: center; color: var(--muted); font-size: 12.5px; margin: 10px 0; }
.fab-add { position: fixed; inset-inline-start: 18px; bottom: calc(86px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 50%; background: var(--green); color: #fff; display: flex; align-items: center; justify-content: center; box-shadow: 0 8px 20px rgba(11,122,90,.4); z-index: 9; }
.nav-item.fab svg { background: var(--green); color: #fff; padding: 9px; width: 42px; height: 42px; border-radius: 50%; margin-top: -22px; box-shadow: 0 6px 16px rgba(11,122,90,.35); }
.nav-item.fab { color: var(--green); font-weight: 700; }
.nav-item { text-decoration: none; }
.empty-ico { width: 64px; height: 64px; border-radius: 50%; background: #E9EFF5; color: var(--navy); display: flex; align-items: center; justify-content: center; margin: 0 auto 12px; }
.empty-ico svg { width: 30px; height: 30px; }
.empty-state .btn { margin-top: 14px; width: auto; display: inline-flex; padding: 12px 26px; }
.skel { height: 74px; background: linear-gradient(90deg, #E9EEF3 25%, #F5F8FA 50%, #E9EEF3 75%); background-size: 200% 100%; animation: sh 1.2s infinite; margin-bottom: 12px; }
.skel.short { height: 46px; }
@keyframes sh { to { background-position: -200% 0; } }
.item { background: #fff; border-radius: 14px; padding: 10px; margin-bottom: 10px; border: 1px solid var(--line); }
.item input { width: 100%; padding: 11px 12px; border: 1.5px solid var(--line); border-radius: 10px; font-size: 16px; background: #fff; min-width: 0; }
.item input:focus { outline: 2px solid var(--green); border-color: transparent; }
.item-top { display: flex; align-items: center; margin-bottom: 8px; }
.item-grid { display: grid; grid-template-columns: .8fr 1fr 1fr 1.1fr; gap: 6px; align-items: center; }
.line-total { text-align: left; font-size: 14px; }
.card.sum { padding: 14px; margin: 12px 0; }
.sum-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 15px; }
.sum-row.big { font-size: 17px; border-top: 1px dashed var(--line); margin-top: 4px; padding-top: 10px; }
.sum-row .debt { color: var(--red); } .sum-row .credit { color: var(--green); }
.payrow .money { white-space: nowrap; }
#toasts { position: fixed; left: 0; right: 0; bottom: calc(90px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 100; pointer-events: none; }
.toast { background: #1A2430; color: #fff; padding: 11px 18px; border-radius: 12px; font-size: 14.5px; box-shadow: 0 8px 24px rgba(0,0,0,.25); animation: up .2s; max-width: 88vw; }
.toast.ok { background: #0B7A5A; } .toast.bad { background: var(--red); } .toast.out { opacity: 0; transition: opacity .3s; }
@keyframes up { from { transform: translateY(12px); opacity: 0; } }
.overlay { position: fixed; inset: 0; background: rgba(12,33,55,.5); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.sheet { background: #fff; width: 100%; max-width: 560px; border-radius: 22px 22px 0 0; padding: 22px 18px calc(18px + env(safe-area-inset-bottom)); animation: sl .2s; }
@keyframes sl { from { transform: translateY(40px); } }
.sheet h3 { font-size: 18px; margin-bottom: 8px; color: var(--navy); }
.row-btns, .share-list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.row-btns .btn, .share-list .btn { width: 100%; }
.hint { color: var(--muted); font-size: 13px; margin-top: 8px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ===== نسخة الكمبيوتر (المتصفح): نفس التطبيق، تخطيط أوسع وفي النص، RTL زي ما هو ===== */
@media (min-width: 900px) {
  body { background: #eef1f4; }
  .page, .login-card { max-width: 760px; margin-inline: auto; }
  .page { padding-block: 24px; }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .card.list, .card { border-radius: 14px; }
  .item-grid { grid-template-columns: 2fr 1fr 1fr 1fr 1fr; }
  .tabs { display: flex; gap: 8px; }
  .bottom-nav, nav.bottom { max-width: 760px; margin-inline: auto; left: 0; right: 0; border-radius: 14px 14px 0 0; }
  .list-row:hover { background: rgba(0,0,0,.03); }
}
.tabs { display: flex; gap: 8px; margin: 12px 0; } .tabs .btn { flex: 1; }
.role-pick { display: grid; gap: 12px; margin: 16px 0; }
.pick { margin-top: 6px; max-width: 100%; }

/* ===== English / LTR ===== */
html.en body, html.en input, html.en select, html.en button, html.en textarea { font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans', sans-serif; }
html.en .field, html.en .check { text-align: start; }
html.en .line-total { text-align: end; }
html.en .icon-btn { transform: none; }
html.en [scaleflip], html.en .icon-btn svg, html.en .back svg, html.en .chev, html.en .row-arrow { transform: none; }
html.en .login-brand, html.en h1, html.en h2, html.en h3 { letter-spacing: 0; }
.lang-btn { display: block; margin: 8px auto 0; }
html.en .icon-btn svg { transform: scaleX(-1); } html.en .icon-btn.light svg { transform: none; }
