/* ══════════════════════════════════════════════
   MINIMUMS DIRECTORY (Head Office → Seuils)
   Every class is prefixed .thr- ; colours, radii and type come from style.css tokens.
   Blue = interaction and change markers. Sienna/amber appear only for errors.
══════════════════════════════════════════════ */
.thr { margin-top: 16px; --thr-row-h: 40px; --thr-first-w: 272px; --thr-col-w: 84px; }

/* ── Top row: view switcher + month navigator ── */
.thr-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px; margin-bottom: 16px; }
.thr-views { flex: 0 1 auto; }
.thr-views .segmented__opt { flex: 0 1 auto; }
.thr-months { display: inline-flex; align-items: center; gap: 6px; }
.thr-months[hidden] { display: none; }
.thr-nav-btn.btn-icon { width: 38px; height: 38px; }
.thr-month-select { width: auto; min-width: 178px; height: 38px; font-weight: 500; }
.thr-today { height: 38px; padding: 0 14px; }

/* ── Intro, toolbar, summary ── */
.thr-intro { max-width: 72ch; margin: 0 0 14px; color: var(--text-muted); font-size: var(--fs-sm); }
.thr-controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; margin-bottom: 12px; }
.thr-controls .field { margin-bottom: 0; }
.thr-controls .input, .thr-controls .select { height: 40px; }
.thr-controls__spacer { flex: 1 1 auto; }
.thr-field { flex: 0 1 220px; min-width: 170px; }
.thr-field--grow { flex: 1 1 260px; max-width: 420px; }
.thr-search { position: relative; flex: 1 1 260px; min-width: 200px; max-width: 420px; }
.thr-search .input { padding-left: 40px; }
.thr-search__icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); display: flex; color: var(--text-faint); pointer-events: none; }
.thr-select { flex: 0 1 230px; min-width: 170px; }
.thr-switch { display: inline-flex; align-items: center; gap: 10px; min-height: 40px; padding: 0 4px; cursor: pointer; font-size: var(--fs-sm); font-weight: 500; }
.thr-switch input { width: 18px; height: 18px; margin: 0; flex-shrink: 0; accent-color: var(--accent); }

.thr-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; min-height: 22px; margin: 0 0 10px; color: var(--text-muted); font-size: var(--fs-sm); }
.thr-summary strong { color: var(--text); font-weight: 500; }
.thr-key { display: inline-flex; align-items: center; gap: 4px; margin-left: auto; }
.thr-key .icon { color: var(--blue); }

.thr-panel { position: relative; }
.thr-panel.is-busy { opacity: 0.55; pointer-events: none; transition: opacity var(--dur) var(--ease); }
.thr-skel { padding: 20px; }
.thr-banner-sub { display: block; margin-top: 2px; font-size: var(--fs-sm); font-weight: 400; }
.thr-notice { margin-bottom: 12px; }
.thr-notice .result-banner__text small { display: block; margin-top: 2px; font-size: var(--fs-sm); font-weight: 400; }

