/* Tasks module — styles layered on top of styles.css (which stays untouched). */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-align: center;
}
.stat-num { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.stat-lbl { color: var(--muted); font-size: 0.8rem; }
.stat.alert .stat-num { color: var(--warn); }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
}
.toolbar .cmd-input { flex: 1 1 200px; }

.select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--surface);
  color: var(--ink);
}
.check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--muted);
  white-space: nowrap;
}

/* بطاقة المهمة */
.task {
  background: var(--surface);
  border: 1px solid var(--line);
  border-inline-start: 3px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
}
.task:hover { transform: translateY(-1px); box-shadow: 0 8px 24px rgba(20, 30, 45, 0.08); }
.task.p1 { border-inline-start-color: var(--warn); }
.task.p2 { border-inline-start-color: var(--accent); }
.task.p3 { border-inline-start-color: var(--line-strong); }
.task.terminal { opacity: 0.62; }
.task.terminal .task-title { text-decoration: line-through; }

.task-title { font-weight: 600; margin-bottom: 4px; }
.task-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 0.85rem;
}
.pill-status { background: var(--accent-soft); color: var(--accent); }
.pill-overdue { background: var(--warn-soft); color: var(--warn); }
.pill-none { background: var(--surface-hover); color: var(--muted); }

.pager { display: flex; gap: 8px; justify-content: center; align-items: center; margin-top: 18px; }
.pager span { color: var(--muted); font-size: 0.88rem; }

/* النوافذ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 45, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
  overflow-y: auto;
}
/* `display: flex` above outranks the browser's `[hidden] { display: none }`,
   so a hidden modal would still paint as a full-screen overlay and swallow
   every click. This rule restores the hidden state. */
.modal[hidden] {
  display: none;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px;
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(20, 30, 45, 0.2);
}
.modal-wide { max-width: 720px; }
.modal-box h3 { margin: 0 0 16px; }
.modal-box label { display: block; margin-bottom: 12px; font-size: 0.9rem; color: var(--muted); }
.modal-box label .cmd-input,
.modal-box label .select { width: 100%; margin-top: 5px; display: block; }
.modal-box textarea.cmd-input { resize: vertical; font-family: inherit; }
.row { display: flex; gap: 12px; }
.row > label { flex: 1; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-start; margin-top: 8px; }
.form-error {
  background: var(--warn-soft);
  color: var(--warn);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.86rem;
  margin-bottom: 12px;
}

/* التفاصيل */
.detail-head { margin-bottom: 14px; }
.detail-title { font-size: 1.2rem; font-weight: 700; margin-bottom: 6px; }
.detail-desc { white-space: pre-wrap; margin-bottom: 8px; }
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 8px;
}
.detail-grid div { font-size: 0.88rem; }
.detail-grid .k { color: var(--muted); display: block; font-size: 0.78rem; }

.sec { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.sec h4 { margin: 0 0 10px; font-size: 0.92rem; color: var(--accent); }

.note-item, .att-item, .hist-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}
.note-item:last-child, .att-item:last-child, .hist-item:last-child { border-bottom: none; }
.note-body { white-space: pre-wrap; }
.item-meta { color: var(--muted); font-size: 0.78rem; margin-top: 3px; }
.att-item { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.att-item a { color: var(--accent); text-decoration: none; }
.att-item a:hover { text-decoration: underline; }

.inline-form { display: flex; gap: 8px; margin-top: 10px; }
.inline-form .cmd-input { flex: 1; }

.link-danger {
  background: none;
  border: none;
  color: var(--warn);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0;
}
.status-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

/* ==========================================================================
   منتقي التاريخ الميلادي
   ========================================================================== */

.dp-pop {
  position: absolute; z-index: 400;
  width: 268px; padding: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 14px 38px rgba(18, 38, 32, 0.18);
  font-size: 0.83rem;
  animation: dpIn 0.12s ease-out;
}
@keyframes dpIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.dp-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.dp-sel { flex: 1; display: flex; gap: 5px; }
.dp-month, .dp-year {
  flex: 1; min-width: 0; padding: 5px 7px;
  border: 1px solid var(--line); border-radius: 7px;
  font: inherit; font-size: 0.81rem; background: var(--surface-2); color: var(--ink);
}
.dp-year { max-width: 78px; text-align: center; }
.dp-nav {
  width: 26px; height: 26px; flex: none;
  border: 1px solid var(--line); border-radius: 7px; background: var(--surface);
  cursor: pointer; font-size: 1rem; line-height: 1; color: var(--ink-2);
}
.dp-nav:hover { background: var(--brand-soft); border-color: var(--brand-line); color: var(--brand); }

.dp-dow, .dp-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px;
}
.dp-dow { margin-bottom: 3px; }
.dp-dow span {
  text-align: center; font-size: 0.66rem; font-weight: 600;
  color: var(--muted); padding: 3px 0;
}
.dp-cell {
  height: 30px; border: 1px solid transparent; border-radius: 7px;
  background: none; font: inherit; font-size: 0.81rem; color: var(--ink);
  cursor: pointer; font-variant-numeric: tabular-nums;
  transition: background 0.11s ease, border-color 0.11s ease;
}
.dp-cell.empty { pointer-events: none; }
.dp-cell:hover { background: var(--brand-soft); }
.dp-cell.today { border-color: var(--brand-line); font-weight: 700; color: var(--brand); }
.dp-cell.sel { background: var(--brand); border-color: var(--brand); color: var(--ink-inverse); font-weight: 700; }

