/* ==========================================================================
   kh-tools.css — decision tools (hub + tool pages). Tokens only; no hex.
   ========================================================================== */

/* --- hub ----------------------------------------------------------------- */
.kh-tools-hub__toolbar { margin-bottom: var(--sp-3); }
.kh-tools-hub__chips { margin-bottom: var(--sp-5); }
.kh-tools-hub__chips .kh-chip { text-decoration: none; }
.kh-tools-hub__chips .kh-chip span { font-variant-numeric: tabular-nums; opacity: 0.7; }
.kh-tools-hub__group + .kh-tools-hub__group { margin-top: var(--sp-5); }
.kh-tools-hub__title { font-size: var(--fs-h3); margin-bottom: var(--sp-3); color: var(--text-2); }
.kh-tools-hub__nearest { list-style: none; padding: 0; margin: var(--sp-3) 0 0; text-align: start; display: grid; gap: 0.5rem; }

.kh-tool-cards { margin-top: var(--sp-2); }
.kh-tool-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color var(--dur-fast) var(--ease);
}
.kh-tool-card:hover, .kh-tool-card:focus-within { border-color: var(--accent); }
.kh-tool-card__link { display: block; color: inherit; text-decoration: none; }
.kh-tool-card__link:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 4px; border-radius: var(--radius-sm); }
.kh-tool-card__title { font-size: 1.05rem; font-weight: 700; line-height: 1.7; margin: 0.35rem 0 0.2rem; }
.kh-tool-card__link:hover .kh-tool-card__title { color: var(--accent); }
.kh-tool-card__question { font-size: var(--fs-small); color: var(--text-2); line-height: 1.8; margin: 0; }
.kh-tool-card__meta { margin: auto 0 0; padding-top: var(--sp-2); font-size: var(--fs-caption); color: var(--text-3); }

/* --- tool page -----------------------------------------------------------
   Order on the page: question, short explanation, «امتحان با نمونه», inputs,
   result and how to read it, next step, then the long explanations closed. */
.kh-tool__head { padding-block-end: var(--sp-4); margin-bottom: 0; }
.kh-tool__question { margin-top: var(--sp-3); max-width: 44rem; font-size: 1.12rem; font-weight: 600; line-height: 1.9; color: var(--text); }
.kh-tool__purpose { margin-top: var(--sp-2); max-width: 44rem; color: var(--text); line-height: 2; text-wrap: pretty; }
.kh-tool__head .kh-page-head__lede { margin-top: var(--sp-2); max-width: 44rem; font-size: var(--fs-small); line-height: 1.95; }
.kh-tool__section { margin-top: var(--sp-5); }
.kh-tool__h2 { font-size: var(--fs-h3); margin-bottom: var(--sp-3); }
.kh-tool__h3 { margin: var(--sp-4) 0 var(--sp-2); font-size: 1rem; font-weight: 700; line-height: 1.8; color: var(--text); }
.kh-tool__h3:first-child { margin-top: 0; }
.kh-tool__prose ul { padding-inline-start: 1.2rem; }
.kh-tool__prose li + li { margin-top: 0.5rem; }

/* «امتحان با نمونه» and the label that stays for as long as sample values are on screen */
.kh-tool__try { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); margin-top: var(--sp-4); }
.kh-tool__try .kh-field__hint { flex: 1 1 15rem; min-width: 0; }
.kh-tool__example {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 1rem;
  margin-top: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  border: 1px dashed var(--accent);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  font-size: var(--fs-small);
  line-height: 1.9;
  scroll-margin-top: 5rem;
}
.kh-tool__example p { margin: 0; flex: 1 1 18rem; min-width: 0; }
.kh-tool__example-label {
  flex: none;
  padding: 0.05rem 0.75rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: var(--fs-caption);
  font-weight: 700;
  line-height: 1.9;
  white-space: nowrap;
}
.kh-tool__example-tag { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; margin: var(--sp-5) 0 0; font-size: var(--fs-small); line-height: 1.9; color: var(--text-2); }
.kh-tool__example-tag + .kh-result-region { margin-top: var(--sp-3); }

.kh-tool__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3) var(--sp-4); margin-top: var(--sp-3); grid-column: 1 / -1; }
.kh-tool__share { margin-top: var(--sp-4); font-size: var(--fs-caption); color: var(--text-3); line-height: 1.8; }
.kh-tool__changelog { white-space: pre-wrap; font: inherit; font-size: var(--fs-caption); color: var(--text-2); margin-top: var(--sp-2); }

/* guide sentences: «این عددها را چطور بخوانم؟», «قدم بعدی», the closed groups */
.kh-tool__list { margin: 0; padding-inline-start: 1.3rem; list-style: disc; font-size: 0.95rem; line-height: 2; color: var(--text); }
.kh-tool__list li + li { margin-top: 0.45rem; }
.kh-tool__list li::marker { color: var(--accent); }
.kh-tool__list--steps { list-style: persian; }
[dir='ltr'] .kh-tool__list--steps { list-style: decimal; }
.kh-tool__list--steps li::marker { font-weight: 700; }
.kh-tool > .kh-tool__reading { margin-top: var(--sp-4); border-inline-start: 3px solid var(--accent); }
.kh-tool__next .kh-tool__list { max-width: 48rem; }

.kh-tool__related { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 0 var(--sp-4); }
.kh-tool__related-link { display: block; padding: 0.75rem 0; border-top: 1px solid var(--border-soft); color: inherit; text-decoration: none; }
.kh-tool__related-link:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: var(--radius-sm); }
.kh-tool__related-title { display: block; font-weight: 600; line-height: 1.8; }
.kh-tool__related-link:hover .kh-tool__related-title, .kh-tool__related-link:focus-visible .kh-tool__related-title { color: var(--accent); }
.kh-tool__related-question { display: block; font-size: var(--fs-caption); color: var(--text-3); line-height: 1.8; }
.kh-tool__related-content { padding-inline-start: 1.3rem; list-style: disc; font-size: 0.95rem; line-height: 2; }
.kh-tool__related-content li::marker { color: var(--accent); }

