/*
  Mo3dli : composants communs à toutes les pages
  (en-tête, pied de page, blocs de texte, tableaux, formules, préchargement)
  Coder : BEN MAAD ALAA EDDINE
*/

:root {
  --bg: #040507;
  --bg-2: #0c0f15;
  --surface: #11161f;
  --line: #1e2530;
  --text: #ababab;
  --text-strong: #d6d9de;
  --white: #ffffff;
  --green: #2ecc71;
  --blue: #3498db;
  --teal: #1ebba3;
  --teal-dark: #099983;
  --red: #ff0037;
  --sans: "Open Sans", "Segoe UI", Arial, sans-serif;
  --serif: "Libre Baskerville", Georgia, serif;
  --mono: Consolas, "Courier New", monospace;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  overflow-x: hidden;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

/* Accessibilité */
.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -60px;
  z-index: 1000;
  padding: 8px 16px;
  background: var(--teal);
  color: var(--white);
  border-radius: 24px;
  text-decoration: none;
  font-family: var(--sans);
}
.skip-link:focus {
  top: 12px;
}

a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

/* ---------- En-tête ---------- */
.site-header {
  background-color: var(--bg);
  border-top: 4px solid var(--red);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 10;
}
.site-header div {
  margin-bottom: 0;
}
.site-header__inner {
  max-width: 1170px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 24px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--white);
  text-decoration: none;
  font-family: var(--serif);
  font-size: 20px;
  font-weight: bold;
  letter-spacing: 2px;
  line-height: 1;
}
.brand:hover,
.brand:focus {
  color: var(--white);
}
.brand img {
  width: 36px;
  height: 36px;
}
.brand .heart,
.site-footer .heart {
  color: var(--red);
}
.site-nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
}
.site-nav a {
  display: inline-block;
  padding: 6px 0;
  color: var(--text);
  text-decoration: none;
  font-family: var(--sans);
  font-size: 13px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  line-height: 1.6;
  border-bottom: 2px solid transparent;
}
.site-nav a:hover,
.site-nav a:focus,
.site-nav a[aria-current="page"] {
  color: var(--white);
  border-bottom-color: var(--red);
}

/* ---------- Pied de page ---------- */
.site-footer {
  background-color: var(--bg);
  border-top: 1px solid var(--line);
  padding: 32px 16px 24px;
  text-align: center;
  color: var(--text);
  font-size: 15px;
  line-height: 1.7;
}
.site-footer div {
  margin-bottom: 0;
}
.site-footer__inner {
  max-width: 1170px;
  margin: 0 auto;
}
.site-footer .brand {
  margin-bottom: 18px;
}
.footer-links ul,
.social-links {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}
.footer-links ul {
  gap: 6px 22px;
  margin-bottom: 20px;
}
.footer-links a {
  color: var(--text);
  text-decoration: none;
  font-family: var(--sans);
  font-size: 14px;
  letter-spacing: 1px;
}
.footer-links a:hover,
.footer-links a:focus {
  color: var(--white);
  text-decoration: underline;
  text-decoration-color: var(--red);
}
.social-links {
  gap: 16px;
  margin-bottom: 20px;
}
.social-links a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background-color: #171515;
  color: #8a8a8a;
  transition: 0.4s;
}
.social-links svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}
.social-links .fb:hover,
.social-links .fb:focus {
  color: #4f74c4;
  box-shadow: 0 0 15px #3b5998;
}
.social-links .ig:hover,
.social-links .ig:focus {
  color: #e4405f;
  box-shadow: 0 0 15px #e4405f;
}
.social-links .mail:hover,
.social-links .mail:focus {
  color: #dd4b39;
  box-shadow: 0 0 15px #dd4b39;
}
.site-footer__legal {
  margin: 0 0 6px;
  font-size: 14px;
  letter-spacing: 1px;
}
.site-footer__legal .me {
  text-decoration: underline;
  text-decoration-color: var(--red);
}
.site-footer__note {
  margin: 0;
  font-size: 13px;
  color: #7d7d7d;
}