/* ── Tables: scroll area, sticky header row, sticky first column ── */
.thr-scroll {
  position: relative; overflow: auto; background: var(--surface);
  max-height: max(320px, calc(100dvh - 300px));
  scroll-padding: 46px 0 0 var(--thr-first-w);
}
.thr-scroll--short { max-height: none; scroll-padding: 0; }
.thr-scroll .empty-state { padding: 36px 24px; }
.thr-table { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-sm); }
.thr-table th, .thr-table td { padding: 0; border-bottom: 1px solid var(--border); background: var(--surface); text-align: left; font-weight: 400; vertical-align: middle; }
.thr-table thead th {
  position: sticky; top: 0; z-index: 3; padding: 10px 12px; vertical-align: bottom;
  color: var(--text-muted); font-size: 0.6875rem; font-weight: 500; line-height: 1.25;
  text-transform: uppercase; letter-spacing: 0.03em; white-space: normal;
}
.thr-table thead th.thr-colhead { min-width: var(--thr-col-w); max-width: 108px; text-align: right; overflow-wrap: normal; }
.thr-table thead th.thr-corner { left: 0; z-index: 4; min-width: var(--thr-first-w); box-shadow: 1px 0 0 var(--border); }
.thr-table .thr-item {
  position: sticky; left: 0; z-index: 2; height: var(--thr-row-h);
  min-width: var(--thr-first-w); max-width: var(--thr-first-w); width: var(--thr-first-w);
  padding: 0 12px; box-shadow: 1px 0 0 var(--border);
}
.thr-item__in { display: flex; align-items: baseline; gap: 8px; width: calc(var(--thr-first-w) - 24px); overflow: hidden; white-space: nowrap; }
.thr-item__name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.thr-item__btn { display: flex; align-items: center; width: 100%; height: var(--thr-row-h); text-align: left; border-radius: 0; }
.thr-row[hidden] { display: none; }
.thr-row:hover > th, .thr-row:hover > td { background: var(--surface-2); }
.thr-row:hover > td.is-chg { background: var(--blue-tint); }
.thr-row--click { cursor: pointer; }

/* category bands */
.thr-band > td { padding: 0; background: var(--surface-2); }
.thr-band__btn, .thr-band__label {
  position: sticky; left: 0; display: inline-flex; align-items: center; gap: 8px;
  min-height: 38px; padding: 0 12px; color: var(--text); font-size: var(--fs-sm); font-weight: 500; letter-spacing: 0.01em;
}
.thr-band__btn .icon { color: var(--text-muted); transition: transform var(--dur) var(--ease); }
.thr-band__btn[aria-expanded="false"] .icon { transform: rotate(-90deg); }
.thr-band__count { color: var(--text-muted); font-weight: 400; }

/* ── Matrix cells ── */
.thr-c { min-width: var(--thr-col-w); height: var(--thr-row-h); text-align: right; font-variant-numeric: tabular-nums; }
.thr-c.is-chg { background: var(--blue-tint); }
.thr-cell {
  display: flex; align-items: center; justify-content: flex-end; gap: 5px;
  width: 100%; height: var(--thr-row-h); padding: 0 12px; border-radius: 0;
  color: var(--text); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; text-align: right;
}
.thr-cell:hover { background: var(--blue-tint); }
.thr-cell:focus-visible { outline: 2.5px solid var(--focus-ring); outline-offset: -3px; border-radius: 6px; }
.thr-cell .icon, .thr-arrow-ic { color: var(--blue); }
.thr-abs { color: var(--text-muted); font-style: italic; }
.thr-dash { color: var(--text-muted); }

/* ── By clinic table ── */
.thr-ctab .thr-t-num { text-align: right; font-variant-numeric: tabular-nums; }
.thr-ctab td { padding: 0 12px; height: 46px; }
.thr-ctab .thr-item, .thr-ctab .thr-item__btn { height: 46px; }
.thr-ctab thead th.thr-th-num { text-align: right; }
.thr-fmt { max-width: 200px; padding-top: 6px; padding-bottom: 6px; color: var(--text-muted); font-size: var(--fs-xs); line-height: 1.3; }
.thr-minval { display: inline-flex; align-items: center; justify-content: flex-end; gap: 5px; font-weight: 500; }
.thr-spark { display: block; width: 120px; height: 28px; }
.thr-spark__line { fill: none; stroke: var(--blue); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.thr-spark__dot { fill: var(--blue); stroke: var(--surface); stroke-width: 2; }
.thr-spark--empty .thr-spark__line { stroke: var(--border-strong); stroke-dasharray: 2 4; }
.thr-count {
  display: inline-flex; align-items: center; justify-content: center; min-width: 26px; height: 22px; padding: 0 8px;
  border-radius: var(--radius-pill); background: var(--blue-tint); color: var(--blue-dark);
  font-size: var(--fs-xs); font-weight: 500; font-variant-numeric: tabular-nums;
}
.thr-count--zero { background: transparent; color: var(--text-muted); font-weight: 400; }

/* ── By item: picker, header, supplier SKUs ── */
.thr-picker { max-width: 520px; margin-bottom: 14px; }
.thr-picker__box { position: relative; }
.thr-picker__box .input { padding-left: 40px; }
.thr-picker__list {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); max-height: 340px; overflow-y: auto;
  margin: 0; padding: 4px; background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
}
.thr-picker__list[hidden] { display: none; }
.thr-opt { display: flex; align-items: baseline; gap: 10px; padding: 10px 12px; border-radius: 6px; font-size: var(--fs-sm); cursor: pointer; }
.thr-opt:hover, .thr-opt[aria-selected="true"] { background: var(--blue-tint); }
.thr-opt__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thr-opt__cat { flex-shrink: 0; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); font-size: var(--fs-xs); }
.thr-picker__none { padding: 12px; color: var(--text-muted); font-size: var(--fs-sm); }