.dp-foot {
  display: flex; gap: 6px; margin-top: 9px;
  padding-top: 8px; border-top: 1px solid var(--surface-hover);
}
.dp-btn {
  flex: 1; padding: 6px 0; border: 1px solid var(--line); border-radius: 7px;
  background: var(--surface); font: inherit; font-size: 0.78rem; font-weight: 600;
  color: var(--ink-2); cursor: pointer; transition: all 0.12s ease;
}
.dp-btn:hover { background: var(--brand-soft); border-color: var(--brand-line); color: var(--brand); }
.dp-btn.danger:hover { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger); }

/* ==========================================================================
   المهام — ترويسة وقائمة وعرض مركَّز
   ========================================================================== */

.tk-page {
  --tk-line: var(--line);
  --tk-soft: var(--surface-2);
  --tk-ink: var(--ink);
  --tk-ink-2: var(--ink-2);
  --tk-ink-3: var(--muted);
  --tk-brand: var(--brand);
  --tk-brand-soft: var(--brand-soft);
  --tk-brand-line: var(--brand-line);
  --tk-warn: var(--warn);
  --tk-warn-soft: var(--warn-soft);
  --tk-warn-line: var(--warn-line);
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 22px 40px;
  color: var(--tk-ink);
}
.tk-page[hidden] { display: none; }
.tk-hidden-filters { display: none; }

