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

:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --border: #e2e6ea;
  --border-light: #f0f2f5;
  --text: #1a1d21;
  --text-muted: #6b7280;
  --accent: #1d4ed8;
  --accent-light: #eff6ff;
  --up: #15803d;
  --up-bg: #f0fdf4;
  --down: #b91c1c;
  --down-bg: #fef2f2;
  --tag-bg: #f1f5f9;
  --tag-text: #374151;
  --sidebar-w: 220px;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

/* ── Layout ── */
.app {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  display: flex;
  align-items: center;
  gap: 32px;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}

header h1 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

header h1 span {
  color: var(--accent);
}

nav {
  display: flex;
  gap: 4px;
}

nav button {
  background: none;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

nav button:hover {
  background: var(--border-light);
  color: var(--text);
}

nav button.active {
  background: var(--accent-light);
  color: var(--accent);
}

.body {
  display: flex;
  align-items: flex-start;
}

/* ── Sidebar ── */
aside {
  width: var(--sidebar-w);
  flex-shrink: 0;
  padding: 24px 16px;
  border-right: 1px solid var(--border);
  min-height: calc(100vh - 56px);
  background: var(--surface);
  position: sticky;
  top: 56px;
  overflow-y: auto;
  max-height: calc(100vh - 56px);
}

.filter-group {
  margin-bottom: 24px;
}

.filter-group h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.filter-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
}

.filter-group label:hover {
  color: var(--accent);
}

.filter-group input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.group-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-bottom: 10px;
}

.group-btn {
  background: var(--tag-bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  text-align: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.group-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

.group-btn.active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

.mineral-checks {
  border-top: 1px solid var(--border-light);
  padding-top: 8px;
}

.filter-actions {
  margin-bottom: 16px;
  display: flex;
  gap: 6px;
}

.btn-action {
  flex: 1;
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px 8px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.btn-action:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Main content ── */
main {
  flex: 1;
  padding: 28px 32px;
  min-width: 0;
}

.section {
  display: none;
}

.section.active {
  display: block;
}

.section-header {
  margin-bottom: 20px;
}

.section-header h2 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.section-header p {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 4px;
}

.count-badge {
  display: inline-block;
  background: var(--tag-bg);
  border-radius: 20px;
  padding: 1px 8px;
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 8px;
  font-weight: 500;
}

/* ── Deal cards ── */
.deal-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.deal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 8px;
  transition: border-color 0.15s;
}

.deal-card:hover {
  border-color: #cbd5e1;
}

.deal-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.deal-date {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

.deal-type {
  display: inline-block;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  letter-spacing: 0.02em;
}

.deal-type.type-trade { background: #fefce8; color: #a16207; }
.deal-type.type-mou { background: #f5f3ff; color: #6d28d9; }
.deal-type.type-statement { background: #fff7ed; color: #c2410c; }
.deal-type.type-non { background: #f0fdf4; color: #15803d; }
.deal-type.type-harmful { background: #fef2f2; color: #b91c1c; }
.deal-type.type-liberalising { background: #f0fdf4; color: #15803d; }

.deal-summary {
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
  margin-bottom: 10px;
}

.deal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.mineral-tags {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.mineral-tag {
  background: var(--tag-bg);
  color: var(--tag-text);
  font-size: 11px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 4px;
}

.deal-link {
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

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

/* ── Project cards ── */
.project-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 8px;
  transition: border-color 0.15s;
}

.project-card:hover {
  border-color: #cbd5e1;
}

.project-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.project-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.project-type {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  letter-spacing: 0.02em;
}

.project-type.type-mine {
  background: #fdf4ff;
  color: #7e22ce;
}

.project-type.type-refinery {
  background: #fff7ed;
  color: #c2410c;
}

/* ── Price cards ── */
.price-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.price-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  transition: border-color 0.15s;
}

.price-card:hover {
  border-color: #cbd5e1;
}

.price-card.up {
  border-left: 3px solid var(--up);
}

.price-card.down {
  border-left: 3px solid var(--down);
}

.price-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 8px;
}

.price-mineral {
  font-size: 15px;
  font-weight: 600;
}

.price-change {
  font-size: 16px;
  font-weight: 700;
}

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

.price-period {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.price-date {
  font-size: 11px;
  color: var(--text-muted);
}

.price-summary {
  font-size: 13px;
  color: var(--text);
  line-height: 1.6;
  margin-bottom: 10px;
}

/* ── New badge & highlight ── */
.new-badge {
  display: inline-block;
  background: #16a34a;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 2px 7px;
  border-radius: 4px;
  vertical-align: middle;
  flex-shrink: 0;
}

.deal-card.is-new,
.project-card.is-new {
  border-left: 3px solid #16a34a;
  background: #f8fffe;
}

.price-card.is-new {
  outline: 2px solid #16a34a;
  outline-offset: -2px;
}

/* ── Source badge (SCMP etc.) ── */
.source-badge {
  display: inline-block;
  background: #fef9c3;
  color: #854d0e;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

/* ── Loading spinner ── */
.loading-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 40px 0;
  color: var(--text-muted);
  font-size: 13px;
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

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

/* ── Trade flow cards ── */
.trade-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.trade-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.trade-card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
  gap: 8px;
  flex-wrap: wrap;
}

.trade-mineral {
  font-size: 14px;
  font-weight: 600;
}

.trade-total {
  font-size: 11px;
  color: var(--text-muted);
}

.trade-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  border-top: 1px solid var(--border-light);
  font-size: 12px;
}

.trade-rank {
  color: var(--text-muted);
  font-weight: 600;
  width: 14px;
  flex-shrink: 0;
}

.trade-country {
  flex: 1;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.trade-value {
  font-weight: 600;
  color: var(--text);
  flex-shrink: 0;
}

/* ── Empty state ── */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty p {
  font-size: 14px;
}

/* ── Mobile filter toggle button (hidden on desktop) ── */
#filter-toggle {
  display: none;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  header {
    padding: 0 16px;
    height: auto;
    padding-top: 10px;
    padding-bottom: 10px;
    gap: 8px;
    flex-wrap: wrap;
  }

  header h1 {
    font-size: 14px;
  }

  nav button {
    padding: 5px 10px;
    font-size: 12px;
  }

  .body {
    flex-direction: column;
  }

  #filter-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: var(--surface);
    border: none;
    border-bottom: 1px solid var(--border);
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    letter-spacing: 0.02em;
  }

  #filter-toggle:hover {
    color: var(--text);
    background: var(--bg);
  }

  aside {
    display: none;
    width: 100%;
    min-height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 16px;
    max-height: none;
  }

  .body.filters-open aside {
    display: block;
  }

  .filter-group {
    margin-bottom: 16px;
  }

  .filter-group:last-child {
    margin-bottom: 0;
  }

  .group-btns {
    grid-template-columns: repeat(4, 1fr);
  }

  .mineral-checks {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 12px;
  }

  main {
    padding: 16px;
  }

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