/* ════════════════════════════════════════════════
   AstroE TrendBoard — Dashboard page
   Desktop: stat cards + full-width table. Hovering a row previews the chart
            panel on the right; clicking pins it (.is-pinned) with full details.
   Mobile:  hero → (chart card after a tap) → token list → galaxy banner
   ════════════════════════════════════════════════ */

.dash {
  display: grid; gap: 16px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "stats" "table";
  align-items: start;
}
.dash-hero, .dash-banner { display: none; }
.dash-stats { grid-area: stats; }
.mw { grid-area: table; }
.cp { grid-area: chart; }
.dash:not(.has-panel) .cp { display: none; }
.dash.has-panel .cp { animation: panel-in var(--slow) var(--ease-out) both; }
@keyframes panel-in { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
.cp-close { width: 34px; height: 34px; }

/* ════════ Overview stat cards ════════ */
.dash-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.dash.is-pinned .dash-stats { gap: 8px; }
.dash.is-pinned .kpi { padding: 12px; }
.dash.is-pinned .kpi-v { font-size: 19px; }
.dash.is-pinned .kpi-s { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi {
  all: unset; box-sizing: border-box; cursor: pointer;
  display: flex; flex-direction: column; gap: 4px; padding: 14px 16px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-2xl);
  transition: border-color var(--fast), transform var(--fast) var(--ease-out);
}
.kpi[tabindex="-1"] { cursor: default; }
.kpi:hover:not([tabindex="-1"]) { border-color: var(--accent); }
.kpi:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.kpi-l { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.kpi-v { font-family: var(--font-display); font-size: 24px; font-weight: 600; letter-spacing: -.01em; line-height: 1.2; }
.kpi-s { font-size: 12px; color: var(--muted); }

.sort { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.sort select {
  height: 30px; padding: 0 26px 0 10px; border-radius: var(--r-pill); border: 1px solid var(--line2);
  background: transparent; color: var(--text); font: inherit; font-size: 12px; cursor: pointer;
}
.sort select:hover { border-color: var(--accent); }
.sort select option { background: var(--tip); color: var(--text); }

.orb--lg { width: 38px; height: 38px; font-size: 15px; }

/* ════════ Market Watch table ════════ */
.mw { display: flex; flex-direction: column; overflow: hidden; container: mw / inline-size; }
.mw-bar { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.mw-bar .hint { margin-left: 0; font-size: 12px; color: var(--muted); white-space: nowrap; }
.mw-bar-title { display: none; }

.chips { display: flex; gap: 8px; min-width: 0; }
.chip {
  flex-shrink: 0; height: 30px; padding: 0 12px; border-radius: var(--r-pill);
  border: 1px solid var(--line2); background: transparent; color: var(--muted); font-size: 12px; white-space: nowrap;
  transition: color var(--fast), background-color var(--fast), border-color var(--fast), transform var(--fast) var(--ease-out);
}
.chip:hover { color: var(--text); border-color: var(--accent); }
.chip:active { transform: scale(.97); }
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.chip--m { display: none; }

.mw-cols, .row {
  display: grid; gap: 10px; align-items: center;
  grid-template-columns: 28px minmax(140px, 1fr) minmax(70px, 1.2fr) 64px 72px 64px 84px 100px 56px;
  padding: 0 16px;
}
.mw-cols {
  padding-block: 11px; border-bottom: 1px solid var(--line);
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .08em; color: var(--muted);
}
.mw-cols .r, .row .r { text-align: right; justify-self: end; }

.mw-rows { position: relative; }
.row {
  position: relative; height: 62px; border-bottom: 1px solid var(--line);
  transition: background-color var(--fast);
}
.row:hover { background: var(--accent-soft); }
.row.is-selected { background: var(--accent-soft); }
.row.is-selected::after { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 2px; border-radius: 2px; background: var(--accent); }
.row:has(.row-btn:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }
.row-in { animation: rise-in var(--base) var(--ease-out) both; animation-delay: calc(var(--i, 0) * 25ms); }

.c-rank { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
.c-token { display: flex; align-items: center; gap: 10px; min-width: 0; }
.row-btn {
  all: unset; cursor: pointer; display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.row-btn::after { content: ""; position: absolute; inset: 0; z-index: 1; } /* whole row is the hit area */
.row-btn:focus-visible { outline: none; }
.sym { font-family: var(--font-mono); font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; transition: color var(--fast); }
.row:hover .sym { color: var(--accent-text); }
.sub { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub-m { display: none; }
.c-heat { font-family: var(--font-mono); font-size: 13.5px; font-weight: 600; }
.c-num { font-family: var(--font-mono); font-size: 13px; }
.c-eng { color: var(--muted); }
.c-seen { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
.mw-cols .h-bar { text-align: left; }
.hbar { display: block; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.hbar i { display: block; height: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--accent), var(--accent-text)); transform: scaleX(var(--p)); transform-origin: left; transition: transform var(--slow) var(--ease-out); }
.c-watch { width: 12px; height: 12px; color: var(--accent-text); flex-shrink: 0; }
.c-watch path { fill: currentColor; }

.mw-empty { padding: 48px 20px; text-align: center; color: var(--muted); font-size: 13px; }
.mw-empty strong { display: block; margin-bottom: 4px; color: var(--text); font-size: 14px; font-weight: 600; }

.mw-foot { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 54px; margin-top: auto; }
.pager { display: flex; align-items: center; gap: 4px; font-family: var(--font-mono); font-size: 12px; }
.pager button.pg {
  width: 30px; height: 30px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--muted);
  transition: color var(--fast), background-color var(--fast);
}
.pager button.pg:hover { color: var(--text); }
.pager button.pg[aria-current="page"] { background: var(--accent-soft); color: var(--text); }
.pager .gap { width: 20px; text-align: center; color: var(--faint-text); }
.pager .icon-btn { width: 30px; height: 30px; border-radius: var(--r-sm); }
.pager .icon-btn:disabled { opacity: .35; cursor: default; transform: none; }
.mw-more { display: none; }

/* ════════ Chart panel ════════ */
.cp {
  display: flex; flex-direction: column; gap: 14px; padding: 18px;
  background-image: radial-gradient(ellipse 360px 200px at 0% 0%, var(--accent-soft), transparent 70%);
}
.cp-head { display: flex; align-items: flex-start; gap: 12px; }
.cp-id { display: flex; flex-direction: column; gap: 4px; flex-grow: 1; min-width: 0; }
.cp-sym { font-family: var(--font-display); font-size: 22px; font-weight: 600; letter-spacing: -.01em; line-height: 1.2; }
.cp-sub { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.cp-sub b { font-weight: 600; }
.cp-sub-m, .cp-heat-m, .cp-open-m { display: none; }
.cp-head .icon-btn { width: 34px; height: 34px; }
.cp-tf { display: flex; align-items: center; gap: 10px; }
.cp-main { display: flex; flex-direction: column; gap: 14px; }
.cp-tf > span { font-size: 12px; color: var(--muted); }

.chart-box {
  position: relative; height: 274px; border-radius: var(--r-lg);
  background: var(--chart); border: 1px solid var(--line); overflow: hidden;
}

.cp-stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.cp-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.cp-actions .btn { width: 100%; }

/* ════════ ≥1024px: preview / pinned panel ════════
   The panel is a fixed drawer on the right. Hover previews it over the table;
   clicking pins it (adds .is-pinned): the table steps aside and the details show. */
@media (min-width: 1024px) {
  .dash:not(.has-panel) .cp { display: flex; opacity: 0; visibility: hidden; pointer-events: none; transform: translateX(28px); animation: none;
    transition: opacity var(--base) var(--ease-out), transform var(--base) var(--ease-out), visibility 0s linear var(--base); }
  .cp {
    position: fixed; top: 14px; right: 14px; width: var(--chart-panel-w); max-height: calc(100vh - 28px); z-index: var(--z-panel);
    overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin;
    background-color: var(--frame); -webkit-backdrop-filter: blur(22px); backdrop-filter: blur(22px);
    box-shadow: 0 24px 60px rgba(0, 0, 0, .45);
  }
  .dash.has-panel .cp { opacity: 1; visibility: visible; transform: none; transition: opacity var(--base) var(--ease-out), transform var(--base) var(--ease-out); }
  .cp-hint { display: block; }
  .cp { padding: 14px; gap: 10px; }
  .cp .chart-box { height: 190px; }
  .dash:not(.is-pinned) .cpm--pin { display: none; }
  .dash.is-pinned .cp-hint { display: none; }
  .cp-full { display: none; grid-column: 1 / -1; }
  .dash.is-pinned .cp-full { display: inline-flex; }
}
@media (min-width: 1180px) { .dash.is-pinned { margin-right: calc(var(--chart-panel-w) + 12px); } }
@media (max-width: 1279.98px) { :root { --chart-panel-w: 320px; } }

.cp-hint { display: none; margin: -2px 0 0; font-size: 12px; color: var(--muted); text-align: center; }
.cp-full { display: none; }
.cp-more { display: flex; flex-direction: column; gap: 16px; }
.cpm { display: flex; flex-direction: column; gap: 8px; padding-top: 14px; border-top: 1px solid var(--line); }
.cpm h3 { font-family: var(--font-mono); font-size: 10.5px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.cpm-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.cpm-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cpm-grid .stat small { font-size: 10px; font-weight: 400; color: var(--muted); }
.cpm-ca { display: flex; align-items: center; gap: 10px; }
.cpm-ca code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-family: var(--font-mono); font-size: 12px; padding: 8px 10px; border-radius: var(--r-md); background: var(--input); border: 1px solid var(--line); }
.cpm-ca .btn { height: 34px; }
.cpm-empty { font-size: 12px; color: var(--muted); }
.cpm-snaps { display: flex; flex-direction: column; }
.cpm-snaps li { display: grid; grid-template-columns: 1fr 48px 60px 52px; gap: 10px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line); font-family: var(--font-mono); font-size: 11.5px; }
.cpm-snaps li:last-child { border-bottom: 0; }
.cpm-snaps li > span:first-child { color: var(--muted); }
.cpm-snaps li > span:last-child { text-align: right; }
.cpm-snaps .lvl { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.cpm-snaps .lvl i { display: block; height: 100%; background: var(--accent); transform: scaleX(var(--p)); transform-origin: left; }
.cpm-post { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border-radius: var(--r-lg); background: var(--input); border: 1px solid var(--line); }
.cpm-post-top { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.cpm-post-top .orb { width: 22px; height: 22px; font-size: 9px; }
.cpm-post-top span:last-child { margin-left: auto; color: var(--muted); font-size: 11px; }
.cpm-post p { font-size: 12.5px; line-height: 1.45; white-space: pre-line; }
.cpm-post .cash { color: var(--accent-text); font-family: var(--font-mono); }
.cpm-post a { font-size: 11.5px; color: var(--accent-text); }
.cpm-tags, .cpm-rel { display: flex; flex-wrap: wrap; gap: 6px; }
.cpm-tags span { padding: 3px 9px; border-radius: var(--r-pill); border: 1px solid var(--line2); font-size: 11.5px; color: var(--muted); }
.cpm-rel .chip { font-family: var(--font-mono); }

/* ════════ Table columns follow the table's own width (it narrows when the panel is pinned) ════════ */
@media (min-width: 1024px) {
  @container mw (max-width: 819px) {
    .mw-cols, .row { grid-template-columns: 28px minmax(120px, 1fr) minmax(70px, 1.2fr) 64px 72px 64px 84px 100px; }
    .c-seen, .h-seen, .mw-bar .hint { display: none; }
  }
  @container mw (max-width: 739px) {
    .mw-cols, .row { grid-template-columns: 28px minmax(120px, 1fr) 64px 72px 64px 84px 100px; }
    .c-bar, .h-bar, button.chip--d { display: none; }
  }
  @container mw (max-width: 639px) {
    .mw-cols, .row { grid-template-columns: 28px minmax(100px, 1fr) 64px 84px 96px; }
    .c-mentions, .c-eng, .h-num, .h-eng { display: none; }
  }
}

/* ════════ <1024px: mobile dashboard ════════ */
@media (max-width: 1023.98px) {
  .dash {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "hero" "chart" "table" "banner";
    gap: 20px; padding-bottom: 8px;
  }
  .dash.has-panel .cp { animation-name: rise-in; }
  .cp-head .cp-close { width: var(--tap); height: var(--tap); border-radius: 12px; }

  .dash-hero { grid-area: hero; display: flex; flex-direction: column; gap: 12px; padding-top: 22px; }
  .dash-hero .eyebrow { color: var(--accent-text); font-size: 11px; }
  .dash-hero h1 { font-family: var(--font-display); font-size: 34px; line-height: 1.05; font-weight: 700; letter-spacing: -.03em; }
  .dash-hero p { font-size: 15px; line-height: 1.5; color: var(--muted); }
  .dash-hero p b { font-family: var(--font-mono); font-weight: 400; color: var(--text); }
  .dash-hero .search { width: 100%; height: 46px; padding: 0 14px; border-radius: var(--r-lg); }
  .dash-hero .search input { font-size: 16px; }

  /* Featured chart card */
  .cp { padding: 14px; gap: 12px; border-radius: var(--r-3xl); scroll-margin-top: 110px; }
  .cp-head { align-items: center; gap: 10px; }
  .cp-head .orb--lg { width: 36px; height: 36px; font-size: 14px; }
  .cp-sym { font-size: 19px; }
  .cp-sub, .cp-head > .cp-open, .cp-stats, .cp-actions { display: none; }
  .cp-sub-m { display: block; font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); }
  .cp-heat-m { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-family: var(--font-mono); }
  .cp-heat-m b { font-size: 20px; font-weight: 600; }
  .cp-heat-m span { font-size: 11px; font-weight: 600; }
  .cp-main { order: 2; }
  .chart-box { height: 222px; }
  .cp-tf { order: 3; gap: 8px; }
  .cp-tf > span { display: none; }
  .cp-tf .seg { flex-grow: 1; justify-content: space-between; }
  .cp-tf .seg button { height: 32px; }
  .cp-open-m {
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
    width: var(--tap); height: 38px; border-radius: 12px; background: var(--accent); color: var(--on-accent);
  }
  .cp-open-m svg { width: 15px; height: 15px; }

  /* Token list */
  .mw { border-radius: 0; background: none; border: 0; overflow: visible; }
  .mw-bar { flex-direction: column; align-items: stretch; gap: 12px; padding: 0; border: 0; }
  .mw-bar-title { display: flex; align-items: center; justify-content: space-between; }
  .mw-bar .hint { display: none; }
  .mw-bar-title .hint-m { font-size: 12px; color: var(--muted); }
  .chips { overflow-x: auto; scrollbar-width: none; margin: -5px -16px; padding: 5px 16px; }   /* 5px: room for 44px hit areas */
  .chips::-webkit-scrollbar { display: none; }
  .chip { height: 34px; padding: 0 14px; font-size: 13px; }
  .chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
  .chip--d { display: none; }
  .chip--m { display: inline-block; }
  .mw-cols { display: none; }
  .mw-rows { margin-top: 12px; border-radius: var(--r-3xl); background: var(--panel); border: 1px solid var(--line); overflow: hidden; }

  .row {
    height: auto; min-height: 60px; padding: 12px 14px; gap: 4px 12px;
    grid-template-columns: 14px minmax(0, 1fr) 54px 62px;
    grid-template-areas: "rank token trend heat" "rank token trend change";
  }
  .row:last-child { border-bottom: 0; }
  .c-rank { grid-area: rank; font-size: 11px; }
  .c-token { grid-area: token; gap: 12px; }
  .c-token .orb { width: 34px; height: 34px; font-size: 13px; }
  .sym { font-size: 14px; }
  .sub-d { display: none; }
  .sub-m { display: block; font-family: var(--font-mono); font-size: 10.5px; }
  .c-heat { grid-area: heat; font-size: 14px; align-self: end; }
  .c-change { grid-area: change; align-self: start; }
  .c-change .chg { padding: 1px 5px; font-size: 10.5px; border-radius: 5px; }
  .c-trend { grid-area: trend; }
  .c-trend .spark { width: 54px; height: 22px; }
  .c-mentions, .c-eng, .c-bar, .c-seen, .cp-more, .cp-hint, .dash-stats, .sort { display: none; }

  .mw-foot { display: none; }
  .mw-more {
    display: flex; align-items: center; justify-content: center; width: 100%; height: 50px;
    border: 0; border-top: 1px solid var(--line); background: transparent; color: var(--accent-text); font-size: 14px; font-weight: 500;
  }
  .mw-more[hidden] { display: none; }
  /* "Show all" is the list card's last row */
  .mw:has(.mw-more:not([hidden])) .mw-rows { border-bottom-left-radius: 0; border-bottom-right-radius: 0; border-bottom: 0; }
  .mw-more { background: var(--panel); border: 1px solid var(--line); border-radius: 0 0 var(--r-3xl) var(--r-3xl); }

  /* Galaxy banner */
  .dash-banner {
    grid-area: banner; position: relative; overflow: hidden; display: flex; flex-direction: column; gap: 8px;
    padding: 20px; border-radius: var(--r-3xl); color: var(--text);
    background-image: radial-gradient(circle at 85% 50%, var(--g1), transparent 55%);
  }
  .dash-banner:hover { opacity: 1; }
  .dash-banner .eyebrow { color: var(--accent-text); }
  .dash-banner strong { max-width: 200px; font-family: var(--font-display); font-size: 22px; font-weight: 600; line-height: 1.15; }
  .dash-banner span:not(.eyebrow):not(.bn) { max-width: 200px; font-size: 13px; color: var(--muted); }
  .bn { position: absolute; top: 50%; border-radius: 50%; pointer-events: none; }
  .bn-sun { right: 26px; width: 56px; height: 56px; margin-top: -28px; background: radial-gradient(circle at 36% 30%, #FBCFE8, #EC4899 45%, #6B1440 85%); box-shadow: 0 0 40px rgba(236, 72, 153, .6); }
  .bn-ring { right: -6px; width: 120px; height: 120px; margin-top: -60px; border: 1px dashed var(--line2); animation: spin 60s linear infinite; }
  .bn-ring::after { content: ""; position: absolute; left: 50%; top: -7px; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; background: var(--up); box-shadow: 0 0 12px var(--up); }
}
