/*
 * لوحة مشوار — نمطٌ واحد بلا اعتماديّات.
 *
 * القاعدة: كل شيء يعمل على هاتف بعرض 360px أوّلًا، ثم يتّسع. الجداول وحدها
 * تُمرَّر أفقيًّا داخل صندوقها؛ الصفحة نفسها لا تُمرَّر أفقيًّا أبدًا.
 */

:root {
  color-scheme: dark light;

  --bg: #0b1220;
  --panel: #121b2d;
  --panel-2: #16223a;
  --line: #24334f;
  --ink: #e8eefc;
  --ink-2: #9fb0d0;
  --brand: #2dd4bf;
  --brand-ink: #032420;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.25);
  --r: 14px;

  /* ألوان أنواع المساهمة — ثابتة عبر الرسم والأسطورة والتدفّق */
  --k-installs: #64748b;
  --k-traces: #2dd4bf;
  --k-suggestions: #a78bfa;
  --k-votes: #60a5fa;
  --k-fares: #fbbf24;
  --k-comments: #f472b6;
  --k-comment_votes: #4ade80;
}

html[data-theme='light'] {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --panel-2: #f7f9ff;
  --line: #dbe3f0;
  --ink: #16203a;
  --ink-2: #5b6b8a;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --shadow: 0 1px 2px rgb(16 32 64 / 0.06), 0 8px 24px rgb(16 32 64 / 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0 max(12px, env(safe-area-inset-right)) 64px max(12px, env(safe-area-inset-left));
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.65 'Segoe UI', 'Noto Naskh Arabic', 'Tahoma', system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

h1 {
  font-size: 1.25rem;
  margin: 0;
}
h2 {
  font-size: 1.1rem;
  margin: 0 0 4px;
  letter-spacing: 0.2px;
}
h3 {
  font-size: 1rem;
  margin: 0 0 8px;
}
a {
  color: var(--brand);
}
code {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 4px;
  font-size: 0.85em;
  direction: ltr;
  display: inline-block;
}

.muted {
  color: var(--ink-2);
  font-size: 0.85rem;
}
.lede {
  color: var(--ink-2);
  font-size: 0.9rem;
  margin: 0 0 12px;
  max-width: 68ch;
}

/* ------------------------------------------------------------------ الترويسة */

.top {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
  margin-bottom: 12px;
}

.top-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.top-row.wrap {
  flex-wrap: wrap;
  margin-top: 8px;
}

.env-badge {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink-2);
  white-space: nowrap;
}
.env-badge[data-danger='true'] {
  background: color-mix(in srgb, var(--bad) 20%, transparent);
  border-color: var(--bad);
  color: var(--bad);
}
.env-badge[data-danger='false'] {
  background: color-mix(in srgb, var(--ok) 18%, transparent);
  border-color: var(--ok);
  color: var(--ok);
}

.gate {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-top: 10px;
}
.gate[data-open='false'] {
  display: none;
}
.gate-actions {
  display: flex;
  gap: 8px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.8rem;
  color: var(--ink-2);
  min-width: 0;
}
.field.grow {
  flex: 1 1 220px;
}
.field input,
.field select {
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  min-width: 0;
  width: 100%;
}
.field input:focus-visible,
.field select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--ink-2);
  white-space: nowrap;
}

button {
  font: inherit;
  font-size: 0.9rem;
  border-radius: 10px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  cursor: pointer;
  min-height: 38px;
}
button:hover {
  border-color: var(--brand);
}
button:disabled {
  opacity: 0.5;
  cursor: default;
}
button.primary {
  background: var(--brand);
  color: var(--brand-ink);
  border-color: transparent;
  font-weight: 700;
}
button.ghost {
  background: transparent;
}
button.tiny {
  font-size: 0.8rem;
  padding: 4px 10px;
  min-height: 30px;
}
button.danger {
  border-color: var(--bad);
  color: var(--bad);
}

.banner {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--bad);
  background: color-mix(in srgb, var(--bad) 14%, transparent);
  font-size: 0.9rem;
}
.banner[data-kind='info'] {
  border-color: var(--brand);
  background: color-mix(in srgb, var(--brand) 14%, transparent);
}

/* --------------------------------------------------------------------- تبويب */

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 12px;
  scrollbar-width: thin;
}
.tabs button {
  white-space: nowrap;
  border-radius: 999px;
  padding: 6px 14px;
  min-height: 34px;
}
.tabs button[aria-current='true'] {
  background: var(--brand);
  color: var(--brand-ink);
  border-color: transparent;
  font-weight: 700;
}

/* -------------------------------------------------------------------- ألواح */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px;
  margin: 0 0 14px;
  box-shadow: var(--shadow);
}
.panel[hidden] {
  display: none;
}

.row {
  display: flex;
  gap: 10px;
  align-items: center;
}
.row.wrap {
  flex-wrap: wrap;
}

.split {
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr;
  margin-top: 14px;
}
@media (min-width: 720px) {
  .split {
    grid-template-columns: 1fr 1fr;
  }
}

/* ------------------------------------------------------------- بطاقات الأرقام */

.cards {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}

