/* ─────────────────────────────────────────────────────────────
   أدوات تفاعلية داخل مقالات المدونة (tools.js) — بطاقة الحاسبة أعلى نص المقال.
   الألوان والمتغيرات من portal.css (:root --mh-*).
   ───────────────────────────────────────────────────────────── */
.mh-tool { background: var(--mh-paper); border: 1px solid var(--mh-line); border-radius: var(--mh-r); padding: clamp(20px, 3.4vw, 36px); margin: 0 0 20px; box-shadow: var(--mh-shadow); color: var(--mh-ink); font-family: var(--mh-font); line-height: 1.7; }
.mh-tool p { margin: 0; }

.mh-tool-title { font-size: clamp(22px, 3vw, 28px); font-weight: 700; line-height: 1.4; }

/* سطر واحد: [ 15 % ] من [ 100 ]. الحقول بيضاء بإطار رمادي مثل حقل البحث (.mh-search-box في portal.css) */
.mh-tool-row { display: flex; align-items: center; gap: 12px; margin-top: 18px; }
.mh-tool-input { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 4px; height: 56px; padding-inline: 18px; background: #fff; border: 1px solid #DCDCDC; border-radius: 999px; cursor: text; transition: border-color .2s, box-shadow .2s; }
.mh-tool-input:hover { border-color: #C4C4C4; }
.mh-tool-input:focus-within { border-color: var(--mh-mint-d); box-shadow: 0 0 0 3px rgba(63,203,136,.15); }
.mh-tool-input:has(.is-bad) { border-color: #D64545; }
/* عرض الحقل = طول الرقم (--len من tools.js) فيبقى % ملاصقاً له؛ الحقل الثاني بلا رمز يأخذ العرض كله */
.mh-tool-input > input { flex: 0 1 auto; width: calc(var(--len, 1) * 1ch + 1.2ch); min-width: 0; max-width: 100%; height: 100%; padding: 0; border: 0; outline: 0; background: transparent; color: var(--mh-ink); font: inherit; font-size: 20px; font-weight: 600; text-align: center; font-variant-numeric: tabular-nums; }
.mh-tool-input > input:only-child { flex: 1; width: auto; }
.mh-tool-input > span { flex: none; color: var(--mh-muted); font-size: 20px; font-weight: 600; }
.mh-tool-of { flex: none; color: var(--mh-ink-2); font-size: 17px; font-weight: 600; }

/* حاسبات بعدة حقول (نهاية الخدمة): السبب بعرض كامل، ثم التاريخان متجاوران، ثم الراتب الإجمالي بعرض كامل */
.mh-tool-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; margin-top: 18px; }
.mh-tool-grid > .mh-tool-field { grid-column: span 3; }
.mh-tool-grid > .mh-tool-wide { grid-column: 1 / -1; }
.mh-tool-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.mh-tool-field > span:first-child { font-size: 14px; font-weight: 500; color: var(--mh-muted); padding-inline: 6px; }
/* علامة «!» بجانب عنوان الحقل: دائرة تفتح تلميحاً عند النقر */
.mh-tool-label { position: relative; display: flex; align-items: center; gap: 6px; }
.mh-tool-hint { display: inline-grid; place-items: center; width: 18px; height: 18px; padding: 0; border: 1.5px solid currentColor; border-radius: 50%; background: transparent; color: var(--mh-muted); font: inherit; font-size: 11.5px; font-weight: 700; line-height: 1; cursor: pointer; transition: color .15s; }
.mh-tool-hint:hover, .mh-tool-hint[aria-expanded="true"] { color: var(--mh-ink); }
.mh-tool-hint:focus-visible { outline: 3px solid var(--mh-mint); outline-offset: 2px; }
.mh-tool-tip { position: absolute; z-index: 5; top: calc(100% + 8px); inset-inline-start: 0; max-width: min(320px, 100%); padding: 10px 14px; border-radius: 12px; background: var(--mh-ink); color: #fff; font-size: 13.5px; font-weight: 500; line-height: 1.6; box-shadow: 0 10px 24px rgba(17,17,17,.18); }
.mh-tool-tip[hidden] { display: none; }
.mh-tool-grid .mh-tool-input { flex: none; height: 50px; }   /* داخل عمود: flex:1 يلغي الارتفاع */
.mh-tool-grid .mh-tool-input > input { font-size: 17px; }
.mh-tool-input > select { flex: 1; min-width: 0; height: 100%; padding: 0; border: 0; outline: 0; background: transparent; color: var(--mh-ink); font: inherit; font-size: 15px; font-weight: 500; cursor: pointer; }
.mh-tool-input > input[type="date"] { font-size: 16px; font-weight: 500; }
.mh-tool-lines { margin: 12px 0 0 !important; padding: 12px 0 0 !important; border-top: 1px solid rgba(17,17,17,.08); list-style: none; text-align: start; font-size: 14.5px; color: var(--mh-ink-2); }
.mh-tool-lines:empty { display: none; }
.mh-tool-lines li { margin: 2px 0 !important; padding: 0 !important; }
.mh-tool-lines bdi { display: inline-block; }   /* المعادلة تنتقل للسطر التالي كاملة ولا تنكسر في منتصفها */
.mh-tool-lines li::before { content: none !important; }
.mh-tool-value small { font-size: .45em; font-weight: 600; color: var(--mh-muted); }

.mh-tool-result { margin-top: 16px; padding: 18px 20px; border-radius: var(--mh-r-sm); background: var(--mh-mint-soft); text-align: center; transition: background .15s; }
.mh-tool-value { display: block; font-size: clamp(34px, 6vw, 46px); font-weight: 700; line-height: 1.3; color: var(--mh-ink); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.mh-tool-say { font-size: 15.5px; color: var(--mh-ink-2); }
.mh-tool-math { margin-top: 6px !important; font-size: 14px; color: var(--mh-muted); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.mh-tool-say:empty, .mh-tool-math:empty { display: none; }
/* قبل الكتابة: 0 باهت */
.mh-tool-result[data-state="empty"] { background: var(--mh-bg); }
.mh-tool-result[data-state="empty"] .mh-tool-value { color: var(--mh-soft); }
.mh-tool-result[data-state="error"] { background: #FFF5F5; }
.mh-tool-result[data-state="error"] .mh-tool-value { display: none; }
.mh-tool-result[data-state="error"] .mh-tool-say { color: #B23B3B; }

@media (max-width: 560px) {
  .mh-tool-row { gap: 8px; }
  .mh-tool-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .mh-tool-grid > .mh-tool-field { grid-column: span 1; }
  .mh-tool-grid > .mh-tool-wide { grid-column: 1 / -1; }   /* التاريخان يبقيان متجاورين */
  .mh-tool-input > input[type="date"] { font-size: 14.5px; }
  .mh-tool-grid .mh-tool-input:has(input[type="date"]) { padding-inline: 10px; }
  .mh-tool-input { height: 52px; padding-inline: 14px; }
  .mh-tool-input > input, .mh-tool-input > span { font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) { .mh-tool * { transition: none !important; } }
