/**
 * Styles of the Customer Operations module (templates/customer_operations): the dashboard, the detail of a customer,
 * its chart of the total score per week and its history. Builds on the app shell and building blocks of app.css;
 * nothing here applies outside body.app-layout.
 */

.app-layout {
    --score-series: #2a78d6;
    --score-grid: #e8e7e3;
    --score-green: 25, 135, 84;
    --score-orange: 255, 193, 7;
    --score-red: 220, 53, 69;
}

/* The total score per week: a plot area of a fixed height over the whole width, in percentages (ScoreChartDTO); the
 * bands of the colours and the grid as boxes, the line as SVG stretched over the area (a stroke that doesn't scale),
 * the points and labels as HTML on top, so they stay round and sharp at any width. */
.app-layout .score-chart {
    position: relative;
    height: 15rem;
    padding: 0.5rem 0.75rem 1.75rem 2.25rem; /* room for the ticks on the left, the weeks below */
}

.app-layout .score-chart-plot {
    position: relative;
    height: 100%;
    border-bottom: 1px solid var(--bs-border-color);
}

.app-layout .score-band {
    position: absolute;
    left: 0;
    right: 0;
}

.app-layout .score-band-green { background: rgba(var(--score-green), 0.08); }
.app-layout .score-band-orange { background: rgba(var(--score-orange), 0.14); }
.app-layout .score-band-red { background: rgba(var(--score-red), 0.08); }

.app-layout .score-chart-grid {
    position: absolute;
    left: 0;
    right: 0;
    border-top: 1px solid var(--score-grid);
}

.app-layout .score-chart-tick,
.app-layout .score-chart-week {
    position: absolute;
    color: var(--bs-secondary-color);
    font-size: 0.75rem;
    line-height: 1;
    white-space: nowrap;
}

.app-layout .score-chart-tick {
    right: calc(100% + 0.5rem);
    transform: translateY(-50%);
}

.app-layout .score-chart-week {
    top: calc(100% + 0.5rem);
    transform: translateX(-50%);
}

.app-layout .score-chart-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
}

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

.app-layout .score-chart-point {
    position: absolute;
    width: 0.75rem;
    height: 0.75rem;
    border: 2px solid #fff; /* surface ring */
    border-radius: 50%;
    background: var(--score-series);
    transform: translate(-50%, 50%);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.app-layout .score-chart-point-green { background: rgb(var(--score-green)); }
.app-layout .score-chart-point-orange { background: rgb(var(--score-orange)); }
.app-layout .score-chart-point-red { background: rgb(var(--score-red)); }

.app-layout .score-chart-point:focus-visible {
    outline: 2px solid var(--bs-body-color);
    outline-offset: 1px;
}

/* The score of the latest week, above its point */
.app-layout .score-chart-label {
    position: absolute;
    transform: translate(-50%, -0.6rem);
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1;
    pointer-events: none;
}

/* A cell of the history that changed since the week before: neutral grey, so it never reads as a risk colour (the
 * arrow tells whether it went up or down); also the swatch of its legend */
.app-layout .history-changed {
    background-color: rgba(33, 37, 41, 0.05);
    box-shadow: inset 3px 0 0 rgba(33, 37, 41, 0.35);
}

.app-layout .history-changed-swatch {
    display: inline-block;
    width: 1.25rem;
    height: 0.85rem;
    vertical-align: -0.1rem;
}

/* An implementation project that doesn't count for the milestones (e.g. completed): shown, but greyed out */
.app-layout .project-not-counting > td {
    color: var(--bs-secondary-color);
}

/* A card per pillar and one for the total score on the detail of a customer: as many in a row as fit, the risk large,
 * a border on the left in the colour of the risk (the bands of the total score); grey when it doesn't count. */
.app-layout .pillar-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
    gap: 0.75rem;
}

.app-layout .pillar-card {
    min-width: 0;
    border-left: 4px solid var(--bs-border-color);
    overflow-wrap: anywhere; /* a long status (PI_Fully Live with ...) stays inside the card */
}

.app-layout .pillar-card > .card-body {
    display: flex;
    flex-direction: column;
}

/* The weight at the bottom of every card, also when the cards of a row differ in height */
.app-layout .pillar-weight {
    margin-top: auto !important;
}

.app-layout .pillar-card-green { border-left-color: rgb(var(--score-green)); }
.app-layout .pillar-card-orange { border-left-color: rgb(var(--score-orange)); }
.app-layout .pillar-card-red { border-left-color: rgb(var(--score-red)); }

