/* ==========================================================================
   CNY FX Tracker — Material Design 3 inspired styles
   ========================================================================== */

:root {
  color-scheme: light;

  --primary: #0b57d0;
  --primary-hover: #0a4cba;
  --on-primary: #ffffff;
  --primary-container: #d3e3fd;
  --on-primary-container: #041e49;

  --secondary: #00696d;
  --secondary-container: #b6ebee;
  --on-secondary-container: #002021;

  --tertiary: #b26a00;
  --tertiary-container: #ffddb0;

  --surface: #ffffff;
  --surface-dim: #f6f8fb;
  --surface-container-low: #f0f4f9;
  --surface-container: #eaeff7;
  --surface-container-high: #e3e9f3;
  --on-surface: #191c20;
  --on-surface-variant: #44474e;

  --outline: #74777f;
  --outline-variant: #c9ccd6;

  --error: #ba1a1a;
  --error-container: #ffdad6;
  --success: #156d2f;
  --warning: #8a5300;

  --shadow-1: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
  --shadow-2: 0 4px 14px rgba(16, 24, 40, 0.1), 0 2px 6px rgba(16, 24, 40, 0.06);
  --shadow-3: 0 10px 30px rgba(16, 24, 40, 0.14);

  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;

  --font-sans: "Roboto", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui,
    -apple-system, "Segoe UI", sans-serif;
  --font-mono: "Roboto Mono", "SFMono-Regular", ui-monospace, "Cascadia Mono", monospace;

  --page-max: 1180px;
  --ease-emphasized: cubic-bezier(0.2, 0, 0, 1);
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  color: var(--on-surface);
  background:
    radial-gradient(1200px 420px at 20% -80px, rgba(11, 87, 208, 0.14), transparent 70%),
    radial-gradient(900px 360px at 100% 0, rgba(0, 105, 109, 0.1), transparent 65%),
    var(--surface-dim);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
p {
  margin: 0;
}

a {
  color: var(--primary);
}

button,
input {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}

/* --------------------------------------------------------------------------
   Skip link
   -------------------------------------------------------------------------- */
.skip-link {
  position: fixed;
  top: -60px;
  left: 16px;
  z-index: 100;
  padding: 12px 20px;
  border-radius: 12px;
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 500;
  text-decoration: none;
  transition: top 0.2s var(--ease-emphasized);
}

.skip-link:focus-visible {
  top: 16px;
}

/* --------------------------------------------------------------------------
   App bar
   -------------------------------------------------------------------------- */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid rgba(201, 204, 214, 0.6);
}

.app-bar__inner {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.brand__mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(135deg, #2f7cf6, var(--primary) 55%, #0842a0);
  box-shadow: 0 6px 16px rgba(11, 87, 208, 0.28);
}

.brand__text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.brand__title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand__subtitle {
  font-size: 12.5px;
  color: var(--on-surface-variant);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-bar__actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
}

/* --------------------------------------------------------------------------
   Layout
   -------------------------------------------------------------------------- */
.page {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 28px 24px 56px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-1);
  padding: 24px 28px;
}

.card__title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card__subtitle {
  margin-top: 4px;
  font-size: 13px;
  color: var(--on-surface-variant);
}

/* --------------------------------------------------------------------------
   Controls
   -------------------------------------------------------------------------- */
.controls {
  padding-bottom: 22px;
}

.controls__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.controls__body {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  position: relative;
  overflow: hidden;
  height: 38px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--outline-variant);
  background: transparent;
  color: var(--on-surface-variant);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition:
    background-color 0.16s ease,
    border-color 0.16s ease,
    color 0.16s ease,
    transform 0.16s ease;
}

.chip:hover {
  background: rgba(11, 87, 208, 0.06);
  border-color: var(--primary);
  color: var(--primary);
}

.chip[aria-pressed="true"] {
  background: var(--secondary-container);
  border-color: transparent;
  color: var(--on-secondary-container);
}

.chip[aria-pressed="true"]:hover {
  background: #a5e2e6;
  color: var(--on-secondary-container);
}

.chip:active {
  transform: scale(0.98);
}

.date-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.date-form__sep {
  padding-bottom: 14px;
  color: var(--on-surface-variant);
  font-size: 14px;
}

.text-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 158px;
}

.text-field__label {
  font-size: 12px;
  font-weight: 500;
  color: var(--on-surface-variant);
  letter-spacing: 0.02em;
}

.text-field input {
  height: 46px;
  width: 100%;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--outline);
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  transition:
    border-color 0.16s ease,
    box-shadow 0.16s ease;
}

.text-field input:hover {
  border-color: var(--on-surface);
}

.text-field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: inset 0 0 0 1px var(--primary);
}

.text-field input.invalid {
  border-color: var(--error);
  box-shadow: inset 0 0 0 1px var(--error);
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 46px;
  padding: 0 26px;
  border: none;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background-color 0.18s ease,
    box-shadow 0.18s ease,
    transform 0.18s ease,
    opacity 0.18s ease;
}

