/* ==========================================================================
   AMQ Härtegrad-Rechner (Mattress Firmness Calculator)
   ==========================================================================
   Premium Light-Theme component for calculating mattress firmness grades.
   Uses BEM naming with `amq-hr` prefix.

   Compact form: two number fields, sleep-position buttons and a submit
   button. Pressing "Empfehlung berechnen" swaps the form (.amq-hr__form) for
   the result view; "Angaben ändern" swaps back. The active view is driven by
   data-view on the .amq-hr root.

   Data-state driven result display:
     data-state="found"      → accent badge with the single grade
     data-state="transition" → accent badge for a Grenzbereich grade
     data-state="not-found"  → subtle warning
   ========================================================================== */

.amq-hr {
  /* ── Design Tokens (Custom Light Theme) ────────────────────────────── */
  --amq-hr-bg-start:     #ffffff;
  --amq-hr-bg-end:       #ffffff;
  --amq-hr-border:       #e9edf2;
  --amq-hr-card-shadow:  0 12px 30px -8px rgba(0, 52, 102, 0.12), 0 4px 12px -4px rgba(0, 52, 102, 0.06);

  --amq-hr-accent:       #003466;
  --amq-hr-accent-light: #7290AC;
  --amq-hr-accent-glow:  rgba(0, 52, 102, 0.08);

  --amq-hr-red:          #E66721;
  --amq-hr-red-soft:     #FFF0E2;
  --amq-hr-red-border:   #FAC898;
  --amq-hr-red-text:     #E66721;

  --amq-hr-white:        #ffffff;
  --amq-hr-text:         #003466;
  --amq-hr-label:        #2E2D2C;
  --amq-hr-text-muted:   #335c85;
  --amq-hr-text-dim:     #6685a3;

  --amq-hr-badge-bg:     #f5f7f9;
  --amq-hr-badge-border: #dde3ea;

  /* Hairline separators between form sections and around the trust strip. */
  --amq-hr-divider:      #edf1f5;

  --amq-hr-font: 'Lato', sans-serif;

  --amq-hr-gap:    1.375rem;
  --amq-hr-radius: 12px;
  --amq-hr-radius-sm: 8px;
  --amq-hr-radius-xs: 8px;

  /* Desktop width: px instead of rem so a theme's root font-size
     (e.g. html { font-size: 62.5% }) cannot shrink the card. */
  --amq-hr-max-width: 580px;

  --amq-hr-ease:     cubic-bezier(.4, 0, .2, 1);
  --amq-hr-ease-out: cubic-bezier(.0, 0, .2, 1);
  --amq-hr-duration: .35s;
}

/* ── Block: .amq-hr ─────────────────────────────────────────────────────── */
.amq-hr {
  position: relative;
  width: 100%;
  max-width: var(--amq-hr-max-width);
  margin-left: auto;
  margin-right: auto;
  font-family: var(--amq-hr-font);
  color: var(--amq-hr-text);
  /* Plain white card – saved bg_start/bg_end options must not tint it. */
  background: var(--amq-hr-white) !important;
  border: 1px solid var(--amq-hr-border);
  border-radius: var(--amq-hr-radius);
  padding: clamp(1.375rem, 4.4vw, 2.2rem);
  box-shadow: var(--amq-hr-card-shadow);
  overflow: hidden;
  box-sizing: border-box;
}

.amq-hr *,
.amq-hr *::before,
.amq-hr *::after {
  box-sizing: border-box;
}

/* ── Element: .amq-hr__header ───────────────────────────────────────────── */
.amq-hr__header {
  position: relative;
  z-index: 1;
  margin-bottom: 1.375rem;
}

.amq-hr__title {
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--amq-hr-text);
  margin: 0 0 .33rem;
}

.amq-hr__subtitle {
  font-size: .96rem;
  color: var(--amq-hr-text-muted);
  margin: 0;
}