.app-layout .pillar-card-missing {
    border-left-style: dashed;
    background: var(--bs-tertiary-bg);
}

.app-layout .pillar-risk {
    font-size: 2.25rem;
    font-weight: 700;
    line-height: 1.1;
    margin-bottom: 0.25rem;
    font-variant-numeric: tabular-nums;
}

.app-layout .pillar-card-green .pillar-risk { color: rgb(var(--score-green)); }
.app-layout .pillar-card-orange .pillar-risk { color: #b07d00; } /* the orange of the band is too light for text */
.app-layout .pillar-card-red .pillar-risk { color: rgb(var(--score-red)); }

/* The total score: a heavier border, first on a narrow screen */
.app-layout .pillar-card-total {
    border-left-width: 6px;
}

@media (max-width: 991.98px) {
    .app-layout .pillar-card-total { order: -1; }
}

/* The calculation of the score, folded: a chevron and "show"/"hide", the whole header clickable */
.app-layout .build-up > summary {
    cursor: pointer;
    list-style: none;
}

.app-layout .build-up > summary::-webkit-details-marker { display: none; }
.app-layout .build-up > summary:hover .build-up-show { text-decoration: underline; }
.app-layout .build-up-chevron { transition: transform 0.15s ease; }
.app-layout .build-up[open] .build-up-chevron { transform: rotate(90deg); }
.app-layout .build-up .build-up-hide,
.app-layout .build-up[open] .build-up-show { display: none; }
.app-layout .build-up[open] .build-up-hide { display: inline; }

/* Dashboard: the icons of the key figures in the colour of the risk */
.app-layout .stat-icon.tone-risk-red {
    background: rgba(var(--score-red), 0.1);
    color: rgb(var(--score-red));
}

.app-layout .stat-icon.tone-risk-orange {
    background: rgba(var(--score-orange), 0.18);
    color: #b07d00; /* the orange of the band is too light for text */
}

.app-layout .stat-icon.tone-risk-green {
    background: rgba(var(--score-green), 0.1);
    color: rgb(var(--score-green));
}

.app-layout .stat-icon.tone-risk-none {
    background: var(--bs-secondary-bg);
    color: var(--bs-secondary-color);
}

/* Dashboard: a long list scrolls within its block */
.app-layout .dashboard-list {
    max-height: 26rem;
    overflow-y: auto;
}

/* Dashboard: a kind of data quality, folded: a chevron, the whole header clickable */
.app-layout .quality-kind > summary {
    cursor: pointer;
    list-style: none;
}

.app-layout .quality-kind > summary::-webkit-details-marker { display: none; }
.app-layout .quality-chevron { transition: transform 0.15s ease; }
.app-layout .quality-kind[open] .quality-chevron { transform: rotate(90deg); }

/* Dashboard: a card without anything to show, compact */
.app-layout .dashboard-empty {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-height: 4.5rem;
    font-size: 0.875rem;
    color: var(--bs-secondary-color);
}

.app-layout .dashboard-empty > .bi {
    font-size: 1.25rem;
    opacity: 0.6;
}

/* Dashboard: the kinds of change of colour, as badges in the colour of the risk */
.app-layout .dashboard-kind { font-weight: 500; }
.app-layout .dashboard-kind-new_red { background: rgba(var(--score-red), 0.12); color: rgb(var(--score-red)); }
.app-layout .dashboard-kind-new_orange { background: rgba(var(--score-orange), 0.2); color: #8a6200; }
.app-layout .dashboard-kind-improvement { background: rgba(var(--score-green), 0.12); color: rgb(var(--score-green)); }
.app-layout .dashboard-kind-other { background: var(--bs-secondary-bg); color: var(--bs-secondary-color); }

/* Dashboard: a table in a card keeps the padding of the card at its sides */
.app-layout .dashboard-card .data-table > :not(caption) > * > :first-child { padding-left: 1rem; }
.app-layout .dashboard-card .data-table > :not(caption) > * > :last-child { padding-right: 1rem; }
.app-layout .dashboard-card .data-table td { vertical-align: middle; }
.app-layout .dashboard-card .data-table th:not(.w-100),
.app-layout .dashboard-card .data-table td:not(:first-child) { white-space: nowrap; }
.app-layout .dashboard-card .data-table .text-end { min-width: 4rem; }

/* Dashboard: the customers per colour per week (ColourHistoryChartDTO), like the score chart: a plot area of a fixed
 * height over the whole width, in percentages; a slot per week over the whole height (it carries the tooltip, also for
 * a thin part of the bar), the stacked bar in its middle (red at the bottom), the escalations as a line (SVG) with its
 * points (HTML) on top. A week without snapshot: an empty slot with a dashed mark on the axis. */
.app-layout .colour-chart {
    position: relative;
    height: 16rem;
    padding: 0.5rem 0.75rem 1.75rem 2.75rem; /* room for the ticks on the left (up to 4 digits), the weeks below */
}

.app-layout .colour-chart-plot {
    position: relative;
    height: 100%;
    border-bottom: 1px solid var(--bs-border-color);
}

.app-layout .colour-chart-slot {
    position: absolute;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    border-radius: 0.25rem;
}

.app-layout .colour-chart-slot:hover,
.app-layout .colour-chart-slot:focus-visible {
    background: rgba(33, 37, 41, 0.04);
}

.app-layout .colour-chart-slot:focus-visible {
    outline: 2px solid var(--bs-body-color);
    outline-offset: -2px;
}

.app-layout .colour-chart-bar {
    display: flex;
    flex-direction: column-reverse; /* the first part (red) at the bottom */
    width: 62%;
    max-width: 2.5rem;
    overflow: hidden;
    border-radius: 2px 2px 0 0;
}

/* A part keeps at least a sliver, so a few red customers among a thousand stay visible */
.app-layout .colour-chart-part {
    flex-basis: 0;
    min-height: 3px;
}

.app-layout .colour-chart-part + .colour-chart-part {
    box-shadow: 0 1px 0 #fff; /* a hairline between the parts */
}

.app-layout .colour-chart-part-red { background: rgb(var(--score-red)); }
.app-layout .colour-chart-part-orange { background: rgb(var(--score-orange)); }
.app-layout .colour-chart-part-green { background: rgba(var(--score-green), 0.55); }
.app-layout .colour-chart-part-none { background: var(--bs-secondary-bg); }

.app-layout .colour-chart-gap {
    width: 62%;
    max-width: 2.5rem;
    border-bottom: 2px dashed var(--bs-border-color);
}

.app-layout .colour-chart-svg,
.app-layout .colour-chart-point {
    pointer-events: none; /* the tooltip is the slot's */
}

.app-layout .colour-chart-line {
    fill: none;
    stroke: var(--bs-body-color);
    stroke-width: 1.5;
    stroke-dasharray: 4 3;
    stroke-linejoin: round;
    vector-effect: non-scaling-stroke;
}

.app-layout .colour-chart-point {
    position: absolute;
    width: 0.55rem;
    height: 0.55rem;
    border: 2px solid #fff; /* surface ring */
    border-radius: 50%;
    background: var(--bs-body-color);
    transform: translate(-50%, 50%);
}

/* The legend: a swatch per colour, a dashed line for the escalations */
.app-layout .colour-chart-swatch {
    display: inline-block;
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 2px;
    vertical-align: -0.1rem;
}

.app-layout .colour-chart-swatch-line {
    display: inline-block;
    width: 1.25rem;
    vertical-align: 0.25rem;
    border-top: 2px dashed var(--bs-body-color);
}

/* Dashboard: the distribution, the header stays in view while its list scrolls */
.app-layout .distribution-list {
    max-height: 32rem;
}

.app-layout .distribution-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--bs-body-bg);
}

.app-layout .distribution-table td:first-child {
    white-space: normal;
    overflow-wrap: anywhere;
}

.app-layout .distribution-count {
    font-variant-numeric: tabular-nums;
    text-decoration: none;
}

.app-layout .distribution-count:hover { text-decoration: underline; }
.app-layout .distribution-count-red { color: rgb(var(--score-red)); font-weight: 600; }
.app-layout .distribution-count-orange { color: #b07d00; font-weight: 600; } /* the orange of the band is too light */
.app-layout .distribution-count-green { color: rgb(var(--score-green)); }
.app-layout .distribution-count-none { color: var(--bs-secondary-color); }

/* A row's colours as one thin bar, so the groups compare at a glance */
.app-layout .distribution-bar-column {
    width: 10rem;
    min-width: 7rem;
}

.app-layout .distribution-bar {
    display: flex;
    height: 0.6rem;
    overflow: hidden;
    border-radius: 0.3rem;
    background: var(--bs-secondary-bg);
}

.app-layout .distribution-bar > span {
    display: block;
    height: 100%;
}
