.heatmap-page {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
}

.heatmap-page .header {
    padding-block: .7rem;
}

.heatmap-page .main {
    width: 100%;
    max-width: none;
    min-height: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

.heatmap-shell {
    height: 100%;
    min-height: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: .45rem;
    padding: .45rem;
}

.heatmap-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-width: 0;
    min-height: 2.65rem;
    padding: .35rem .7rem;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: color-mix(in srgb, var(--bg-secondary) 92%, transparent);
}

.heatmap-heading {
    display: flex;
    align-items: baseline;
    gap: .55rem;
    min-width: 0;
    white-space: nowrap;
}

.heatmap-heading h1 {
    font-size: 1rem;
    line-height: 1;
}

.heatmap-kicker,
.heatmap-count {
    color: var(--text-muted);
    font-size: .72rem;
}

.heatmap-kicker {
    color: var(--accent-primary);
    font-weight: 700;
}

.heatmap-legend {
    direction: ltr;
    display: flex;
    align-items: center;
    gap: .4rem;
    flex: 0 0 auto;
    color: var(--text-secondary);
    font-size: .7rem;
    font-variant-numeric: tabular-nums;
}

.legend-scale {
    display: flex;
    width: clamp(11rem, 17vw, 15rem);
    height: 1.35rem;
    overflow: hidden;
    border: 1px solid var(--border-color);
    border-radius: 6px;
}

.legend-segment {
    display: grid;
    flex: 1 1 0;
    place-items: center;
    min-width: 0;
    background: var(--heat-color);
    color: var(--heat-text, #fff);
    font-size: .55rem;
    font-weight: 700;
    line-height: 1;
}

.legend-segment + .legend-segment {
    border-left: 1px solid rgba(255, 255, 255, .28);
}

.heatmap-stage {
    position: relative;
    min-height: 0;
    overflow: hidden;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: var(--bg-primary);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--bg-primary) 75%, transparent);
}

.market-heatmap {
    direction: ltr;
    width: 100%;
    height: 100%;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-auto-rows: minmax(0, 1fr);
    overflow: hidden;
}

.heatmap-tile {
    position: relative;
    direction: rtl;
    display: grid;
    place-items: center;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    padding: clamp(.3rem, 1vw, .75rem);
    border: 1px solid var(--bg-primary);
    background: var(--heat-color);
    color: var(--heat-text, #fff);
    text-decoration: none;
    isolation: isolate;
}

.heat-negative-strong {
    --heat-color: #D62D4D;
}

html[lang="en"] .heatmap-tile {
    direction: ltr;
}

.heat-negative-medium {
    --heat-color: #9A2C42;
}

.heat-negative-weak {
    --heat-color: #7B3E50;
}

.heat-neutral {
    --heat-color: #4E4752;
}

.heat-positive-weak {
    --heat-color: #356958;
}

.heat-positive-medium {
    --heat-color: #1B8B5F;
    --heat-text: #0d1117;
}

.heat-positive-strong {
    --heat-color: #02AD65;
    --heat-text: #0d1117;
}

.heatmap-tile:hover {
    z-index: 3;
    filter: brightness(1.12);
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .78);
}

.heatmap-tile:focus-visible,
.heatmap-tile.is-selected {
    z-index: 4;
    outline: 3px solid var(--accent-primary);
    outline-offset: -3px;
}

.heatmap-tile-copy {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .08rem;
    width: 100%;
    min-width: 0;
    text-align: center;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .72);
}

.heatmap-tile.heat-positive-medium .heatmap-tile-copy,
.heatmap-tile.heat-positive-strong .heatmap-tile-copy {
    text-shadow: 0 1px 2px rgba(255, 255, 255, .38);
}

