/* ─── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --gold:          #d4af37;
  --gold-light:    #f0c040;
  --gold-dim:      rgba(212,175,55,0.15);
  --bg:            #0a0a0a;
  --card-bg:       #141414;
  --card-hajar-bg: #110f00;
  --border:        #2a2a2a;
  --text:          #ffffff;
  --muted:         #666;
  --green:         #4caf50;
  --red:           #f44336;
  --amber:         #ff9800;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

/* ─── Layout ────────────────────────────────────────────────── */
.wrapper {
  width: 100%;
  max-width: 1080px;   /* widened from 820px to fit the third rate card */
}

/* ─── Header ────────────────────────────────────────────────── */
.header {
  text-align: center;
  margin-bottom: 2rem;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.site-title {
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  font-weight: 800;
  letter-spacing: 6px;
  color: var(--gold);
  text-shadow: 0 0 30px rgba(212,175,55,0.3);
}

/* ─── Live Badge ────────────────────────────────────────────── */
.live-badge {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--gold);
  border-radius: 999px;
  padding: 0.3rem 0.9rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--gold);
  background: var(--gold-dim);
  transition: border-color 0.4s, color 0.4s, background 0.4s;
}

/* Market Closed badge style */
.live-badge.closed {
  border-color: var(--amber);
  color: var(--amber);
  background: rgba(255,152,0,0.1);
}

/* "NOT LIVE" badge — the market is open but the feed is down or silent
   (applyNotLiveMode() in public/js/main.js). Red rather than the amber used for
   "closed": that state means no rate is expected, this one means what is on
   screen may be WRONG — or absent entirely. Pairs with .dot.dead below.
   The class is still named .stale; only the label changed. */
.live-badge.stale {
  border-color: var(--red);
  color: var(--red);
  background: rgba(244,67,54,0.1);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  transition: background 0.4s;
}

.dot.live   { background: var(--green);  animation: pulse 1.4s ease-in-out infinite; }
/* Feed down or silent while the market is open — set by applyNotLiveMode(). Deliberately
   does NOT pulse: a pulsing dot reads as "receiving data", which is the opposite
   of what this state means. */
.dot.dead   { background: var(--red);    animation: none; }
.dot.closed { background: var(--amber);  animation: none; }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.75); }
}

/* ─── Market Closed Banner ──────────────────────────────────── */
.mc-banner {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  background: rgba(255, 152, 0, 0.06);
  border: 1px solid rgba(255, 152, 0, 0.35);
  border-left: 4px solid var(--amber);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.75rem;
  animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.mc-icon {
  font-size: 1.4rem;
  color: var(--amber);
  line-height: 1;
  padding-top: 0.05rem;
  flex-shrink: 0;
}

.mc-body { display: flex; flex-direction: column; gap: 0.25rem; }

.mc-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--amber);
  letter-spacing: 1px;
}

.mc-sub {
  font-size: 0.82rem;
  color: #bbb;
}

/* ─── Disclaimer ────────────────────────────────────────────── */
/* Sits between the market-closed banner and the rate cards. Deliberately
   quieter than .mc-banner — it is permanent, not an alert. */
.disclaimer {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: 10px;
  padding: 0.8rem 1.1rem;
  margin-bottom: 1.5rem;
  font-size: 0.8rem;
  line-height: 1.55;
  color: #9a9a9a;
}

.disclaimer-icon {
  color: var(--gold);
  font-size: 0.95rem;
  line-height: 1.35;
  flex-shrink: 0;
}

.disclaimer strong {
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.5px;
}

@media (max-width: 860px) {
  .disclaimer { font-size: 0.75rem; padding: 0.7rem 0.9rem; gap: 0.55rem; }
}

/* ─── Notes ─────────────────────────────────────────────────── */
/* Admin-authored, sits between the disclaimer and the rate cards. Red on purpose:
   it must read as louder than the permanently-present grey disclaimer above it.
   Numbering comes from a CSS counter, never from the text, so 1,2,3 can never
   drift out of step with the array order the server sent. */
.notes-box {
  background: rgba(244, 67, 54, 0.06);
  border: 1px solid rgba(244, 67, 54, 0.25);
  border-left: 3px solid var(--red);
  border-radius: 10px;
  padding: 0.9rem 1.1rem;
  margin-bottom: 1.5rem;
  animation: fadeIn 0.4s ease;
}

.notes-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

.notes-icon {
  color: var(--red);
  font-size: 0.95rem;
  line-height: 1;
  flex-shrink: 0;
}

.notes-title {
  color: var(--red);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.notes-list {
  list-style: none;
  counter-reset: note;
  margin: 0;
  padding: 0;
}

.notes-list li {
  counter-increment: note;
  display: flex;
  gap: 0.55rem;
  font-size: 0.82rem;
  line-height: 1.55;
  color: #c9c9c9;
}

.notes-list li + li { margin-top: 0.35rem; }

.notes-list li::before {
  content: counter(note) ".";
  color: var(--red);
  font-weight: 700;
  flex-shrink: 0;
  min-width: 1.1rem;
}

@media (max-width: 860px) {
  .notes-box   { padding: 0.8rem 0.9rem; }
  .notes-title { font-size: 0.72rem; }
  .notes-list li { font-size: 0.77rem; gap: 0.45rem; }
}

/* ─── Rate Cards Grid ───────────────────────────────────────── */
/* 3 cards side by side on desktop → 1 per row once they can no longer fit */
.rates-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  margin-bottom: 2rem;
  transition: opacity 0.4s;
}

