/* ==========================================================================
   COMPONENT: KAMAJI ROI CALCULATOR (Clastix case study rebuild)
   Uses the Clastix tokens defined on .cx-canvas (component-explorer.css).
   ========================================================================== */

.cx-canvas.roi { max-width: none; padding: clamp(14px, 3vw, 32px); }

.roi__frame {
  margin: 0;
  background-color: var(--color-bg-surface);
  border: var(--border-cyber);
  border-radius: 4px;
  overflow: hidden;
}

.roi__stage {
  padding: clamp(12px, 3vw, 32px);
  background-color: var(--color-bg-base);
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 24px 24px;
}

.roi__grid {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  gap: 20px;
  align-items: start;
}

@container cx (max-width: 760px) {
  .roi__grid { grid-template-columns: minmax(0, 1fr); }
}

.roi__head { margin-bottom: 20px; }
.roi__title { font-size: clamp(20px, 2.4vw, 26px); font-weight: 600; color: var(--cx-heading); line-height: 1.25; max-width: 30ch; }
.roi__sub { font-size: 14px; color: var(--cx-body); margin-top: 6px; max-width: 60ch; line-height: 1.55; }

/* ---------- Inputs ---------- */
.roi__inputs { display: grid; gap: 18px; }

.roi-field { display: grid; gap: 6px; }
.roi-field__top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.roi-field__label { font-size: 13px; font-weight: 600; color: var(--cx-heading); }
.roi-field__hint { font-size: 12px; color: var(--cx-muted); line-height: 1.45; }
.roi-field__big { font-size: 28px; font-weight: 600; color: var(--cx-heading); font-variant-numeric: tabular-nums; line-height: 1; }

.roi-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 24px;
  background: transparent;
  cursor: pointer;
  --pct: 33%;
}

.roi-range::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--cx-cta) var(--pct), var(--cx-track) var(--pct));
}
.roi-range::-moz-range-track { height: 6px; border-radius: 999px; background: var(--cx-track); }
.roi-range::-moz-range-progress { height: 6px; border-radius: 999px; background: var(--cx-cta); }

.roi-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px; margin-top: -8px;
  border-radius: 50%;
  background: #FFFFFF;
  border: 2px solid var(--cx-cta);
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.2);
  transition: transform 0.15s ease;
}
.roi-range::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #FFFFFF;
  border: 2px solid var(--cx-cta);
}
.roi-range:active::-webkit-slider-thumb { transform: scale(1.15); }
.roi-range:focus-visible { outline: none; }
.roi-range:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 2px var(--cx-ring-gap), 0 0 0 4px var(--cx-ring); }
.roi-range:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 2px var(--cx-ring-gap), 0 0 0 4px var(--cx-ring); }

.roi-range__scale { display: flex; justify-content: space-between; font-size: 11px; color: var(--cx-muted); font-variant-numeric: tabular-nums; }

.roi__pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); gap: 14px; }

.roi-input {
  display: flex;
  align-items: center;
  height: 44px;
  background: var(--cx-surface);
  border: 1px solid var(--cx-sec-border);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.roi-input:focus-within { border-color: var(--cx-blue-300); box-shadow: 0 0 0 4px var(--cx-info-bg); }
.roi-input__affix { padding: 0 0 0 12px; font-size: 14px; color: var(--cx-muted); }
.roi-input__affix--end { padding: 0 12px 0 0; }

.roi-input input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  color: var(--cx-heading);
  padding: 0 10px;
  font-variant-numeric: tabular-nums;
}
.roi-input input:focus { outline: none; }

.roi-field.is-invalid .roi-input { border-color: var(--cx-err-fill); }
.roi-field.is-invalid .roi-input:focus-within { box-shadow: 0 0 0 4px var(--cx-err-bg); }
.roi-field__error { font-size: 12px; color: var(--cx-err-text); display: none; }
.roi-field.is-invalid .roi-field__error { display: block; }

/* Toggle switch */
.roi-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--cx-heading);
  background: none;
  border: 0;
  padding: 4px 0;
  cursor: pointer;
  text-align: left;
}
.roi-switch__track {
  position: relative;
  flex: none;
  width: 36px; height: 20px;
  border-radius: 999px;
  background: var(--cx-gray-300);
  transition: background-color 0.2s ease;
}
.cx-canvas[data-theme='dark'] .roi-switch__track { background: rgba(204, 204, 230, 0.25); }
.roi-switch__track::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.2);
  transition: transform 0.2s cubic-bezier(0.25, 1, 0.5, 1);
}
.roi-switch[aria-checked='true'] .roi-switch__track { background: var(--cx-cta); }
.roi-switch[aria-checked='true'] .roi-switch__track::after { transform: translateX(16px); }
.roi-switch:focus-visible { outline: none; }
.roi-switch:focus-visible .roi-switch__track { box-shadow: 0 0 0 2px var(--cx-ring-gap), 0 0 0 4px var(--cx-ring); }

.roi__more { display: grid; gap: 14px; padding-top: 4px; }
.roi__more[hidden] { display: none; }

/* ---------- Results ---------- */
.roi__results { display: grid; gap: 14px; }

