/* ════════════════════════════════════════════════════════════════════════════
   Inventory analytics (inventory-analytics.js) — Analytics dashboard, Buying plan, item Trends, Reports hub.
   Built on psa.css / inventory.css tokens (--c1…--c8 chart hues, --grid-line, --axis, status tokens), so light
   and dark themes are both selected from the same tokens. Everything is prefixed .ian-.
   ════════════════════════════════════════════════════════════════════════════ */
#tip{white-space:pre-line}                               /* multi-line chart tooltips */

/* ── page bar + filters ──────────────────────────────────────────────────── */
.ian-bar{display:flex;align-items:center;gap:8px;flex-wrap:wrap;width:100%}
.ian-bar .inv-seg,.ian-rbar .inv-seg,.ian-itb .inv-seg{flex-wrap:nowrap;overflow-x:auto;max-width:100%}
.ian-bar .inv-seg button,.ian-itb .inv-seg button{white-space:nowrap}
.ian-bar .sp,.ian-bbar .sp,.ian-rbar .sp,.ian-btb .sp,.ian-itb .sp{flex:1}
.ian-bar select,.ian-bbar select,.ian-rbar select{width:auto;min-width:0;max-width:220px}
.ian-rbar input[type=date]{width:auto}
.ian-per{white-space:nowrap}
.ian-note{font-size:11.5px;color:var(--mut);margin:6px 2px 0;display:flex;align-items:center;gap:6px;flex-wrap:wrap}
.ian-note a{cursor:pointer}

/* ── delta chips + sparklines ────────────────────────────────────────────── */
.ian-dl{display:inline-flex;align-items:center;gap:3px;font-size:11.5px;font-weight:650;padding:0 7px 0 5px;border-radius:999px;line-height:1.7;white-space:nowrap;font-variant-numeric:tabular-nums}
.ian-dl svg{width:12px;height:12px;stroke-width:2.4}
.ian-dl.good{background:var(--ok-bg);color:var(--ok)} .ian-dl.bad{background:var(--bad-bg);color:var(--bad)} .ian-dl.mut{background:var(--surface3);color:var(--ink2)}
.ian-spark{display:block;flex-shrink:0;overflow:visible}

