/* ============================================================================
   KHW — دليل الأدوات التفاعلي  ·  assets/tools-dir.css
   ----------------------------------------------------------------------------
   طبقة واحدة فوق kh.css. لا متغيّرات جديدة ولا خطوط جديدة ولا مكتبة:
   كل لون هنا var() من الهوية القائمة (--amber / --violet / --green / --teal).
   كل الأصناف مسبوقة بـ td- أو داخل #discover فلا تتسرّب إلى صفحة أخرى.
   ========================================================================== */

/* نصّ للقارئ الشاشي فقط — لا إزاحة خارج الحافة (تولّد تمريراً أفقياً في RTL) */
.sr-only, .sr-h {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; white-space: nowrap; border: 0; clip-path: inset(50%);
}

/* دعوتا المقدّمة */
.td-cta { display: flex; gap: 11px; flex-wrap: wrap; margin-top: 22px }
.td-cta .btn, .td-cta .b2 { min-height: 48px }

#discover { margin-top: 30px; scroll-margin-top: 92px }
#discover [hidden] { display: none !important }

/* ─── أزرار ومساحات لمس ──────────────────────────────────────
   كل عنصر تفاعلي هنا ≥ 44px ارتفاعاً — قاعدة اللمس على الهاتف. */
.td-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px; border-radius: 11px;
  font-family: 'Cairo', sans-serif; font-size: 14.5px; font-weight: 700;
  color: var(--ink); cursor: pointer;
  background: linear-gradient(180deg, var(--smoke-1), var(--smoke-2) 52%, var(--smoke-3));
  border: 1px solid var(--smoke-line); box-shadow: var(--smoke-sh);
  transition: transform .14s ease, box-shadow .14s ease;
}
.td-btn:hover { transform: translateY(-1px); box-shadow: var(--smoke-sh-hi) }
.td-btn:active { transform: translateY(0); box-shadow: var(--smoke-sh-in) }
.td-btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; box-shadow: var(--smoke-sh) }
.td-btn.pri {
  color: #fff; border-color: var(--amber-edge); box-shadow: var(--amber-sh);
  background: linear-gradient(180deg, var(--amber-lo), var(--amber) 55%, var(--amber-hi));
}
.td-btn.pri:hover { box-shadow: var(--amber-sh-hi) }
.td-btn.sm { min-height: 40px; padding: 8px 14px; font-size: 13.2px }
.td-btn.gh { background: none; border: 1px solid var(--line-2); box-shadow: none }
.td-btn.gh:hover { background: var(--sunk); box-shadow: none }

/* ─── ١. مسارات الجمهور في المقدّمة ───────────────────────── */
.td-routes {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px; margin-top: 22px;
}
.td-route {
  display: flex; align-items: center; gap: 10px; min-height: 52px;
  padding: 12px 15px; border-radius: 12px; text-align: start;
  background: var(--card); border: 1px solid var(--line); cursor: pointer;
  font-family: 'Cairo', sans-serif; font-size: 13.6px; font-weight: 700; color: var(--ink);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .9) inset, 0 2px 0 rgba(17, 17, 24, .045);
  transition: border-color .16s ease, transform .16s ease;
}
.td-route:hover { border-color: rgba(217, 119, 6, .45); transform: translateY(-1px) }
.td-route i { font-style: normal; font-size: 18px; line-height: 1; flex: 0 0 auto }
.td-route .t { display: block; min-width: 0 }
.td-route .t span { display: block; font-size: 11.6px; font-weight: 500; color: var(--mut); line-height: 1.65 }

/* ─── ٢. الغلاف المشترك ───────────────────────────────────── */
.td-panel {
  padding: 22px 24px; border-radius: var(--r); background: var(--card);
  border: 1px solid var(--line); margin-bottom: 20px; scroll-margin-top: 92px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .9) inset, 0 2px 0 rgba(17, 17, 24, .045),
              0 8px 20px rgba(17, 17, 24, .07);
}
.td-panel > h2 { font-size: 20px; color: var(--amber) }
.td-panel > .sub { margin-top: 9px; font-size: 14.4px; color: var(--mut); line-height: 1.9 }
.td-head { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; flex-wrap: wrap }