.kh-tool__more .kh-tool__group { margin-bottom: var(--sp-2); }
.kh-tool__dl { margin: 0; }
.kh-tool__dl-row { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.15rem; padding-block: 0.7rem; border-top: 1px solid var(--border-soft); }
.kh-tool__dl-row:first-child { padding-top: 0; border-top: 0; }
.kh-tool__dl dt { font-size: var(--fs-small); font-weight: 600; line-height: 1.8; color: var(--text); }
.kh-tool__dl dd { margin: 0; font-size: var(--fs-small); line-height: 1.9; color: var(--text-2); }
@media (min-width: 720px) {
  .kh-tool__dl-row { grid-template-columns: minmax(0, 17rem) minmax(0, 1fr); gap: var(--sp-4); }
}
.kh-tool__version .kh-live__note { margin: 0; }

/* a block the tool's own template left empty: no heading over nothing */
.kh-tool__prose:empty { display: none; }
.kh-tool__h3:has(+ .kh-tool__prose:empty) { display: none; }
.kh-tool__group:has(> .kh-disclosure__body > .kh-tool__prose:only-child:empty) { display: none; }

/* --- form ---------------------------------------------------------------- */
.kh-tool-form { display: grid; grid-template-columns: 1fr; gap: 0 var(--sp-4); }
.kh-tool-form__group { grid-column: 1 / -1; min-width: 0; margin: 0 0 var(--sp-4); padding: var(--sp-3) var(--sp-4) 0; border: 1px solid var(--border-soft); border-radius: var(--radius); }
.kh-tool-form__group legend { padding: 0 0.5rem; font-weight: 700; font-size: var(--fs-small); color: var(--text); }
.kh-tool-form__grouphint { margin: 0 0 var(--sp-3); }
/* a group that ends with a sentence instead of a field has no field margin to rest on */
.kh-tool-form__group[data-group='mode'], .kh-tool-form__group[data-group='method'], .kh-tool-form__group[data-group='columns'] { padding-bottom: var(--sp-3); }
.kh-tool-form__grid { display: grid; grid-template-columns: 1fr; gap: 0 var(--sp-4); }
.kh-tool-form__unit { grid-column: 1 / -1; margin: 0 0 var(--sp-4); padding: var(--sp-3) var(--sp-4); border: 1px solid var(--border-soft); border-radius: var(--radius); }
.kh-tool-form__unit legend { padding: 0 0.5rem; font-weight: 700; font-size: var(--fs-small); }
.kh-tool-form__radios { display: flex; flex-wrap: wrap; gap: var(--sp-3) var(--sp-4); margin-bottom: 0.5rem; }
.kh-radio { display: inline-flex; align-items: center; gap: 0.5rem; min-height: 44px; cursor: pointer; font-size: var(--fs-small); }
.kh-radio input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
.kh-radio input:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

@media (min-width: 720px) {
  .kh-tool-form__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.kh-field { min-width: 0; }
.kh-field__req { text-decoration: none; color: var(--accent); border: 0; }
.kh-field__hint { margin: 0; font-size: var(--fs-caption); color: var(--text-3); line-height: 1.7; }
.kh-field__hint:empty { display: none; }
.kh-field__error { margin: 0; font-size: var(--fs-caption); font-weight: 600; color: var(--neg); line-height: 1.7; }
.kh-field__error::before { content: '! '; font-family: var(--font-mono); }
.kh-field__error[hidden] { display: none; }
.kh-field.has-error .kh-input, .kh-input[aria-invalid='true'] { border-color: var(--neg); }

.kh-input--num {
  direction: ltr;
  text-align: left;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 1rem;
  letter-spacing: 0.02em;
}
.kh-input:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.kh-input-group { display: flex; align-items: stretch; min-width: 0; }
/* the input is the first flex item (inline-start side); the unit hangs on its inline-end */
.kh-input-group .kh-input { flex: 1; min-width: 0; border-start-end-radius: 0; border-end-end-radius: 0; }
.kh-input-group__unit {
  display: inline-flex; align-items: center;
  padding: 0 0.8rem;
  border: 1px solid var(--border); border-inline-start: 0;
  border-start-end-radius: var(--radius-sm); border-end-end-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-3);
  font-size: var(--fs-caption);
  white-space: nowrap;
}
.kh-input-group__unit:empty { display: none; }
.kh-input-group__unit:empty + .kh-input, .kh-input-group:has(.kh-input-group__unit:empty) .kh-input { border-radius: var(--radius-sm); }

