/* حاسبات — التصميم العام (RTL، أولوية للجوال) */
:root {
  --bg: #f6f8f7;
  --surface: #ffffff;
  --surface-2: #eef4f2;
  --text: #13221f;
  --muted: #5b6b67;
  --border: #dde6e3;
  --brand: #0f766e;
  --brand-dark: #0b5a54;
  --brand-soft: #d9f0ec;
  --accent: #d99a1e;
  --wa: #25d366;
  --wa-dark: #1da851;
  --radius: 16px;
  --shadow: 0 4px 18px rgba(16, 40, 36, 0.08);
  --font: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1513;
    --surface: #16201d;
    --surface-2: #1c2926;
    --text: #e8f0ee;
    --muted: #9db0ab;
    --border: #2a3a36;
    --brand: #2bb3a5;
    --brand-dark: #1f9488;
    --brand-soft: #173a35;
    --shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  font-size: 17px;
}

a { color: var(--brand); }

img { max-width: 100%; height: auto; }

.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px; }

/* الهيدر */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 58px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 22px;
  color: var(--text);
  text-decoration: none;
}
.logo-mark {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 18px;
}
.nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 15px;
  margin-inline-start: 14px;
}
.nav a:hover { color: var(--brand); }

/* مسار التنقل */
.crumbs { font-size: 14px; color: var(--muted); margin: 14px 0 0; }
.crumbs a { color: var(--muted); text-decoration: none; }

