/* ==========================================================================
   Calculator page — v3 (brand/identity.html, "the ledger")
   --------------------------------------------------------------------------
   Loaded last on tools/*.html, after style.css and src/ui/enhanced.css, so
   it can restyle the shared template without touching the markup: the
   calculator engines read input ids, and 84 pages share this structure.

   The idea: a calculation is a ledger that ends in "=". On wide screens the
   widget splits in two — inputs on the start side, the answer on the other —
   so the result sits next to the numbers that made it instead of a screen
   below them. The main figure is the hero of the page; the other result
   lines read as ledger rows under it.

   Selectors are prefixed with .tool-page so they outrank the older layers
   (style.css has three passes over these components, enhanced.css a fourth).
   ========================================================================== */

.tool-page {
  --tp-radius: 22px;
  --tp-radius-sm: 12px;
  --tp-line: color-mix(in srgb, var(--primary-text) 14%, transparent);
  --tp-field: var(--bg);
  --tp-shadow: 0 1px 2px rgba(26, 58, 92, .06), 0 12px 32px -12px rgba(26, 58, 92, .16);
  /* The brand bars: a long one (the question) over a short one (the answer). */
  --tp-bars: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 40'%3E%3Crect x='0' y='6' width='60' height='11' rx='5.5'/%3E%3Crect x='22' y='23' width='38' height='11' rx='5.5'/%3E%3C/svg%3E");
  max-width: 1160px;
}

/* ── Top of the page: one edge for everything ──────────────────────────
   The breadcrumb, the share bar main.js inserts after it, and the title used
   to sit on three different edges (the bar was a centred 900px box, the
   breadcrumb carried its own container padding). The page is now a grid:
   breadcrumb and share bar share the first row, start and end, and every
   other block spans the full width under them. */

.tool-page {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 16px;
  align-content: start;
}
.tool-page > * { grid-column: 1 / -1; min-width: 0; }
.tool-page > .breadcrumb {
  grid-column: 1;
  grid-row: 1;
  max-width: none;
  margin: 0;
  padding: 0;
  min-height: 40px;
  align-self: center;
  border-block-end: 0;
}
.tool-page > .share-bar {
  grid-column: 2;
  grid-row: 1;
  align-self: center;
  max-width: none;
  margin: 0;
  padding: 0;
  gap: 6px;
  flex-wrap: nowrap;
}
.tool-page .share-bar .share-label { font-size: var(--text-xs, 13px); font-weight: 500; }
/* Neutral until hovered: five brand-coloured discs were the loudest thing
   above the title. */