.btn--filled {
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: var(--shadow-1);
}

.btn--filled:hover {
  background: var(--primary-hover);
  box-shadow: var(--shadow-2);
}

.btn--tonal {
  height: 40px;
  padding: 0 20px;
  background: var(--secondary-container);
  color: var(--on-secondary-container);
  font-weight: 500;
}

.btn--tonal:hover {
  background: #a5e2e6;
  box-shadow: var(--shadow-1);
}

.btn--text {
  height: 40px;
  padding: 0 16px;
  background: transparent;
  color: var(--primary);
  font-weight: 500;
}

.btn--text:hover {
  background: rgba(11, 87, 208, 0.07);
}

.btn:active {
  transform: scale(0.985);
}

.btn[disabled] {
  opacity: 0.6;
  cursor: progress;
  transform: none;
}

.icon-btn {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--on-surface-variant);
  cursor: pointer;
  transition: background-color 0.16s ease, color 0.16s ease;
}

.icon-btn:hover {
  background: rgba(11, 87, 208, 0.08);
  color: var(--primary);
}

.icon-btn.spinning svg {
  animation: spin 0.9s linear infinite;
}

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

/* Ripple */
.ripple {
  position: absolute;
  border-radius: 50%;
  transform: scale(0);
  background: currentColor;
  opacity: 0.22;
  pointer-events: none;
  animation: ripple 0.55s ease-out forwards;
}

@keyframes ripple {
  to {
    transform: scale(2.4);
    opacity: 0;
  }
}

/* --------------------------------------------------------------------------
   Segmented buttons
   -------------------------------------------------------------------------- */
.segmented {
  display: inline-flex;
  border: 1px solid var(--outline-variant);
  border-radius: 999px;
  background: var(--surface);
  overflow: hidden;
}

.segmented__item {
  position: relative;
  overflow: hidden;
  height: 40px;
  padding: 0 18px;
  border: none;
  background: transparent;
  color: var(--on-surface-variant);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.18s ease, color 0.18s ease;
}

.segmented__item + .segmented__item {
  border-left: 1px solid var(--outline-variant);
}

.segmented__item:hover {
  background: rgba(11, 87, 208, 0.06);
}

.segmented__item[aria-pressed="true"],
.segmented__item[aria-selected="true"] {
  background: var(--primary);
  color: var(--on-primary);
}

.segmented--lang .segmented__item {
  height: 36px;
  padding: 0 16px;
  font-size: 13px;
}

.segmented--lang .segmented__item[aria-pressed="true"] {
  background: var(--secondary-container);
  color: var(--on-secondary-container);
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   Stats
   -------------------------------------------------------------------------- */
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.stat {
  position: relative;
  background: var(--surface);
  border-radius: 24px;
  box-shadow: var(--shadow-1);
  padding: 20px 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

.stat::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--stat-accent, var(--primary));
  opacity: 0.9;
}

.stat__head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stat__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--stat-tint, var(--primary-container));
  color: var(--stat-accent, var(--primary));
  flex: none;
}

.stat__label {
  font-size: 13px;
  font-weight: 500;
  color: var(--on-surface-variant);
}

.stat__value {
  font-size: 27px;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.stat__value.pos {
  color: var(--error);
}

.stat__value.neg {
  color: var(--success);
}

.stat__meta {
  font-size: 12px;
  color: var(--on-surface-variant);
  line-height: 1.5;
}

.stat__meta strong {
  font-weight: 600;
  color: var(--on-surface);
}

/* --------------------------------------------------------------------------
   Chart
   -------------------------------------------------------------------------- */
.chart-card {
  padding: 24px 24px 14px;
}

.chart-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 0 4px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  padding: 14px 4px 0;
  font-size: 12px;
  font-weight: 500;
}

.legend__item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.legend__swatch {
  width: 18px;
  height: 8px;
  border-radius: 4px;
  background: currentColor;
  flex: none;
}

.legend__swatch--dashed {
  height: 0;
  border-top: 2px dashed currentColor;
  border-radius: 0;
  background: none;
}

.legend__text {
  color: var(--on-surface-variant);
}

.chart-wrap {
  position: relative;
  margin-top: 6px;
}

.chart {
  width: 100%;
  height: 420px;
}

.chart-loader {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  font-size: 13px;
  color: var(--on-surface-variant);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(2px);
  border-radius: var(--radius-lg);
  z-index: 2;
}

.chart-loader[hidden] {
  display: none;
}

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--primary-container);
  border-top-color: var(--primary);
  animation: spin 0.85s linear infinite;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--on-surface-variant);
  font-size: 14px;
  background: var(--surface);
}

.empty-state[hidden] {
  display: none;
}

.chart-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 6px 4px;
  flex-wrap: wrap;
}

.chart-note {
  font-size: 12px;
  color: var(--on-surface-variant);
  line-height: 1.6;
  max-width: 70ch;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--surface-container-low);
  color: var(--on-surface-variant);
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.badge--warn {
  background: #fff1d6;
  color: var(--warning);
}