h1 { font-size: 28px; line-height: 1.35; margin: 12px 0 6px; }
h2 { font-size: 21px; margin: 28px 0 8px; }
h3 { font-size: 18px; margin: 18px 0 6px; }
.lead { color: var(--muted); margin: 0 0 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

/* حقل الإدخال */
.field label { display: block; font-weight: 600; margin-bottom: 6px; }
.input {
  width: 100%;
  font: inherit;
  font-size: 20px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.input:focus { border-color: var(--brand); background: var(--surface); }

/* أزرار */
.btn {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: 12px;
  padding: 10px 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-wa {
  background: var(--wa);
  color: #fff;
  font-size: 19px;
  padding: 16px 20px;
  width: 100%;
  border-radius: 14px;
}
.btn-wa:hover { background: var(--wa-dark); }
.btn-wa svg { width: 26px; height: 26px; }

/* فلاتر */
.tabs { display: flex; gap: 8px; margin: 16px 0 4px; flex-wrap: wrap; }
.tab {
  font: inherit;
  font-size: 15px;
  padding: 6px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
.tab[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }

/* نتائج الزخرفة */
.results { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 10px; }
.result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.result-text {
  flex: 1;
  min-width: 0;
  font-size: 22px;
  overflow-wrap: anywhere;
  line-height: 1.6;
  cursor: pointer;
}
.result-actions { display: flex; gap: 6px; flex-shrink: 0; }
.icon-btn {
  width: 44px; height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn svg { width: 21px; height: 21px; }
.icon-btn.share { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.icon-btn:active { transform: scale(.94); }
.empty { color: var(--muted); text-align: center; padding: 22px 0; }

/* نافذة البطاقة */
dialog.sheet {
  border: 0;
  padding: 0;
  width: min(480px, calc(100% - 24px));
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
dialog.sheet::backdrop { background: rgba(5, 15, 13, .6); }
.sheet-body { padding: 16px; display: grid; gap: 10px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2, .sheet-title { margin: 0; font-size: 19px; font-weight: 700; }
.card-preview { width: 100%; border-radius: 14px; display: block; aspect-ratio: 1 / 1; background: var(--surface-2); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* تنبيه صغير */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #13221f;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transition: .2s;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* المحتوى والشرح */
.prose p, .prose li { color: var(--text); }
.prose ul, .prose ol { padding-inline-start: 22px; }
.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 14px;
  color: var(--muted);
  border-top: 1px dashed var(--border);
  padding-top: 12px;
  margin-top: 24px;
}
details.faq {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
}
details.faq summary { font-weight: 600; cursor: pointer; }
details.faq p { margin: 8px 0 0; color: var(--muted); }

/* مساحات الإعلانات (محجوزة لمنع قفز الصفحة لاحقاً) */
.ad-slot { margin: 20px 0; min-height: 0; }
.ad-slot:empty { display: none; }

/* قائمة الأدوات بالرئيسية */
.tools { display: grid; gap: 12px; grid-template-columns: 1fr; margin-top: 16px; }
@media (min-width: 560px) { .tools { grid-template-columns: 1fr 1fr; } }
.tool {
  display: flex;
  gap: 12px;
  align-items: center;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.tool:hover { border-color: var(--brand); }
.tool-ico {
  width: 48px; height: 48px;
  flex-shrink: 0;
  border-radius: 12px;
  background: var(--brand-soft);
  display: grid;
  place-items: center;
  font-size: 24px;
}
.tool b { display: block; font-size: 17px; }
.tool small { color: var(--muted); font-size: 14px; }
.tool.soon { opacity: .55; pointer-events: none; box-shadow: none; }
.badge {
  font-size: 12px;
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 999px;
  padding: 1px 8px;
  margin-inline-start: 6px;
  font-weight: 400;
}

/* الفوتر */
.site-footer {
  margin-top: 48px;
  padding: 24px 0 32px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  font-size: 14px;
  color: var(--muted);
}
.site-footer nav { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-bottom: 8px; }
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--brand); }

@media (max-width: 420px) {
  h1 { font-size: 24px; }
  .nav a { margin-inline-start: 10px; font-size: 14px; }
  .result-text { font-size: 20px; }
}

/* اسماء مزخرفة جاهزة */
.examples { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 8px; }
.examples li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  display: grid;
  gap: 6px;
}
.ex-name { font-weight: 600; text-decoration: none; font-size: 15px; }
.ex-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ex-chip {
  font: inherit;
  font-size: 18px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 12px;
  cursor: pointer;
  max-width: 100%;
  overflow-wrap: anywhere;
}
.ex-chip:active { transform: scale(.97); }

/* ===== نماذج الحاسبات ===== */
.form { display: grid; gap: 14px; }
.form-row { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 520px) { .form-row.two { grid-template-columns: 1fr 1fr; } .form-row.three { grid-template-columns: 1fr 1fr 1fr; } }
.form label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 15px; }
.form .hint { display: block; color: var(--muted); font-size: 13px; font-weight: 400; margin-top: 4px; }
.form .input { font-size: 18px; padding: 12px 14px; min-width: 0; }
select.input { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: 18px 55%, 12px 55%; background-size: 6px 6px; background-repeat: no-repeat; padding-left: 34px; }
input[type="date"].input { min-height: 52px; }
.seg { display: flex; gap: 6px; background: var(--surface-2); border-radius: 12px; padding: 4px; }
.seg button { flex: 1; font: inherit; font-size: 15px; border: 0; background: transparent; color: var(--muted); padding: 8px; border-radius: 9px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 700; box-shadow: var(--shadow); }
.btn-block { width: 100%; font-size: 18px; padding: 14px; }
.error { color: #b42318; font-size: 15px; margin: 0; }
@media (prefers-color-scheme: dark) { .error { color: #f97066; } }

/* ===== لوحة النتيجة ===== */
.result-panel { margin-top: 16px; display: grid; gap: 12px; }
.result-panel[hidden] { display: none; }
.big {
  background: var(--brand);
  color: #fff;
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
}
.big small { display: block; opacity: .85; font-size: 15px; }
.big strong { display: block; font-size: 34px; line-height: 1.3; margin: 4px 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.big span { font-size: 15px; opacity: .9; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.stat small { display: block; color: var(--muted); font-size: 13px; }
.stat b { font-size: 18px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat.wide { grid-column: 1 / -1; }
.note { background: var(--surface-2); border-radius: 12px; padding: 10px 14px; font-size: 14px; color: var(--muted); margin: 0; }
.words { font-size: 21px; line-height: 1.9; font-weight: 600; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 0; }
.table-wrap { overflow-x: auto; }
table.simple { width: 100%; border-collapse: collapse; font-size: 15px; background: var(--surface); border-radius: 12px; overflow: hidden; }
table.simple th, table.simple td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: right; }
table.simple th { background: var(--surface-2); font-weight: 600; }
.related { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; margin-top: 10px; }
.related a { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; text-decoration: none; color: var(--text); font-weight: 600; font-size: 15px; }

/* صف مادة بحاسبة المعدل */
.courses { display: grid; gap: 8px; }
.course { display: grid; grid-template-columns: 24px 1fr 72px 44px; gap: 6px; align-items: center; }
.course .input { padding: 10px; font-size: 16px; }
.course-n { color: var(--muted); font-size: 14px; text-align: center; }
.course-head { display: grid; grid-template-columns: 24px 1fr 72px 44px; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }

/* خانات اختيار (حاسبة المواريث) */
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-weight: 600; font-size: 15px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--brand); }
