/* ------------------------------------------------------------------
   متابعة العبادات — تنسيق محلي بالكامل، بلا أي مورد خارجي.
   الخطوط: خطوط النظام فقط (Segoe UI على ويندوز يعرض العربية جيدًا).
   إن أردت خطًا خاصًا: ضع ملف الخط في public/fonts/ وفعّل @font-face أدناه.

   @font-face {
     font-family: "AppArabic";
     src: url("/fonts/app-arabic.woff2") format("woff2");
     font-display: swap;
   }
------------------------------------------------------------------ */

:root {
  --paper: #FAF9F6;
  --card: #FFFFFF;
  --ink: #15211C;
  --muted: #7A807B;
  --faint: #B9BDB8;
  --line: #E7E5DE;
  --line-soft: #F0EEE8;
  --accent: #2E6B54;
  --accent-dark: #265843;
  --accent-soft: #EDF3F0;
  --accent-line: #D6E4DD;
  --danger: #9A3B2B;
  --danger-soft: #FCF0EE;
  --danger-line: #F0DCD7;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
}

body {
  color: var(--ink);
  font-family: "Segoe UI", "Noto Sans Arabic", "Dubai", Tahoma, "Traditional Arabic", sans-serif;
  font-size: 15px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 920px;
  margin: 0 auto;
  padding: 38px 18px 64px;
}

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

.head { text-align: center; padding: 4px 0 26px; }
.head h1 { font-size: 30px; font-weight: 600; margin: 0; }
.dua { color: var(--muted); font-size: 15px; margin: 8px 0 0; }

/* ------------------------------ البطاقات ------------------------------ */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px 20px 22px;
  margin-bottom: 22px;
}

.card-today { border-inline-start: 3px solid var(--accent); }

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.card-top h2 { font-size: 17px; font-weight: 600; margin: 0; }
.note { font-size: 12.5px; color: var(--muted); }
.date { font-size: 14px; color: var(--muted); margin: 2px 0 18px; }
.hint { font-size: 13px; color: var(--muted); margin: 4px 0 14px; }

/* ------------------------------ قائمة اليوم ------------------------------ */

.list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line-soft); }
.list li { border-bottom: 1px solid var(--line-soft); }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 4px;
  background: none;
  border: 0;
  text-align: start;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.row:disabled { cursor: default; color: var(--faint); }
.row .label { flex: 1; }

.box {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  border: 1.5px solid #CFCDC5;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  line-height: 1;
  transition: background .12s, border-color .12s;
}

.row:hover:not(:disabled) .box { border-color: var(--accent); }
.row.on .box { background: var(--accent); border-color: var(--accent); }
.row.on .label { color: var(--accent); }
.row:disabled .box { background: var(--line-soft); border-color: var(--line); }
.row:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.tag {
  font-size: 12px;
  color: var(--muted);
  background: var(--line-soft);
  padding: 2px 9px;
  border-radius: 20px;
  white-space: nowrap;
}

/* ------------------------------ الأزرار ------------------------------ */

.save {
  margin-top: 20px;
  width: 100%;
  padding: 13px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 500;
  font-size: 15px;
  cursor: pointer;
}

.save:hover:not(:disabled) { background: var(--accent-dark); }
.save:disabled { opacity: .55; cursor: default; }
.save:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.tools { display: flex; gap: 10px; flex-wrap: wrap; }

.btn {
  padding: 9px 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-quiet { color: var(--muted); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------ الرسائل ------------------------------ */

.msg {
  border-radius: 8px;
  padding: 11px 14px;
  font-size: 14.5px;
  margin: 16px 0 0;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-line);
}

.msg.error {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: var(--danger-line);
}

/* ------------------------------ الإحصائيات ------------------------------ */

.stats {
  display: flex;
  gap: 30px;
  flex-wrap: wrap;
  padding: 16px 0 2px;
  margin-top: 12px;
  border-top: 1px solid var(--line-soft);
}

.stats div { display: flex; flex-direction: column; }
.stat-n { font-size: 20px; font-weight: 600; line-height: 1.35; font-variant-numeric: tabular-nums; }
.stat-l { font-size: 12.5px; color: var(--muted); }

select {
  font: inherit;
  font-size: 14px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
}

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

.empty { color: var(--muted); text-align: center; padding: 26px 0 14px; font-size: 14px; }

.scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 14px;
}