/* --- disclosure ----------------------------------------------------------- */
.kh-disclosure { grid-column: 1 / -1; margin: 0 0 var(--sp-4); border: 1px solid var(--border-soft); border-radius: var(--radius); background: var(--bg-2); }
/* the +/− sits in a hanging indent, so a summary that wraps stays aligned with its first line */
.kh-disclosure > summary { cursor: pointer; padding: var(--sp-3) var(--sp-4); padding-inline-start: calc(var(--sp-4) + 1.2rem); text-indent: -1.2rem; font-weight: 600; font-size: var(--fs-small); line-height: 1.9; list-style: none; }
.kh-disclosure > summary > * { text-indent: 0; }
.kh-disclosure > summary::-webkit-details-marker { display: none; }
.kh-disclosure > summary::before { content: '+'; display: inline-block; width: 1.2rem; text-indent: 0; font-family: var(--font-mono); color: var(--accent); }
.kh-disclosure[open] > summary::before { content: '−'; }
.kh-disclosure > summary:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; border-radius: var(--radius); }
.kh-disclosure > :not(summary) { margin-inline: var(--sp-4); }
.kh-disclosure > .kh-tool-form__group { margin-inline: var(--sp-3); }
.kh-disclosure > ul { padding-block: 0 var(--sp-3); padding-inline-start: 2.2rem; font-size: var(--fs-small); color: var(--text-2); }
.kh-disclosure > ul li + li { margin-top: 0.4rem; }
.kh-disclosure__body { padding-block: 0 var(--sp-4); }
.kh-disclosure__body > .kh-tool__list, .kh-disclosure__body > .kh-tool__prose, .kh-disclosure__body > .kh-tool__dl { max-width: 58rem; }

/* --- result ---------------------------------------------------------------- */
.kh-result-region { margin-top: var(--sp-5); scroll-margin-top: 5rem; }
.kh-result { padding-top: var(--sp-4); border-top: 2px solid var(--accent); }
.kh-result__unit { font-size: var(--fs-caption); color: var(--text-3); margin-bottom: var(--sp-3); }
.kh-result__headline { margin-top: var(--sp-3); }
.kh-result__headline .kh-facts__value { font-size: 1.15rem; font-family: var(--font-mono); }
.kh-result__note { margin-top: var(--sp-3); font-size: var(--fs-small); color: var(--text-2); line-height: 1.8; }
.kh-result__h3 { font-size: 1.02rem; margin-top: var(--sp-5); margin-bottom: var(--sp-2); }
.kh-num { font-variant-numeric: tabular-nums; font-family: var(--font-mono); white-space: nowrap; text-align: end; }
.kh-dash__table .kh-num { text-align: start; }
.kh-dash__table td.is-up, .kh-dash__table .is-up { color: var(--pos); }
.kh-dash__table td.is-down, .kh-dash__table .is-down { color: var(--neg); }
.kh-dash__table tr.is-subtotal td, .kh-dash__table tr.is-total td { font-weight: 700; color: var(--text); border-top: 1px solid var(--border); }
.kh-dash__table tr.is-total td { border-bottom: 2px solid var(--accent); }
.kh-dash__table tr.is-base td, .kh-sens td.is-base { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.kh-dash__table th, .kh-dash__table td { padding-inline: 0.45rem; }
.kh-sens td small { display: block; font-size: 0.72rem; color: var(--text-3); font-weight: 400; }
.kh-sens th[scope='row'] { font-weight: 600; color: var(--text-2); min-width: 7.5rem; }
.kh-sens td.is-up small { color: var(--pos); }
.kh-sens td.is-down small { color: var(--neg); }

.kh-alert--warning { border-inline-start-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.kh-alert[hidden] { display: none; }
.kh-alert p { margin: 0; }

/* a result the live recompute could not refresh (rate limit, offline, invalid
   inputs): the note says so in words; the dimming is only a second cue */
.kh-result-region.is-stale > .kh-result { opacity: 0.55; }
.kh-result__stale { margin-bottom: var(--sp-3); }

.kh-result__breakdown { margin: 0; }
.kh-result__bar { display: block; width: 100%; height: 22px; border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-2); }
.kh-result__seg--a { fill: var(--series-a); background: var(--series-a); }
.kh-result__seg--b { fill: var(--series-b); background: var(--series-b); }
.kh-result__seg--c { fill: var(--series-c); background: var(--series-c); }
.kh-result__seg--d { fill: var(--series-d); background: var(--series-d); }
.kh-result__seg--e { fill: var(--series-e); background: var(--series-e); }
.kh-result__seg--f { fill: var(--series-f); background: var(--series-f); }
.kh-result__seg--profit { fill: var(--pos); background: var(--pos); }
.kh-result__legend { list-style: none; padding: 0; margin: var(--sp-3) 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0.4rem var(--sp-4); font-size: var(--fs-caption); color: var(--text-2); }
.kh-result__legend b { font-family: var(--font-mono); color: var(--text); margin-inline-start: 0.35rem; }
.kh-result__swatch { display: inline-block; width: 0.8rem; height: 0.8rem; border-radius: 2px; margin-inline-end: 0.45rem; vertical-align: -0.05em; }
.kh-result__assumptions { margin-top: var(--sp-4); }

.kh-tool__download { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); margin-top: var(--sp-4); padding-top: var(--sp-3); border-top: 1px solid var(--border-soft); }
.kh-tool__download .kh-field__hint { flex: 1 1 260px; }

/* keep every table inside the viewport on a phone */
.kh-tool .kh-table-wrap { max-width: 100%; }
.kh-tool .kh-dash__table { min-width: 100%; }
@media (max-width: 480px) {
  .kh-facts { grid-template-columns: 1fr; }
  .kh-tool-form__group, .kh-tool-form__unit { padding-inline: var(--sp-3); }
  .kh-disclosure > :not(summary) { margin-inline: var(--sp-2); }
  .kh-disclosure > summary { padding-inline: calc(var(--sp-3) + 1.2rem) var(--sp-3); }
  .kh-disclosure > .kh-disclosure__body { margin-inline: var(--sp-3); }
  .kh-tool__example { padding-inline: var(--sp-3); }
  .kh-disclosure > .kh-tool-form__group { margin-inline: var(--sp-2); padding-inline: var(--sp-2); }
  .kh-input-group .kh-input--num { padding-inline: 0.75rem; }
  .kh-input-group__unit { padding-inline: 0.6rem; }
}

