/*
 * Kevin Kos calculators — front-end styles.
 *
 * Scoped under .kk so nothing leaks into the surrounding WordPress theme, and
 * inheriting the theme's font rather than shipping one.
 */

.kk {
  --kk-accent: #e8c88a;
  --kk-surface: #fff;
  --kk-border: #e3e3e0;
  --kk-text: #1a1a1a;
  --kk-muted: #6b6b6b;
  --kk-radius: 6px;
  --kk-gap: 16px;

  position: relative;
  color: var(--kk-text);
  font-family: inherit;
  line-height: 1.45;
}

.kk *,
.kk *::before,
.kk *::after {
  box-sizing: border-box;
}

/* ---------- toolbar ---------- */

.kk-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: var(--kk-gap);
}

.kk-toolbar__group {
  display: inline-flex;
  border: 1px solid var(--kk-border);
  border-radius: var(--kk-radius);
  overflow: hidden;
}

.kk-toolbar__button {
  padding: 6px 14px;
  border: 0;
  background: var(--kk-surface);
  color: var(--kk-muted);
  font: inherit;
  font-size: 0.85em;
  cursor: pointer;
}

.kk-toolbar__button + .kk-toolbar__button {
  border-left: 1px solid var(--kk-border);
}

.kk-toolbar__button[aria-pressed='true'] {
  background: var(--kk-accent);
  color: var(--kk-text);
  font-weight: 600;
}

/* ---------- layout ---------- */

.kk-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(280px, 1.5fr) minmax(220px, 1.2fr);
  gap: var(--kk-gap);
  align-items: start;
}

/*
 * One calculator on its own — [kk_calc] — builds no tab strip, so the three
 * column template above would put the calculator itself in the 180px tab slot,
 * the side column where the calculator belongs, and leave column three empty.
 * Two columns, in the same proportions the other two had.
 *
 * The narrow-screen rule below collapses both to a single column; it comes
 * later in the file and carries equal specificity, so it still wins there.
 */
.kk-grid--solo {
  grid-template-columns: minmax(280px, 1.5fr) minmax(220px, 1.2fr);
}

/* Nothing in the side column — a locked calculator — so do not reserve it. */
.kk-grid--solo.kk-grid--noside {
  grid-template-columns: 1fr;
}

/* ---------- tab column ---------- */

/*
 * No container box. The rows carry the rounded corners, so a white panel behind
 * them showed a square of background in each corner — visible on the live site
 * against anything but white.
 */
.kk-tabs {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: none;
  border: 0;
}

