#analysis-matrix-content {
    position: relative;
}

.analysis-matrix-meta-header {
    position: absolute;
    z-index: 85;
    top: var(--analysis-matrix-header-height, 4rem);
    left: 50%;
    display: grid;
    box-sizing: border-box;
    width: min(64rem, calc(100% - 2rem));
    min-height: 3.15rem;
    grid-template-areas:
        "title views actions"
        "context context context"
        "stats stats stats";
    grid-template-columns: auto auto auto;
    align-items: center;
    justify-content: center;
    gap: 0.28rem 0.8rem;
    padding: 0.45rem 0.75rem;
    transform: translateX(-50%);
    border: 1px solid rgba(123, 145, 173, 0.4);
    border-top: 0;
    border-radius: 0 0 0.85rem 0.85rem;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 0.35rem 0.9rem rgba(1, 10, 45, 0.12);
    color: #173864;
    backdrop-filter: blur(10px);
    pointer-events: none;
}

.analysis-matrix-meta-header.analysis-matrix-meta-header--constraints-open {
    z-index: 100500;
    overflow: visible;
}

.analysis-matrix-meta-header__constraints {
    position: relative;
    pointer-events: auto;
}

/* The constraints workflow is retired for now.  Keep this rule alongside the
 * inline guard in analysisMetaHeader.js so stale DOM or CSS cannot expose it. */
.analysis-matrix-meta-header__constraints {
    display: none !important;
}

.analysis-matrix-meta-header__views {
    grid-area: views;
    display: flex;
    gap: .2rem;
    padding: .2rem;
    border-radius: .55rem;
    background: #edf2f7;
    pointer-events: auto;
}

.analysis-matrix-meta-header__views[hidden] { display: none; }

.analysis-matrix-meta-header__views > button {
    min-height: 2rem;
    padding: .35rem .55rem;
    border: 0;
    border-radius: .4rem;
    background: transparent;
    color: #36536f;
    font: 750 .7rem/1 "Ubuntu", sans-serif;
    cursor: pointer;
}

.analysis-matrix-meta-header__views > button[aria-pressed="true"] {
    background: #c01466;
    color: #fff;
    cursor: default;
}

.analysis-matrix-meta-header__views > button:not(:disabled):hover,
.analysis-matrix-meta-header__views > button:focus-visible {
    background: #dce9f2;
    outline: 2px solid #2f6f9f;
}

.analysis-matrix-meta-header__actions {
    grid-area: actions;
    pointer-events: auto;
}

.analysis-matrix-meta-header__actions > button {
    display: inline-flex;
    min-height: 2rem;
    align-items: center;
    gap: .38rem;
    padding: .35rem .62rem;
    border: 1px solid rgba(23, 56, 100, .24);
    border-radius: .5rem;
    background: #f5f9fc;
    color: #173864;
    font: 750 .7rem/1 "Ubuntu", sans-serif;
    cursor: pointer;
}

.analysis-matrix-meta-header__actions > button[hidden] {
    display: none;
}

.analysis-matrix-meta-header__actions > button:hover,
.analysis-matrix-meta-header__actions > button:focus-visible {
    border-color: #2f6f9f;
    background: #eaf4fa;
    outline: none;
}

.analysis-matrix-meta-header__material-focus {
    display: grid;
    gap: .2rem;
    margin-top: .3rem;
    color: #36536f;
    font: 650 .65rem/1.2 "Ubuntu", sans-serif;
}

.analysis-matrix-meta-header__material-focus[hidden] {
    display: none;
}

.analysis-matrix-meta-header__material-focus select {
    width: 100%;
    min-height: 2rem;
    padding: .28rem .45rem;
    border: 1px solid rgba(23, 56, 100, .24);
    border-radius: .5rem;
    background: #f5f9fc;
    color: #173864;
    font: 650 .7rem/1.2 "Ubuntu", sans-serif;
    cursor: pointer;
}

