/* Guide-page micro-tools (mounted by /lib/guide-widgets.js).
   Extends the guide-article design language: brand tokens from style.css,
   callout-style container, cyan accent, dark glass surfaces. All dynamic
   geometry (bar bands/markers) arrives via CSS custom properties set from
   JS — no inline style attributes, per the strict nonce-only CSP. */

.qc-widget {
  display: grid;
  gap: 0.9rem;
  padding: 1.25rem 1.35rem 1.35rem;
  border-radius: 1.1rem;
  background: rgba(0, 200, 255, 0.05);
  border: 1px solid rgba(0, 200, 255, 0.28);
  box-shadow: 0 18px 40px -30px rgba(0, 200, 255, 0.55);
}

.qc-widget__title {
  margin: 0;
  color: var(--accent-aaa);
  font-weight: 700;
  font-size: 1.02rem;
  letter-spacing: 0.01em;
}

.qc-widget__sub,
.qc-widget__foot {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.5;
}

.qc-widget__foot a,
.qc-widget__fallback a {
  color: var(--accent-aaa);
}

.qc-widget__fallback {
  margin: 0;
  color: var(--text-mid);
}

/* --- form fields --------------------------------------------------- */

.qc-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.65rem;
}

.qc-field {
  display: grid;
  gap: 0.3rem;
  align-content: start;
}

.qc-field__label {
  color: var(--text-mid);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
}

.qc-widget input[type='text'],
.qc-widget select,
.qc-widget textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 0.55rem 0.7rem;
  border-radius: 0.6rem;
  border: 1px solid rgba(0, 200, 255, 0.3);
  background: rgba(0, 0, 0, 0.45);
  color: var(--text-strong);
  font: inherit;
  font-size: 0.92rem;
}

.qc-widget input[type='text']:focus-visible,
.qc-widget select:focus-visible,
.qc-widget textarea:focus-visible,
.qc-widget input[type='range']:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(47, 233, 255, 0.45);
}

.qc-widget input[disabled] {
  opacity: 0.45;
}

.qc-input--small {
  max-width: 9.5rem;
}

/* --- tabs / buttons / choices -------------------------------------- */

.qc-tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.qc-tab {
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  border: 1px solid rgba(0, 200, 255, 0.35);
  background: transparent;
  color: var(--text-mid);
  font: inherit;
  font-size: 0.84rem;
  cursor: pointer;
}

.qc-tab[aria-pressed='true'] {
  background: var(--accent-aaa);
  border-color: var(--accent-aaa);
  color: #000;
  font-weight: 700;
}

.qc-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  border: none;
  background: var(--accent-aaa);
  color: #000;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 160ms ease;
}

.qc-btn:is(:hover, :focus-visible) {
  transform: translateY(-1px);
  outline: none;
  box-shadow: 0 0 0 3px rgba(47, 233, 255, 0.35);
}

.qc-btn[disabled] {
  opacity: 0.55;
  cursor: progress;
  transform: none;
}

.qc-btn--ghost {
  background: transparent;
  border: 1px solid rgba(0, 200, 255, 0.45);
  color: var(--accent-aaa);
  justify-self: start;
}

.qc-choices {
  display: grid;
  gap: 0.45rem;
  border: none;
  margin: 0;
  padding: 0;
}

