/* تطبيق جوال أولاً: شريط علوي فيه المتجر والفترة، والمحتوى، وشريط تنقل تحت. على الشاشات الكبيرة التنقل يصير جنب. */
:root {
  --bg: #f4f6f5; --surface: #ffffff; --sunk: #eaefed; --ink: #15201d; --muted: #5d6b67; --line: #dbe2df;
  --accent: #0c6b63; --accent-ink: #ffffff; --accent-soft: #e0f0ed;
  --gain: #12773a; --loss: #c0352e; --warn: #a96b12;
  --gain-bg: #e4f3ea; --loss-bg: #fbe9e7; --warn-bg: #fbf1df;
  --font-display: "Readex Pro", "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  --font-body: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  --r: 14px; --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root {
  --bg: #0e1412; --surface: #151e1b; --sunk: #1b2622; --ink: #e5edea; --muted: #93a29d; --line: #263430;
  --accent: #3cb5a7; --accent-ink: #06201d; --accent-soft: #15302c;
  --gain: #4bc27a; --loss: #f0695f; --warn: #e3a646;
  --gain-bg: #14291d; --loss-bg: #311816; --warn-bg: #2e2412; color-scheme: dark } }

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 15px; line-height: 1.6; }
h1, h2, h3 { font-family: var(--font-display); margin: 0; text-wrap: balance; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; display: inline-block; }
.pos { color: var(--gain); } .neg { color: var(--loss); } .muted { color: var(--muted); }

/* ---------- الهيكل ---------- */
.shell { min-height: 100vh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px)); }
.topbar { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--line);
  padding: calc(10px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px));
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.store-pick { display: flex; flex-direction: column; min-width: 0; }
.store-pick select { border: 0; background: transparent; font-family: var(--font-display); font-weight: 700; font-size: 18px; padding: 0; max-width: 60vw; }
.store-pick small { color: var(--muted); font-size: 12px; }
.chips { display: flex; gap: 4px; background: var(--sunk); padding: 4px; border-radius: 999px; }
.chip { border: 0; background: transparent; padding: 5px 11px; border-radius: 999px; font-size: 13px; color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / .08); }
main { max-width: 760px; margin: 0 auto; padding-block: 14px 24px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); display: grid; gap: 14px; }

.nav { position: fixed; inset: auto 0 0 0; z-index: 6; background: var(--surface); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr); padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px); }
.nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: var(--nav-h); color: var(--muted); text-decoration: none; font-size: 12px; }
.nav a svg { width: 22px; height: 22px; }
.nav a[aria-current="page"] { color: var(--accent); font-weight: 600; }
@media (min-width: 900px) {
  .shell { padding-bottom: 0; padding-right: 220px; }
  .nav { inset: 0 0 0 auto; width: 220px; grid-template-columns: 1fr; align-content: start; border-top: 0; border-left: 1px solid var(--line); padding-top: 80px; }
  .nav a { flex-direction: row; justify-content: flex-start; height: 48px; padding-inline: 20px; font-size: 15px; gap: 12px; }
}