/* ── Element: .amq-hr__empty ────────────────────────────────────────────── */
.amq-hr__empty {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 2rem 1rem;
  color: var(--amq-hr-text-dim);
  font-style: italic;
}

.amq-hr__empty p {
  margin: 0;
}

/* ── Element: .amq-hr__inputs ───────────────────────────────────────────── */
.amq-hr__inputs {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--amq-hr-gap);
}

/* ── Element: .amq-hr__field ────────────────────────────────────────────── */
.amq-hr__field {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  min-width: 0;
}

/* ── Element: .amq-hr__label ────────────────────────────────────────────── */
.amq-hr__label {
  font-family: 'Lato', sans-serif !important;
  font-size: 17px !important;
  font-weight: 700 !important;
  text-transform: none !important;
  letter-spacing: normal !important;
  color: var(--amq-hr-label) !important;
  margin: 0 !important;
}

/* ── Element: .amq-hr__input ────────────────────────────────────────────── */
.amq-hr__input {
  width: 100% !important;
  height: auto !important;
  margin: 0 !important;
  padding: .77rem .94rem !important;
  background: var(--amq-hr-badge-bg) !important;
  border: 1px solid var(--amq-hr-badge-border) !important;
  border-radius: var(--amq-hr-radius-xs) !important;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.04) !important;
  font-family: inherit !important;
  font-size: 1rem !important;
  font-weight: 600 !important;
  color: var(--amq-hr-text) !important;
  text-align: left !important;
  outline: none !important;
  -moz-appearance: textfield !important;
  transition: border-color var(--amq-hr-duration) var(--amq-hr-ease),
              box-shadow var(--amq-hr-duration) var(--amq-hr-ease);
}

.amq-hr__input:focus {
  background: var(--amq-hr-white) !important;
  border-color: var(--amq-hr-accent) !important;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.04), 0 0 0 3px var(--amq-hr-accent-glow) !important;
}

/* Spinners would fight the fixed width of the narrow field */
.amq-hr__input::-webkit-outer-spin-button,
.amq-hr__input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* ── Element: .amq-hr__positions ────────────────────────────────────────── */
.amq-hr__positions {
  position: relative;
  z-index: 1;
  margin-top: var(--amq-hr-gap);
  display: flex;
  flex-direction: column;
  gap: .4rem;
}

.amq-hr__position-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .66rem;
}

/* Themes bring their own button paint, and on :hover / :focus it lands on top
   of ours – white text on our white button was the result, plus an underline
   on the clicked one. Every colour here therefore insists. */
.amq-hr__position {
  display: block;
  width: 100%;
  margin: 0;
  padding: .77rem .55rem;
  background: var(--amq-hr-white) !important;
  border: 2px solid var(--amq-hr-badge-border) !important;
  border-radius: var(--amq-hr-radius-xs);
  font-family: inherit;
  font-size: 1.03rem;
  font-weight: 500;
  line-height: 1.2;
  color: var(--amq-hr-text) !important;
  text-align: center;
  text-transform: none;
  text-decoration: none !important;
  box-shadow: none !important;
  cursor: pointer;
  transition: border-color var(--amq-hr-duration) var(--amq-hr-ease),
              background-color var(--amq-hr-duration) var(--amq-hr-ease),
              color var(--amq-hr-duration) var(--amq-hr-ease);
}

/* Hover and selection read as a blue outline – the button keeps its white
   fill and dark label, only the border marks the choice.
   Prefixed with .amq-hr so we also outweigh themes that style their buttons
   through two classes. */
.amq-hr .amq-hr__position:hover,
.amq-hr .amq-hr__position:focus,
.amq-hr .amq-hr__position:active,
.amq-hr .amq-hr__position--active,
.amq-hr .amq-hr__position--active:hover,
.amq-hr .amq-hr__position--active:focus {
  background: var(--amq-hr-white) !important;
  border-color: var(--amq-hr-accent) !important;
  color: var(--amq-hr-text) !important;
  text-decoration: none !important;
}

