:root {
  --ink: #10251e;
  --muted: #5d6c66;
  --green: #073d2d;
  --green-2: #0d5a43;
  --gold: #c8a85b;
  --paper: #f7f7f2;
  --surface: #ffffff;
  --line: #d9ded9;
  --error: #a63131;
  --focus: #1679d3;
  --shadow: 0 18px 50px rgba(7, 61, 45, .12);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); }
body { margin: 0; min-height: 100svh; color: var(--ink); background: var(--paper); }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
[hidden] { display: none !important; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.no-js { padding: 12px; color: #fff; background: var(--error); text-align: center; font-weight: 700; }
.preview-banner { padding: 8px 12px; color: #251c05; background: #f2d77f; text-align: center; font-size: 12px; font-weight: 800; }
.brand { color: #fff; text-decoration: none; font-family: Georgia, serif; font-size: 22px; font-weight: 700; line-height: 1; letter-spacing: 0; }
.brand span { color: var(--gold); }
.brand-dark { color: var(--green); }
.eyebrow { margin: 0 0 5px; color: var(--green-2); font-size: 11px; font-weight: 800; text-transform: uppercase; }

.site-header {
  min-height: 52px;
  padding: 0 max(16px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #fff;
  background: var(--green);
}
.header-status { display: flex; align-items: center; gap: 8px; font-size: 12px; color: #dbe8e2; }
.header-status span { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); }

.calculator-page { width: min(1120px, 100%); min-height: calc(100svh - 52px); margin: 0 auto; padding: 18px; display: grid; align-content: start; gap: 10px; }
.calculator { padding: 28px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.calculator-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.calculator-heading h1 { margin: 0; font-family: Georgia, serif; font-size: 38px; line-height: 1.06; letter-spacing: 0; }
.disclaimer { margin: 7px 0 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.calculation-status { min-height: 14px; margin: 5px 0 0; color: var(--green-2); font-size: 10px; font-weight: 750; line-height: 1.2; opacity: 0; transition: opacity .16s ease; }
.calculation-status.visible { opacity: 1; }
.calculation-status[data-tone="checking"] { color: var(--muted); }
.calculation-status[data-tone="muted"] { color: var(--muted); }
.icon-button { width: 44px; height: 44px; flex: 0 0 44px; display: inline-grid; place-items: center; border: 1px solid var(--line); border-radius: 8px; color: var(--green); background: #fff; font-size: 24px; cursor: pointer; }
.icon-button:hover { border-color: var(--green-2); }

.calculator-layout { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-areas: "price down months" "monthly markup total" "tariffs empty actions" "description empty actions"; column-gap: 30px; row-gap: 12px; align-items: start; }
.tariff-fieldset { grid-area: tariffs; min-width: 0; margin: 0; padding: 0; border: 0; }
.tariff-fieldset legend { margin-bottom: 9px; padding: 0; color: var(--ink); font-size: 12px; font-weight: 800; }
.tariff-tabs { display: flex; align-items: stretch; flex-wrap: wrap; gap: 5px; }
.tariff-tab { min-width: 48px; min-height: 40px; padding: 5px 11px; overflow: hidden; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); font-size: 12px; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.tariff-tab[aria-checked="true"] { color: #fff; border-color: var(--green); background: var(--green); }
.tariff-tab:hover { border-color: var(--green-2); }

.tariff-description { grid-area: description; min-height: 24px; margin: 0; display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 10px; line-height: 1.35; }
.tariff-description > span:first-child { width: 17px; height: 17px; flex: 0 0 17px; display: grid; place-items: center; border: 1px solid var(--green-2); border-radius: 50%; color: var(--green-2); font-size: 10px; font-weight: 850; line-height: 1; }
.tariff-description > span:last-child { min-width: 0; flex: 1 1 auto; display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.control-group { min-width: 0; min-height: 112px; padding: 0; }
[data-control="price"] { grid-area: price; }
[data-control="down"] { grid-area: down; }
[data-control="months"] { grid-area: months; }
.control-group > label { min-height: 20px; display: block; color: var(--ink); font-size: 12px; font-weight: 800; }
.number-shell { width: 100%; height: 54px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 7px; padding: 0 14px; border: 1px solid var(--line); border-radius: 6px 6px 3px 3px; background: #f7f8f6; }
.number-shell:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px rgba(22,121,211,.15); }
.number-shell.compact { width: 100%; }
.number-shell input { width: 100%; min-width: 0; padding: 0; border: 0; outline: 0; color: var(--ink); background: transparent; text-align: right; font-size: 18px; font-variant-numeric: tabular-nums; font-weight: 800; }
.number-shell span { color: var(--muted); font-size: 12px; font-weight: 700; }
.range { width: 100%; height: 4px; margin: 0; appearance: none; border-radius: 2px; background: linear-gradient(to right, var(--gold) 0 var(--fill, 0%), #d8dfdb var(--fill, 0%) 100%); cursor: pointer; }
.range::-webkit-slider-thumb { width: 18px; height: 18px; appearance: none; border: 3px solid #fff; border-radius: 50%; background: var(--green-2); box-shadow: 0 0 0 1px var(--green-2); }
.range::-moz-range-thumb { width: 14px; height: 14px; border: 3px solid #fff; border-radius: 50%; background: var(--green-2); box-shadow: 0 0 0 1px var(--green-2); }
.field-error { min-height: 15px; margin: -3px 0 0; color: var(--error); font-size: 10px; line-height: 1.2; }
.zero-down-preview-note { margin: -2px 0 0; color: #785a13; font-size: 9px; font-weight: 750; line-height: 1.25; }
.term-chips { display: none; gap: 5px; flex-wrap: wrap; }
.term-chip { min-height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 5px; color: var(--ink); background: #fff; font-size: 11px; font-weight: 750; cursor: pointer; }
.term-chip[aria-pressed="true"] { color: #fff; border-color: var(--green); background: var(--green); }

.result-cell { min-width: 0; min-height: 108px; padding: 16px 0 8px; display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-start; border-top: 2px solid var(--green); }
.result-monthly { grid-area: monthly; }
.result-markup { grid-area: markup; }
.result-total { grid-area: total; }
.result-cell strong { order: 1; display: block; color: var(--green); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 30px; font-weight: 800; line-height: 1.08; letter-spacing: 0; font-variant-numeric: tabular-nums lining-nums; font-feature-settings: "tnum" 1, "lnum" 1; white-space: nowrap; }
.result-markup strong { color: var(--green-2); }
.result-total strong { font-weight: 850; }
.result-cell span { order: 2; min-height: 28px; margin-top: 8px; display: flex; align-items: flex-start; color: var(--muted); font-size: 11px; font-weight: 700; line-height: 1.2; }
.result-cell strong.result-updated { animation: result-update .16s ease-out; }
.result-cell small { order: 3; margin-top: 9px; display: block; color: var(--muted); font-size: 9px; }

.calculator-actions { grid-area: actions; min-height: 42px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; }
.text-button { min-height: 40px; padding: 0; border: 0; color: var(--green-2); background: transparent; font-weight: 750; text-decoration: underline; text-underline-offset: 4px; cursor: pointer; }
.share-status { color: var(--muted); font-size: 12px; line-height: 1.35; }
.button { min-height: 42px; padding: 0 18px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--green); border-radius: 6px; color: var(--green); background: #fff; font-weight: 800; text-decoration: none; cursor: pointer; }
.button.primary, .application-button { color: var(--green); border-color: var(--gold); background: var(--gold); }
.button-icon { font-size: 14px; line-height: 1; }
.application-button, .submit-application { justify-self: end; white-space: nowrap; }
.button:hover { filter: brightness(.97); }
.button:disabled { opacity: .5; cursor: not-allowed; }

.contact-strip { min-height: 48px; padding: 7px 13px; display: flex; align-items: center; justify-content: center; gap: 22px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255,255,255,.86); }
.contact-strip a { min-height: 32px; display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; text-decoration: none; }
.contact-strip strong { color: var(--ink); font-size: 13px; }
.contact-strip .whatsapp-link { min-height: 36px; padding: 0 14px; color: #fff; border-radius: 6px; background: #167d4b; font-size: 12px; font-weight: 800; }

.full-mode-content { padding: 34px 28px; border-top: 1px solid var(--line); }
.full-mode-copy { max-width: 650px; }
.full-mode-copy h2 { margin: 0; font-family: Georgia, serif; font-size: 30px; }

.application-dialog { width: min(760px, calc(100% - 24px)); max-height: calc(100svh - 24px); padding: 0; overflow-y: auto; border: 0; border-radius: 8px; box-shadow: 0 30px 100px rgba(0,0,0,.28); }
.application-dialog::backdrop { background: rgba(5,24,18,.68); }
.application-dialog form { padding: 24px; }
.dialog-head { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.dialog-head h2 { margin: 0; font-family: Georgia, serif; font-size: 28px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid label, .application-dialog label { color: var(--ink); font-size: 12px; font-weight: 750; }
.form-grid input { width: 100%; height: 42px; margin-top: 5px; padding: 0 11px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.form-grid input:focus { border-color: var(--focus); outline: 3px solid rgba(22,121,211,.14); }
.form-grid small, .consent-error { min-height: 15px; display: block; color: var(--error); font-size: 10px; }
.span-2 { grid-column: span 2; }
.consent-row { margin: 16px 0 0; display: grid; grid-template-columns: 20px 1fr; gap: 9px; line-height: 1.45; }
.consent-row input { width: 18px; height: 18px; margin: 0; }
.submit-application { width: 100%; margin-top: 12px; }
.form-error-summary { margin-bottom: 12px; padding: 10px 12px; color: #6a1717; border: 1px solid #e5b5b5; border-radius: 6px; background: #fff0f0; }
.form-error-summary.success { color: #075b36; border-color: #9dd0b5; background: #eef9f3; }
.honeypot { position: absolute !important; left: -9999px !important; }

.confirmation-page, .legal-page { background: var(--paper); }
.confirmation-shell, .legal-document { width: min(760px, calc(100% - 28px)); margin: 30px auto; padding: 30px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: var(--shadow); }
.confirmation-shell h1, .legal-document h1 { margin: 8px 0 18px; font-family: Georgia, serif; font-size: 34px; }
.confirmation-content { min-height: 180px; padding: 18px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.confirmation-content dl { margin: 0; }
.confirmation-content div { display: flex; justify-content: space-between; gap: 20px; padding: 7px 0; }
.confirmation-content dt { color: var(--muted); }
.confirmation-content dd { margin: 0; font-weight: 750; text-align: right; }
.confirmation-actions { margin-top: 18px; display: flex; gap: 10px; }
.legal-document { line-height: 1.6; }
.legal-document h2 { margin-top: 26px; font-size: 19px; }
.legal-unavailable, .legal-warning { padding: 16px; border-left: 3px solid var(--gold); background: #fbf8ec; }
.document-meta { color: var(--muted); font-size: 13px; }
.legal-print { margin-bottom: 18px; }
.approved-legal-text { white-space: normal; overflow-wrap: anywhere; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
@keyframes result-update { from { opacity: .55; transform: translateY(2px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 760px) {
  .site-header { min-height: 46px; padding-inline: 12px; }
  .brand { font-size: 19px; }
  .header-status { font-size: 10px; }
  .calculator-page { min-height: calc(100svh - 46px); padding: 8px; align-content: start; gap: 7px; }
  .calculator { padding: 14px; box-shadow: none; }
  .calculator-heading { margin-bottom: 8px; gap: 8px; }
  .calculator-heading h1 { font-size: 23px; line-height: 1.1; }
  .disclaimer { max-width: none; margin-top: 3px; font-size: 10px; line-height: 1.25; }
  .calculation-status { min-height: 11px; margin-top: 2px; font-size: 8px; }
  .reset-button { width: 44px; height: 44px; flex-basis: 44px; }
  .calculator-layout { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-areas: "tariffs tariffs tariffs" "description description description" "price price price" "down down down" "months months months" "monthly markup total" "actions actions actions"; gap: 7px 6px; }
  .tariff-fieldset { margin-bottom: 2px; }
  .tariff-fieldset legend { margin-bottom: 6px; font-size: 11px; }
  .tariff-description { min-height: 20px; margin: 2px 0; align-items: center; font-size: 9px; line-height: 1.25; }
  .tariff-description > span:first-child { width: 16px; height: 16px; flex-basis: 16px; font-size: 9px; }
  .tariff-tabs { gap: 3px; }
  .tariff-tab { min-height: 44px; padding-inline: 7px; font-size: 11px; line-height: 1.1; white-space: normal; }
  .control-group { min-height: 82px; padding: 5px 0 1px; }
  .control-group > label { min-height: 17px; font-size: 11px; }
  .number-shell, .number-shell.compact { width: 100%; height: 44px; border: 0; border-bottom: 2px solid var(--gold); border-radius: 4px 4px 0 0; background: #f6f7f5; }
  .number-shell input { font-size: 17px; text-align: right; }
  .range { height: 4px; margin: 0; }
  .field-error { min-height: 11px; font-size: 9px; }
  .zero-down-preview-note { margin-top: -4px; font-size: 8px; }
  .result-cell { min-height: 72px; padding: 8px 0 3px; }
  .result-cell strong { font-size: 14px; line-height: 1.1; }
  .result-cell span { min-height: 22px; margin-top: 5px; font-size: 8px; line-height: 1.15; }
  .result-cell small { display: none; }
  .calculator-actions { min-height: 38px; margin-top: 0; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
  .text-button { min-height: 44px; font-size: 11px; }
  .share-status { font-size: 10px; }
  .application-button { min-height: 40px; padding-inline: 14px; font-size: 11px; }
  .contact-strip { min-height: 48px; padding: 2px 7px; display: grid; grid-template-columns: minmax(90px, 1fr) minmax(0, 1fr) auto; gap: 4px; }
  .contact-strip a { min-width: 0; min-height: 44px; overflow: hidden; font-size: 0; text-overflow: ellipsis; white-space: nowrap; }
  .contact-strip strong { font-size: 11px; }
  .contact-strip .whatsapp-link { min-height: 44px; padding-inline: 9px; font-size: 10px; }
  .application-dialog { width: calc(100% - 12px); max-height: calc(100svh - 12px); }
  .application-dialog form { padding: 15px; }
  .form-grid { grid-template-columns: 1fr; gap: 8px; }
  .span-2 { grid-column: auto; }
  .confirmation-shell, .legal-document { width: calc(100% - 16px); margin: 8px auto; padding: 18px; }
  .confirmation-shell h1, .legal-document h1 { font-size: 28px; }
}

@media (max-width: 760px) and (max-height: 700px) {
  .site-header { min-height: 40px; }
  .brand { font-size: 17px; }
  .header-status { font-size: 9px; }
  .calculator-page { min-height: calc(100svh - 40px); padding: 5px 7px; gap: 4px; }
  .calculator { padding: 9px 11px; }
  .calculator-heading { margin-bottom: 4px; }
  .calculator-heading .eyebrow { display: none; }
  .calculator-heading h1 { font-size: 19px; }
  .disclaimer { margin-top: 1px; font-size: 8px; line-height: 1.15; white-space: normal; }
  .calculation-status { min-height: 9px; margin-top: 1px; font-size: 7px; }
  .reset-button { width: 38px; height: 38px; flex-basis: 38px; font-size: 20px; }
  .calculator-layout { gap: 4px 5px; }
  .tariff-fieldset legend { margin-bottom: 3px; font-size: 10px; }
  .tariff-tab { min-height: 36px; }
  .tariff-description { min-height: 16px; margin: 0; align-items: center; font-size: 8px; }
  .tariff-description > span:first-child { width: 15px; height: 15px; flex-basis: 15px; font-size: 8px; }
  .control-group { min-height: 70px; padding-top: 2px; }
  .control-group > label { min-height: 14px; font-size: 10px; }
  .number-shell, .number-shell.compact { height: 38px; }
  .number-shell input { font-size: 16px; }
  .field-error { min-height: 8px; }
  .result-cell { min-height: 58px; padding-top: 5px; }
  .result-cell strong { font-size: 13px; }
  .result-cell span { min-height: 18px; margin-top: 4px; font-size: 7px; }
  .calculator-actions { min-height: 32px; }
  .text-button { min-height: 36px; }
  .contact-strip { min-height: 42px; }
}

@media (max-width: 340px) {
  .calculator-page { overflow: auto; }
  .number-shell { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

@media print {
  .site-header, .legal-print { display: none !important; }
  .legal-document { width: 100%; margin: 0; padding: 0; border: 0; box-shadow: none; }
}

/* Wider desktop layout and collision-free mobile heading — v8 */
@media (min-width: 761px) {
  .calculator-page { width: min(1760px, calc(100% - 24px)); padding-inline: 0; }
  .calculator { width: 100%; }
}
@media (max-width: 760px) {
  .calculator-heading { display: grid; grid-template-columns: minmax(0, 1fr); align-items: start; gap: 8px; }
  .calculator-heading > div { min-width: 0; }
  .calculator-heading h1, .calculator-heading .disclaimer { max-width: 100%; overflow-wrap: anywhere; }
}
@media (max-width: 760px) and (max-height: 700px) {
  .calculator-heading { grid-template-columns: minmax(0, 1fr); gap: 6px; }
}

/* Safa Finance visual identity — v14 */
.brand {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  flex: 0 0 auto;
  min-width: 0;
  color: inherit;
  text-decoration: none;
  font-size: 0;
  line-height: 0;
}
.brand img {
  display: block;
  width: auto;
  height: 44px;
  max-width: min(235px, 52vw);
  object-fit: contain;
}
.site-header {
  color: var(--ink);
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.header-status { color: var(--muted); }
.header-status span { background: var(--gold); }

@media (max-width: 760px) {
  .site-header { min-height: 52px; }
  .brand img { height: 37px; max-width: 175px; }
}

@media (max-width: 760px) and (max-height: 700px) {
  .site-header { min-height: 46px; }
  .brand img { height: 33px; max-width: 158px; }
}
