/* Stock & suppliers page (suppliers.html). Generic chart styles: charts.css. Stock statuses use the
   fixed status palette (same as the table pills) and always carry a text label or legend entry;
   supplier identity uses the categorical slots sc-0..sc-4 in fixed order, everyone else is sc-x. */

.st-out { --st: var(--status-critical); }
.st-low { --st: var(--c-orange); }
.st-on_order { --st: var(--c-yellow); }
.st-ok { --st: var(--status-good); }
.sc-0 { --sc: var(--c-blue); }
.sc-1 { --sc: var(--c-aqua); }
.sc-2 { --sc: var(--c-violet); }
.sc-3 { --sc: var(--c-magenta); }
.sc-4 { --sc: var(--c-yellow); }
.sc-x { --sc: var(--muted-2); }

/* Toolbar: the period drives every supplier figure on the page */
.sp-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px 16px; flex-wrap: wrap; margin-bottom: 18px; }
.sp-period { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.sp-period > .icon { width: 16px; height: 16px; color: var(--muted); }
.sp-focus { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600; padding: 4px 6px 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.sp-focus[hidden] { display: none; }
.sp-focus button { border: none; background: none; padding: 2px; color: inherit; display: inline-flex; border-radius: 50%; }
.sp-focus button:hover { background: color-mix(in srgb, var(--accent) 15%, transparent); }
.sp-focus .icon { width: 13px; height: 13px; }

.sp-section { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 26px 2px 12px; }
.sp-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-bottom: 18px; }
.sp-grid > .panel { margin-bottom: 0; min-width: 0; }
@media (max-width: 1000px) { .sp-grid { grid-template-columns: minmax(0, 1fr); } }
.sp-empty { padding: 8px 0; }

/* Legends */
.sp-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; margin-top: 10px; font-size: 12px; color: var(--text-2); }
.sp-legend:empty { display: none; }
.sp-legend > span, .sp-legend > button { display: inline-flex; align-items: center; gap: 6px; }
.sp-legend > button { border: none; background: none; padding: 3px 8px; margin: -3px -8px; border-radius: 999px; font: inherit; color: inherit; cursor: pointer; }
.sp-legend > button:hover { background: var(--panel-2); }
.sp-legend > button[aria-pressed="true"] { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.sp-legend > button.is-dim { opacity: .45; }
i.sw { width: 10px; height: 10px; border-radius: 50%; background: var(--st, var(--sc, var(--hue, var(--accent)))); display: inline-block; flex: none; }
i.sw.sq { border-radius: 3px; }
i.sw.line { width: 16px; height: 2px; border-radius: 1px; background: var(--text-2); }
i.sw.line.dashed { background: repeating-linear-gradient(90deg, var(--muted-2) 0 4px, transparent 4px 7px); }
i.sw.ring { background: var(--panel); box-shadow: inset 0 0 0 2px var(--muted-2); }
i.sw.is-ext { background: repeating-linear-gradient(135deg, var(--muted-2) 0 2px, transparent 2px 4px); box-shadow: inset 0 0 0 1px var(--muted-2); }
i.sw.ot-low { background: var(--panel); box-shadow: inset 0 0 0 2px var(--status-critical); }

/* Shared marks */
.ca-chart .row-hit { fill: transparent; cursor: pointer; }
.ca-chart .row-hit:hover { fill: color-mix(in srgb, var(--text) 4%, transparent); }
.ca-chart .row-label { fill: var(--text-2); font-size: 12px; font-family: var(--font-sans); }
.ca-chart .row-value { fill: var(--text); font-size: 11.5px; font-weight: 600; font-family: var(--font-sans); font-variant-numeric: tabular-nums; }
.ca-chart .row-value .muted { fill: var(--muted); font-weight: 500; }
.ca-chart .quad-line { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 4; }
.ca-chart .quad-label { fill: var(--muted); font-size: 10.5px; font-weight: 600; font-family: var(--font-sans); text-transform: uppercase; letter-spacing: .04em; }
.ca-chart .zero-line { stroke: var(--border-strong); }
.ca-chart .is-dim { opacity: .18; }
.ca-chart [data-sup] { cursor: pointer; }
.ca-chart .st-mark { fill: var(--st); }

/* 1. Stock health donut */
.sp-health { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.sp-donut-wrap { flex: none; margin: 0 auto; }
.sp-donut { width: 180px; overflow: visible; }
.sp-donut .donut-track { fill: none; stroke: var(--panel-2); stroke-width: 24; }
.sp-donut .donut-seg { fill: none; stroke: var(--st); stroke-width: 24; cursor: pointer; transition: opacity var(--t-fast) var(--ease), stroke-width var(--t-fast) var(--ease); }
.sp-donut .donut-seg.is-hover { opacity: 1; stroke-width: 28; }
.sp-donut .donut-value { fill: var(--text); font-size: 20px; font-weight: 700; font-family: var(--font-sans); font-variant-numeric: tabular-nums; }
.sp-donut .donut-sub { fill: var(--muted); font-size: 11px; font-family: var(--font-sans); }
.sp-donut-legend { flex: 1 1 200px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.sp-legend-item {
  display: grid; grid-template-columns: 10px minmax(0, 1fr) auto 38px; align-items: center; gap: 10px;
  border: 1px solid transparent; background: none; border-radius: var(--radius-sm); padding: 7px 10px;
  font: inherit; font-size: 13px; color: var(--text); text-align: start; cursor: pointer;
}
.sp-legend-item:hover { background: var(--panel-2); }
.sp-legend-item.is-on { background: color-mix(in srgb, var(--st) 10%, var(--panel)); border-color: color-mix(in srgb, var(--st) 45%, var(--border)); }
.sp-legend-item .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-legend-item strong { font-variant-numeric: tabular-nums; }
.sp-legend-item .muted { font-size: 12px; text-align: end; font-variant-numeric: tabular-nums; }

/* 3. Runway: days left (solid) + extra days from stock on order (hatched) */
.ca-chart .ext { fill: color-mix(in srgb, var(--st) 22%, transparent); stroke: var(--st); stroke-width: 1; stroke-dasharray: 3 2; }

/* 4. Stock in and out */
.ca-chart .f-in { fill: var(--c-blue); }
.ca-chart .f-out { fill: var(--c-aqua); }
.ca-chart .f-net { fill: none; stroke: var(--text-2); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; pointer-events: none; }
.ca-chart .f-net-dot { fill: var(--text-2); stroke: var(--panel); stroke-width: 2; pointer-events: none; }

/* 5. Purchasing by month + on-time strip */
.ca-chart .seg { fill: var(--sc); }
#ch-ontime { margin-top: 6px; }
.ca-chart .strip-title { fill: var(--text-2); font-size: 11.5px; font-weight: 600; font-family: var(--font-sans); }
.ca-chart .ot-line { fill: none; stroke: var(--text-2); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.ca-chart .ot-dot { fill: var(--text-2); stroke: var(--panel); stroke-width: 2; }
.ca-chart .ot-dot.is-low { fill: var(--panel); stroke: var(--status-critical); }

/* 6. Scorecard scatter */
.ca-chart .bubble { fill: color-mix(in srgb, var(--sc) 78%, transparent); stroke: var(--panel); stroke-width: 2; }
.ca-chart .bubble.is-hover, .ca-chart .bubble.is-focus { opacity: 1; stroke: var(--text); stroke-width: 2; }
.ca-chart .pt-label { fill: var(--text); font-size: 11px; font-weight: 600; font-family: var(--font-sans); paint-order: stroke; stroke: var(--panel); stroke-width: 3px; stroke-linejoin: round; pointer-events: none; }

/* 7. Lead time dumbbell */
.ca-chart .lead-gap { stroke: var(--muted-2); stroke-width: 2; }
.ca-chart .lead-gap.is-slower { stroke: var(--status-critical); }
.ca-chart .lead-gap.is-faster { stroke: var(--status-good); }
.ca-chart .q-dot { fill: var(--panel); stroke: var(--muted-2); stroke-width: 2; }
.ca-chart .a-dot { fill: var(--hue, var(--accent)); stroke: var(--panel); stroke-width: 2; }
.ca-chart .a-dot.is-slower { fill: var(--status-critical); }
.ca-chart .a-dot.is-faster { fill: var(--status-good); }
.ca-chart .lead-row.is-dim { opacity: .3; }

/* 8. Purchase-order pipeline (HTML flow diagram) */
.pl-draft { --st: var(--muted-2); }
.pl-ordered { --st: var(--c-blue); }
.pl-partially_received { --st: var(--c-yellow); }
.pl-received { --st: var(--status-good); }
.pl-cancelled { --st: var(--status-critical); }
.sp-pipe { display: flex; flex-direction: column; align-items: stretch; }
.sp-node {
  border: 1px solid var(--border); border-inline-start: 4px solid var(--st); border-radius: var(--radius-sm);
  background: var(--panel); padding: 9px 12px 10px; display: flex; flex-direction: column; gap: 6px; outline: none;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.sp-node:hover, .sp-node:focus-visible { border-color: color-mix(in srgb, var(--st) 55%, var(--border)); box-shadow: var(--shadow-sm); }
.sp-node.is-zero { opacity: .55; }
.sp-node-head { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.sp-node-head .status-pill { margin-inline-start: auto; font-size: 11px; }
.sp-node-figs { display: flex; align-items: baseline; gap: 10px; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.sp-node-figs strong { font-size: 18px; color: var(--text); }
.sp-node-figs .muted { margin-inline-start: auto; }
.sp-node-bar { display: block; height: 5px; border-radius: 3px; background: var(--panel-2); overflow: hidden; }
.sp-node-bar i { display: block; height: 100%; border-radius: 3px; background: var(--st); }
.sp-arrow { align-self: center; width: 2px; height: 16px; background: var(--border-strong); position: relative; margin: 2px 0 6px; }
.sp-arrow::after { content: ""; position: absolute; left: 50%; bottom: -5px; transform: translateX(-50%); border: 5px solid transparent; border-top-color: var(--border-strong); border-bottom: 0; }
.sp-branch { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--border-strong); display: flex; flex-direction: column; gap: 8px; }
.sp-branch-label { font-size: 11.5px; color: var(--muted); }

/* 9. Spend flow (Sankey) */
.ca-chart .sk-link { fill: var(--sc); opacity: .32; transition: opacity var(--t-fast) var(--ease); }
.ca-chart .sk-link.is-hover { opacity: .6; }
.ca-chart .sk-link.is-dim { opacity: .07; }
.ca-chart .sk-node { fill: var(--sc); }
.ca-chart .sk-node.sk-cat { fill: var(--text-2); }

/* Supplier table: identity swatch next to the key suppliers */
.sp-sup-cell { display: flex; align-items: flex-start; gap: 8px; }
.sp-sup-cell i.sw { margin-top: 4px; }

/* Stock table: scrolls inside the panel so the supplier charts stay close */
#tbl-stock .table-scroll { max-height: 560px; overflow-y: auto; }
#tbl-stock thead th { position: sticky; top: 0; z-index: 1; }
#status-chips .chip.active .muted { color: inherit; opacity: .8; }
#panel-health { display: flex; flex-direction: column; }
#panel-health .sp-health { flex: 1; }

/* RTL: chart coordinates are LTR, so anchors keep their meaning; each label still lays out by its own script. */
.ca-chart { direction: ltr; }
.ca-chart text { unicode-bidi: plaintext; }
.sp-legend > span, .sp-legend > button, .sp-focus { unicode-bidi: plaintext; }
