/* LOGINA — نظام تصميم واحد، عربي أولاً، RTL، موبايل أولاً */

:root {
  --bg: #FBFAF6;
  --bg-soft: #F4F1E9;
  --surface: #FFFFFF;
  --surface-2: #FBF9F3;
  --ink: #16181D;
  --ink-2: #3B414B;
  --muted: #6C7480;
  --line: #E7E2D6;
  --line-2: #F0ECE2;
  --gold: #C98A0B;
  --gold-2: #F3B62B;
  --gold-soft: #FDF3DA;
  --ok: #137A4E;
  --ok-soft: #E7F6EE;
  --bad: #B23A22;
  --bad-soft: #FCEDE9;
  --info: #2352B4;
  --info-soft: #EAF0FD;
  --shadow: 0 1px 2px rgba(22, 24, 29, .05), 0 8px 24px -18px rgba(22, 24, 29, .35);
  --shadow-lg: 0 2px 6px rgba(22, 24, 29, .06), 0 24px 48px -28px rgba(22, 24, 29, .45);
  --r-sm: 10px;
  --r: 14px;
  --r-lg: 20px;
  --max: 1080px;
  --tab-h: 62px;
}

html[data-theme="dark"] {
  --bg: #0E1116;
  --bg-soft: #131820;
  --surface: #161B22;
  --surface-2: #1B2129;
  --ink: #E9ECF1;
  --ink-2: #C6CCD6;
  --muted: #98A1AE;
  --line: #262D37;
  --line-2: #202730;
  --gold: #F3B62B;
  --gold-2: #FFC94A;
  --gold-soft: #2A2214;
  --ok: #4ED39B;
  --ok-soft: #123024;
  --bad: #FF8A73;
  --bad-soft: #2E1A16;
  --info: #8FB2FF;
  --info-soft: #16203A;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -20px rgba(0, 0, 0, .8);
  --shadow-lg: 0 2px 8px rgba(0, 0, 0, .5), 0 30px 60px -30px rgba(0, 0, 0, .9);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Cairo", "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px));
  overflow-x: hidden;
}
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.35; font-weight: 800; letter-spacing: -.01em; }
h1 { font-size: clamp(1.5rem, 5vw, 2.1rem); }
h2 { font-size: clamp(1.15rem, 3.6vw, 1.45rem); }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .8em; }
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 6px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- header ---------- */
.hdr {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.hdr-in {
  max-width: var(--max); margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 10px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 900; font-size: 1.05rem; letter-spacing: -.02em; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand .dot {
  width: 22px; height: 22px; border-radius: 7px;
  background: linear-gradient(140deg, var(--gold-2), var(--gold));
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .35);
  display: inline-grid; place-items: center; color: #3A2A00; font-size: 12px; font-weight: 900;
}
.brand small { color: var(--muted); font-weight: 600; font-size: .72rem; letter-spacing: 0; }
.hdr-spacer { flex: 1; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-2); display: inline-grid; place-items: center;
  cursor: pointer; font-size: .8rem; font-weight: 700; padding: 0;
}
.icon-btn:hover { border-color: var(--gold); color: var(--gold); }
.icon-btn svg { width: 18px; height: 18px; }

.topnav { display: none; gap: 4px; }
.topnav a {
  padding: 8px 12px; border-radius: 10px; color: var(--ink-2); font-weight: 700; font-size: .9rem;
}
.topnav a:hover { background: var(--bg-soft); text-decoration: none; }
.topnav a.on { background: var(--gold-soft); color: var(--gold); }

@media (min-width: 860px) {
  .topnav { display: flex; }
  body { padding-bottom: 0; }
}

/* ---------- tabbar ---------- */
.tabbar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 45;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: grid; grid-template-columns: repeat(5, 1fr);
}
.tabbar a {
  height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--muted); font-size: .68rem; font-weight: 700; text-decoration: none;
}
.tabbar a svg { width: 21px; height: 21px; }
.tabbar a.on { color: var(--gold); }
.tabbar a.on svg { transform: translateY(-1px); }
@media (min-width: 860px) { .tabbar { display: none; } }