.amq-hr__position:focus-visible {
  outline: 2px solid var(--amq-hr-accent-light);
  outline-offset: 2px;
}

/* ── Element: .amq-hr__submit ───────────────────────────────────────────── */
.amq-hr__submit-wrap {
  position: relative;
  z-index: 1;
  margin-top: var(--amq-hr-gap);
  padding-top: var(--amq-hr-gap);
  border-top: 1px solid var(--amq-hr-divider);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
}

/* Themes paint their own buttons; every colour here insists so the accent
   fill and white label survive :hover / :focus. */
.amq-hr .amq-hr__submit,
.amq-hr .amq-hr__apply {
  display: block;
  width: 100%;
  margin: 0;
  padding: .94rem 1.1rem;
  background: var(--amq-hr-accent) !important;
  border: 1px solid var(--amq-hr-accent) !important;
  border-radius: var(--amq-hr-radius-xs);
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--amq-hr-white) !important;
  text-align: center;
  text-transform: none;
  text-decoration: none !important;
  box-shadow: 0 3px 10px var(--amq-hr-accent-glow) !important;
  cursor: pointer;
  transition: background-color var(--amq-hr-duration) var(--amq-hr-ease),
              border-color var(--amq-hr-duration) var(--amq-hr-ease),
              box-shadow var(--amq-hr-duration) var(--amq-hr-ease);
}

.amq-hr .amq-hr__submit:hover,
.amq-hr .amq-hr__submit:focus,
.amq-hr .amq-hr__submit:active,
.amq-hr .amq-hr__apply:hover,
.amq-hr .amq-hr__apply:focus,
.amq-hr .amq-hr__apply:active {
  background: var(--amq-hr-accent-light) !important;
  border-color: var(--amq-hr-accent-light) !important;
  color: var(--amq-hr-white) !important;
  text-decoration: none !important;
}

.amq-hr__submit:focus-visible,
.amq-hr__apply:focus-visible {
  outline: 2px solid var(--amq-hr-accent-light);
  outline-offset: 2px;
}

/* Loading state: hide the label and center a spinner while the short
   calculation delay runs. */
.amq-hr .amq-hr__submit--loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
  cursor: default;
}

.amq-hr .amq-hr__submit--loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1.15rem;
  height: 1.15rem;
  margin: -0.575rem 0 0 -0.575rem;
  border: 2px solid rgba(255, 255, 255, .45);
  border-top-color: var(--amq-hr-white);
  border-radius: 50%;
  animation: amqHrSpin 1.5s linear infinite;
}

@keyframes amqHrSpin {
  to {
    transform: rotate(360deg);
  }
}

/* Full-bleed pill strip at the bottom of the result view. */
.amq-hr__badges {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  gap: .55rem;
  margin: var(--amq-hr-gap) calc(-1 * clamp(1.375rem, 4.4vw, 2.2rem)) calc(-1 * clamp(1.375rem, 4.4vw, 2.2rem));
  padding: 1.21rem clamp(1.375rem, 4.4vw, 2.2rem);
  border-top: 1px solid var(--amq-hr-divider);
  background: #f7f9fb;
}

.amq-hr__badge {
  display: inline-block;
  padding: .4rem .9rem;
  background: var(--amq-hr-white);
  border: 1px solid var(--amq-hr-badge-border);
  border-radius: 999px;
  font-size: .85rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--amq-hr-text);
  white-space: nowrap;
}

.amq-hr__error {
  margin: 0;
  font-size: .89rem;
  color: var(--amq-hr-red-text);
  text-align: center;
  line-height: 1.4;
}

/* ── View toggle: form ⇄ result (same popup, no size jump) ───────────────── */
.amq-hr[data-view="result"] .amq-hr__form {
  display: none;
}

.amq-hr[data-view="form"] .amq-hr__result {
  display: none;
}

