/*
 * TERA OPTIONS — shared components (buttons, inputs, cards, tabs, badges, tooltips, toasts, states).
 * Requires tokens.css. Hover looks only apply where a pointer can hover (on a phone they would stick
 * after a tap); every control also shows a pressed (:active) state, and touch screens get larger targets.
 */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; -webkit-tap-highlight-color: rgba(56, 189, 248, 0.12); }
body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font: 400 var(--fs-md) / var(--lh-body) var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg, canvas { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
/* no double-tap-to-zoom wait on controls */
a, button, input, select, textarea, label, summary, [role="button"], [role="tab"] { touch-action: manipulation; }
a { color: var(--c-cyan); text-decoration: none; }
@media (hover: hover) { a:hover { text-decoration: underline; text-underline-offset: 3px; } }
:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 3px; border-radius: 4px; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.skip-link {
  position: absolute; left: var(--s-4); top: -60px; z-index: 1000;
  background: var(--c-accent); color: #fff; padding: var(--s-2) var(--s-4); border-radius: var(--r-sm);
  transition: top var(--dur-2) var(--ease-out);
}
.skip-link:focus { top: var(--s-4); text-decoration: none; }

/* ---------- brand ---------- */
.brand { display: inline-flex; direction: ltr; align-items: center; gap: 10px; color: var(--c-text); text-decoration: none; }
.brand:hover { text-decoration: none; }
.logo-mark { flex: none; color: var(--c-logo); }
.wordmark { font-family: var(--font-wordmark); font-size: 15px; font-weight: 700; letter-spacing: 0.06em; white-space: nowrap; }
.wordmark b { font-weight: inherit; color: inherit; }

/* ---------- buttons ---------- */
.btn {
  --btn-bg: var(--c-surface-2);
  --btn-fg: var(--c-text);
  --btn-bd: var(--c-border-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: 44px; padding: 0 var(--s-5);
  border: 1px solid var(--btn-bd); border-radius: var(--r-md);
  background: var(--btn-bg); color: var(--btn-fg);
  font-weight: 600; font-size: var(--fs-sm); letter-spacing: 0.01em; white-space: nowrap;
  cursor: pointer; text-decoration: none; -webkit-tap-highlight-color: transparent;
  transition: background var(--dur-1) var(--ease-out), border-color var(--dur-1) var(--ease-out), transform var(--dur-1) var(--ease-out), box-shadow var(--dur-2) var(--ease-out);
}
.btn-primary { --btn-bg: var(--c-accent); --btn-bd: transparent; --btn-fg: #fff; box-shadow: 0 8px 24px -10px rgba(49, 95, 234, 0.8); }
.btn-secondary { --btn-bg: rgba(255, 255, 255, 0.03); }
.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; --btn-fg: var(--c-text-2); }
@media (hover: hover) {
  .btn:hover { text-decoration: none; background: var(--c-surface-3); }
  .btn-primary:hover { background: var(--c-accent-hover); box-shadow: var(--sh-glow); }
  .btn-ghost:hover { color: var(--c-text); background: rgba(255, 255, 255, 0.05); }
}
/* pressed: a light wash over whatever colour the button has, so every variant answers a tap */
.btn:active { transform: translateY(1px); background-image: linear-gradient(rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.09)); }
.btn-ghost:active { color: var(--c-text); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; transform: none; background-image: none; }
.btn-sm { height: 36px; padding: 0 var(--s-4); font-size: var(--fs-xs); border-radius: var(--r-sm); }
.btn-lg { height: 52px; padding: 0 var(--s-6); font-size: var(--fs-md); }
.btn-block { width: 100%; }
.btn .spinner { width: 16px; height: 16px; border-width: 2px; }
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- form fields ---------- */
.field { display: grid; gap: 6px; }
.field-label { font-size: var(--fs-sm); font-weight: 500; color: var(--c-text); }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }
.input-wrap { position: relative; display: flex; align-items: center; }
.input {
  width: 100%; height: 48px; padding: 0 var(--s-4);
  background: var(--c-bg-2); color: var(--c-text);
  border: 1px solid var(--c-border-strong); border-radius: var(--r-md);
  font-size: var(--fs-md);
  /* when a field scrolls into view (focus, errors), keep room for its label above and its error line below */
  scroll-margin: 72px 0 64px;
  transition: border-color var(--dur-1) var(--ease-out), box-shadow var(--dur-1) var(--ease-out), background var(--dur-1);
}
.input::placeholder { color: var(--c-text-3); }
@media (hover: hover) { .input:hover { border-color: rgba(148, 163, 184, 0.4); } }
.input:focus { outline: none; border-color: var(--c-accent); box-shadow: 0 0 0 4px var(--c-accent-soft); }
.input[aria-invalid="true"] { border-color: var(--c-down); }
.input[aria-invalid="true"]:focus { box-shadow: 0 0 0 4px rgba(240, 82, 90, 0.16); }
.input-wrap .input { padding-right: 52px; }
.input-action {
  position: absolute; right: 6px; height: 36px; padding: 0 10px; border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--c-text-2); cursor: pointer; display: grid; place-items: center;
  -webkit-tap-highlight-color: transparent;
}
@media (hover: hover) { .input-action:hover { color: var(--c-text); background: rgba(255, 255, 255, 0.05); } }
.input-action:active { color: var(--c-text); background: rgba(255, 255, 255, 0.08); }
.input-action svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.field-hint { font-size: var(--fs-xs); color: var(--c-text-3); }
.field-error { font-size: var(--fs-xs); color: #ff8a8f; display: flex; gap: 6px; align-items: flex-start; }
.field-error:empty { display: none; }

.check { display: flex; gap: var(--s-3); align-items: flex-start; cursor: pointer; font-size: var(--fs-sm); color: var(--c-text-2); line-height: 1.5; -webkit-tap-highlight-color: transparent; }
.check input {
  appearance: none; -webkit-appearance: none; flex: none; width: 18px; height: 18px; margin: 1px 0 0; border-radius: 5px;
  border: 1px solid var(--c-border-strong); background: var(--c-bg-2); display: grid; place-items: center; cursor: pointer;
  transition: background var(--dur-1), border-color var(--dur-1);
}
.check input::after { content: ''; width: 9px; height: 5px; border: 2px solid #fff; border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px) scale(0); transition: transform var(--dur-1) var(--ease-spring); }
.check input:checked { background: var(--c-accent); border-color: var(--c-accent); }
.check input:checked::after { transform: rotate(-45deg) translate(1px, -1px) scale(1); }
.check input[aria-invalid="true"] { border-color: var(--c-down); }
.check:active input { border-color: var(--c-focus); }

/* ---------- cards & surfaces ---------- */
.card {
  background: linear-gradient(180deg, rgba(20, 39, 64, 0.72), rgba(16, 31, 51, 0.72));
  border: 1px solid var(--c-border); border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
}
.surface { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-lg); }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px;
  border-radius: var(--r-pill); border: 1px solid var(--c-border-strong);
  font-size: 11px; font-weight: 600; letter-spacing: 0.04em; color: var(--c-text-2); white-space: nowrap;
}
.badge-accent { color: #a9c0ff; border-color: rgba(49, 95, 234, 0.45); background: var(--c-accent-soft); }
.badge-cyan { color: var(--c-cyan); border-color: rgba(56, 189, 248, 0.35); background: var(--c-cyan-soft); }
.badge-warn { color: var(--c-warn); border-color: rgba(242, 184, 75, 0.4); background: rgba(242, 184, 75, 0.1); }
/* the first box-shadow is the fallback for browsers without color-mix() (iOS before 16.2) */
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.16); box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 22%, transparent); }

