/* Heatmap page navigation and mobile-first interaction layer. */
.heatmap-mobile-brand,
.heatmap-bottom-nav,
.detail-sheet-close,
.mobile-heatmap-toggle {
  display: none;
}

.heatmap-desktop-nav {
  display: flex;
  gap: 6px;
  margin-top: 18px;
}

.heatmap-desktop-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(15, 23, 42, 0.48);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.heatmap-desktop-nav a:hover,
.heatmap-desktop-nav a.is-active {
  color: #e0f2fe;
  border-color: rgba(96, 165, 250, 0.4);
  background: rgba(37, 99, 235, 0.2);
}

#refreshBtn svg {
  display: none;
}

.heatmap-sheet-backdrop[hidden] {
  display: none;
}

.heatmap > .empty-detail {
  grid-column: 1 / -1;
  grid-row: 1 / span 4;
  min-height: 220px;
}

@media (max-width: 640px) {
  html {
    scroll-padding-bottom: calc(78px + env(safe-area-inset-bottom));
  }

  body.mobile-detail-open {
    overflow: hidden;
    touch-action: none;
  }

  .app-shell {
    max-width: 100%;
    padding: 14px 10px calc(82px + env(safe-area-inset-bottom));
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 72;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: calc(56px + env(safe-area-inset-top));
    margin: -14px -10px 8px;
    padding: env(safe-area-inset-top) 10px 0;
    border-bottom: 1px solid rgba(78, 98, 124, 0.32);
    background: rgba(8, 13, 21, 0.94);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
    backdrop-filter: blur(18px);
  }

  .topbar-copy {
    display: none;
  }

  .heatmap-mobile-brand {
    display: grid;
    min-height: 44px;
    min-width: 0;
    align-content: center;
    color: var(--text);
    text-decoration: none;
  }

  .heatmap-mobile-brand strong {
    font-size: 18px;
    line-height: 1.1;
    letter-spacing: -0.04em;
  }

  .heatmap-mobile-brand span {
    margin-top: 3px;
    color: var(--muted);
    font-size: 10px;
  }

  .topbar .market-card {
    display: flex;
    align-items: center;
    justify-items: initial;
    width: auto;
    min-width: 0;
    gap: 6px;
  }

  .topbar .market-status {
    width: auto;
    min-width: 0;
    gap: 7px;
    padding: 7px 9px;
    border-radius: 999px;
  }

  .topbar .market-status strong {
    max-width: 84px;
    overflow: hidden;
    font-size: 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar .market-status #updatedAt,
  .topbar .switch-control,
  .topbar .refresh-countdown {
    display: none;
  }

  .topbar .market-actions {
    display: block;
    width: auto;
    padding: 0;
    overflow: visible;
    border: 0;
    background: transparent;
  }

  .topbar .market-actions .ghost-button {
    display: grid;
    width: 44px;
    height: 44px;
    min-width: 44px;
    padding: 0;
    place-items: center;
    border-radius: 11px;
  }

  #refreshBtn svg {
    display: block;
    width: 18px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
  }

  #refreshBtn.is-loading svg {
    animation: heatmap-rotate 900ms linear infinite;
  }

  #refreshBtn .refresh-button-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .summary-grid {
    display: none;
  }

  .control-card {
    position: relative;
    top: auto;
    z-index: 1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    margin: 0 0 8px;
    padding: 8px;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    border-radius: 14px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
  }

  .control-group {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
  }

  .control-group > span {
    display: none;
  }

  .segmented {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    min-height: 50px;
    gap: 3px;
    padding: 3px;
    border-radius: 11px;
  }

  .segmented button {
    flex: 1 0 auto;
    min-width: max-content;
    min-height: 44px;
    padding: 6px 9px;
    border-radius: 8px;
    font-size: 11px;
  }

  .search-box input {
    display: block;
    min-width: 0;
    max-width: 100%;
    height: 50px;
    padding: 0 10px;
    border-radius: 11px;
    font-size: 11px;
  }

  .workspace {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .workspace > *,
  .rank-lists,
  .heatmap {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .heatmap-panel {
    order: 1;
  }

  .sidebar {
    order: 2;
  }

  .panel {
    border-radius: 15px;
  }

  .heatmap-panel .panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 11px;
  }

  .heatmap-panel .panel-head .eyebrow {
    display: none;
  }

  .heatmap-panel .panel-head h2 {
    font-size: 14px;
  }

  .heatmap-panel .legend {
    width: auto;
    flex: 0 0 auto;
    gap: 4px;
    font-size: 9px;
  }

  .heatmap-panel .legend-bar {
    width: 68px;
    height: 7px;
  }

  .heatmap {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: auto;
    grid-auto-flow: row;
    gap: 6px;
    min-height: 0;
    padding: 7px;
  }

  .heatmap > .empty-detail {
    grid-column: 1 / -1;
    grid-row: auto;
    min-height: 180px;
  }

  .tile {
    grid-column: auto !important;
    grid-row: auto !important;
    width: 100%;
    min-height: 102px;
    gap: 6px;
    padding: 10px;
    border-radius: 12px;
  }

  .tile:hover,
  .tile.is-selected {
    transform: none;
  }

  .tile-top {
    display: block;
  }

  .tile-name {
    display: -webkit-box;
    overflow: hidden;
    font-size: 13px;
    line-height: 1.25;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
  }

  .tile-badge {
    display: none !important;
  }

  .tile-change {
    margin-top: 5px;
    font-size: 23px;
    line-height: 1;
  }

  .tile-meta {
    gap: 2px;
    font-size: 9px;
    line-height: 1.3;
  }

  .tile-meta span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tile-meta span:nth-child(n + 3) {
    display: none !important;
  }

  .mobile-heatmap-toggle {
    display: block;
    grid-column: 1 / -1;
    min-height: 44px;
    border: 1px solid rgba(96, 165, 250, 0.28);
    border-radius: 11px;
    color: #bfdbfe;
    background: rgba(59, 130, 246, 0.1);
    font-size: 12px;
    font-weight: 750;
  }

  .rank-lists {
    padding: 10px;
  }

  .detail-panel {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 100;
    order: 3;
    width: 100%;
    max-height: min(84dvh, 760px);
    min-height: 180px;
    padding: 0 0 calc(18px + env(safe-area-inset-bottom));
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 24px 24px 0 0;
    background: #111a27;
    box-shadow: 0 -28px 70px rgba(0, 0, 0, 0.52);
    transform: translateY(104%);
    transition: transform 220ms ease;
  }

  .detail-panel.is-open {
    transform: translateY(0);
  }

  .detail-sheet-close {
    position: sticky;
    top: 10px;
    z-index: 3;
    display: grid;
    width: 44px;
    height: 44px;
    margin: 10px 10px -54px auto;
    padding: 0;
    place-items: center;
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 50%;
    color: #e2e8f0;
    background: rgba(15, 23, 42, 0.92);
    font-size: 22px;
    line-height: 1;
  }

  .detail-panel .detail-hero {
    padding: 20px 54px 18px 16px;
  }

  .detail-panel .detail-hero h2 {
    font-size: 25px;
  }

  .detail-panel .detail-change {
    font-size: 34px;
  }

  .heatmap-sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: block;
    background: rgba(0, 0, 0, 0.58);
    opacity: 0;
    transition: opacity 220ms ease;
  }

  .heatmap-sheet-backdrop.is-visible {
    opacity: 1;
  }

  .heatmap-bottom-nav {
    position: fixed;
    right: 10px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    left: 10px;
    z-index: 80;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    min-height: 68px;
    padding: 6px;
    border: 1px solid rgba(83, 103, 131, 0.38);
    border-radius: 20px;
    background: rgba(13, 20, 31, 0.96);
    box-shadow: 0 18px 46px rgba(0, 0, 0, 0.46);
    backdrop-filter: blur(22px);
  }

  .heatmap-bottom-nav a {
    display: grid;
    min-width: 0;
    place-content: center;
    place-items: center;
    border-radius: 15px;
    color: #77869a;
    font-size: 10px;
    text-decoration: none;
  }

  .heatmap-bottom-nav a.is-active {
    color: #dce8ff;
    background: rgba(76, 141, 255, 0.13);
  }

  .heatmap-bottom-nav svg {
    width: 20px;
    height: 20px;
    margin-bottom: 3px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.7;
  }
}

@media (max-width: 370px) {
  .topbar .market-status strong {
    max-width: 62px;
  }

  .segmented button {
    padding-inline: 7px;
    font-size: 10px;
  }

  .tile {
    min-height: 98px;
    padding: 9px;
  }

  .tile-change {
    font-size: 21px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .detail-panel,
  .heatmap-sheet-backdrop {
    transition-duration: 0.01ms !important;
  }
}

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