/*
 * Forex Board — design tokens carried over from the Lovable-built
 * frontend (src/styles.css in i-m-live-rates-main), reproduced here as
 * plain CSS since there's no Tailwind build step in a Thymeleaf app.
 * Same oklch values, same component visual language.
 */

:root {
  --bg: oklch(0.2 0.085 265);
  --panel: oklch(0.27 0.105 265);
  --hairline: oklch(0.85 0.04 250 / 22%);
  --fg: oklch(0.98 0.005 250);
  --muted: oklch(0.82 0.04 250);
  --accent: oklch(0.78 0.14 185);   /* teal — matches the logo's #18BAB1 accent */
  --buy: oklch(0.87 0.15 160);
  --sell: oklch(0.87 0.16 78);

  --font-body: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-data: "JetBrains Mono", ui-monospace, "SFMono-Regular", "Menlo", monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
}

.board {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
}

/* ---------------------------------------------------------------- */
/* Header                                                            */
/* ---------------------------------------------------------------- */

.board-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 1rem;
  height: 8vh;
  min-height: 3.5rem;
  padding: 0 1.5vw;
  border-bottom: 1px solid var(--hairline);
}

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

.brand-logo {
  height: 4vh;
  min-height: 1.75rem;
  width: auto;
  flex-shrink: 0;
  color: var(--fg);
}

.brand-divider {
  height: 3.5vh;
  width: 1px;
  background: var(--hairline);
  flex-shrink: 0;
}

.brand-title {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
  font-size: clamp(1rem, 1.7vw, 2.2rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.8vw;
  flex-shrink: 0;
}

.status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.status-dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 999px;
  background: var(--muted);
}

.status.is-live .status-dot {
  background: var(--accent);
}

.status-label {
  font-size: clamp(0.65rem, 0.95vw, 1.05rem);
  color: var(--muted);
}

.chrome {
  display: flex;
  align-items: center;
  gap: 0.6vw;
  transition: opacity 0.5s ease;
}

.chrome.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.interval-group {
  display: flex;
  align-items: center;
  overflow: hidden;
  border: 1px solid var(--hairline);
  border-radius: 999px;
}

.interval-btn {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0.25rem 0.75rem;
  font: inherit;
  font-size: clamp(0.65rem, 0.85vw, 1rem);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.interval-btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--bg);
}

.interval-btn:hover:not([aria-pressed="true"]) {
  color: var(--fg);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  transition: background 0.15s;
}

.icon-button:hover:not(:disabled) {
  background: var(--hairline);
}

.icon-button:disabled {
  color: var(--muted);
  opacity: 0.5;
  cursor: not-allowed;
}

.icon-button svg {
  width: 1rem;
  height: 1rem;
}

.refresh-ring {
  position: relative;
}

.ring-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-track {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  opacity: 0.18;
}

.ring-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  transition: stroke-dashoffset 1s linear;
}

.ring-icon {
  position: relative;
  width: 1rem;
  height: 1rem;
}

