/* ============================================================
   .uk-heatmap — unified canonical activity heatmap (loaded only on /docs/ui-kit)
   ============================================================
   Replaces the legacy declarations in public/css/docs.css:
     .heatmap-demo + .heatmap-row + .heatmap-cell + .level-0..4 (grid)
     .color-box + .level-0..4                                  (legend list — duplicate of .heatmap-cell)
     .heatmap-legend                                           (legend bar)

   Slots:
     .uk-heatmap                  root, optional card chrome via --card
       .uk-heatmap-row            one row of cells (default row-based layout)
       .uk-heatmap-grid           cell grid container; with --year switches
                                    to GitHub-style 53-column flow
       .uk-heatmap-cell           a single cell (carries data-level="0..4");
                                    same primitive used in grids AND legends
       .uk-heatmap-legend         row with min/max labels and a level ramp

   Levels — monochromatic primary ramp (consumer-overridable via CSS vars):
     --heatmap-level-0  rgba(255, 255, 255, 0.05)
     --heatmap-level-1  rgba(var(--color-primary-rgb), 0.2)
     --heatmap-level-2  rgba(var(--color-primary-rgb), 0.4)
     --heatmap-level-3  rgba(var(--color-primary-rgb), 0.6)
     --heatmap-level-4  var(--color-primary)
   Legacy used --color-success-rgb for 1-3 then --color-primary for 4 — the
   green-to-blue jump made the palette read as two systems mashed together.

   Sizes — driven by --heatmap-cell-size + -gap + -radius:
     --sm        12px / 3px gap / 2px radius
     default     16px / 4px gap / 3px radius   (matches production)
     --lg        20px / 5px gap / 4px radius

   Tooltip:
     data-tooltip="2026-04-15 — 12 checks, 100% uptime" on a cell renders a
     primary-tinted pill above the cell on hover. Pure CSS — no JS required.
   ============================================================ */

.uk-heatmap {
    --heatmap-cell-size: 16px;
    --heatmap-cell-gap: 4px;
    --heatmap-cell-radius: 3px;
    --heatmap-level-0: rgba(255, 255, 255, 0.05);
    --heatmap-level-1: rgba(var(--color-primary-rgb), 0.2);
    --heatmap-level-2: rgba(var(--color-primary-rgb), 0.4);
    --heatmap-level-3: rgba(var(--color-primary-rgb), 0.6);
    --heatmap-level-4: var(--color-primary);

    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
    min-width: 0;
}

/* Optional card chrome — replaces .heatmap-demo wrapper */
.uk-heatmap--card {
    padding: var(--space-xl);
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
}

/* ---------- Row-based layout ---------- */
.uk-heatmap-row {
    display: flex;
    gap: var(--heatmap-cell-gap);
    justify-content: center;
}

/* ---------- Year-grid layout (GitHub-style) ---------- */
.uk-heatmap-grid {
    display: flex;
    flex-direction: column;
    gap: var(--heatmap-cell-gap);
}

.uk-heatmap-grid--year {
    /* GitHub-like density — overrides the default 16px/4px so 53 weeks fit
       comfortably (53*11 + 52*2 = 687px) inside any sensible card. Consumers
       can still re-override per-instance. */
    --heatmap-cell-size: 11px;
    --heatmap-cell-gap: 2px;
    --heatmap-cell-radius: 2px;

    display: grid;
    grid-template-rows: repeat(7, var(--heatmap-cell-size));
    grid-auto-flow: column;
    grid-auto-columns: var(--heatmap-cell-size);
    gap: var(--heatmap-cell-gap);
    /* Padding gives tooltips physical room INSIDE the grid box so the grid's
       overflow context doesn't clip them. Sized to fit a "9 checks"-length
       tooltip including the 1.4× hover scale on the cell (which scales the
       tooltip too — pseudo-elements inherit parent transforms): top 48px
       absorbs the upward extension; side 60px keeps the tooltip on rightmost
       and leftmost cells inside the grid box. */
    padding: 48px 60px 8px;
    /* min-width: 0 + max-width: 100% lets the grid shrink and scroll inside a
       flex parent on narrow viewports without forcing the parent to expand. */
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    justify-content: center;
    scrollbar-width: thin;
    scrollbar-color: rgba(var(--color-primary-rgb), 0.45) transparent;
}

