/* =============================================================================
   Insights (js/views/insights.js) — analytical views for management.
   Each view is a card: title + window, what it shows, the headline finding,
   the chart / tables, the bottom line and a method note. Reuses the app's
   KPI cards, section blocks and chart containers; only what is new is here.
   ============================================================================= */

.insights {
    --ins-teal: #0F9FC4;
    --ins-teal-dark: #0A7A97;
    --ins-navy: #1F3D7C;
    --ins-slate: #808FAD;
    --ins-silver: #E3E4E9;
    --ins-red: #D93025;
    --ins-amber: #E8710A;
    --ins-ink: #1b2a4a;
    --ins-chart-h: 320px;
}

.insights__loading,
.insights__empty {
    color: var(--slate, #808FAD);
    font-size: 0.85rem;
    margin: 0.75rem 0;
}

.insights__section {
    margin-bottom: 1.25rem;
}

/* ---- One view ---- */
.insights__view {
    margin-top: 1rem;
    padding: 1.1rem 1.25rem 1rem;
}

.insights__view-head {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.insights__title {
    margin: 0;
    font-size: 0.9rem;
}

.insights__window {
    margin: 0.1rem 0 0;
    font-size: 0.75rem;
    color: var(--ins-slate, #808FAD);
}

/* Small caps label over each block: In plain words / What the data says / bottom line. */
.insights__label {
    margin: 0 0 0.3rem;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    color: var(--ins-slate, #808FAD);
}

/* How to read the chart, in everyday words. */
.insights__plain {
    margin-bottom: 0.85rem;
}

.insights__plain p {
    margin: 0;
    font-size: 0.85rem;
    line-height: 1.55;
    color: var(--ins-ink, #1b2a4a);
    max-width: 75rem;
}

/* The money impact — set apart so it is the second thing a manager reads. */
.insights__money {
    margin-top: 1rem;
    padding: 0.7rem 0.9rem;
    border: 1px solid #CDEBD6;
    border-left: 4px solid #1E8E3E;
    border-radius: 0 8px 8px 0;
    background: #F2FAF4;
}

.insights__money p {
    margin: 0;
    font-size: 0.86rem;
    line-height: 1.55;
    color: var(--ins-ink, #1b2a4a);
}

.insights__label--money {
    color: #1E8E3E;
}

/* The finding — the line a manager reads first. */
.insights__headline {
    margin: 0 0 0.9rem;
    padding: 0.6rem 0.85rem;
    border-left: 4px solid var(--ins-teal, #0F9FC4);
    background: var(--pale-cyan, #EAF7FA);
    border-radius: 0 8px 8px 0;
    font-size: 0.92rem;
    font-weight: 600;
    line-height: 1.5;
    color: var(--ins-ink, #1b2a4a);
}

.insights__note {
    margin: 0.75rem 0 0;
    font-size: 0.72rem;
    color: var(--ins-slate, #808FAD);
}

.insights__good { color: var(--ins-teal-dark, #0A7A97); }
.insights__bad { color: var(--ins-red, #D93025); }

/* ---- Charts ---- */
.insights__chart {
    position: relative;
    height: var(--ins-chart-h, 320px);
}

.insights__chart--tall { height: 420px; }
.insights__chart--short { height: 220px; }

/* Price bands customer chart: height follows the customer count, about 22px
   a bar (classes picked in insights.js, BAND_ROW_CLASSES). */
.insights__chart--rows-s { height: 320px; }
.insights__chart--rows-m { height: 560px; }
.insights__chart--rows-l { height: 800px; }
.insights__chart--rows-xl { height: 1060px; }

/* A chart whose bars can be clicked (set while the pointer is over a bar). */
.insights__canvas--clickable { cursor: pointer; }

/* ---- Price bands: product picker above the customer chart ---- */
.insights__band-pick {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 1rem;
}

.insights__band-pick .insights__mini-title {
    margin: 0;
}

.insights__band-select {
    width: auto;
    max-width: 100%;
}

/* Export to PDF: the price-bands card without its customer block (page 1)… */
.insights__view--pdf-no-detail .insights__band-detail {
    display: none;
}

/* …and the customer block captured on its own (page 2), padded like a card. */
.insights__band-detail--pdf {
    padding: 0.25rem 1.25rem 1rem;
    background: var(--white, #ffffff);
}

.insights__split {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    gap: 1.25rem;
    align-items: start;
}

.insights__split--wide {
    grid-template-columns: minmax(0, 4fr) minmax(0, 1.4fr);
}

/* ---- Small lists (bridge contributors) ---- */
.insights__minis {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.insights__mini-title {
    margin: 0.75rem 0 0.4rem;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--ins-navy, #1F3D7C);
}

.insights__mini-list {
    margin: 0;
    padding-left: 1.1rem;
    font-size: 0.78rem;
    color: var(--ins-ink, #1b2a4a);
}

.insights__mini-list li {
    margin-bottom: 0.2rem;
}

.insights__mini-list li span {
    display: inline-block;
    max-width: calc(100% - 5.5rem);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
}

.insights__mini-list li b {
    float: right;
    font-variant-numeric: tabular-nums;
}

/* ---- Tables ---- */
.insights__table-wrap {
    overflow-x: auto;
}

.insights__table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}

.insights__table th {
    text-align: left;
    font-size: 0.66rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--ins-slate, #808FAD);
    padding: 0.35rem 0.5rem;
    border-bottom: 1px solid var(--ins-silver, #E3E4E9);
    white-space: nowrap;
}

.insights__table td {
    padding: 0.35rem 0.5rem;
    border-bottom: 1px solid var(--ins-silver, #E3E4E9);
    color: var(--ins-ink, #1b2a4a);
}

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

.insights__details {
    margin-top: 0.75rem;
    font-size: 0.8rem;
}

.insights__details summary {
    cursor: pointer;
    color: var(--ins-teal-dark, #0A7A97);
    font-weight: 600;
}

/* ---- ABC–XYZ matrix ---- */
.insights__matrix {
    display: grid;
    grid-template-columns: 7rem repeat(3, minmax(0, 1fr));
    gap: 0.5rem;
    align-items: stretch;
}

.insights__axis {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--ins-navy, #1F3D7C);
    text-align: center;
    align-self: end;
}

.insights__axis--row {
    text-align: left;
    align-self: center;
}

.insights__cell {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.1rem;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--ins-silver, #E3E4E9);
    border-radius: 8px;
    text-align: left;
    font-family: 'Red Hat Display', sans-serif;
    color: var(--ins-ink, #1b2a4a);
    cursor: pointer;
}

.insights__cell:focus-visible {
    outline: 2px solid var(--ins-teal, #0F9FC4);
    outline-offset: 2px;
}

/* Share-of-sales steps, light → dark; dark steps switch to white text. */
.insights__cell--l0 { background: #F7F7F8; }
.insights__cell--l1 { background: #EAF7FA; }
.insights__cell--l2 { background: #C3E7F0; }
.insights__cell--l3 { background: #6CC3DB; }
.insights__cell--l4 { background: #0F9FC4; color: #ffffff; }

.insights__cell--active {
    box-shadow: 0 0 0 3px var(--ins-navy, #1F3D7C);
}

.insights__cell-key { font-weight: 800; font-size: 0.95rem; }
.insights__cell-count { font-weight: 700; font-size: 0.85rem; }
.insights__cell-share { font-size: 0.78rem; }
.insights__cell-policy { font-size: 0.7rem; opacity: 0.85; }

.insights__cell-list {
    margin-top: 0.5rem;
}

/* ---- Dispatch calendar ---- */
.insights__cal-scroll {
    overflow-x: auto;
}

.insights__cal {
    display: grid;
    grid-template-columns: 5.2rem repeat(31, minmax(11px, 1fr)) 4.6rem 5.4rem;
    gap: 3px;
    align-items: center;
    min-width: 640px;
    font-size: 0.7rem;
}

.insights__cal-head {
    text-align: center;
    color: var(--ins-slate, #808FAD);
    font-size: 0.6rem;
}

.insights__cal-head--r { text-align: right; }

.insights__cal-month {
    font-weight: 600;
    color: var(--ins-navy, #1F3D7C);
    white-space: nowrap;
}

.insights__cal-day {
    display: inline-block;
    aspect-ratio: 1;
    min-height: 11px;
    border-radius: 3px;
}

.insights__cal-day--tail {
    outline: 1.5px solid var(--ins-navy, #1F3D7C);
    outline-offset: -1px;
}

.insights__cal-day--s0 { background: #F1F3F6; }
.insights__cal-day--s1 { background: #D6EFF5; }
.insights__cal-day--s2 { background: #A6DCEA; }
.insights__cal-day--s3 { background: #5FBFD9; }
.insights__cal-day--s4 { background: #1C96B8; }
.insights__cal-day--s5 { background: #1F3D7C; }

.insights__legend .insights__cal-day {
    width: 12px;
    height: 12px;
    margin: 0 1px;
    vertical-align: middle;
}

.insights__cal-total {
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--ins-ink, #1b2a4a);
}

.insights__cal-tail {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    font-variant-numeric: tabular-nums;
    color: var(--ins-ink, #1b2a4a);
}

.insights__cal-bar {
    display: inline-block;
    height: 8px;
    border-radius: 2px;
    background: var(--ins-amber, #E8710A);
}

/* Bar width in tenths of the largest month-end share. */
.insights__cal-bar--w0 { width: 0; }
.insights__cal-bar--w1 { width: 3px; }
.insights__cal-bar--w2 { width: 6px; }
.insights__cal-bar--w3 { width: 9px; }
.insights__cal-bar--w4 { width: 12px; }
.insights__cal-bar--w5 { width: 15px; }
.insights__cal-bar--w6 { width: 18px; }
.insights__cal-bar--w7 { width: 21px; }
.insights__cal-bar--w8 { width: 24px; }
.insights__cal-bar--w9 { width: 27px; }
.insights__cal-bar--w10 { width: 30px; }

.insights__legend {
    margin: 0.5rem 0 0;
    font-size: 0.7rem;
    color: var(--ins-slate, #808FAD);
}

/* ---- Supply-risk matrix legend ---- */
.insights__keys {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 1.2rem;
    margin: 0 0 0.5rem;
    font-size: 0.75rem;
    color: var(--ins-ink, #1b2a4a);
}

.insights__key {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.insights__key-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.insights__key-dot--strategic { background: #D93025; }
.insights__key-dot--bottleneck { background: #E8710A; }
.insights__key-dot--leverage { background: #0F9FC4; }
.insights__key-dot--routine { background: #808FAD; }

/* ---- Simple trend measures (revenue per kg, RM cost, key accounts, lead time) ---- */
.insights__plain-line {
    margin: 0 0 0.6rem;
    font-size: 0.84rem;
    line-height: 1.5;
    color: var(--ins-ink, #1b2a4a);
}

.insights__figures {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.75rem;
    margin-bottom: 0.75rem;
}

.insights__figure {
    display: flex;
    flex-direction: column;
}

.insights__figure-value {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--ins-navy, #1F3D7C);
    font-variant-numeric: tabular-nums;
}

.insights__figure-value.insights__good { color: var(--ins-teal-dark, #0A7A97); }
.insights__figure-value.insights__bad { color: var(--ins-red, #D93025); }

.insights__figure-label {
    font-size: 0.68rem;
    color: var(--ins-slate, #808FAD);
}

/* Two measures side by side on wide screens. */
.insights__pair {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 1rem;
}

/* ---- Narrow screens ---- */
@media (max-width: 991px) {
    .insights__split,
    .insights__split--wide {
        grid-template-columns: minmax(0, 1fr);
    }

    .insights__minis {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .insights__pair {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 575px) {
    .insights__view {
        padding: 0.9rem 0.85rem;
    }

    .insights__minis {
        grid-template-columns: minmax(0, 1fr);
    }

    .insights__matrix {
        grid-template-columns: 4.5rem repeat(3, minmax(0, 1fr));
        gap: 0.3rem;
    }

    .insights__cell {
        padding: 0.45rem;
    }

    .insights__cell-policy {
        display: none;
    }

    .insights__chart--tall { height: 360px; }
}