.kk-tabs__button {
  padding: 14px 16px;
  border: 1px solid var(--kk-border);
  border-radius: var(--kk-radius);
  background: var(--kk-surface);
  color: var(--kk-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.kk-tabs__button::after {
  content: '›';
  float: right;
  color: var(--kk-muted);
}

/* Members-only: the padlock replaces the chevron, same slot, same weight. */
.kk-tabs__button--locked::after {
  content: '🔒';
  font-size: 0.85em;
}

.kk-tabs__button:hover {
  background: #faf8f4;
}

.kk-tabs__button[aria-selected='true'] {
  background: var(--kk-accent);
  font-weight: 600;
}

/* ---------- calculator ---------- */

.kk-calc {
  border: 1px solid var(--kk-border);
  border-radius: var(--kk-radius);
  overflow: hidden;
  background: var(--kk-surface);
}

/*
 * 16px flat, as on Wix — inheriting the theme's h2 scale made this enormous.
 * The thin border and bottom shadow are what give the bar its raised edge; the
 * live site has both and without them the block reads as a flat colour fill.
 */
.kk-calc__title {
  margin: 0;
  padding: 12px 16px;
  border: 1px solid rgb(0 0 0 / 12%);
  box-shadow: 0 2px 4px rgb(0 0 0 / 12%);
  background: var(--kk-accent);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
}

.kk-calc__body {
  padding: 16px;
}

/* ---------- body: inputs, results and notes in author order ---------- */

.kk-body > * + * {
  margin-top: 14px;
}

.kk-divider {
  border: 0;
  border-top: 1px solid var(--kk-border);
  margin: 18px 0;
}

/*
 * The 5px keeps a note from sitting flush against whatever is above it. The
 * `* +` sibling rule already adds 14px between blocks, so this only shows up
 * where a note follows something with no spacing of its own.
 */
.kk-text {
  margin: 0;
  padding-top: 5px;
  color: var(--kk-muted);
  font-size: 0.92em;
}

.kk-field__label {
  display: block;
  margin-bottom: 4px;
  color: var(--kk-muted);
  font-size: 0.9em;
}

/*
 * The required marker. Decoration only — aria-required on the control is what
 * a screen reader acts on, and this span is aria-hidden.
 */
.kk-field__required {
  margin-left: 2px;
  color: #c0392b;
}

.kk-field__row {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- radio group ---------- */

/*
 * A fieldset, so the group is announced as one. Browsers give fieldset its own
 * border, padding and margin, and legend its own padding — all reset here.
 */
.kk-field--radio {
  margin: 0;
  padding: 0;
  border: 0;
}

.kk-radios {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
}

.kk-radio {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
}

/*
 * The real radio drives everything and is only moved out of sight, never
 * display:none — same reasoning as the switch: it stays focusable and stays in
 * the accessibility tree.
 */
.kk-radio__input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.kk-radio__mark {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  border: 1px solid var(--kk-text);
  border-radius: 50%;
  background: var(--kk-surface);
}

.kk-radio__input:checked + .kk-radio__mark {
  border-color: var(--kk-accent);
  border-width: 5px;
}

.kk-radio__input:focus-visible + .kk-radio__mark {
  outline: 2px solid #2271b1;
  outline-offset: 2px;
}

.kk-field__input,
.kk-field__select {
  flex: 1 1 auto;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--kk-text);
  border-radius: 2px;
  background: var(--kk-surface);
  color: inherit;
  font: inherit;
}

/*
 * The select sizes itself to its widest option by default, which on narrow
 * screens pushed the text under the arrow. Fixed room for the arrow, and a
 * width that tracks the text box rather than the content.
 */
.kk-field__select {
  width: 100%;
  padding-right: 34px;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentcolor 50%),
                    linear-gradient(135deg, currentcolor 50%, transparent 50%);
  background-position: right 16px center, right 11px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  text-overflow: ellipsis;
}

.kk-field__input[aria-invalid='true'] {
  border-color: #c0392b;
}

.kk-field__unit {
  flex: 0 0 auto;
  font-size: 1.4em;
  font-weight: 600;
}

.kk-field__range {
  flex: 1 1 auto;
  min-width: 0;
}

.kk-field__readout {
  flex: 0 0 auto;
  min-width: 2.5em;
  color: var(--kk-muted);
  text-align: right;
}

.kk-field__error {
  margin: 4px 0 0;
  color: #c0392b;
  font-size: 0.85em;
}

.kk-field--toggle {
  display: flex;
  align-items: center;
  gap: 10px;
}

.kk-field--toggle .kk-field__label {
  margin: 0;
  color: inherit;
  cursor: pointer;
}

/* ---------- switch ---------- */

/*
 * A real checkbox drives this — it is only moved out of sight, never hidden
 * with display:none, so it stays focusable and reachable by screen readers.
 */
.kk-field__switch {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.kk-switch {
  position: relative;
  flex: 0 0 auto;
  width: 44px;
  height: 24px;
  border-radius: 12px;
  background: #c9c9c4;
  cursor: pointer;
}

.kk-switch__dot {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 30%);
}

.kk-field__switch:checked + .kk-switch {
  background: var(--kk-accent);
}

.kk-field__switch:checked + .kk-switch .kk-switch__dot {
  left: 23px;
}

.kk-field__switch:focus-visible + .kk-switch {
  outline: 2px solid #2271b1;
  outline-offset: 2px;
}

/* ---------- slider step names ---------- */

.kk-field__ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
}

.kk-field__tick {
  flex: 1 1 0;
  color: var(--kk-muted);
  font-size: 0.8em;
  text-align: center;
}

.kk-field__tick:first-child {
  text-align: left;
}

.kk-field__tick:last-child {
  text-align: right;
}