/* ─── ٣. المرشد (الأسئلة الخمسة) ──────────────────────────── */
.td-prog { display: flex; align-items: center; gap: 12px; margin: 18px 0 4px; flex-wrap: wrap }
.td-prog .bar {
  flex: 1 1 180px; height: 6px; min-width: 120px; border-radius: 99px;
  background: var(--sunk); overflow: hidden;
}
.td-prog .bar i {
  display: block; height: 100%; border-radius: 99px;
  background: linear-gradient(90deg, var(--amber-lo), var(--amber-hi));
  transition: width .28s ease;
}
.td-prog .n {
  font-size: 12.4px; font-weight: 700; color: var(--mut);
  font-variant-numeric: tabular-nums; flex: 0 0 auto;
}

.td-q { margin-top: 18px; border: 0; padding: 0; min-width: 0 }
.td-q legend {
  font-family: 'Cairo', sans-serif; font-size: 17px; font-weight: 800;
  color: var(--ink); line-height: 1.5; padding: 0;
}
.td-q legend .hint { display: block; margin-top: 6px; font-size: 13px; font-weight: 500; color: var(--mut) }
.td-opts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 16px }
.td-opt { position: relative; display: block; min-width: 0 }
.td-opt input {
  position: absolute; inset-block-start: 0; inset-inline-start: 0;
  width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer;
}
.td-opt span {
  display: flex; align-items: center; gap: 9px; min-height: 48px;
  padding: 11px 15px; border-radius: 11px; font-size: 14.2px; line-height: 1.6;
  background: var(--alt); border: 1px solid var(--line); color: var(--ink);
  transition: border-color .14s ease, background .14s ease;
}
.td-opt span::before {
  content: ""; flex: 0 0 auto; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--line-2); background: var(--card);
}
.td-opt input:hover + span { background: var(--sunk) }
.td-opt input:checked + span {
  border-color: var(--amber); background: rgba(217, 119, 6, .08); font-weight: 700;
}
.td-opt input:checked + span::before { border-color: var(--amber); box-shadow: inset 0 0 0 3px var(--amber) }
.td-opt input:focus-visible + span { outline: 2px solid var(--violet); outline-offset: 3px }

.td-nav { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 20px }
.td-nav .grow { flex: 1 1 auto }

/* ─── ٤. نتائج المرشد ─────────────────────────────────────── */
.td-recs { display: grid; gap: 14px; margin-top: 18px }
.td-rec {
  padding: 16px 18px; border-radius: 13px; background: var(--card);
  border: 1px solid var(--line); border-inline-start: 3px solid var(--amber);
}
.td-rec .rh { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap }
.td-rec .rank {
  font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--faint);
  direction: ltr; unicode-bidi: isolate;
}
.td-rec h4 { font-size: 16px }
.td-rec .en { font-family: 'IBM Plex Mono', monospace; direction: ltr; unicode-bidi: isolate;
  font-size: 11px; color: var(--faint) }
.td-rec p { margin-top: 8px; font-size: 14px; color: var(--mut); line-height: 1.9 }
.td-why { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 11px }
.td-why b {
  font-size: 11.6px; font-weight: 700; padding: 4px 10px; border-radius: 99px;
  color: #046B4D; background: rgba(5, 150, 105, .10); border: 1px solid rgba(5, 150, 105, .30);
}
.td-why b.warn { color: var(--amber-hi); background: rgba(217, 119, 6, .10); border-color: rgba(217, 119, 6, .32) }
.td-relax {
  margin-top: 14px; padding: 12px 15px; border-radius: 11px; font-size: 13.4px; line-height: 1.9;
  color: var(--mut); background: rgba(239, 160, 43, .09); border: 1px solid rgba(217, 119, 6, .4);
}
.td-empty { margin-top: 16px; padding: 20px; border-radius: 12px; background: var(--alt);
  border: 1px dashed var(--line-2); text-align: center }
.td-empty p { font-size: 14.4px; color: var(--mut); line-height: 1.95 }
.td-empty .td-btn { margin-top: 14px }

/* ─── ٥. أدوات البحث والفلترة ─────────────────────────────── */
.td-search { position: relative; margin-top: 16px }
.td-search input {
  width: 100%; min-height: 48px; padding: 12px 44px 12px 16px; font: inherit; font-size: 15px;
  color: var(--ink); background: var(--alt); border: 1px solid var(--line-2); border-radius: 12px;
}
.td-search input:focus-visible { outline: 2px solid var(--violet); outline-offset: 2px }
.td-search .ic { position: absolute; inset-inline-end: 15px; inset-block-start: 13px;
  color: var(--faint); font-size: 17px; pointer-events: none }

