/* ============================================================================
   THE SITE HEADER. One bar, every page, signed in or not.
   ----------------------------------------------------------------------------
   WHY THIS FILE EXISTS. Andrew, 2026-09-07, looking at /gambar-passport:
   "where is the login log out thing on the top right". He was right, and the
   gap was wider than the page he was looking at. Measured across the 19 public
   pages on main that day:

     - 7 had NO header at all: /, /faq, /terms, /privacy, /gambar-passport,
       /studio/verify, /studio/wan-test
     - the other 12 each hand-rolled their own `.topbar` markup
     - the ONLY customer-facing logout on the whole site was a footer button at
       the bottom of /studio, shipped `display:none` until the dashboard loaded

   So a signed-in customer could not see that they were signed in, could not see
   their balance, and could not sign out, anywhere. /gambar-passport went one
   worse and told a customer who was already signed in WITH credits to "Daftar
   dulu - percuma", because the page had no notion of session state on load.

   This is the second half of the fix Andrew asked for on 2026-08-07 ("there is
   sign up but there is no sign in for existing users in the ui ux flow which is
   super weird"). That one shipped the LOGIC - showLoginAffordance() in
   studio.js - but it only ever fired on a page that both had a `.topbar` and
   loaded studio.js, which is why it never reached the pages above.

   NO CUMULATIVE LAYOUT SHIFT. The header is injected by JS, so the space it
   occupies has to be reserved by CSS that is already in the <head> before the
   first paint. `body.rjk-has-hdr` does that, and the class is written into the
   markup rather than added by the script, so it is there from parse. Injecting
   into unreserved space would push the hero of every landing page down after
   load, which is both ugly and a Core Web Vitals regression on the pages that
   actually rank.

   SELF-CONTAINED ON PURPOSE. Only /index.html loads theme.css; the rest carry
   inline <style>. So every colour here names the theme variable AND a literal
   fallback, and the file depends on nothing else.
   ========================================================================== */

:root {
  --rjk-hdr-h: 52px;
}

/* Reserve the height before the header exists. See the CLS note above. */
body.rjk-has-hdr {
  padding-top: var(--rjk-hdr-h);
}

/* Paint the reserved band, so the reservation is never a bare gap. Without JS
   - or in the moment before header.js runs - the page would otherwise open on
   52px of nothing above the content, which reads as broken rather than as
   loading. The real header is opaque and sits on top of this. */
body.rjk-has-hdr::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--rjk-hdr-h);
  background: #fff;
  border-bottom: 1px solid rgba(6, 36, 19, 0.10);
  z-index: 89;          /* one below .rjk-hdr */
}

.rjk-hdr {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 90;
  box-sizing: border-box;
  height: var(--rjk-hdr-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 14px;
  background: #fff;
  border-bottom: 1px solid rgba(6, 36, 19, 0.10);
  font-family: var(--font-body, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif);
}

.rjk-hdr-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -0.2px;
  color: var(--rojak-green-900, #062413);
  text-decoration: none;
  flex-shrink: 0;
}
.rjk-hdr-brand .rjk-hdr-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: url(/studio/icons/icon-96.png) center / cover no-repeat;
  flex-shrink: 0;
}

/* The account cluster. Also appended, on its own, into the hand-rolled
   `.topbar` that the studio and guide pages already have - those keep their
   own back link and credits chip, and only gain the account controls. */
.rjk-acct {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

/* Nothing is painted until /api/user/me answers. A header that guesses shows
   "Log masuk" to a signed-in customer for a beat, which is the exact confusion
   this file exists to end. */
.rjk-acct:empty { display: none; }

.rjk-acct-login,
.rjk-acct-link,
.rjk-acct-out {
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  border-radius: 999px;
  padding: 8px 12px;          /* a real tap target, not just the text */
  text-decoration: none;
  cursor: pointer;
}

.rjk-acct-login {
  color: var(--rojak-orange, #ff6b00);
  border: 1.5px solid var(--rojak-orange, #ff6b00);
  background: transparent;
}
.rjk-acct-login:active { transform: translateY(1px); }

.rjk-acct-credits {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--rojak-green-900, #062413);
  color: #fff;
  padding: 7px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 12.5px;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}
.rjk-acct-credits .rjk-acct-dia { color: var(--rojak-orange-2, #ffae00); }

.rjk-acct-link {
  color: var(--rojak-green-900, #062413);
  background: rgba(6, 36, 19, 0.06);
}
.rjk-acct-out {
  color: var(--rojak-green-900, #062413);
  background: transparent;
  border: 0;
  opacity: 0.75;
}
.rjk-acct-out:hover { opacity: 1; }
.rjk-acct-out[disabled] { opacity: 0.4; cursor: default; }

/* At 360-400px the brand, the balance, "Akaun" and "Log keluar" do not all fit.
   The balance and the way out are what a customer needs from a header, so the
   word "credits" goes first and "Akaun" goes next - the account page is still
   one tap away from /studio, and the logout is not. */
@media (max-width: 430px) {
  .rjk-acct-credits .rjk-acct-unit { display: none; }
}
@media (max-width: 380px) {
  .rjk-acct-link { display: none; }
  .rjk-hdr { padding: 0 10px; }
}

/* Inside a page's own `.topbar` the cluster is a guest: that bar brings its own
   background, height and sticky behaviour, so take none of ours with us. */
.topbar .rjk-acct { margin-left: auto; }

/* Those bars are already close to full at 375px - the studio one carries a back
   link, a BETA pill and a credits chip before we add anything. Measured on
   /studio/motion-sync: adding "Log keluar" at the normal size overflowed by 6px
   and clipped it against the right edge. So inside a host bar, on a narrow
   screen, the cluster gets out of the way rather than pushing the page wider. */
@media (max-width: 460px) {
  .topbar .rjk-acct { gap: 4px; }
  .topbar .rjk-acct-out,
  .topbar .rjk-acct-link { font-size: 11.5px; padding: 8px 6px; }
  /* The balance is the first thing to go. /panduan's bar already carries a back
     link, the brand AND a "Buka Studio" CTA; adding a chip to it overflowed by
     18px, and its affiliate guide by 45. On a bar we do not own, the way OUT of
     the account is what has to survive - the balance is one tap away in the
     studio, and on the bars we DO inject there is room for both. */
  .topbar .rjk-acct-credits { display: none; }
}
