/* ==========================================================================
   Alia Exchange Office — public rate board

   One rule drives this layout: the NUMBERS are the product. They get the
   space, the weight and the contrast. Everything else is a label.
   Rows divide the screen height evenly, so the board always fills the
   display exactly — no scrolling, no dead space at the bottom.
   ========================================================================== */

:root {
  --navy-900: #0b1730;
  --navy-800: #16233d;
  --gold-500: #c9a227;
  --gold-400: #d9b53f;
  --gold-300: #e8cd77;

  --up: #12a150;
  --down: #d92d20;

  /* Light board — matches a printed shop board, readable across the room. */
  --bg: linear-gradient(180deg, #e6efff 0%, #d7e6fb 100%);
  --head-bg: rgba(255, 255, 255, 0.55);
  --cell: #ffffff;
  --cell-alt: #f2f7ff;
  --line: rgba(27, 79, 168, 0.14);
  --ink: #16233d;
  --ink-num: #101d33;
  --accent: #1b4fa8;
  --ink-dim: #5b7099;

  color-scheme: light;
}

[data-theme='dark'] {
  --bg: linear-gradient(180deg, #0e1f3d 0%, #071223 100%);
  --head-bg: rgba(255, 255, 255, 0.05);
  --cell: rgba(255, 255, 255, 0.055);
  --cell-alt: rgba(255, 255, 255, 0.03);
  --line: rgba(201, 162, 39, 0.2);
  --ink: #f2f5f9;
  --ink-num: #ffffff;
  --accent: var(--gold-400);
  --ink-dim: #9fb0c7;
  --up: #3ddc84;
  --down: #ff6b6b;

  color-scheme: dark;
}

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

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans Arabic',
               'Noto Kufi Arabic', 'Dubai', Tahoma, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.stage {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: clamp(0.4rem, 1vh, 1rem) clamp(0.5rem, 1.2vw, 1.4rem);
  gap: clamp(0.3rem, 0.8vh, 0.8rem);
}

/* ==========================================================================
   Header — deliberately compact. Every pixel here is a pixel off the numbers.
   ========================================================================== */

.head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.brand__mark {
  width: clamp(42px, 8vh, 104px);
  height: auto;
  flex: none;
}

.brand__names {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  min-width: 0;
}

.brand__ar {
  font-size: clamp(0.95rem, 2.6vh, 2.1rem);
  font-weight: 800;
  color: var(--ink);
}

.brand__en {
  font-size: clamp(0.5rem, 1.15vh, 0.95rem);
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--accent);
  text-transform: uppercase;
}

.head__right {
  display: flex;
  align-items: center;
  gap: clamp(0.6rem, 2vw, 2rem);
}

.clock {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.05;
}

.clock__time {
  font-size: clamp(1rem, 2.9vh, 2.3rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.clock__date {
  font-size: clamp(0.5rem, 1.2vh, 0.95rem);
  font-variant-numeric: tabular-nums;
  color: var(--ink-dim);
}

.phones {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1em;
  text-align: right;
}

.phones li {
  font-size: clamp(0.55rem, 1.35vh, 1.05rem);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink-dim);
  direction: ltr;
}

.phones:empty { display: none; }

/* ==========================================================================
   The board
   ========================================================================== */

.board {
  flex: 1;
  min-height: 0;
  display: flex;
}

.rates {
  width: 100%;
  height: 100%;
  border-collapse: separate;
  border-spacing: 0 clamp(2px, 0.5vh, 7px);
  table-layout: fixed;
}

/* Column widths: the two rate columns take two thirds of the width. */
.c-flag { width: clamp(48px, 6vw, 110px); }
.c-name { width: 26%; }
.c-rate { width: 33%; }

.rates thead th {
  padding: 0.15rem clamp(0.5rem, 1vw, 1.1rem);
  background: var(--head-bg);
  text-align: right;
  font-weight: 700;
  height: 1px;              /* shrink-to-fit: the header takes only what it needs */
  border-radius: 8px;
}

.rates thead .th-en {
  display: block;
  font-size: clamp(0.6rem, 1.5vh, 1.15rem);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
}

.rates thead .th-alt {
  display: block;
  font-size: clamp(0.5rem, 1.2vh, 0.95rem);
  color: var(--accent);
  font-weight: 700;
}

.rates tbody tr { height: auto; }

.rates tbody td {
  background: var(--cell);
  border: 1px solid var(--line);
  padding: 0 clamp(0.5rem, 1vw, 1.1rem);
  vertical-align: middle;
  border-radius: clamp(8px, 1.1vh, 16px);
}

.rates tbody .c-rate { background: var(--cell-alt); }

/* Flag */

.flag {
  width: 100%;
  max-width: clamp(38px, 4.6vw, 88px);
  aspect-ratio: 3 / 2;
  border-radius: 6px;
  object-fit: cover;
  display: block;
  margin-inline: auto;
  box-shadow: 0 1px 4px rgba(11, 23, 48, 0.25);
}

/* Currency name */

.c-name { text-align: left; }

.name { min-width: 0; }

.name__en {
  display: block;
  font-size: clamp(0.75rem, 2.5vh, 2rem);
  font-weight: 700;
  color: var(--ink);
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  direction: ltr;
  text-align: left;
}

.name__sub {
  display: flex;
  align-items: baseline;
  justify-content: flex-start;
  gap: 0.5em;
  min-width: 0;
  line-height: 1.15;
  direction: ltr;
}

.name__alt {
  font-size: clamp(0.55rem, 1.6vh, 1.25rem);
  color: var(--accent);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.name__code {
  font-size: clamp(0.45rem, 1.1vh, 0.85rem);
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--ink-dim);
  flex: none;
  direction: ltr;
}

/* ------------------------------------------------------------------ */
/* The numbers                                                        */
/* ------------------------------------------------------------------ */

/* Numbers hug the right edge of their cell, arrow tucked to their left. */
.rate {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.3em;
  direction: ltr;
}

.rate__value {
  font-size: clamp(1.5rem, 6.1vh, 5.4rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--ink-num);
  white-space: nowrap;
  transition: color 300ms ease;
}

.c-sell .rate__value { color: var(--accent); }
[data-theme='dark'] .c-sell .rate__value { color: var(--gold-300); }

/* The number is the signal: green when the rate rose, red when it fell.
   These win over the column colours above, in both columns. */
.rate__value[data-dir='1']  { color: var(--up) !important; }
.rate__value[data-dir='-1'] { color: var(--down) !important; }

/* On an actual change the number pops, so movement is visible from a distance
   even to someone who was not watching that row. */
@keyframes pop {
  0%   { transform: scale(1);    opacity: 1; }
  22%  { transform: scale(1.14); opacity: 1; }
  45%  { transform: scale(0.99); opacity: 1; }
  100% { transform: scale(1);    opacity: 1; }
}

.rate__value.pop {
  animation: pop 900ms cubic-bezier(0.22, 0.68, 0.36, 1);
  transform-origin: right center;
  display: inline-block;
}

.rate__unit { display: none; }

.trend {
  font-size: clamp(0.85rem, 3vh, 2.4rem);
  line-height: 1;
  flex: none;
  font-weight: 700;
}

.trend[data-dir='1']  { color: var(--up); }
.trend[data-dir='-1'] { color: var(--down); }
.trend[data-dir='0']  { color: transparent; }

/* The cell background is deliberately left alone — the coloured number and its
   arrow carry the change. A flashing background competed with them and made the
   board harder to read, which is the opposite of what a rate board is for. */

@keyframes row-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.rates tbody tr.enter {
  animation: row-in 380ms cubic-bezier(0.22, 0.68, 0.36, 1) backwards;
}

.skeleton td {
  text-align: center;
  color: var(--ink-dim);
  font-size: 1rem;
}

/* ==========================================================================
   Footer
   ========================================================================== */

.foot {
  flex: none;
  display: flex;
  align-items: center;
  gap: 1rem;
  border-top: 1px solid var(--line);
  padding-top: clamp(0.2rem, 0.6vh, 0.6rem);
}

.ticker {
  flex: 1;
  overflow: hidden;
  min-width: 0;
}

.ticker__text {
  display: inline-block;
  white-space: nowrap;
  padding-left: 100%;
  font-size: clamp(0.6rem, 1.7vh, 1.3rem);
  font-weight: 700;
  color: var(--accent);
  animation: scroll-left var(--ticker-duration, 28s) linear infinite;
}

@keyframes scroll-left {
  from { transform: translateX(0); }
  to   { transform: translateX(-100%); }
}

.foot__meta {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  font-size: clamp(0.5rem, 1.15vh, 0.85rem);
  color: var(--ink-dim);
  flex: none;
}

.note { display: none; }        /* the ticker already carries the message */

.live {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 700;
  white-space: nowrap;
}

.live__dot {
  width: 0.5em; height: 0.5em;
  border-radius: 50%;
  background: var(--ink-dim);
  flex: none;
}

.live[data-state='live'] { color: var(--up); }
.live[data-state='live'] .live__dot { background: var(--up); animation: pulse 2.4s ease-out infinite; }
.live[data-state='error'] { color: var(--down); }
.live[data-state='error'] .live__dot { background: var(--down); }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(18, 161, 80, 0.5); }
  70%  { box-shadow: 0 0 0 0.55em rgba(18, 161, 80, 0); }
  100% { box-shadow: 0 0 0 0 rgba(18, 161, 80, 0); }
}

/* ==========================================================================
   Phones — the board becomes scrollable rather than unreadably small
   ========================================================================== */

@media (max-width: 640px) {
  body { overflow: auto; }
  .stage { height: auto; min-height: 100dvh; }

  .c-flag { width: 40px; }
  .c-name { width: 34%; }
  .c-rate { width: auto; }

  .phones { display: none; }

  .rate__value { font-size: clamp(1.1rem, 5.6vw, 2rem); }
  .name__en    { font-size: clamp(0.7rem, 3.2vw, 1rem); }
  .name__alt   { font-size: clamp(0.55rem, 2.6vw, 0.85rem); }
  .name__code  { display: none; }
  .rates tbody td { padding: 0.45rem 0.4rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .ticker__text { padding-left: 0; }
}