/* ---------- tabs ---------- */
.tabs { display: inline-flex; gap: 4px; padding: 4px; background: var(--c-bg-2); border: 1px solid var(--c-border); border-radius: var(--r-md); }
.tab-btn {
  height: 36px; padding: 0 var(--s-4); border: 0; border-radius: var(--r-sm); background: transparent;
  color: var(--c-text-2); font-weight: 600; font-size: var(--fs-sm); cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: background var(--dur-2) var(--ease-out), color var(--dur-2) var(--ease-out);
}
@media (hover: hover) { .tab-btn:hover { color: var(--c-text); } }
.tab-btn:active { color: var(--c-text); background: rgba(255, 255, 255, 0.05); }
.tab-btn[aria-selected="true"] { background: var(--c-surface-3); color: var(--c-text); box-shadow: var(--sh-1); }

/* ---------- tooltip (extra detail only: anything a person needs must also be on the page) ---------- */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 8px); z-index: 20;
  transform: translate(-50%, 4px); width: max-content; max-width: 240px;
  padding: 6px 10px; border-radius: var(--r-sm); background: #1d3352; color: var(--c-text);
  font-size: 12px; font-weight: 500; line-height: 1.4; text-align: center; white-space: normal;
  box-shadow: var(--sh-2); opacity: 0; pointer-events: none;
  transition: opacity var(--dur-1) var(--ease-out), transform var(--dur-1) var(--ease-out);
}
[data-tip]:focus-visible::after { opacity: 1; transform: translate(-50%, 0); }
@media (hover: hover) { [data-tip]:hover::after { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- alerts / notifications ---------- */
.alert {
  display: flex; gap: var(--s-3); align-items: flex-start; padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md); border: 1px solid var(--c-border-strong); background: var(--c-surface);
  font-size: var(--fs-sm); line-height: 1.5; scroll-margin: 72px 0;
}
.alert svg { flex: none; width: 18px; height: 18px; margin-top: 1px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.alert-error { border-color: rgba(240, 82, 90, 0.45); background: rgba(240, 82, 90, 0.08); color: #ffc2c5; }
.alert-success { border-color: rgba(34, 179, 154, 0.45); background: rgba(34, 179, 154, 0.08); color: #a8f0e1; }
.alert-info { border-color: rgba(56, 189, 248, 0.35); background: var(--c-cyan-soft); color: #bfe9fc; }

/* ---------- loading / empty / error states ---------- */
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.25); border-top-color: currentColor;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--c-surface) 0%, var(--c-surface-2) 50%, var(--c-surface) 100%); background-size: 200% 100%; animation: shimmer 1.4s ease-in-out infinite; border-radius: var(--r-sm); }
@keyframes shimmer { to { background-position: -200% 0; } }
.state {
  display: grid; justify-items: center; gap: var(--s-2); padding: var(--s-10) var(--s-6);
  text-align: center; color: var(--c-text-2); font-size: var(--fs-sm);
}
.state-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--c-surface-2); color: var(--c-text-2); }
.state-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.state b { color: var(--c-text); font-size: var(--fs-md); }

