/*
 * NepseIQ — Market Map
 * ───────────────────────────────────────────────────────────────────────
 * Geometry is computed in JS and written as absolute left/top/width/height,
 * so nothing here positions a tile. These rules only decide how a tile looks
 * once it has been placed, and the page chrome around the map.
 *
 * Tokens come from style.css. No gradients, no shadows, no rounded slabs —
 * the colour of the tiles is the entire visual language of this page, and
 * anything else competing with it makes the market harder to read.
 */

.hm { display: flex; flex-direction: column; gap: 10px; padding-bottom: 28px; }

/* ── header ───────────────────────────────────────────────────────────── */
.hm-head {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    padding: 4px 0 10px;
    border-bottom: 1px solid var(--border-color);
}
.hm-head h1 {
    margin: 0; flex: 1;
    color: var(--text-primary);
}
.hm-modes { display: inline-flex; border: 1px solid var(--border-color); border-radius: 6px; overflow: hidden; }
.hm-mode {
    height: 30px; padding: 0 14px;
    background: transparent; border: 0;
    color: var(--text-secondary);
    font-family: var(--font-main); font-size: 12px; font-weight: 600;
    cursor: pointer;
    transition: background var(--duration-fast, .15s), color var(--duration-fast, .15s);
}
.hm-mode + .hm-mode { border-left: 1px solid var(--border-color); }
.hm-mode:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.hm-mode.active { background: var(--bg-elevated); color: var(--text-primary); }
.hm-mode:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: -2px; }

.hm-btn {
    height: 30px; padding: 0 12px;
    background: transparent;
    border: 1px solid var(--border-color); border-radius: 6px;
    color: var(--text-secondary);
    font-family: var(--font-main); font-size: 12px; font-weight: 600;
    cursor: pointer;
}
.hm-btn:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.hm-btn:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 1px; }

/* ── controls row ─────────────────────────────────────────────────────── */
.hm-bar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; justify-content: space-between; }
.hm-sizebar { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.hm-sizebar[hidden] { display: none; }
.hm-sizebar-label {
    font-size: 10px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase;
    color: var(--text-dim); margin-right: 4px;
}
.hm-size {
    height: 26px; padding: 0 10px;
    background: transparent;
    border: 1px solid var(--border-subtle); border-radius: 5px;
    color: var(--text-muted);
    font-family: var(--font-main); font-size: 11.5px; font-weight: 600;
    cursor: pointer;
    transition: color var(--duration-fast, .15s), border-color var(--duration-fast, .15s);
}
.hm-size:hover { color: var(--text-primary); border-color: var(--border-hover); }
.hm-size.active { color: var(--text-primary); border-color: var(--accent-blue); background: var(--bg-elevated); }
.hm-size:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 1px; }

.hm-legend {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    font-family: var(--font-mono); font-size: 10.5px; color: var(--text-muted);
}
.hm-legend-bar {
    width: 132px; height: 6px; border-radius: 3px;
    background: linear-gradient(90deg,
        rgba(239,68,68,.84), rgba(239,68,68,.30), rgb(38,45,60),
        rgba(16,185,129,.30), rgba(16,185,129,.84));
}

/* ── the map ──────────────────────────────────────────────────────────── */
.hm-canvas {
    position: relative;
    width: 100%;
    min-height: 360px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-card);
    overflow: hidden;
}
.hm-canvas:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 2px; }

/* A sector's own footprint, drawn under its stocks so the grouping reads
   even where the tiles inside it are all the same colour. */
.hm-group {
    position: absolute;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: 3px;
    pointer-events: none;
}

.hm-ghead {
    position: absolute;
    height: 17px;
    display: flex; align-items: center; gap: 6px;
    padding: 0 4px;
    background: none; border: 0;
    overflow: hidden; white-space: nowrap;
    font-family: var(--font-main);
    text-align: left;
}
.hm-ghead-name {
    flex: 1; min-width: 0;
    overflow: hidden; text-overflow: ellipsis;
    font-size: 10px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase;
    color: var(--text-secondary);
}
.hm-ghead-pct { font-family: var(--font-mono); font-size: 10px; font-weight: 700; }
.hm-ghead-pct.up { color: var(--market-up); }
.hm-ghead-pct.down { color: var(--market-down); }
.hm-ghead.is-link { cursor: pointer; }
.hm-ghead.is-link:hover .hm-ghead-name { color: var(--text-primary); text-decoration: underline; }