.td-filters { margin-top: 14px; display: grid; gap: 10px }
.td-fgroup { border: 1px solid var(--line); border-radius: 11px; background: var(--alt); overflow: hidden }
.td-fgroup > summary {
  padding: 11px 15px; min-height: 44px; font-size: 13.6px; font-family: 'Cairo', sans-serif; font-weight: 700;
}
.td-fgroup > summary .c {
  font-size: 11px; font-weight: 700; color: #fff; background: var(--amber);
  border-radius: 99px; padding: 1px 7px; margin-inline-start: 6px;
}
.td-fbody { padding: 4px 15px 14px; display: flex; flex-wrap: wrap; gap: 8px }
.td-check { position: relative; display: inline-block }
.td-check input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer }
.td-check span {
  display: inline-flex; align-items: center; min-height: 40px; padding: 8px 14px; border-radius: 99px;
  font-size: 13px; line-height: 1.5; color: var(--mut);
  background: var(--card); border: 1px solid var(--line); transition: .14s;
}
.td-check input:hover + span { background: var(--sunk); color: var(--ink) }
.td-check input:checked + span {
  color: var(--amber-hi); font-weight: 700;
  background: rgba(217, 119, 6, .11); border-color: rgba(217, 119, 6, .42);
}
.td-check input:focus-visible + span { outline: 2px solid var(--violet); outline-offset: 3px }

.td-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line);
}
.td-count { font-size: 13.6px; font-weight: 700; color: var(--ink) }
.td-count b { color: var(--amber) }
.td-sort { display: flex; align-items: center; gap: 8px; margin-inline-start: auto }
.td-sort label { font-size: 12.6px; color: var(--mut); white-space: nowrap }
.td-sort select {
  font: inherit; font-size: 13px; min-height: 40px; padding: 6px 11px; max-width: 200px;
  color: var(--ink); background: var(--card); border: 1px solid var(--line-2); border-radius: 9px; cursor: pointer;
}
.td-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px }
.td-chip {
  display: inline-flex; align-items: center; gap: 7px; min-height: 34px; padding: 5px 8px 5px 12px;
  border-radius: 99px; font-size: 12.4px; font-weight: 700; color: var(--amber-hi); cursor: pointer;
  background: rgba(217, 119, 6, .11); border: 1px solid rgba(217, 119, 6, .32);
}
.td-chip::after { content: "×"; font-size: 15px; line-height: 1; opacity: .8 }
.td-chip:hover { background: rgba(217, 119, 6, .18) }

/* ─── ٦. شبكة البطاقات ────────────────────────────────────── */
.td-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr));
  gap: 14px; margin-top: 18px;
}
.td-card {
  display: flex; flex-direction: column; gap: 9px; min-width: 0;
  padding: 16px 17px; border-radius: 13px; background: var(--card); border: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .9) inset, 0 2px 0 rgba(17, 17, 24, .04);
  transition: border-color .16s ease, transform .16s ease;
}
.td-card:hover { border-color: var(--line-2); transform: translateY(-2px) }
.td-card h3 { font-size: 15.5px; line-height: 1.45 }
.td-card .en { display: block; margin-top: 2px; font-family: 'IBM Plex Mono', monospace;
  direction: ltr; unicode-bidi: isolate; font-size: 10.5px; color: var(--faint) }
