.card.dashboard-widget.model-heatmap-card {
    --mh-card: #121214;
    --mh-card-2: #18181b;
    --mh-border: rgba(255, 255, 255, 0.1);
    --mh-text: #f4f4f5;
    --mh-muted: #a1a1aa;
    --mh-soft: #71717a;
    --mh-empty: #262626;
    --mh-unknown: #171717;
    --mh-cell: 20px;
    --mh-gap: 3px;
    background: linear-gradient(180deg, #171717 0%, #111111 100%);
    border: 1px solid rgba(255, 255, 255, 0.11);
    border-radius: 18px;
    box-shadow: 0 22px 60px rgba(0, 0, 0, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.04);
    color: var(--mh-text);
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
    overflow: hidden;
    padding: 0;
    min-width: 0;
    max-width: 100%;
}

.card.dashboard-widget.model-heatmap-card:hover {
    background: linear-gradient(180deg, #171717 0%, #111111 100%);
    border-color: rgba(255, 255, 255, 0.14);
}

.mh-shell {
    padding: 1.15rem;
    min-width: 0;
    max-width: 100%;
}

.mh-topbar {
    align-items: flex-start;
    display: flex;
    gap: 1rem;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.mh-eyebrow {
    color: #d4d4d8;
    font-size: 0.68rem;
    letter-spacing: 0.11em;
    margin-bottom: 0.34rem;
    text-transform: uppercase;
}

.mh-title {
    color: #fafafa;
    font-size: 1.12rem;
    font-weight: 750;
    letter-spacing: 0;
    line-height: 1.2;
    margin: 0;
}

.mh-subtitle {
    color: var(--mh-muted);
    font-size: 0.73rem;
    line-height: 1.45;
    margin-top: 0.4rem;
    max-width: 74ch;
}

.mh-status {
    align-items: flex-end;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    min-width: 14rem;
}

.mh-updated {
    color: var(--mh-muted);
    font-size: 0.72rem;
    text-align: right;
}

.mh-alerts {
    align-items: flex-end;
    display: flex;
    flex-direction: column;
    gap: 0.28rem;
}

.mh-alert {
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.38);
    border-radius: 999px;
    color: #fbbf24;
    font-size: 0.68rem;
    max-width: 34rem;
    overflow: hidden;
    padding: 0.25rem 0.55rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mh-controls {
    align-items: center;
    display: flex;
    gap: 0.8rem;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.mh-tabs {
    background: #0b0b0c;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    display: inline-flex;
    padding: 0.22rem;
}

.mh-tab {
    background: transparent;
    border: 0;
    border-radius: 7px;
    color: #a1a1aa;
    cursor: pointer;
    font: inherit;
    font-size: 0.72rem;
    font-weight: 700;
    min-height: 2rem;
    padding: 0.45rem 0.75rem;
}

.mh-tab:hover {
    color: #f4f4f5;
}

.mh-tab[aria-selected="true"] {
    background: #27272a;
    color: #fafafa;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.mh-scale {
    align-items: center;
    color: var(--mh-muted);
    display: flex;
    font-size: 0.68rem;
    gap: 0.35rem;
    white-space: nowrap;
}

.mh-scale-swatch {
    background: #3f3f46;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 4px;
    height: 12px;
    width: 12px;
}

.mh-scale-swatch:nth-of-type(2) { opacity: 0.45; }
.mh-scale-swatch:nth-of-type(3) { opacity: 0.65; }
.mh-scale-swatch:nth-of-type(4) { opacity: 0.85; }
.mh-scale-swatch:nth-of-type(5) { opacity: 1; }

.mh-body {
    display: grid;
    gap: 0.9rem;
    grid-template-columns: minmax(0, 1fr);
    min-width: 0;
}

.mh-heatmap-panel {
    min-width: 0;
    max-width: 100%;
}

.mh-scroll {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0.15rem 0 0.45rem;
    scrollbar-color: #3f3f46 #111111;
}

.mh-chart {
    display: grid;
    gap: 0.42rem;
    grid-template-columns: 2.2rem max-content;
    width: max-content;
}

.mh-day-labels {
    color: var(--mh-soft);
    display: grid;
    font-size: 0.65rem;
    gap: var(--mh-gap);
    grid-template-rows: 1rem repeat(7, var(--mh-cell));
    text-align: right;
}

.mh-day-labels span {
    align-items: center;
    display: flex;
    justify-content: flex-end;
    width: 2.2rem;
    padding-right: 0.2rem;
}

.mh-months {
    display: grid;
    gap: var(--mh-gap);
    grid-template-columns: repeat(26, var(--mh-cell));
    height: 1rem;
    margin-bottom: var(--mh-gap);
}

.mh-month {
    color: var(--mh-soft);
    font-size: 0.65rem;
    line-height: 1rem;
    white-space: nowrap;
}

.mh-grid {
    display: grid;
    gap: var(--mh-gap);
    grid-auto-flow: column;
    grid-template-rows: repeat(7, var(--mh-cell));
}

.mh-cell {
    appearance: none;
    background: var(--mh-empty);
    border: 1px solid rgba(255, 255, 255, 0.055);
    border-radius: 3px;
    cursor: pointer;
    height: var(--mh-cell);
    padding: 0;
    position: relative;
    transition: border-color 0.12s ease, box-shadow 0.12s ease, transform 0.12s ease;
    width: var(--mh-cell);
}

.mh-cell:hover,
.mh-cell:focus-visible,
.mh-cell.is-active {
    border-color: rgba(255, 255, 255, 0.52);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08);
    outline: none;
    transform: scale(1.16);
    z-index: 2;
}

.mh-cell[data-state="unknown"] {
    background:
        repeating-linear-gradient(135deg, #111 0, #111 3px, #1f1f22 3px, #1f1f22 6px);
    cursor: default;
}

.mh-cell[data-state="future"] {
    opacity: 0;
    pointer-events: none;
}

.mh-cell[data-state="zero"] {
    background: #242426;
}

.mh-cell[data-tie="true"]::after {
    background: rgba(255, 255, 255, 0.78);
    border-radius: 999px;
    bottom: 2px;
    content: "";
    height: 3px;
    position: absolute;
    right: 2px;
    width: 3px;
}

.mh-footnote {
    color: var(--mh-soft);
    font-size: 0.67rem;
    line-height: 1.45;
    margin-top: 0.6rem;
}

.mh-side {
    background: rgba(255, 255, 255, 0.035);
    border: 1px solid rgba(255, 255, 255, 0.075);
    border-radius: 12px;
    display: grid;
    gap: 0.75rem;
    min-width: 0;
    padding: 0.75rem;
}

.mh-stats {
    display: grid;
    gap: 0.5rem;
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.mh-stat {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 9px;
    padding: 0.55rem 0.62rem;
}

.mh-stat strong {
    color: #fafafa;
    display: block;
    font-size: 0.95rem;
    line-height: 1.1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mh-stat span {
    color: var(--mh-muted);
    display: block;
    font-size: 0.62rem;
    letter-spacing: 0.08em;
    margin-top: 0.25rem;
    text-transform: uppercase;
}

.mh-detail {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding-top: 0.75rem;
    min-width: 0;
}

.mh-detail-date {
    color: #fafafa;
    font-size: 0.8rem;
    font-weight: 800;
}

.mh-detail-meta {
    color: var(--mh-muted);
    font-size: 0.7rem;
    line-height: 1.45;
    margin-top: 0.3rem;
}

.mh-breakdown {
    display: grid;
    gap: 0.42rem 0.8rem;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-top: 0.7rem;
}

.mh-row {
    display: grid;
    gap: 0.45rem;
    grid-template-columns: 0.7rem minmax(0, 1fr) auto;
}

.mh-dot {
    border-radius: 3px;
    height: 0.7rem;
    margin-top: 0.22rem;
    width: 0.7rem;
}

.mh-row-name {
    color: #e4e4e7;
    font-size: 0.7rem;
    line-height: 1.35;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mh-row-value {
    color: #fafafa;
    font-size: 0.7rem;
    font-weight: 750;
    white-space: nowrap;
}

.mh-row-bar {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    grid-column: 2 / 4;
    height: 4px;
    overflow: hidden;
}

.mh-row-fill {
    background: currentColor;
    border-radius: inherit;
    height: 100%;
}

.mh-legend {
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid rgba(255, 255, 255, 0.065);
    border-radius: 10px;
    min-width: 0;
    padding: 0.62rem;
}

.mh-legend-title {
    color: var(--mh-muted);
    font-size: 0.62rem;
    letter-spacing: 0.08em;
    margin-bottom: 0.45rem;
    text-transform: uppercase;
}

.mh-legend-list {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.4rem 0.55rem;
    max-height: none;
    overflow: visible;
    padding-right: 0;
}

.mh-legend-item {
    align-items: center;
    background: rgba(0, 0, 0, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.055);
    border-radius: 999px;
    display: inline-grid;
    gap: 0.36rem;
    grid-template-columns: 0.65rem minmax(0, auto) auto;
    max-width: min(100%, 18rem);
    padding: 0.25rem 0.45rem;
}

.mh-legend-name {
    color: #e4e4e7;
    font-size: 0.68rem;
    max-width: 13rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mh-legend-total {
    color: var(--mh-muted);
    font-size: 0.66rem;
    white-space: nowrap;
}

.mh-loading,
.mh-error {
    color: var(--mh-muted);
    padding: 1rem;
}

@media (max-width: 1080px) {
    .card.dashboard-widget.model-heatmap-card {
        --mh-cell: 17px;
    }

    .mh-breakdown {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    .dashboard-grid:has(.model-heatmap-card) {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    .card.dashboard-widget.model-heatmap-card {
        --mh-cell: 12px;
        --mh-gap: 3px;
        contain: inline-size;
        inline-size: 100%;
        justify-self: stretch;
        max-inline-size: 100%;
    }

    .mh-shell {
        inline-size: 100%;
        max-inline-size: 100%;
        padding: 0.9rem;
    }

    .mh-topbar,
    .mh-controls {
        align-items: stretch;
        flex-direction: column;
    }

    .mh-status {
        align-items: flex-start;
        min-width: 0;
    }

    .mh-updated {
        text-align: left;
    }

    .mh-tabs {
        overflow-x: auto;
        max-width: 100%;
    }

    .mh-tab {
        flex: 1 0 auto;
    }

    .mh-scale {
        justify-content: flex-start;
    }

    .mh-body,
    .mh-heatmap-panel,
    .mh-side,
    .mh-detail,
    .mh-legend,
    .mh-scroll {
        inline-size: 100%;
        max-inline-size: 100%;
        min-inline-size: 0;
    }

    .mh-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .mh-legend-item {
        max-width: 100%;
    }

    .mh-legend-name {
        max-width: 11rem;
    }

    .mh-breakdown {
        grid-template-columns: 1fr;
    }
}

#model-heatmap { scroll-margin-top: 70px; }
