/* =========================================================
   JISR | جسر — styles built from the JISR brand guidelines v1.0
   Colours, type, spacing, radii and states follow the guide.
   ========================================================= */
:root {
  /* Brand colours (guide p.07) */
  --navy: #0B1B35;       /* الكحلي الداكن */
  --blue: #102F63;       /* الأزرق الأساسي */
  --yellow: #FFC928;     /* الأصفر المميز */
  --bg: #F5F7FB;         /* الخلفيات */
  --border: #D9E2EF;     /* الحدود */
  --white: #FFFFFF;

  /* Derived semantic tokens */
  --text: var(--navy);
  --text-muted: #3E4C66;       /* 8.6:1 on white */
  --surface: var(--white);
  --focus: #1F5BD8;
  --error: #B42318;            /* 6.5:1 on white */
  --error-bg: #FEF3F2;
  --success: #106B3A;
  --success-bg: #ECFDF3;
  --border-strong: #8A9AB5;

  /* Type (guide p.08) */
  --font-ar: "Cairo", "Noto Naskh Arabic", system-ui, sans-serif;
  --font-en: "Poppins", system-ui, sans-serif;
  --font-ur: "Noto Naskh Arabic", "Cairo", serif;

  /* Spacing — 8px base (guide p.10) */
  --s1: 8px; --s2: 16px; --s3: 24px; --s4: 32px; --s6: 48px; --s8: 64px;
  --r-field: 12px;
  --r-card: 16px;
  --max: 1200px;
  --gutter: 16px;
  --shadow: 0 1px 2px rgba(11, 27, 53, .06), 0 8px 24px rgba(11, 27, 53, .06);
  --ease: cubic-bezier(.2, .8, .2, 1);
}
@media (min-width: 768px) { :root { --gutter: 24px; } }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 88px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ar);
  font-size: 16px;
  line-height: 1.8;
  text-rendering: optimizeLegibility;
  /* Arabic must never be letter-spaced: it breaks the joins between letters */
  letter-spacing: 0;
}
html[lang="en"] body { font-family: var(--font-en); line-height: 1.6; }
[lang="en"] { font-family: var(--font-en); }
[lang="ar"] { font-family: var(--font-ar); }
[lang="ur"], .ur { font-family: var(--font-ur); }
img { max-width: 100%; display: block; }
h1, h2, h3 { margin: 0; line-height: 1.4; font-weight: 700; text-wrap: balance; }
h2 { font-size: 24px; line-height: 1.5; }
@media (min-width: 768px) { h2 { font-size: 28px; } }
h3 { font-size: 18px; font-weight: 700; }
p { margin: 0; }
a { color: var(--blue); }

.container { width: 100%; max-width: var(--max); margin-inline: auto; padding-inline: var(--gutter); }
[hidden] { display: none !important; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Focus: blue 2px ring with 2px white gap (guide p.10) */
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; box-shadow: 0 0 0 2px var(--white); border-radius: 6px; }

.skip-link {
  position: absolute; inset-inline-start: 16px; top: -100px; z-index: 100;
  background: var(--yellow); color: var(--navy); padding: 10px 16px; border-radius: var(--r-field);
  font-weight: 700; text-decoration: none;
}
.skip-link:focus { top: 12px; }

.ic { width: 24px; height: 24px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ic-lg { width: 32px; height: 32px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s1);
  min-height: 48px; padding: 10px 22px; border-radius: var(--r-field);
  font: inherit; font-size: 16px; font-weight: 600; line-height: 1.5;
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
  transition: background-color .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease), box-shadow .15s var(--ease);
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: var(--white); }
.btn-primary:hover:not(:disabled) { background: var(--navy); }
.btn-primary-yellow { background: var(--yellow); color: var(--navy); }
.btn-primary-yellow:hover:not(:disabled) { background: #F2B800; }
.btn-outline { background: var(--white); color: var(--blue); border-color: var(--blue); }
.btn-outline:hover { background: var(--bg); }

.btn-icon {
  display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
  border-radius: var(--r-field); border: 1px solid var(--border); background: var(--white); color: var(--blue);
  cursor: pointer; transition: background-color .15s, border-color .15s, transform .1s; touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn-icon:hover:not(:disabled) { background: var(--bg); border-color: var(--blue); }
.btn-icon:active:not(:disabled) { transform: scale(.95); }
.btn-icon:disabled { opacity: .45; cursor: not-allowed; }
.btn-icon.is-active { background: var(--blue); color: var(--white); border-color: var(--blue); }
.btn-icon.is-done { color: var(--success); border-color: var(--success); }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 40;
  background: rgba(255, 255, 255, .94); backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; gap: var(--s2); min-height: 72px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--navy); }
