/**
 * Styles of the User Stats module (templates/user_stats): the toppers & floppers tables and the data point charts.
 * Builds on the app shell and building blocks of app.css; nothing here applies outside body.app-layout.
 */

/* Diverging scale of the growth (z-score): blue = more growth than normal, red = less, gray around zero (the same
 * poles as the dataviz reference palette, see assets/styles/marketing_funnel.css for its blue ramp). */
.app-layout {
    --growth-up: 42, 120, 214;
    --growth-down: 227, 73, 72;
    --growth-zero: 137, 135, 129;
    --line-series: #2a78d6;
    --line-highlight: #0d366b;
    --line-grid: #e8e7e3;
}

.app-layout .ranking-table .ranking-position {
    width: 3rem;
    font-variant-numeric: tabular-nums;
}

.app-layout .growth-cell {
    width: 8rem;
    text-align: center;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    background-color: rgba(var(--growth-zero), var(--growth-intensity, 0.08));
    box-shadow: inset 2px 0 0 #fff; /* surface gap between adjacent cells */
}

.app-layout .growth-cell.is-up {
    background-color: rgba(var(--growth-up), var(--growth-intensity));
}

.app-layout .growth-cell.is-down {
    background-color: rgba(var(--growth-down), var(--growth-intensity));
}

.app-layout .growth-cell.is-empty {
    background-color: transparent;
    color: var(--bs-secondary-color);
}

.app-layout .skipped-value {
    cursor: help;
    text-decoration: underline dotted;
}

.app-layout .growth-legend-text {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
}

.app-layout .growth-legend {
    display: inline-block;
    width: 8rem;
    height: 0.625rem;
    border-radius: 2px;
    background: linear-gradient(
        to right,
        rgba(var(--growth-down), 0.58),
        rgba(var(--growth-zero), 0.08),
        rgba(var(--growth-up), 0.58)
    );
}

.app-layout .ranking-date {
    width: 10rem;
}

/* Line chart of the data points of a metric ------------------------------------------------------------------------ */
.app-layout .line-chart {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
}

.app-layout .line-chart-grid {
    stroke: var(--line-grid);
    stroke-width: 1;
}

.app-layout .line-chart-tick {
    fill: var(--bs-secondary-color);
    font-size: 12px;
}

