.ucw-overlay {
  position: fixed;
  inset: 0;
  z-index: 10020;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgb(15 23 42 / 0.62);
  backdrop-filter: blur(6px);
}

.ucw-modal {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(100%, 42rem);
  max-height: min(90vh, 52rem);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  background: var(--white);
  color: var(--text);
  box-shadow: 0 24px 70px rgb(15 23 42 / 0.28);
}

.ucw-close {
  position: absolute;
  top: 0.85rem;
  right: 0.85rem;
  z-index: 101;
  display: grid;
  width: 2.25rem;
  height: 2.25rem;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 1px 4px rgb(15 23 42 / 0.08);
}

.ucw-close:hover,
.ucw-close:focus-visible {
  background: var(--bg);
  color: var(--text);
}

/* Explicit resets: main.css globally styles the bare `header` element
   (sticky, z-index 100, background, shadow), which would otherwise cover
   the close button and float this header inside the modal. */
.ucw-header {
  position: static;
  z-index: auto;
  flex-shrink: 0;
  padding: 2rem 2rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: transparent;
  box-shadow: none;
}

.ucw-eyebrow {
  margin: 0 2.5rem 0.65rem 0;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.055em;
  text-transform: uppercase;
}

.ucw-progress {
  height: 0.35rem;
  margin-bottom: 1.35rem;
  overflow: hidden;
  border-radius: 999px;
  background: var(--bg);
}

.ucw-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width 180ms ease;
}

.ucw-header h2 {
  margin: 0;
  font-size: clamp(1.35rem, 4vw, 1.75rem);
  line-height: 1.2;
}

.ucw-header > p:last-child {
  margin: 0.6rem 0 0;
  color: var(--muted);
  font-size: 0.925rem;
  line-height: 1.55;
}

.ucw-form {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 2rem 2rem;
}

.ucw-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.1rem;
}

.ucw-field,
.ucw-fieldset {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 0.45rem;
}

.ucw-field > span:first-child,
.ucw-fieldset legend {
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 650;
}

/* Choice questions own the full row so their options never share a column
   with other fields. */
.ucw-fieldset {
  margin: 0;
  padding: 0;
  border: 0;
  grid-column: 1 / -1;
}

.ucw-input-wrap {
  position: relative;
  display: block;
}

.ucw-field input,
.ucw-field select,
.ucw-field textarea {
  width: 100%;
  min-height: 2.85rem;
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  background: var(--bg);
  color: var(--text);
  padding: 0.7rem 0.8rem;
  font: inherit;
}

.ucw-input-wrap input[aria-describedby] {
  padding-right: 4.5rem;
}

.ucw-unit {
  position: absolute;
  top: 50%;
  right: 0.8rem;
  max-width: 3.5rem;
  overflow: hidden;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 0.75rem;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.ucw-field input:focus,
.ucw-field select:focus,
.ucw-field textarea:focus,
.ucw-option:focus-within {
  border-color: var(--primary);
  outline: 3px solid color-mix(in srgb, var(--primary) 18%, transparent);
}

.ucw-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.ucw-option {
  display: flex;
  min-height: 2.7rem;
  align-items: center;
  gap: 0.55rem;
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  background: var(--bg);
  padding: 0.65rem 0.75rem;
  color: var(--text);
  font-size: 0.84rem;
  cursor: pointer;
}

.ucw-option input {
  accent-color: var(--primary);
}

.ucw-error {
  min-height: 1.25rem;
  margin: 1rem 0 0;
  color: #dc2626;
  font-size: 0.84rem;
}

[data-theme="dark"] .ucw-error {
  color: #fca5a5;
}

/* Reset main.css bare-`footer` styles (dark background, centered text). */
.ucw-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.6rem;
  padding: 0;
  background: transparent;
  text-align: left;
}

.ucw-btn {
  min-height: 2.75rem;
  border: 1px solid transparent;
  border-radius: 0.7rem;
  padding: 0.7rem 1.15rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

.ucw-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ucw-btn-primary {
  margin-left: auto;
  background: var(--primary);
  color: #fff;
}

.ucw-btn-primary:hover:not(:disabled) {
  filter: brightness(0.92);
}

.ucw-btn-secondary {
  border-color: var(--border);
  background: var(--white);
  color: var(--text);
}

.ucw-btn-secondary:hover:not(:disabled) {
  background: var(--bg);
}

.ucw-engine-frame {
  position: fixed;
  width: 1px;
  height: 1px;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

@media (max-width: 640px) {
  .ucw-overlay {
    align-items: end;
    padding: 0;
  }

  .ucw-modal {
    width: 100%;
    max-height: 94vh;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 1.25rem 1.25rem 0 0;
  }

  .ucw-header {
    padding: 1.5rem 1.25rem 1rem;
  }

  .ucw-form {
    padding: 1.25rem;
  }

  .ucw-grid,
  .ucw-options {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ucw-progress span {
    transition: none;
  }
}