.brand-logo { background: var(--white); border-radius: 10px; padding: 2px; border: 1px solid var(--border); }
.brand-logo img { width: 58px; height: auto; }
.brand-name { font-weight: 700; font-size: 20px; white-space: nowrap; }
.brand-name .sep { color: var(--border-strong); font-weight: 400; margin-inline: 2px; }
.brand-name .en-name { font-family: var(--font-en); font-size: 18px; }
.main-nav { display: none; gap: 4px; margin-inline-start: auto; }
.main-nav a {
  padding: 10px 14px; border-radius: var(--r-field); text-decoration: none; color: var(--text); font-weight: 600;
  min-height: 44px; display: inline-flex; align-items: center;
}
.main-nav a:hover { background: var(--bg); color: var(--blue); }
.ui-lang { margin-inline-start: auto; min-height: 44px; padding: 8px 14px; font-size: 15px; }
@media (min-width: 900px) { .main-nav { display: flex; } .ui-lang { margin-inline-start: 0; } }

/* ---------- Hero ---------- */
.hero { padding-block: var(--s4) var(--s8); background: var(--blue); color: var(--white); position: relative; }
.hero-grid { display: grid; gap: var(--s3); align-items: center; }
.eyebrow { font-family: var(--font-en); font-weight: 600; font-size: 14px; letter-spacing: .12em; color: var(--yellow); }
.hero h1 { font-size: 30px; line-height: 1.4; margin-block: var(--s1) var(--s2); }
.hero-sub { font-size: 17px; line-height: 1.8; color: #E3EAF6; max-width: 56ch; }
.lang-chip {
  display: inline-block; margin-top: var(--s3); background: var(--yellow); color: var(--navy);
  font-weight: 700; padding: 8px 16px; border-radius: var(--r-field);
}
.lang-chip [lang="en"] { font-weight: 600; }
.hero-logo { margin: 0; justify-self: center; background: var(--white); border-radius: var(--r-card); padding: var(--s2) var(--s3); text-align: center; color: var(--navy); }
.hero-logo img { width: min(240px, 60vw); height: auto; margin-inline: auto; }
.hero-logo figcaption { font-weight: 700; font-size: 18px; margin-top: 4px; }
.hero-logo figcaption [lang="en"] { font-family: var(--font-en); }
@media (min-width: 768px) {
  .hero { padding-block: var(--s6) 96px; }
  .hero-grid { grid-template-columns: 1.4fr 1fr; gap: var(--s6); }
  .hero h1 { font-size: 40px; }
  .hero-logo img { width: 260px; }
}

/* ---------- Translator ---------- */
.translator-section { margin-top: -48px; position: relative; z-index: 2; }
.translator-section:focus { outline: none; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); }
.translator { padding: var(--s2); box-shadow: var(--shadow); }
@media (min-width: 768px) { .translator { padding: var(--s4); } }
.tr-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px var(--s2); margin-bottom: var(--s2); }
.tr-hint { color: var(--text-muted); font-size: 15px; }