.qc-choices--grid {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.qc-choice {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  color: var(--text-mid);
  font-size: 0.88rem;
  line-height: 1.45;
  cursor: pointer;
}

.qc-choice input {
  margin-top: 0.2rem;
  accent-color: var(--accent-aaa);
  flex-shrink: 0;
}

.qc-choice--inline {
  margin-top: 0.2rem;
}

.qc-maint-rows {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.qc-maint-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.qc-subhead {
  margin: 0.5rem 0 0;
  color: var(--text-mid);
  font-size: 0.86rem;
  font-weight: 700;
}

/* --- result panel --------------------------------------------------- */

.qc-result {
  display: none;
  gap: 0.55rem;
  padding: 1rem 1.1rem;
  border-radius: 0.9rem;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(0, 200, 255, 0.2);
}

.qc-result--visible {
  display: grid;
}

.qc-result__badge {
  justify-self: start;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.qc-result[data-status='good'] { border-color: rgba(47, 233, 255, 0.45); }
.qc-result[data-status='warn'] { border-color: rgba(255, 198, 107, 0.5); }
.qc-result[data-status='bad'] { border-color: rgba(255, 107, 107, 0.55); }

.qc-result[data-status='good'] .qc-result__badge { background: rgba(47, 233, 255, 0.16); color: var(--accent-aaa); }
.qc-result[data-status='warn'] .qc-result__badge { background: rgba(255, 198, 107, 0.16); color: #ffc66b; }
.qc-result[data-status='bad'] .qc-result__badge { background: rgba(255, 107, 107, 0.16); color: #ff6b6b; }

.qc-result__title {
  margin: 0;
  color: var(--text-strong);
  font-weight: 700;
  font-size: 0.98rem;
  line-height: 1.45;
}

.qc-result__detail {
  margin: 0;
  color: var(--text-mid);
  font-size: 0.88rem;
  line-height: 1.6;
}

.qc-result__extras {
  display: grid;
  gap: 0.45rem;
}

.qc-result__extras:empty {
  display: none;
}

.qc-result__cta {
  justify-self: start;
  margin-top: 0.25rem;
  font-size: 0.88rem;
  padding: 0.6rem 1.25rem;
}

.qc-result--sub {
  margin-top: 0.25rem;
}

.qc-note {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

/* --- bars / gauges --------------------------------------------------
   Geometry via custom props set from JS:
     --qc-band-lo / --qc-band-hi : typical-range band edges (0..1)
     --qc-pos                    : marker position (0..1)               */

.qc-bar {
  position: relative;
  height: 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.qc-bar__band {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--qc-band-lo, 0) * 100%);
  width: calc((var(--qc-band-hi, 1) - var(--qc-band-lo, 0)) * 100%);
  background: rgba(47, 233, 255, 0.28);
  border-radius: 999px;
}

.qc-bar__band--good { background: rgba(47, 233, 255, 0.32); }
.qc-bar__band--bad { background: rgba(255, 107, 107, 0.3); }

.qc-bar__marker {
  position: absolute;
  top: -2px;
  bottom: -2px;
  left: calc(var(--qc-pos, 0) * 100%);
  width: 3px;
  transform: translateX(-50%);
  background: var(--text-strong);
  box-shadow: 0 0 6px rgba(241, 251, 255, 0.8);
}

.qc-bar__legend {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.78rem;
}

/* Labor/materials stacked bar (--qc-a = labor share 0..1) */
.qc-stack {
  display: flex;
  height: 26px;
  border-radius: 0.5rem;
  overflow: hidden;
  font-size: 0.72rem;
  font-weight: 700;
  color: #000;
}

.qc-stack__labor {
  flex: 0 0 calc(var(--qc-a, 0.5) * 100%);
  background: var(--accent-aaa);
  display: flex;
  align-items: center;
  padding-left: 0.5rem;
  white-space: nowrap;
  overflow: hidden;
}

.qc-stack__materials {
  flex: 1;
  background: rgba(255, 198, 107, 0.85);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 0.5rem;
  white-space: nowrap;
  overflow: hidden;
}

/* Cost-plus growth bar (--qc-a = base share, --qc-b = overage share) */
.qc-grow {
  display: flex;
  height: 18px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.07);
}

.qc-grow__base {
  flex: 0 0 calc(var(--qc-a, 0) * 100%);
  background: rgba(47, 233, 255, 0.45);
  transition: flex-basis 220ms ease;
}

.qc-grow__over {
  flex: 0 0 calc(var(--qc-b, 0) * 100%);
  background: rgba(255, 107, 107, 0.65);
  transition: flex-basis 220ms ease;
}

/* --- milestone schedule table ---------------------------------------- */

.qc-schedule {
  display: grid;
  gap: 0.6rem;
}

.qc-schedule:empty {
  display: none;
}

.qc-schedule__caption {
  caption-side: top;
  text-align: left;
  color: var(--text-mid);
  font-size: 0.84rem;
  font-weight: 700;
  padding-bottom: 0.4rem;
}

.qc-schedule__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
  color: var(--text-mid);
}

.qc-schedule__table th,
.qc-schedule__table td {
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid rgba(0, 200, 255, 0.14);
}

.qc-schedule__table th {
  color: var(--text-muted);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.qc-schedule__table td:nth-child(3),
.qc-schedule__table td:nth-child(4) {
  white-space: nowrap;
}

/* --- completeness score ---------------------------------------------- */

.qc-score {
  display: flex;
  align-items: baseline;
  gap: 0.2rem;
  color: var(--text-muted);
}

.qc-score__num {
  font-size: 2.1rem;
  font-weight: 700;
  color: var(--text-strong);
}

.qc-score[data-status='good'] .qc-score__num { color: var(--accent-aaa); }
.qc-score[data-status='warn'] .qc-score__num { color: #ffc66b; }
.qc-score[data-status='bad'] .qc-score__num { color: #ff6b6b; }

/* --- per-line maintenance verdicts ------------------------------------ */

.qc-lines {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}

.qc-line {
  display: grid;
  gap: 0.25rem;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-mid);
}

.qc-line__badge {
  justify-self: start;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.qc-line[data-status='good'] .qc-line__badge { background: rgba(47, 233, 255, 0.16); color: var(--accent-aaa); }
.qc-line[data-status='warn'] .qc-line__badge { background: rgba(255, 198, 107, 0.16); color: #ffc66b; }
.qc-line[data-status='bad'] .qc-line__badge { background: rgba(255, 107, 107, 0.16); color: #ff6b6b; }

/* --- overrun slider ---------------------------------------------------- */

.qc-slider {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-top: 0.5rem;
}

.qc-slider input[type='range'] {
  flex: 1;
  accent-color: var(--accent-aaa);
}

.qc-slider__out {
  color: var(--text-strong);
  font-size: 0.88rem;
  font-weight: 700;
  white-space: nowrap;
}

/* --- AI line-check panel ----------------------------------------------- */

.qc-ai {
  display: grid;
  gap: 0.55rem;
  padding-top: 0.85rem;
  border-top: 1px dashed rgba(0, 200, 255, 0.25);
}

.qc-ai__title {
  margin: 0;
  color: var(--text-strong);
  font-size: 0.9rem;
  font-weight: 700;
}

.qc-ai__input {
  resize: vertical;
  min-height: 3.2rem;
}

.qc-ai__row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.qc-ai__meta {
  color: var(--text-muted);
  font-size: 0.74rem;
}

.qc-ai__meta a {
  color: var(--text-muted);
  text-decoration: underline;
}

.qc-ai__verdict {
  margin: 0;
  color: var(--text-mid);
  font-size: 0.88rem;
  line-height: 1.6;
}

.qc-ai__verdict:empty {
  display: none;
}

.qc-ai__cta {
  color: var(--accent-aaa);
  font-size: 0.88rem;
  font-weight: 700;
  text-decoration: none;
}

.qc-ai__cta:is(:hover, :focus-visible) {
  text-decoration: underline;
}

/* --- responsive + motion ------------------------------------------------ */

@media (max-width: 560px) {
  .qc-widget {
    padding: 1rem 0.9rem 1.1rem;
  }

  .qc-fields {
    grid-template-columns: 1fr 1fr;
  }

  .qc-maint-row {
    align-items: flex-start;
  }

  .qc-input--small {
    max-width: 100%;
  }
}

@media (max-width: 400px) {
  .qc-fields {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .qc-btn,
  .qc-grow__base,
  .qc-grow__over {
    transition: none;
  }
}
