/* getsafi.me/calculator, on top of landing.css (brand guidelines v2.3 §11). The boxes on a light
   canvas, the result as one card that reads as a screenshot: the brand, one hero figure, the
   figure a merchant thinks they made, and every cost in its own hue. Logical properties only. */

.calc-page .head { background: rgb(12 17 15 / 0.92); border-block-end-color: var(--f-line); }

/* ---------- Hero: the question, smaller than the answer ---------- */
.calc-hero { padding-block: clamp(24px, 4vw, 48px) clamp(28px, 4vw, 44px); position: relative; isolation: isolate; }
.calc-hero::before {
  content: ""; position: absolute; z-index: -1; inset-inline: -10%; inset-block: 0;
  background: radial-gradient(40% 60% at 30% 70%, rgb(31 174 106 / 0.22), transparent 70%);
  filter: blur(20px);
}
.calc-hero h1 {
  margin-block: 18px 12px; font-size: clamp(2.125rem, 4.6vw, 3.75rem); font-weight: 800; line-height: 1.04;
  letter-spacing: -0.035em; text-wrap: balance; max-inline-size: 18ch;
}
html[lang="ar"] .calc-hero h1 { letter-spacing: 0; line-height: 1.3; max-inline-size: 20ch; }
.calc-hero h1 .accent { color: var(--brand-lt); }

/* ---------- The canvas and its two columns ---------- */
.calc-canvas { padding-block: clamp(24px, 4vw, 56px); }
.calc-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(340px, 440px); gap: clamp(24px, 4vw, 56px); align-items: start; }
.calc-side { position: sticky; inset-block-start: 84px; display: grid; gap: 16px; }
@media (max-width: 900px) {
  .calc-grid { grid-template-columns: 1fr; }
  .calc-side { position: static; }
}

/* ---------- The boxes ---------- */
.calc-form { display: grid; gap: 12px; }
.grp {
  margin: 0; padding: clamp(18px, 2.4vw, 26px); border: 1px solid var(--line); border-radius: 20px; background: var(--elevated);
  min-inline-size: 0;
}
.grp legend {
  float: inline-start; inline-size: 100%; display: flex; align-items: center; gap: 10px; padding: 0; margin-block-end: 14px;
  font-weight: 700; font-size: 1.0625rem;
}
.grp legend + * { clear: both; }
.grp .n {
  inline-size: 26px; block-size: 26px; border-radius: 8px; display: inline-grid; place-items: center; flex: none;
  font-size: 0.8125rem; background: var(--surface); color: var(--ink-2);
  box-shadow: inset 0 -2px 0 var(--c, var(--brand));
}
.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.pair.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 560px) { .pair, .pair.three { grid-template-columns: 1fr; } }
.fld { display: grid; gap: 6px; align-content: start; min-inline-size: 0; }
.fld > label, .rate > span { font-weight: 600; font-size: 0.9375rem; color: var(--ink); }
.box {
  display: flex; align-items: center; min-block-size: 48px; border-radius: 12px; background: var(--elevated);
  border: 1px solid var(--line-strong); transition: border-color 160ms var(--settle), box-shadow 160ms var(--settle);
}
.box:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px rgb(10 125 68 / 0.18); }
.box:has(input[aria-invalid="true"]) { border-color: var(--loss); }
.box input {
  flex: 1; min-inline-size: 0; inline-size: 100%; border: 0; background: transparent; outline: none; color: var(--ink);
  font: inherit; font-size: 1rem; padding-inline: 14px; min-block-size: 46px;
  font-variant-numeric: tabular-nums lining-nums; direction: ltr; text-align: end;
}
/* the figure sits beside its unit: the unit is at the box's end, and the input is always LTR */
html[dir="rtl"] .box input { text-align: start; }
.box input::placeholder { color: var(--ink-3); }
.box .unit { padding-inline: 0 14px; color: var(--ink-2); font-size: 0.875rem; font-weight: 500; white-space: nowrap; }
.box.sm { min-block-size: 44px; }
.box.sm input { min-block-size: 42px; padding-inline: 10px; }
.box.sm .unit { padding-inline-end: 10px; }
.hint { color: var(--ink-2); font-size: 0.875rem; line-height: 1.6; }
.hint.top { margin-block-end: 12px; }
.err { color: var(--loss); font-size: 0.875rem; font-weight: 500; min-block-size: 0; }
.err:empty { display: none; }