.lang-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: var(--s1); margin-bottom: var(--s2); }
@media (min-width: 768px) { .lang-bar { gap: var(--s2); } }
.field-select { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-select label { font-size: 14px; font-weight: 600; color: var(--text-muted); }
.field-select select {
  appearance: none; -webkit-appearance: none; width: 100%; min-height: 48px;
  border: 1px solid var(--border-strong); border-radius: var(--r-field); background: var(--white);
  color: var(--text); font: inherit; font-weight: 600; font-size: 16px; padding-block: 8px; padding-inline: 14px 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23102F63' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-size: 20px; background-position: left 12px center; cursor: pointer;
}
[dir="ltr"] .field-select select { background-position: right 12px center; }
.field-select select:hover { border-color: var(--blue); }
.swap { width: 48px; height: 48px; border-radius: 50%; }
.swap .ic { transition: transform .3s var(--ease); }
.swap.spin .ic { transform: rotate(180deg); }

.panes { display: grid; gap: var(--s2); }
@media (min-width: 768px) { .panes { grid-template-columns: 1fr 1fr; } }
.pane { background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-card); padding: var(--s2); display: flex; flex-direction: column; min-width: 0; }
.pane-tgt { background: #F0F4FA; }
.pane-label { font-size: 14px; font-weight: 700; color: var(--text-muted); margin-bottom: var(--s1); }
.tr-text {
  width: 100%; min-height: 168px; flex: 1; resize: vertical;
  border: 1px solid var(--border); border-radius: var(--r-field); background: var(--white);
  padding: 14px 16px; color: var(--text); font-size: 20px; line-height: 1.8;
  overflow-wrap: anywhere; white-space: pre-wrap;
}
.tr-text[lang="ar"] { font-family: var(--font-ar); }
.tr-text[lang="en"] { font-family: var(--font-en); line-height: 1.6; }
.tr-text[lang="ur"] { font-family: var(--font-ur); line-height: 2; }
textarea.tr-text:hover { border-color: var(--border-strong); }
textarea.tr-text:focus-visible { border-color: var(--focus); }
.tr-output { cursor: text; }
.tr-output .placeholder { color: #6B7891; font-size: 18px; font-family: var(--font-ar); }
html[lang="en"] .tr-output .placeholder { font-family: var(--font-en); }
.tr-output.loading { color: var(--text-muted); }
.tr-output .dots::after { content: "…"; animation: dots 1.2s steps(4) infinite; display: inline-block; width: 1.2em; text-align: start; overflow: hidden; vertical-align: bottom; }
@keyframes dots { 0% { width: 0 } 100% { width: 1.2em } }
.pane-tools { display: flex; align-items: center; justify-content: space-between; gap: var(--s1); margin-top: var(--s1); flex-wrap: wrap; }
.tool-group { display: flex; gap: var(--s1); margin-inline-start: auto; }
.count { font-family: var(--font-en); font-size: 13px; color: var(--text-muted); margin-top: 6px; text-align: end; }
.count.near { color: var(--error); font-weight: 600; }
.provider { font-family: var(--font-en); font-size: 12px; color: var(--text-muted); }

.mic { min-width: 148px; }
.mic.listening { background: var(--blue); color: var(--white); }
.mic.listening .ic { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.tr-actions { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); margin-top: var(--s2); flex-wrap: wrap; }
.tr-actions .btn-primary { min-width: 160px; }
@media (max-width: 479px) { .tr-actions .btn-primary { width: 100%; } }
.auto-toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; min-height: 44px; font-size: 15px; color: var(--text-muted); font-weight: 600; }
.auto-toggle input { width: 22px; height: 22px; accent-color: var(--blue); cursor: pointer; margin: 0; }

.status:empty { display: none; }
.status { margin-top: var(--s2); display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-field); font-size: 15px; line-height: 1.7; }
.status.info { background: var(--bg); border: 1px solid var(--border); color: var(--text); }
.status.error { background: var(--error-bg); border: 1px solid #F4C7C3; color: var(--error); }
.status .ic { width: 20px; height: 20px; margin-top: 3px; }
.status .retry { margin-inline-start: auto; min-height: 36px; padding: 4px 12px; font-size: 14px; border-color: var(--error); color: var(--error); background: var(--white); }
.disclaimer { margin-top: var(--s2); font-size: 14px; color: var(--text-muted); border-inline-start: 3px solid var(--yellow); padding-inline-start: 12px; line-height: 1.7; }

/* ---------- Ornament (Asiri-inspired, margins only) ---------- */
.ornament { display: flex; justify-content: center; gap: 22px; padding-block: var(--s6) 0; color: #9AA9C2; font-size: 18px; user-select: none; }
.ornament span:nth-child(even) { color: var(--yellow); }

/* ---------- Sections ---------- */
.section { padding-block: var(--s6) var(--s8); }
.section-alt { background: var(--white); border-block: 1px solid var(--border); }
.section-sub { color: var(--text-muted); font-size: 17px; margin-top: var(--s1); max-width: 70ch; }

/* Phrases */
.tabs { display: flex; gap: var(--s1); margin-block: var(--s3) var(--s2); overflow-x: auto; padding: 4px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: 8px; flex: none; min-height: 44px; padding: 8px 16px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--white); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; transition: background-color .15s, color .15s, border-color .15s;
}
.tab .ic { width: 20px; height: 20px; }
.tab:hover { border-color: var(--blue); }
.tab[aria-selected="true"] { background: var(--blue); color: var(--white); border-color: var(--blue); }
.tab[data-cat="emergency"][aria-selected="true"] { background: var(--error); border-color: var(--error); }
.phrase-grid { display: grid; gap: var(--s1); grid-template-columns: 1fr; }
.phrase-grid:focus-visible { border-radius: var(--r-card); }
@media (min-width: 640px) { .phrase-grid { grid-template-columns: 1fr 1fr; gap: 12px; } }
@media (min-width: 1024px) { .phrase-grid { grid-template-columns: repeat(3, 1fr); } }
.phrase {
  display: flex; flex-direction: column; align-items: stretch; gap: 2px; width: 100%; text-align: start;
  min-height: 64px; padding: 12px 16px; border-radius: var(--r-field); border: 1px solid var(--border);
  background: var(--white); color: var(--text); font: inherit; cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .1s;
}
.phrase:hover { border-color: var(--blue); box-shadow: var(--shadow); }
.phrase:active { transform: scale(.99); }
.phrase .p-main { font-weight: 600; font-size: 17px; line-height: 1.6; }
.phrase .p-sub { font-size: 14px; color: var(--text-muted); line-height: 1.5; }
.phrase .p-sub[lang="en"] { font-family: var(--font-en); }
.emergency-note { margin-top: var(--s3); display: flex; align-items: center; gap: 12px; padding: var(--s2); border-radius: var(--r-card); background: var(--error-bg); border: 1px solid #F4C7C3; color: var(--error); font-weight: 600; }
.em-num { font-family: var(--font-en); font-weight: 700; font-size: 22px; color: var(--error); margin-inline-start: 4px; }

/* Steps */
.steps { list-style: none; padding: 0; margin: var(--s3) 0 0; display: grid; gap: var(--s2); }
@media (min-width: 768px) { .steps { grid-template-columns: repeat(3, 1fr); gap: var(--s3); } }
.step { padding: var(--s3); position: relative; color: var(--blue); }
.step h3 { margin-block: 12px 6px; color: var(--navy); }
.step p { color: var(--text-muted); }
.step-num { position: absolute; inset-inline-end: 20px; top: 16px; font-family: var(--font-en); font-weight: 700; font-size: 28px; color: var(--yellow); line-height: 1; }

/* About */
.about-grid { display: grid; gap: var(--s2); margin-top: var(--s3); }
@media (min-width: 768px) { .about-grid { grid-template-columns: repeat(3, 1fr); gap: var(--s3); } }
.info { padding: var(--s3); background: var(--white); }
.info .ic { color: var(--blue); }
.info h3 { margin-block: 10px 6px; }
.info p { color: var(--text-muted); }

/* ---------- Footer ---------- */
.site-footer { background: var(--navy); color: #DCE4F2; padding-block: var(--s4); }
.footer-inner { display: flex; flex-direction: column; gap: var(--s3); align-items: flex-start; }
@media (min-width: 768px) { .footer-inner { flex-direction: row; align-items: center; justify-content: space-between; } }
.footer-brand { display: flex; align-items: center; gap: 14px; }
.footer-logo { background: var(--white); border-radius: 12px; padding: 4px; } /* logo stays on white on dark backgrounds */
.footer-logo img { width: 72px; height: auto; }
.footer-name { font-weight: 700; color: var(--white); font-size: 18px; }
.footer-desc { font-size: 14px; }
.rights { font-weight: 700; color: var(--white); font-family: var(--font-ar); font-size: 16px; border-top: 2px solid var(--yellow); padding-top: 10px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; inset-inline: 0; bottom: max(20px, env(safe-area-inset-bottom)); margin-inline: auto; width: max-content; max-width: calc(100% - 32px);
  background: var(--navy); color: var(--white); padding: 12px 20px; border-radius: var(--r-field); box-shadow: var(--shadow);
  font-weight: 600; z-index: 100; display: flex; gap: 8px; align-items: center;
  animation: toastIn .2s var(--ease);
}
.toast .ic { width: 20px; height: 20px; color: var(--yellow); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
@media print { .site-header, .tr-actions, .pane-tools, .tabs, .toast { display: none !important; } }

/* ---------- Small screens: translator first (guide p.11) ---------- */
@media (max-width: 767px) {
  .hero { padding-block: var(--s3) 64px; }
  .hero-logo { display: none; } /* logo stays in the header */
  .hero h1 { font-size: 28px; }
  .hero-sub { font-size: 16px; }
  .lang-chip { margin-top: var(--s2); }
}
@media (max-width: 400px) {
  .field-select select { padding-inline: 10px 32px; font-size: 15px; background-size: 16px; background-position: left 8px center; }
  [dir="ltr"] .field-select select { background-position: right 8px center; }
  .lang-bar { gap: 6px; }
  .swap { width: 44px; height: 44px; }
  .brand-logo img { width: 48px; }
  .brand-name { font-size: 18px; }
}