/* ---------- layout ---------- */
.wrap { max-width: var(--max); margin: 0 auto; padding: 18px 16px 40px; }
.view { display: none; }
.view.on { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.pad { padding: 16px; }
.stack { display: grid; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 620px) { .grid.g2 { grid-template-columns: 1fr 1fr; } }
.rates-grid { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
@media (min-width: 900px) { .rates-grid { grid-template-columns: repeat(4, 1fr); } }
.tool-card .fgrid.two { grid-template-columns: 1fr 1fr; }
@media (max-width: 359px) { .tool-card .fgrid.two { grid-template-columns: 1fr; } }
@media (min-width: 900px) { .grid.g3 { grid-template-columns: repeat(3, 1fr); } }

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.tiny { font-size: .74rem; }
.strong { font-weight: 800; }
.center { text-align: center; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.hr { height: 1px; background: var(--line); border: 0; margin: 14px 0; }

/* ---------- hero ---------- */
.hero {
  border-radius: 22px; padding: 20px 18px;
  background:
    radial-gradient(120% 100% at 100% 0%, color-mix(in srgb, var(--gold-soft) 85%, transparent) 0%, transparent 55%),
    linear-gradient(160deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.hero h1 { margin-bottom: 6px; }
.hero .lede { color: var(--ink-2); font-size: .95rem; max-width: 46ch; }
.hero .kicker {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .74rem; font-weight: 800; color: var(--gold);
  background: var(--gold-soft); border-radius: 999px; padding: 4px 10px; margin-bottom: 10px;
}

/* ---------- search ---------- */
.searchbar { position: relative; margin-top: 14px; }
.searchbar input {
  width: 100%; padding: 14px 46px 14px 44px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 1rem; font-family: inherit;
}
.searchbar input::placeholder { color: var(--muted); }
.searchbar .mag { position: absolute; inset-inline-start: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.searchbar .mag svg { width: 18px; height: 18px; }
.searchbar .clr {
  position: absolute; inset-inline-end: 8px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 1.1rem; padding: 6px 8px;
}
.suggest {
  position: absolute; z-index: 30; inset-inline: 0; top: calc(100% + 6px);
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow-lg); overflow: hidden; max-height: 300px; overflow-y: auto;
}
.suggest button {
  display: flex; width: 100%; gap: 8px; align-items: center; justify-content: space-between;
  padding: 10px 14px; border: 0; background: transparent; color: var(--ink); cursor: pointer;
  font-size: .9rem; text-align: start; font-family: inherit;
}
.suggest button:hover, .suggest button[aria-selected="true"] { background: var(--bg-soft); }
.suggest .tag { font-size: .7rem; color: var(--muted); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  border-radius: 999px; padding: 7px 12px; font-size: .82rem; font-weight: 700; cursor: pointer;
}
.chip:hover { border-color: var(--gold); }
.chip.on { background: var(--gold-soft); border-color: var(--gold); color: var(--gold); }

/* ---------- live rates ---------- */
.livebar {
  display: flex; align-items: center; gap: 8px; font-size: .76rem; color: var(--muted);
  margin: 4px 0 10px; flex-wrap: wrap;
}
.dot-live { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot-live.stale { background: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.dot-live.dead { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }

.rate {
  border: 1px solid var(--line); border-radius: var(--r); background: var(--surface);
  padding: 14px; display: grid; gap: 4px;
}
.rate .lbl { font-size: .78rem; color: var(--muted); font-weight: 700; display: flex; align-items: center; gap: 6px; }
.rate .val { font-size: 1.28rem; font-weight: 800; letter-spacing: -.02em; }
.rate .sub { font-size: .74rem; color: var(--muted); }
.rate.up .val { color: var(--ok); }
.rate.down .val { color: var(--bad); }
.rate .bar { height: 3px; border-radius: 3px; background: var(--line-2); overflow: hidden; }
.rate .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold-2), var(--gold)); }

/* ---------- gold table ---------- */
.karat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 700px) { .karat-grid { grid-template-columns: repeat(4, 1fr); } }
.karat {
  border: 1px solid var(--line); border-radius: var(--r); padding: 12px; background: var(--surface);
}
.karat .k { font-size: .76rem; color: var(--muted); font-weight: 700; }
.karat .p { font-size: 1.05rem; font-weight: 800; }
.karat .g { font-size: .72rem; color: var(--muted); }

table.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.tbl th, table.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line-2); text-align: start; }
table.tbl th { font-size: .76rem; color: var(--muted); font-weight: 800; }
table.tbl tr:last-child td { border-bottom: 0; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 11px 16px; font-weight: 800; font-size: .9rem; cursor: pointer; font-family: inherit;
  min-height: 44px;
}
.btn:hover { border-color: var(--gold); }
.btn.primary {
  background: linear-gradient(160deg, var(--gold-2), var(--gold)); border-color: transparent; color: #3A2A00;
  box-shadow: 0 6px 18px -10px rgba(201, 138, 11, .9);
}
.btn.primary:hover { filter: brightness(1.04); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 7px 12px; min-height: 34px; font-size: .82rem; border-radius: 10px; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, var(--line)); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- forms ---------- */
.field { display: grid; gap: 6px; }
.field > label { font-size: .8rem; font-weight: 800; color: var(--ink-2); }
.input, select.input, textarea.input {
  width: 100%; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: .95rem; font-family: inherit;
}
.input:focus { border-color: var(--gold); outline: none; box-shadow: 0 0 0 3px var(--gold-soft); }
textarea.input { min-height: 90px; resize: vertical; line-height: 1.7; }
.hint { font-size: .74rem; color: var(--muted); }
.fgrid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 620px) { .fgrid.two { grid-template-columns: 1fr 1fr; } .fgrid.three { grid-template-columns: repeat(3, 1fr); } }

