/* FB Atlas shared web components — SOURCE OF TRUTH.
   Sheet modal · toggle · slider · card surface · webapp top bar ·
   section nav · unified login · home button · loader.
   Link dynamically from every web project, before the project's own stylesheet:
   <link rel="stylesheet" href="https://fb-atlas-ui-kit.web.app/atlas-components.css">
   Tokens: reads tokens.css custom properties (--core-*, --atlas-*) with safe fallbacks,
   so it works on any page that loads tokens.css (and degrades gracefully without it). */

/* ─────────────────────────────────────────────────────────────
   1. MODAL SHEET (.atlas-sheet) — THE dialog pattern
   ─ web port of the app bottom sheet: scrim60 → solid secondaryBackground,
     top radius 35, 30×4 grabber, X-circle close (top right), subtitle,
     full-bleed divider, sheet form fields, single 60px primary CTA.
   ─ structure:
       .atlas-sheet-scrim.open > .atlas-sheet
         .as-handle · .as-close (×) · .as-title · .as-sub · .as-divider
         .as-field / .as-row … · .as-error · .as-actions > .as-cta
   ─ close = X, scrim tap, or Esc. Validation: add .err to missing fields,
     text in .as-error, .shake on the sheet — never fail silently.
   ───────────────────────────────────────────────────────────── */