/* ---------- Blocs de texte (pages calculateurs, accueil, articles) ---------- */
.page-content {
  max-width: 860px;
  margin: 48px auto 0;
  padding: 0 16px;
  text-align: left;
  color: var(--text-strong);
  font-size: 16px;
  line-height: 1.8;
}
.page-content > :first-child {
  margin-top: 0;
}
.page-content h2 {
  margin: 44px 0 14px;
  color: var(--white);
  font-family: var(--sans);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.5px;
  line-height: 1.35;
  text-transform: none;
  text-decoration: none;
  text-align: left;
  padding: 0;
}
.page-content h2::after {
  content: "";
  display: block;
  width: 56px;
  height: 3px;
  margin-top: 10px;
  background-color: var(--red);
}
.page-content h3 {
  margin: 28px 0 10px;
  color: var(--white);
  font-family: var(--sans);
  font-size: 19px;
  line-height: 1.4;
}
.page-content p,
.page-content ul,
.page-content ol {
  margin: 0 0 16px;
}
.page-content ul,
.page-content ol {
  padding-left: 22px;
}
.page-content li {
  margin-bottom: 6px;
}
.page-content a {
  color: var(--green);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.page-content a:hover,
.page-content a:focus {
  color: var(--white);
}
.page-content strong {
  color: var(--white);
}
.page-content code {
  padding: 1px 6px;
  border-radius: 4px;
  background-color: var(--surface);
  color: var(--white);
  font-family: var(--mono);
  font-size: 0.9em;
}

/* Tableaux */
.table-wrap {
  overflow-x: auto;
  margin: 0 0 20px;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
  line-height: 1.5;
}
.data-table caption {
  caption-side: top;
  text-align: left;
  padding-bottom: 8px;
  color: var(--text);
  font-size: 14px;
}
.data-table th,
.data-table td {
  padding: 10px 14px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.data-table thead th {
  background-color: var(--line);
  color: var(--white);
  font-family: var(--sans);
  font-weight: 600;
}
.data-table tbody tr:nth-child(even) {
  background-color: rgba(30, 37, 48, 0.35);
}
.data-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.data-table tfoot td {
  font-weight: bold;
  color: var(--white);
}

/* Formules : toujours de gauche à droite, même dans un texte arabe */
.formula {
  direction: ltr;
  unicode-bidi: isolate;
  text-align: left;
  margin: 0 0 20px;
  padding: 14px 18px;
  background-color: var(--surface);
  border-left: 4px solid var(--green);
  border-radius: 6px;
  color: var(--white);
  font-family: var(--mono);
  font-size: 16px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}
.formula-inline {
  direction: ltr;
  unicode-bidi: isolate;
  font-family: var(--mono);
  color: var(--white);
  white-space: nowrap;
}
.data-table .formula-inline {
  white-space: normal;
  font-size: 14px;
}

/* Encadrés */
.example-box,
.note-box {
  margin: 0 0 20px;
  padding: 16px 20px;
  border-radius: 8px;
  background-color: var(--surface);
}
.example-box {
  border: 1px dashed var(--blue);
}
.example-box__title {
  display: block;
  margin-bottom: 6px;
  color: var(--blue);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
}
.note-box {
  border-left: 4px solid var(--red);
  font-size: 15px;
  color: var(--text);
}
.example-box > :last-child,
.note-box > :last-child {
  margin-bottom: 0;
}

/* Boutons d'appel à l'action */
.cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 8px 0 24px;
}
.cta-btn,
.page-content a.cta-btn {
  display: inline-block;
  padding: 10px 22px;
  border: 4px solid var(--teal-dark);
  border-radius: 50px;
  background-color: var(--teal);
  color: var(--white);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.4;
  text-decoration: none;
  text-align: center;
  transition: 0.25s;
}
.cta-btn:hover,
.cta-btn:focus,
.page-content a.cta-btn:hover,
.page-content a.cta-btn:focus {
  background-color: #0069d9;
  border-color: #0069d9;
  color: var(--white);
}
.cta-btn--ghost,
.page-content a.cta-btn--ghost {
  background-color: transparent;
  border: 2px solid var(--green);
  padding: 12px 24px;
}

/* Grille des sections (accueil, guides) */
.section-grid {
  list-style: none;
  margin: 0 0 24px;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}
.page-content .section-grid {
  padding-left: 0;
}
.section-grid li {
  margin: 0;
}
.section-grid a,
.page-content .section-grid a {
  display: block;
  height: 100%;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background-color: var(--surface);
  color: var(--text-strong);
  text-decoration: none;
  transition: 0.25s;
}
.section-grid a:hover,
.section-grid a:focus {
  border-color: var(--red);
  color: var(--white);
}
.section-grid strong {
  display: block;
  margin-bottom: 4px;
  font-family: var(--sans);
}
.section-grid span {
  display: block;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
}

/* Texte arabe */
[lang="ar"] {
  font-family: "Segoe UI", Tahoma, "Noto Naskh Arabic", "Amiri", sans-serif;
  letter-spacing: 0;
}
[dir="rtl"] .page-content,
.page-content [dir="rtl"],
[dir="rtl"].page-content,
[dir="rtl"] .page-content h2,
.page-content [dir="rtl"] h2 {
  text-align: right;
}
.page-content [dir="rtl"] ul,
.page-content [dir="rtl"] ol,
html[lang="ar"] body {
  font-family: "Segoe UI", Tahoma, "Noto Naskh Arabic", "Amiri", sans-serif;
}
[dir="rtl"] .page-content h2::after {
  margin-left: auto;
}

/* Bouton de langue FR | عربي (calculateurs et accueil) */
.lang-toggle {
  display: flex;
  gap: 2px;
  width: fit-content;
  margin: 0 0 4px auto;
  padding: 3px;
  border: 1px solid #1e2530;
  border-radius: 999px;
  background-color: #0d1219;
  font: 600 14px "Open Sans", "Segoe UI", Tahoma, Arial, sans-serif;
  line-height: 1;
}
[dir="rtl"] .lang-toggle {
  margin: 0 auto 4px 0;
}
.lang-toggle a,
.lang-toggle span {
  display: block;
  padding: 8px 14px;
  border-radius: 999px;
  text-decoration: none;
}
.lang-toggle a:link,
.lang-toggle a:visited {
  color: #ababab;
}
.lang-toggle a:hover {
  color: #ffffff;
  background-color: #151c27;
}
.lang-toggle a:focus-visible {
  outline: 3px solid #ffffff;
  outline-offset: 2px;
}
.lang-toggle [aria-current] {
  background-color: #1e2530;
  color: #ffffff;
}
[dir="rtl"] .note-box {
  border-left: 0;
  border-right: 4px solid var(--red);
}
[dir="rtl"] .data-table th,
[dir="rtl"] .data-table td,
[dir="rtl"] .data-table caption {
  text-align: right;
}
[dir="rtl"] .data-table .num {
  text-align: left;
}
[dir="rtl"] .page-content ul,
[dir="rtl"] .page-content ol {
  padding-left: 0;
  padding-right: 22px;
}

@media (max-width: 767px) {
  .site-header__inner {
    justify-content: center;
  }
  .site-nav ul {
    justify-content: center;
    gap: 2px 16px;
  }
  .site-nav a {
    font-size: 12px;
    letter-spacing: 1px;
  }
  .page-content {
    margin-top: 36px;
    font-size: 15.5px;
  }
  .page-content h2 {
    font-size: 21px;
  }
  .data-table th,
  .data-table td {
    padding: 8px 10px;
  }
  .formula {
    font-size: 14.5px;
    padding: 12px 14px;
  }
  .formula-inline {
    white-space: normal;
    overflow-wrap: anywhere;
  }
}
