:root {
  --bg: #f3f6fb;
  --card: #ffffff;
  --ink: #0f1f37;
  --muted: #5a6a86;
  --line: #dfe6f3;
  --brand: #1f6feb;
  --brand-soft: #e7f0ff;
  --up: #cf222e;
  --up-bg: #fff1f0;
  --down: #1a7f37;
  --down-bg: #eefbe5;
  --radius: 14px;
  --shadow: 0 8px 26px rgba(20, 50, 100, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "PingFang SC", "Noto Sans SC", "Helvetica Neue", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 20% 0%, #f8fbff, var(--bg));
  -webkit-font-smoothing: antialiased;
}

/* ===== Home page ===== */

.home-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.home-wrap {
  width: min(960px, 92vw);
  padding: 32px 0 48px;
}

.home-header h1,
.page-header h1 {
  margin: 0;
  font-size: clamp(1.5rem, 2.2vw, 2.3rem);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--brand);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: 0.78rem;
  font-weight: 700;
}

.subtitle,
.page-subtitle,
.page-footer p {
  color: var(--muted);
  margin: 6px 0 0;
}

.card-grid {
  margin-top: 32px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}

.portal-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  text-decoration: none;
  color: inherit;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.portal-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 32px rgba(20, 50, 100, 0.1);
}

.portal-card h2 {
  margin: 0;
  font-size: 1.15rem;
}

.card-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--brand-soft);
  color: var(--brand);
  padding: 2px 8px;
  border-radius: 6px;
  width: fit-content;
}

.card-preview {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 8px 0 4px;
}

.card-rate {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.card-change {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 2px 8px;
  border-radius: 6px;
}

.card-desc {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}

.card-link {
  display: inline-block;
  margin-top: 8px;
  color: var(--brand);
  font-weight: 600;
  font-size: 0.92rem;
}

.home-footer {
  margin-top: 40px;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
}

/* ===== Detail page ===== */

.page-wrap {
  width: min(1120px, 92vw);
  margin: 24px auto 36px;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.back-link {
  color: var(--brand);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
}

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

.page-header {
  margin-bottom: 18px;
}

.page-subtitle {
  font-size: 0.92rem;
}

.refresh-btn {
  border: none;
  border-radius: 10px;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 0.88rem;
  transition: background 0.15s ease;
  white-space: nowrap;
}

.refresh-btn:hover {
  background: #d4e5ff;
}

.refresh-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Status cards */

.status-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.status-card,
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.status-card {
  padding: 18px 20px;
}

.label {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
}

.big {
  margin: 6px 0;
  font-size: clamp(1.3rem, 2.4vw, 2rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.change {
  margin: 0 0 4px;
  font-size: 0.85rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.change.up {
  color: var(--up);
}

.change.down {
  color: var(--down);
}

.change.flat {
  color: var(--muted);
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 0.82rem;
  color: var(--muted);
}

.stat-row .up {
  color: var(--up);
}

.stat-row .down {
  color: var(--down);
}

/* Panels / charts */

.panel {
  padding: 18px 20px;
  margin-bottom: 16px;
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 1rem;
  font-weight: 600;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 14px;
}

.panel-head h2 {
  margin: 0;
}

.panel-action {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--brand);
  cursor: pointer;
  white-space: nowrap;
}

.panel-action:hover {
  text-decoration: underline;
}

.chart-wrap {
  position: relative;
}

canvas {
  display: block;
  width: 100%;
}

.chart-crosshair {
  position: absolute;
  width: 1px;
  background: var(--brand);
  opacity: 0.3;
  pointer-events: none;
  display: none;
}

.chart-tooltip {
  position: absolute;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
  pointer-events: none;
  display: none;
  z-index: 10;
  white-space: nowrap;
}

.tooltip-date {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 2px;
}

.tooltip-value {
  display: block;
  font-size: 1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Table */

.table-wrap {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 520px;
}

th,
td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tbody tr:nth-child(even) {
  background: rgba(243, 246, 251, 0.5);
}

tbody tr:last-child {
  background: var(--brand-soft);
  font-weight: 600;
}

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

.page-footer {
  margin-top: 8px;
  font-size: 0.82rem;
}

/* Loading */

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 0;
  color: var(--muted);
  gap: 16px;
}

.loading-state p {
  margin: 0;
  font-size: 0.92rem;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Error banner */

.error-banner {
  background: #fff1f0;
  border: 1px solid #ffccc7;
  color: #a8071a;
  padding: 12px 20px;
  border-radius: 10px;
  margin-bottom: 16px;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.error-banner button {
  border: none;
  background: none;
  color: #a8071a;
  font-weight: 700;
  cursor: pointer;
  font-size: 1rem;
  padding: 0 4px;
}

/* Modal */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-box {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
  width: min(720px, 92vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  transform: translateY(12px);
  transition: transform 0.2s ease;
}

.modal-overlay.open .modal-box {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
}

.modal-header h3 {
  margin: 0;
  font-size: 1.05rem;
}

.modal-close {
  border: none;
  background: none;
  font-size: 1.2rem;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.modal-close:hover {
  background: var(--line);
}

.modal-body {
  overflow-y: auto;
  padding: 0 24px 24px;
}

.modal-body table {
  min-width: 100%;
}

.modal-body th,
.modal-body td {
  padding: 8px 10px;
  font-size: 0.85rem;
}

.modal-body .change-cell {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.modal-body .change-cell.up {
  color: var(--up);
}

.modal-body .change-cell.down {
  color: var(--down);
}

/* Responsive */

@media (max-width: 900px) {
  .status-row {
    grid-template-columns: 1fr 1fr;
  }

  .status-row .status-card:last-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 600px) {
  .status-row {
    grid-template-columns: 1fr;
  }

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

  .panel {
    padding: 14px;
  }
}

/* Dark mode */

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --card: #161b22;
    --ink: #e6edf3;
    --muted: #8b949e;
    --line: #30363d;
    --brand: #58a6ff;
    --brand-soft: #1a2332;
    --up: #f85149;
    --up-bg: #2d1a1a;
    --down: #3fb950;
    --down-bg: #1a2d1a;
    --shadow: 0 8px 26px rgba(0, 0, 0, 0.3);
  }

  body {
    background: var(--bg);
  }

  tbody tr:nth-child(even) {
    background: rgba(22, 27, 34, 0.6);
  }

  .error-banner {
    background: #2d1a1a;
    border-color: #5c2020;
    color: #f85149;
  }

  .error-banner button {
    color: #f85149;
  }

  .refresh-btn:hover {
    background: #253545;
  }
}
