/* The Raqeeb Mini App: the logo's green and gold, a light and a dark palette,
   one spacing scale (4 / 8 / 12 / 16 / 20 / 24) and one radius scale. */

:root {
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px;
  --r-sm: 10px; --r-md: 14px; --r-lg: 20px;
  --green-900: #0d4f33;
  --green-700: #17694a;
  --gold: #c9a24f;
  --gold-light: #e6c67f;
  --up: #16a05a;
  --down: #d64545;
  --font: system-ui, -apple-system, "Segoe UI", Tahoma, "Noto Naskh Arabic", sans-serif;
}

/* Light (the default) */
:root, [data-theme="light"] {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #f0f3f1;
  --text: #15201a;
  --text-2: #4a5a51;
  --hint: #7a8a81;
  --line: rgba(21, 32, 26, 0.08);
  --accent: #17694a;
  --accent-soft: rgba(23, 105, 74, 0.10);
  --gold-soft: rgba(201, 162, 79, 0.16);
  --shadow: 0 1px 2px rgba(16, 24, 20, 0.05), 0 6px 18px rgba(16, 24, 20, 0.06);
  --hero-1: #0d4f33;
  --hero-2: #17694a;
  --input: #ffffff;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0c1210;
  --surface: #151d19;
  --surface-2: #1b2520;
  --text: #e9f0ec;
  --text-2: #b9c7bf;
  --hint: #8a9a91;
  --line: rgba(233, 240, 236, 0.08);
  --accent: #3fb07c;
  --accent-soft: rgba(63, 176, 124, 0.14);
  --gold-soft: rgba(230, 198, 127, 0.14);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.25);
  --hero-1: #0b3d28;
  --hero-2: #145a3e;
  --input: #111815;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.2s ease, color 0.2s ease;
}
svg.icon { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
svg.icon.sm { width: 18px; height: 18px; }
[dir="rtl"] svg.flip { transform: scaleX(-1); }

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4);
  background: linear-gradient(135deg, var(--hero-1), var(--hero-2));
  color: #fff;
}
.topbar-logo { width: 38px; height: 38px; border-radius: 11px; background: #fff; padding: 3px; }
.topbar-text { flex: 1; min-width: 0; }
.brand { font-weight: 800; font-size: 17px; line-height: 1.2; }
.brand .en { color: var(--gold-light); font-weight: 700; font-size: 13px; margin-inline-start: 6px; }
.subtitle { font-size: 12px; opacity: 0.8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  border: 0; background: rgba(255, 255, 255, 0.14); color: #fff; width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center; cursor: pointer;
}

main { padding: var(--s4) var(--s4) var(--s2); max-width: 720px; margin: 0 auto; }
.splash { display: grid; place-items: center; min-height: 60vh; }
.splash img { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

/* ---- bottom tabs ---- */
.tabbar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--s1);
  padding: var(--s2) var(--s2) calc(var(--s2) + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.04);
}
.tabbar button {
  border: 0; background: none; color: var(--hint); font: inherit; border-radius: var(--r-md);
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; cursor: pointer;
}
.tabbar .lbl { font-size: 11px; }
.tabbar button.on { color: var(--accent); background: var(--accent-soft); font-weight: 700; }

/* ---- page structure ---- */
.page { display: flex; flex-direction: column; gap: var(--s4); }
.page-title { font-size: 20px; font-weight: 800; margin: 0; }
.section { display: flex; flex-direction: column; gap: var(--s2); }
.section-head { display: flex; justify-content: space-between; align-items: center; padding: 0 var(--s1); }
.section-head h2 { font-size: 15px; font-weight: 800; margin: 0; color: var(--text-2); }
.link-btn { border: 0; background: none; color: var(--accent); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; padding: 0; }