.analysis-matrix-meta-header__material-focus select:focus-visible {
    outline: 2px solid #2f6f9f;
}

.analysis-matrix-meta-header__constraints > button {
    display: inline-flex;
    min-height: 2rem;
    align-items: center;
    gap: .38rem;
    padding: .35rem .62rem;
    border: 1px solid rgba(192, 20, 102, .28);
    border-radius: .5rem;
    background: #fff7fb;
    color: #b3125e;
    font: 750 .7rem/1 "Ubuntu", sans-serif;
    cursor: pointer;
}

.analysis-matrix-meta-header__constraints > button:hover,
.analysis-matrix-meta-header__constraints > button[aria-expanded="true"] {
    border-color: #c01466;
    background: #ffedf6;
}

.analysis-matrix-meta-header__constraints-popover {
    position: absolute;
    z-index: 100501;
    top: calc(100% + .55rem);
    right: 0;
    width: min(36rem, calc(100vw - 2rem));
    max-height: min(70vh, 42rem);
    overflow: hidden;
    border: 1px solid #cadce8;
    border-radius: .85rem;
    background: #f8fafc;
    box-shadow: 0 1.2rem 3rem rgba(1, 10, 45, .25);
    pointer-events: auto;
}

.analysis-matrix-meta-header__constraints-popover[hidden] { display: none; }
.analysis-matrix-meta-header__constraints-popover > header,
.analysis-matrix-meta-header__constraints-popover > footer {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .8rem 1rem;
    background: #fff;
}
.analysis-matrix-meta-header__constraints-popover > header { border-bottom: 1px solid #d9e5ed; }
.analysis-matrix-meta-header__constraints-popover > header > div { display: grid; gap: .12rem; }
.analysis-matrix-meta-header__constraints-popover > header strong { color: #102c52; font-size: .9rem; }
.analysis-matrix-meta-header__constraints-popover > header small { color: #69819a; font-size: .67rem; }
.analysis-matrix-meta-header__constraints-popover > header button { margin-left: auto; border: 0; background: transparent; color: #526b84; cursor: pointer; }
.analysis-matrix-meta-header__constraints-content { max-height: calc(min(70vh, 42rem) - 8rem); padding: .65rem; overflow: auto; }
.analysis-matrix-meta-header__constraints-content #customFilters { display: block !important; width: 100%; }
.analysis-matrix-meta-header__constraints-popover > footer { justify-content: flex-end; border-top: 1px solid #d9e5ed; }
.analysis-matrix-meta-header__constraints-popover > footer button { padding: .5rem .8rem; border: 1px solid #cbdce7; border-radius: .5rem; background: #fff; color: #36536f; font-weight: 700; cursor: pointer; }
.analysis-matrix-meta-header__constraints-popover > footer button[data-action="apply"] { border-color: #c01466; background: #c01466; color: #fff; }

.analysis-matrix-meta-header[hidden] {
    display: none;
}

.analysis-matrix-meta-header__title {
    grid-area: title;
    display: grid;
    min-width: 10rem;
    grid-template-columns: 1.5rem auto;
    grid-template-rows: auto auto;
    align-items: center;
    justify-self: center;
    column-gap: 0.4rem;
    text-align: left;
}

.analysis-matrix-meta-header__title > i {
    grid-row: 1 / 3;
    color: #c01466;
    font-size: 1.2rem;
}

.analysis-matrix-meta-header__title > strong {
    color: #0b2757;
    font: 800 0.82rem/1.1 "Ubuntu", sans-serif;
    letter-spacing: 0.045em;
    text-transform: uppercase;
    white-space: nowrap;
}

.analysis-matrix-meta-header__view {
    color: #607c9c;
    font: 600 0.62rem/1.15 "Ubuntu", sans-serif;
    white-space: nowrap;
}

.analysis-matrix-meta-header__context,
.analysis-matrix-meta-header__statistics {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 0.35rem;
    overflow: hidden;
}

.analysis-matrix-meta-header__context {
    grid-area: context;
    justify-content: center;
    flex-wrap: wrap;
}

.analysis-matrix-meta-header__statistics {
    grid-area: stats;
    justify-content: center;
}

.analysis-matrix-meta-header__context-item,
.analysis-matrix-meta-header__stat {
    display: inline-flex;
    min-width: 0;
    align-items: baseline;
    gap: 0.24rem;
    padding: 0.22rem 0.38rem;
    border-radius: 0.42rem;
    white-space: nowrap;
}

.analysis-matrix-meta-header__context-item {
    background: rgba(224, 242, 247, 0.82);
}

.analysis-matrix-meta-header__stat {
    background: rgba(244, 247, 251, 0.94);
}

.analysis-matrix-meta-header__context-item small,
.analysis-matrix-meta-header__stat small {
    color: #6c829f;
    font: 700 0.58rem/1 "Ubuntu", sans-serif;
    text-transform: uppercase;
}

.analysis-matrix-meta-header__context-item b,
.analysis-matrix-meta-header__stat b {
    max-width: 15rem;
    overflow: hidden;
    color: #173864;
    font: 750 0.69rem/1.1 "Ubuntu", sans-serif;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.analysis-matrix-meta-header[data-section="context"] {
    border-color: rgba(192, 20, 102, 0.35);
    background: linear-gradient(110deg, rgba(255, 247, 251, 0.94), rgba(255, 255, 255, 0.92));
}

@media (max-width: 1100px) {
    .analysis-matrix-meta-header {
        width: calc(100% - 1rem);
        padding: 0.4rem 0.55rem;
    }

    .analysis-matrix-meta-header__statistics,
    .analysis-matrix-meta-header__views {
        overflow-x: auto;
    }
}

@media (max-width: 760px) {
    .analysis-matrix-meta-header {
        grid-template-areas:
            "title"
            "views"
            "actions"
            "context"
            "stats";
        grid-template-columns: 1fr;
    }

    .analysis-matrix-meta-header__views,
    .analysis-matrix-meta-header__context,
    .analysis-matrix-meta-header__statistics {
        justify-self: center;
    }
}

/* Compact canvas tools: no repeated level title or full-width context card. */
#analysis-matrix-meta-header {
    display: flex;
    flex-wrap: wrap;
    width: max-content;
    max-width: calc(100% - 1rem);
    min-height: 0;
    justify-content: center;
    gap: .2rem .5rem;
    padding: .25rem .5rem;
    border: 0;
    border-radius: 0 0 .4rem .4rem;
    background: rgba(255, 255, 255, .92);
    box-shadow: none;
    backdrop-filter: none;
}
#analysis-matrix-meta-header .analysis-matrix-meta-header__context,
#analysis-matrix-meta-header .analysis-matrix-meta-header__title { display: none; }
#analysis-matrix-meta-header .analysis-matrix-meta-header__actions {
    display: flex;
    align-items: center;
    gap: .25rem;
}
#analysis-matrix-meta-header .analysis-matrix-meta-header__actions > button {
    min-height: 1.65rem;
    padding: .25rem .4rem;
}
#analysis-matrix-meta-header .analysis-matrix-meta-header__statistics:empty { display: none; }
#analysis-matrix-meta-header .analysis-matrix-meta-header__statistics { flex-wrap: wrap; }

#analysis-matrix-header > #analysis-matrix-header-graph-actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: .3rem;
    pointer-events: auto;
}
#analysis-matrix-header > #analysis-matrix-header-graph-actions[hidden] { display: none; }
#analysis-matrix-header-graph-actions > button {
    min-height: 1.8rem;
    padding: .3rem .45rem;
    white-space: nowrap;
}
#analysis-matrix-meta-header:has(.analysis-matrix-meta-header__statistics:empty):not(:has(.analysis-matrix-meta-header__actions > :not([hidden]))) {
    display: none;
}
