/* =====================================================================
   calculator.css — أنماط صفحة حاسبة الحديد فقط (تعتمد على tokens في base.css)
   ---------------------------------------------------------------------
   01 تخطيط الحاسبة (.calc) — الجوال أولًا: النموذج ← الإجمالي ← البنود
   02 بطاقة الحاسبة (.calc-card) + مبدّل طريقة الحساب (.segmented)
   03 المعاينة الفورية (.calc-preview)
   04 لوحة الإجمالي (.totals)
   05 جدول البنود (.calc-table) + الحالة الفارغة
   06 قسم المعادلة (.formula / .steps) + الجدول المرجعي (.ref)
   ===================================================================== */

/* ===== 01 LAYOUT ==================================================== */
.calc {
  display: grid; gap: var(--s-5);
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "form" "totals" "rows";
}
.calc__form { grid-area: form; }
.calc__side { grid-area: totals; }
.calc__rows { grid-area: rows; }
@media (min-width: 1024px) {
  .calc {
    grid-template-columns: minmax(0, 1fr) 360px;
    grid-template-areas: "form totals" "rows totals";
    gap: var(--s-6);
    align-items: start;
  }
  .calc__side { position: sticky; inset-block-start: calc(var(--header-h) + var(--s-5)); }
}
@media (min-width: 1280px) {
  .calc { grid-template-columns: minmax(0, 1fr) 400px; gap: var(--s-8); }
}

/* ===== 02 CARD + SEGMENTED ======================================== */
.calc-card {
  display: grid; gap: var(--s-5); align-content: start;
  background: var(--white); border: 1px solid var(--line); border-radius: var(--r-2);
  padding: var(--s-5); box-shadow: var(--sh-1);
}
@media (min-width: 768px) { .calc-card { padding: var(--s-6); } }
.calc-card__head { display: grid; gap: var(--s-2); justify-items: start; }
.calc-card__head .h3 { font-size: var(--fs-lg); }
@media (min-width: 768px) { .calc-card__head .h3 { font-size: var(--fs-xl); } }
.calc-card__head--row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-3);
}

