/**
 * CPT Magic Votes — vote button styles.
 *
 * Colors are driven by CSS custom properties set as inline styles on .cmv-wrap
 * by the PHP render() method. The defaults below apply when no inline style is
 * present (e.g. in custom theme overrides).
 *
 * Class reference:
 *   .cmv-wrap         Flex container; centers the button horizontally.
 *   .cmv-style-solid  Applied when the solid style is selected in settings.
 *   .cmv-button       The <button> element.
 *   .cmv-icon-right   Applied when icon+count should appear to the right of text.
 *   .cmv-icon-group   Wraps the icon SVG and count together.
 *   .cmv-icon         Base class on every vote icon SVG.
 *   .cmv-heart        Applied to the heart SVG icon.
 *   .cmv-checkbox     Applied to the checkbox SVG icon.
 *   .cmv-check-box    The rect element inside .cmv-checkbox.
 *   .cmv-check        The polyline checkmark inside .cmv-checkbox.
 *   .cmv-count        The numeric count <span>.
 *   .cmv-label        Optional text label <span>.
 *   .cmv-voted        Applied when the current user has voted.
 *   .cmv-loading      Applied during the fetch; dims the button.
 *   .cmv-pop          Triggers the bounce animation (JS-managed).
 *
 * CSS custom properties (set via inline style on .cmv-wrap):
 *   --cmv-button-color      Idle border / text / icon color (outline) or bg (solid).
 *   --cmv-outline-color     Idle border color.
 *   --cmv-heart-color       Idle icon color.
 *   --cmv-hover-color       Hover & voted border / background color.
 *   --cmv-hover-text-color  Hover & voted text / icon-on-bg color.
 *   --cmv-text-color        Idle label text color.
 */

/* ── Container ─────────────────────────────────────────────────────────── */

.cmv-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 1.25rem 0;
}

/* ── Button ─────────────────────────────────────────────────────────────── */