.rates-grid.stale { opacity: 0.6; }

@media (max-width: 860px) {
  .rates-grid { grid-template-columns: 1fr; gap: 1.25rem; }
  /* Full-width cards — every label fits on one line, so drop the reserved second line */
  .card-label { min-height: 0; }
}

/* ─── Rate Card ─────────────────────────────────────────────── */
.rate-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem 1.5rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.rate-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--border);
}

.card-mcx::before   { background: linear-gradient(90deg, #444, #666, #444); }

/* Gold Estimated Value (class still `.card-hajar`) + Gold RTGS Including 3% GST
   (class still `.card-rtgs`) — both are premium-added rates, so they share
   the gold treatment and are told apart by their badge text. */
.card-hajar,
.card-rtgs          { background: var(--card-hajar-bg); border-color: var(--gold); }
.card-hajar::before,
.card-rtgs::before  { background: linear-gradient(90deg, var(--gold), var(--gold-light), var(--gold)); }

/* When market is closed, the gold borders dim */
.rates-grid.stale .card-hajar,
.rates-grid.stale .card-rtgs { border-color: rgba(212,175,55,0.4); }

.card-badge {
  position: absolute;
  top: 1rem; right: 1rem;
  background: var(--gold);
  color: #000;
  font-size: 0.55rem;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

/* min-height reserves two lines on EVERY card. "Gold RTGS Including 3% GST" wraps
   at a third of the grid width; without the reserved height that card's rate would
   sit lower than the other two. Reset in the ≤860px block, where nothing wraps.
   margin-top clears the absolutely-positioned `.card-badge` so the label doesn't
   sit flush under it — applied to every card so all three rates stay aligned. */
.card-label {
  font-size: 0.85rem;
  color: var(--muted);
  letter-spacing: 2px;
  text-transform: uppercase;
  line-height: 1.4;
  min-height: 2.8em;
  margin-top: 0.6rem;
  margin-bottom: 0.6rem;
}

.card-hajar .card-label,
.card-rtgs  .card-label { color: var(--gold); }

.card-rate {
  font-size: clamp(1.8rem, 4.4vw, 2.7rem);   /* tuned down for the 3-card row */
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  transition: color 0.3s;
}

.card-hajar .card-rate,
.card-rtgs  .card-rate { color: var(--gold-light); }

.card-unit {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 0.6rem;
  letter-spacing: 1px;
}

/* ─── Flash animations ──────────────────────────────────────── */
@keyframes flash-white {
  0%   { color: #ffffff; }
  100% { color: var(--text); }
}
@keyframes flash-gold {
  0%   { color: #ffffff; }
  100% { color: var(--gold-light); }
}

.flash-white { animation: flash-white 0.6s ease-out; }
.flash-gold  { animation: flash-gold  0.6s ease-out; }

/* ─── Footer ────────────────────────────────────────────────── */
.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.conn-online  { color: var(--green); }
.conn-offline { color: var(--red); }

/* ─── Offline overlay ───────────────────────────────────────── */
/* Shared by BOTH pages that can be offline — the rate display (`/`) and the
   login page (`/user`). It lived inline in each of them, byte-identical; the
   two copies are now this one block. Only the message TEXT still differs, and
   that stays in each page's markup.
   `pwaCloseApp()` is deliberately still duplicated inline in both pages — it
   must work even if pwa.js never loaded, which is exactly the offline case.

   Blocks the whole screen rather than dimming the cards: a stale gold rate
   mistaken for a live one is the worst failure this app has.
   z-index sits BELOW #force-logout-overlay's 99999 — a terminated session must
   still paint over this. Do not raise it. */
#offline-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: #0a0a0a;        /* fully opaque: nothing behind may show through */
  z-index: 99000;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  text-align: center;
}
#offline-overlay.visible { display: flex; }

.off-box   { max-width: 380px; width: 100%; }
.off-icon  { font-size: 2.75rem; margin-bottom: 1rem; color: var(--gold); }
.off-title {
  font-size: 1.05rem; font-weight: 700; color: var(--gold);
  letter-spacing: 1px; margin-bottom: 0.75rem;
}
.off-message { font-size: 0.86rem; color: #888; line-height: 1.7; margin-bottom: 1.75rem; }
.off-close {
  background: var(--gold);
  border: none;
  color: #000;
  border-radius: 8px;
  padding: 0.65rem 2rem;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
  transition: background 0.2s;
}
.off-close:hover { background: var(--gold-light, #f0c040); }
/* Revealed only when window.close() was refused — see pwaCloseApp().
   Deliberately NO `display` here: any display value in a class rule beats the
   `hidden` attribute and the hint would show permanently. */
.off-hint { font-size: 0.76rem; color: #666; line-height: 1.6; margin-top: 1rem; }