.tool-page .share-bar .share-btn {
  width: 34px;
  height: 34px;
  min-height: 34px;
  border: 1px solid var(--tp-line);
  background: var(--surface);
  color: var(--text-muted);
  transition: color .18s ease, border-color .18s ease, background-color .18s ease;
}
.tool-page .share-bar .share-btn svg { width: 16px; height: 16px; }
.tool-page .share-bar .share-btn:hover { transform: none; opacity: 1; color: #fff; border-color: transparent; }
.tool-page .share-bar .share-whatsapp:hover { background: #25d366; }
.tool-page .share-bar .share-twitter:hover { background: #000; }
.tool-page .share-bar .share-facebook:hover { background: #1877f2; }
.tool-page .share-bar .share-telegram:hover { background: #0088cc; }
.tool-page .share-bar .share-copy:hover { background: var(--primary); }

/* ── Header ─────────────────────────────────────────────────────────────── */

.tool-page .tool-header {
  position: relative;
  margin: 28px 0 28px;
  padding: 0;
  padding-inline-end: 56px;
  border-bottom: 0;
}
/* The per-page icon above the title was often unrelated to the tool (a copy
   icon on the end-of-service page) and pushed the title off the page edge. */
.tool-page .tool-header > .tool-icon { display: none; }
.tool-page .tool-header h1 {
  font-size: clamp(28px, 3.6vw, 42px);
  line-height: 1.35;
  color: var(--text);
  margin: 0 0 12px;
  max-width: 26ch;
}
.tool-page .tool-header .desc {
  font-size: var(--text-md, 18px);
  line-height: 1.8;
  color: var(--text-muted);
  max-width: 64ch;
  margin: 0;
}
/* One-number questions ("القدم كام سم") answered before the calculator,
   so a visitor who only needs the factor has it without scrolling. */
.tool-page .tool-header .quick-answer {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 18px 0 0;
  max-width: 64ch;
  border-block: 1px solid var(--border);
}
.tool-page .tool-header .quick-answer > div { min-width: 0; padding: 12px 14px; }
.tool-page .tool-header .quick-answer > div + div { border-inline-start: 1px solid var(--border); }
.tool-page .tool-header .quick-answer dt { font-size: var(--text-sm, 14px); color: var(--text-muted); }
.tool-page .tool-header .quick-answer dd { margin: 2px 0 0; font-size: var(--text-md, 18px); color: var(--text); font-variant-numeric: tabular-nums; }
.tool-page .tool-header .quick-answer b { font-weight: 700; color: var(--primary-text); }
.tool-page .tool-header .quick-answer-more { margin: 10px 0 0; font-size: var(--text-sm, 14px); }
.tool-page .tool-header .quick-answer-more a { color: var(--primary-text); }
@media (max-width: 560px) {
  .tool-page .tool-header .quick-answer { grid-template-columns: minmax(0, 1fr); }
  .tool-page .tool-header .quick-answer > div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 2px; }
  .tool-page .tool-header .quick-answer > div + div { border-inline-start: 0; border-top: 1px solid var(--border); }
  .tool-page .tool-header .quick-answer dd { margin: 0; }
}
.tool-page .tool-header .last-updated {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px !important;
}
.tool-page .tool-header .last-updated::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success, #27ae60);
}
/* favorites.js styles its button for a dark hero (white on glass), which
   left it all but invisible on this light header. */
.tool-page .tool-header .fav-btn--floating {
  top: 4px;
  inset-inline-end: 0;
  width: 42px;
  height: 42px;
  border: 1px solid var(--tp-line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text-muted);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.tool-page .tool-header .fav-btn--floating:hover {
  color: var(--primary-text);
  border-color: var(--primary-text);
  background: var(--surface);
  transform: none;
}
.tool-page .tool-header .fav-btn--floating.is-active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

/* ── Widget shell ───────────────────────────────────────────────────────── */

.tool-page .calculator-widget {
  background: var(--surface);
  border: 1px solid var(--tp-line);
  border-radius: var(--tp-radius);
  box-shadow: var(--tp-shadow);
  overflow: visible;
  margin-bottom: 48px;
}
.tool-page .widget-header {
  background: none;
  color: var(--text);
  border: 0;
  border-bottom: 1px solid var(--tp-line);
  padding: 18px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.tool-page .widget-header::before,
.tool-page .widget-header::after { display: none; }
.tool-page .widget-header h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base, 16px);
  font-weight: 600;
  color: var(--text);
  line-height: 1.5;
}
.tool-page .widget-header .sec-icon {
  flex: none;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
}
.tool-page .widget-header #dataStatus { font-size: var(--text-xs, 13px); color: var(--text-muted); }
.tool-page .widget-header #dataStatus:empty { display: none; }

.tool-page .widget-body { padding: 28px; }

/* Two columns once the answer has room beside the inputs. Every child but
   the results goes in the first column; the results span the explicit rows,
   and the closing 1fr row takes their extra height so the input rows keep
   their own size instead of being stretched apart. */
@media (min-width: 960px) {
  .tool-page .widget-body:has(> .results-area) {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    grid-template-rows: repeat(8, auto) 1fr;
    column-gap: 36px;
    row-gap: 0;
    align-items: start;
  }
  .tool-page .widget-body:has(> .results-area) > * { grid-column: 1; }
  .tool-page .widget-body:has(> .results-area) > .results-area {
    grid-column: 2;
    grid-row: 1 / -1;
    margin: 0;
    position: sticky;
    top: 84px;
  }
}

/* ── Inputs ─────────────────────────────────────────────────────────────── */

.tool-page .form-grid {
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 18px 16px;
}
.tool-page .form-group { gap: 8px; }
.tool-page .form-group label {
  font-size: var(--text-sm, 14px);
  font-weight: 600;
  color: var(--text);
  line-height: 1.5;
}
.tool-page .widget-body input[type="number"],
.tool-page .widget-body input[type="text"],
.tool-page .widget-body input[type="date"],
.tool-page .widget-body input[type="email"],
.tool-page .widget-body input:not([type]),
.tool-page .widget-body select,
.tool-page .form-group input,
.tool-page .form-group select {
  min-height: 52px;
  padding: 12px 16px;
  border: 1.5px solid var(--tp-line);
  border-radius: var(--tp-radius-sm);
  background: var(--tp-field);
  color: var(--text);
  font-family: inherit;
  font-size: var(--text-md, 17px);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  box-shadow: none;
  transition: border-color .18s ease, box-shadow .18s ease, background-color .18s ease;
}
.tool-page .widget-body input::placeholder { color: color-mix(in srgb, var(--text-muted) 70%, transparent); font-weight: 400; }
.tool-page .widget-body input:hover,
.tool-page .widget-body select:hover { border-color: color-mix(in srgb, var(--primary-text) 35%, transparent); }
.tool-page .widget-body input:focus,
.tool-page .widget-body select:focus {
  outline: none;
  border-color: var(--primary-text);
  background: var(--surface);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 28%, transparent);
}
.tool-page .widget-body input[aria-invalid="true"],
.tool-page .widget-body .form-group.error input {
  border-color: var(--error-text, #b13c2f);
}

/* Field notes were amber boxes inside the grid; now a quiet aside. */
.tool-page .field-note {
  margin: 2px 0 0;
  padding: 0;
  padding-inline-start: 12px;
  border: 0;
  border-inline-start: 2px solid var(--accent);
  border-radius: 0;
  background: none;
  font-size: var(--text-xs, 13px);
  line-height: 1.75;
  color: var(--text-muted);
}

/* ── The calculate button: the "=" of the ledger ───────────────────────── */

.tool-page .calc-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  margin-top: 24px;
  padding: 14px 24px;
  border: 0;
  border-radius: 14px;
  background: var(--primary);
  color: #fff;
  font-family: inherit;
  font-size: var(--text-md, 18px);
  font-weight: 700;
  letter-spacing: normal;
  box-shadow: 0 10px 24px -12px color-mix(in srgb, var(--primary) 70%, transparent);
  transition: background-color .18s ease, transform .12s ease, box-shadow .18s ease;
  cursor: pointer;
  opacity: 1;
}
.tool-page .calc-btn::before {
  content: "";
  width: 22px;
  height: 15px;
  flex: none;
  background: var(--accent);
  -webkit-mask: var(--tp-bars) center / contain no-repeat;
          mask: var(--tp-bars) center / contain no-repeat;
}
.tool-page .calc-btn:hover { background: var(--primary-dark, #12283f); transform: none; opacity: 1; }
.tool-page .calc-btn:active { transform: translateY(1px); box-shadow: none; }
.tool-page .calc-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.tool-page .review-stamp {
  margin-top: 16px;
  font-size: var(--text-xs, 13px);
  line-height: 1.8;
  color: var(--text-muted);
}

/* ── Results ────────────────────────────────────────────────────────────── */

/* Before the first calculation the answer column shows what will appear
   there, so the split layout never opens on an empty half. */
@media (min-width: 960px) {
  .tool-page .widget-body > .results-area:empty {
    display: grid;
    place-items: center;
    align-content: center;
    gap: 14px;
    min-height: 320px;
    border: 1.5px dashed var(--tp-line);
    border-radius: 20px;
    background: color-mix(in srgb, var(--primary-text) 3%, transparent);
    text-align: center;
  }
  .tool-page .widget-body > .results-area:empty::before {
    content: "";
    width: 84px;
    height: 56px;
    background: var(--primary-text);
    opacity: .18;
    -webkit-mask: var(--tp-bars) center / contain no-repeat;
            mask: var(--tp-bars) center / contain no-repeat;
  }
  .tool-page .widget-body > .results-area:empty::after {
    content: "النتيجة هتظهر هنا";
    font-size: var(--text-md, 18px);
    font-weight: 600;
    color: var(--text-muted);
  }
}

.tool-page .results-area {
  margin-top: 28px;
  padding: 0;
  border: 0;
}
/* result-actions.js adds a fuller bar (copy, WhatsApp, print) at the end;
   the renderer's own copy/share pair would then appear twice. */
.tool-page .results-area:has(.result-actions-bar) .result-actions { display: none; }
.tool-page .result-actions-bar {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--tp-line);
  justify-content: flex-start;
}

/* "The next step" block that intent.js appends after the results: full
   width under both columns, so its links get a row instead of a stack. */
@media (min-width: 960px) {
  .tool-page .widget-body:has(> .results-area) > .intent-block {
    grid-column: 1 / -1;
    max-width: none;
    margin: 28px 0 0;
  }
}
.tool-page .intent-block {
  border: 1px solid var(--tp-line);
  border-radius: 18px;
  background: color-mix(in srgb, var(--primary-text) 4%, var(--surface));
}
.tool-page .intent-block .ib-item {
  border: 1px solid var(--tp-line);
  background: var(--surface);
}
.tool-page .results-area.show { animation: tp-rise .35s cubic-bezier(.2, .8, .2, 1) both; }

.tool-page .results-grid,
.tool-page .results-grid.enhanced {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 0;
}
/* Ledger rows: label on the start side, figure on the end, dashed rule. */
.tool-page .results-grid .result-item,
.tool-page .results-grid.enhanced .result-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding: 13px 4px;
  margin: 0;
  background: none;
  border: 0;
  border-bottom: 1px dashed var(--tp-line);
  border-radius: 0;
  box-shadow: none;
  color: var(--text);
  transform: none;
  text-align: start;
}
.tool-page .results-grid .result-item:hover { transform: none; box-shadow: none; }
.tool-page .results-grid .result-item .r-label {
  font-size: var(--text-sm, 14px);
  font-weight: 500;
  color: var(--text-muted);
  opacity: 1;
  margin: 0;
  text-transform: none;
  letter-spacing: normal;
}
.tool-page .results-grid .result-item .r-value {
  font-size: var(--text-md, 18px);
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.tool-page .results-grid .result-item .r-tooltip {
  flex-basis: 100%;
  font-size: var(--text-xs, 13px);
  color: var(--text-muted);
  opacity: 1;
}

/* The answer: first, large, on navy, introduced by the bars. */
.tool-page .results-grid .result-item.highlight,
.tool-page .results-grid.enhanced .result-item.highlight {
  order: -1;
  display: grid;
  gap: 6px;
  justify-items: start;
  padding: 22px 24px 24px;
  margin-bottom: 10px;
  border: 0;
  border-radius: 20px;
  background: var(--primary);
  color: #fff;
  box-shadow: 0 18px 40px -20px color-mix(in srgb, var(--primary) 80%, transparent);
}
.tool-page .results-grid .result-item.highlight + .result-item.highlight { margin-top: 0; }
.tool-page .results-grid .result-item.highlight .r-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: rgba(255, 255, 255, .82);
  font-size: var(--text-sm, 15px);
}
.tool-page .results-grid .result-item.highlight .r-label::before {
  content: "";
  width: 20px;
  height: 14px;
  flex: none;
  background: var(--accent);
  -webkit-mask: var(--tp-bars) center / contain no-repeat;
          mask: var(--tp-bars) center / contain no-repeat;
}
.tool-page .results-grid .result-item.highlight .r-value {
  color: #fff;
  font-size: clamp(30px, 3.4vw, 42px);
  font-weight: 700;
  line-height: 1.25;
}
.tool-page .results-grid .result-item.highlight .r-tooltip { color: rgba(255, 255, 255, .75); }

/* Copy / share sit right under the figure, as quiet text buttons. */
.tool-page .result-actions {
  justify-content: flex-start;
  gap: 8px;
  margin: 16px 0 0;
  flex-wrap: wrap;
}
.tool-page .action-btn {
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--tp-line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-sm, 14px);
  font-weight: 600;
  box-shadow: none;
  transition: border-color .18s ease, background-color .18s ease;
}
.tool-page .action-btn:hover {
  border-color: var(--primary-text);
  background: color-mix(in srgb, var(--primary-text) 6%, transparent);
  transform: none;
}

.tool-page .result-explanation,
.tool-page .result-sources,
.tool-page .result-recommendations {
  margin-top: 18px;
  border-radius: 16px;
}
.tool-page .result-explanation {
  border: 1px solid var(--tp-line);
  background: var(--surface);
  overflow: hidden;
}
.tool-page .explanation-toggle {
  min-height: 50px;
  font-weight: 600;
  color: var(--text);
  background: none;
}
.tool-page .result-sources {
  border: 0;
  border-inline-start: 3px solid var(--primary-text);
  border-radius: 0;
  border-start-end-radius: 12px;
  border-end-end-radius: 12px;
  background: color-mix(in srgb, var(--primary-text) 5%, transparent);
}
.tool-page .rec-card {
  border: 1px solid var(--tp-line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: none;
}
.tool-page .rec-card:hover { border-color: var(--primary-text); transform: none; }

@keyframes tp-rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ── The article under the calculator: a reading column, not a card ────── */

.tool-page > .content-section,
.tool-page > article.content-section,
.tool-page > nav.content-section {
  /* width:100% because a grid item with auto side margins shrinks to its
     content; short sections (related tools) came out narrower than the rest. */
  width: 100%;
  max-width: 760px;
  margin-inline: auto;
  margin-bottom: 40px;
  padding: 0;
  background: none;
  border: 0;
  box-shadow: none;
}
.tool-page .content-section h2 {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 40px 0 14px;
  font-family: var(--font-display);
  font-size: clamp(22px, 2.4vw, 27px);
  font-weight: 700;
  line-height: 1.45;
  color: var(--text);
  letter-spacing: normal;
}
.tool-page .content-section > h2:first-child { margin-top: 0; }
.tool-page .content-section h2::before {
  content: "";
  width: 22px;
  height: 15px;
  flex: none;
  background: var(--accent);
  -webkit-mask: var(--tp-bars) center / contain no-repeat;
          mask: var(--tp-bars) center / contain no-repeat;
}
.tool-page .content-section h3 {
  margin: 26px 0 10px;
  font-size: var(--text-lg, 20px);
  font-weight: 700;
  color: var(--primary-text);
}
.tool-page .content-section p,
.tool-page .content-section li {
  font-size: 17px;
  line-height: 1.95;
  color: var(--text);
}
.tool-page .content-section ul,
.tool-page .content-section ol { padding-inline-start: 22px; }
.tool-page .content-section ul li::marker { color: var(--accent); }
.tool-page .content-section table {
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--tp-line);
}

/* FAQ: plain rows divided by rules; the question carries the weight. */
.tool-page .faq-section .faq-item {
  border-top: 1px solid var(--tp-line);
  padding: 18px 0;
}
.tool-page .faq-section .faq-item:first-of-type { border-top: 0; }
.tool-page .faq-section .faq-q {
  font-size: var(--text-md, 17px);
  font-weight: 600;
  color: var(--text);
  gap: 16px;
}
.tool-page .faq-section .faq-a { font-size: 16px; line-height: 1.9; color: var(--text-muted); }

/* Related tools */
.tool-page .related-grid { gap: 12px; }
.tool-page .related-grid a {
  border: 1px solid var(--tp-line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: none;
  transition: border-color .18s ease, transform .18s ease;
}
.tool-page .related-grid a:hover { border-color: var(--primary-text); transform: translateY(-2px); }

/* ── Small screens ──────────────────────────────────────────────────────── */

@media (max-width: 640px) {
  /* The share bar drops under the breadcrumb; until main.js adds it, the
     header holds its row so the title does not jump down. */
  .tool-page { grid-template-columns: minmax(0, 1fr); }
  .tool-page > .share-bar { grid-column: 1; grid-row: 2; margin-top: 8px; }
  .tool-page > .breadcrumb + .tool-header { margin-top: 70px; }
  .tool-page .tool-header { margin-top: 22px; padding-inline-end: 52px; }
  .tool-page .tool-header .desc { font-size: var(--text-base, 16px); }
  .tool-page .calculator-widget { border-radius: 18px; }
  .tool-page .widget-header { padding: 14px 18px; }
  .tool-page .widget-body { padding: 20px 18px 22px; }
  .tool-page .form-grid { grid-template-columns: minmax(0, 1fr); }
  .tool-page .results-grid .result-item.highlight { padding: 20px; }
  .tool-page .content-section p,
  .tool-page .content-section li { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .tool-page .results-area.show { animation: none; }
  .tool-page .related-grid a:hover { transform: none; }
}