/* ---------- الترويسة ---------- */
.tk-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; margin-bottom: 14px;
}
.tk-title { font-size: 1.32rem; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.tk-head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.tk-search { position: relative; }
.tk-search-icon {
  position: absolute; inset-inline-start: 11px; top: 50%;
  transform: translateY(-50%); font-size: 0.82rem; opacity: 0.5; pointer-events: none;
}
.tk-search input {
  width: 240px; padding: 8px 32px 8px 12px;
  border: 1px solid var(--tk-line); border-radius: 9px;
  background: var(--surface-2); font: inherit; font-size: 0.86rem; color: inherit;
  transition: border-color 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
}
.tk-search input:focus {
  outline: none; background: var(--surface); border-color: var(--brand-line);
  box-shadow: 0 0 0 3px rgba(33, 161, 121, 0.1);
}

.tk-new {
  height: 36px; padding: 0 16px; border-radius: 9px;
  border: 1px solid var(--tk-brand); background: var(--tk-brand); color: var(--ink-inverse);
  font: inherit; font-size: 0.86rem; font-weight: 650; cursor: pointer;
  transition: filter 0.13s ease;
}
.tk-new:hover { filter: brightness(1.08); }

/* ---------- المرشّحات والترتيب ---------- */
.tk-controls {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 12px;
}
.tk-chips { display: flex; gap: 5px; flex-wrap: wrap; }
.tk-chip {
  padding: 6px 13px; border-radius: 999px;
  border: 1px solid var(--tk-line); background: var(--surface);
  font: inherit; font-size: 0.81rem; font-weight: 600; color: var(--tk-ink-2);
  cursor: pointer; transition: all 0.13s ease;
}
.tk-chip:hover { background: var(--tk-soft); }
.tk-chip.active {
  background: var(--tk-brand-soft); border-color: var(--tk-brand-line); color: var(--tk-brand);
}

.tk-sort { display: flex; align-items: center; gap: 7px; }
.tk-sort label { font-size: 0.78rem; color: var(--tk-ink-3); }
.tk-select {
  padding: 6px 10px; border: 1px solid var(--tk-line); border-radius: 8px;
  background: var(--surface); font: inherit; font-size: 0.82rem; color: inherit; cursor: pointer;
}

/* ---------- بطاقة المهمة ---------- */
#list { display: flex; flex-direction: column; gap: 7px; }

.tk-card {
  position: relative; display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: start; font: inherit; color: inherit;
  padding: 12px 14px 12px 10px;
  border: 1px solid var(--tk-line); border-radius: 11px; background: var(--surface);
  cursor: pointer; transition: border-color 0.13s ease, box-shadow 0.13s ease, transform 0.13s ease;
}
.tk-card:hover {
  border-color: var(--tk-brand-line);
  box-shadow: 0 2px 10px rgba(18, 38, 32, 0.06);
  transform: translateY(-1px);
}

/* شريط الأولوية: إشارة هادئة بلا ضجيج لوني */
.tk-card-bar {
  width: 3px; align-self: stretch; border-radius: 3px; flex: none;
  background: var(--tk-line);
}
.tk-card.p1 .tk-card-bar { background: var(--tk-warn); }
.tk-card.p2 .tk-card-bar { background: var(--tk-brand-line); }

.tk-card-main { flex: 1; min-width: 0; display: block; }
/* العنوان أقوى عنصر في البطاقة */
.tk-card-title {
  display: block; font-size: 0.95rem; font-weight: 650; line-height: 1.5;
  color: var(--tk-ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tk-card-meta {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  margin-top: 4px; font-size: 0.78rem; color: var(--tk-ink-3);
}
.tk-sep { opacity: 0.45; }
.tk-who.none { font-style: italic; opacity: 0.75; }
.tk-clip { font-size: 0.8rem; }

.tk-due.overdue { color: var(--tk-warn); font-weight: 650; }
.tk-due.today   { color: var(--tk-brand); font-weight: 650; }
.tk-due.soon    { color: var(--tk-brand); }
.tk-due.none    { opacity: 0.6; }

.tk-card-side { display: flex; align-items: center; gap: 6px; flex: none; }
.tk-badge {
  font-size: 0.72rem; font-weight: 650; padding: 3px 9px; border-radius: 999px;
  background: var(--tk-soft); color: var(--tk-ink-2); white-space: nowrap;
}
.tk-badge.urgent { background: var(--tk-warn-soft); color: var(--tk-warn); }
.tk-badge.st-open { background: var(--surface-2); color: var(--ink-2); }
.tk-badge.st-in_progress { background: var(--warn-soft); color: var(--warn); }
.tk-badge.st-done { background: var(--brand-soft); color: var(--tk-brand); }
.tk-badge.st-blocked { background: var(--danger-soft); color: var(--danger); }
.tk-badge.st-cancelled { background: var(--line-soft); color: var(--muted); }

/* المنجزة تبدو مختلفة بوضوح دون أن تختفي */
.tk-card.terminal { background: var(--surface-2); }
.tk-card.terminal .tk-card-title {
  color: var(--tk-ink-3); text-decoration: line-through; font-weight: 550;
}
.tk-card.terminal .tk-card-bar { opacity: 0.4; }

/* ---------- عرض المهمة ---------- */
.tk-detail-head { margin-bottom: 12px; }
.tk-back {
  border: 0; background: none; cursor: pointer; padding: 4px 0;
  font: inherit; font-size: 0.82rem; font-weight: 650; color: var(--tk-brand);
}
.tk-back:hover { text-decoration: underline; }

/* ---------- استجابة ---------- */
@media (max-width: 720px) {
  .tk-page { padding: 16px 14px 32px; }
  .tk-head { align-items: stretch; }
  .tk-head-actions { width: 100%; }
  .tk-search { flex: 1; }
  .tk-search input { width: 100%; }
  .tk-controls { align-items: stretch; }
  .tk-chips { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 3px; scrollbar-width: none; }
  .tk-chips::-webkit-scrollbar { display: none; }
  .tk-chip { flex: none; }
  .tk-sort { width: 100%; }
  .tk-sort select { flex: 1; }
  .tk-card { flex-wrap: wrap; }
  .tk-card-side { width: 100%; padding-inline-start: 15px; }
  .tk-card-title { white-space: normal; }
}


/* ============================================================================
   المهام — القسم هـ حرفًا بحرف
   ============================================================================
   قائمة مضغوطة لا بطاقات كبيرة: صفّ ٧٢ بكسل، حدّ سفليّ واحد، وشارة حالة
   بألوانها المحدّدة. لا أزرق فاتح لأي حالة. */

.tk-page { background: var(--bg); padding: var(--s-6); }
.tk-title { font-size: var(--fs-page); font-weight: 600; }

/* القائمة لوحة واحدة، والصفوف تفصلها حدود لا فجوات */
/* الحاوية في الترميز هي #list — تُلفّ الصفوف في لوحة واحدة */
#list {
  /* قاعدة أقدم تضع فجوة ٧ بين الصفوف — تُلغى ليصير الفصل حدًّا لا فراغًا */
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
}

.tk-card {
  min-height: 72px;
  background: var(--surface);
  border: none;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  box-shadow: none;
  transform: none;
  transition: background 0.14s ease;
}
.tk-card:last-child { border-bottom: 0; }
.tk-card:hover { background: var(--surface-hover); box-shadow: none; transform: none; }
.tk-card.selected { background: var(--brand-soft); }
.tk-card-title { font-size: var(--fs-body); font-weight: 600; line-height: var(--lh-ar); }
.tk-card-meta { font-size: var(--fs-meta); color: var(--ink-2); }

/* ألوان الحالة — قيم المواصفة بالضبط */
.tk-badge {
  border-radius: var(--r-badge);
  font-size: var(--fs-meta);
  font-weight: 600;
  padding: 3px var(--s-2);
  border: 1px solid transparent;
}
.tk-badge.st-open        { background: var(--surface-2); color: var(--ink-2); }  /* جديدة */
.tk-badge.st-in_progress { background: var(--brand-soft); color: var(--brand); }  /* جاري التنفيذ */
.tk-badge.st-done        { background: var(--ok-soft); color: var(--ok); }  /* مكتملة */
.tk-badge.st-blocked,
.tk-badge.st-cancelled   { background: var(--surface-2); color: var(--ink-2); }
.tk-badge.urgent         { background: var(--danger-soft); color: var(--danger); }  /* متأخرة */

.tk-due.overdue { color: var(--danger); font-weight: 600; }

/* شريط الأدوات: عنوان، بحث، فلاتر، ثم زرّ أساسي */
.tk-controls {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  margin-bottom: var(--s-4);
}
.tk-new {
  height: 40px;
  background: var(--brand);
  color: var(--ink-inverse);
  border: 1px solid var(--brand);
  border-radius: var(--r-sm);
  padding: 0 var(--s-4);
  font-weight: 600;
  font-size: var(--fs-body);
  cursor: pointer;
}
.tk-new:hover { background: var(--brand-hover); }

/* تفاصيل المهمة: نافذة واسعة ٧٢٠–٨٢٠ */
.tk-detail, .tk-drawer { width: min(820px, 100vw); border-radius: var(--r-dialog); }

@media (max-width: 1199px) { .tk-page { padding: 20px; } }
@media (max-width: 767px) {
  .tk-page { padding: var(--s-3); }
  .tk-detail, .tk-drawer { width: 100vw; border-radius: 0; }
}

/* ============================================================================
   ٩: المهامّ — اللغة البصرية نفسها، والبيانات والمنطق كما هما
   ============================================================================ */

.tk-page { background: var(--bg); }
.tk-title { color: var(--ink); font-weight: 650; }

#list, .tk-controls {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: none;
}
.tk-card {
  background: var(--surface);
  border: none;
  border-bottom: 1px solid var(--line-soft);
  border-radius: 0;
}
.tk-card:last-child { border-bottom: 0; }
.tk-card:hover { background: var(--surface-hover); }
.tk-card.selected { background: var(--beige-deep); }
.tk-card-title { color: var(--ink); }
.tk-card-meta { color: var(--ink-2); }

/* الشرائح: المفعَّلة أخضر، والباقي هادئ بلا حدود */
.tk-chip {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-2);
  border-radius: var(--r-sm);
  height: 34px;
  font-size: var(--fs-body);
  font-weight: 500;
}
.tk-chip:hover { background: var(--surface-hover); color: var(--ink); }
.tk-chip.active {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--ink-inverse);
  font-weight: 600;
}

/* الأولوية: خطّ جانبيّ رفيع، بالأخضر أو المحايد — لا برتقاليّ ولا أزرق */
.task.p1 { border-inline-start-color: var(--danger); }
.task.p2 { border-inline-start-color: var(--brand); }
.task.p3 { border-inline-start-color: var(--line-strong); }

/* نوافذ الإنشاء والتعديل من نظام التصميم نفسه */
#tkDetail {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-dialog);
  box-shadow: var(--shadow-lg);
}
.tk-select, .cmd-input {
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--fs-body);
}
.tk-select:focus, .cmd-input:focus {
  outline: none; border-color: var(--brand); box-shadow: var(--focus-ring);
}