.cmv-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px 7px 12px;
  background: transparent;
  border: 1.5px solid var(--cmv-outline-color, #888888);
  border-radius: 100px;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
  line-height: 1;
  color: var(--cmv-button-color, #888888);
  transition:
    color 0.18s ease,
    background-color 0.18s ease,
    border-color 0.18s ease;
  -webkit-user-select: none;
      user-select: none;
}

.cmv-wrap .cmv-button:hover,
.cmv-wrap .cmv-button:focus-visible {
  background-color: transparent; /* block theme/builder from injecting a hover background */
  color: var(--cmv-hover-text-color, var(--cmv-hover-color, #e0245e));
  border-color: var(--cmv-hover-color, #e0245e);
}

.cmv-wrap .cmv-button:focus-visible {
  outline: 2px solid var(--cmv-hover-color, #e0245e);
  outline-offset: 3px;
}

.cmv-wrap .cmv-button.cmv-voted {
  color: var(--cmv-hover-text-color, var(--cmv-hover-color, #e0245e));
  border-color: var(--cmv-hover-color, #e0245e);
}

.cmv-button:disabled,
.cmv-button.cmv-loading {
  opacity: 0.55;
  cursor: default;
  pointer-events: none;
}

/* ── Solid style ─────────────────────────────────────────────────────────── */

.cmv-wrap.cmv-style-solid .cmv-button {
  background: var(--cmv-button-color, #888888);
  color: var(--cmv-text-color, #ffffff);
  border-color: var(--cmv-outline-color, var(--cmv-button-color, #888888));
}

.cmv-wrap.cmv-style-solid .cmv-button:hover,
.cmv-wrap.cmv-style-solid .cmv-button:focus-visible,
.cmv-wrap.cmv-style-solid .cmv-button.cmv-voted {
  background: var(--cmv-hover-color, #e0245e);
  border-color: var(--cmv-hover-color, #e0245e);
  color: var(--cmv-hover-text-color, var(--cmv-text-color, #ffffff));
}

/* ── Icon group ──────────────────────────────────────────────────────────── */

.cmv-icon-group {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

/* ── Label text ─────────────────────────────────────────────────────────── */

.cmv-label {
  color: var(--cmv-text-color, currentColor);
  transition: color 0.18s ease;
}

.cmv-wrap .cmv-button:hover .cmv-label,
.cmv-wrap .cmv-button:focus-visible .cmv-label,
.cmv-wrap .cmv-button.cmv-voted .cmv-label {
  color: var(--cmv-hover-text-color, var(--cmv-hover-color, #e0245e));
}

.cmv-wrap.cmv-style-solid .cmv-button:hover .cmv-label,
.cmv-wrap.cmv-style-solid .cmv-button:focus-visible .cmv-label,
.cmv-wrap.cmv-style-solid .cmv-button.cmv-voted .cmv-label {
  color: var(--cmv-hover-text-color, var(--cmv-text-color, #ffffff));
}

/* ── Icon right: icon+count appears after the label ─────────────────────── */

.cmv-button.cmv-icon-right .cmv-icon-group {
  order: 2;
}

.cmv-button.cmv-icon-right .cmv-label {
  order: 1;
}

/* ── Shared icon base ───────────────────────────────────────────────────── */

.cmv-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* ── Heart SVG ──────────────────────────────────────────────────────────── */

.cmv-heart {
  fill: none;
  stroke: var(--cmv-heart-color, var(--cmv-button-color, #888888));
  stroke-width: 1.8;
  transition:
    fill 0.18s ease,
    stroke 0.18s ease;
}

.cmv-wrap .cmv-button:hover .cmv-heart,
.cmv-wrap .cmv-button:focus-visible .cmv-heart {
  stroke: var(--cmv-hover-color, #e0245e);
}

/* When voted: filled heart */
.cmv-wrap .cmv-button.cmv-voted .cmv-heart {
  fill: var(--cmv-hover-color, #e0245e);
  stroke: var(--cmv-hover-color, #e0245e);
}

/* Solid style heart — inherits text color */
.cmv-wrap.cmv-style-solid .cmv-button .cmv-heart {
  stroke: var(--cmv-heart-color, var(--cmv-text-color, #ffffff));
}

.cmv-wrap.cmv-style-solid .cmv-button:hover .cmv-heart,
.cmv-wrap.cmv-style-solid .cmv-button:focus-visible .cmv-heart {
  stroke: var(--cmv-heart-color, var(--cmv-text-color, #ffffff));
}

.cmv-wrap.cmv-style-solid .cmv-button.cmv-voted .cmv-heart {
  fill: var(--cmv-heart-color, var(--cmv-text-color, #ffffff));
  stroke: var(--cmv-heart-color, var(--cmv-text-color, #ffffff));
}

/* ── Checkbox SVG ───────────────────────────────────────────────────────── */

/* The square border */
.cmv-checkbox .cmv-check-box {
  fill: none;
  stroke: var(--cmv-heart-color, var(--cmv-button-color, #888888));
  stroke-width: 1.8;
  transition:
    fill 0.18s ease,
    stroke 0.18s ease;
}

/* The checkmark polyline — hidden until hover/voted */
.cmv-checkbox .cmv-check {
  fill: none;
  stroke: transparent;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke 0.18s ease;
}

/* Hover: border and checkmark hint appear */
.cmv-wrap .cmv-button:hover .cmv-checkbox .cmv-check-box,
.cmv-wrap .cmv-button:focus-visible .cmv-checkbox .cmv-check-box {
  stroke: var(--cmv-hover-color, #e0245e);
}

.cmv-wrap .cmv-button:hover .cmv-checkbox .cmv-check,
.cmv-wrap .cmv-button:focus-visible .cmv-checkbox .cmv-check {
  stroke: var(--cmv-hover-color, #e0245e);
}

/* Voted: filled square with contrast checkmark */
.cmv-wrap .cmv-button.cmv-voted .cmv-checkbox .cmv-check-box {
  fill: var(--cmv-hover-color, #e0245e);
  stroke: var(--cmv-hover-color, #e0245e);
}

.cmv-wrap .cmv-button.cmv-voted .cmv-checkbox .cmv-check {
  stroke: var(--cmv-hover-text-color, #ffffff);
}

/* Solid style checkbox — idle */
.cmv-wrap.cmv-style-solid .cmv-button .cmv-checkbox .cmv-check-box {
  stroke: var(--cmv-heart-color, var(--cmv-text-color, #ffffff));
}

/* Solid style checkbox — hover */
.cmv-wrap.cmv-style-solid .cmv-button:hover .cmv-checkbox .cmv-check-box,
.cmv-wrap.cmv-style-solid .cmv-button:focus-visible .cmv-checkbox .cmv-check-box {
  stroke: var(--cmv-heart-color, var(--cmv-text-color, #ffffff));
}

.cmv-wrap.cmv-style-solid .cmv-button:hover .cmv-checkbox .cmv-check,
.cmv-wrap.cmv-style-solid .cmv-button:focus-visible .cmv-checkbox .cmv-check {
  stroke: var(--cmv-heart-color, var(--cmv-text-color, #ffffff));
}

/* Solid style checkbox — voted */
.cmv-wrap.cmv-style-solid .cmv-button.cmv-voted .cmv-checkbox .cmv-check-box {
  fill: var(--cmv-heart-color, var(--cmv-text-color, #ffffff));
  stroke: var(--cmv-heart-color, var(--cmv-text-color, #ffffff));
}

.cmv-wrap.cmv-style-solid .cmv-button.cmv-voted .cmv-checkbox .cmv-check {
  stroke: var(--cmv-hover-color, #e0245e);
}

/* ── Count ──────────────────────────────────────────────────────────────── */

.cmv-count {
  font-variant-numeric: tabular-nums;
  min-width: 1ch; /* prevents layout shift when count changes width */
}

/* ── Top Voted leaderboard shortcode ───────────────────────────────────── */

/**
 * Class reference:
 *   .cmv-top-voted            Outer wrapper (ol or div).
 *   .cmv-top-voted--list      Applied when template="list" (ordered list).
 *   .cmv-top-voted--grid      Applied when template="grid" (CSS grid).
 *   .cmv-top-voted__item      Each post row / card.
 *   .cmv-top-voted__link      Post title anchor.
 *   .cmv-top-voted__count     Vote count badge.
 */

.cmv-top-voted {
  margin: 1.25rem 0;
  padding: 0;
}

/* ── List template ────────────────────────────────────────────────────── */

ol.cmv-top-voted--list {
  list-style: none;
  counter-reset: cmv-rank;
}

.cmv-top-voted--list .cmv-top-voted__item {
  counter-increment: cmv-rank;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.07);
}

.cmv-top-voted--list .cmv-top-voted__item:last-child {
  border-bottom: none;
}

.cmv-top-voted--list .cmv-top-voted__item::before {
  content: counter(cmv-rank);
  min-width: 1.75rem;
  font-size: 0.8rem;
  color: #999;
  flex-shrink: 0;
  text-align: right;
}

.cmv-top-voted--list .cmv-top-voted__link {
  flex: 1;
}

/* ── Grid template ────────────────────────────────────────────────────── */

.cmv-top-voted--grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.cmv-top-voted--grid .cmv-top-voted__item {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 1rem;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 6px;
}

/* ── Shared elements ─────────────────────────────────────────────────── */

.cmv-top-voted__link {
  text-decoration: none;
  color: inherit;
}

.cmv-top-voted__link:hover {
  text-decoration: underline;
}

.cmv-top-voted__count {
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  color: #888;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Pop animation ──────────────────────────────────────────────────────── */

@keyframes cmv-pop {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.35); }
  65%  { transform: scale(0.88); }
  85%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: no-preference) {
  .cmv-button.cmv-pop .cmv-heart,
  .cmv-button.cmv-pop .cmv-checkbox {
    animation: cmv-pop 0.42s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
  }
}