/* Chart tooltip */
.chart-tooltip {
  min-width: 200px;
}

.chart-tooltip__date {
  font-size: 12px;
  font-weight: 600;
  color: #44474e;
  margin-bottom: 8px;
  letter-spacing: 0.02em;
}

.chart-tooltip__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  font-size: 12.5px;
  line-height: 1.9;
}

.chart-tooltip__label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #44474e;
}

.chart-tooltip__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.chart-tooltip__value {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: #191c20;
}

.chart-tooltip__foot {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed #d7dae2;
  font-size: 11.5px;
  color: #74777f;
}

/* --------------------------------------------------------------------------
   Table
   -------------------------------------------------------------------------- */
.table-card {
  padding: 24px 24px 12px;
}

.table-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 0 4px 14px;
}

.table-card__actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.table-scroll {
  max-height: 460px;
  overflow: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--surface-container);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-container-low);
  color: var(--on-surface-variant);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-align: left;
  padding: 12px 18px;
  white-space: nowrap;
  border-bottom: 1px solid var(--surface-container);
}

.data-table thead th.num {
  text-align: right;
}

.data-table tbody td {
  padding: 12px 18px;
  border-bottom: 1px solid #f1f3f8;
  vertical-align: middle;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:hover {
  background: rgba(11, 87, 208, 0.035);
}

.data-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  white-space: nowrap;
}

.data-table td.date {
  font-variant-numeric: tabular-nums;
  color: var(--on-surface-variant);
  white-space: nowrap;
}

.data-table td.pos {
  color: var(--error);
}

.data-table td.neg {
  color: var(--success);
}

.cell-sub {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--outline);
  margin-top: 1px;
}

.data-table td.table-empty {
  text-align: center;
  padding: 44px 18px;
  color: var(--outline);
  font-size: 13px;
}

.text-field input::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.6;
}

.text-field input::-webkit-calendar-picker-indicator:hover {
  opacity: 1;
}

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */
.footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 8px 0;
  font-size: 12px;
  color: var(--on-surface-variant);
  line-height: 1.7;
}

.footer__sources {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
}

.footer__label {
  font-weight: 600;
  color: var(--on-surface);
}

.footer a {
  color: var(--primary);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.16s ease;
}

.footer a:hover {
  border-bottom-color: currentColor;
}

.footer__disclaimer {
  max-width: 90ch;
}

.footer__limit {
  color: var(--warning);
}

/* --------------------------------------------------------------------------
   Snackbar
   -------------------------------------------------------------------------- */
.snackbar {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 50px;
  padding: 12px 20px;
  border-radius: 12px;
  background: #303134;
  color: #f1f3f4;
  font-size: 13.5px;
  box-shadow: var(--shadow-3);
  transform: translate(-50%, 140%);
  opacity: 0;
  transition:
    transform 0.32s var(--ease-emphasized),
    opacity 0.24s ease;
  max-width: min(92vw, 560px);
}

.snackbar.visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

.snackbar__action {
  border: none;
  background: transparent;
  color: #a8c7fa;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  white-space: nowrap;
}

.snackbar__action:hover {
  background: rgba(168, 199, 250, 0.12);
}

.snackbar__action[hidden] {
  display: none;
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 1020px) {
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .brand__subtitle {
    display: none;
  }

  .data-table thead th,
  .data-table tbody td {
    padding: 10px 12px;
  }

  .controls__body {
    align-items: stretch;
    flex-direction: column;
  }

  .date-form {
    width: 100%;
  }

  .text-field {
    flex: 1 1 150px;
  }

  .chart {
    height: 400px;
  }
}

@media (max-width: 640px) {
  .chart-legend {
    gap: 6px 16px;
    font-size: 11.5px;
  }
}

@media (max-width: 640px) {
  .app-bar__inner {
    padding: 10px 16px;
  }

  .brand__title {
    font-size: 15px;
  }

  .page {
    padding: 18px 14px 44px;
    gap: 14px;
  }

  .card {
    border-radius: 22px;
    padding: 20px 18px;
  }

  .stats {
    gap: 12px;
  }

  .stat {
    padding: 16px 16px 14px;
    border-radius: 20px;
  }

  .stat__value {
    font-size: 22px;
  }

  .chart {
    height: 380px;
  }

  .date-form__sep {
    display: none;
  }

  .btn--filled {
    width: 100%;
  }

  .chart-card__header {
    flex-direction: column;
    align-items: stretch;
  }

  .segmented--tabs {
    align-self: flex-start;
  }

  .table-card__header {
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .data-table {
    min-width: 460px;
  }
}

@media (max-width: 420px) {
  .brand__mark {
    width: 38px;
    height: 38px;
    border-radius: 12px;
  }

  .segmented--lang .segmented__item {
    padding: 0 12px;
  }

  .stats {
    grid-template-columns: 1fr;
  }
}

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