/* ── Element: .amq-hr__actions ──────────────────────────────────────────── */
.amq-hr__actions {
  display: none;
  flex-direction: column;
  align-items: stretch;
  gap: .825rem;
  margin-top: var(--amq-hr-gap);
}

.amq-hr__result[data-state="found"] .amq-hr__actions,
.amq-hr__result[data-state="transition"] .amq-hr__actions,
.amq-hr__result[data-state="not-found"] .amq-hr__actions {
  display: flex;
}

/* No grade to transfer when nothing was found. */
.amq-hr__result[data-state="not-found"] .amq-hr__apply {
  display: none;
}

/* "Angaben ändern" reads as a quiet link, not a second button. */
.amq-hr .amq-hr__back {
  display: block;
  width: 100%;
  margin: 0;
  padding: .28rem;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  font-family: inherit;
  font-size: .96rem;
  font-weight: 500;
  line-height: 1.2;
  color: var(--amq-hr-text-muted) !important;
  text-align: center;
  text-transform: none;
  text-decoration: underline !important;
  cursor: pointer;
}

.amq-hr .amq-hr__back:hover,
.amq-hr .amq-hr__back:focus {
  color: var(--amq-hr-accent) !important;
  text-decoration: underline !important;
}

.amq-hr__back:focus-visible {
  outline: 2px solid var(--amq-hr-accent-light);
  outline-offset: 2px;
}

/* ── Element: .amq-hr__result ───────────────────────────────────────────── */
.amq-hr__result {
  position: relative;
  z-index: 1;
  min-height: 4.5rem;
}

.amq-hr__result-initial,
.amq-hr__result-found,
.amq-hr__result-transition,
.amq-hr__result-not-found {
  display: none;
}

.amq-hr__result[data-state="initial"]    > .amq-hr__result-initial,
.amq-hr__result[data-state="found"]      > .amq-hr__result-found,
.amq-hr__result[data-state="transition"] > .amq-hr__result-transition,
.amq-hr__result[data-state="not-found"]  > .amq-hr__result-not-found {
  display: flex;
  animation: amqHrFadeIn var(--amq-hr-duration) var(--amq-hr-ease-out) forwards;
}

