/*
 * Performance dashboard - a layer on top of mls-on-the-fly-style.css, which
 * supplies the dashboard shell, field/select styling and .mls-on-the-fly-btn.
 *
 * Series colours (brand purple vs orange) are validated as a categorical pair on
 * white: CVD dE 33.7, normal-vision dE 41.8, both >= 3:1. Status colours always
 * ship with their word, never colour alone.
 */

.mofp {
    --brand: #6302DD;
    --brand-deep: #3C2B7D;
    --brand-soft: #f4efff;

    --surface: #ffffff;
    --plane: #f7f7f9;
    --ink: #1D2327;
    --ink-secondary: #525252;
    --ink-muted: #8D8D8D;
    --line: #E6E4EC;
    --baseline: #C6C6C6;

    --series-a: #6302DD; /* served from cache */
    --series-b: #eb6834; /* went to the API */

    --status-good: #0ca30c;
    --status-warning: #fab219;
    --status-critical: #DD1435;

    --radius-card: 16px;
    --radius-control: 8px;

    width: 100%;
    color: var(--ink);
    font-size: 14px;
    line-height: 24px;
}

/* The chart columns size themselves against their container's height; without
   border-box their padding overflows the plot and the bars ride up over the
   heading. */
.mofp *,
.mofp *::before,
.mofp *::after {
    box-sizing: border-box;
}

/* The shared shell adds overflow-x:auto for wide tables; the dashboard content
   wrapper is the full-width container this page lives in. */
.realtyna-base-plugin-dashboard-content-wrapper:has(.mofp) {
    overflow-y: visible;
}

/* ---------- cards ---------- */

.mofp-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-card);
    padding: 22px 24px;
    margin: 0 0 18px;
}

.mofp-card__title {
    margin: 0 0 2px;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.4;
    color: var(--ink);
}

.mofp-card__sub {
    margin: 0 0 20px;
    color: var(--ink-secondary);
    font-size: 13px;
    line-height: 20px;
    max-width: 78ch;
}

.mofp-grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
    gap: 18px;
}

.mofp-grid-2 > .mofp-card {
    margin-bottom: 18px;
}

/* ---------- filters: the settings page's own control styling ---------- */

.mofp-filters {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 0 0 20px;
    padding: 14px 18px;
    background: var(--brand-soft);
    border-radius: var(--radius-card);
}

.mofp-filters select {
    padding: 10px 30px 10px 14px;
    border: 1px solid var(--baseline);
    border-radius: var(--radius-control);
    background-color: #fff;
    line-height: 24px;
    font-size: 14px;
    color: var(--ink-secondary);
    min-width: 170px;
}

.mofp-filters select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 1px var(--brand);
    outline: none;
}

.mofp-filters__meta {
    color: var(--ink-secondary);
    font-size: 13px;
    margin-left: auto;
}

/* Revealed by the window select when "Specific day" is chosen; the browser
   supplies the calendar popup, so there is no widget of our own to style. */
.mofp-filters__date {
    padding: 9px 12px;
    border: 1px solid var(--baseline);
    border-radius: var(--radius-control);
    background-color: #fff;
    line-height: 24px;
    font-size: 14px;
    color: var(--ink-secondary);
}

.mofp-filters__date:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 1px var(--brand);
    outline: none;
}

/* [hidden] loses to the label's own display rule without this. */
.mofp-filters [hidden] {
    display: none;
}

/* Percentile labels carry their explanation in a tooltip; the dotted underline
   is the only thing telling a reader there is one to hover. */
.mofp-abbr {
    text-decoration: underline dotted;
    text-underline-offset: 2px;
    cursor: help;
}

/* ---------- hero ---------- */

.mofp-hero {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 40px;
    flex-wrap: wrap;
    background: linear-gradient(92.11deg, #3C2B7D 17.71%, #5F43CB 88.87%);
    border: none;
    color: #fff;
}

.mofp-hero__label {
    margin: 0 0 6px;
    color: rgba(255, 255, 255, 0.82);
    font-size: 14px;
    font-weight: 500;
}

.mofp-hero__value {
    margin: 0;
    font-size: 56px;
    line-height: 1.05;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: #fff;
}

.mofp-hero__sub {
    margin: 12px 0 0;
    color: rgba(255, 255, 255, 0.82);
    font-size: 13px;
}

.mofp-hero__note {
    margin: 0;
    flex: 1 1 340px;
    max-width: 52ch;
    color: rgba(255, 255, 255, 0.72);
    font-size: 13px;
    line-height: 21px;
}

/* On the gradient the status dot still carries colour, but the word needs to
   stay legible against it rather than using the light-surface ink token. */
.mofp-hero .mofp-status {
    color: #fff;
}

/* ---------- stat tiles ---------- */

.mofp-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(225px, 1fr));
    gap: 18px;
    margin-bottom: 18px;
}