.segmented {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px;
  padding: 4px; background: var(--concrete); border-radius: var(--r-2);
}
.segmented__item { position: relative; min-width: 0; }
.segmented__item input {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer;
}
.segmented__box {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  min-height: 64px; padding: 8px 6px; border-radius: var(--r-1);
  font-family: var(--font-head); font-weight: 600; font-size: var(--fs-sm); line-height: 1.3; color: var(--steel);
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.segmented__box small {
  font-family: var(--font-body); font-weight: 400; font-size: var(--fs-xs); color: var(--slate); margin-block-start: 2px;
}
.segmented__item input:hover + .segmented__box { background: rgba(255, 255, 255, .6); color: var(--ink); }
.segmented__item input:checked + .segmented__box { background: var(--ink); color: var(--white); box-shadow: var(--sh-1); }
.segmented__item input:checked + .segmented__box small { color: var(--orange-light); }
.segmented__item input:focus-visible + .segmented__box { outline: 2px solid var(--orange-deep); outline-offset: 2px; }
@media (max-width: 479px) {
  .segmented { grid-template-columns: 1fr; }
  .segmented__box { flex-direction: row; justify-content: flex-start; gap: 8px; min-height: 48px; padding-inline: 14px; text-align: start; }
  .segmented__box small { margin: 0; }
  .segmented__box small::before { content: "— "; }
}

/* ===== 03 PREVIEW =================================================== */
.calc-preview {
  display: flex; gap: var(--s-3); align-items: center;
  min-height: 72px; padding: var(--s-4);
  background: var(--orange-tint); border: 1px dashed rgba(242, 106, 27, .45); border-radius: var(--r-1);
  transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.calc-preview.is-ready { border-style: solid; border-color: var(--orange); background: var(--orange-pale); }
.calc-preview__icon { flex: none; font-size: 24px; color: var(--orange-mid); }
.calc-preview__body { min-width: 0; display: grid; gap: 2px; }
.calc-preview__text { font-size: var(--fs-sm); color: var(--steel); line-height: 1.5; }
.calc-preview__result {
  font-family: var(--font-head); font-weight: 700; font-size: var(--fs-lg); color: var(--ink); line-height: 1.3;
  font-variant-numeric: lining-nums tabular-nums;
}
.calc-preview__result:empty { display: none; }
@media (min-width: 768px) { .calc-preview__result { font-size: var(--fs-xl); } }

/* ===== 04 TOTALS =================================================== */
.totals {
  position: relative; isolation: isolate; overflow: hidden;
  display: grid; gap: var(--s-4);
  padding: var(--s-5); border-radius: var(--r-2);
  background: var(--ink); color: var(--on-dark-soft);
  border-inline-start: 4px solid var(--orange); box-shadow: var(--sh-3);
}
.totals {
  /* زخرفة القوس البرتقالي (CSS فقط بدون صور) في الزاوية السفلية البعيدة عن النص */
  --arch-x: 12%; --arch-y: 118%; --arch-r: 210px;
}
.totals::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background-image:
    radial-gradient(circle at var(--arch-x) var(--arch-y), rgba(242, 106, 27, .34) 0, rgba(242, 106, 27, .10) calc(var(--arch-r) * .72), rgba(242, 106, 27, 0) var(--arch-r)),
    radial-gradient(circle at var(--arch-x) var(--arch-y), rgba(255, 179, 71, 0) calc(var(--arch-r) - 1.5px), rgba(255, 179, 71, .55) calc(var(--arch-r) - .5px), rgba(255, 179, 71, .55) calc(var(--arch-r) + .5px), rgba(255, 179, 71, 0) calc(var(--arch-r) + 1.5px)),
    radial-gradient(circle at var(--arch-x) var(--arch-y), rgba(255, 179, 71, 0) calc(var(--arch-r) * 1.28 - 1.5px), rgba(255, 179, 71, .28) calc(var(--arch-r) * 1.28 - .5px), rgba(255, 179, 71, .28) calc(var(--arch-r) * 1.28 + .5px), rgba(255, 179, 71, 0) calc(var(--arch-r) * 1.28 + 1.5px)),
    repeating-linear-gradient(135deg, rgba(255, 179, 71, .05) 0 1px, rgba(255, 179, 71, 0) 1px 26px);
  background-repeat: no-repeat, no-repeat, no-repeat, repeat;
}
.totals::after {
  /* تعتيم خفيف جهة النص (البداية) حتى تبقى الأرقام واضحة فوق التوهج */
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: linear-gradient(to left, rgba(29, 21, 18, .35), rgba(29, 21, 18, 0));
}
/* .totals__eyebrow = نمط العناوين الصغيرة الموحّد في base.css (القسم 17) */
.totals__live { display: grid; gap: var(--s-3); }
.totals__main { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.totals__value {
  font-family: var(--font-head); font-weight: 700; line-height: 1.05;
  font-size: clamp(2.5rem, 2rem + 2vw, 3.5rem); color: var(--orange);
  background: var(--grad-orange); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  font-variant-numeric: lining-nums tabular-nums; overflow-wrap: anywhere;
}
.totals__unit { font-family: var(--font-head); font-weight: 600; font-size: var(--fs-lg); color: var(--orange-light); }
.totals__grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-3);
  padding-block: var(--s-3); border-block: 1px solid rgba(255, 255, 255, .14);
}
.totals__grid > div { display: grid; gap: 2px; min-width: 0; }
.totals__grid dt { font-size: var(--fs-xs); color: var(--on-dark-muted); }
.totals__grid dd { font-family: var(--font-head); font-weight: 700; font-size: var(--fs-lg); color: var(--white); line-height: 1.2; text-align: start; }
.totals .btn--primary[aria-disabled="true"] { opacity: .5; cursor: not-allowed; pointer-events: auto; }
.totals .btn--primary[aria-disabled="true"]:hover { background: var(--grad-orange); border-color: transparent; box-shadow: none; }
.totals .btn--primary[aria-disabled="true"]:hover::before { opacity: 0; }
.totals__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.totals__actions .btn--secondary { color: var(--white); border-color: rgba(255, 255, 255, .55); }
.totals__actions .btn--secondary:hover { background: var(--white); color: var(--ink); border-color: var(--white); }
.totals__actions .btn--ghost { color: var(--on-dark-muted); min-height: 40px; padding-inline: 10px; }
.totals__actions .btn--ghost:hover { color: var(--white); }
.totals__actions .btn--ghost.is-armed { color: var(--error-on-dark); font-weight: 700; }
.totals__status { margin: 0; font-size: var(--fs-sm); }
.totals__status.is-success { background: rgba(30, 107, 58, .25); color: #CFEBD8; border-color: rgba(30, 107, 58, .6); }
.totals__status.is-error { background: rgba(180, 35, 24, .22); color: var(--error-on-dark); border-color: rgba(240, 154, 143, .4); }
.totals__note { font-size: var(--fs-xs); line-height: 1.6; color: var(--on-dark-dim); }

/* ===== 05 ROWS TABLE + EMPTY ======================================= */
.calc-empty {
  display: flex; flex-direction: column; align-items: center; gap: var(--s-2);
  padding: var(--s-6) var(--s-4); text-align: center;
  color: var(--slate); font-size: var(--fs-sm); line-height: 1.6;
  border: 1px dashed var(--line-strong); border-radius: var(--r-1); background: var(--paper);
}
.calc-empty .icon { color: var(--orange-mid); font-size: 20px; }
.calc-empty span { max-width: 36ch; }
.calc-table { min-width: 620px; }
.calc-table th, .calc-table td { white-space: nowrap; }
.calc-table tbody th { font-family: var(--font-head); }
.calc-table tbody td.calc-table__kg { font-weight: 600; color: var(--ink); }
.calc-table tfoot th { text-align: start; }
.calc-table tfoot td { font-family: var(--font-head); font-weight: 700; color: var(--ink); }
.row-del {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--r-1);
  color: var(--slate); border: 1px solid transparent;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.row-del .icon { font-size: 18px; }
.row-del:hover, .row-del:focus-visible { color: var(--error); border-color: var(--error); background: #FBEAE8; }
.calc-table__mode { font-size: var(--fs-xs); color: var(--slate); display: block; }

/* حركة بسيطة عند إضافة صف (تُلغى مع تقليل الحركة) */
@keyframes calc-row-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
html.js .calc-table tbody tr.is-new { animation: calc-row-in 280ms var(--ease); }
@media (prefers-reduced-motion: reduce) { html.js .calc-table tbody tr.is-new { animation: none; } }

/* ===== 06 FORMULA + STEPS + REFERENCE ============================== */
.formula-grid { --grid-gap: var(--s-5); }
.formula-card { display: grid; align-content: start; justify-items: start; gap: var(--s-2); }
.formula-card .card__title { margin-block-end: 0; }
.formula-card .card__text { font-size: 0.9375rem; line-height: 1.8; }
.formula {
  width: 100%; margin-block: var(--s-2) var(--s-3);
  padding: var(--s-4) var(--s-5); border-radius: var(--r-1);
  background: var(--ink); color: var(--white);
  font-family: var(--font-head); font-weight: 600; font-size: var(--fs-xl); line-height: 1.4; text-align: center;
  font-variant-numeric: lining-nums; letter-spacing: .02em;
  overflow-x: auto;
}
.formula sup { font-size: .6em; vertical-align: super; color: var(--orange-light); }
.formula__var { color: var(--orange-light); font-style: italic; }
.formula__op { color: var(--on-dark-muted); padding-inline: .15em; }

.steps { --grid-gap: var(--s-4); }
.step {
  display: grid; gap: 4px; align-content: start;
  padding: var(--s-5); border-radius: var(--r-2);
  background: var(--paper); border: 1px solid var(--line);
}
.step__n {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: var(--grad-orange); color: var(--ink);
  font-family: var(--font-head); font-weight: 700; font-size: var(--fs-md); margin-block-end: var(--s-2);
}
.step__title { font-family: var(--font-head); font-weight: 700; font-size: var(--fs-base); }
.step__text { font-size: var(--fs-sm); color: var(--steel); line-height: 1.7; }

.ref {
  background: var(--white); border: 1px solid var(--line); border-radius: var(--r-2); box-shadow: var(--sh-1);
}
.ref__summary {
  list-style: none; cursor: pointer;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-3);
  padding: var(--s-4) var(--s-5); border-radius: var(--r-2);
}
.ref__summary::-webkit-details-marker { display: none; }
.ref__summary::marker { content: ""; }
.ref__summary:hover .ref__title { color: var(--orange-deep); }
.ref__title { display: inline-flex; align-items: center; gap: 10px; font-family: var(--font-head); font-weight: 700; font-size: var(--fs-md); color: var(--ink); transition: color var(--dur) var(--ease); }
.ref__title .icon { font-size: 22px; color: var(--orange-mid); }
.ref__hint { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--slate); }
.ref__hint .icon { transition: transform var(--dur) var(--ease); }
.ref[open] .ref__hint .icon { transform: rotate(180deg); }
.ref__body { padding: 0 var(--s-5) var(--s-5); display: grid; gap: var(--s-3); }
.ref__note { font-size: var(--fs-sm); color: var(--slate); }
@media (max-width: 479px) {
  .ref__summary, .ref__body { padding-inline: var(--s-4); }
  .ref__hint { display: none; }
}

/* ===== 07 MOTION (GSAP) — حالات مساعدة لـ js/motion-products.js ============ */
/* أثناء حركة GSAP فقط: نعطّل انتقالات CSS حتى لا تتنازع مع التحويل المضمّن (تعود بعد finish) */
html.gsap .is-animating { transition: none; }
/* الصف الجديد: GSAP يتولى الانزلاق بدل keyframe الـ CSS */
html.gsap .calc-table tbody tr.is-new { animation: none; }
/* مبدّل طريقة الحساب: مؤشر داكن ينزلق تحت الخيار المحدد (x/y من JS) */
html.gsap .segmented { position: relative; }
html.gsap .segmented__item { z-index: 1; }
html.gsap .segmented--thumb .segmented__item input:checked + .segmented__box { background: transparent; box-shadow: none; }
.segmented__thumb {
  position: absolute; left: 0; top: 0; z-index: 0;
  border-radius: var(--r-1); background: var(--ink); box-shadow: var(--sh-1);
  pointer-events: none; will-change: transform;
}
/* الجدول المرجعي: أثناء حركة الإغلاق نعيد سهم «اضغط للعرض» مبكرًا */
html.gsap .ref.is-closing .ref__hint .icon { transform: none; }
