/* ============================================================
   CryptoTrackPro — /markets page (loaded only by markets.html)
   Builds on the tokens and components in style.css.
   ============================================================ */

/* Change colours checked for WCAG AA (>= 4.5:1) on the card surface #1a1a2e:
   up 8.4:1, down 5.9:1. The site's --error (#ea4335) is only 4.35:1 there. */
:root {
  --mk-up: #3ecf72;
  --mk-down: #f2706a;
  --mk-row-hover: #1f1f35;
  --mk-head-bg: #1e1e32;
}

/* Elements toggled with the hidden attribute keep their own display otherwise. */
.markets-page [hidden] { display: none !important; }

.mk-sr {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.mk-hero { padding-bottom: 20px; }
.mk-section { padding: 16px 0 48px; }

/* ── Controls bar (sticky under the 64px fixed nav) ─────────── */
.mk-controls {
  position: sticky;
  top: 64px;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 0;
  margin-bottom: 12px;
  background: rgba(15, 15, 26, 0.94);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.mk-search {
  position: relative;
  flex: 1 1 260px;
  max-width: 360px;
}
.mk-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}
.mk-search-input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.mk-search-input::placeholder { color: var(--text-dim); }
.mk-search-input:focus {
  border-color: var(--blue-border);
  box-shadow: 0 0 0 3px var(--blue-dim);
}
.mk-controls-side {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

/* USD / EUR / GBP segmented control. Active uses #b35900 so white text meets AA. */
.mk-seg {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.mk-seg-btn {
  padding: 6px 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.mk-seg-btn:hover { color: var(--text-primary); }
.mk-seg-btn[aria-pressed="true"] { background: #b35900; color: #fff; }
.mk-seg-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* "Updated 12 s ago" pill with a live dot */
.mk-age {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 11em;
  margin: 0;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.mk-dot {
  width: 8px;
  height: 8px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--text-dim);
}
.mk-age.is-live .mk-dot { background: var(--mk-up); animation: mkPulse 2s ease-out infinite; }
.mk-age.is-stale { color: #fdd663; border-color: rgba(249, 171, 0, 0.35); }
.mk-age.is-stale .mk-dot { background: var(--accent-light); }
.mk-age.is-error { color: #f28b82; border-color: rgba(234, 67, 53, 0.35); }
.mk-age.is-error .mk-dot { background: var(--mk-down); }
@keyframes mkPulse {
  0%   { box-shadow: 0 0 0 0 rgba(62, 207, 114, 0.55); }
  70%  { box-shadow: 0 0 0 7px rgba(62, 207, 114, 0); }
  100% { box-shadow: 0 0 0 0 rgba(62, 207, 114, 0); }
}

/* ── Asset-class tabs (only when the snapshot has several classes) ── */
.mk-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
}
.mk-tab {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.mk-tab:hover { color: var(--text-primary); }
.mk-tab[aria-pressed="true"] {
  color: var(--text-primary);
  border-color: var(--accent-border);
  background: var(--accent-dim);
}

/* ── Delayed / error banner ─────────────────────────────────── */
.mk-banner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 12px;
  padding: 10px 14px;
  border: 1px solid rgba(249, 171, 0, 0.35);
  border-radius: var(--radius-sm);
  background: rgba(249, 171, 0, 0.08);
  color: #fdd663;
  font-size: 14px;
  line-height: 1.5;
}
.mk-banner.is-error {
  border-color: rgba(234, 67, 53, 0.35);
  background: rgba(234, 67, 53, 0.08);
  color: #f28b82;
}
.mk-banner-icon { flex-shrink: 0; }
.mk-retry {
  margin-left: auto;
  padding: 6px 16px;
  border: 1px solid currentColor;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.mk-retry:hover { background: rgba(255, 255, 255, 0.06); }
.mk-noscript {
  margin: 0 0 12px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ── Table ──────────────────────────────────────────────────── */
.mk-table-wrap {
  position: relative; /* contains the visually hidden labels so they cannot widen the page */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.mk-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.mk-table th,
.mk-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}
.mk-table tbody tr:last-child > * { border-bottom: 0; }
.mk-table thead th {
  padding-top: 10px;
  padding-bottom: 10px;
  background: var(--mk-head-bg);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}
.mk-table tbody th { font-weight: 400; }
.mk-table .mk-num { text-align: right; }
.mk-col-rank { width: 52px; color: var(--text-dim); }
.mk-col-spark { width: 128px; }
.mk-table .mk-col-sheets { width: 1%; text-align: right; }

/* Sortable headers: real buttons; the arrow follows the th's aria-sort */
.mk-sort {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.mk-sort:hover,
th[aria-sort] .mk-sort { color: var(--text-primary); }
.mk-sort-ico {
  display: inline-block;
  width: 8px;
  font-size: 8px;
  line-height: 1;
}
th[aria-sort="ascending"] .mk-sort-ico::before { content: "\25B2"; }
th[aria-sort="descending"] .mk-sort-ico::before { content: "\25BC"; }

.mk-row > * { transition: background-color 0.15s; }
.mk-row:hover > * { background-color: var(--mk-row-hover); }
.mk-coin {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.mk-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #2a2a44;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}
.mk-name {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
  font-weight: 600;
}
.mk-sym {
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.mk-table .mk-col-price { color: var(--text-primary); font-weight: 600; }
.mk-table .mk-up { color: var(--mk-up); }
.mk-table .mk-down { color: var(--mk-down); }
.mk-table .mk-flat { color: var(--text-muted); }

/* A stale row shows its last confirmed price, dimmed, with an amber dot. */
.mk-table .mk-is-stale .mk-price { color: var(--text-muted); }
.mk-is-stale .mk-price::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--accent-light);
  vertical-align: middle;
}
.mk-flag {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Subtle flash when a price changes between refreshes */
.mk-table td.mk-flash-up { animation: mkFlashUp 1.2s ease-out; }
.mk-table td.mk-flash-down { animation: mkFlashDown 1.2s ease-out; }
@keyframes mkFlashUp {
  from { background-color: rgba(62, 207, 114, 0.22); }
  to   { background-color: rgba(62, 207, 114, 0); }
}
@keyframes mkFlashDown {
  from { background-color: rgba(242, 112, 106, 0.22); }
  to   { background-color: rgba(242, 112, 106, 0); }
}

/* 7-day sparkline */
.mk-spark {
  display: block;
  width: 120px;
  height: 36px;
  overflow: visible;
}
.mk-spark polyline {
  fill: none;
  stroke: var(--text-dim);
  stroke-width: 1.6;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.mk-spark.up polyline { stroke: var(--mk-up); }
.mk-spark.down polyline { stroke: var(--mk-down); }

/* "Sheets" button per row */
.mk-sheets-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.mk-sheets-btn svg { fill: none; stroke: currentColor; stroke-width: 1.4; }
.mk-sheets-btn:hover,
.mk-sheets-btn[aria-expanded="true"] {
  color: var(--accent-light);
  border-color: var(--accent-border);
  background: var(--accent-dim);
}

/* Skeleton rows while the first snapshot loads */
.mk-skel td { padding-top: 17px; padding-bottom: 17px; }
.mk-skel-bar {
  display: block;
  width: 72px;
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.05) 25%, rgba(255, 255, 255, 0.1) 50%, rgba(255, 255, 255, 0.05) 75%);
  background-size: 200% 100%;
  animation: mkShimmer 1.4s linear infinite;
}
.mk-skel .mk-num .mk-skel-bar,
.mk-skel .mk-col-sheets .mk-skel-bar { margin-left: auto; }
.mk-skel .mk-col-rank .mk-skel-bar { width: 18px; }
.mk-skel .mk-col-coin .mk-skel-bar { width: 150px; }
.mk-skel .mk-col-spark .mk-skel-bar { width: 120px; height: 20px; }
.mk-skel .mk-col-sheets .mk-skel-bar { width: 66px; height: 26px; }
@keyframes mkShimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}
.mk-msg td {
  padding: 40px 16px;
  color: var(--text-muted);
  text-align: center;
  white-space: normal;
}

/* Attribution and disclaimer under the table */
.mk-notes {
  display: grid;
  gap: 6px;
  margin-top: 16px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.6;
}
.mk-attribution { color: var(--text-muted); }

/* ── Add-on call to action ──────────────────────────────────── */
.mk-cta { text-align: center; }
.mk-cta h2 {
  margin-bottom: 10px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.3px;
}
.mk-cta p {
  max-width: 560px;
  margin: 0 auto 16px;
  color: var(--text-muted);
  line-height: 1.65;
}
.mk-cta .code-block {
  max-width: 420px;
  margin: 0 auto 20px;
  text-align: left;
}

/* ── "Use in Google Sheets" popover ─────────────────────────── */
.mk-pop {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 150;
  width: 340px;
  max-width: calc(100vw - 32px);
  padding: 16px;
  background: var(--bg-card-alt);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
}
.mk-pop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.mk-pop-title {
  margin: 0;
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 700;
}
.mk-pop-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.mk-pop-close:hover { background: rgba(255, 255, 255, 0.06); color: var(--text-primary); }
.mk-pop-help {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
}
.mk-pop-code { margin: 10px 0 14px; }
.mk-pop-install { width: 100%; }
.mk-pop-note {
  margin: 10px 0 0;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.5;
}

/* Keyboard focus is always visible */
.mk-controls :focus-visible,
.mk-tabs :focus-visible,
.mk-table :focus-visible,
.mk-banner :focus-visible,
.mk-pop :focus-visible {
  outline: 2px solid var(--blue-light);
  outline-offset: 2px;
}

/* ── Narrower desktops and tablets: drop the least essential columns first ── */
@media (max-width: 1060px) {
  .mk-col-vol { display: none; }
}
@media (max-width: 900px) {
  .mk-col-spark { display: none; }
  .mk-name { max-width: 130px; }
  .mk-sheets-label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
}
@media (max-width: 820px) {
  .mk-col-7d { display: none; }
}

/* ── Phones: fewer columns, stacked controls, popover docked at the bottom ── */
@media (max-width: 720px) {
  .mk-col-7d,
  .mk-col-vol,
  .mk-col-spark { display: none; }
  .mk-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .mk-search { flex: 0 0 auto; max-width: none; }
  .mk-controls-side { justify-content: space-between; }
  .mk-table { font-size: 13px; }
  .mk-table th,
  .mk-table td { padding: 10px; }
  /* Keep the coin name in view while the table scrolls sideways */
  .mk-table .mk-col-coin {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--bg-card);
  }
  .mk-table thead .mk-col-coin { background: var(--mk-head-bg); }
  .mk-row:hover > .mk-col-coin { background: var(--mk-row-hover); }
  .mk-name { max-width: 110px; }
  .mk-pop {
    position: fixed;
    top: auto !important;
    left: 12px !important;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-width: none;
  }
}

/* ── Small phones: coin, price, 24h and an icon-only Sheets button ── */
@media (max-width: 640px) {
  .mk-col-rank { display: none; }
  /* Name above ticker so the coin column stays narrow */
  .mk-coin {
    display: grid;
    grid-template-columns: 26px minmax(0, auto);
    column-gap: 8px;
    row-gap: 1px;
  }
  .mk-avatar { grid-row: 1 / span 2; }
  .mk-name { max-width: 104px; line-height: 1.2; }
  .mk-sym { grid-column: 2; font-size: 11px; line-height: 1.2; }
}
@media (max-width: 480px) {
  .mk-col-cap { display: none; }
  .mk-table th,
  .mk-table td { padding: 10px 8px; }
}

/* ── Reduced motion: no pulse, shimmer, flash or hero entrance ── */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .mk-age.is-live .mk-dot,
  .mk-skel-bar,
  .mk-table td.mk-flash-up,
  .mk-table td.mk-flash-down { animation: none; }
  .markets-page .highlight,
  .markets-page .page-hero-label,
  .markets-page .page-hero h1,
  .markets-page .page-hero p { animation: none; }
  .mk-row > *,
  .mk-seg-btn,
  .mk-sheets-btn,
  .mk-search-input { transition: none; }
}