.mofp-tile {
    margin: 0;
    padding: 18px 20px;
    transition: border-color 120ms ease;
}

.mofp-tile:hover {
    border-color: #cfc6e8;
}

.mofp-tile__label {
    margin: 0 0 8px;
    color: var(--ink-secondary);
    font-size: 13px;
    line-height: 18px;
}

.mofp-tile__value {
    margin: 0;
    font-size: 30px;
    font-weight: 700;
    line-height: 1.15;
    color: var(--ink);
}

.mofp-tile__meta {
    margin: 8px 0 0;
    color: var(--ink-muted);
    font-size: 12px;
    line-height: 18px;
}

/* ---------- status: a dot plus the word, never colour alone ---------- */

.mofp-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-right: 8px;
    font-weight: 700;
    color: var(--ink-secondary);
}

.mofp-status::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ink-muted);
    flex: none;
}

.mofp-status--good::before { background: var(--status-good); }
.mofp-status--warning::before { background: var(--status-warning); }
.mofp-status--critical::before { background: var(--status-critical); }

/* ---------- callout ---------- */

.mofp-callout {
    border: 1px solid var(--line);
    border-left: 4px solid var(--ink-muted);
    border-radius: var(--radius-control);
    background: var(--surface);
    padding: 16px 20px;
    margin: 0 0 18px;
}

.mofp-callout p {
    margin: 0;
    line-height: 22px;
    max-width: 100ch;
}

.mofp-callout--critical { border-left-color: var(--status-critical); }

/* ---------- charts ---------- */

.mofp-chart {
    display: flex;
    align-items: stretch;
    gap: 2px; /* 2px surface gap between adjacent bars */
    height: 190px;
    margin-bottom: 28px;
    border-bottom: 1px solid var(--baseline);
    position: relative;
}

.mofp-col {
    position: relative;
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    height: 100%;
}

.mofp-col__plot {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: flex-end;
}

/* Distribution charts have few, wide columns; inset the mark so bars read as
   marks on a surface rather than as solid blocks. Timeline columns are already
   one thin bar each. */
.mofp-chart:not(.mofp-chart--timeline) .mofp-col__plot {
    padding: 0 9px;
}