.td-card .desc { font-size: 13.4px; color: var(--mut); line-height: 1.85 }
.td-card .best { font-size: 12.8px; color: var(--mut); line-height: 1.8 }
.td-card .best b { color: var(--ink) }
.td-badges { display: flex; flex-wrap: wrap; gap: 6px }
.td-b {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700;
  padding: 3px 9px; border-radius: 99px; white-space: nowrap;
  color: var(--mut); background: var(--alt); border: 1px solid var(--line);
}
.td-b .dot { width: 8px; height: 8px }
.td-b.ar1 { color: #046B4D; background: rgba(5, 150, 105, .10); border-color: rgba(5, 150, 105, .30) }
.td-b.ar2 { color: #065F7C; background: rgba(8, 145, 178, .10); border-color: rgba(8, 145, 178, .30) }
.td-b.ar3 { color: var(--amber-hi); background: rgba(217, 119, 6, .11); border-color: rgba(217, 119, 6, .32) }
.td-b.ar4 { color: #8A2B2B; background: rgba(180, 60, 60, .10); border-color: rgba(180, 60, 60, .30) }
.td-b.free { color: #046B4D; background: rgba(5, 150, 105, .10); border-color: rgba(5, 150, 105, .30) }
.td-b.priv { color: #5219B5; background: rgba(124, 58, 237, .10); border-color: rgba(124, 58, 237, .30) }
.td-b.pend { color: var(--faint); background: var(--sunk); border-style: dashed }
.td-foot {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: auto; padding-top: 11px; border-top: 1px solid var(--line);
}
.td-ver { font-size: 11px; color: var(--faint); margin-inline-end: auto }
.td-ver time { font-variant-numeric: tabular-nums }

.td-cmp { position: relative; display: inline-block }
.td-cmp input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer }
.td-cmp span {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 7px 12px;
  border-radius: 9px; font-size: 12.4px; font-weight: 700; color: var(--mut);
  background: var(--alt); border: 1px solid var(--line);
}
.td-cmp input:checked + span { color: var(--amber-hi); background: rgba(217, 119, 6, .11);
  border-color: rgba(217, 119, 6, .42) }
.td-cmp input:disabled + span { opacity: .4; cursor: not-allowed }
.td-cmp input:focus-visible + span { outline: 2px solid var(--violet); outline-offset: 3px }

.td-none {
  margin-top: 18px; padding: 26px 22px; border-radius: 13px; text-align: center;
  background: var(--alt); border: 1px dashed var(--line-2);
}
.td-none b { display: block; font-family: 'Cairo', sans-serif; font-size: 15.5px; margin-bottom: 8px }
.td-none p { font-size: 13.8px; color: var(--mut); line-height: 1.9 }

/* ─── ٧. شريط المقارنة الملتصق ────────────────────────────────
   sticky لا fixed: يبقى داخل عمود المحتوى فلا يغطّي زرّ سيف
   العائم في أسفل الحافة البادئة، ولا يعترض تمرير الصفحة كلها.  */
.td-tray {
  position: sticky; inset-block-end: 14px; z-index: 40;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 18px; padding: 12px 16px; border-radius: 13px;
  background: rgba(252, 252, 253, .96); backdrop-filter: blur(8px);
  border: 1px solid var(--line-2); box-shadow: 0 8px 24px rgba(17, 17, 24, .16);
}
.td-tray .lbl { font-size: 13.4px; font-weight: 700; margin-inline-end: auto }
.td-tray .lbl span { color: var(--mut); font-weight: 500 }

/* ─── ٨. المقارنة والتفاصيل (نوافذ حوارية) ────────────────── */
.td-dialog {
  width: min(940px, calc(100% - 32px)); max-height: 86dvh; padding: 0;
  border: 1px solid var(--line-2); border-radius: var(--r); background: var(--card);
  color: var(--ink); box-shadow: 0 24px 60px rgba(17, 17, 24, .3);
}
.td-dialog::backdrop { background: rgba(17, 17, 24, .45) }
.td-dialog .dh {
  position: sticky; inset-block-start: 0; z-index: 2;
  display: flex; align-items: center; gap: 12px; padding: 16px 20px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.td-dialog .dh h3 { font-size: 17px; margin-inline-end: auto }
.td-dialog .db { padding: 18px 20px 24px; overflow: auto }
.td-x {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 10px; font-size: 20px; line-height: 1; cursor: pointer;
  color: var(--mut); background: var(--alt); border: 1px solid var(--line);
}
.td-x:hover { background: var(--sunk); color: var(--ink) }

.td-table { width: 100%; border-collapse: collapse; font-size: 13.4px }
.td-table th, .td-table td {
  padding: 11px 13px; text-align: start; border-bottom: 1px solid var(--line); vertical-align: top;
  line-height: 1.8;
}
.td-table thead th {
  position: sticky; inset-block-start: 0; background: var(--alt); color: var(--ink);
  font-family: 'Cairo', sans-serif; font-size: 13.6px; font-weight: 800; z-index: 1;
}
.td-table tbody th { font-weight: 700; color: var(--ink); background: var(--alt); width: 130px }
.td-table td { color: var(--mut) }

.td-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px }
.td-fact { padding: 11px 13px; border-radius: 10px; background: var(--alt); border: 1px solid var(--line) }
.td-fact b { display: block; font-size: 11.4px; color: var(--faint); font-weight: 700; margin-bottom: 3px }
.td-fact span { font-size: 13.4px; color: var(--ink); line-height: 1.75 }
.td-dialog .db p { font-size: 13.8px; color: var(--mut); line-height: 1.9; margin-top: 12px }
.td-dialog .db p b { color: var(--ink) }
.td-dialog .db .acts { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px }

/* ─── ٩. محتويات الصفحة القابلة للطيّ على الهاتف ──────────── */
/* details يُنشئ كتلة احتواء تُبطل position:sticky على .toc — و display:contents
   يرفعه من شجرة التخطيط تماماً، فيبقى العمود لاصقاً كما كان قبل التغيير.
   على الهاتف يعود عنصراً حقيقياً ليعمل الطيّ. */
.toc-d { display: contents }
.toc-d > summary { display: none }
/* اللصق ينتقل من .toc إلى الـ aside نفسه: بعد لفّ العمود في <details>
   صار .toc ابناً لعنصر شبكة غير ممدود (align-items:start)، وsticky داخل
   عنصر بارتفاع محتواه لا يتحرّك — فيسقط العمود اللاصق بصمت. */
.toc-wrap { position: sticky; top: 92px; align-self: start }
.toc-wrap .toc { position: static }
.toc .toc-top {
  list-style: none; display: grid; gap: 2px;
  margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px solid var(--line);
}
@media (max-width: 900px) {
  .toc-d { display: block }
  .toc-d > summary {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    min-height: 44px; padding: 12px 16px; margin: 0 0 2px;
    font-family: 'Cairo', sans-serif; font-size: 14px; font-weight: 700; color: var(--ink);
    background: var(--alt); border-radius: 10px; cursor: pointer;
  }
  .toc-d > summary::after { content: "+"; color: var(--amber); font-size: 20px; font-weight: 400 }
  .toc-d[open] > summary::after { content: "−" }
  .toc-d .toc { padding: 14px 8px 4px }
  .toc-d .toc h4 { display: none }
  .toc-d .toc a { min-height: 44px; align-items: center }
}

/* ─── ١٠. الهاتف ──────────────────────────────────────────── */
@media (max-width: 760px) {
  .td-routes { grid-template-columns: 1fr }
  .td-opts { grid-template-columns: 1fr }
  .td-facts { grid-template-columns: 1fr }
  .td-panel { padding: 18px 16px }
  .td-sort { margin-inline-start: 0; width: 100% }
  .td-sort select { max-width: none; flex: 1 1 auto }
  .td-tray { inset-block-end: 10px; padding: 11px 13px }
  /* زرّ سيف يجلس أسفل الحافة البادئة — نُخلي له مكاناً هنا فقط */
  .td-tray { padding-inline-start: 62px }

  /* الجدول يصير بطاقات مكدّسة: أعمدة الأدوات تحت بعضها بعناوينها */
  .td-table, .td-table tbody, .td-table tr, .td-table td, .td-table th { display: block; width: auto }
  .td-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%) }
  .td-table tbody tr {
    margin-bottom: 12px; border: 1px solid var(--line); border-radius: 11px; overflow: hidden;
  }
  .td-table tbody th { width: auto; border-bottom: 1px solid var(--line) }
  .td-table td { border-bottom: 1px solid var(--line) }
  .td-table td:last-child { border-bottom: 0 }
  .td-table td::before {
    content: attr(data-label); display: block; font-family: 'Cairo', sans-serif;
    font-size: 11.4px; font-weight: 800; color: var(--amber-hi); margin-bottom: 3px;
  }
  /* inset بدل 100vw: الأخير يشمل عرض شريط التمرير فيتجاوز الحافة */
  .td-dialog {
    inset: 0; width: auto; height: auto; max-width: none; max-height: none;
    border-radius: 0; border: 0;
  }
  .toc-wrap { position: static }
}
@media (max-width: 420px) {
  .td-nav .td-btn { flex: 1 1 100% }
  .td-nav .grow { display: none }
}

/* ─── ١١. حركة مخفَّضة وطباعة ─────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .td-btn, .td-card, .td-route, .td-prog .bar i { transition: none }
  .td-btn:hover, .td-card:hover, .td-route:hover { transform: none }
}
@media print {
  .td-tray, .td-filters, .td-search, #finder { display: none }
}