/* ---------- phones and tablets ---------- */
/* iOS Safari zooms into any field under 16px when it gets focus (and stays zoomed), so phones get 16px */
@media (max-width: 600px), (pointer: coarse) {
  .input { font-size: 16px; }
}
/* fingers need bigger targets than a mouse: 44px for buttons, 40px for the small ones */
@media (pointer: coarse) {
  .btn { min-height: var(--tap); }
  .btn-sm { min-height: var(--tap-sm); }
  .tab-btn { min-height: var(--tap-sm); }
  .input-action { right: 2px; height: var(--tap); min-width: var(--tap); }
  .check input { width: 24px; height: 24px; margin-top: -2px; border-radius: 6px; }
  .check input::after { width: 11px; height: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 1.6s; }
  .skeleton { animation: none; }
}

/* page hand-off to the platform (js/page-leave.js) */
html.is-leaving body { opacity: 0; transform: scale(0.985); filter: blur(4px); transition: opacity 380ms var(--ease-out), transform 380ms var(--ease-out), filter 380ms var(--ease-out); pointer-events: none; }
html.is-leaving { background: #07111f; }
/* a full-page blur is costly on a phone's GPU: fade and scale only */
@media (pointer: coarse) { html.is-leaving body { filter: none; } }

/* Signed-in avatar in the public pages' nav (landing, offers, help). */
.nav-avatar { display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none; border-radius: 50%; overflow: hidden; background: linear-gradient(135deg, var(--c-accent), var(--c-cyan)); border: 2px solid rgba(255, 255, 255, 0.14); color: #fff; font-weight: 700; font-size: 15px; text-decoration: none; }
.nav-avatar[hidden] { display: none; }
.nav-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.nav-avatar:focus-visible { outline: 2px solid var(--c-cyan); outline-offset: 2px; }

/* ---------- language (js/i18n.js) ---------- */
html.i18n-wait body { opacity: 0; }
.lang-switch { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 12px; border: 1px solid var(--c-border); border-radius: var(--r-pill, 999px); background: transparent; color: var(--c-text-2); font: 600 13px/1 var(--font-sans); cursor: pointer; white-space: nowrap; }
.lang-switch:empty { display: none; }
.lang-switch[lang="ar"] { font-family: "IBM Plex Sans Arabic", var(--font-sans); font-size: 14px; }
.lang-switch:focus-visible { outline: 2px solid var(--c-cyan); outline-offset: 2px; }
@media (hover: hover) { .lang-switch:hover { color: var(--c-text); border-color: var(--c-text-3); } }
.lang-switch-wide { width: 100%; margin: 8px 0; }

/* Arabic: IBM Plex Sans Arabic for Arabic letters; Inter still draws Latin letters and digits, so prices line up the same. */
html[lang="ar"] {
  --font-sans: Inter, "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Inter Tight", "IBM Plex Sans Arabic", Inter, system-ui, sans-serif;
}
html[lang="ar"] body { font-family: var(--font-sans); line-height: 1.7; }
html[lang="ar"] body * { letter-spacing: 0 !important; } /* letter spacing breaks Arabic joining */
html[lang="ar"] h1, html[lang="ar"] h2, html[lang="ar"] h3 { line-height: 1.35; }
/* Charts, prices and codes stay left-to-right. */
html[dir="rtl"] canvas, html[dir="rtl"] code { direction: ltr; }