.kk-field__tick.is-on {
  color: var(--kk-text);
  font-weight: 700;
}

/* ---------- outputs ---------- */

.kk-heading {
  margin: 18px 0 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--kk-border);
  color: var(--kk-muted);
  font-size: 0.8em;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/*
 * Results pair up two across, and a result that can't fit in half the panel
 * takes the whole row on its own.
 *
 * The whole mechanism is the flex content-based minimum. Each row asks for half
 * the width, but a flex item is never shrunk below its own min-content, so a row
 * whose value is wider than half cannot share a line — it wraps and, having the
 * line to itself, grows to fill it. Nothing is measured in JavaScript, and it
 * re-decides on its own as the numbers change while someone types.
 *
 * `white-space: nowrap` on the value is what makes that minimum meaningful:
 * without it a long number would wrap mid-value and always "fit" in half.
 */
.kk-results {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.kk-results > .kk-output {
  flex: 1 1 calc(50% - 7px);
  /* No min-width:0 here — the automatic content minimum is the mechanism. */
}

.kk-output__label {
  display: block;
  font-size: 1.05em;
  font-weight: 700;
}

/* The label and its ⓘ on one line, so a long label wraps around the icon. */
.kk-output__head {
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.kk-output__head .kk-output__label {
  display: inline;
}

/*
 * A trailing parenthetical — "Whiskey (45 % ABV)". Quieter than the name it
 * qualifies, but not so quiet it reads as disabled.
 */
.kk-output__detail {
  color: var(--kk-muted);
  font-size: 0.86em;
  font-weight: 400;
  /* Wrap before the bracket, never inside it — "(45 %" above "ABV)" reads as
     two broken things rather than one qualifier. It does raise the row's
     content minimum, which is what decides whether two results share a line;
     these qualifiers are short enough that it costs nothing. */
  white-space: nowrap;
}

/*
 * Links wherever the author pointed it. A real anchor, so it opens in a new
 * tab, can be middle-clicked and shows its destination in the status bar —
 * none of which a button gives you.
 */
.kk-output__info {
  flex: 0 0 auto;
  color: var(--kk-muted);
  font-size: 1em;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
}

.kk-output__info:hover,
.kk-output__info:focus {
  color: var(--kk-accent);
}

.kk-output__value {
  display: block;
  white-space: nowrap;
  font-size: 1.9em;
  font-weight: 700;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

/* ---------- side column ---------- */

.kk-side {
  display: grid;
  gap: var(--kk-gap);
}

.kk-side__panel {
  border: 1px solid var(--kk-border);
  border-radius: var(--kk-radius);
  padding: 14px 16px;
  background: var(--kk-surface);
}

.kk-side__panel p {
  margin: 0;
}

.kk-side__heading {
  margin: -14px -16px 14px;
  padding: 12px 16px;
  background: var(--kk-accent);
  font-size: 0.95em;
  font-weight: 700;
  text-align: center;
}

/*
 * Always three columns, never auto-fit. With auto-fit a single product stretched
 * to the full panel width and a row of two came out half-width each; the cards
 * changed size with the count. Fixed columns plus empty filler cells keep every
 * card identical and leave the gaps where they fall.
 */
.kk-products {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.kk-product {
  text-align: center;
}

.kk-product--empty {
  visibility: hidden;
}

.kk-product__stores {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.kk-product__store {
  padding: 2px 6px;
  border: 1px solid var(--kk-border);
  border-radius: var(--kk-radius);
  background: var(--kk-surface);
  font-size: 1.15em;
  line-height: 1.4;
  text-decoration: none;
}

.kk-product__store:hover,
.kk-product__store.is-preferred {
  background: var(--kk-accent);
}

.kk-product__image {
  display: block;
  width: 100%;
  max-width: 140px;
  height: auto;
  margin: 0 auto 6px;
}

.kk-product__name {
  margin: 0 0 6px;
  font-size: 0.85em;
}

/*
 * The video fills its panel edge to edge. The panel's own 14/16px padding left
 * a white margin around the player, which looks like a mistake rather than a
 * frame — so the video panel drops its padding entirely.
 */
.kk-side__panel--video {
  padding: 0;
  overflow: hidden;
  line-height: 0;
}

.kk-video {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 0;
}

/* ---------- members only ---------- */

.kk-locked__text {
  margin: 0;
  color: var(--kk-muted);
}

.kk-locked__cta {
  display: inline-block;
  margin-top: 14px;
  padding: 10px 18px;
  border: 1px solid var(--kk-border);
  border-radius: var(--kk-radius);
  background: var(--kk-accent);
  color: var(--kk-text);
  text-decoration: none;
}

/* ---------- theme armour ---------- */

/*
 * Salient styles bare elements at a specificity our single classes lose to —
 * `input[type=number]` is 0,1,1 against `.kk-field__input`'s 0,1,0. Every rule
 * below answers a measured collision; the extra `.kk` is enough, no
 * !important. Run demo/salient-check.html to see them, ?nokk=1 for the damage.
 */

.kk .kk-field__input,
.kk .kk-field__select {
  width: auto;
  padding: 10px 12px;
  border: 1px solid var(--kk-text);
  border-radius: 2px;
  background-color: var(--kk-surface);
  box-shadow: none;
  color: inherit;
  font-size: inherit;
  line-height: inherit;
}

.kk .kk-field__input[aria-invalid='true'] {
  border-color: #c0392b;
}

/* The gutter the arrow sits in — the rule above would otherwise reset it. */
.kk .kk-field__select {
  width: 100%;
  padding-right: 34px;
}

/* The theme zeroes the focus ring globally. Keyboard users still need one. */
.kk :is(input, select, button, a):focus-visible {
  outline: 2px solid #2271b1;
  outline-offset: 2px;
}

/* Otherwise 27px of dead space opens under every note, error and product. */
.kk p {
  padding: 0;
}

/* Salient colours and underlines every bare `a` — the upsell button is one. */
.kk .kk-locked__cta {
  color: var(--kk-text);
  text-decoration: none;
}

/*
 * Heading margins. Salient carries `.row .col h4 { margin-bottom: 8px }` and
 * friends at 0,2,1 — which beats a single class at 0,1,0, so the moment these
 * became real h4/h5 tags the theme started spacing them.
 *
 * Each selector below is anchored on the element's own container to reach 0,3,0
 * and clear 0,2,1 outright, rather than tying 0,2,1 with `.kk h4.kk-calc__title`
 * and depending on which stylesheet the page happens to load last.
 */
.kk .kk-calc .kk-calc__title {
  margin: 0;
}

.kk .kk-body .kk-heading {
  margin: 18px 0 8px;
}

.kk .kk-side__panel .kk-side__heading {
  margin: -14px -16px 14px;
}

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .kk-grid {
    grid-template-columns: 1fr;
  }

  /*
   * Tabs stay stacked, matching the current site: every calculator is visible
   * without horizontal scrolling, and each row is a comfortable tap target.
   */
  .kk-tabs__button {
    padding: 16px;
    font-size: 1.05em;
  }

  /* Results centre on narrow screens, as they do on the live site today. */
  .kk-output {
    text-align: center;
  }

  .kk-output__value {
    font-size: 1.75em;
  }

  .kk-heading {
    text-align: center;
  }

  /* Prefixed to stay above the theme's `input[type=number]`, as above. */
  .kk .kk-field__input,
  .kk .kk-field__select {
    padding: 12px;
    font-size: 1.05em;
  }

  /* Keep the arrow's gutter — this is where options overlapped it. */
  .kk .kk-field__select {
    padding-right: 36px;
  }

  .kk-field__unit {
    font-size: 1.6em;
  }

  .kk-toolbar {
    justify-content: center;
  }

  .kk-toolbar__button {
    padding: 10px 18px;
  }

  /*
   * Products stay three across on phones too. The side column is full width
   * there, so three cards still get ~105px each — and dropping to two would
   * leave the empty-slot filler misaligned.
   */
  .kk-product__name {
    font-size: 0.78em;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .kk-tabs__button,
  .kk-toolbar__button,
  .kk-product__store {
    transition: background-color 120ms ease;
  }

  .kk-switch,
  .kk-switch__dot {
    transition: background-color 140ms ease, left 140ms ease;
  }
}
