:root {
  --primary: #1976d2;
  --primary-dark: #1565c0;
  --secondary: #6f48c9;
  --success: #4caf50;
  --danger: #f44336;
  --warning: #ff9800;
  --text: #212121;
  --text-light: #757575;
  --bg: #ffffff;
  --bg-light: #f5f5f5;
  --border: #e0e0e0;
  --radius: 8px;
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  --transition: all 0.3s ease;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --primary: #90caf9;
    --primary-dark: #64b5f6;
    --secondary: #b39ddb;
    --text: #e0e0e0;
    --text-light: #bdbdbd;
    --bg: #1e1e1e;
    --bg-light: #2c2c2c;
    --border: #424242;
  }
}

[data-theme='dark'] {
  --primary: #90caf9;
  --primary-dark: #64b5f6;
  --secondary: #b39ddb;
  --text: #e0e0e0;
  --text-light: #bdbdbd;
  --bg: #1e1e1e;
  --bg-light: #2c2c2c;
  --border: #424242;
}

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

html,
body {
  width: 100%;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: var(--transition);
  padding: 16px;
  max-width: 1200px;
  margin: 0 auto;
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 12px;
}

h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
}

.header-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

button {
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  background-color: var(--primary);
  color: white;
}

button:hover {
  background-color: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

button:active {
  transform: translateY(0);
}

#install-btn {
  display: none;
  background-color: var(--secondary);
}

#install-btn:hover {
  background-color: #5e35b1;
}

/* Value Proposition Banner */
.value-props {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.value-prop {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  background-color: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.vp-icon {
  font-size: 15px;
}

/* Ad Slots */
.ad-slot {
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-light);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  margin: 16px 0;
  position: relative;
  overflow: hidden;
}

.ad-slot .ad-label {
  position: absolute;
  top: 4px;
  left: 8px;
  font-size: 10px;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ad-slot .adsbygoogle {
  width: 100%;
}

.ad-slot .manual-ad {
  display: block;
  width: 100%;
  height: 100%;
}

.ad-slot .manual-ad img {
  width: 100%;
  height: auto;
  max-height: 250px;
  object-fit: contain;
  display: block;
}

/* Tab Navigation (mobile) */
.tab-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
}

.tab-btn {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--bg-light);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.tab-btn:hover {
  transform: none;
  box-shadow: none;
  background-color: var(--bg-light);
}

.tab-btn.active {
  background-color: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Main Container */
main {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Price Sections */
.price-section {
  display: none;
}

.price-section.active {
  display: block;
}

.section-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 12px;
}

/* Desktop: show all sections at once, hide tab buttons, use section titles as quick-nav */
@media (min-width: 900px) {
  .tab-nav {
    display: none;
  }

  .price-section {
    display: block !important;
  }

  .section-title {
    position: sticky;
    top: 0;
    background-color: var(--bg);
    padding: 8px 0;
    z-index: 1;
  }
}

/* Prices Container */
#prices-container,
#base-metals-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

/* Base Metal Card Extras */
.grade-badge {
  padding: 4px 8px;
  background-color: var(--bg-light);
  border: 1px solid var(--border);
  color: var(--text-light);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.grade-details {
  display: none;
  flex-direction: column;
  gap: 6px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
  font-size: 13px;
}

.grade-details.open {
  display: flex;
}

.grade-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--text-light);
}

.grade-row span:first-child {
  color: var(--text);
}

.toggle-grades {
  background: none;
  color: var(--primary);
  padding: 4px 0;
  font-size: 13px;
  text-align: left;
}

.toggle-grades:hover {
  background: none;
  transform: none;
  box-shadow: none;
  text-decoration: underline;
}

/* Rare Earth Categories */
.rare-category {
  background-color: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.rare-category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.rare-category-header h3 {
  font-size: 16px;
  color: var(--primary);
}

.rare-count {
  font-size: 12px;
  color: var(--text-light);
}

.rare-table-wrapper {
  overflow-x: auto;
}

.rare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.rare-table th,
.rare-table td {
  padding: 8px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.rare-table th:first-child,
.rare-table td:first-child {
  text-align: left;
}

.rare-table th {
  color: var(--text-light);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
}

.rare-empty {
  color: var(--text-light);
  font-size: 13px;
  padding: 8px 0;
}

/* Price Card */
.price-card {
  background-color: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  gap: 12px;
  cursor: pointer;
}

.price-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow);
  border-color: var(--primary);
}

.metal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.metal-header h3 {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  margin: 0;
}

.source-badge {
  padding: 4px 8px;
  background-color: var(--primary);
  color: white;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.price-display {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.price {
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
}

.unit {
  font-size: 12px;
  color: var(--text-light);
  font-weight: 600;
  text-transform: uppercase;
}

.change-info {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 14px;
  font-weight: 600;
}

.change-value {
  padding: 4px 8px;
  border-radius: 4px;
}

.change-value.positive {
  background-color: rgba(76, 175, 80, 0.2);
  color: var(--success);
}

.change-value.negative {
  background-color: rgba(244, 67, 54, 0.2);
  color: var(--danger);
}

.change-percent {
  color: var(--text-light);
  font-size: 12px;
}

.timestamp {
  font-size: 12px;
  color: var(--text-light);
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

/* Reference Links */
.reference-links {
  margin: 8px 0;
  padding: 16px;
  background-color: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.reference-links h3 {
  font-size: 14px;
  margin-bottom: 8px;
  color: var(--text);
}

.reference-links a {
  color: var(--primary);
}

/* Loading & Error States */
.loading {
  text-align: center;
  padding: 32px;
  color: var(--text-light);
  font-size: 16px;
}

.no-data,
.error {
  text-align: center;
  padding: 32px;
  border-radius: var(--radius);
  background-color: var(--bg-light);
  color: var(--text-light);
}

.error {
  background-color: rgba(244, 67, 54, 0.1);
  color: var(--danger);
}

/* Responsive Design */
@media (max-width: 768px) {
  body {
    padding: 12px;
  }

  h1 {
    font-size: 24px;
  }

  #prices-container {
    grid-template-columns: 1fr;
  }

  header {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-actions {
    width: 100%;
  }

  button {
    flex: 1;
    min-height: 44px;
  }
}

@media (max-width: 480px) {
  h1 {
    font-size: 20px;
  }

  .price-display {
    flex-direction: column;
  }

  .price {
    font-size: 28px;
  }

  button {
    font-size: 12px;
    padding: 12px;
  }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@supports (padding: max(0px)) {
  body {
    padding: max(16px, env(safe-area-inset-left), env(safe-area-inset-right));
    padding-top: max(16px, env(safe-area-inset-top));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
}