/* --- rfm (browser-only tool: file drop, column guide, client-rendered result) --- */
.kh-rfm__privacy { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.5rem 0.8rem; margin: 0 0 var(--sp-3); font-size: var(--fs-small); color: var(--text); }
.kh-rfm__drop { margin: 0 0 var(--sp-3); padding: var(--sp-4); border: 2px dashed var(--border); border-radius: var(--radius); background: var(--bg-2); text-align: center; transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease); }
.kh-rfm__drop.is-over, .kh-rfm__drop:focus-within { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--bg-2)); }
.kh-rfm__droplabel { display: block; font-weight: 600; margin-bottom: var(--sp-2); cursor: pointer; }
.kh-rfm__file { display: block; max-width: 100%; margin: 0 auto var(--sp-2); font: inherit; font-size: var(--fs-small); color: var(--text-2); }
.kh-rfm__file:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 4px; }
.kh-rfm__drop .kh-field__hint { text-align: start; }
.kh-rfm__sample { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.8rem; margin: var(--sp-3) 0 0; font-size: var(--fs-small); }
.kh-rfm__linkbtn { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }
.kh-rfm__linkbtn:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 3px; border-radius: 2px; }
.kh-rfm__status { min-height: 1.6em; margin-top: var(--sp-2); }
.kh-rfm__paste textarea { min-height: 8rem; font-family: var(--font-mono); font-size: var(--fs-small); direction: ltr; text-align: left; }
.kh-rfm__paste .kh-btn { margin: var(--sp-2) 0 var(--sp-3); }
.kh-rfm__guide td:first-child { font-family: var(--font-mono); direction: ltr; text-align: end; white-space: nowrap; }
.kh-rfm__guide td:nth-child(3) { font-family: var(--font-mono); direction: ltr; text-align: end; white-space: nowrap; }
.kh-rfm__radios { border: 0; padding: 0; margin: 0; min-width: 0; }
.kh-rfm__radios legend { padding: 0; margin-bottom: 0.3rem; font-weight: 600; font-size: var(--fs-small); }
.kh-rfm__radios .kh-radio { min-height: 40px; }
.kh-rfm__output { grid-column: 1 / -1; }
.kh-rfm__output[hidden] { display: none; }
.kh-rfm__guidance { list-style: none; padding: 0; margin: var(--sp-3) 0 0; display: grid; gap: var(--sp-3); }
.kh-rfm__guide-item { padding: var(--sp-3) var(--sp-4); border: 1px solid var(--border-soft); border-radius: var(--radius); font-size: var(--fs-small); line-height: 1.9; }
.kh-rfm__suggestion { color: var(--text-2); }
.kh-rfm__invalid { margin-top: var(--sp-3); }
.kh-rfm__invalid ul { padding-inline-start: 1.4rem; font-size: var(--fs-caption); color: var(--text-2); }
.kh-rfm__scores td:first-child { font-family: var(--font-mono); direction: ltr; text-align: end; }
.kh-rfm__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); margin-top: var(--sp-4); padding-top: var(--sp-3); border-top: 1px solid var(--border-soft); }
.kh-rfm__actions .kh-field__hint { flex: 1 1 260px; }
@media (min-width: 720px) { .kh-rfm__guidance { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* --- ai-cost: the two ways of entering the model cost, switched by a radio --
   CSS-only enhancement: without :has() support every block simply stays visible.
   A block that holds a validation error is never hidden. In «مستقیم» mode the
   token fields stay visible (optional, for the record) and are only flagged as
   unused; the dated price reference sits outside both blocks, so it is
   reachable in either mode. */
.kh-aicost-choice { margin: 0 0 var(--sp-3); padding: 0; border: 0; min-width: 0; }
.kh-aicost-choice > legend { padding: 0; font-size: var(--fs-caption); font-weight: 600; color: var(--text-2); }
.kh-aicost-choice .kh-tool-form__radios { margin: 0.35rem 0 0; }
.kh-aicost-choice .kh-field__error { margin-top: 0.25rem; }
.kh-aicost-block { padding-top: var(--sp-3); margin-top: var(--sp-2); border-top: 1px dashed var(--border-soft); }
.kh-aicost-block__title { margin: 0 0 var(--sp-2); font-size: var(--fs-caption); font-weight: 600; color: var(--text-2); }
.kh-aicost-block__optional { font-weight: 400; color: var(--text-3); }
.kh-aicost-mode:has(input[name="cost_mode"][value="tokens"]:checked) .kh-aicost-direct:not(:has(.has-error)) { display: none; }
.kh-aicost-mode:has(input[name="cost_mode"][value="tokens"]:checked) .kh-aicost-block__optional { display: none; }
.kh-aicost-ref { margin-top: var(--sp-3); }
.kh-aicost-ref__meta { margin: 0 0 var(--sp-2); font-size: var(--fs-caption); color: var(--text-3); line-height: 1.8; }
.kh-aicost-ref .kh-table-wrap { margin-bottom: var(--sp-3); }
.kh-aicost-ref__vendor { font-size: var(--fs-small); font-weight: 700; margin: var(--sp-3) 0 0.35rem; }
.kh-aicost-ref__none { margin: 0 0 var(--sp-3); font-size: var(--fs-small); color: var(--text-2); }
.kh-aicost-ref__url { direction: ltr; unicode-bidi: isolate; font-family: var(--font-mono); font-size: var(--fs-caption); overflow-wrap: anywhere; }

/* a multiplier such as «× ۱٫۰۹» must not leave the × alone on a line (375px) */
.kh-result__nowrap { white-space: nowrap; }

/* --- sales-growth page ----------------------------------------------------
   (tools/templates/tools/sales-growth.html; every colour is a kh.css token) */
.kh-sg-panel { grid-column: 1 / -1; min-width: 0; }
.kh-sg-panel[hidden] { display: none; }
.kh-segmented { display: inline-flex; flex-wrap: wrap; max-width: 100%; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.kh-segmented__item { position: relative; display: inline-flex; align-items: center; gap: 0.4rem; min-height: 44px; padding: 0 1rem; cursor: pointer; font-size: var(--fs-small); color: var(--text-2); }
.kh-segmented__item + .kh-segmented__item { border-inline-start: 1px solid var(--border); }
.kh-segmented__item input { position: absolute; opacity: 0; width: 0; height: 0; }
.kh-segmented__item:focus-within { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
.kh-segmented__item.is-active, .kh-segmented__item:has(input:checked) { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.kh-segmented__item.is-active::before, .kh-segmented__item:has(input:checked)::before { content: '✓'; font-family: var(--font-mono); }
.kh-sg-mode .kh-field__hint { margin-top: var(--sp-2); }
.kh-sg-grid1 { grid-template-columns: 1fr; }
.kh-sg-csv { font-family: var(--font-mono); font-size: 0.85rem; min-height: 200px; white-space: pre; overflow: auto; }
.kh-sg-file { margin: 0 0 var(--sp-3); }
.kh-sg-file label { display: block; margin-bottom: 0.35rem; font-size: var(--fs-small); font-weight: 600; }
.kh-sg-file__input { padding: 0.55rem 0.75rem; font-size: var(--fs-small); }
.kh-sg-file__input:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.kh-sg-sample { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-4); margin: 0 0 var(--sp-3); font-size: var(--fs-small); }
.kh-sg-guide { margin: 0 0 var(--sp-3); }
.kh-sg-guide .kh-table-wrap { margin: 0 var(--sp-3) var(--sp-3); font-size: var(--fs-caption); }
.kh-sg-guide code { font-family: var(--font-mono); direction: ltr; unicode-bidi: isolate; }
.kh-sg-method .kh-radio { align-items: flex-start; line-height: 1.7; }
.kh-sg-method .kh-radio input { margin-top: 0.45rem; }
.kh-sg-bars { margin: var(--sp-3) 0 0; }
.kh-sg-bars svg { display: block; width: 100%; height: auto; max-height: 160px; background: var(--bg-2); border-radius: var(--radius-sm); }
.kh-sg-bars__axis { stroke: var(--border); stroke-width: 0.3; }
.kh-sg-bars__bar.is-up { fill: var(--pos); }
.kh-sg-bars__bar.is-down { fill: var(--neg); }
.kh-sg-bars__bar.is-flat { fill: var(--text-3); }
.kh-sg-products td:first-child { white-space: normal; min-width: 8rem; }
.kh-sg-flag { color: var(--text-3); font-size: var(--fs-caption); }

/* hub card: topic tag inside the meta line (colour is never the only signal — the group heading repeats it) */
.kh-tool-card__topic { color: var(--accent); font-weight: 600; }

/* ==========================================================================
   Problem paths (hub) and the browser-side tool workspace («lab»).
   Tokens only; charts are plain SVG coloured through the series tokens.
   ========================================================================== */

/* --- hub: paths ---------------------------------------------------------- */
.kh-tools-hub__navlabel { margin: 0 0 var(--sp-2); font-weight: 700; font-size: var(--fs-small); color: var(--text-2); }
.kh-tools-hub__paths { margin-bottom: var(--sp-3); }
.kh-tools-hub__paths .kh-chip, .kh-tools-hub__filters .kh-chip { text-decoration: none; }
.kh-tools-hub__paths .kh-chip span { font-variant-numeric: tabular-nums; opacity: 0.7; }
.kh-tools-hub__filters { margin-bottom: var(--sp-5); }
.kh-tools-hub__filtergroup { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; margin-top: var(--sp-2); }
.kh-tools-hub__filterlabel { font-size: var(--fs-caption); color: var(--text-3); min-width: 6.5rem; }
.kh-chip--sm { font-size: var(--fs-caption); }

.kh-tools-path { padding-top: var(--sp-4); border-top: 1px solid var(--border-soft); }
.kh-tools-path + .kh-tools-path { margin-top: var(--sp-5); }
.kh-tools-path__title { font-size: var(--fs-h3); margin: 0; }
.kh-tools-path__question { margin: 0.35rem 0 var(--sp-3); color: var(--text-2); font-size: var(--fs-small); line-height: 1.9; }
.kh-tools-path__steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; counter-reset: none; }
.kh-tools-path__step {
  display: grid; grid-template-columns: 2rem 1fr auto; align-items: center; gap: 0.35rem 0.75rem;
  padding: 0.7rem var(--sp-3); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.kh-tools-path__step:hover, .kh-tools-path__step:focus-within { border-color: var(--accent); }
.kh-tools-path__n {
  display: grid; place-items: center; width: 1.8rem; height: 1.8rem; border-radius: 50%;
  border: 1px solid var(--accent); color: var(--accent); font-weight: 700; font-size: var(--fs-caption);
}
.kh-tools-path__link { color: inherit; text-decoration: none; min-width: 0; }
.kh-tools-path__link:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 3px; border-radius: var(--radius-sm); }
.kh-tools-path__steptitle { display: block; font-weight: 700; }
.kh-tools-path__link:hover .kh-tools-path__steptitle { color: var(--accent); }
.kh-tools-path__stepq { display: block; font-size: var(--fs-caption); color: var(--text-2); line-height: 1.8; }
.kh-tools-path__where { font-size: var(--fs-caption); color: var(--text-3); white-space: nowrap; }
.kh-tools-path__also { margin: var(--sp-3) 0 var(--sp-2); font-size: var(--fs-caption); color: var(--text-3); }
@media (max-width: 640px) {
  .kh-tools-path__step { grid-template-columns: 2rem 1fr; }
  .kh-tools-path__where { grid-column: 2; }
}

.kh-tool-list { display: grid; gap: var(--sp-3); grid-template-columns: repeat(auto-fill, minmax(min(100%, 17rem), 1fr)); margin-top: var(--sp-2); }
.kh-tool-list--also { margin-top: var(--sp-3); }
.kh-tool-list--also .kh-tools-path__also { grid-column: 1 / -1; margin: 0; }
.kh-tool-card__badges { list-style: none; display: flex; flex-wrap: wrap; gap: 0.35rem; margin: auto 0 0; padding: var(--sp-2) 0 0; }
.kh-tool-card__badges .kh-badge { border-color: var(--border); color: var(--text-2); font-weight: 500; }
.kh-badge--local { border-color: color-mix(in srgb, var(--pos) 55%, transparent) !important; }
.kh-tool__badges { margin-top: var(--sp-3); }
.kh-tool__question--lead { font-size: 1.12rem; line-height: 1.9; }
.kh-tool__resources { margin-top: var(--sp-3); display: flex; flex-wrap: wrap; gap: 0.4rem 0.6rem; align-items: baseline; }

/* --- «you are here» on a path ------------------------------------------- */
.kh-pathstrip { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.3rem 0.6rem; margin-top: var(--sp-3); font-size: var(--fs-caption); color: var(--text-3); }
.kh-pathstrip__label { font-weight: 700; color: var(--text-2); }
.kh-pathstrip__steps { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.3rem; }
.kh-pathstrip__steps li + li::before { content: '←'; margin-inline-end: 0.3rem; color: var(--text-3); }
[dir="ltr"] .kh-pathstrip__steps li + li::before { content: '→'; }
.kh-pathstrip__current { color: var(--text); font-weight: 700; }

/* --- lab workspace ------------------------------------------------------- */
.kh-lab__privacy {
  display: flex; gap: 0.6rem; align-items: baseline; margin-top: var(--sp-4);
  padding: 0.6rem var(--sp-3); border-inline-start: 3px solid var(--pos);
  background: color-mix(in srgb, var(--pos) 6%, transparent); font-size: var(--fs-small); line-height: 1.9;
}
.kh-lab__workspace { margin-top: var(--sp-4); }
.kh-lab__form { display: grid; gap: 0 var(--sp-4); grid-template-columns: 1fr; }
@media (min-width: 720px) { .kh-lab__form--2 { grid-template-columns: 1fr 1fr; } .kh-lab__form--3 { grid-template-columns: repeat(3, 1fr); } }
.kh-lab__form .kh-field { margin-bottom: var(--sp-3); min-width: 0; }
.kh-lab__form .kh-field > label, .kh-lab__label { display: block; font-weight: 600; font-size: var(--fs-small); margin-bottom: 0.35rem; }
.kh-lab__form .kh-field__hint { margin-top: 0.3rem; }
.kh-lab__form .full { grid-column: 1 / -1; }
.kh-lab select.kh-input { appearance: auto; }
.kh-lab .kh-input[data-num] { direction: ltr; text-align: end; font-variant-numeric: tabular-nums; }
[dir="ltr"] .kh-lab .kh-input[data-num] { text-align: start; }
.kh-lab textarea.kh-input { font-family: var(--font-mono); font-size: 0.85rem; direction: ltr; text-align: left; }
.kh-lab textarea.kh-input[dir="rtl"], .kh-lab textarea.kh-input.is-prose { font-family: inherit; font-size: inherit; direction: rtl; text-align: right; }
.kh-lab__source { display: grid; gap: var(--sp-3); }
.kh-lab__drop { padding: var(--sp-3); border: 1px dashed var(--border); border-radius: var(--radius); }
.kh-lab__drop.is-over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, transparent); }
.kh-lab__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); margin: var(--sp-3) 0; }
.kh-lab__linkbtn { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.kh-lab__linkbtn:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.kh-lab__status { min-height: 1.5em; }
.kh-lab__output { margin-top: var(--sp-4); padding-top: var(--sp-4); border-top: 1px solid var(--border); }
.kh-lab__output:focus { outline: none; }
.kh-lab__output h2 { font-size: var(--fs-h3); margin: 0 0 var(--sp-3); }
.kh-lab__output h3 { font-size: 1.02rem; margin: var(--sp-5) 0 var(--sp-2); }
.kh-lab__output p { line-height: 1.95; }
.kh-lab__headline { font-size: 1.08rem; font-weight: 700; line-height: 1.9; margin: 0 0 var(--sp-3); }
.kh-lab__sources li { font-size: var(--fs-small); }
.kh-lab-rows { display: grid; gap: 0.5rem; margin: 0 0 var(--sp-3); }
.kh-lab-row { display: grid; gap: 0.5rem; grid-template-columns: 1fr; align-items: end; padding: 0.6rem; border: 1px solid var(--border-soft); border-radius: var(--radius-sm); }
@media (min-width: 720px) { .kh-lab-row { grid-template-columns: var(--row-cols, 2fr 1fr auto); } }
.kh-lab-row .kh-field { margin: 0; }
.kh-lab-row__remove { align-self: center; }

.kh-num { unicode-bidi: isolate; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* KPI row */
.kh-kpis { display: grid; gap: var(--sp-3); grid-template-columns: repeat(auto-fit, minmax(min(100%, 9rem), 1fr)); margin: 0 0 var(--sp-3); }
.kh-kpi { margin: 0; padding: 0.8rem var(--sp-3); border: 1px solid var(--border-soft); border-radius: var(--radius); background: var(--surface); }
.kh-kpi__label { font-size: var(--fs-caption); color: var(--text-2); }
.kh-kpi__value { margin: 0.25rem 0 0; font-size: 1.35rem; font-weight: 700; line-height: 1.5; }
.kh-kpi__note { margin: 0.2rem 0 0; font-size: var(--fs-caption); color: var(--text-3); line-height: 1.7; }
.kh-kpi--warn { border-color: color-mix(in srgb, var(--series-a) 55%, transparent); }
.kh-kpi--neg { border-color: color-mix(in srgb, var(--neg) 50%, transparent); }
.kh-kpi--pos { border-color: color-mix(in srgb, var(--pos) 50%, transparent); }

/* tables */
.kh-lab-tableblock { margin: 0 0 var(--sp-3); }
.kh-lab-table { width: 100%; }
.kh-lab-table__caption { caption-side: top; text-align: start; font-size: var(--fs-caption); color: var(--text-3); padding-bottom: 0.4rem; }
.kh-lab-table th.is-num, .kh-lab-table td.is-num { text-align: end; }
.kh-lab-table td.is-muted { color: var(--text-3); }
.kh-lab-table td.is-flag { color: var(--neg); font-weight: 600; }
.kh-lab-table td.is-na { color: var(--text-3); background: repeating-linear-gradient(135deg, transparent 0 6px, color-mix(in srgb, var(--text-3) 10%, transparent) 6px 7px); }
.kh-lab-table tr.is-emph td, .kh-lab-table tr.is-emph th { font-weight: 700; }
.kh-lab-table--heat td.is-num { min-width: 3.4rem; }
.kh-lab-table--compact td, .kh-lab-table--compact th { padding: 0.35rem 0.5rem; font-size: var(--fs-caption); }
.kh-sev { display: inline-block; padding: 0.05rem 0.5rem; border-radius: 999px; font-size: 0.72rem; font-weight: 700; border: 1px solid var(--border); white-space: nowrap; }
.kh-sev--high { border-color: color-mix(in srgb, var(--neg) 60%, transparent); color: var(--neg); }
.kh-sev--medium { border-color: color-mix(in srgb, var(--series-a) 60%, transparent); color: var(--series-a); }
.kh-sev--low { color: var(--text-2); }
.kh-sev--info { color: var(--text-3); }

/* charts */
.kh-chart-figure { margin: 0 0 var(--sp-4); max-width: 880px; }
.kh-chart { width: 100%; height: auto; display: block; overflow: visible; }
.kh-chart text { font-family: var(--font-fa); fill: var(--text-2); }
.kh-chart__tick { font-size: 11px; }
.kh-chart__value, .kh-chart__legend, .kh-chart__label { font-size: 11px; fill: var(--text); }
.kh-chart__reflabel { font-size: 10.5px; fill: var(--text-3); }
.kh-chart__grid { stroke: var(--border-soft); stroke-width: 1; }
.kh-chart__ref { stroke: var(--text-3); stroke-dasharray: 4 4; stroke-width: 1; }
.kh-chart__marker { stroke: var(--text); stroke-width: 1.2; stroke-dasharray: 3 3; }
.kh-chart__marker.is-accent { stroke: var(--accent); stroke-dasharray: none; stroke-width: 2; }
.kh-chart__line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.kh-chart__line.is-dashed { stroke-dasharray: 5 4; }
.kh-chart__band { fill: var(--series-b); opacity: 0.16; stroke: none; }
.kh-chart__band.is-a { fill: var(--series-a); }
.kh-chart__s0 { stroke: var(--series-a); fill: var(--series-a); }
.kh-chart__s1 { stroke: var(--series-b); fill: var(--series-b); }
.kh-chart__s2 { stroke: var(--series-c); fill: var(--series-c); }
.kh-chart__s3 { stroke: var(--series-d); fill: var(--series-d); }
.kh-chart__s4 { stroke: var(--series-e); fill: var(--series-e); }
.kh-chart__s5 { stroke: var(--series-f); fill: var(--series-f); }
.kh-chart__line.kh-chart__s0, .kh-chart__line.kh-chart__s1, .kh-chart__line.kh-chart__s2, .kh-chart__line.kh-chart__s3, .kh-chart__line.kh-chart__s4, .kh-chart__line.kh-chart__s5 { fill: none; }
.kh-chart__bar { stroke: none; }
.kh-chart__bar.is-muted { fill: var(--text-3); opacity: 0.45; }
.kh-chart__bar.is-neg { fill: var(--neg); }
.kh-chart__bar.is-pos { fill: var(--pos); }
.kh-chart-figure__cap { margin-top: 0.4rem; font-size: var(--fs-caption); color: var(--text-3); line-height: 1.8; }
.kh-chart-figure__data { margin-top: 0.4rem; }

/* findings list (issues, flags) */
.kh-findings { list-style: none; margin: 0 0 var(--sp-3); padding: 0; display: grid; gap: 0.6rem; }
.kh-finding { padding: 0.7rem var(--sp-3); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); background: var(--surface); }
.kh-finding__head { display: flex; flex-wrap: wrap; gap: 0.4rem 0.7rem; align-items: baseline; }
.kh-finding__title { font-weight: 700; }
.kh-finding__body { margin: 0.35rem 0 0; font-size: var(--fs-small); color: var(--text-2); line-height: 1.9; }
.kh-finding__quote { margin: 0.4rem 0 0; padding: 0.3rem 0.7rem; border-inline-start: 2px solid var(--border); color: var(--text); font-size: var(--fs-small); }
.kh-finding__fix { margin: 0.35rem 0 0; font-size: var(--fs-small); }
.kh-finding__fix::before { content: '→ '; color: var(--accent); }
[dir="rtl"] .kh-finding__fix::before { content: '← '; }

@media (prefers-reduced-motion: reduce) {
  .kh-tools-path__step, .kh-tool-card { transition: none; }
}

/* HTML bar list (horizontal bars that reflow on phones) */
.kh-barlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.7rem; }
.kh-barlist__label { display: flex; justify-content: space-between; gap: 1rem; font-size: var(--fs-small); line-height: 1.7; }
.kh-barlist__value { color: var(--text); font-weight: 600; }
.kh-barlist__track { display: block; height: 0.7rem; margin-top: 0.2rem; background: var(--border-soft); border-radius: 999px; overflow: hidden; }
.kh-barlist__bar { display: block; height: 100%; background: var(--series-b); border-radius: 999px; }
.kh-barlist__bar.is-neg { background: var(--neg); }
.kh-barlist__bar.is-pos { background: var(--pos); }
.kh-barlist__bar.is-a { background: var(--series-a); }
.kh-barlist__bar.is-muted { background: var(--text-3); }
.kh-barlist__note { display: block; margin-top: 0.15rem; font-size: var(--fs-caption); color: var(--text-3); }
@media (max-width: 600px) {
  .kh-chart__tick, .kh-chart__value, .kh-chart__legend, .kh-chart__label { font-size: 12px; }
}
.kh-input--sm { min-height: 36px; width: auto; max-width: 100%; padding: 0.25rem 0.6rem; margin-top: 0.45rem; font-size: var(--fs-caption); }
.kh-list { margin: 0.4rem 0 0; padding-inline-start: 1.2rem; display: grid; gap: 0.7rem; }
.kh-chart__dot.is-hollow { fill: var(--bg); stroke-width: 1.6; }
.kh-lab-docblock { margin-top: var(--sp-4); }
.kh-lab-doc { white-space: pre-wrap; word-break: break-word; font: inherit; font-size: var(--fs-small); line-height: 2; margin: 0; padding: var(--sp-3); max-height: 28rem; overflow: auto; border: 1px solid var(--border-soft); border-radius: var(--radius-sm); background: var(--surface); }