/* the goods: a cost or a margin */
.seg-in { display: inline-flex; padding: 3px; background: var(--surface); border-radius: 999px; margin-block-end: 12px; max-inline-size: 100%; }
.seg-in label { position: relative; flex: 1; }
.seg-in input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg-in span {
  display: flex; align-items: center; justify-content: center; min-block-size: 44px; padding-inline: 16px; border-radius: 999px;
  font-size: 0.9375rem; font-weight: 600; color: var(--ink-2); white-space: nowrap; transition: background-color 180ms var(--settle), color 180ms;
}
.seg-in input:checked + span { background: var(--elevated); color: var(--ink); box-shadow: 0 1px 2px rgb(15 21 18 / 0.12); }
.seg-in input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

/* payment methods: one row each */
.mix { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 16px; }
@media (max-width: 560px) { .mix { grid-template-columns: 1fr; } }
.fld.row { grid-template-columns: minmax(0, 1fr) 112px; align-items: center; gap: 4px 12px; }
.fld.row .err { grid-column: 1 / -1; }
.mix-total { margin-block-start: 12px; font-size: 0.9375rem; font-weight: 600; color: var(--ink-2); min-block-size: 1.6em; }
.mix-total.off { color: var(--ink); }
.mix-total.off::before { content: ""; display: inline-block; inline-size: 8px; block-size: 8px; border-radius: 50%; background: #c98a00; margin-inline-end: 8px; }
.rates { margin-block-start: 8px; border-block-start: 1px solid var(--line); padding-block-start: 12px; }
.rates summary {
  cursor: pointer; font-weight: 600; font-size: 0.9375rem; color: var(--ink); min-block-size: 44px; display: flex; align-items: center; gap: 8px;
  list-style: none;
}
.rates summary::-webkit-details-marker { display: none; }
.rates summary::after { content: ""; inline-size: 8px; block-size: 8px; border-inline-end: 2px solid var(--ink-2); border-block-end: 2px solid var(--ink-2); transform: rotate(45deg) translateY(-2px); transition: transform 200ms var(--settle); }
.rates[open] summary::after { transform: rotate(225deg) translateY(-2px); }
.rates > .hint { margin-block: 4px 14px; }
.rate-head, .rate { display: grid; grid-template-columns: minmax(0, 1fr) 112px 128px; gap: 4px 10px; align-items: center; }
.rate-head { color: var(--ink-2); font-size: 0.8125rem; font-weight: 600; margin-block-end: 6px; }
.rate-head span:not(:first-child) { text-align: center; }
.rate { padding-block: 4px; }
.rate .err { grid-column: 1 / -1; }
@media (max-width: 420px) { .rate-head, .rate { grid-template-columns: minmax(0, 1fr) 96px 108px; } .rate > span { font-size: 0.875rem; } }

.privacy { color: var(--ink-2); font-size: 0.875rem; padding-inline: 4px; }

/* ---------- The result card: what a merchant screenshots ---------- */
.result {
  background: var(--elevated); border-radius: 24px; padding: clamp(20px, 2.6vw, 30px); isolation: isolate; position: relative; overflow: hidden;
  box-shadow: 0 1px 2px rgb(15 21 18 / 0.06), 0 30px 60px -30px rgb(15 21 18 / 0.28), 0 0 0 1px var(--line);
}
.r-head { display: flex; justify-content: space-between; align-items: center; color: var(--ink-2); font-size: 0.875rem; }
.r-head .brand { color: var(--ink); font-size: 1rem; gap: 8px; }
.r-head .mark { --s: 26px; }
.r-label { margin-block-start: 20px; color: var(--ink-2); font-weight: 600; font-size: 0.9375rem; }
.result .figure { font-size: clamp(2.75rem, 5vw, 4rem); margin-block: 2px 4px; color: var(--ink); transition: color 300ms var(--settle); }
.result .figure[data-len="11"], .result .figure[data-len="12"] { font-size: clamp(2.5rem, 4.4vw, 3.5rem); }
.result .figure[data-len="13"], .result .figure[data-len="14"] { font-size: clamp(2.125rem, 3.8vw, 3rem); }
.result .figure.profit { color: var(--profit); }
.result .figure.loss { color: var(--loss); }
.result .figure::before { opacity: 1; }
.result .figure.loss::before { background: radial-gradient(50% 50% at 50% 55%, rgb(198 45 42 / 0.12), transparent 70%); }
.result .figure:not(.profit):not(.loss)::before { opacity: 0; }
.r-empty { color: var(--ink-2); font-size: 0.9375rem; margin-block-start: 8px; }
.result:not(.is-empty) .r-empty { display: none; }
.result.is-empty .r-body { display: none; }
.result.is-empty .figure .cur { visibility: hidden; }

.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 18px 0 20px; }
.compare > div { background: var(--surface); border-radius: 14px; padding: 12px 14px; }
.compare dt { font-size: 0.8125rem; color: var(--ink-2); font-weight: 600; }
.compare dd { margin: 2px 0 0; font-size: 0.875rem; color: var(--ink-2); }
.compare dd.fig { white-space: nowrap; }
.compare dd.fig span { font-size: 0.8125rem; }
.compare dd b { font-size: clamp(1rem, 4.2vw, 1.1875rem); font-weight: 700; color: var(--ink); }
.compare dd.sm { font-size: 0.8125rem; }
.compare dd.sm b { font-size: inherit; font-weight: 600; color: var(--ink-2); }
.compare .ate.lost dd:not(.sm) b { color: var(--loss); }