.mofp-col__label {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    padding-top: 8px;
    font-size: 11px;
    color: var(--ink-muted);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Timeline ticks are drawn on every Nth column only, so they may spill past
   their own column rather than being ellipsised into "1...". */
.mofp-col__label--sparse {
    width: auto;
    min-width: 100%;
    overflow: visible;
    text-overflow: clip;
    transform: translateX(-50%);
    left: 50%;
}

.mofp-bar {
    width: 100%;
    border-radius: 4px 4px 0 0; /* rounded data-end, square against the baseline */
    background: var(--series-a);
    transition: filter 120ms ease;
}

.mofp-bar--b { background: var(--series-b); }

.mofp-stack {
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

/* Upper segment keeps the rounded end; lower segment squares off and leaves a
   2px surface gap so the two series never touch. */
.mofp-stack .mofp-bar--b {
    border-radius: 4px 4px 0 0;
    margin-bottom: 2px;
}

.mofp-stack .mofp-bar--a {
    border-radius: 0;
}

.mofp-col:hover .mofp-bar {
    filter: brightness(1.15);
}

/* ---------- hover tooltip ---------- */

.mofp-tip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translate(-50%, -8px);
    background: var(--brand-deep);
    color: #fff;
    font-size: 12px;
    line-height: 1.45;
    padding: 7px 10px;
    border-radius: var(--radius-control);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 120ms ease;
    z-index: 5;
}

.mofp-col:hover .mofp-tip,
.mofp-col:focus-within .mofp-tip {
    opacity: 1;
}

/* Columns near either edge would push a centred tooltip outside the card, where
   it gets clipped. Anchor those to the inside edge instead. The timeline needs a
   wider band because its columns are much narrower. */
.mofp-chart:not(.mofp-chart--timeline) .mofp-col:first-child .mofp-tip,
.mofp-chart--timeline .mofp-col:nth-child(-n+8) .mofp-tip {
    left: 0;
    transform: translate(0, -8px);
}

.mofp-chart:not(.mofp-chart--timeline) .mofp-col:last-child .mofp-tip,
.mofp-chart--timeline .mofp-col:nth-last-child(-n+8) .mofp-tip {
    left: auto;
    right: 0;
    transform: translate(0, -8px);
}

/* ---------- legend ---------- */

.mofp-legend {
    display: flex;
    gap: 20px;
    margin: 0 0 16px;
    font-size: 13px;
    color: var(--ink-secondary);
}

.mofp-legend__item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.mofp-swatch {
    width: 11px;
    height: 11px;
    border-radius: 3px;
    display: inline-block;
}

.mofp-swatch--a { background: var(--series-a); }
.mofp-swatch--b { background: var(--series-b); }

/* ---------- tables ---------- */

.mofp-table-toggle {
    margin-top: 20px;
    font-size: 13px;
}

.mofp-table-toggle summary {
    cursor: pointer;
    color: var(--brand);
    font-weight: 500;
}

.mofp-table-toggle table {
    margin-top: 12px;
}

.mofp table.widefat {
    border: 1px solid var(--line);
    border-radius: var(--radius-control);
    overflow: hidden;
    border-collapse: separate;
    border-spacing: 0;
}

.mofp table.widefat thead th {
    background: var(--plane);
    font-weight: 700;
    font-size: 13px;
    color: var(--ink);
    border-bottom: 1px solid var(--line);
}

.mofp table.widefat td {
    font-size: 13px;
    color: var(--ink-secondary);
    vertical-align: middle;
}

.mofp .mofp-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.mofp-shape {
    display: block;
    max-width: 78ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    background: var(--brand-soft);
    color: var(--ink-secondary);
    padding: 4px 8px;
    border-radius: 6px;
}

/* ---------- empty state & footer ---------- */

.mofp-empty {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-card);
    padding: 48px 32px;
    text-align: center;
    color: var(--ink-secondary);
}

.mofp-empty p {
    margin: 0 auto 8px;
    max-width: 66ch;
    line-height: 22px;
}

.mofp-reset {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 4px;
}

.mofp-reset__note {
    color: var(--ink-muted);
    font-size: 13px;
}

/* The shared button styles carry a 10px bottom margin for stacked forms; inside
   this flex row that would knock the button out of alignment. */
.mofp-reset .mls-on-the-fly-btn,
.mofp-filters .mls-on-the-fly-btn {
    margin-bottom: 0;
}

@media (max-width: 782px) {
    .mofp-hero__value { font-size: 42px; }
    .mofp-filters__meta { margin-left: 0; width: 100%; }
}

/* ---------- per-request table ---------- */

/* A recorded URL can be 400 characters of query string. Without a scroll box of
   its own, one row like that widens the table, the table widens the page, and
   wp-admin's fixed sidebar ends up overlapping the content. */
.mofp-scroll {
    overflow-x: auto;
    max-width: 100%;
}

/* Fixed layout is what makes truncation possible at all: with auto layout the
   longest cell still dictates the column width, ellipsis or not. */
.mofp-requests {
    table-layout: fixed;
    width: 100%;
    min-width: 900px;
}

.mofp-requests .mofp-col-url { width: 30%; }
.mofp-requests .mofp-col-shapes { width: 18%; }
.mofp-requests .mofp-col-n { width: 8%; }
.mofp-requests .mofp-col-when { width: 12%; }

.mofp .mofp-clip {
    overflow: hidden;
}

.mofp-requests .mofp-url {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 600;
}

.mofp-chip {
    display: inline-block;
    margin-top: 4px;
    padding: 1px 8px;
    border-radius: 999px;
    background: var(--brand-soft);
    color: var(--ink-secondary);
    font-size: 11px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.mofp-requests .mofp-shape {
    max-width: 100%;
}

/* The status word carries its own dot, so no right margin is needed in a cell. */
.mofp-cache .mofp-status {
    margin-right: 0;
    white-space: nowrap;
}
