/* Base: reset, type scale, utilities, buttons and form controls. Colours and fonts come from tokens.css only. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: var(--bg); }
html.no-scroll { overflow: hidden; }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--text);
  font-family: var(--font-ui); font-size: 14px; line-height: 1.5;
  font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
:lang(ar) body, body:lang(ar) { line-height: 1.7; }
h1, h2, h3, h4, p, ul, ol, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
img, svg { display: block; }
abbr[title] { text-decoration: none; cursor: help; }
[hidden] { display: none !important; }
strong { font-weight: 600; }

bdi.n { unicode-bidi: isolate; direction: ltr; font-variant-numeric: tabular-nums; }
.money { white-space: nowrap; }
.cur { font-size: max(12px, 0.86em); color: var(--text-3); font-weight: 500; }
.neg { color: var(--loss); }
.pos { color: var(--profit); }
.muted { color: var(--text-3); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; letter-spacing: 0.01em; }
.vh, .vh-file { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ico { flex: none; }
[dir="rtl"] .flip { transform: scaleX(-1); }
p.small:has(> .ico:first-child), p.muted:has(> .ico:first-child) { display: flex; gap: 6px; align-items: flex-start; }
p.small > .ico, p.muted > .ico { margin-top: 2px; }

/* Type */
.h1 { font-size: 24px; line-height: 1.25; font-weight: 600; letter-spacing: -0.015em; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.h2 { font-size: 18px; line-height: 1.3; font-weight: 600; letter-spacing: -0.01em; }
.h3 { font-size: 15px; line-height: 1.35; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.h4 { font-size: 14px; line-height: 1.4; font-weight: 600; display: flex; align-items: center; gap: 8px; }
:lang(ar) .h1, :lang(ar) .h2 { letter-spacing: 0; }
.lbl { display: block; font-size: 12px; color: var(--text-3); font-weight: 500; }

/* Focus */
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
#main:focus, .al-card:focus { outline: none; }
.skip { position: absolute; inset-inline-start: 12px; top: -80px; z-index: 100; background: var(--surface); color: var(--text); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow-2); }
.skip:focus { top: calc(12px + env(safe-area-inset-top)); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; min-width: 44px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--line-2); background: var(--surface); color: var(--text);
  font-weight: 500; font-size: 14px; text-decoration: none; cursor: pointer; white-space: nowrap;
  box-shadow: var(--shadow-1); transition: background-color 150ms ease, border-color 150ms ease, transform 150ms ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.btn-primary:hover { background: var(--ink); opacity: 0.9; }
.btn-quiet { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn-quiet:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { min-height: 44px; padding: 0 12px; font-size: 13px; }
.btn.is-on { border-color: var(--profit); color: var(--profit); background: var(--profit-bg); }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 8px; border: 0;
  background: transparent; color: var(--text-2); cursor: pointer; transition: background-color 150ms ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.lang-txt { font-size: 13px; font-weight: 600; }
.link { color: var(--text-2); font-weight: 500; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-2); min-height: 44px; display: inline-flex; align-items: center; }
.link:hover { color: var(--text); text-decoration-color: currentColor; }

/* Fields */
.field { display: grid; gap: 6px; margin: 0 0 16px; border: 0; padding: 0; min-width: 0; }
.f-label { font-size: 13px; font-weight: 500; color: var(--text-2); padding: 0; }
.field input[type="text"], .field input[type="email"], .field input[type="password"], .field select, .search input {
  width: 100%; min-height: 44px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--text); font-size: 16px;
}
.field input[type="file"] { font-size: 14px; min-height: 44px; }
.field input::placeholder, .search input::placeholder { color: var(--text-3); }
.f-err { color: var(--loss); font-size: 13px; display: flex; gap: 6px; align-items: center; }
.checks, .radios { display: grid; gap: 4px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--ink); margin: 0; }
@media (min-width: 1024px) { .field input, .field select, .search input { font-size: 14px; } }

/* Switch */
.switch { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; background: none; border: 0; padding: 0; cursor: pointer; text-align: start; }
/* Off: outlined track and a solid thumb, both >= 3:1 against the surface. On: filled ink track */
.sw-track { width: 36px; height: 20px; border-radius: 10px; background: var(--surface); border: 2px solid var(--text-3); position: relative; flex: none; transition: background-color 150ms ease, border-color 150ms ease; }
.sw-thumb { position: absolute; top: 2px; inset-inline-start: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--text-3); transition: transform 180ms ease, background-color 150ms ease; }
.switch[aria-checked="true"] .sw-track { background: var(--ink); border-color: var(--ink); }
.switch[aria-checked="true"] .sw-thumb { background: var(--on-ink); transform: translateX(16px); }
[dir="rtl"] .switch[aria-checked="true"] .sw-thumb { transform: translateX(-16px); }
.sw-label { font-weight: 500; }

/* Segmented control */
.seg { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 2px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--line); }
.seg button { min-height: 40px; padding: 0 12px; border: 0; border-radius: 7px; background: transparent; color: var(--text-2); font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }
.cnt { color: var(--text-3); font-size: 12px; }

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