.result {
  border-radius: var(--r); padding: 14px; background: var(--surface-2); border: 1px dashed var(--line);
  display: grid; gap: 8px;
}
.result .kv { display: flex; justify-content: space-between; gap: 10px; font-size: .9rem; }
.result .kv b { font-variant-numeric: tabular-nums; }
.result .big { font-size: 1.4rem; font-weight: 900; color: var(--gold); }

.badge {
  display: inline-flex; align-items: center; gap: 5px; border-radius: 999px;
  padding: 3px 9px; font-size: .72rem; font-weight: 800; background: var(--bg-soft); color: var(--ink-2);
  border: 1px solid var(--line);
}
.badge.gold { background: var(--gold-soft); color: var(--gold); border-color: transparent; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }

.note {
  border-radius: var(--r); padding: 12px 14px; font-size: .84rem;
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: space-between;
  background: var(--info-soft); color: var(--info); border: 1px solid color-mix(in srgb, var(--info) 18%, transparent);
}
.note > span { flex: 1 1 220px; }
.note.warn { background: var(--gold-soft); color: var(--gold); border-color: color-mix(in srgb, var(--gold) 25%, transparent); }

/* ---------- compare ---------- */
.cmp-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
table.cmp { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .86rem; min-width: 520px; }
table.cmp th, table.cmp td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); text-align: start; vertical-align: top; }
table.cmp thead th { background: var(--surface-2); position: sticky; top: 0; }
table.cmp th.rowhead, table.cmp td.rowhead {
  position: sticky; inset-inline-start: 0; background: var(--surface); font-weight: 800; color: var(--ink-2);
  min-width: 104px; z-index: 1; border-inline-end: 1px solid var(--line);
}
table.cmp thead th.rowhead { background: var(--surface-2); z-index: 2; }
table.cmp tr:last-child td, table.cmp tr:last-child th { border-bottom: 0; }
.cmp-col-head { display: grid; gap: 2px; }
.cmp-col-head .nm { font-weight: 800; }
.del { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: .74rem; padding: 4px 6px; border-radius: 8px; font-family: inherit; }
.del:hover { color: var(--bad); background: var(--bad-soft); }
.cmp-col-head .del { padding: 0; text-align: start; }
.best { color: var(--ok); font-weight: 900; }
.cell-ok { background: color-mix(in srgb, var(--ok-soft) 60%, transparent); }

.item-card { border: 1px solid var(--line); border-radius: var(--r); padding: 12px; background: var(--surface); display: grid; gap: 8px; }
.item-card .top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.item-card .nm { font-weight: 800; }
.offer-line { display: flex; justify-content: space-between; font-size: .84rem; color: var(--ink-2); gap: 8px; }
.offer-line .pr { font-variant-numeric: tabular-nums; font-weight: 800; }
.stores { display: flex; gap: 6px; flex-wrap: wrap; }
.store-link {
  font-size: .76rem; font-weight: 700; border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 10px; color: var(--ink-2); background: var(--surface);
}
.store-link:hover { border-color: var(--gold); color: var(--gold); text-decoration: none; }

/* ---------- misc ---------- */
.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.empty .ico { font-size: 1.6rem; }
.toast {
  position: fixed; inset-inline: 16px; bottom: calc(var(--tab-h) + 14px); z-index: 80;
  background: var(--ink); color: var(--bg); border-radius: 12px; padding: 12px 16px;
  font-size: .88rem; font-weight: 700; box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(8px);
  transition: opacity .18s, transform .18s; pointer-events: none; max-width: 420px; margin-inline: auto;
}
.toast.on { opacity: 1; transform: none; }
@media (min-width: 860px) { .toast { bottom: 20px; } }

.sheet-back {
  position: fixed; inset: 0; background: rgba(10, 12, 16, .5); z-index: 70;
  display: none; align-items: flex-end; justify-content: center; padding: 0;
}
.sheet-back.on { display: flex; }
.sheet {
  background: var(--surface); border-radius: 20px 20px 0 0; width: 100%; max-width: 560px;
  max-height: 88vh; overflow-y: auto; padding: 16px; border: 1px solid var(--line);
}
@media (min-width: 620px) {
  .sheet-back { align-items: center; padding: 24px; }
  .sheet { border-radius: 20px; }
}
.sheet h3 { margin-bottom: 10px; }
.sheet .close { float: inline-end; }

.footer { border-top: 1px solid var(--line); margin-top: 28px; padding: 18px 0 8px; color: var(--muted); font-size: .8rem; }
.footer a { color: var(--ink-2); }
.src-list { display: grid; gap: 6px; font-size: .82rem; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin: 22px 0 10px; }
.section-head h2 { margin: 0; }
.section-head a { font-size: .82rem; font-weight: 800; }

.kpi { display: grid; gap: 2px; }
.kpi .v { font-size: 1.15rem; font-weight: 900; }
.kpi .l { font-size: .74rem; color: var(--muted); font-weight: 700; }

.range { display: flex; gap: 10px; align-items: center; }
.range input[type="range"] { flex: 1; accent-color: var(--gold); }

/* أرقام ورموز لاتينية جوه نص عربي */
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.offer-line .pr, .kv b, .result .big { direction: ltr; unicode-bidi: isolate; }
