:root {
  --bg: #0f1115;
  --card-bg: #171a21;
  --border: #2a2e38;
  --text: #f2f2f0;
  --muted: #9aa0ab;
  --gold: #d4af37;
  --green: #4caf7d;
  --red: #e0665f;
  --series-buy: #3987e5;
  --series-sell: #d95926;
  --chart-grid: #2c2c2a;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f5f0;
    --card-bg: #ffffff;
    --border: #e4e0d6;
    --text: #1c1c1c;
    --muted: #6b6b6b;
    --gold: #b8860b;
    --green: #2e8b57;
    --red: #c0392b;
    --series-buy: #2a78d6;
    --series-sell: #eb6834;
    --chart-grid: #e1e0d9;
  }
}

* { box-sizing: border-box; }

:root {
  /* Original system stack, kept as-is for the elements explicitly excluded
     from the Manrope change below: main title, business names, buy/sell
     prices. */
  --font-original: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

body {
  margin: 0;
  font-family: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Exceptions — keep the original font exactly as before the Manrope change. */
h1,
.card h2,
.price-value {
  font-family: var(--font-original);
}

header {
  position: relative;
  text-align: center;
  padding: 2.5rem 1rem 1rem;
}

.filter-bar {
  position: absolute;
  top: 1rem;
  right: 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
}

.locate-btn {
  background: #2a78d6;
  color: #ffffff;
  border: 1px solid #2a78d6;
  border-radius: 8px;
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.locate-btn:hover { background: #2467bd; }
.locate-btn:disabled { opacity: 0.6; cursor: default; }

.filter-bar label {
  font-size: 0.78rem;
  color: var(--muted);
}

.filter-bar select {
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  font-size: 0.82rem;
  font-family: inherit;
}

@media (max-width: 640px) {
  .filter-bar {
    position: static;
    justify-content: center;
    margin-bottom: 0.75rem;
  }
}

h1 {
  margin: 0 0 0.4rem;
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
}

.coin-icon {
  height: 2em;
  width: 2em;
  object-fit: contain;
  border-radius: 50%;
}

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

.updated {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--gold);
  font-weight: 600;
}

.search-bar {
  position: relative;
  max-width: 320px;
  margin: 1rem auto 0;
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
  pointer-events: none;
  opacity: 0.7;
}

.search-input {
  width: 100%;
  background: #f5f5f3;
  color: #1c1c1c;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.55rem 0.9rem 0.55rem 2.1rem;
  font-size: 0.9rem;
  font-family: inherit;
}
.search-input::placeholder { color: #6b6b6b; }
.search-input:focus {
  outline: none;
  border-color: var(--gold);
}

main.cards {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
  max-width: 1000px;
  margin: 1.5rem auto;
  padding: 0 1.25rem;
  width: 100%;
}

main.cards.single-card {
  grid-template-columns: minmax(280px, 320px);
  justify-content: center;
  align-content: start;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.details-toggle {
  align-self: center;
  margin-top: auto;
  background: #ffffff;
  color: #1c1c1c;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-size: 0.82rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
}
.details-toggle:hover { background: #f0f0f0; }

.card-details { display: none; }

.card.expanded .card-details-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.75rem;
}

.card.expanded .card-details-history {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 999;
}
.modal-backdrop.active { display: block; }

body.modal-open { overflow: hidden; }

main.cards.modal-open .card:not(.expanded) {
  visibility: hidden;
}

.card.expanded {
  display: flex;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1000;
  width: min(480px, 92vw);
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.card.expanded .card-details {
  display: flex;
}

.card.expanded .price-change-detail {
  display: block;
}

.card h2 {
  margin: 0;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.live-tag {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}
.live-tag.live { background: rgba(76, 175, 125, 0.15); color: var(--green); }
.live-tag.stale { background: rgba(224, 102, 95, 0.15); color: var(--red); }

.distance-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: #2a78d6;
  color: #ffffff;
  white-space: nowrap;
}
.distance-badge[hidden] { display: none; }

.note a { color: inherit; }

.card a.source-link {
  font-size: 0.8rem;
  color: var(--muted);
  text-decoration: none;
}
.card a.source-link:hover { text-decoration: underline; }

.location-links {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0 0.75rem;
}

.price-row {
  padding: 0.6rem 0;
  border-top: 1px solid var(--border);
}
.price-row:first-of-type { border-top: none; }

.price-row-main {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.price-change {
  margin: 0.2rem 0 0;
  font-size: 0.72rem;
  text-align: right;
}
.price-change.up { color: var(--green); }
.price-change.down { color: var(--red); }
.price-change.neutral { color: var(--muted); }

.price-label {
  color: var(--muted);
  font-size: 0.9rem;
}

.price-value {
  font-size: 1.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.price-value.buy,
.price-value.sell { color: var(--text); }
.price-value.na { color: var(--muted); font-weight: 400; font-size: 1rem; }

.card .note {
  font-size: 0.78rem;
  color: var(--muted);
}

.price-change-time {
  margin: 0.1rem 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: right;
}

footer {
  text-align: center;
  padding: 1.5rem 1rem 2rem;
  color: var(--muted);
  font-size: 0.8rem;
}

footer .sources a {
  color: var(--gold);
  text-decoration: none;
}
footer .sources a:hover { text-decoration: underline; }

.chart-block {
  border-top: 1px solid var(--border);
  padding-top: 0.85rem;
}

.chart-title {
  margin: 0 0 0.5rem;
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.chart-container {
  position: relative;
}

.chart-empty {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  padding: 1.5rem 0;
  text-align: center;
}

.chart-svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.chart-grid {
  stroke: var(--chart-grid);
  stroke-width: 1;
}

.chart-axis-label {
  font-size: 9px;
  fill: var(--muted);
}

.chart-line {
  fill: none;
  stroke-width: 2;
}

.chart-dot {
  cursor: pointer;
}

.chart-legend {
  display: flex;
  gap: 1rem;
  margin-bottom: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.chart-legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.chart-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

.chart-tooltip {
  position: absolute;
  transform: translate(-50%, -130%);
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.72rem;
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.chart-table-toggle {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
}
.chart-table-toggle summary {
  cursor: pointer;
}

.chart-table {
  width: 100%;
  margin-top: 0.5rem;
  border-collapse: collapse;
  font-size: 0.75rem;
}
.chart-table th, .chart-table td {
  text-align: left;
  padding: 0.3rem 0.4rem;
  border-bottom: 1px solid var(--border);
}

.no-results {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
  padding: 2rem 0;
}

.error-banner {
  max-width: 1000px;
  margin: 0 auto 1rem;
  padding: 0.75rem 1.25rem;
  background: rgba(224, 102, 95, 0.12);
  border: 1px solid var(--red);
  color: var(--red);
  border-radius: 10px;
  font-size: 0.85rem;
}

/* --- Alert button (matches .details-toggle) --- */

.alert-btn {
  align-self: flex-start;
  background: #ffffff;
  color: #1c1c1c;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-size: 0.82rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
}
.alert-btn:hover { background: #f0f0f0; }

/* --- Account status widget (lives inside .filter-bar) --- */

.auth-status-wrap {
  position: relative;
}

.auth-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--gold);
  color: #1c1c1c;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  overflow: hidden;
}

.auth-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.auth-menu {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  min-width: 180px;
  z-index: 1100;
  overflow: hidden;
}

.auth-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.65rem 0.9rem;
  cursor: pointer;
}
.auth-menu-item:hover { background: rgba(255, 255, 255, 0.06); }

/* --- Auth modals (login / create alert / my alerts) — independent of the
   card-details modal (#modalBackdrop) used elsewhere on the site. --- */

.auth-modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1199;
}
.auth-modal-backdrop.active { display: block; }

.auth-modal {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1200;
  width: min(360px, 92vw);
  max-height: 85vh;
  overflow-y: auto;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}
.auth-modal:not([hidden]) { display: block; }
.auth-modal-wide { width: min(480px, 92vw); }

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

.auth-modal p { margin: 0 0 1rem; font-size: 0.9rem; }

.auth-modal-error { color: var(--red); font-size: 0.82rem; }

.auth-modal-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1rem;
}

.google-btn {
  background: #2a78d6;
  color: #ffffff;
  border: 1px solid #2a78d6;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
}
.google-btn:hover { background: #2467bd; }

.auth-modal-close {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
}

#alertForm { display: flex; flex-direction: column; gap: 0.85rem; }
#alertForm label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.82rem;
  color: var(--muted);
}
#alertForm input,
#alertForm select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  font-size: 0.9rem;
  font-family: inherit;
}
#alertForm input:disabled { opacity: 0.7; }

.alert-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--border);
}
.alert-row:first-child { border-top: none; }

.alert-row-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.85rem;
}
.alert-status { color: var(--muted); font-size: 0.75rem; }

.alert-row-actions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex-shrink: 0;
}

.alert-toggle-btn,
.alert-delete-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  font-size: 0.75rem;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.alert-delete-btn { color: var(--red); border-color: var(--red); }