@keyframes amqHrFadeIn {
  from {
    opacity: 0;
    transform: translateY(6px) scale(.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ── Result blocks ────────────────────────────────────────────── */
.amq-hr__result-initial,
.amq-hr__result-found,
.amq-hr__result-transition {
  flex-direction: column;
  align-items: flex-start;
  color: var(--amq-hr-text);
}

/* The label now sits above the card, not inside it. */
.amq-hr__result-box {
  width: 100%;
  padding: 1.1rem 1.27rem;
  border: 1px solid #e2e9f2;
  border-radius: 12px;
  background: #f5f8fc;
  box-shadow: none;
}

.amq-hr__result-not-found {
  flex-direction: row;
  align-items: center;
  gap: 1.27rem;
  padding: .25rem 0;
}

.amq-hr__result-not-found {
  border-radius: 0;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

.amq-hr__result-label {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--amq-hr-text);
  margin: 0 0 .35rem;
  text-align: left;
}

.amq-hr__result-sub {
  font-size: .96rem;
  color: var(--amq-hr-text-muted);
  line-height: 1.4;
  margin: 0 0 22px;
  text-align: left;
}

/* Badge und Text als eine Gruppe, oben ausgerichtet unter der Überschrift */
.amq-hr__result-body {
  display: flex;
  align-items: center;
  gap: .85rem;
}

.amq-hr__result-text {
  display: flex;
  flex-direction: column;
  gap: .15rem;
}

.amq-hr__result-grade {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-weight: 800;
  line-height: 1;
  letter-spacing: .04em;
  border-radius: var(--amq-hr-radius-xs);
  transition: transform var(--amq-hr-duration) var(--amq-hr-ease),
              box-shadow var(--amq-hr-duration) var(--amq-hr-ease);
}

.amq-hr__result-name {
  font-family: 'Lato', sans-serif !important;
  font-size: 17px !important;
  font-weight: 700 !important;
  text-transform: none !important;
  letter-spacing: normal !important;
  color: var(--amq-hr-label) !important;
  margin: 0 !important;
}

.amq-hr__result-range {
  font-size: .89rem;
  color: var(--amq-hr-text-muted);
  line-height: 1.4;
}

/* ── State: found ───────────────────────────────────────────────────────── */
.amq-hr__result-found .amq-hr__result-grade,
.amq-hr__result-transition .amq-hr__result-grade {
  font-size: 1.65rem;
  min-width: 3.6rem;
  padding: .55rem .77rem;
  border-radius: 10px;
  background: var(--amq-hr-accent);
  color: var(--amq-hr-white);
  box-shadow: 0 3px 10px var(--amq-hr-accent-glow);
}

/* ── State: not-found ───────────────────────────────────────────────────── */
.amq-hr__result-not-found {
  color: var(--amq-hr-red-text);
}

.amq-hr__result-not-found .amq-hr__result-text {
  font-size: .99rem;
  color: var(--amq-hr-red-text);
  line-height: 1.5;
}

/* ── Element: .amq-hr__trust ────────────────────────────────────────── */
/* Full-bleed strip at the bottom of the form: negative margins cancel the
   card padding so it reaches the rounded edges (clipped by overflow:hidden). */
.amq-hr__trust {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: var(--amq-hr-gap) calc(-1 * clamp(1.375rem, 4.4vw, 2.2rem)) calc(-1 * clamp(1.375rem, 4.4vw, 2.2rem));
  padding: 1.21rem clamp(1.375rem, 4.4vw, 2.2rem);
  border-top: 1px solid var(--amq-hr-divider);
  background: #f7f9fb;
}

.amq-hr__trust-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .15rem;
  text-align: center;
}

.amq-hr__trust-item + .amq-hr__trust-item {
  border-left: 1px solid var(--amq-hr-badge-border);
}

.amq-hr__trust-value {
  font-size: 1.375rem;
  font-weight: 800;
  line-height: 1.1;
  color: var(--amq-hr-accent);
}

.amq-hr__trust-label {
  font-size: .825rem;
  line-height: 1.3;
  color: var(--amq-hr-text-muted);
}

/* ── Responsive Adjustments ──────────────────────────────── */

@media (max-width: 767px) {
  .amq-hr {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }

  /* Clears the modal close button sitting in the top-right corner. */
  .amq-hr__result {
    padding-top: 1.25rem;
  }
}

@media (max-width: 380px) {
  .amq-hr {
    padding: 1rem;
  }

  /* Below this width the two fields would wrap their labels */
  .amq-hr__inputs {
    grid-template-columns: minmax(0, 1fr);
  }

  /* Match the reduced card padding so the strip stays flush. */
  .amq-hr__trust,
  .amq-hr__badges {
    margin: var(--amq-hr-gap) -1rem -1rem;
    padding: 1.1rem 1rem;
  }

  /* Not enough room for one line here. */
  .amq-hr__badges {
    flex-wrap: wrap;
  }
}

/* ── Accessibility: Reduced Motion ──────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .amq-hr__input,
  .amq-hr__position,
  .amq-hr__result-initial,
  .amq-hr__result-found,
  .amq-hr__result-not-found,
  .amq-hr__result-grade {
    transition: none;
    animation: none;
  }
}

/* ── Print Styles ───────────────────────────────────────────────────────── */
@media print {
  .amq-hr {
    background: #fff;
    color: #1a1a1a;
    border: 1px solid #ccc;
    box-shadow: none;
  }

  .amq-hr__input,
  .amq-hr__position {
    background: #f0f0f0;
    color: #1a1a1a;
    border-color: #ccc;
  }

  .amq-hr__label,
  .amq-hr__result-label,
  .amq-hr__result-desc {
    color: #555;
  }
}

.amq-hr__badges{
  display: none;
}