.app-layout .line-chart-line {
    fill: none;
    stroke: var(--line-series);
    stroke-width: 2;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.app-layout .line-chart-point {
    fill: var(--line-series);
    stroke: #fff; /* surface ring */
    stroke-width: 2;
    cursor: default;
}

.app-layout .line-chart-point.is-highlighted {
    fill: var(--line-highlight);
}

/* The charts of a customer per month: the average of the last 3 months (categorical slot 2, validated with slot 1)
 * and the hollow point of an estimated month */
.app-layout {
    --line-trend: #eb6834;
}

.app-layout .month-chart-trend {
    fill: none;
    stroke: var(--line-trend);
    stroke-width: 2;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.app-layout .line-chart-point.is-estimated {
    fill: #fff;
    stroke: var(--line-series);
}

.app-layout .month-chart-legend svg {
    vertical-align: -1px;
    overflow: visible;
}

.app-layout .line-chart-point:focus-visible {
    outline: none;
    stroke: var(--bs-body-color);
}

/* Status (data stream): the fixed status scale of the dataviz reference palette; never color alone (icon + label) */
.app-layout {
    --status-good: #0ca30c;
    --status-warning: #fab219;
    --status-serious: #ec835a;
    --status-critical: #d03b3b;
}

.app-layout .status-fill-good { background: var(--status-good); }
.app-layout .status-fill-warning { background: var(--status-warning); }
.app-layout .status-fill-critical { background: var(--status-critical); }
.app-layout .status-fill-neutral { background: rgb(var(--growth-zero)); } /* excluded on purpose: no status */

.app-layout .status-text-good { color: #0b7a0b; }
.app-layout .status-text-warning { color: #9a6700; }
.app-layout .status-text-critical { color: var(--status-critical); }

.app-layout .status-badge {
    font-weight: 500;
    border: 1px solid transparent;
}

.app-layout .status-badge.status-good { background: #e3f4e3; color: #0b5e0b; border-color: #b6e0b6; }
.app-layout .status-badge.status-warning { background: #fff3d6; color: #7a5200; border-color: #f5d68a; }
.app-layout .status-badge.status-neutral { background: #f0efec; color: #55534e; border-color: #dcdad5; }
.app-layout .status-badge.status-new { background: #e8f0fc; color: #1c4f94; border-color: #bcd3f3; }
.app-layout .status-badge.status-critical { background: #fbe4e4; color: #9c2424; border-color: #f0b5b5; }

.app-layout .status-swatch {
    display: inline-block;
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 2px;
    vertical-align: -0.05rem;
}

/* The active customers per group: a 100% bar */
.app-layout .logfile-bar {
    display: flex;
    gap: 2px; /* surface gap between the segments */
    height: 1.25rem;
}

.app-layout .logfile-segment {
    flex-basis: 0;
    min-width: 3px;
}

.app-layout .logfile-segment:first-child { border-radius: 4px 0 0 4px; }
.app-layout .logfile-segment:last-child { border-radius: 0 4px 4px 0; }

/* The logfiles per week: stacked columns, the total on the cap */
.app-layout .week-chart {
    display: flex;
    align-items: stretch;
    gap: 0.5rem;
    height: 11rem;
    border-bottom: 1px solid var(--line-grid);
}

.app-layout .week-column {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    min-width: 0;
    position: relative;
}

.app-layout .week-stack {
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 100%;
    max-width: 24px;
    min-height: 2px;
}

.app-layout .week-segment {
    flex-basis: 0;
    min-height: 2px;
}

.app-layout .week-segment:first-child { border-radius: 4px 4px 0 0; }

.app-layout .week-total {
    font-variant-numeric: tabular-nums;
    color: var(--bs-secondary-color);
}

.app-layout .week-label {
    position: absolute;
    top: 100%;
    padding-top: 0.25rem;
    white-space: nowrap;
}

.app-layout .week-chart + details {
    margin-top: 2rem !important;
}

/* The customers per release of MultiPress: a donut on an ordinal blue ramp, one hue from dark to light (the newest
 * release darkest, the same steps as the segments of the Marketing funnel). The lighter steps are below 3:1 on the
 * card, so the legend always writes out the release, number and share. */
.app-layout {
    --release-0: #0d366b;
    --release-1: #1c5cab;
    --release-2: #2a78d6;
    --release-3: #5598e7;
    --release-4: #86b6ef;
}

.app-layout .release-slice.release-0 { stroke: var(--release-0); }
.app-layout .release-slice.release-1 { stroke: var(--release-1); }
.app-layout .release-slice.release-2 { stroke: var(--release-2); }
.app-layout .release-slice.release-3 { stroke: var(--release-3); }
.app-layout .release-slice.release-4 { stroke: var(--release-4); }
.app-layout .release-swatch.release-0 { background: var(--release-0); }
.app-layout .release-swatch.release-1 { background: var(--release-1); }
.app-layout .release-swatch.release-2 { background: var(--release-2); }
.app-layout .release-swatch.release-3 { background: var(--release-3); }
.app-layout .release-swatch.release-4 { background: var(--release-4); }

.app-layout .release-donut {
    position: relative;
    max-width: 14rem;
}

.app-layout .release-donut svg {
    display: block;
    width: 100%;
}

.app-layout .release-slice {
    fill: none;
    stroke-width: 6;
}

/* A slice links to its customers: thicker on hover or keyboard focus, never the outline of the whole donut */
.app-layout .release-link {
    outline: none;
}

.app-layout .release-link:hover .release-slice,
.app-layout .release-link:focus-visible .release-slice {
    stroke-width: 7.5;
}

.app-layout .release-donut-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.app-layout .release-legend li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0;
}

.app-layout .release-legend li + li {
    border-top: 1px solid var(--line-grid);
}

.app-layout .release-swatch {
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 2px;
    flex-shrink: 0;
}

.app-layout .release-value {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* The new (up) and deactivated (down) users per month: bars about a zero line, on one scale */
.app-layout .user-fill-new { background: rgb(var(--growth-up)); }
.app-layout .user-fill-deactivated { background: rgb(var(--growth-down)); }

.app-layout .user-chart {
    display: flex;
    gap: 0.5rem;
    height: 14rem;
    margin-bottom: 2rem;
}

.app-layout .user-month {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 0;
    position: relative;
}

.app-layout .user-half {
    flex: 1 1 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.app-layout .user-half-up {
    justify-content: flex-end;
    border-bottom: 1px solid var(--bs-secondary-color); /* the zero line */
}

.app-layout .user-bar {
    width: 100%;
    max-width: 24px;
    min-height: 1px;
}

.app-layout .user-half-up .user-bar { border-radius: 4px 4px 0 0; }
.app-layout .user-half-down .user-bar { border-radius: 0 0 4px 4px; }

.app-layout .user-value {
    font-variant-numeric: tabular-nums;
    color: var(--bs-secondary-color);
}

/* The userstats per month of a job (ranking detail, tab "Monthly figures"): the legend of the flags */
.app-layout .month-legend {
    display: grid;
    gap: 0.5rem;
}

.app-layout .month-legend > div {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}

.app-layout .month-legend dt {
    flex: 0 0 9rem;
    font-weight: normal;
}

/* The control table: the header and the customer column stay in view while scrolling the table */
.app-layout .control-table-scroll {
    max-height: 75vh;
    overflow: auto;
}

.app-layout .control-table th,
.app-layout .control-table td {
    white-space: nowrap;
    background: var(--bs-body-bg);
}

/* The numbers are right aligned, the text columns left (set here instead of on every cell of 500+ rows) */
.app-layout .control-table td {
    text-align: right;
}

.app-layout .control-table td.control-text {
    text-align: left;
}

.app-layout .control-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #fafbfd;
    vertical-align: bottom;
}

.app-layout .control-table .control-customer,
.app-layout .control-table thead th:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    min-width: 14rem;
    max-width: 18rem;
    white-space: normal;
    font-weight: normal;
    border-right: 1px solid var(--app-card-border);
}

.app-layout .control-table thead th:first-child {
    z-index: 3;
}

/* The months of a customer: the month column is narrow */
.app-layout .control-history .control-customer,
.app-layout .control-history thead th:first-child {
    min-width: 5.5rem;
}

@media (max-width: 575.98px) {
    .app-layout .control-table .control-customer,
    .app-layout .control-table thead th:first-child {
        min-width: 9rem;
        max-width: 11rem;
    }
}

/*
 * The status icons of the control table (growth, latest logfile), in the status palette (good, warning, serious,
 * critical). Warning and serious are close and below 3:1 on white: every status has its own icon and a label (title,
 * screen readers, legend), and the value itself stays in the text color.
 */
.app-layout .status-icon {
    margin-right: 0.3rem;
}

.app-layout .status-icon-good { color: var(--status-good); }
.app-layout .status-icon-warning { color: var(--status-warning); }
.app-layout .status-icon-serious { color: var(--status-serious); }
.app-layout .status-icon-critical { color: var(--status-critical); }

.app-layout .control-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 2rem;
    margin-bottom: 0.75rem !important;
}

.app-layout .control-legend > div {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem 1rem;
}

.app-layout .control-legend dt {
    font-weight: 500;
}

/* The toppers & floppers history of a customer (templates/user_stats/customer/_ranking.html.twig): a bar per day with a
 * successful run, up from the middle line for a topper, down for a flopper, its length (--ranking-height, 0..1) the
 * higher the position; a day without the job is a dot on the line. */
.app-layout .ranking-history-facts {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 2rem;
    margin-bottom: 1rem;
}

.app-layout .ranking-history-facts dt {
    font-weight: 400;
    color: var(--bs-secondary-color);
}

.app-layout .ranking-history-facts dd {
    margin-bottom: 0;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.app-layout .ranking-strip {
    position: relative;
    display: flex;
    gap: 1px;
    height: 4rem;
}

.app-layout .ranking-strip::before {
    content: '';
    position: absolute;
    inset: calc(50% - 0.5px) 0 auto;
    height: 1px;
    background: var(--line-grid);
}

.app-layout .ranking-strip-day {
    position: relative;
    flex: 1 1 0;
    min-width: 0;
}

.app-layout .ranking-strip-day::before {
    content: '';
    position: absolute;
    inset-inline: 0;
    border-radius: 1px;
}

.app-layout .ranking-strip-day.is-top::before {
    bottom: 50%;
    height: calc(var(--ranking-height) * 50%);
    background: var(--status-good);
}

.app-layout .ranking-strip-day.is-flop::before {
    top: 50%;
    height: calc(var(--ranking-height) * 50%);
    background: var(--status-critical);
}

.app-layout .ranking-strip-day.is-none::before {
    top: calc(50% - 1px);
    height: 2px;
    background: rgb(var(--growth-zero));
}

.app-layout a.ranking-strip-day:hover::before {
    filter: brightness(0.8);
}

.app-layout .ranking-strip-axis {
    position: relative;
    height: 1.25rem;
    margin-top: 0.25rem;
}

.app-layout .ranking-strip-axis span {
    position: absolute;
    top: 0;
    white-space: nowrap;
}

/* The market on the dashboard: the growth against a year before of the latest month, and the diffusion as columns of
 * 100% in the diverging colors of the ranking (growth blue on top, stable gray, decline red at the bottom), every
 * segment with a tooltip and the shares in the legend and table */
.app-layout .market-yoy {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr));
    gap: 0.5rem 1rem;
}

.app-layout .diffusion-growth { background: rgb(var(--growth-up)); }
.app-layout .diffusion-stable { background: rgb(var(--growth-zero)); }
.app-layout .diffusion-decline { background: rgb(var(--growth-down)); }

.app-layout .diffusion-chart {
    display: flex;
    align-items: stretch;
    gap: 3px;
    height: 11rem;
    border-bottom: 1px solid var(--line-grid);
}

.app-layout .diffusion-column {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    min-width: 0;
    position: relative;
}

.app-layout .diffusion-stack {
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 100%;
    max-width: 22px;
    height: 100%;
}

.app-layout .diffusion-segment {
    flex-basis: 0;
    min-height: 2px;
}

.app-layout .diffusion-segment:first-child { border-radius: 4px 4px 0 0; }

/* Over more than 5 years the columns are narrow: a smaller gap and corner */
.app-layout .diffusion-chart.is-dense { gap: 1px; }
.app-layout .diffusion-chart.is-dense .diffusion-stack { gap: 1px; }
.app-layout .diffusion-chart.is-dense .diffusion-segment:first-child { border-radius: 1px 1px 0 0; }

.app-layout .diffusion-label {
    position: absolute;
    top: 100%;
    padding-top: 0.25rem;
    white-space: nowrap;
    color: var(--bs-secondary-color);
    font-size: 12px; /* as the ticks of the line charts */
}

/* On a phone only every half year, the labels would overlap */
@media (max-width: 575.98px) {
    .app-layout .diffusion-label:not(.is-major) {
        display: none;
    }
}