.heatmap-tile-symbol,
.heatmap-tile-change {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.heatmap-tile-symbol,
.heatmap-tile-change {
    font-size: clamp(.65rem, .9vw, .9rem);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.heatmap-details-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.market-heatmap:not(.is-ready) .heatmap-tile:nth-child(n+25) {
    display: none;
}

.market-heatmap.is-ready {
    display: block;
    position: relative;
}

.market-heatmap.is-ready .heatmap-tile {
    position: absolute;
    container-type: size;
    padding: 0;
}

@container (max-width: 72px) {
    .heatmap-tile-change {
        display: none;
    }
}

@container (max-height: 40px) {
    .heatmap-tile-change {
        display: none;
    }
}

@container (max-width: 40px) {
    .heatmap-tile-copy {
        display: none;
    }
}

@container (max-height: 22px) {
    .heatmap-tile-copy {
        display: none;
    }
}

.heatmap-details {
    position: absolute;
    z-index: 20;
    top: 0;
    left: 0;
    width: min(19rem, calc(100% - 1rem));
    max-height: calc(100% - 1rem);
    overflow: auto;
    padding: .75rem;
    border: 2px solid var(--heat-color, var(--border-color));
    border-radius: 12px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: 0 16px 36px rgba(0, 0, 0, .38);
    pointer-events: none;
}

.heatmap-details.is-locked {
    pointer-events: auto;
}

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

.heatmap-details-close {
    position: absolute;
    top: .45rem;
    inset-inline-end: .45rem;
    display: grid;
    place-items: center;
    width: var(--touch-target);
    height: var(--touch-target);
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    font-size: 1.4rem;
    cursor: pointer;
}

.heatmap-details:not(.is-locked) .heatmap-details-close,
.heatmap-details:not(.is-locked) .heatmap-details-link {
    display: none;
}

.heatmap-details-close:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.heatmap-details-close:focus-visible,
.heatmap-details-link:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

.heatmap-details-identity {
    display: grid;
    grid-template-columns: 3rem minmax(0, 1fr);
    align-items: center;
    gap: .75rem;
    padding-inline-end: 2.25rem;
}

.heatmap-details-logo {
    display: grid;
    place-items: center;
    width: 3rem;
    height: 3rem;
    overflow: hidden;
    border-radius: 12px;
    background: #fff;
    color: #334155;
    font-weight: 700;
}

.heatmap-details h2 {
    overflow: hidden;
    font-size: .95rem;
    line-height: 1.5;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.heatmap-details-identity p {
    overflow: hidden;
    color: var(--text-secondary);
    font-size: .78rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.heatmap-details-values {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .5rem;
    margin-block: .6rem;
}

.heatmap-details-values div {
    padding: .55rem .65rem;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-tertiary);
}

.heatmap-details-values dt {
    color: var(--text-muted);
    font-size: .68rem;
}

.heatmap-details-values dd {
    margin: 0;
    font-family: 'Space Grotesk', 'Vazirmatn', sans-serif;
    font-size: .92rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.heatmap-details-values dd.positive {
    color: var(--accent-green);
}

.heatmap-details-values dd.negative {
    color: var(--accent-red);
}

.heatmap-details-link {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: var(--touch-target);
    border-radius: 10px;
    background: var(--accent-primary);
    color: #17100a;
    font-size: .84rem;
    font-weight: 700;
    text-decoration: none;
}

@media (max-width: 767px) {
    .market-heatmap {
        touch-action: pinch-zoom;
    }

    .heatmap-page .header {
        padding-block: .5rem;
    }

    .heatmap-shell {
        gap: .3rem;
        padding: .3rem;
    }

    .heatmap-toolbar {
        min-height: 2.4rem;
        padding: .28rem .55rem;
    }

    .heatmap-kicker,
    .heatmap-count {
        display: none;
    }

    .heatmap-heading h1 {
        font-size: .9rem;
    }

    .legend-scale {
        width: clamp(9rem, 46vw, 11rem);
    }

    .heatmap-stage {
        border-radius: 11px;
    }

    .heatmap-details-values {
        margin-block: .55rem;
    }
}

@media (max-height: 520px) and (max-width: 767px) {
    .heatmap-page .header {
        padding: .3rem var(--layout-pad);
    }

    .heatmap-page .header-content {
        grid-template-columns: minmax(0, auto) minmax(7rem, 1fr) auto auto;
        grid-template-areas:
            "logo search theme menu"
            "stats stats stats stats";
        gap: .3rem .5rem;
    }

    .heatmap-page .logo-text {
        font-size: 1.05rem;
    }

    .heatmap-page .logo-icon {
        width: 45px;
        height: 23px;
    }

    .heatmap-page .site-logo-link {
        gap: .35rem;
    }

    .heatmap-page .search-box,
    .heatmap-page .mobile-menu-toggle {
        min-height: 38px;
        height: 38px;
    }

    .heatmap-page .mobile-menu-toggle {
        width: 38px;
    }

    .heatmap-page .stat-item {
        padding-block: .18rem;
    }

    .heatmap-page .stat-label {
        font-size: .56rem;
    }

    .heatmap-page .stat-value {
        font-size: .72rem;
    }

    .heatmap-toolbar {
        min-height: 2rem;
    }
}

@media (max-height: 390px) and (max-width: 767px) {
    .heatmap-page .stat-label {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .heatmap-tile {
        transition: none;
    }
}