.thr-head { margin-bottom: 14px; }
.thr-head__title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.thr-head__code { font-size: var(--fs-lg); }
.thr-head__name { font-size: var(--fs-md); font-weight: 500; overflow-wrap: anywhere; }
.thr-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 24px; margin: 14px 0 0; }
.thr-facts dt { margin: 0 0 2px; color: var(--text-muted); font-size: var(--fs-xs); font-weight: 500; text-transform: uppercase; letter-spacing: 0.03em; }
.thr-facts dd { margin: 0; font-size: var(--fs-sm); overflow-wrap: anywhere; }
.thr-skus { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.thr-skus__label { margin-bottom: 4px; color: var(--text-muted); font-size: var(--fs-xs); font-weight: 500; text-transform: uppercase; letter-spacing: 0.03em; }
.thr-skus__list { font-size: var(--fs-sm); line-height: 1.65; overflow-wrap: anywhere; }
.thr-skus__skel { display: inline-block; width: min(320px, 70%); height: 14px; vertical-align: middle; }
.thr-skug strong { font-weight: 500; }
.thr-sku { font-variant-numeric: tabular-nums; }
.thr-skus__sep { margin: 0 8px; color: var(--text-faint); }

/* ── Chart card: chips, SVG, tooltip, month table ── */
.thr-chartcard { margin-bottom: 14px; }
.thr-chartcard__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 12px; margin-bottom: 10px; }
.thr-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 12px; }
.thr-chip {
  display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 12px 0 10px;
  border: 1.5px solid var(--border-strong); border-radius: var(--radius-pill); background: var(--surface);
  color: var(--text); font-size: var(--fs-sm);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.thr-chip:hover { border-color: var(--accent); }
.thr-chip__key { display: inline-flex; flex-shrink: 0; }
.thr-chip__val { font-weight: 500; font-variant-numeric: tabular-nums; }
.thr-chip[aria-pressed="false"] { background: var(--surface-2); border-color: transparent; color: var(--text-muted); }
.thr-chip[aria-pressed="false"] .thr-chip__name { text-decoration: line-through; }
.thr-chip[aria-pressed="false"] .thr-chip__key svg { opacity: 0.35; }
.thr-note { margin: 8px 0 0; color: var(--text-muted); font-size: var(--fs-xs); }

.thr-chart-host { width: 100%; min-height: 180px; }
.thr-chart-wrap { position: relative; touch-action: pan-y; border-radius: var(--radius-sm); }
.thr-chart { display: block; width: 100%; height: auto; user-select: none; -webkit-user-select: none; }
.thr-chart text { fill: var(--text-muted); font-family: var(--font-body); font-size: 11px; }
.thr-chart .thr-xtick--sel { fill: var(--text); font-weight: 500; }
.thr-chart .thr-grid { stroke: var(--border); stroke-width: 1; }
.thr-chart .thr-grid--base { stroke: var(--border-strong); }
.thr-chart .thr-selband { fill: var(--blue-tint); }
.thr-chart .thr-nodata { fill: var(--surface-2); }
.thr-chart .thr-nodata-label, .thr-chart .thr-empty-msg { text-anchor: middle; font-style: italic; }
.thr-chart .thr-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.thr-chart .thr-xhair { stroke: var(--text-faint); stroke-width: 1; }
.thr-tip {
  position: absolute; z-index: 6; min-width: 160px; max-width: 280px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); font-size: var(--fs-sm); pointer-events: none;
}
.thr-tip[hidden] { display: none; }
.thr-tip__head { margin-bottom: 6px; font-weight: 500; }
.thr-tip__row { display: flex; align-items: center; gap: 8px; padding: 1px 0; }
.thr-tip__key { display: inline-flex; flex-shrink: 0; }
.thr-tip__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); }
.thr-tip__val { font-weight: 500; font-variant-numeric: tabular-nums; color: var(--text); }

