/**
 * Styled Form Component CSS
 *
 * Uses CSS variables from FormStyle model:
 * - --form-primary-color
 * - --form-background-color
 * - --form-text-color
 * - --form-font-family
 * - --form-border-radius
 */

.styled-form-shell {
  background-color: var(--form-background-color, #ffffff);
}

.styled-form {
  background-color: #ffffff;
  color: var(--form-text-color, #1a1a1a);
  font-family: var(--form-font-family, Inter), system-ui, sans-serif;
  padding: 1.5rem;
  border-bottom-left-radius: var(--form-border-radius, 4px);
  border-bottom-right-radius: var(--form-border-radius, 4px);
  border-top: none;
  border-bottom: 1px solid #e5e7eb;
  border-left: 1px solid #e5e7eb;
  border-right: 1px solid #e5e7eb;
  box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  max-width: 36rem;
  margin: 0 auto;
}

/* Remove borders and shadow when using Tailwind overrides (e.g., in preview) */
.styled-form.border-0 {
  border: none;
}

.styled-form.shadow-none {
  box-shadow: none;
}

.styled-form.m-0 {
  margin: 0;
  max-width: none;
}

/* Form header */
.styled-form-header h1 {
  color: var(--form-text-color, #1a1a1a);
  font-family: var(--form-header-font-family, var(--form-font-family, Inter)), system-ui, sans-serif;
  font-size: var(--form-header-font-size, 1.5rem);
}

.styled-form-header p,
.styled-form-header div {
  color: var(--form-text-color, #1a1a1a);
}

.styled-form-header p,
.styled-form-header .styled-form-header-text,
.styled-form-header .styled-form-header-text * {
  font-family: var(--form-text-font-family, var(--form-font-family, Inter)), system-ui, sans-serif !important;
  font-size: var(--form-text-font-size, 0.875rem) !important;
}

/* Input base styles */
.styled-form input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]),
.styled-form select,
.styled-form textarea {
  border-radius: var(--form-border-radius, 4px);
  width: 100%;
  padding: 0.625rem 0.875rem;
  font-family: var(--form-question-font-family, var(--form-font-family, Inter)), system-ui, sans-serif;
  font-size: var(--form-label-size, 0.875rem);
  line-height: 1.5rem;
  color: var(--form-text-color, #1a1a1a);
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

/* Boxed input style (default) */
.styled-form[data-input-style="boxed"] input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]),
.styled-form[data-input-style="boxed"] select,
.styled-form[data-input-style="boxed"] textarea {
  border: 1px solid var(--form-input-border-color, #9ca3af);
  background-color: var(--form-input-bg-color, #ffffff);
}

.styled-form[data-input-style="boxed"] input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):hover,
.styled-form[data-input-style="boxed"] select:hover,
.styled-form[data-input-style="boxed"] textarea:hover {
  border-color: color-mix(in srgb, var(--form-input-border-color, #9ca3af) 80%, black);
}

/* Underlined input style */
.styled-form[data-input-style="underlined"] input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]),
.styled-form[data-input-style="underlined"] select,
.styled-form[data-input-style="underlined"] textarea {
  border: none;
  border-bottom: 1px solid var(--form-input-border-color, #d1d5db);
  border-radius: 0;
  background-color: transparent;
  padding-left: 0;
  padding-right: 0;
}

.styled-form[data-input-style="underlined"] input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):hover,
.styled-form[data-input-style="underlined"] select:hover,
.styled-form[data-input-style="underlined"] textarea:hover {
  border-bottom-color: color-mix(in srgb, var(--form-input-border-color, #9ca3af) 80%, black);
}

/* Focus states with primary color */
.styled-form input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):focus,
.styled-form select:focus,
.styled-form textarea:focus {
  outline: none;
  border-color: var(--form-primary-color, #0058ff);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--form-primary-color, #0058ff) 20%, transparent);
}

.styled-form[data-input-style="underlined"] input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):focus,
.styled-form[data-input-style="underlined"] select:focus,
.styled-form[data-input-style="underlined"] textarea:focus {
  box-shadow: none;
  border-bottom-color: var(--form-primary-color, #0058ff);
  border-bottom-width: 2px;
}

/* Phone input wrapper - unified styling for country code + phone number */
.styled-form .phone-input-wrapper {
  border: 1px solid var(--form-input-border-color, #9ca3af);
  border-radius: var(--form-border-radius, 4px);
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.styled-form .phone-input-wrapper:hover {
  border-color: #6b7280;
}

.styled-form .phone-input-wrapper:focus-within {
  border-color: var(--form-primary-color, #0058ff);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--form-primary-color, #0058ff) 20%, transparent);
}

/* Phone input field inside wrapper - remove default input styling */
.styled-form .phone-input-wrapper .phone-input-field {
  border: none !important;
  box-shadow: none !important;
  border-radius: 0 !important;
}

.styled-form .phone-input-wrapper .phone-input-field:focus {
  border: none !important;
  box-shadow: none !important;
}

/* Underlined style for phone input */
.styled-form[data-input-style="underlined"] .phone-input-wrapper {
  border: none;
  border-bottom: 1px solid var(--form-input-border-color, #d1d5db);
  border-radius: 0;
}

.styled-form[data-input-style="underlined"] .phone-input-wrapper:hover {
  border-bottom-color: #9ca3af;
}

.styled-form[data-input-style="underlined"] .phone-input-wrapper:focus-within {
  box-shadow: none;
  border-bottom-color: var(--form-primary-color, #0058ff);
  border-bottom-width: 2px;
}

/* Checkbox and radio styling */
.styled-form input[type="checkbox"],
.styled-form input[type="radio"] {
  accent-color: var(--form-primary-color, #0058ff);
  color: var(--form-primary-color, #0058ff) !important;
}

.styled-form input[type="checkbox"]:checked {
  background-color: var(--form-primary-color, #0058ff) !important;
  border-color: var(--form-primary-color, #0058ff) !important;
}

.styled-form input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 1px solid #d1d5db;
  border-radius: 9999px;
  background-color: #ffffff;
  flex-shrink: 0;
}

.styled-form input[type="radio"]::before {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 9999px;
  transform: translate(-50%, -50%) scale(0);
  transition: transform 120ms ease-in-out;
  background-color: var(--form-primary-color, #0058ff);
}

.styled-form input[type="radio"]:checked {
  border-color: var(--form-primary-color, #0058ff) !important;
  background-color: #ffffff !important;
  background-image: none !important;
}

.styled-form input[type="radio"]:checked::before {
  transform: translate(-50%, -50%) scale(1);
}

.styled-form input[type="checkbox"]:focus,
.styled-form input[type="radio"]:focus {
  --tw-ring-color: color-mix(in srgb, var(--form-primary-color, #0058ff) 45%, transparent) !important;
  border-color: var(--form-primary-color, #0058ff) !important;
}

.styled-form input[type="checkbox"]:checked + div,
.styled-form input[type="radio"]:checked + div {
  background-color: var(--form-primary-color, #0058ff) !important;
}

/* Labels */
.styled-form label {
  color: var(--form-text-color, #1a1a1a);
  font-family: var(--form-question-font-family, var(--form-font-family, Inter)), system-ui, sans-serif;
  font-size: var(--form-label-size, 0.875rem);
}

.styled-form .paragraph-preview,
.styled-form .paragraph-preview *,
.styled-form .styled-form-text,
.styled-form .styled-form-text *,
.styled-form .styled-form-terms-scroll,
.styled-form .styled-form-terms-scroll *,
.styled-form .styled-form-help-text,
.styled-form .styled-form-help-text * {
  font-family: var(--form-text-font-family, var(--form-font-family, Inter)), system-ui, sans-serif !important;
  font-size: var(--form-text-font-size, 0.875rem) !important;
}

.styled-form .styled-form-section-heading,
.styled-form .styled-form-state-title {
  font-family: var(--form-header-font-family, var(--form-font-family, Inter)), system-ui, sans-serif;
  font-size: var(--form-header-font-size, 1.5rem);
}

.styled-form .styled-form-state-text,
.styled-form .styled-form-state-text * {
  font-family: var(--form-text-font-family, var(--form-font-family, Inter)), system-ui, sans-serif !important;
  font-size: var(--form-text-font-size, 0.875rem) !important;
}

.styled-form .styled-form-text.text-sm,
.styled-form .styled-form-text.text-sm *,
.styled-form .styled-form-terms-scroll.text-sm,
.styled-form .styled-form-terms-scroll.text-sm * {
  font-size: 0.875rem !important;
}

.styled-form .styled-form-text.text-base,
.styled-form .styled-form-text.text-base *,
.styled-form .styled-form-terms-scroll.text-base,
.styled-form .styled-form-terms-scroll.text-base * {
  font-size: 1rem !important;
}

.styled-form .styled-form-text.text-lg,
.styled-form .styled-form-text.text-lg *,
.styled-form .styled-form-terms-scroll.text-lg,
.styled-form .styled-form-terms-scroll.text-lg * {
  font-size: 1.125rem !important;
}

.styled-form .styled-form-text.text-xl,
.styled-form .styled-form-text.text-xl *,
.styled-form .styled-form-terms-scroll.text-xl,
.styled-form .styled-form-terms-scroll.text-xl * {
  font-size: 1.25rem !important;
}

.styled-form .styled-form-text.text-2xl,
.styled-form .styled-form-text.text-2xl *,
.styled-form .styled-form-terms-scroll.text-2xl,
.styled-form .styled-form-terms-scroll.text-2xl * {
  font-size: 1.5rem !important;
}

/* Increase gap between label and input in styled forms */
.styled-form [data-slot="field"] {
  gap: 0.625rem;
}

/* Placeholder color */
.styled-form input::placeholder,
.styled-form textarea::placeholder {
  color: var(--form-placeholder-color, #9ca3af);
}

.styled-form select option[value=""] {
  color: var(--form-placeholder-color, #9ca3af);
}

/* Tighter label-to-input gap for underlined style */
.styled-form[data-input-style="underlined"] label.mb-2 {
  margin-bottom: 0.25rem !important;
}

.styled-form[data-input-style="underlined"] input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]),
.styled-form[data-input-style="underlined"] select,
.styled-form[data-input-style="underlined"] textarea {
  padding-top: 0.125rem;
  padding-bottom: 0.375rem;
}

/* Submit button */
.styled-form-submit {
  background-color: var(--form-primary-color, #0058ff);
  color: #ffffff;
  padding: 0.75rem 2rem;
  border-radius: var(--form-border-radius, 4px);
  font-weight: 500;
  font-size: 0.875rem;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s ease-in-out, transform 0.1s ease-in-out;
}

.styled-form-submit:hover {
  opacity: 0.9;
}

.styled-form-submit:active {
  transform: scale(0.98);
}

.styled-form-submit:focus {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--form-primary-color, #0058ff) 30%, transparent);
}

.styled-form-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Tagify select styling */
.styled-form .tagify {
  --tags-focus-border-color: var(--form-primary-color, #0058ff);
  --tag-bg: #f3f4f6;
  --tag-hover: #e5e7eb;
  --tag-text-color: var(--form-text-color, #1a1a1a);
  --tag-text-color--edit: var(--form-text-color, #1a1a1a);
  --tag-remove-btn-color: #6b7280;
  --tag-remove-btn-bg--hover: #e5e7eb;
}

.styled-form .tagify--focus {
  --tags-border-color: var(--form-primary-color, #0058ff) !important;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--form-primary-color, #0058ff) 20%, transparent) !important;
}

.styled-form .tagify--select.tagify--focus {
  --tags-border-color: var(--form-primary-color, #0058ff) !important;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--form-primary-color, #0058ff) 20%, transparent) !important;
}

.styled-form .tagify__tag > div,
.styled-form .tagify--select .tagify__tag > div {
  color: var(--form-text-color, #1a1a1a) !important;
}

.styled-form .tagify__dropdown {
  --tagify-dd-color-primary: var(--form-primary-color, #0058ff);
}

.styled-form .tagify__dropdown__item--active {
  background: color-mix(in srgb, var(--form-primary-color, #0058ff) 10%, white) !important;
}

.styled-form .tagify__dropdown__item:hover,
.styled-form .tagify__dropdown__item--active {
  background: color-mix(in srgb, var(--form-primary-color, #0058ff) 12%, white) !important;
}

.styled-form .tagify__dropdown__item--active .font-medium,
.styled-form .tagify__dropdown__item--active {
  color: var(--form-text-color, #1a1a1a) !important;
}

/* Error messages */
.styled-form-errors {
  color: #b91c1c;
}

/* Terms and conditions */
.styled-form-terms {
  border-radius: var(--form-border-radius, 4px);
  background-color: transparent;
}

.styled-form-terms-scroll::-webkit-scrollbar { width: 4px; }
.styled-form-terms-scroll::-webkit-scrollbar-track { background: transparent; }
.styled-form-terms-scroll::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 9999px; }
.styled-form-terms-scroll::-webkit-scrollbar-thumb:hover { background: #64748b; }
.styled-form-terms-scroll { scrollbar-width: thin; scrollbar-color: #94a3b8 transparent; }

/* Banner */
.styled-form-banner {
  aspect-ratio: 1242 / 568;
  box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
}

.styled-form-banner.shadow-none {
  box-shadow: none;
}

.styled-form-banner img {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

@media (min-width: 1024px) {
  .styled-form-banner img {
    border-top-left-radius: var(--form-border-radius, 4px);
    border-top-right-radius: var(--form-border-radius, 4px);
  }
}

/* Restore native date/time picker icons (Tailwind v4 hides them) */
/* Make clicking anywhere on the input open the picker dropdown */
.styled-form input[type="time"],
.styled-form input[type="date"] {
  position: relative;
  cursor: pointer;
}

.styled-form input[type="time"]::-webkit-calendar-picker-indicator,
.styled-form input[type="date"]::-webkit-calendar-picker-indicator {
  background: revert;
  cursor: pointer;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
}

/* Hidden field (conditional visibility) */
.styled-form [data-hidden="true"] {
  display: none;
}

/* Collapse question-row grid when all its children are conditionally hidden,
   so parent row spacing doesn't stack empty-row margins into a blank gap. */
.form-question-row:not(:has(> *:not(.hidden))) {
  display: none;
}

/* Preview mode - transparent background */
.styled-form--preview {
  background-color: transparent !important;
  box-shadow: none !important;
}

/* Softer bold text in form content */
.styled-form .lexxy-content {
  color: inherit;
}

.styled-form .styled-form-state-text .lexxy-content {
  text-align: left;
}

.styled-form .lexxy-content p {
  line-height: 1.55;
  margin: 0 0 0.5rem;
}

.styled-form .lexxy-content p:last-child {
  margin-bottom: 0;
}

.styled-form .lexxy-content ul,
.styled-form .lexxy-content ol {
  margin-bottom: 0.5rem;
  padding-left: 1.5rem;
  list-style-position: outside;
}

.styled-form strong,
.styled-form b {
  font-weight: 600;
  color: inherit;
}
