/* ==========================================================================
   KNOWLEDGE HEATMAP — V7 ROSE ATELIER ANALYTICAL MATRIX
   Clean light pastel surfaces, WCAG AA+ contrast scales, keyboard-accessible.
   ========================================================================== */
.kh-page {
    --kh-ink: var(--ip-text, #102F43);
    --kh-muted: var(--ip-muted, #34596E);
    --kh-line: var(--ip-border, #BCE4F0);
    --kh-purple: var(--ip-link, #0E6E7B);
    --kh-panel: var(--ip-panel, #FFFFFF);
    display: grid;
    gap: 1.12rem;
    color: var(--kh-ink);
}
.kh-page [hidden] { display: none !important; }
.kh-page :focus-visible { outline: 3px solid var(--ip-link, #0E6E7B); outline-offset: 3px; }
.kh-hero {
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: .88rem;
    padding-block: .28rem .63rem;
}
.kh-hero-icon { display: grid; place-items: center; width: 3.05rem; height: 3.05rem; border-radius: 16px; background: var(--ip-lavender, #E7F8FF); color: var(--ip-link, #0E6E7B); }
.kh-hero-icon .ip-icon { width: 1.4rem; height: 1.4rem; }
.kh-page .kh-hero h1 { color: var(--kh-ink); margin: 0; font-size: clamp(1.48rem, 3.1vw, 2.35rem); letter-spacing: -.047em; line-height: 1.24; }
.kh-page .kh-hero p { color: var(--kh-muted); margin: .37rem 0 0; max-width: 44rem; line-height: 1.58; font-size: .95rem; }
.kh-map-link { white-space: nowrap; }
.kh-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .73rem; margin: 0; }
.kh-metric {
    display: flex; flex-direction: column; justify-content: space-between; min-height: 7.25rem; min-width: 0;
    padding: .85rem 1rem .9rem; color: var(--ip-link, #0E6E7B); border: 1px solid var(--ip-border, #BCE4F0);
    background: var(--ip-hover, #E7F8FF); border-radius: 18px; box-shadow: 0 5px 14px rgba(7, 28, 44, 0.08);
}
.kh-metric-verified { color: var(--ip-success-text, #187457); background: var(--ip-mint, #E2F6EE); border-color: #C7EBD9; }
.kh-metric-pending { color: var(--ip-warning-text, #8B5414); background: var(--ip-cream, #FFF4D9); border-color: #F2DAA6; }
.kh-metric-rate { color: var(--ip-sky-text, #245D8F); background: var(--ip-sky, #E7F3FC); border-color: #CDE2F5; }
.kh-metric dt { display: flex; align-items: center; gap: .43rem; font-weight: 600; font-size: .87rem; line-height: 1.4; }
.kh-metric dt svg { flex: 0 0 auto; width: 1.1rem; height: 1.1rem; }
.kh-metric dd { margin: .48rem 0 0; font-size: clamp(1.7rem, 3vw, 2.35rem); font-weight: 700; line-height: 1; letter-spacing: -.055em; }
.kh-metric dd > span { margin-left: .08em; font-size: .6em; }

.kh-workspace {
    --kh-0: #F2FBFD; --kh-1: #E7F8FF; --kh-2: #A5F3FC;
    --kh-3: #48DCE9; --kh-4: #14787B; --kh-5: #0B2940;
    min-width: 0; background: var(--kh-panel); border: 1px solid var(--kh-line); border-radius: 22px;
    box-shadow: 0 12px 30px rgba(7, 28, 44, 0.10); overflow: hidden;
}
.kh-workspace[data-metric="verified"] {
    --kh-0: #F4FBF8; --kh-1: #E2F6EE; --kh-2: #C2EAD8;
    --kh-3: #8AD4B4; --kh-4: #24785E; --kh-5: #165944;
}
.kh-workspace[data-metric="rate"] {
    --kh-0: #F5FAFE; --kh-1: #E7F3FC; --kh-2: #C9E2F8;
    --kh-3: #99C4ED; --kh-4: #2F64A3; --kh-5: #1F477A;
}
.kh-workspace-heading {
    display: flex; justify-content: space-between; align-items: flex-start; gap: .7rem 1.25rem;
    background: linear-gradient(110deg, #FFF0F3, #FFFFFF); border-bottom: 1px solid var(--kh-line); padding: 1.2rem 1.34rem;
}
.kh-page .kh-workspace-heading h2 { margin: 0; color: var(--kh-ink); font-size: clamp(1.24rem, 2.3vw, 1.65rem); letter-spacing: -.035em; line-height: 1.28; }
.kh-page .kh-workspace-heading p { margin: .37rem 0 0; color: var(--kh-muted); line-height: 1.5; font-size: .9rem; }
.kh-export { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .37rem; flex: 0 0 auto; }
.kh-export .ip-button { min-height: 2.5rem; padding-inline: .65rem; font-size: .81rem; white-space: nowrap; }
.kh-filters { display: grid; gap: .86rem; padding: 1.16rem 1.32rem 1rem; border-bottom: 1px solid var(--kh-line); }
.kh-metric-picker { margin: 0; padding: 0; border: 0; min-width: 0; }
.kh-metric-picker legend { padding: 0; margin-bottom: .46rem; color: var(--kh-muted); font-weight: 600; font-size: .87rem; }
.kh-segmented { display: inline-flex; flex-wrap: wrap; max-width: 100%; gap: .28rem; padding: .24rem; border-radius: 13px; background: var(--ip-bg, #FFF9FA); border: 1px solid var(--kh-line); }
.kh-segmented label { position: relative; cursor: pointer; }
.kh-segmented input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.kh-segmented span {
    display: flex; align-items: center; min-height: 2.45rem; padding: .38rem .68rem; border: 1px solid transparent;
    border-radius: 10px; color: var(--kh-muted); font-size: .86rem; font-weight: 600;
}
.kh-segmented input:checked + span { background: var(--ip-fill, #148C98); border-color: var(--ip-fill, #148C98); color: #FFFFFF; box-shadow: 0 3px 10px rgba(20, 140, 152, 0.24); }
.kh-segmented input:focus-visible + span { outline: 3px solid var(--ip-link, #0E6E7B); outline-offset: 2px; }
.kh-segmented span:hover { background: var(--ip-lavender, #D8F4FC); color: var(--ip-link, #0E6E7B); }
.kh-filter-fields { display: grid; grid-template-columns: 1.25fr .7fr .94fr auto; gap: .63rem; align-items: end; }
.kh-filter-fields > label { display: grid; gap: .35rem; min-width: 0; color: var(--kh-muted); font-size: .86rem; font-weight: 600; }
.ip-main .kh-filter-fields select { width: 100%; min-width: 0; min-height: 2.75rem; margin: 0; font-size: .9rem; border-color: var(--kh-line); padding-right: 2rem; background-color: var(--ip-control, #FFFDFD); }
.kh-filter-actions { display: flex; flex-wrap: wrap; gap: .33rem; }
.kh-filter-actions .ip-button { min-height: 2.75rem; white-space: nowrap; padding-inline: .67rem; }
.kh-page .kh-filter-note, .kh-page .kh-source-note { margin: 0; color: var(--kh-muted); font-size: .82rem; line-height: 1.54; }
.kh-page .kh-source-note { margin: .4rem 1.32rem 1.15rem; }
.kh-chart { padding: .45rem 1.14rem 0; }
.kh-page .kh-scroll-hint { display: none; margin: .45rem .17rem 0; color: var(--kh-muted); font-size: .82rem; }
.kh-scroll { overflow-x: auto; padding: .13rem .18rem .44rem; }
.kh-page .kh-table { width: 100%; min-width: 40rem; border: 0; border-collapse: separate; border-spacing: .46rem .44rem; table-layout: fixed; margin: 0; }
.kh-page .kh-table-single { min-width: 23rem; }
.kh-page .kh-table :is(th,td) { background: transparent; border: 0; padding: 0; text-align: center; vertical-align: middle; }
.kh-page .kh-table thead th { font-size: .85rem; color: var(--kh-muted); font-weight: 700; padding: .26rem .14rem .1rem; }
.kh-page .kh-table thead th:first-child { width: 31%; text-align: left; padding-left: .25rem; }
.kh-page .kh-table thead th:last-child { width: 16%; }
.kh-page .kh-table-single thead th:first-child { width: 45%; }
.kh-page .kh-table-single thead th:last-child { width: 23%; }
.kh-theme { display: flex; align-items: center; gap: .62rem; text-align: left; font-weight: 600; font-size: .9rem; line-height: 1.35; }
.kh-theme b { flex: 0 0 2rem; height: 2rem; display: grid; place-items: center; border-radius: 9px; background: var(--ip-lavender, #D8F4FC); color: var(--ip-link, #0E6E7B); }
.kh-theme span { overflow-wrap: anywhere; }
.kh-cell, .kh-row-total {
    min-height: 4.25rem; display: grid; place-content: center; justify-items: center; gap: .22rem;
    padding: .48rem .2rem; background: var(--kh-0); border: 1px solid rgba(87, 52, 73, 0.12); border-radius: 13px; text-align: center;
}
.kh-page a.kh-cell { color: var(--kh-ink); text-decoration: none; transition: transform .16s ease, box-shadow .16s ease; }
.kh-page a.kh-cell:hover, .kh-page a.kh-cell:focus-visible { transform: translateY(-2px); box-shadow: 0 5px 14px rgba(87, 52, 73, 0.15); }
.kh-cell.kh-level-1 { background: var(--kh-1); }
.kh-cell.kh-level-2 { background: var(--kh-2); }
.kh-cell.kh-level-3 { background: var(--kh-3); }
.kh-page .kh-cell.kh-level-4 { background: var(--kh-4); color: #FFFFFF; }
.kh-page .kh-cell.kh-level-5 { background: var(--kh-5); color: #FFFFFF; }
.kh-cell.kh-cell-empty { background: repeating-linear-gradient(135deg, #FFFDFD 0 6px, #FFF0F3 6px 12px); }
.kh-cell.kh-cell-filtered { border-style: dashed; }
.kh-cell strong, .kh-row-total strong { font-size: clamp(1.28rem, 2.65vw, 1.7rem); line-height: 1.12; font-weight: 700; letter-spacing: -.05em; }
.kh-cell strong i { font: inherit; font-size: .65em; margin-left: .05em; }
.kh-cell small, .kh-row-total small { font-size: .74rem; line-height: 1.3; font-weight: 600; }
.kh-row-total { color: var(--kh-ink); background: var(--ip-hover, #FFF0F3); border-color: var(--kh-line); }
.kh-row-total strong { font-size: 1.2rem; }
.kh-legend { display: flex; flex-wrap: wrap; align-items: baseline; gap: .61rem 1rem; padding: .75rem .45rem .2rem; color: var(--kh-muted); font-size: .82rem; }
.kh-legend > strong { color: var(--kh-ink); font-weight: 600; }
.kh-legend-scale { display: grid; flex: 0 1 13rem; min-width: 8rem; gap: .17rem; }
.kh-gradient { height: .58rem; border-radius: 10px; border: 1px solid rgba(87, 52, 73, 0.14); background: linear-gradient(90deg, var(--kh-0), var(--kh-1), var(--kh-2), var(--kh-3), var(--kh-4), var(--kh-5)); }
.kh-legend-ticks { display: flex; justify-content: space-between; gap: .3rem; font-variant-numeric: tabular-nums; }
.kh-page .ip-explorer-empty { margin: 1rem 1.3rem; }

.kh-tooltip {
    position: fixed; z-index: 100; width: min(17rem, calc(100vw - 1rem)); padding: .74rem .87rem;
    pointer-events: none; border-radius: 14px; background: var(--ip-panel, #FFFFFF); color: var(--kh-ink);
    border: 1px solid var(--ip-control-border, #E4A0B7); box-shadow: 0 12px 28px rgba(87, 52, 73, 0.16);
    font-size: .88rem; line-height: 1.5;
}
.kh-tooltip > strong { display: block; font-size: .97rem; }
.kh-tooltip > span { color: var(--kh-muted); font-size: .81rem; }
.kh-tooltip dl { border-top: 1px solid var(--kh-line); margin: .43rem 0 0; display: grid; gap: .3rem; padding-top: .42rem; }
.kh-tooltip dl div { display: flex; justify-content: space-between; gap: .5rem; }
.kh-tooltip dd { margin: 0; font-weight: 700; }
.kh-detail {
    position: fixed; inset: 0 0 0 auto; width: min(100vw, 31.25rem); max-width: 100%; height: 100%;
    max-height: 100%; margin: 0; border: 0; padding: 0; border-radius: 20px 0 0 20px; background: #FFFFFF;
    color: var(--kh-ink); box-shadow: -15px 0 45px rgba(87, 52, 73, 0.18);
}
.kh-detail::backdrop { background: rgba(70, 40, 58, 0.45); }
.kh-detail-body { height: 100%; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: .75rem; padding: 1.2rem; }
.kh-detail-header { display: flex; justify-content: space-between; align-items: flex-start; gap: .55rem; }
.kh-page .kh-detail-header h2 { color: var(--kh-ink); margin: .22rem 0 0; font-size: 1.35rem; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.kh-page .kh-detail-header p { color: var(--ip-link, #0E6E7B); margin: 0; font-weight: 600; font-size: .84rem; }
.kh-detail-header form { margin: 0; }
.kh-close.ip-button { padding: .52rem; min-width: 2.6rem; min-height: 2.6rem; }
.kh-detail-summary { margin: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .3rem; }
.kh-detail-summary div { border: 1px solid var(--kh-line); background: var(--ip-hover, #EAF7FC); border-radius: 10px; padding: .49rem .37rem; }
.kh-detail-summary dt { color: var(--kh-muted); font-size: .76rem; line-height: 1.4; }
.kh-detail-summary dd { margin: .22rem 0 0; color: var(--ip-link, #0E6E7B); font-weight: 700; font-size: 1.03rem; line-height: 1.15; }
.kh-detail-actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.kh-page .kh-detail-status { color: var(--kh-muted); margin: 0; min-height: 1.3rem; font-size: .88rem; }
.kh-detail-results { display: grid; gap: .39rem; margin: 0; padding: 0; list-style: none; }
.kh-detail-results li { min-width: 0; padding: .58rem .68rem; border: 1px solid var(--kh-line); border-radius: 12px; background: var(--ip-bg, #F4FBFD); }
.kh-result-heading { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .26rem .55rem; align-items: center; }
.kh-page .kh-detail-results a { color: var(--ip-link, #0E6E7B); font-size: .88rem; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; overflow-wrap: anywhere; }
.kh-page .kh-detail-results p { margin: .3rem 0 0; color: var(--kh-ink); font-size: .88rem; line-height: 1.5; overflow-wrap: anywhere; }
.kh-result-status { border-radius: 7px; background: var(--ip-cream, #FFF4D9); color: var(--ip-warning-text, #8B5414); padding: .16rem .42rem; font-size: .74rem; font-weight: 600; }
.kh-result-status.is-verified { background: var(--ip-mint, #E2F6EE); color: var(--ip-success-text, #187457); }
.kh-pagination { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .3rem; padding-block: .36rem; color: var(--kh-muted); font-size: .85rem; }

@media (max-width: 72rem) {
    .kh-filter-fields { grid-template-columns: 1.1fr .75fr 1fr; }
    .kh-filter-actions { grid-column: 1 / -1; }
}
@media (max-width: 51rem) {
    .kh-hero { grid-template-columns: auto minmax(0, 1fr); gap: .63rem; }
    .kh-map-link { width: max-content; grid-column: 2; }
    .kh-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .48rem; }
    .kh-metric { min-height: 6.15rem; padding: .64rem .72rem; border-radius: 15px; }
    .kh-workspace-heading { flex-wrap: wrap; padding: .9rem .83rem; }
    .kh-export { justify-content: flex-start; }
    .kh-filters { padding: .86rem .84rem; }
    .kh-chart { padding-inline: .5rem; }
    .kh-page .kh-source-note { margin-inline: .86rem; }
    .kh-page .kh-scroll-hint { display: block; }
    .kh-page .kh-table { min-width: 36.5rem; }
    .kh-page .kh-table-single { min-width: 21rem; }
}
@media (max-width: 34rem) {
    .kh-hero-icon { width: 2.45rem; height: 2.45rem; border-radius: 13px; }
    .kh-hero-icon .ip-icon { width: 1.1rem; height: 1.1rem; }
    .kh-map-link { grid-column: 1 / -1; }
    .kh-filter-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kh-filter-fields > label:first-child { grid-column: 1 / -1; }
    .kh-segmented span { padding-inline: .4rem; font-size: .81rem; }
    .kh-detail { inset: auto 0 0; width: 100%; height: min(86dvh, 46rem); border-radius: 20px 20px 0 0; }
    .kh-detail-body { padding: .86rem; }
    .kh-detail-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
    .kh-page a.kh-cell { transition: none; }
    .kh-page a.kh-cell:hover, .kh-page a.kh-cell:focus-visible { transform: none; }
}