/* optional-AI status line and quoted evidence (stage 3) */
.kh-lab__ai {
  display: flex; gap: 0.6rem; align-items: baseline; margin: var(--sp-3) 0;
  padding: 0.6rem var(--sp-3); border-inline-start: 3px solid var(--border);
  font-size: var(--fs-small); line-height: 1.9; color: var(--text-2);
}
.kh-lab__ai p { margin: 0; }
.kh-quotes { list-style: none; margin: 0.4rem 0 0; padding: 0; display: grid; gap: 0.35rem; }
.kh-quotes li { padding: 0.35rem var(--sp-3); border-inline-start: 2px solid var(--border-soft); font-size: var(--fs-small); line-height: 1.9; color: var(--text-2); overflow-wrap: anywhere; }
.kh-quotes .kh-muted { font-size: 0.72rem; }
.kh-theme { padding-block: var(--sp-3); border-top: 1px solid var(--border-soft); }
.kh-theme:first-of-type { border-top: 0; }
.kh-theme h4 { margin: 0 0 0.2rem; font-size: 1rem; }
.kh-review { display: grid; gap: 0 var(--sp-2); grid-template-columns: 1fr 1fr; padding-block: var(--sp-3) 0; border-top: 1px solid var(--border-soft); }
.kh-review__text { grid-column: 1 / -1; margin-bottom: var(--sp-2) !important; }
.kh-review .kh-field { margin-bottom: var(--sp-2); min-width: 0; }
.kh-review label { font-size: 0.78rem; }
@media (min-width: 720px) { .kh-review { grid-template-columns: minmax(0, 1fr) 9rem 11rem; align-items: start; } .kh-review__text { grid-column: auto; } }
.kh-review__text { margin: 0; font-size: var(--fs-small); line-height: 1.9; overflow-wrap: anywhere; }
.kh-review select { width: 100%; }
.kh-lab-row--grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 480px) { .kh-lab-row--grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.kh-lab-row--grid .is-full { grid-column: 1 / -1; }
.kh-lab-row--grid label { font-size: 0.78rem; }
@media (min-width: 720px) { .kh-lab-row--grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.kh-tier { margin-top: var(--sp-3); }
.kh-tier h4 { margin: 0 0 0.3rem; font-size: 1rem; }
.kh-tier ul { margin: 0; padding-inline-start: 1.2rem; line-height: 2; }
.kh-lab__form.kh-lab__weights { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 720px) { .kh-lab__form.kh-lab__weights { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kh-checks { display: grid; gap: 0.3rem; margin: var(--sp-2) 0 var(--sp-3); }
.kh-lab-row--pair { grid-template-columns: 1fr 1fr; }
.kh-lab-row--pair .is-full { grid-column: 1 / -1; }
@media (min-width: 720px) { .kh-lab-row--pair { grid-template-columns: 1fr 1fr auto; } }
.kh-quotes .kh-sev { margin-inline-start: 0.2rem; }
.kh-check--inline { display: flex; gap: 0.4rem; align-items: center; margin: 0.25rem 0 0; font-size: 0.78rem; color: var(--text-3); }
.kh-check--inline input { width: auto; }
.kh-checks .kh-check { margin-bottom: 0.2rem; }
.kh-filebtn:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }
.kh-review--eval { grid-template-columns: 1fr !important; }
.kh-eval-scores { border: 0; padding: 0; }
@media (min-width: 720px) { .kh-eval-scores { grid-template-columns: repeat(5, minmax(0, 1fr)) !important; } }
.kh-range { width: 100%; accent-color: var(--accent); min-height: 2rem; }
.kh-range:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
