:root {
  --bg-main: #0b0f19;
  --bg-card: #111827;
  --bg-card-hover: #17223b;
  --bg-input: #1f293d;
  --bg-badge-pos: rgba(16, 185, 129, 0.16);
  --bg-badge-neg: rgba(244, 63, 94, 0.16);
  --bg-badge-neutral: rgba(148, 163, 184, 0.12);

  --border-subtle: #1e293b;
  --border-card: #223049;
  --border-highlight: #38bdf8;

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --color-mid: #38bdf8;
  --color-buy: #10b981;
  --color-sell: #f43f5e;
  --color-amber: #f59e0b;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding: 24px 16px 48px;
}

.container {
  max-width: 1160px;
  margin: 0 auto;
}

/* Header & Top Bar */
.site-header {
  margin-bottom: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
}

.site-header::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #38bdf8 0%, #818cf8 50%, #10b981 100%);
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 14px;
}

.title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.brand-badge {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.12);
  color: var(--color-mid);
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.page-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.updated-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--color-buy);
  box-shadow: 0 0 8px var(--color-buy);
}

/* Rate Display Hero Section */
.rate-hero {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 32px;
}

.rate-primary {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rate-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.rate-value-group {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}

.big-rate {
  font-size: 2.75rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: #ffffff;
  line-height: 1.1;
}

.rate-currency {
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--text-muted);
}

.change-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.change-badge.positive {
  background: var(--bg-badge-pos);
  color: var(--color-buy);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.change-badge.negative {
  background: var(--bg-badge-neg);
  color: var(--color-sell);
  border: 1px solid rgba(244, 63, 94, 0.3);
}

.change-badge.neutral {
  background: var(--bg-badge-neutral);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

/* Secondary Transfer Rates */
.rate-details {
  display: flex;
  justify-content: flex-end;
  gap: 20px;
  flex-wrap: wrap;
}

.detail-item {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  min-width: 140px;
}

.detail-title {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.detail-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.detail-dot.buy { background: var(--color-buy); }
.detail-dot.sell { background: var(--color-sell); }
.detail-dot.spread { background: var(--color-mid); }

.detail-val {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.detail-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: 2px;
}

/* Controls Toolbar */
.toolbar-section {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 16px;
}

.range-switcher {
  display: inline-flex;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 4px;
}

.range-tab {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease-in-out;
}

.range-tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.range-tab.active {
  background: var(--color-mid);
  color: #0b0f19;
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.toolbar-toggles {
  display: flex;
  align-items: center;
  gap: 16px;
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  user-select: none;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: color 0.15s;
}

.toggle-label:hover {
  color: var(--text-primary);
}

.toggle-switch {
  position: relative;
  width: 38px;
  height: 22px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: var(--bg-input);
  border: 1px solid var(--border-card);
  transition: 0.2s ease;
  border-radius: 999px;
}

.slider::before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: var(--text-muted);
  transition: 0.2s ease;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: rgba(56, 189, 248, 0.2);
  border-color: var(--color-mid);
}

input:checked + .slider::before {
  transform: translateX(16px);
  background-color: var(--color-mid);
}

/* Stats Strip */
.stats-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-box {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  transition: border-color 0.15s ease;
}

.stat-box:hover {
  border-color: #2e4063;
}

.stat-caption {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stat-value.pos {
  color: var(--color-buy);
}

.stat-value.neg {
  color: var(--color-sell);
}

.stat-sub {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Main Chart Card */
.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-card);
  margin-bottom: 24px;
  position: relative;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding: 0 8px;
  flex-wrap: wrap;
  gap: 8px;
}

.chart-legend-custom {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-line {
  width: 14px;
  height: 3px;
  border-radius: 2px;
}

.legend-line.mid { background: var(--color-mid); }
.legend-line.buy { background: var(--color-buy); }
.legend-line.sell { background: var(--color-sell); }

.chart-container {
  width: 100%;
  height: 480px;
  min-height: 360px;
}

/* Footer Info */
.site-footer {
  text-align: center;
  padding: 16px 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.footer-link {
  color: var(--color-mid);
  text-decoration: none;
}

.footer-link:hover {
  text-decoration: underline;
}

/* Loading & Error Overlays */
.overlay-message {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(17, 24, 39, 0.88);
  border-radius: var(--radius-lg);
  z-index: 10;
  gap: 12px;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(56, 189, 248, 0.2);
  border-top-color: var(--color-mid);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Responsive adjustments */
@media (max-width: 900px) {
  .rate-hero {
    grid-template-columns: 1fr;
    gap: 18px;
  }
  .rate-details {
    justify-content: flex-start;
  }
  .big-rate {
    font-size: 2.25rem;
  }
  .chart-container {
    height: 400px;
  }
}

@media (max-width: 640px) {
  body {
    padding: 14px 10px 32px;
  }
  .site-header {
    padding: 18px 16px;
  }
  .header-top {
    flex-direction: column;
    align-items: flex-start;
  }
  .big-rate {
    font-size: 1.85rem;
  }
  .stats-strip {
    grid-template-columns: repeat(2, 1fr);
  }
  .toolbar-section {
    flex-direction: column;
    align-items: stretch;
  }
  .range-switcher {
    display: flex;
    justify-content: space-between;
  }
  .range-tab {
    flex: 1;
    text-align: center;
    padding: 6px 8px;
    font-size: 0.8rem;
  }
  .chart-card {
    padding: 14px 10px;
  }
  .chart-container {
    height: 340px;
  }
}