table { border-collapse: collapse; width: 100%; font-size: 13.5px; white-space: nowrap; }

th {
  font-weight: 500;
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
  padding: 10px 12px;
  background: #FBFAF7;
  border-bottom: 1px solid var(--line);
}

td { padding: 10px 12px; text-align: center; border-bottom: 1px solid var(--line-soft); }
tr:last-child td { border-bottom: 0; }

.sticky {
  position: sticky;
  inset-inline-start: 0;
  z-index: 2;
  text-align: start;
  border-inline-end: 1px solid var(--line);
}

th.sticky { background: #FBFAF7; }
td.sticky { background: var(--card); }
tr.missing td.sticky { background: #FCFBF9; }

.td-date { display: block; font-variant-numeric: tabular-nums; }
.td-day { display: block; font-size: 11.5px; color: var(--muted); }

.mark { display: inline-block; min-width: 26px; font-size: 15px; }
.mark.yes { color: var(--accent); font-weight: 600; }
.mark.no { color: var(--faint); }
.mark.na { color: #A9ADA8; font-size: 11px; }

/* النص يبدأ بجوار عمود التاريخ حتى يظهر على الجوال بلا تمرير */
.none {
  color: var(--faint);
  font-size: 13px;
  text-align: start;
  padding-inline-start: 18px;
}

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

@media (max-width: 560px) {
  .wrap { padding: 26px 14px 48px; }
  .head h1 { font-size: 26px; }
  .card { padding: 17px 15px 19px; }
  .note { display: none; }
  .stats { gap: 22px; }
  .tools .btn { flex: 1 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ------------------------------ الدخول والوضع ------------------------------ */

.wrap-narrow { max-width: 460px; }

.field { display: block; margin-top: 14px; }
.field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

.field input {
  width: 100%;
  font: inherit;
  font-size: 16px; /* 16px يمنع تكبير الصفحة تلقائيًا على iPhone */
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
}

.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

.foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 4px 0;
  font-size: 12.5px;
  color: var(--muted);
}

.link {
  background: none;
  border: 0;
  font: inherit;
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
  padding: 4px;
}

.link:hover { color: var(--accent); }

/* مساحة آمنة أسفل شاشات الجوال ذات الحواف المنحنية */
@supports (padding: max(0px)) {
  .wrap { padding-bottom: max(48px, env(safe-area-inset-bottom)); }
}

/* ------------------------------ مؤشر الحفظ التلقائي ------------------------------ */

.save-status {
  font-size: 12.5px;
  color: var(--muted);
  min-height: 1.4em;
  transition: color .15s;
}

.save-status.is-saving { color: var(--muted); }
.save-status.is-saved { color: var(--accent); }
.save-status.is-error { color: var(--danger); font-weight: 500; }

.note-block {
  display: block;
  margin: 16px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

@media (max-width: 560px) {
  .save-status { font-size: 12px; }
  .note-block { margin-top: 14px; }
}

/* ------------------------------ صفحات الحساب ------------------------------ */

.optional { color: var(--faint); font-weight: 400; }

.alt {
  margin: 14px 0 0;
  font-size: 13.5px;
  color: var(--muted);
  text-align: center;
}

.alt a { color: var(--accent); text-decoration: none; }
.alt a:hover { text-decoration: underline; }

.code-input {
  text-align: center;
  font-size: 26px !important;
  letter-spacing: 10px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.user-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  font-size: 13.5px;
  color: var(--muted);
}

.user-bar strong { color: var(--ink); font-weight: 600; }

/* ------------------------ وضع تعديل قائمة العبادات ------------------------ */

.card-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-small { padding: 5px 11px; font-size: 13px; }

.card-today.editing .list { margin-bottom: 4px; }

/* صف التعديل يحاكي صف المتابعة في مقاسه فلا تقفز القائمة عند تبديل الوضع */
.row-editing {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 4px;
  cursor: default;
}

/* زر الحذف يشغل موضع مربع الاختيار — على الجوال لا يجتمع الاثنان أبدًا */
.del {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  padding: 0;
  border: 1.5px solid var(--danger-line);
  border-radius: 5px;
  background: var(--danger-soft);
  color: var(--danger);
  font: inherit;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}

.del:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.del { font-weight: 600; }
.del:focus-visible { outline: 2px solid var(--danger); outline-offset: 2px; }

.name {
  flex: 1;
  min-width: 0;
  padding: 4px 6px;
  margin-inline-start: -6px;
  border: 0;
  border-radius: 6px;
  background: none;
  font: inherit;
  color: inherit;
  text-align: start;
  cursor: text;
  overflow-wrap: anywhere;
}

.name:hover { background: var(--line-soft); }
.name:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }

.name-input {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  border: 1px solid var(--accent-line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
}

.name-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.ok {
  flex: 0 0 auto;
  padding: 5px 11px;
  border: 1px solid var(--accent-line);
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font: inherit;
  cursor: pointer;
}

.ok:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.ok:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.manage-add { margin-top: 14px; }
.btn-add { width: 100%; padding: 11px 15px; color: var(--accent); border-style: dashed; }
.btn-add:hover:not(:disabled) { background: var(--accent-soft); }
.tools-edit { margin-top: 12px; }

/* على الشاشات الواسعة يذهب الحذف إلى طرف الصف كما في التصميم المطلوب */
@media (min-width: 768px) {
  .del { order: 2; margin-inline-start: auto; }
  .name { order: 1; }
  .name-input { order: 1; }
  .ok { order: 1; }
}

/* على الجوال: حقول عريضة يسهل لمسها */
@media (max-width: 480px) {
  .manage-add { flex-direction: column; }
  .manage-add .btn { width: 100%; padding: 11px 15px; }
  .del { width: 28px; height: 28px; flex-basis: 28px; font-size: 19px; }
}

/* ----------------------------- نافذة التأكيد ----------------------------- */

.btn-danger {
  border-color: var(--danger-line);
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) { background: #872F21; border-color: #872F21; color: #fff; }
.btn-danger:focus-visible { outline: 2px solid var(--danger); outline-offset: 2px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(21, 33, 28, .45);
}

.modal-backdrop[hidden] { display: none; }

.modal {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 18px 40px rgba(21, 33, 28, .18);
}

.modal h3 {
  margin: 0 0 10px;
  font-size: 17px;
}

.modal-body {
  margin: 0;
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.modal .msg { margin-top: 14px; }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-start;
  margin-top: 20px;
}

@media (max-width: 480px) {
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; padding: 11px 15px; }
}

/* ------------------- الاسم والجدول داخل صف التعديل ------------------- */

.row-editing .name {
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
}

.name-text { font-size: 15px; }

.name-schedule {
  font-size: 12.5px;
  color: var(--muted);
}

.row-editing .name:hover .name-schedule { color: var(--accent); }

/* ------------------------ حقول نافذة العبادة ------------------------ */

.field { margin-top: 16px; }
.field:first-of-type { margin-top: 18px; }

.field-label {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
  color: var(--muted);
}

.field input[type="text"],
.field select,
.select-like {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
}

.field select { cursor: pointer; }

.field input[type="text"]:focus-visible,
.field select:focus-visible,
.select-like:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }
.btn-primary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* النافذة لا تتجاوز الشاشة، وتُمرَّر داخليًا إن طالت */
.modal {
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

@media (max-width: 480px) {
  .field input[type="text"], .field select, .select-like { padding: 12px; }
}

/* ------------------------- عرضا نافذة العبادة ------------------------- */

/* النافذة تأخذ ارتفاع محتواها: عرض التعديل قصير، وعرض الأيام أطول */
.modal-view[hidden] { display: none; }

.select-like {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: start;
  cursor: pointer;
}

.select-like:hover { border-color: var(--accent); }
.select-like .chev { color: var(--faint); font-size: 16px; line-height: 1; }

.view-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.view-head h3 { margin: 0; font-size: 17px; }

.back {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.back:hover { background: var(--line-soft); color: var(--accent); }
.back:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.repeat-options {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.repeat-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 15px;
  cursor: pointer;
  user-select: none;
}

.repeat-option:last-child { border-bottom: 0; }
.repeat-option:hover { background: var(--accent-soft); }
.repeat-option.on .repeat-label { color: var(--accent); font-weight: 600; }
.repeat-option:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* «يوميًا» أول القائمة ومفصولة عنها: اختصار لكل الأيام لا يوم ثامن */
.repeat-daily { border-bottom: 1px solid var(--line); }

.repeat-label { flex: 1; }

.tick {
  width: 18px;
  flex: 0 0 18px;
  text-align: center;
  color: var(--accent);
  font-size: 14px;
  line-height: 1;
}

/* الصفوف الثمانية تظهر كاملة بلا تمرير على الشاشات المعتادة؛
   والتمرير يبقى مخرجًا أخيرًا على الشاشات القصيرة جدًا وحدها */
@media (max-width: 767px) {
  .repeat-option { padding: 12px 14px; font-size: 15.5px; }
  .repeat-options { margin-top: 12px; }
}

@media (max-height: 620px) {
  .repeat-option { padding: 8px 14px; font-size: 14.5px; }
}

/* ------------------- تمدّد النافذة بين عرضيها ------------------- */

/* الحركة تُضاف بشرطين: أن يقبلها المستخدم، وأن نكون في أثناء التبديل.
   خارج التبديل تبقى النافذة بلا انتقال فلا تتأثر بأي تغيّر آخر. */
@media (prefers-reduced-motion: no-preference) {
  .modal.resizing {
    transition: height 250ms ease-out;
    overflow: hidden;   /* يمنع وميض شريط التمرير أثناء التمدّد */
  }

  /* ظهور لطيف للمحتوى الجديد — بلا انزلاق حتى لا يبدو نافذة أخرى دخلت */
  .modal-view { animation: view-fade 200ms ease-out; }
}

@keyframes view-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* --------------------------- عبادات مقترحة --------------------------- */

.suggest { margin-top: 18px; }

.suggest-title {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.suggest-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.suggest-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 13px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: none;
  font: inherit;
  color: inherit;
  text-align: start;
  cursor: pointer;
}

.suggest-list li:last-child .suggest-row { border-bottom: 0; }
.suggest-row:hover:not(:disabled) { background: var(--accent-soft); }
.suggest-row:disabled { opacity: .55; cursor: default; }
.suggest-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.suggest-plus {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--accent-line);
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 15px;
  line-height: 1;
}

.suggest-row:hover:not(:disabled) .suggest-plus { background: var(--accent); border-color: var(--accent); color: #fff; }

.suggest-name { flex: 1; min-width: 0; font-size: 15px; overflow-wrap: anywhere; }
.suggest-schedule { font-size: 12.5px; color: var(--faint); }

@media (max-width: 480px) {
  .suggest-row { padding: 13px; }
  .suggest-plus { width: 24px; height: 24px; flex-basis: 24px; }
}

/* ------------- انتقال العبادة بين القائمة والمقترحات ------------- */

/* الخروج: تنكمش وتنزلق في اتجاه وجهتها، فيُرى إلى أين ذهبت */
.leaving {
  transition: max-height 240ms ease-in, opacity 160ms ease-in, transform 240ms ease-in;
  overflow: hidden;
  pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
  .arriving-up { animation: arrive-up 280ms ease-out; }
  .arriving-down { animation: arrive-down 280ms ease-out; }
}

/* صاعدة من المقترحات إلى القائمة */
@keyframes arrive-up {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

/* نازلة من القائمة إلى المقترحات */
@keyframes arrive-down {
  from { opacity: 0; transform: translateY(-14px); }
  to { opacity: 1; transform: none; }
}

/* ----------------------- مقبض إعادة الترتيب ----------------------- */

.grip {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: none;
  cursor: grab;
  touch-action: none;   /* الإصبع يسحب الصف لا الصفحة */
}

.grip span {
  width: 14px;
  height: 2px;
  border-radius: 1px;
  background: var(--faint);
  transition: background .12s;
}

.grip:hover span { background: var(--accent); }
.grip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.grip:active { cursor: grabbing; }

/* الصف المسحوب يعلو على البقية ويتبع الإصبع بلا تأخير */
#checklist li.dragging {
  position: relative;
  z-index: 5;
}

#checklist li.dragging .row-editing {
  background: var(--card);
  border-radius: 10px;
  box-shadow: 0 10px 22px rgba(21, 33, 28, .16);
}

#checklist li.dragging .grip { cursor: grabbing; }

/* البقية تنزاح لتفتح مكانًا — وهي وحدها التي تتحرك بانتقال */
@media (prefers-reduced-motion: no-preference) {
  #checklist.reordering li:not(.dragging) {
    transition: transform 160ms ease-out;
  }
}

/* لا تحديد للنص أثناء السحب */
#checklist.reordering { user-select: none; }
