/* ==========================================================================
   Base: reset, typography, focus, accessibility helpers.
   All spacing uses logical properties so RTL and LTR both work.
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: var(--lh);
  color: var(--text);
  background: var(--bg);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

h1,
h2,
h3,
h4,
p,
figure,
blockquote,
ul,
ol,
dl,
dd {
  margin: 0;
}

ul[role="list"],
ol[role="list"] {
  list-style: none;
  padding: 0;
}

h1,
h2,
h3,
h4 {
  line-height: var(--lh-tight);
  font-weight: var(--fw-bold);
  letter-spacing: -0.01em;
}

h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }

img,
svg,
video,
canvas {
  display: block;
  max-width: 100%;
}

img {
  height: auto;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
}

button:disabled {
  cursor: not-allowed;
}

a {
  color: var(--brand-text);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--sp-2) 0;
}

/* ---- Focus: visible ring for keyboard users only ---- */
:focus {
  outline: none;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* Headings and the main region get focus from script after navigation
   (for screen readers); they are not controls, so no ring. */
[tabindex="-1"]:focus {
  outline: none;
}

/* Keep the ring readable on brand-colored buttons */
.btn-primary:focus-visible,
.scan-fab:focus-visible {
  outline-color: var(--focus);
  outline-offset: 3px;
}

::selection {
  background: var(--brand-soft-2);
}

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

.skip-link {
  position: fixed;
  inset-inline-start: var(--sp-2);
  top: calc(var(--sp-1) + var(--safe-top));
  z-index: calc(var(--z-splash) + 1);
  padding: var(--sp-1) var(--sp-2);
  background: var(--brand);
  color: var(--text-on-brand);
  border-radius: var(--r-sm);
  font-weight: var(--fw-semibold);
  transform: translateY(-200%);
  transition: transform var(--dur-2) var(--ease);
}

.skip-link:focus {
  transform: translateY(0);
}

/* Numbers, phone numbers and codes always read left-to-right */
.ltr {
  direction: ltr;
  unicode-bidi: isolate;
}

bdi {
  unicode-bidi: isolate;
}

/* Icons inherit color and size from text */
.icon {
  width: 1.25em;
  height: 1.25em;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon.icon-fill {
  fill: currentColor;
  stroke: none;
}

/* Mirror direction-dependent icons (arrows, chevrons) in RTL */
[dir="rtl"] .icon.flip-rtl {
  transform: scaleX(-1);
}

/* ---- Text helpers ---- */
.muted { color: var(--text-2); }
.subtle { color: var(--text-3); }
.small { font-size: var(--fs-sm); }
.xsmall { font-size: var(--fs-xs); }
.bold { font-weight: var(--fw-bold); }
.semibold { font-weight: var(--fw-semibold); }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Layout helpers on the 8px grid ---- */
.stack { display: flex; flex-direction: column; }
.stack-1 { display: flex; flex-direction: column; gap: var(--sp-1); }
.stack-2 { display: flex; flex-direction: column; gap: var(--sp-2); }
.stack-3 { display: flex; flex-direction: column; gap: var(--sp-3); }
.stack-4 { display: flex; flex-direction: column; gap: var(--sp-4); }
.row { display: flex; align-items: center; gap: var(--sp-1); }
.row-2 { display: flex; align-items: center; gap: var(--sp-2); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.mt-1 { margin-top: var(--sp-1); }
.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }
.mb-1 { margin-bottom: var(--sp-1); }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-3 { margin-bottom: var(--sp-3); }
.hidden { display: none !important; }