.result .bar { block-size: 14px; }
.result .bar i[hidden] { display: none; }
.result .rows { margin-block-start: 14px; }
.result .rows li { padding-block: 8px; }
.result .rows li .tag {
  font-size: 0.8125rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: #fdf1d6; color: #7a5200;
}
.result .rows li .tag[hidden] { display: none; }
.result .rows li.missing b { color: var(--ink-2); font-weight: 500; }
.result .rows li.total.loss b { color: var(--loss); }
.calc-notes { list-style: none; margin: 14px 0 0; padding: 12px 14px; border-radius: 14px; background: #fdf1d6; color: #5c3d00; font-size: 0.875rem; display: grid; gap: 6px; }
.calc-notes[hidden] { display: none; }
.r-foot { display: flex; justify-content: space-between; align-items: center; margin-block-start: 18px; padding-block-start: 14px; border-block-start: 1px solid var(--line); color: var(--ink-2); font-size: 0.8125rem; font-weight: 600; }
.r-foot .url { color: var(--profit); }

/* ---------- Under the card: share, and the breakdown by email ---------- */
.r-actions { display: grid; gap: 10px; }
html:not(.has-result) .r-actions { display: none; }
.r-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-quiet { background: var(--surface); color: var(--ink); }
.btn-quiet:hover { background: var(--surface-2); }
.r-msg { font-size: 0.875rem; color: var(--ink-2); overflow-wrap: anywhere; }
.r-msg:empty { display: none; }
.r-mail { display: grid; gap: 8px; margin-block-start: 6px; }
.r-mail > label:first-child { font-weight: 600; font-size: 0.9375rem; }
.mail-row { display: flex; gap: 8px; }
.mail-row input {
  flex: 1; min-inline-size: 0; min-block-size: 48px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--elevated);
  font: inherit; font-size: 1rem; padding-inline: 14px; color: var(--ink); outline: none;
}
.mail-row input:focus { border-color: var(--focus); box-shadow: 0 0 0 3px rgb(10 125 68 / 0.18); }
.mail-row .btn { min-block-size: 48px; }
.r-mail .wl-msg { margin: 0; min-block-size: 0; }
.r-mail .wl-msg.is-ok { color: var(--profit); }
.r-mail .wl-msg.is-err { color: var(--loss); }

/* ---------- The close ---------- */
.calc-final h2 { font-size: clamp(2.75rem, 7vw, 5.5rem); }
.calc-final .sub { margin-block-end: 28px; }
.btn.big { min-block-size: 52px; padding-inline: 28px; font-size: 1rem; }

/* ---------- On a phone: the net rides the foot until the card is in view ---------- */
.calc-peek { display: none; }
@media (max-width: 900px) {
  .has-result .calc-peek {
    position: fixed; z-index: 40; inset-inline: 12px; inset-block-end: 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
    min-block-size: 56px; padding-inline: 18px; border-radius: 18px; text-decoration: none;
    background: rgb(12 17 15 / 0.94); color: var(--f-ink-2); font-weight: 600; font-size: 0.9375rem;
    box-shadow: 0 0 0 1px var(--f-line), 0 20px 40px -10px rgb(0 0 0 / 0.5);
    transition: transform 300ms var(--settle), opacity 300ms var(--settle);
  }
  .has-result .calc-peek.away { transform: translateY(140%); opacity: 0; pointer-events: none; }
  .calc-peek .figure { color: var(--brand-lt); font-size: 1.25rem; font-weight: 700; letter-spacing: -0.01em; }
  .calc-peek .figure.loss { color: #ff9b97; }
  .calc-peek .figure .cur { font-size: 0.8125rem; color: var(--f-ink-2); }
  .has-result .foot { padding-block-end: 96px; }
}
@media (prefers-reduced-motion: reduce) { .calc-peek { transition: none !important; } }