.hm-tile {
    position: absolute;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 1px;
    padding: 1px;
    border: 1px solid rgba(0, 0, 0, .35);
    border-radius: 2px;
    overflow: hidden;
    cursor: pointer;
    font-family: var(--font-mono);
    line-height: 1.1;
    /* Colour is the data. A transition makes a refresh read as a change rather
       than a redraw, and it is the only animation on this page. */
    transition: filter 120ms linear;
}
.hm-tile:hover, .hm-tile.kb { filter: brightness(1.28); z-index: 3; }
.hm-tile.kb { outline: 2px solid #fff; outline-offset: -2px; }
.hm-tile-sector { border-radius: 4px; }
.hm-tile-sector:not(.is-link) { cursor: default; }

/* Ink is chosen per tile from that tile's luminance, so a pale tile gets dark
   type and a saturated one gets light. The shadow has to follow it — a dark
   shadow under dark type is just a smudge. */
.hm-tile.ink-light { color: #f4f6fb; --hm-shadow: 0 1px 2px rgba(0, 0, 0, .55); }
.hm-tile.ink-dark  { color: #0b1220; --hm-shadow: 0 1px 2px rgba(255, 255, 255, .45); }

.hm-t-name {
    max-width: 100%;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 11px; font-weight: 700;
    text-shadow: var(--hm-shadow);
}
.hm-t-pct { font-size: 10px; font-weight: 600; opacity: .92; text-shadow: var(--hm-shadow); }
.hm-t-sub {
    max-width: 100%;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 9.5px; opacity: .8;
    font-family: var(--font-mono);
    text-shadow: var(--hm-shadow);
}
.hm-tile-sector .hm-t-name { font-family: var(--font-main); font-size: 12px; }
.hm-tile-sector .hm-t-pct { font-size: 13px; font-weight: 700; }

.hm-state {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
    font-family: var(--font-main); text-align: center; padding: 20px;
}
.hm-state b { font-size: 13px; color: var(--text-primary); }
.hm-state span { font-size: 12px; color: var(--text-muted); }

.hm-note {
    margin: 0;
    font-family: var(--font-mono); font-size: 11px; color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.hm-note[hidden] { display: none; }

/* ── tooltip ──────────────────────────────────────────────────────────── */
.hm-tip {
    position: fixed; z-index: 9999;
    display: none;
    min-width: 190px; max-width: 260px;
    padding: 9px 11px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-family: var(--font-main);
    pointer-events: none;
}
.hm-tip-head {
    display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
    padding-bottom: 5px; margin-bottom: 6px;
    border-bottom: 1px solid var(--border-subtle);
}
.hm-tip-head b { font-family: var(--font-mono); font-size: 13px; color: var(--text-primary); }
.hm-tip-head span { font-family: var(--font-mono); font-size: 12px; font-weight: 700; }
.hm-tip-head.up span { color: var(--market-up); }
.hm-tip-head.down span { color: var(--market-down); }
.hm-tip-name { font-size: 11px; color: var(--text-muted); margin-bottom: 6px; line-height: 1.35; }
.hm-tip-row {
    display: flex; justify-content: space-between; gap: 12px;
    font-size: 11.5px; padding: 1.5px 0;
}
.hm-tip-row span { color: var(--text-muted); }
.hm-tip-row b {
    color: var(--text-primary); font-weight: 600;
    font-family: var(--font-mono); font-variant-numeric: tabular-nums;
}
.hm-tip-foot {
    margin-top: 6px; padding-top: 5px;
    border-top: 1px solid var(--border-subtle);
    font-size: 10.5px; color: var(--text-dim);
}

/* ── responsive ───────────────────────────────────────────────────────── */
@media (max-width: 720px) {
    .hm-head { gap: 8px; }
    .hm-head h1 { flex-basis: 100%; }
    .hm-modes { flex: 1; }
    .hm-mode { flex: 1; padding: 0 8px; }
    .hm-bar { gap: 8px; }
    .hm-legend { width: 100%; }
    /* The canvas sets its own height on a phone — one band per sector, stacked
       — so it must not be pinned to a viewport-shaped box. The page scrolls. */
    .hm-canvas { min-height: 420px; }
    .hm-ghead { height: 19px; }
    .hm-ghead-name { font-size: 10.5px; }
    .hm-ghead-pct { font-size: 10.5px; }
    .hm-t-name { font-size: 11.5px; }
    .hm-t-pct { font-size: 10.5px; }
}

@media (prefers-reduced-motion: reduce) {
    .hm-tile, .hm-mode, .hm-size { transition: none; }
}