.atlas-sheet-scrim {
  position: fixed; inset: 0; z-index: 90;
  background: var(--atlas-scrim-6-0, rgba(0, 0, 0, 0.6));
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity .28s ease;
}
.atlas-sheet-scrim.open { opacity: 1; pointer-events: auto; }
.atlas-sheet {
  position: relative;
  background: var(--core-secondary-background, #FFFFFF);
  color: var(--core-primary-text, #121212);
  font-weight: 300;   /* type rule: 300 main, 400 labels only */
  width: 100%; max-width: 480px;
  max-height: 88svh; overflow-y: auto;
  border-radius: 35px 35px 0 0;
  padding: 0 24px calc(24px + env(safe-area-inset-bottom));
  transform: translateY(60px);
  transition: transform .38s cubic-bezier(.25, .9, .3, 1);
  box-shadow: 0 -12px 40px var(--atlas-shadow-1-0, rgba(0, 0, 0, 0.10));
}
.atlas-sheet-scrim.open .atlas-sheet { transform: none; }
.as-handle { width: 30px; height: 4px; border-radius: 100px; background: var(--core-secondary, #CBC4BC); margin: 12px auto 18px; }
.as-close {
  position: absolute; top: 14px; right: 16px;
  width: 36px; height: 36px; border: 0; border-radius: 100px; cursor: pointer;
  background: var(--core-tertiary, #F2F2F6); color: var(--core-primary, #776F6D);
  display: grid; place-items: center; font: inherit; font-size: 16px; line-height: 1;
  transition: transform .16s ease;
}
.as-close:active { transform: scale(.92); }
.as-title { font-size: 22px; font-weight: 300; margin-bottom: 4px; padding-right: 44px; }
.as-sub { font-size: 14px; font-weight: 300; color: var(--core-primary, #776F6D); line-height: 1.5; padding-right: 44px; }
.as-divider { height: 1px; background: rgba(139, 129, 126, 0.16); margin: 18px -24px 20px; }
.as-field { display: block; margin-bottom: 18px; }
.as-field > span {
  display: block; font-size: 12.5px; font-weight: 400; letter-spacing: .12em; text-transform: uppercase;
  color: var(--core-primary, #776F6D); margin-bottom: 4px;
}
.as-field > span small { text-transform: none; letter-spacing: .02em; opacity: .75; }
.as-field input, .as-field select, .as-field textarea {
  width: 100%; height: 48px; border: 0; border-bottom: 1px solid var(--core-secondary, #CBC4BC);
  border-radius: 0; background: transparent; color: var(--core-primary-text, #121212);
  font: inherit; font-size: 17px; outline: none;
  transition: border-color .2s ease;
}
.as-field textarea { height: auto; min-height: 64px; padding-top: 8px; resize: vertical; }
.as-field input:focus, .as-field select:focus, .as-field textarea:focus { border-bottom-color: var(--core-primary-text, #121212); }
.as-field.err input, .as-field.err select { border-bottom-color: var(--core-alternate, #F74827); }
.as-field.err > span { color: var(--core-alternate, #F74827); }
.as-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.as-error { color: var(--core-alternate, #F74827); font-size: 13.5px; margin: 2px 0 10px; }
/* sliders inside sheets are the same .atlas-slider — one slider everywhere */
.as-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 22px; }
.as-cta {
  width: 100%; height: 60px; border: 0; border-radius: 100px; cursor: pointer;
  /* CTA recipe = fill primaryBackground, label tertiary (matches the app's FFButton) */
  background: var(--core-primary-background, #000000); color: var(--core-tertiary, #F2F2F6);
  font: inherit; font-size: 15px; font-weight: 400; letter-spacing: .22em; text-indent: .22em; text-transform: uppercase;
  transition: transform .16s ease, opacity .16s ease;
}
.as-cta:active { transform: scale(.97); }
.as-cta:disabled { opacity: .45; }
.atlas-sheet.shake { animation: asShake .4s ease; }
@keyframes asShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); } 50% { transform: translateX(8px); } 75% { transform: translateX(-4px); }
}
@media (min-width: 640px) {
  .atlas-sheet-scrim { align-items: center; padding: 24px; }
  .atlas-sheet { border-radius: 35px; padding-bottom: 24px; transform: translateY(28px) scale(.97); }
}

/* ─────────────────────────────────────────────────────────────
   2. TOGGLE (.atlas-toggle) — iOS-style switch, ONE size (44×26)
   ─ structure: <label class="atlas-toggle"><input type="checkbox"><i></i></label>
   ─ on = success green, white knob.
   ───────────────────────────────────────────────────────────── */
.atlas-toggle { position: relative; display: inline-block; width: 44px; height: 26px; flex: none; }
.atlas-toggle input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.atlas-toggle i {
  position: absolute; inset: 0; border-radius: 100px;
  background: var(--core-secondary, #CBC4BC);   /* tokenized — stays visible in Midnight too */
  transition: background .2s ease;
}
.atlas-toggle i::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform .2s cubic-bezier(.3, .8, .3, 1);
}
.atlas-toggle input:checked + i { background: var(--core-success, #00783F); }
.atlas-toggle input:checked + i::after { transform: translateX(18px); }

/* ─────────────────────────────────────────────────────────────
   3. SLIDER (.atlas-slider) — iOS-style: colored fill follows the thumb
   ─ 6px track, 28px white thumb, 36px hit area.
   ─ fill color: --as-fill (default ink). Fill position: --as-p (0–100%).
     One line of JS keeps the fill in sync (WebKit needs it; Firefox is native):
       const sync = s => s.style.setProperty('--as-p',
         ((s.value - s.min) / ((s.max - s.min) || 1)) * 100 + '%');
       document.querySelectorAll('.atlas-slider').forEach(sync);
       document.addEventListener('input', e =>
         e.target.classList?.contains('atlas-slider') && sync(e.target));
   ───────────────────────────────────────────────────────────── */
.atlas-slider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 36px; margin: 0;
  background: transparent; cursor: pointer;
  --as-fill-c: var(--as-fill, var(--core-primary-text, #121212));
}
.atlas-slider::-webkit-slider-runnable-track {
  height: 6px; border-radius: 6px;
  background: linear-gradient(90deg, var(--as-fill-c) var(--as-p, 50%), var(--core-secondary, #CBC4BC) var(--as-p, 50%));
}
.atlas-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 28px; height: 28px; border-radius: 50%; margin-top: -11px;
  background: #fff; box-shadow: 0 2px 7px rgba(0, 0, 0, 0.28), 0 0 0 .5px rgba(0, 0, 0, 0.08);
  transition: transform .15s ease;
}
.atlas-slider:active::-webkit-slider-thumb { transform: scale(1.12); }
.atlas-slider::-moz-range-track { height: 6px; border-radius: 6px; background: var(--core-secondary, #CBC4BC); }
.atlas-slider::-moz-range-progress { height: 6px; border-radius: 6px; background: var(--as-fill-c); }
.atlas-slider::-moz-range-thumb {
  width: 28px; height: 28px; border: 0; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 7px rgba(0, 0, 0, 0.28), 0 0 0 .5px rgba(0, 0, 0, 0.08);
}

/* ─────────────────────────────────────────────────────────────
   3b. FADER (.atlas-fader) — Control-Center-style vertical lever
   ─ drag up/down; the color fills from the bottom. No thumb.
   ─ structure:
       <div class="atlas-fader" role="slider" tabindex="0">
         <div class="af-track"><div class="af-fill"></div></div>
         <div class="af-val">12,000 SAR</div>
         <div class="af-lbl">Money in</div>
       </div>
   ─ fill color: --af-fill (default ink). JS contract: set .af-fill height
     to (value/max*100)% ; add .dragging to the root while the pointer is
     down (kills the settle transition); keep aria-valuenow in sync.
   ───────────────────────────────────────────────────────────── */
.atlas-fader { display: flex; flex-direction: column; align-items: center; gap: 10px;
  user-select: none; -webkit-user-select: none; outline: none; }
.af-track {
  width: 72px; height: 180px; border-radius: 36px; position: relative; overflow: hidden;
  background: rgba(0, 0, 0, 0.08);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
  cursor: grab; touch-action: none;
  transition: transform .25s cubic-bezier(.3, .8, .3, 1);
}
.atlas-fader.dragging .af-track { cursor: grabbing; transform: scale(1.03); }
.atlas-fader:focus-visible .af-track { box-shadow: inset 0 1px 2px rgba(0,0,0,.06), 0 0 0 2px var(--core-primary-text, #121212); }
.af-fill {
  position: absolute; left: 0; right: 0; bottom: 0; height: 50%;
  background: var(--af-fill, var(--core-primary-text, #121212));
  transition: height .4s cubic-bezier(.25, .8, .3, 1);
}
.atlas-fader.dragging .af-fill { transition: none; }
.af-val { font-size: 16.5px; font-weight: 400; font-variant-numeric: tabular-nums; white-space: nowrap; }
.af-lbl { font-size: 11.5px; font-weight: 300; letter-spacing: .14em; text-transform: uppercase;
  color: var(--core-primary, #776F6D); text-align: center; }

/* ─────────────────────────────────────────────────────────────
   4. CARD SURFACE (.atlas-card) — the standard opaque card recipe
   ─ BG secondaryBackground · radius 24 (.soft → 30) · padding 24.
     .shadowed → shadow-sm (0 1px 3px 10% black) · .outlined → warm hairline.
     For translucent cards use atlas-glass.css (.atlas-glass-squircle) instead.
   ───────────────────────────────────────────────────────────── */
.atlas-card {
  background: var(--core-secondary-background, #FFFFFF);
  color: var(--core-primary-text, #121212);
  border-radius: 24px;
  padding: 24px;
}
.atlas-card.soft { border-radius: 30px; }
.atlas-card.shadowed { box-shadow: 0 1px 3px var(--atlas-shadow-1-0, rgba(0, 0, 0, 0.10)); }
.atlas-card.outlined { border: 1px solid rgba(139, 129, 126, 0.16); }
.atlas-card.warm { background: var(--atlas-ivory, #F4F2EE); }

/* ─────────────────────────────────────────────────────────────
   5. WEBAPP TOP BAR (.atlas-topbar) — THE header for every webapp
   ─ sticky brand row: wordmark left ("FB ATLAS <span>· APP</span>"),
     nav/actions right. Gains a linen glass veil once scrolled.
   ─ structure: <header class="atlas-topbar"> .brand · (.atlas-seg | actions) </header>
   ─ JS (one line): addEventListener('scroll', () =>
       topbar.classList.toggle('scrolled', scrollY > 8), {passive:true})
   ───────────────────────────────────────────────────────────── */
.atlas-topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 14px; padding: 14px 4px; margin: 0 -4px 16px;
  font-weight: 300;
  transition: background .3s ease, box-shadow .3s ease, backdrop-filter .3s ease;
}
/* Scrolled veil — EDGE TO EDGE: the glass spans the full viewport width via a
   ::before that escapes the container's padding, regardless of page gutters. */
.atlas-topbar::before {
  content: ""; position: absolute; top: 0; bottom: 0;
  left: calc(50% - 50vw); right: calc(50% - 50vw);
  z-index: -1; opacity: 0; transition: opacity .3s ease;
  background: rgba(235, 233, 229, 0.72);   /* linen @72% over blur */
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  backdrop-filter: blur(18px) saturate(150%);
  box-shadow: 0 1px 0 var(--atlas-shadow-1-0, rgba(0, 0, 0, 0.06));
}
.atlas-topbar.scrolled::before { opacity: 1; }
/* Dark themes: the veil flips to a dark glass (light linen would show as a pale band). */
[data-theme="midnight"] .atlas-topbar::before,
[data-theme="dark"] .atlas-topbar::before {
  background: rgba(18, 18, 18, 0.72);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06);
}
.atlas-topbar .brand { font-size: 17px; font-weight: 300; letter-spacing: normal; color: var(--core-primary-text, #121212); }
.atlas-topbar .brand span { color: var(--core-accent, #F74827); letter-spacing: normal; font-weight: 300; }

/* ─────────────────────────────────────────────────────────────
   6. SECTION NAV (.atlas-seg) — THE section switcher for every webapp
   ─ glass pill with a sliding ink thumb; active label flips to tertiary.
   ─ structure: <nav class="atlas-seg"><i class="thumb"></i>
       <button class="is-on">A</button><button>B</button>…</nav>
   ─ JS: position the thumb under the .is-on button —
       const seg = (nav, b) => { const t = nav.querySelector('.thumb');
         t.style.left = b.offsetLeft + 'px'; t.style.width = b.offsetWidth + 'px'; };
   ───────────────────────────────────────────────────────────── */
.atlas-seg {
  position: relative; display: flex; gap: 2px; padding: 5px; border-radius: 100px;
  background: var(--atlas-glass, rgba(255, 255, 255, 0.247));
  -webkit-backdrop-filter: blur(15px) saturate(140%);
  backdrop-filter: blur(15px) saturate(140%);
  border: 1px solid var(--atlas-glass, rgba(255, 255, 255, 0.247));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28);
}
.atlas-seg .thumb {
  position: absolute; top: 5px; bottom: 5px; left: 5px; width: 0; border-radius: 100px;
  background: var(--core-accent, #F74827);
  transition: left .38s cubic-bezier(.3, .8, .25, 1), width .38s cubic-bezier(.3, .8, .25, 1);
}
.atlas-seg button {
  position: relative; z-index: 1; padding: 9px 17px; border: 0; border-radius: 100px;
  background: none; cursor: pointer; font: inherit; font-size: 14px; font-weight: 400;
  letter-spacing: .04em; white-space: nowrap;
  color: var(--core-primary, #776F6D); transition: color .28s ease, background-color .2s ease;
}
.atlas-seg button.is-on { color: #FFFFFF; }
.atlas-seg button:hover:not(.is-on) { background: var(--core-accent, #F74827); color: #FFFFFF; }

/* ─────────────────────────────────────────────────────────────
   7. UNIFIED LOGIN (.atlas-login) — THE sign-in for every current
      and future Atlas web property. Ports the app's auth card
      (member_login): tertiary page, wordmark, secondaryBackground
      card radius 10 maxW 500, NO field labels, 20px light text,
      0.2-opacity hairline between fields, 60px CTA, quiet link.
   ─ structure: .atlas-login > .al-box >
       .al-wordmark · .al-tag · .al-card > input+input · .al-error ·
       .al-cta · .al-link · .al-foot
   ─ auth: Firebase email/password on project tasks-er8tqr — the SAME
     accounts as the iOS app. On error: text in .al-error + .shake on
     .al-card (reuses asShake). Never fail silently.
   ───────────────────────────────────────────────────────────── */
.atlas-login {
  min-height: 100svh; display: grid; place-items: center; padding: 24px;
  background: var(--atlas-linen, #EBE9E5);
  color: var(--core-primary-text, #121212); font-weight: 300;
}
.atlas-login .al-box { width: min(500px, 100%); }
.al-wordmark { text-align: center; font-size: 26px; font-weight: 300; letter-spacing: .42em; text-indent: .42em; }
.al-tag { text-align: center; font-size: 13px; font-weight: 400; letter-spacing: .18em; text-indent: .18em;
  text-transform: uppercase; color: var(--core-primary, #776F6D); margin: 8px 0 26px; }
.al-card { background: var(--core-secondary-background, #FFFFFF); border-radius: 10px; overflow: hidden; }
.al-card.shake { animation: asShake .4s ease; }
.al-card input {
  display: block; width: 100%; height: 64px; padding: 0 22px; border: 0;
  background: transparent; color: var(--core-primary-text, #121212);
  font: inherit; font-size: 20px; font-weight: 300; outline: none;
}
.al-card input::placeholder { color: var(--core-secondary, #CBC4BC); }
.al-card input + input { border-top: 1px solid rgba(197, 197, 199, 0.2); }  /* secondaryText @ .2 */
.al-error { color: var(--core-alternate, #F74827); font-size: 13.5px; min-height: 18px; margin: 10px 4px 0; }
.al-cta {
  width: 100%; height: 60px; margin-top: 16px; border: 0; border-radius: 100px; cursor: pointer;
  background: var(--core-primary-background, #000000); color: var(--core-tertiary, #F2F2F6);
  font: inherit; font-size: 15px; font-weight: 400; letter-spacing: .22em; text-indent: .22em; text-transform: uppercase;
  transition: transform .16s ease, opacity .16s ease;
}
.al-cta:active { transform: scale(.97); }
.al-cta:disabled { opacity: .45; }
.al-link { display: block; text-align: center; margin-top: 18px; font-size: 14px;
  color: var(--core-primary, #776F6D); text-decoration: none; }
.al-foot { text-align: center; margin-top: 34px; font-size: 11.5px; font-weight: 400;
  letter-spacing: .14em; text-transform: uppercase; color: var(--atlas-warm-grey, #8B817E); }

/* ─────────────────────────────────────────────────────────────
   8. HOME BUTTON (.atlas-home) — REQUIRED first child of every
      webapp's .atlas-topbar: glass circle back to the Atlas Console.
   ─ structure: <a class="atlas-home" href="https://fbatlas.web.app"
       aria-label="Atlas Console"><i class="ph-light ph-caret-left"></i></a>
   ─ web port of the app's glass back button (circle, blur, caret).
   ───────────────────────────────────────────────────────────── */
.atlas-home {
  width: 44px; height: 44px; border-radius: 100px; flex: none;
  display: grid; place-items: center; text-decoration: none;
  background: var(--atlas-glass, rgba(255, 255, 255, 0.247));
  -webkit-backdrop-filter: blur(5px); backdrop-filter: blur(5px);
  border: 1px solid var(--atlas-glass, rgba(255, 255, 255, 0.247));
  color: var(--core-primary-text, #121212); font-size: 19px;
  transition: transform .16s ease;
}
.atlas-home:active { transform: scale(.92); }
.atlas-topbar .lead { display: flex; align-items: center; gap: 14px; }

/* ─────────────────────────────────────────────────────────────
   9. LOADER (.atlas-loader) — THE one waiting state on the web,
      port of AtlasLoader: the square mark, 50px, easeInOutQuint
      pulse (1.25s each way). Opaque on tertiary between screens;
      .translucent = scrim60 veil over the current screen.
   ─ structure:
       <div class="atlas-loader" id="loader">
         <img src="https://fb-atlas-ui-kit.web.app/assets/atlas-mark-ink.png" alt="">
       </div>
     (.translucent → use atlas-mark-light.png). Hide: loader.remove()
     or add .done. Never a spinner, never text like "Loading…".
   ───────────────────────────────────────────────────────────── */
.atlas-loader {
  position: fixed; inset: 0; z-index: 150;
  display: grid; place-items: center;
  background: var(--atlas-linen, #EBE9E5);
  transition: opacity .3s ease;
}
.atlas-loader.translucent { background: var(--atlas-scrim-6-0, rgba(0, 0, 0, 0.6)); }
.atlas-loader.done { opacity: 0; pointer-events: none; }
.atlas-loader img { width: 50px; height: 50px; animation: atlasPulse 2.5s cubic-bezier(.86, 0, .07, 1) infinite alternate; }
@keyframes atlasPulse { from { opacity: 1; } to { opacity: 0.2; } }
@media (prefers-reduced-motion: reduce) { .atlas-loader img { animation: none; opacity: .8; } }