.roi-hero {
  background: var(--cx-blue-500);
  color: #FFFFFF;
  border-radius: 10px;
  padding: 22px;
  display: grid;
  gap: 4px;
}
.cx-canvas[data-theme='dark'] .roi-hero { background: var(--cx-surface); border: 1px solid var(--cx-border); }
.roi-hero__label { font-size: 13px; font-weight: 500; color: var(--cx-blue-100); }
.roi-hero__value { font-size: clamp(32px, 5vw, 46px); font-weight: 600; line-height: 1.05; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.roi-hero__split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; padding-top: 14px; border-top: 1px solid rgba(204, 204, 230, 0.25); }
.roi-hero__k { font-size: 12px; color: var(--cx-blue-100); }
.roi-hero__v { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.roi-hero__note { font-size: 11px; color: var(--cx-blue-200); margin-top: 2px; }

.roi-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.roi-stat { background: var(--cx-surface); border: 1px solid var(--cx-border); border-radius: 8px; padding: 12px 14px; }
.roi-stat__v { font-size: 22px; font-weight: 600; color: var(--cx-heading); font-variant-numeric: tabular-nums; line-height: 1.1; }
.roi-stat__k { font-size: 12px; color: var(--cx-muted); margin-top: 4px; line-height: 1.35; }
.roi-stat--accent .roi-stat__v { color: var(--cx-magenta-500); }
.cx-canvas[data-theme='dark'] .roi-stat--accent .roi-stat__v { color: var(--cx-magenta-300); }

@container cx (max-width: 420px) {
  .roi-stats { grid-template-columns: 1fr 1fr; }
  .roi-stats .roi-stat:first-child { grid-column: 1 / -1; }
}

/* Before / after server field */
.roi-servers { background: var(--cx-surface); border: 1px solid var(--cx-border); border-radius: 8px; padding: 14px; }
.roi-servers__head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 10px; font-size: 12px; color: var(--cx-muted); }
.roi-servers__head strong { color: var(--cx-heading); font-weight: 600; font-size: 13px; }
.roi-dots { display: grid; grid-template-columns: repeat(auto-fill, minmax(7px, 1fr)); gap: 3px; }
.roi-dot {
  aspect-ratio: 1;
  border-radius: 2px;
  background: var(--cx-gray-300);
  transition: background-color 0.35s ease, opacity 0.35s ease, transform 0.35s ease;
}
.cx-canvas[data-theme='dark'] .roi-dot { background: rgba(204, 204, 230, 0.3); }
.roi-dots.is-after .roi-dot { opacity: 0.18; transform: scale(0.7); }
.roi-dots.is-after .roi-dot.is-kept { opacity: 1; transform: scale(1.25); background: var(--cx-magenta-500); }
.roi-servers__legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 12px; color: var(--cx-muted); }
.roi-servers__legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: 0; }

.roi-seg { display: inline-flex; border: 1px solid var(--cx-sec-border); border-radius: 8px; overflow: hidden; }
.roi-seg button {
  font: inherit; font-size: 12px; font-weight: 600;
  padding: 6px 10px;
  border: 0;
  background: var(--cx-surface);
  color: var(--cx-sec-text);
  cursor: pointer;
}
.roi-seg button + button { border-left: 1px solid var(--cx-sec-border); }
.roi-seg button[aria-pressed='true'] { background: var(--cx-info-bg); color: var(--cx-primary); }
.roi-seg button:focus-visible { outline: 2px solid var(--cx-ring); outline-offset: -2px; }

.roi-power[hidden] { display: none; }

.roi__invalid { display: none; font-size: 13px; color: var(--cx-err-text); background: var(--cx-err-bg); border-radius: 8px; padding: 10px 12px; }
.roi.is-invalid .roi__invalid { display: block; }
.roi.is-invalid .roi__results [data-out] { opacity: 0.35; }

.roi__foot { margin-top: 18px; font-size: 11px; color: var(--cx-muted); line-height: 1.5; }

@media (prefers-reduced-motion: reduce) {
  .roi-dot, .roi-switch__track::after { transition: none; }
}

/* Grid children must be allowed to shrink below their content width */
.roi__inputs, .roi__results, .roi-field, .roi-input { min-width: 0; }
.roi-input input { width: 100%; }
.roi-input input::-webkit-outer-spin-button,
.roi-input input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.roi-input input[type='number'] { -moz-appearance: textfield; appearance: textfield; }
.roi-dots.is-after .roi-dot { opacity: 0.28; }

/* Dark theme (matches the live calculator) */
.cx-canvas.roi[data-theme='dark'] {
  background:
    radial-gradient(120% 60% at 85% 0%, rgba(51, 51, 153, 0.45), transparent 60%),
    var(--cx-blue-800);
}
.cx-canvas[data-theme='dark'] .roi-hero {
  background:
    radial-gradient(100% 120% at 100% 0%, rgba(216, 29, 86, 0.22), transparent 55%),
    linear-gradient(180deg, var(--cx-blue-600), var(--cx-blue-700));
  border: 1px solid rgba(204, 204, 230, 0.2);
  box-shadow: 0 20px 40px -24px rgba(0, 0, 0, 0.8);
}
.roi-legend-gone { background: var(--cx-gray-300); }
.cx-canvas[data-theme='dark'] .roi-legend-gone { background: rgba(204, 204, 230, 0.3); }