.thr-mtab td, .thr-mtab th { white-space: nowrap; }
.thr-mtab thead th.thr-mh { min-width: 64px; padding: 8px 10px; text-align: right; }
.thr-mh span { display: block; }
.thr-mh__y { font-weight: 400; opacity: 0.8; }
.thr-mtab td.thr-v { height: 40px; padding: 0 10px; text-align: right; font-variant-numeric: tabular-nums; }
.thr-v-in { display: inline-flex; align-items: center; justify-content: flex-end; gap: 4px; }
.thr-mtab td.is-sel, .thr-mtab thead th.is-sel { background: var(--blue-tint); }
.thr-mtab thead th.is-sel { color: var(--blue-dark); }
.thr-mtab td.thr-nd { background: var(--surface-2); }
.thr-mtab .thr-item { width: auto; min-width: 150px; max-width: 220px; }
.thr-clinicname { display: flex; align-items: center; gap: 8px; width: auto; }
.thr-clinicname span:last-child { overflow: hidden; text-overflow: ellipsis; }

/* ── History ── */
.thr-htab thead th { position: static; }
.thr-htab td { padding: 12px 14px; vertical-align: top; }
.thr-htab .thr-hdate { white-space: nowrap; color: var(--text-muted); }
.thr-htab .thr-hchange { white-space: nowrap; font-variant-numeric: tabular-nums; }
.thr-htab .thr-hitem { min-width: 190px; max-width: 320px; }
.thr-hitem__name { display: block; color: var(--text-muted); font-size: var(--fs-xs); overflow-wrap: anywhere; }
.thr-htab .thr-hreason { min-width: 180px; max-width: 340px; white-space: pre-wrap; overflow-wrap: anywhere; }
.thr-from { color: var(--text-muted); }
.thr-to { font-weight: 500; }
.thr-to-arrow { margin: 0 6px; color: var(--text-faint); }
.thr-delta {
  display: inline-flex; align-items: center; gap: 2px; margin-left: 8px; padding: 1px 8px 1px 6px;
  border-radius: var(--radius-pill); background: var(--blue-tint); color: var(--blue-dark);
  font-size: var(--fs-xs); font-weight: 500;
}
.thr-req { margin-top: 6px; }
.thr-more { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 14px; color: var(--text-muted); font-size: var(--fs-sm); }