.card {
  background: var(--surface); border-radius: var(--r-lg); padding: var(--s4); box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.card.flush { padding: var(--s1) var(--s4); }
.card.hero {
  background: linear-gradient(140deg, var(--hero-1), var(--hero-2)); color: #fff; border: 0;
  position: relative; overflow: hidden; cursor: pointer;
}
.card.hero::after {
  content: ""; position: absolute; inset-inline-end: -50px; top: -60px; width: 180px; height: 180px; border-radius: 50%;
  background: radial-gradient(circle, rgba(230, 198, 127, 0.35), transparent 70%); pointer-events: none;
}
.hero .eyebrow { font-size: 13px; opacity: 0.85; }
.hero .big { font-size: 32px; font-weight: 800; color: var(--gold-light); line-height: 1.15; margin: var(--s1) 0; font-variant-numeric: tabular-nums; }
.hero .sub { font-size: 13px; opacity: 0.85; display: flex; flex-wrap: wrap; gap: var(--s1) var(--s3); }
.hero .chip { background: rgba(255, 255, 255, 0.16); color: #fff; }
.hero .chip.up { color: #9ff0c4; }
.hero .chip.down { color: #ffb4b4; }
.hero .more { margin-top: var(--s3); font-size: 13px; color: var(--gold-light); display: flex; align-items: center; gap: var(--s1); }

.muted, .hint { color: var(--hint); font-size: 13px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); padding: var(--s3) 0; min-height: 52px; }
.row + .row { border-top: 1px solid var(--line); }
.row .lead { display: flex; align-items: center; gap: var(--s3); min-width: 0; flex: 1; }
.row .label { min-width: 0; }
.row .label .sub { color: var(--hint); font-size: 12px; }
.row .value { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; display: flex; align-items: center; gap: var(--s2); }
.row.tap { cursor: pointer; }
.badge-k {
  width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; flex: 0 0 auto;
  background: var(--gold-soft); color: var(--gold); font-weight: 800; font-size: 13px;
}
.badge-k.green { background: var(--accent-soft); color: var(--accent); }
.chip {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: var(--surface-2); color: var(--hint); white-space: nowrap;
}
.chip.up { color: var(--up); background: rgba(22, 160, 90, 0.12); }
.chip.down { color: var(--down); background: rgba(214, 69, 69, 0.12); }
.warn { color: var(--down); font-size: 12px; margin-inline-start: var(--s1); }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s3); }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s3) var(--s4);
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 2px; cursor: pointer; text-align: start;
  font: inherit; color: var(--text);
}
.stat .k { color: var(--hint); font-size: 12px; display: flex; align-items: center; gap: var(--s1); }
.stat .v { font-weight: 800; font-size: 16px; font-variant-numeric: tabular-nums; }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s3); }
.grid.two { grid-template-columns: repeat(2, 1fr); }
.tile {
  border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
  padding: var(--s4) var(--s2); display: flex; flex-direction: column; align-items: center; gap: var(--s2); box-shadow: var(--shadow);
  text-align: center; font-size: 13px; font-weight: 600; min-height: 92px; justify-content: center;
}
.tile .ic { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.tile .ic.gold { background: var(--gold-soft); color: var(--gold); }
.tile:active, .btn:active, .stat:active, .row.tap:active { transform: scale(0.985); }

.btn {
  border: 0; border-radius: var(--r-md); padding: 13px var(--s4); font: inherit; font-weight: 700; cursor: pointer; width: 100%;
  background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
}
.btn.gold { background: linear-gradient(135deg, var(--gold), var(--gold-light)); color: #23190a; }
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn.danger { background: rgba(214, 69, 69, 0.12); color: var(--down); }
.btn.small { width: auto; padding: 7px 12px; font-size: 13px; border-radius: var(--r-sm); }
.btn[disabled] { opacity: 0.5; cursor: default; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }

.seg { display: flex; flex-wrap: wrap; gap: var(--s2); }
.seg button {
  border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 999px;
  padding: 7px 14px; font: inherit; font-size: 13px; cursor: pointer;
}
.seg button.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }

.form { display: flex; flex-direction: column; gap: var(--s3); }
.form-row { display: flex; flex-direction: column; gap: 6px; }
.form-row > label { font-size: 13px; color: var(--text-2); font-weight: 600; }
input, select, textarea {
  width: 100%; padding: 12px 14px; border-radius: var(--r-md); border: 1px solid var(--line);
  background: var(--input); color: var(--text); font: inherit; min-height: 46px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 1px; border-color: transparent; }
textarea { min-height: 120px; resize: vertical; }
.check { display: flex; gap: var(--s2); align-items: flex-start; font-size: 14px; color: var(--text-2); }
.check input { width: 18px; min-height: 18px; margin-top: 3px; accent-color: var(--accent); }

.rich { white-space: pre-wrap; word-break: break-word; line-height: 1.7; }
.rich a { color: var(--accent); }
.rich code { background: var(--surface-2); padding: 0 5px; border-radius: 6px; }
.chart-box { position: relative; height: 260px; }
.spark { position: relative; height: 64px; margin-top: var(--s3); }
.icon-del { border: 0; background: none; color: var(--hint); cursor: pointer; padding: 6px; border-radius: var(--r-sm); display: grid; place-items: center; }
.icon-del:hover { color: var(--down); background: rgba(214, 69, 69, 0.08); }
.link-box { direction: ltr; text-align: start; font-size: 13px; background: var(--surface-2); border-radius: var(--r-sm); padding: var(--s3); word-break: break-all; }
.progress { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--gold-light)); border-radius: 999px; }

.toggle { display: flex; justify-content: space-between; align-items: center; padding: var(--s3) 0; gap: var(--s3); }
.toggle + .toggle { border-top: 1px solid var(--line); }
.switch { position: relative; width: 48px; height: 28px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; min-height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); transition: 0.2s; }
.switch span::before {
  content: ""; position: absolute; width: 22px; height: 22px; top: 2px; inset-inline-start: 2px;
  background: #fff; border-radius: 50%; transition: 0.2s; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::before { transform: translateX(20px); }
[dir="rtl"] .switch input:checked + span::before { transform: translateX(-20px); }

.toast {
  position: fixed; inset-inline: var(--s4); bottom: calc(88px + env(safe-area-inset-bottom)); z-index: 9;
  background: #15201a; color: #fff; padding: var(--s3) var(--s4); border-radius: var(--r-md); font-size: 14px; text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}
[data-theme="dark"] .toast { background: #e9f0ec; color: #15201a; }
.empty { text-align: center; color: var(--hint); padding: var(--s6) 0; }
.foot { text-align: center; color: var(--hint); font-size: 12px; padding: var(--s2) 0 var(--s4); }
.foot img { width: 72px; height: 72px; display: block; margin: 0 auto var(--s1); }

/* [hidden] must win over the flex and grid rules above */
[hidden] { display: none !important; }
.page p { margin: 0; }
.page .rich p { margin: revert; }
.stats > :last-child:nth-child(odd) { grid-column: 1 / -1; }