/* ---------- عناصر ---------- */
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 16px; font-size: 14.5px; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.danger { color: var(--loss); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.small { padding: 5px 11px; font-size: 13px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: default; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: grid; gap: 12px; min-width: 0; }
.card h2 { font-size: 16px; font-weight: 600; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.section-head h2 { font-size: 17px; }
.note { color: var(--muted); font-size: 13px; margin: 0; }
.err { color: var(--loss); font-size: 13.5px; margin: 0; }
.ok-msg { color: var(--gain); font-size: 13.5px; margin: 0; }

.field { display: grid; gap: 4px; font-size: 13.5px; min-width: 0; }
.field label { color: var(--muted); }
.field input, .field select { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; min-width: 0; font-size: 15px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }

.hero { background: var(--surface); border-radius: 20px; padding: 18px; display: grid; gap: 6px; border: 1px solid var(--line); }
.hero .label { color: var(--muted); font-size: 13.5px; }
.hero .big { font-family: var(--font-display); font-weight: 700; font-size: clamp(38px, 11vw, 56px); line-height: 1.1; }
.hero .big small { font-size: .42em; font-weight: 500; color: var(--muted); }
.why { justify-self: start; border: 0; background: none; color: var(--accent); padding: 0; font-size: 13.5px; font-weight: 600; }
.breakdown { display: grid; gap: 2px; border-top: 1px dashed var(--line); padding-top: 10px; font-size: 14px; }
.breakdown div { display: flex; justify-content: space-between; gap: 12px; }
.breakdown .total { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 6px; font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 560px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; display: grid; gap: 2px; min-width: 0; }
.stat span { color: var(--muted); font-size: 12.5px; }
.stat b { font-family: var(--font-display); font-size: 20px; font-weight: 600; }
.road { display: flex; gap: 6px 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; background: var(--sunk); border-radius: var(--r); padding: 10px 14px; font-size: 14px; }

.alerts { display: grid; gap: 8px; }
.alert { background: var(--surface); border: 1px solid var(--line); border-inline-start: 4px solid var(--warn); border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.alert.loss { border-inline-start-color: var(--loss); }
.alert p { margin: 0; } .alert small { color: var(--muted); display: block; }

.list { display: grid; gap: 8px; }
.row { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: grid; gap: 6px; }
.row-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.row-head h3 { font-size: 15px; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.row-head .amt { font-family: var(--font-display); font-weight: 600; font-size: 17px; white-space: nowrap; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: 13px; align-items: center; }
.pill { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--sunk); color: var(--muted); }
.pill.loss { background: var(--loss-bg); color: var(--loss); } .pill.gain { background: var(--gain-bg); color: var(--gain); } .pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.ok { background: var(--accent-soft); color: var(--accent); }
.bar { height: 6px; background: var(--sunk); border-radius: 999px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--loss); border-radius: 999px; }
.cost-input { width: 92px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; text-align: center; }
.cost-input.missing { border-color: var(--warn); background: var(--warn-bg); }

.funnel { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
@media (max-width: 480px) { .funnel { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.funnel div { background: var(--sunk); border-radius: 10px; padding: 8px 10px; display: grid; }
.funnel span { color: var(--muted); font-size: 12px; } .funnel b { font-family: var(--font-display); font-size: 19px; }

.conn { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; }
.conn .logo { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; color: #fff; font-size: 14px; }
.conn h3 { font-size: 15px; } .conn p { margin: 0; color: var(--muted); font-size: 12.5px; }

pre.wa { white-space: pre-wrap; background: var(--gain-bg); border-radius: 12px 12px 4px 12px; padding: 12px 14px; margin: 0; font-family: var(--font-body); font-size: 14px; line-height: 1.75; }
.ledger div { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; padding-block: 6px; border-bottom: 1px solid var(--line); }

/* ---------- الدخول ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding-block: 24px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.auth .card { width: min(420px, 100%); padding: 22px; gap: 14px; }
.auth h1 { font-size: 24px; }
.auth .lead { color: var(--muted); margin: 0; font-size: 14px; }
.empty { text-align: center; padding: 28px 16px; display: grid; gap: 10px; justify-items: center; }
.empty h2 { font-size: 18px; }
.toast { position: fixed; inset: auto 16px calc(var(--nav-h) + 12px + env(safe-area-inset-bottom, 0px)) 16px; margin: auto; max-width: 420px; background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-size: 14px; z-index: 20; text-align: center; }
.skeleton { height: 120px; border-radius: var(--r); background: var(--sunk); }
@media (prefers-reduced-motion: no-preference) { .skeleton { animation: pulse 1.2s ease-in-out infinite; } @keyframes pulse { 50% { opacity: .55; } } }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
label.btn { cursor: pointer; }
.insight h3 { font-size: 15.5px; font-weight: 600; }
.insight.critical { border-color: var(--loss); }
details summary::-webkit-details-marker { display: none; }
.dept-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
@media (min-width: 700px) { .dept-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.dept h3 { display: flex; align-items: center; gap: 6px; font-size: 14.5px; }
.dept .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dept.soon { opacity: .6; }
.dept.critical { border-color: var(--loss); }
textarea { font: inherit; color: inherit; }