/* ── Detail modal ── */
.thr-m__item { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 0 0 12px; }
.thr-m__itemname { font-weight: 500; overflow-wrap: anywhere; }
.thr-m__tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.thr-tile { padding: 12px 14px; gap: 4px; }
.thr-tile .stat-tile__value { font-size: var(--fs-2xl); line-height: 1.1; }
.thr-tile__text { font-size: var(--fs-base); font-weight: 500; overflow-wrap: anywhere; }
.thr-tile__text--muted { color: var(--text-muted); font-weight: 400; }
.thr-m__skus { margin: 0 0 16px; padding: 0 0 14px; border-bottom: 1px solid var(--border); }
.thr-m__grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(250px, 1fr); gap: 18px; align-items: start; margin-bottom: 18px; }
.thr-m__grid--solo { grid-template-columns: minmax(0, 1fr); }
.thr-m__title { margin: 0 0 8px; font-size: var(--fs-base); font-weight: 500; }
.thr-m__go { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.thr-form { padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.thr-form__hint { margin: 0 0 12px; color: var(--text-muted); font-size: var(--fs-sm); }
.thr-form .field { margin-bottom: 14px; }
.thr-form .input[aria-invalid="true"] { border-color: var(--danger-text); }
.thr-form .input:disabled { background: var(--surface-2); color: var(--text-faint); cursor: not-allowed; }
.thr-check { display: flex; align-items: flex-start; gap: 10px; margin: 0 0 14px; font-size: var(--fs-sm); line-height: 1.4; cursor: pointer; }
.thr-check input { width: 18px; height: 18px; margin: 1px 0 0; flex-shrink: 0; accent-color: var(--accent); }
.thr-error { min-height: 1.2em; color: var(--danger-text); font-size: var(--fs-sm); font-weight: 500; }
.thr-form .modal__actions { margin-top: 6px; }
.thr-m__log .thr-htab .thr-hreason { min-width: 160px; }
.thr-m__log .table-wrap { border-radius: var(--radius-sm); }
.thr-m__log .empty-state { padding: 22px 16px; }

/* ── Responsive ── */
@media (max-width: 899px) {
  .thr-scroll { max-height: calc(100dvh - 150px); }
}
@media (max-width: 719px) {
  .thr { --thr-first-w: 150px; --thr-row-h: 48px; }
  .thr-item__in { flex-direction: column; align-items: flex-start; gap: 0; justify-content: center; height: 100%; }
  .thr-item__name { width: 100%; color: var(--text-muted); font-size: var(--fs-xs); }
  .thr-m__grid { grid-template-columns: minmax(0, 1fr); }
  .thr-ctab .thr-item, .thr-ctab .thr-item__btn { height: 52px; }
  .thr-ctab td { height: 52px; }
  .thr-mtab .thr-item { min-width: 120px; max-width: 150px; }
  .thr-key { margin-left: 0; }
}
@media (max-width: 640px) {
  .thr-views { flex: 1 1 100%; }
  .thr-views .segmented__opt { flex: 1 1 calc(50% - 4px); min-width: 0; padding: 0 8px; }
  .thr-months { width: 100%; }
  .thr-month-select { flex: 1 1 auto; min-width: 0; }
  .thr-search, .thr-select, .thr-field, .thr-field--grow { flex: 1 1 100%; max-width: none; }
  .thr-controls__spacer { display: none; }
  .thr-picker { max-width: none; }

  /* history rows become cards on a phone */
  .thr-htab, .thr-htab tbody, .thr-htab tr, .thr-htab td { display: block; width: 100%; }
  .thr-htab thead { display: none; }
  .thr-htab { min-width: 0; width: 100%; }
  .thr-htab tr { padding: 12px 14px; border-bottom: 1px solid var(--border); }
  .thr-htab tr:last-child { border-bottom: 0; }
  .thr-htab td { padding: 3px 0; border: 0; }
  .thr-htab td::before { content: attr(data-label); display: block; color: var(--text-muted); font-size: 0.6875rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.03em; }
  .thr-htab .thr-hitem, .thr-htab .thr-hreason { min-width: 0; max-width: none; }
  .thr-htab .thr-hchange { white-space: normal; }
}
@media (prefers-reduced-motion: reduce) {
  .thr-band__btn .icon, .thr-panel.is-busy { transition: none; }
}