/* ── KPI tiles ───────────────────────────────────────────────────────────── */
.ian-kpis{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));height:100%}
.ian-kpi{padding:6px 14px;border-left:1px solid var(--line-soft);display:flex;flex-direction:column;justify-content:center;gap:3px;min-width:0;cursor:pointer;border-radius:6px}
.ian-kpi:first-child{border-left:0}
.ian-kpi:hover{background:var(--surface2)}
.ian-kpi:focus-visible{outline:2px solid var(--brand);outline-offset:-2px}
.ian-kpi .l{font-size:11.5px;color:var(--mut);font-weight:550;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.ian-kpi .v{font-size:22px;font-weight:650;letter-spacing:-.4px;line-height:1.2;white-space:nowrap;font-variant-numeric:tabular-nums}
.ian-kf{display:flex;align-items:center;justify-content:space-between;gap:6px}

/* ── charts ──────────────────────────────────────────────────────────────── */
.ian-chart{overflow-x:auto;overflow-y:hidden}
.ian-chart svg{display:block;max-width:none}
.ian-tk{font-size:10px;fill:var(--mut);font-variant-numeric:tabular-nums}
.ian-x rect{fill:transparent;cursor:crosshair}
.ian-x line{stroke:var(--ink2);stroke-width:1;stroke-dasharray:2 3;opacity:0;pointer-events:none}
.ian-x:hover line{opacity:.55}
.ian-x:hover rect{fill:color-mix(in srgb,var(--ink) 4%,transparent)}
.ian-leg{margin-top:6px}
.legend .sw.dash{background:none;border-top:2px dashed;height:0;width:14px;border-radius:0;align-self:center}
.ian-flowhd{display:flex;align-items:center;gap:8px;margin:0 0 6px}

/* ── ABC × XYZ matrix ────────────────────────────────────────────────────── */
.ian-mx{display:grid;grid-template-columns:minmax(64px,auto) repeat(3,1fr);gap:4px}
.ian-mxh{display:flex;flex-direction:column;align-items:center;justify-content:center;font-size:11px;color:var(--mut);padding:2px}
.ian-mxh b{font-size:13px;color:var(--ink)} .ian-mxh.r{align-items:flex-start}
.ian-mxc{border:0;border-radius:8px;min-height:48px;display:flex;flex-direction:column;align-items:center;justify-content:center;cursor:pointer;
  background:color-mix(in srgb,var(--c1) var(--k),var(--surface2));color:var(--ink);font:inherit}
.ian-mxc b{font-size:18px;font-weight:650;font-variant-numeric:tabular-nums} .ian-mxc span{font-size:10.5px;opacity:.8}
.ian-mxc.hi{color:#fff} :root[data-theme="dark"] .ian-mxc.hi{color:#fff}
.ian-mxc:hover{outline:2px solid var(--brand);outline-offset:1px}

/* ── stock-out risk ──────────────────────────────────────────────────────── */
.ian-risk{display:grid;gap:2px}
.ian-rr{display:grid;grid-template-columns:minmax(120px,1.3fr) 2fr 56px auto;align-items:center;gap:10px;padding:5px 6px;border-radius:6px;cursor:pointer}
.ian-rr:hover{background:var(--surface2)}
.ian-rn{display:flex;flex-direction:column;min-width:0;font-size:12.5px} .ian-rn .trunc{color:var(--mut);font-size:11.5px}
.ian-rb{position:relative;height:10px;background:var(--surface3);border-radius:5px}
.ian-rb i{position:absolute;left:0;top:0;bottom:0;border-radius:5px;background:var(--c1)}
.ian-rb i.warn{background:var(--c4)} .ian-rb i.bad{background:var(--c8)}
.ian-rb b,.ian-mk{position:absolute;top:-3px;bottom:-3px;width:2px;background:var(--ink);border-radius:1px}
.ian-mk{position:relative;display:inline-block;height:12px;top:0}
.ian-rv{text-align:right;font-variant-numeric:tabular-nums;font-weight:600;font-size:12.5px}

/* ── buying summary widget + plan cards ──────────────────────────────────── */
.ian-bsum{display:grid;grid-template-columns:repeat(3,1fr);gap:8px;margin-bottom:8px}
.ian-bsum div{background:var(--surface2);border-radius:8px;padding:7px 10px;min-width:0}
.ian-bsum span{display:block;font-size:11px;color:var(--mut)} .ian-bsum b{font-size:17px;font-variant-numeric:tabular-nums}
.ian-plan{display:grid;grid-template-columns:repeat(auto-fill,minmax(240px,1fr));gap:10px;margin:0 0 12px}
.ian-pc{background:var(--surface);border:1px solid var(--line);border-radius:10px;padding:12px;display:flex;flex-direction:column;gap:8px;box-shadow:var(--shadow-xs);min-width:0}
.ian-pch{display:flex;align-items:center;gap:8px;min-width:0}
.ian-pcm{display:flex;flex-wrap:wrap;gap:4px 12px;font-size:12px;color:var(--mut)} .ian-pcm b{color:var(--ink)}
.ian-pc .btn{align-self:flex-start}

/* ── recommendations table ───────────────────────────────────────────────── */
.ian-btb{flex-wrap:wrap;gap:8px}
.ian-all{display:inline-flex;align-items:center;gap:6px;margin:0!important;font-size:12.5px}
.ian-bt .inv-itc{white-space:normal} .ian-bt td:nth-child(2){min-width:180px;max-width:300px}
.ian-cc{width:28px} .ian-xc{width:34px;text-align:right}
.ian-xb svg{width:15px;height:15px;transition:transform .15s}
.ian-open .ian-xb svg{transform:rotate(90deg)}
.ian-open td{background:var(--surface2)}
.ian-xrow>td{background:var(--surface2);padding:4px 14px 16px!important}
.ian-lv{display:inline-flex;align-items:center;gap:4px;white-space:nowrap}
.ian-lv svg{width:11px;height:11px;color:var(--mut2)}
.ian-la{display:inline-flex;border-radius:4px;padding:1px}
.ian-la svg{width:12px;height:12px;color:inherit;stroke-width:2.4}
.ian-la.increase,.ian-la.set{background:var(--warn-bg);color:var(--warn)} .ian-la.decrease{background:var(--inv-q-bg);color:var(--inv-q)}

/* ── detail panes (buying row, item trends) ─────────────────────────────── */
.ian-xd{display:grid;grid-template-columns:minmax(0,1.15fr) minmax(0,1fr);gap:18px;margin-top:12px}
.ian-xh{font-size:11px;font-weight:700;text-transform:uppercase;letter-spacing:.5px;color:var(--mut);margin:0 0 6px;display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.ian-xm{text-transform:none;letter-spacing:0;font-weight:600;color:var(--ink2);font-size:12px}
.ian-xw{position:sticky;left:14px;max-width:100%}
.ian-calc{display:grid;grid-template-columns:repeat(auto-fill,minmax(120px,1fr));gap:6px}
.ian-calc div{background:var(--surface);border:1px solid var(--line-soft);border-radius:8px;padding:6px 9px;min-width:0}
.ian-calc span{display:block;font-size:10.5px;color:var(--mut);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.ian-calc b{font-size:14px;font-variant-numeric:tabular-nums;display:inline-flex;align-items:center;gap:3px}
.ian-calc b svg{width:13px;height:13px}
.ian-why{margin:10px 0;padding-left:18px;font-size:12.5px;color:var(--ink2);display:grid;gap:4px}
.ian-it .ian-itb{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-bottom:8px}
.ian-it .ian-itb .chk{margin:0!important}
.ian-itk{margin-top:10px}
.ian-rec{width:100%;font-size:12.5px} .ian-rec td,.ian-rec th{padding:5px 8px}
.ian-rs{font-size:12px;color:var(--mut);margin-top:8px}
.ian-rs b{color:var(--ink)}
.drawer.wide .ian-xd,.ian-xd.one{grid-template-columns:1fr}

/* ── consumers table ─────────────────────────────────────────────────────── */
.ian-ct td{vertical-align:middle}
.ian-cn{font-weight:550;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:260px}
.ian-cb{height:4px;background:var(--surface3);border-radius:2px;margin-top:4px;max-width:260px}
.ian-cb i{display:block;height:100%;border-radius:2px;background:var(--c1)}

/* ── reports hub ─────────────────────────────────────────────────────────── */
.ian-grp{margin:0 0 20px}
.ian-gh{display:flex;align-items:center;gap:8px;font-size:13px;font-weight:700;text-transform:uppercase;letter-spacing:.5px;color:var(--ink2);margin:0 0 10px}
.ian-gh svg{width:16px;height:16px;color:var(--mut)} .ian-gh .muted{font-weight:500}
.ian-new{margin-left:auto;font-size:10.5px;font-weight:650;padding:1px 7px;border-radius:999px;background:var(--inv-q-bg);color:var(--inv-q)}
.ian-sd{display:flex;gap:6px;margin-top:3px;align-items:center;flex-wrap:wrap}
.ian-sd small{font-size:10.5px;color:var(--mut)}
td.ian-long{max-width:340px}
.ian-sched{display:grid;grid-template-columns:repeat(auto-fit,minmax(120px,1fr));gap:8px;margin-bottom:8px}
.ian-sched [hidden]{display:none}
.ian-sgrid{display:grid;grid-template-columns:repeat(auto-fit,minmax(170px,1fr));gap:4px 12px}

/* ── small screens (390 px) ──────────────────────────────────────────────── */
@media (max-width:720px){
  .ian-xd{grid-template-columns:1fr}
  .ian-rr{grid-template-columns:minmax(0,1fr) 44px auto;grid-template-areas:"n v u" "b b b";row-gap:4px}
  .ian-rn{grid-area:n} .ian-rb{grid-area:b} .ian-rv{grid-area:v} .ian-ru{grid-area:u}
  .ian-kpis{grid-template-columns:repeat(2,minmax(0,1fr))}
  .ian-kpi{border-left:0;border-top:1px solid var(--line-soft);padding:6px 8px}
  .ian-kpi .v{font-size:19px}
  .ian-bar select,.ian-bbar select,.ian-rbar select{max-width:none;flex:1 1 140px}
  .ian-bar .inv-seg,.ian-rbar .inv-seg{overflow-x:auto;max-width:100%}
  .ian-per{display:none}
  .ian-bsum b{font-size:15px}
  .ian-ct .hide-sm,.ian-bt .hide-sm,.ian-bar .hide-sm,.ian-it .hide-sm{display:none}
}