.uk-heatmap-grid--year::-webkit-scrollbar {
    height: 6px;
}

.uk-heatmap-grid--year::-webkit-scrollbar-track {
    background: transparent;
}

.uk-heatmap-grid--year::-webkit-scrollbar-thumb {
    background: rgba(var(--color-primary-rgb), 0.45);
    border-radius: 3px;
}

.uk-heatmap-grid--year::-webkit-scrollbar-thumb:hover {
    background: rgba(var(--color-primary-rgb), 0.65);
}

/* ---------- Cell — single primitive, used everywhere ---------- */
.uk-heatmap-cell {
    width: var(--heatmap-cell-size);
    height: var(--heatmap-cell-size);
    border-radius: var(--heatmap-cell-radius);
    background: var(--heatmap-level-0);
    flex-shrink: 0;
    position: relative;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.uk-heatmap-cell[data-level="0"] { background: var(--heatmap-level-0); }
.uk-heatmap-cell[data-level="1"] { background: var(--heatmap-level-1); }
.uk-heatmap-cell[data-level="2"] { background: var(--heatmap-level-2); }
.uk-heatmap-cell[data-level="3"] { background: var(--heatmap-level-3); }
.uk-heatmap-cell[data-level="4"] { background: var(--heatmap-level-4); }

.uk-heatmap-cell[data-tooltip] {
    cursor: help;
}

.uk-heatmap-cell[data-tooltip]:hover {
    transform: scale(1.4);
    box-shadow: 0 0 0 2px rgba(var(--color-primary-rgb), 0.4);
    z-index: 2;
}

/* ---------- Tooltip — pure CSS, anchored to cell ---------- */
.uk-heatmap-cell[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 10px;
    background: var(--gradient-primary);
    color: #000;
    font-size: var(--font-xs);
    font-weight: 600;
    font-family: var(--font-mono);
    white-space: nowrap;
    border-radius: var(--radius-full);
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--transition-fast);
    z-index: 3;
}

.uk-heatmap-cell[data-tooltip]::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 4px solid var(--color-primary);
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--transition-fast);
    z-index: 3;
}

.uk-heatmap-cell[data-tooltip]:hover::after,
.uk-heatmap-cell[data-tooltip]:hover::before {
    opacity: 1;
}

/* ---------- Legend ---------- */
.uk-heatmap-legend {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--heatmap-cell-gap);
    font-size: var(--font-xs);
    color: var(--color-text-muted);
}

.uk-heatmap-legend-label {
    margin: 0 var(--space-sm);
}

/* Vertical color-explainer list — replaces legacy .color-legend list-item pattern */
.uk-heatmap-explainer {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.uk-heatmap-explainer li {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    font-size: var(--font-md);
    color: var(--color-text-secondary);
}

/* ---------- Sizes ---------- */
.uk-heatmap--sm {
    --heatmap-cell-size: 12px;
    --heatmap-cell-gap: 3px;
    --heatmap-cell-radius: 2px;
}

.uk-heatmap--lg {
    --heatmap-cell-size: 20px;
    --heatmap-cell-gap: 5px;
    --heatmap-cell-radius: 4px;
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    .uk-heatmap-cell {
        transition: none;
    }
    .uk-heatmap-cell[data-tooltip]:hover {
        transform: none;
    }
    .uk-heatmap-cell[data-tooltip]::after,
    .uk-heatmap-cell[data-tooltip]::before {
        transition: none;
    }
}
