/* Market Heatmap — two-level squarified treemap.
   Builds on screener.css for the page shell (aurora, hero, wrap, disclaimer). */

:root {
    --hm-gap: rgba(10, 11, 20, 0.9);
    --hm-page-max: 1280px;
}

/* ---- controls ---- */
.hm-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 18px 26px;
    align-items: flex-end;
    max-width: var(--hm-page-max);
    margin: 0 auto 18px;
    padding: 0 4px;
}
.hm-ctl {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.hm-ctl-lbl {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--faint, #5a5f72);
}
.hm-seg {
    display: flex;
    gap: 4px;
    padding: 3px;
    border-radius: 11px;
    border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
    background: rgba(255, 255, 255, 0.02);
}
.hm-seg button {
    padding: 7px 13px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted, #8a8fa3);
    font: inherit;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.14s ease, color 0.14s ease;
}
.hm-seg button:hover {
    color: var(--ink, #e8eaf2);
}
.hm-seg button.on {
    background: rgba(99, 102, 241, 0.9);
    color: #fff;
}

/* ---- summary tiles ---- */
.hm-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 10px;
    max-width: var(--hm-page-max);
    margin: 0 auto 14px;
}
.hm-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 12px 15px;
    border-radius: 13px;
    border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
    background: rgba(22, 24, 40, 0.6);
}
.hm-stat > span {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--faint, #5a5f72);
}
.hm-stat > b {
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 22px;
    font-weight: 700;
    color: var(--ink, #e8eaf2);
    font-variant-numeric: tabular-nums;
    line-height: 1.15;
}
.hm-stat > small {
    font-size: 11px;
    color: var(--muted, #8a8fa3);
}
.hm-up { color: #19e6a8; }
.hm-down { color: #ec6574; }

/* ---- the map ---- */
.hm-map {
    position: relative;
    width: 100%;
    max-width: var(--hm-page-max);
    margin: 0 auto;
    border-radius: 14px;
    overflow: hidden;
    background: var(--hm-gap);
}

.hm-sector {
    position: absolute;
    overflow: hidden;
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.03);
}

/* The sector strip is painted in the sector's own colour, so the top-level
   read (which sectors are green) survives even when the tiles get tiny. */
.hm-sector-head {
    position: absolute;
    inset: 0 0 auto 0;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0 8px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.01em;
    white-space: nowrap;
    overflow: hidden;
}
.hm-sname {
    overflow: hidden;
    text-overflow: ellipsis;
}
.hm-spct {
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
    font-variant-numeric: tabular-nums;
    flex: 0 0 auto;
    opacity: 0.92;
}

.hm-tile {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    padding: 2px;
    margin: 0;
    border: 0;
    border-radius: 4px;
    font: inherit;
    line-height: 1.1;
    overflow: hidden;
    cursor: pointer;
    /* No transition on transform: 200 tiles re-laying out on a resize would
       animate into a mess. */
    transition: box-shadow 0.12s ease;
}
.hm-tile:hover,
.hm-tile:focus-visible {
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.85);
    outline: none;
    z-index: 3;
}
.hm-sym {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: -0.01em;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.hm-pct {
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 9.5px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    opacity: 0.95;
}
.hm-tile.is-big .hm-sym { font-size: 13px; }
.hm-tile.is-big .hm-pct { font-size: 11.5px; }

/* ---- legend ---- */
.hm-legend {
    display: flex;
    align-items: center;
    gap: 3px;
    max-width: var(--hm-page-max);
    margin: 12px auto 0;
    padding: 0 4px;
    flex-wrap: wrap;
}
.hm-legend i {
    width: 26px;
    height: 11px;
    border-radius: 2px;
    display: block;
}
.hm-leg-cap {
    font-size: 10.5px;
    color: var(--faint, #5a5f72);
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
    margin: 0 6px;
}
.hm-leg-note {
    margin-left: 14px;
    font-size: 11.5px;
    color: var(--muted, #8a8fa3);
}

/* ---- selected-stock strip ---- */
.hm-detail {
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
    max-width: var(--hm-page-max);
    margin: 14px auto 0;
    padding: 13px 16px;
    border-radius: 13px;
    border: 1px solid rgba(99, 102, 241, 0.3);
    background: rgba(99, 102, 241, 0.08);
}
.hm-det-l {
    display: flex;
    flex-direction: column;
}
.hm-det-l b {
    font-size: 16px;
    font-weight: 800;
    color: var(--ink, #e8eaf2);
}
.hm-det-sec {
    font-size: 11px;
    color: var(--muted, #8a8fa3);
}
.hm-det-n {
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 15px;
    font-weight: 700;
    color: var(--ink, #e8eaf2);
    font-variant-numeric: tabular-nums;
}
.hm-det-dim {
    font-size: 12.5px;
    font-weight: 500;
    color: var(--muted, #8a8fa3);
}
.hm-det-go {
    margin-left: auto;
    padding: 9px 15px;
    border-radius: 10px;
    background: rgba(99, 102, 241, 0.9);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}
.hm-det-go:hover { background: #6366f1; }

/* These carry a display rule, so the bare `hidden` attribute loses to it —
   without these guards an unselected page shows an empty blue strip. */
.hm-detail[hidden],
.hm-legend[hidden],
.hm-stats[hidden] {
    display: none;
}

/* ---- hover tooltip ---- */
.hm-tip {
    position: fixed;
    z-index: 400;
    min-width: 200px;
    padding: 11px 13px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(14, 16, 30, 0.97);
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.6);
    pointer-events: none;
    font-size: 12px;
}
.hm-tip[hidden] { display: none; }
.hm-tip-h {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: baseline;
    margin-bottom: 7px;
    padding-bottom: 7px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.hm-tip-h b {
    font-size: 14px;
    font-weight: 800;
    color: #e8eaf2;
}
.hm-tip-h span {
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
    font-weight: 700;
}
.hm-tip-r {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 2px 0;
    color: #8a8fa3;
}
.hm-tip-r b {
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
    color: #e8eaf2;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.hm-tip-s {
    margin-top: 7px;
    padding-top: 7px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 11px;
    color: #5a5f72;
}

/* ---- table view (also the accessible view of the same data) ---- */
.hm-tablewrap {
    max-width: var(--hm-page-max);
    margin: 0 auto;
    overflow-x: auto;
    border-radius: 14px;
    border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
}
.hm-tablewrap table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.hm-tablewrap th {
    position: sticky;
    top: 0;
    text-align: left;
    padding: 11px 14px;
    background: #12142400;
    backdrop-filter: blur(8px);
    background-color: rgba(18, 20, 36, 0.96);
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--faint, #5a5f72);
}
.hm-tablewrap td {
    padding: 10px 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--ink, #e8eaf2);
}
.hm-tablewrap td:nth-child(n + 3) {
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
    font-variant-numeric: tabular-nums;
}
.hm-tablewrap a {
    color: #8b5cf6;
    font-weight: 600;
    text-decoration: none;
}
.hm-tablewrap a:hover { text-decoration: underline; }

/* ---- states ---- */
.hm-msg {
    max-width: var(--hm-page-max);
    margin: 40px auto;
    text-align: center;
    color: var(--muted, #8a8fa3);
    font-size: 14px;
    line-height: 1.7;
}
.hm-msg[hidden] { display: none; }
.hm-retry {
    margin-top: 14px;
    padding: 9px 16px;
    border-radius: 10px;
    border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
    background: rgba(255, 255, 255, 0.04);
    color: var(--ink, #e8eaf2);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

@media (min-width: 1600px) {
    :root {
        --hm-page-max: min(1440px, 92vw);
    }
}

@media (max-width: 620px) {
    .hm-controls { gap: 12px 16px; }
    .hm-seg button { padding: 7px 10px; font-size: 12px; }
    .hm-stats { grid-template-columns: repeat(2, 1fr); }
    .hm-leg-note { margin-left: 0; width: 100%; }
    .hm-det-go { margin-left: 0; width: 100%; text-align: center; }
}
