:root {
  --ink: #0d3b2e;
  --ink-2: #155a45;
  --paper: #f6f1e6;
  --card: #fffdf8;
  --line: #e3dccb;
  --text: #1b2a24;
  --mut: #6c7a71;
  --gold: #b8892d;
  --gold-soft: #f3e6c6;
  --buy: #1f5fa8;
  --sell: #b0521a;
  --up: #12784f;
  --dn: #b3261e;
  --r: 14px;
  --shadow: 0 1px 0 rgba(13, 59, 46, 0.04), 0 8px 24px -12px rgba(13, 59, 46, 0.18);
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(circle at 12% -10%, rgba(184, 137, 45, 0.12), transparent 40%),
    repeating-linear-gradient(135deg, rgba(13, 59, 46, 0.025) 0 2px, transparent 2px 9px),
    var(--paper);
  color: var(--text);
  font: 15px/1.5 "IBM Plex Sans Arabic", Tahoma, system-ui, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, .display { font-family: "Reem Kufi", "IBM Plex Sans Arabic", serif; font-weight: 700; margin: 0; }
h2 { font-size: 17px; margin-bottom: 12px; color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
.num, td, .stat b, input[type="number"] { font-variant-numeric: tabular-nums; }

/* Layout */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side {
  background: linear-gradient(180deg, var(--ink) 0%, #0a2f25 100%);
  color: #f6f1e6;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img, .brand .mark {
  width: 44px; height: 44px; border-radius: 12px; object-fit: contain; background: #fffdf8;
  display: grid; place-items: center; color: var(--ink); font: 700 20px "Reem Kufi", serif;
  border: 2px solid var(--gold);
}
.brand b { display: block; font: 700 17px/1.2 "Reem Kufi", serif; }
.brand small { color: #b9c9c0; font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav button {
  display: flex; align-items: center; gap: 10px; padding: 11px 12px; border: 0; border-radius: 10px;
  background: transparent; color: #d6e2db; cursor: pointer; text-align: start; font-weight: 500;
  transition: background 0.15s, color 0.15s, transform 0.15s;
}
.nav button:hover { background: rgba(255, 255, 255, 0.06); }
.nav button.on { background: var(--gold-soft); color: var(--ink); font-weight: 700; }
.nav .ic { width: 22px; text-align: center; font-size: 16px; }
.side .foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.who { padding: 10px 12px; border-radius: 10px; background: rgba(255, 255, 255, 0.06); }
.who b { display: block; }
.who span { color: #b9c9c0; font-size: 12px; }
.side .btns { display: flex; gap: 6px; }
.side .btns button {
  flex: 1; padding: 8px; border-radius: 9px; border: 1px solid rgba(255, 255, 255, 0.18);
  background: transparent; color: #f6f1e6; cursor: pointer; font-size: 13px;
}
.side .btns button:hover { background: rgba(255, 255, 255, 0.08); }
.powered { font-size: 11px; letter-spacing: 0.04em; color: #9fb4a9; direction: ltr; text-align: center; }
.powered b { color: var(--gold); }

main { padding: 26px clamp(14px, 3vw, 36px) 90px; max-width: 1100px; width: 100%; }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 26px; color: var(--ink); }
.page-head p { margin: 2px 0 0; color: var(--mut); font-size: 13px; }
.mfoot { display: none; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side {
    position: fixed; bottom: 0; top: auto; height: auto; inset-inline: 0; z-index: 20;
    flex-direction: row; padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    border-top: 2px solid var(--gold);
  }
  .side .brand, .side .foot { display: none; }
  .nav { flex-direction: row; width: 100%; overflow-x: auto; }
  .nav button { flex: 1 0 auto; flex-direction: column; gap: 2px; padding: 6px 8px; font-size: 11px; min-width: 62px; }
  .nav .ic { font-size: 18px; }
  .mtop { display: flex !important; }
  .mfoot { display: block; margin-top: 22px; }
  .mfoot .powered { color: var(--mut); }
}
.mtop {
  display: none; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px;
  background: var(--ink); color: #f6f1e6; position: sticky; top: 0; z-index: 10;
}
.mtop .brand img, .mtop .brand .mark { width: 34px; height: 34px; font-size: 16px; }
.mtop .btns { display: flex; gap: 6px; }
.mtop .btns button { padding: 6px 10px; border-radius: 8px; border: 1px solid rgba(255,255,255,.2); background: transparent; color: inherit; font-size: 12px; cursor: pointer; }

/* Cards & forms */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 18px;
  box-shadow: var(--shadow); margin-bottom: 16px; animation: rise 0.35s ease both;
}
.grid2 { display: grid; grid-template-columns: 1.15fr 0.85fr; gap: 16px; align-items: start; }
@media (max-width: 980px) { .grid2 { grid-template-columns: 1fr; } }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.row.three { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 520px) { .row, .row.three { grid-template-columns: 1fr; } }
label { display: block; font-size: 12.5px; color: var(--mut); margin-bottom: 4px; font-weight: 500; }
input, select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink-2); box-shadow: 0 0 0 3px rgba(21, 90, 69, 0.15); }
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.field { margin-bottom: 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 18px;
  border-radius: 11px; border: 0; background: var(--ink); color: #fffdf8; font-weight: 700; cursor: pointer;
  transition: transform 0.12s, background 0.15s, opacity 0.15s;
}
.btn:hover { background: var(--ink-2); }
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--gold-soft); }
.btn.gold { background: var(--gold); color: #1b1408; }
.btn.danger { background: var(--dn); }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.seg button {
  padding: 13px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff; cursor: pointer;
  font-weight: 700; font-size: 15px; transition: all 0.15s;
}
.seg button.on.sell { background: var(--sell); border-color: var(--sell); color: #fff; }
.seg button.on.buy { background: var(--buy); border-color: var(--buy); color: #fff; }
.chips { display: flex; gap: 8px; margin-bottom: 12px; }
.chips button {
  flex: 1; padding: 12px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; font-size: 15px;
}
.chips button .sym { font: 700 18px "Reem Kufi", serif; color: var(--gold); }
.chips button.on { border-color: var(--ink); background: var(--ink); color: #fff; }
.chips button.on .sym { color: var(--gold-soft); }

.total {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 16px;
  border-radius: 12px; background: var(--gold-soft); border: 1px dashed var(--gold); margin: 6px 0 14px;
}
.total span { color: #6b5017; font-size: 13px; }
.total b { font: 700 22px "Reem Kufi", serif; color: var(--ink); direction: ltr; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
@media (max-width: 760px) { .stats { grid-template-columns: 1fr 1fr; } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; box-shadow: var(--shadow); animation: rise 0.35s ease both; }
.stat:nth-child(2) { animation-delay: 0.04s; } .stat:nth-child(3) { animation-delay: 0.08s; } .stat:nth-child(4) { animation-delay: 0.12s; }
.stat span { font-size: 12.5px; color: var(--mut); }
.stat b { display: block; font-size: 20px; margin-top: 4px; direction: ltr; text-align: start; }
[dir="rtl"] .stat b { text-align: end; }
.stat.hero { background: linear-gradient(135deg, var(--ink), #0a2f25); color: #fffdf8; border-color: var(--ink); }
.stat.hero span { color: #b9c9c0; }
.stat.hero b { font: 700 26px "Reem Kufi", serif; }
.up { color: var(--up); } .dn { color: var(--dn); }
.stat.hero .up { color: #7ee0b4; } .stat.hero .dn { color: #ffaaa3; }

/* Tables */
.wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 10px 8px; text-align: start; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-weight: 600; color: var(--mut); font-size: 12px; background: #faf6ec; }
tbody tr:hover { background: #fbf8f0; }
td.n { direction: ltr; text-align: end; }
[dir="ltr"] td.n { text-align: end; }
.tag { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; color: #fff; }
.tag.buy { background: var(--buy); } .tag.sell { background: var(--sell); }
.tag.mgr { background: var(--gold); color: #1b1408; } .tag.st { background: #d9e4de; color: var(--ink); } .tag.off { background: #e8e1d2; color: var(--mut); }
.icon-btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 5px 9px; cursor: pointer; font-size: 13px; }
.icon-btn:hover { background: var(--gold-soft); }
.icon-btn.del { color: var(--dn); }
.acts { display: flex; gap: 4px; }
.empty { padding: 26px 10px; text-align: center; color: var(--mut); font-size: 14px; }
.empty .glyph { font: 700 34px "Reem Kufi", serif; color: var(--line); display: block; margin-bottom: 4px; }
.edited { font-size: 11px; color: var(--gold); }

.ctl { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
.ctl > * { flex: 1 1 140px; width: auto; }
.tabs { display: inline-flex; background: #ece5d4; border-radius: 11px; padding: 3px; flex: 0 0 auto !important; }
.tabs button { border: 0; background: transparent; padding: 8px 16px; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--mut); }
.tabs button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); }
.period { color: var(--mut); font-size: 13px; margin: -6px 0 14px; direction: ltr; text-align: start; }
[dir="rtl"] .period { text-align: end; }

.msg { font-size: 13.5px; padding: 10px 12px; border-radius: 10px; margin-top: 10px; }
.msg.err { background: #fbe9e7; color: var(--dn); }
.msg.ok { background: #e3f3ea; color: var(--up); }
.msg.warn { background: #fff3df; color: #8a5a00; }
.hint { color: var(--mut); font-size: 12.5px; margin: 10px 0 0; }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: min(420px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 28px; box-shadow: 0 30px 60px -30px rgba(13, 59, 46, 0.35); position: relative; overflow: hidden; animation: rise 0.4s ease both; }
.auth-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 6px; background: linear-gradient(90deg, var(--ink), var(--gold), var(--ink)); }
.auth-card .brand { justify-content: center; flex-direction: column; text-align: center; margin-bottom: 18px; }
.auth-card .brand img, .auth-card .brand .mark { width: 70px; height: 70px; font-size: 30px; border-radius: 18px; }
.auth-card .brand b { font-size: 22px; color: var(--ink); }
.auth-card .brand small { color: var(--mut); }
.auth-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; }
.auth-foot .powered { color: var(--mut); }
.linkbtn { border: 0; background: none; color: var(--ink-2); cursor: pointer; font-weight: 600; padding: 4px; }

/* Dialog */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(520px, calc(100% - 24px)); max-height: calc(100vh - 40px); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35); background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(10, 30, 24, 0.55); backdrop-filter: blur(2px); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.dlg-body { padding: 18px; overflow: auto; }
.dlg-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.rcpt-frame { width: 100%; height: 520px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }

#toast { position: fixed; bottom: 90px; inset-inline: 0; margin: auto; width: fit-content; max-width: 90vw; padding: 11px 18px; border-radius: 12px; background: var(--ink); color: #fff; font-weight: 600; opacity: 0; transform: translateY(10px); pointer-events: none; transition: all 0.25s; z-index: 50; }
#toast.show { opacity: 1; transform: none; }

.logo-prev { width: 96px; height: 96px; border-radius: 14px; border: 1px dashed var(--line); display: grid; place-items: center; background: #fff; overflow: hidden; color: var(--mut); font-size: 12px; }
.logo-prev img { width: 100%; height: 100%; object-fit: contain; }
.logo-row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); }
.check input { width: auto; }

.boot { max-width: 520px; margin: 80px auto; padding: 20px; }
.skel { height: 64px; border-radius: 14px; margin-bottom: 12px; background: linear-gradient(90deg, #ece5d4 0%, #f6f1e6 50%, #ece5d4 100%); background-size: 200% 100%; animation: sh 1.2s linear infinite; }
.skel.short { width: 60%; }
@keyframes sh { to { background-position: -200% 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