.icon-button.is-busy .ring-icon {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.clock {
  font-family: var(--font-data);
  font-size: clamp(0.9rem, 1.5vw, 1.9rem);
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- */
/* Board / panels                                                    */
/* ---------------------------------------------------------------- */

.board-main {
  flex: 1;
  min-height: 0;
  padding: 1vw;
}

/* rates-column takes 2x the width of ads-column — "covers the space of
   the current two columns" per the redesign that replaced the old
   Forex/Cash/TT three-panel grid with one unified, tabbed rates column. */
.board-main-grid {
  height: 100%;
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1vw;
}

@media (max-width: 900px) {
  .board-main-grid {
    grid-template-columns: 1fr !important;
    grid-auto-rows: auto;
    overflow-y: auto;
  }
  .ads-column {
    min-height: 12rem;
  }
}

.rates-column,
.ads-column {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--hairline);
  border-radius: 1rem;
  background: var(--panel);
}

/* ---------------- Tabs (TZS / USD) ---------------- */

.tabs {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5vw;
  padding: 0.8vh 1.2vw;
  border-bottom: 1px solid var(--hairline);
}

.tab-btn {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 0.4rem 1.1rem;
  font: inherit;
  font-weight: 600;
  font-size: clamp(0.8rem, 1.1vw, 1.3rem);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.tab-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

.tab-btn:hover:not(.is-active) {
  color: var(--fg);
  border-color: var(--fg);
}

.tab-panels {
  position: relative;
  flex: 1;
  min-height: 0;
}

.tab-panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.tab-panel.is-active {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* Lives in the tab bar (#rate-tabs), centered independently of the
   TZS/USD toggle button — absolutely positioned against .tabs (see
   position:relative there) so it stays centered on the bar regardless of
   the button's own width/position. One element, not two: board.js
   rewrites its text and toggles the native `hidden` attribute in place
   (data-tzs-date/data-usd-date hold both tabs' dates) rather than
   showing/hiding a pair of pre-rendered elements via a CSS class — a
   class that's out of sync with the DOM would show both at once, which
   is exactly what happened before this. */
.tab-updated {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.35em 0.9em 0.35em 0.7em;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: linear-gradient(180deg, oklch(0.85 0.04 250 / 10%), oklch(0.85 0.04 250 / 4%));
  color: var(--muted);
  font-size: clamp(0.85rem, 1.2vw, 1.4rem);
  white-space: nowrap;
}

.tab-updated-icon {
  flex-shrink: 0;
  width: 1.1em;
  height: 1.1em;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.6;
  stroke-linejoin: round;
}

.tab-updated-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.8em;
}

.tab-updated strong {
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.01em;
}

.stale-badge {
  flex-shrink: 0;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  font-size: clamp(0.6rem, 0.8vw, 0.95rem);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--muted);
}

.panel-table {
  display: flex;
  flex: 1;
  flex-direction: column;
}

/* Flag | Currency name | Code | Buying | Selling — five columns, name
   flexible, code narrow, buy/sell equal and widest. The flag column is a
   fixed width (matching .cell-flag exactly), not "auto" — .panel-columns
   and .panel-row are separate grid containers (one header, one per data
   row), each sizing its own columns independently. "auto" let the header
   row's empty flag slot collapse to ~0 width while each data row reserved
   real space for the flag image, so "Currency"/"Code"/"Buying"/"Selling"
   drifted left of the data they were meant to label. A fixed width makes
   column 1 identical across every one of these independent grids. */
.panel-columns,
.panel-row {
  display: grid;
  grid-template-columns: clamp(1.5rem, 2.2vw, 2.8rem) minmax(0, 0.9fr) minmax(0, 0.8fr) minmax(0, 1.15fr) minmax(0, 1.15fr);
  gap: 1.2vw;
}

.panel-columns {
  padding: 0.6vh 1.2vw;
  border-bottom: 1px solid var(--hairline);
  font-size: clamp(0.6rem, 0.95vw, 1.15rem);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
}

.panel-columns span:nth-child(4),
.panel-columns span:nth-child(5) {
  text-align: right;
}

.panel-rows {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
}

.panel-row {
  align-items: center;
  flex: 1;
  padding: 0 1.2vw;
  border-bottom: 1px solid var(--hairline);
}

.panel-row:last-child {
  border-bottom: none;
}

.cell-flag {
  display: block;
  width: clamp(1.5rem, 2.2vw, 2.8rem);
  height: clamp(1.5rem, 2.2vw, 2.8rem);
  border-radius: 0.25em;
  object-fit: cover;
}

.cell-name {
  min-width: 0;
  font-weight: 500;
  font-size: clamp(0.95rem, 1.55vw, 2.1rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cell-code {
  min-width: 0;
  font-family: var(--font-data);
  font-weight: 600;
  letter-spacing: 0.02em;
  font-size: clamp(0.75rem, 1.05vw, 1.3rem);
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cell-buy,
.cell-sell {
  text-align: right;
  font-family: var(--font-data);
  font-weight: 600;
  font-size: clamp(1rem, 1.65vw, 2.2rem);
  font-variant-numeric: tabular-nums;
  border-radius: 0.375rem;
}

.cell-buy {
  color: var(--buy);
}

.cell-sell {
  color: var(--sell);
}

.cell-flash {
  animation: cell-flash 1.5s ease-out;
}

@keyframes cell-flash {
  0%   { background-color: color-mix(in oklab, var(--accent) 38%, transparent); }
  100% { background-color: transparent; }
}

.empty-state {
  display: grid;
  place-items: center;
  height: 100%;
  min-height: 6rem;
  color: var(--muted);
  font-size: clamp(0.9rem, 1.4vw, 1.8rem);
  text-align: center;
  padding: 2rem 1rem;
}

.panel-empty {
  flex: 1;
}

/* ---------------------------------------------------------------- */
/* Ads column                                                         */
/* ---------------------------------------------------------------- */

.ads-placeholder {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 2rem;
}

/* Default (no ad content configured) state: the I&M logo filling most of
   the column — no "Internal Ads"/placeholder text shown to viewers. */
.ads-logo {
  width: 100%;
  height: auto;
  max-width: 28rem;
  color: var(--fg);
}

/* Real ad content (app.board.ads.folder) — cross-fades between slides,
   same technique as .tab-panel. Rotation itself is board.js. */
.ads-rotator {
  position: relative;
  flex: 1;
}

.ads-slide {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease;
}

.ads-slide.is-active {
  opacity: 1;
  pointer-events: auto;
}

.ads-slide img,
.ads-slide video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 0.5rem;
}

/* ---------------------------------------------------------------- */
/* Contact marquee                                                    */
/* ---------------------------------------------------------------- */

.marquee {
  overflow: hidden;
  border-top: 1px solid var(--hairline);
  background: var(--panel);
  padding: 0.5vh 0;
}

.marquee-track {
  display: flex;
  width: max-content;
  animation: marquee-scroll 30s linear infinite;
}

.marquee-item {
  flex-shrink: 0;
  padding: 0 3vw;
  font-size: clamp(0.75rem, 1.05vw, 1.25rem);
  color: var(--muted);
  white-space: nowrap;
}

@keyframes marquee-scroll {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); } /* content is duplicated in the template, so -50% is exactly one loop */
}

/* ---------------------------------------------------------------- */
/* Footer                                                             */
/* ---------------------------------------------------------------- */

.board-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: 5vh;
  min-height: 2.25rem;
  padding: 0 1.5vw;
  border-top: 1px solid var(--hairline);
  font-size: clamp(0.6rem, 0.85vw, 1rem);
  color: var(--muted);
}

.footer-disclaimer {
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.footer-updated {
  margin: 0;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

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