.card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  border-inline-start: 3px solid var(--accent, var(--line));
}
.card .k {
  font-size: 0.82rem;
  color: var(--ink-2);
  display: block;
}
.card .v {
  font-size: 1.7rem;
  font-weight: 800;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.card .sub {
  font-size: 0.78rem;
  color: var(--ink-2);
}
.card .delta {
  font-size: 0.78rem;
  color: var(--ok);
}
.card .delta[data-zero='true'] {
  color: var(--ink-2);
}

/* -------------------------------------------------------------------- القمع */

.funnel {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.funnel .bar {
  position: relative;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  padding: 8px 12px;
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.funnel .fill {
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  background: color-mix(in srgb, var(--brand) 26%, transparent);
}
.funnel .bar > span {
  position: relative;
}
.funnel .n {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.note {
  margin-top: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.88rem;
}
.note summary {
  cursor: pointer;
  color: var(--ink-2);
}
.note ul {
  margin: 8px 0 0;
  padding-inline-start: 18px;
}
.note li {
  margin-bottom: 6px;
}

/* -------------------------------------------------------------------- الرسم */

.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.seg button {
  border: 0;
  border-radius: 0;
  background: transparent;
  min-height: 32px;
  padding: 4px 12px;
  font-size: 0.85rem;
}
.seg button[aria-pressed='true'] {
  background: var(--brand);
  color: var(--brand-ink);
  font-weight: 700;
}

#chart svg {
  width: 100%;
  height: auto;
  display: block;
  margin-top: 10px;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--ink-2);
}
.legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-inline-end: 4px;
}

/* -------------------------------------------------------------------- التدفّق */

.feed {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 60vh;
  overflow-y: auto;
}
.feed li {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}
.feed li:last-child {
  border-bottom: 0;
}
.tag {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent, var(--line)) 25%, transparent);
  color: var(--accent, var(--ink-2));
  white-space: nowrap;
  flex: 0 0 auto;
}
.feed .what {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}
.feed .when {
  flex: 0 0 auto;
  color: var(--ink-2);
  font-size: 0.78rem;
  white-space: nowrap;
}

/* ------------------------------------------------------------------ البيانات */

.sets {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  margin: 12px 0;
}
.set {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
.set h3 {
  margin: 0;
  font-size: 0.95rem;
}
.set .desc {
  font-size: 0.8rem;
  color: var(--ink-2);
  margin: 2px 0 8px;
}
.set .acts {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.set[data-available='false'] {
  opacity: 0.55;
}

.progress {
  height: 4px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
}
.progress i {
  display: block;
  height: 100%;
  background: var(--brand);
  width: 0;
  transition: width 0.2s;
}

/* ------------------------------------------------------------------- جداول */

.scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-top: 10px;
}
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.84rem;
  white-space: nowrap;
}
th,
td {
  text-align: start;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
}
th {
  position: sticky;
  top: 0;
  background: var(--panel-2);
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--ink-2);
}
tbody tr:last-child td {
  border-bottom: 0;
}
td.num {
  font-variant-numeric: tabular-nums;
}
td.wrap {
  white-space: normal;
  min-width: 220px;
  overflow-wrap: anywhere;
}
.mono {
  font-family: ui-monospace, 'Consolas', monospace;
  direction: ltr;
  unicode-bidi: isolate;
  font-size: 0.8rem;
}
/*
 * سطرٌ خامّ من الخادم (حالة الموجّه مثلًا): كلمةٌ واحدة طويلة لا فراغ فيها،
 * فتمدّ الصفحة كلّها أفقيًّا على الهاتف ما لم يُسمح بالكسر في أي موضع.
 */
.raw {
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  text-align: left;
}

/* --------------------------------------------------------------- المراجعة */

.item {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
}
.item .head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
  justify-content: space-between;
}
.item .title {
  font-weight: 700;
}
.item .meta {
  font-size: 0.8rem;
  color: var(--ink-2);
}
.item .body {
  margin: 8px 0;
  overflow-wrap: anywhere;
}
.item .acts {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
/*
 * الشارة وحدةٌ واحدة: إن انكسر نصّها على سطرين ظهرت شارتين نصفَيْن على الهاتف،
 * فتُقرأ «أقلّ» و«إصدار تطبيق: ١» بندَين لا بندًا. تُمنَع من الكسر داخلها،
 * ويبقى الكسر بين الشارات — والطويلة منها تُقصّ بنقاطٍ بدل أن تمدّ الصفحة.
 */
.pill {
  display: inline-block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--ink-2);
}
.pill[data-tone='warn'] {
  border-color: var(--warn);
  color: var(--warn);
}
.pill[data-tone='bad'] {
  border-color: var(--bad);
  color: var(--bad);
}
.pill[data-tone='ok'] {
  border-color: var(--ok);
  color: var(--ok);
}

.empty {
  color: var(--ink-2);
  font-size: 0.9rem;
  padding: 10px 0;
}

/* ------------------------------------------------------------------ الحوار */

dialog {
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--panel);
  color: var(--ink);
  padding: 18px;
  max-width: min(520px, 92vw);
  box-shadow: var(--shadow);
}
dialog::backdrop {
  background: rgb(0 0 0 / 0.55);
}
dialog menu {
  display: flex;
  gap: 8px;
  justify-content: flex-start;
  margin: 16px 0 0;
  padding: 0;
}
.confirm-env {
  font-weight: 700;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  margin: 0 0 10px;
}
.confirm-env[data-danger='true'] {
  border-color: var(--bad);
  color: var(--bad);
  background: color-mix(in srgb, var(--bad) 12%, transparent);
}

.toast {
  position: fixed;
  inset-block-end: 16px;
  inset-inline: 16px;
  margin: auto;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--brand);
  border-radius: 12px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  z-index: 40;
  font-size: 0.9rem;
}
.toast[data-kind='bad'] {
  border-color: var(--bad);
}

.foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  justify-content: space-between;
  padding: 14px 2px;
  font-size: 0.8rem;
  color: var(--ink-2);
  border-top: 1px solid var(--line);
}

.skel {
  color: var(--ink-2);
  font-size: 0.9rem;
  padding: 8px 0;
}
