:host {
    display: block;
    all: initial;
    font-family: var(--embed-font-body, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif);
    line-height: 1.5;
    box-sizing: border-box;
}

:host * {
    box-sizing: border-box;
}

.embed-container {
    background: var(--embed-bg-container, #ffffff);
    border: var(--embed-border-container, 1px solid #e5e5e5);
    border-radius: var(--embed-border-radius-container, 12px);
    padding: var(--embed-padding-container, 20px);
    box-shadow: var(--embed-shadow-container, 0 5px 15px rgba(0, 0, 0, 0.08));
    max-width: 400px;
    min-width: 360px;
    margin: 0 auto;
    color: #333;
}

/* Typography */
.embed-title {
    margin: 0 0 var(--embed-spacing-content, 15px) 0;
    color: var(--embed-color-title, #333333);
    font-family: var(--embed-font-title, inherit);
    font-size: var(--embed-font-size-title, 24px);
    font-weight: var(--embed-font-weight-title, 600);
    line-height: 1.2;
}

.embed-subtitle {
    margin: 0 0 var(--embed-spacing-content, 15px) 0;
    color: var(--embed-color-subtitle, #666666);
    font-size: var(--embed-font-size-subtitle, 16px);
}

/* Row Title & Description */
.embed-row-title {
    margin: 0 0 0.5rem 0;
    color: var(--embed-color-title, #333333);
    font-family: var(--embed-font-title, inherit);
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.3;
}

.embed-row-description {
    margin: 0 0 0.75rem 0;
    color: var(--embed-color-subtitle, #666666);
    font-size: 0.9rem;
    line-height: 1.5;
}

.embed-link {
    color: var(--embed-color-link, #667eea);
    text-decoration: none;
    cursor: pointer;
}

.embed-link:hover {
    text-decoration: underline;
}

.embed-privacy-text {
    font-size: 0.875rem;
    color: var(--embed-color-subtitle, #666666);
    margin-bottom: 10px;
}

.embed-privacy-text a {
    color: var(--embed-color-link, #667eea);
    text-decoration: underline;
}

/* Form Elements */
.embed-form-group {
    margin-bottom: var(--embed-spacing-input, 16px);
    position: relative;
}

/* Ensure form group with helper icon on hover has higher z-index than siblings */
.embed-form-group:has(.helper-icon:hover),
.embed-form-group:has(.helper-icon:focus) {
    z-index: 100;
}

.embed-grid {
    display: flex;
    gap: 10px;
    margin-bottom: var(--embed-spacing-input, 15px);
}

.embed-grid>* {
    min-width: 0;
    /* Prevent grid blowout */
}

.embed-input,
.embed-select,
.embed-textarea {
    display: block;
    width: 100%;
    padding: 8px 12px;
    background-color: var(--embed-bg-input, #ffffff);
    color: var(--embed-color-input, #333333);
    border: var(--embed-border-input, 1px solid #e5e5e5);
    border-radius: var(--embed-border-radius-input, 4px);
    font-size: var(--embed-font-size-input, 16px);
    font-family: inherit;
    transition: border-color 0.2s ease;
    appearance: none;
    -webkit-appearance: none;
}

.embed-input:focus,
.embed-select:focus,
.embed-textarea:focus {
    outline: none;
    border: var(--embed-border-focus-input, 1px solid #667eea);
}

.embed-input::placeholder,
.embed-textarea::placeholder {
    color: var(--embed-color-placeholder, #999999);
    opacity: 1;
}

.embed-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: var(--embed-font-size-label, 14px);
    color: var(--embed-color-label, #666666);
    cursor: pointer;
}

.input-helper-wrapper {
    position: relative;
}

.input-helper-wrapper .embed-input,
.input-helper-wrapper .embed-select,
.input-helper-wrapper .embed-textarea {
    padding-right: 38px;
}

.helper-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--embed-color-placeholder, #999999);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.helper-icon svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

.helper-icon::after {
    content: attr(data-tooltip);
    position: absolute;
    top: 130%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(51, 51, 51, 0.95);
    color: #fff;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 12px;
    line-height: 1.4;
    white-space: normal;
    min-width: 180px;
    max-width: 260px;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease-in-out, transform 0.2s ease-in-out;
    z-index: 10000;
}

.helper-icon::before {
    content: '';
    position: absolute;
    top: 120%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-bottom-color: rgba(51, 51, 51, 0.95);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease-in-out;
}

.helper-icon:hover::after,
.helper-icon:hover::before,
.helper-icon:focus::after,
.helper-icon:focus::before {
    opacity: 1;
    visibility: visible;
}

.helper-icon:focus::after {
    transform: translateX(-50%) translateY(2px);
}

.helper-icon-inline {
    position: relative;
    right: auto;
    top: auto;
    transform: none;
    margin-left: 8px;
}

/* Helper text below field (alternative to tooltip) */
.helper-text-below {
    font-size: 12px;
    color: var(--embed-color-placeholder, #999);
    margin: 4px 0 0 0;
    line-height: 1.4;
}

/* Helper icon positioning for textareas - align to top */
.input-helper-wrapper:has(.embed-textarea) .helper-icon {
    top: 12px;
    transform: none;
}

/* Mobile responsive tooltip positioning - constrain to viewport to prevent clipping */
@media (max-width: 500px) {
    .helper-icon::after {
        /* Keep centered but use smaller width to fit within field boundaries */
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        min-width: 140px;
        max-width: 200px;
        white-space: normal;
        word-wrap: break-word;
    }

    .helper-icon::before {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
    }

    .helper-icon:focus::after {
        transform: translateX(-50%) translateY(2px);
    }
}

.embed-checkbox {
    appearance: none;
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    min-width: 16px;
    flex-shrink: 0;
    border: 1px solid #ccc;
    border-radius: 3px;
    background-color: #fff;
    cursor: pointer;
    position: relative;
    margin: 0;
}

.embed-checkbox:checked {
    background-color: var(--embed-primary-color, var(--embed-color-link, #667eea));
    border-color: var(--embed-primary-color, var(--embed-color-link, #667eea));
}

.embed-checkbox:checked::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 5px;
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* Radio Button */
.embed-radio {
    appearance: none;
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border: 1px solid #ccc;
    border-radius: 50%;
    background-color: #fff;
    cursor: pointer;
    position: relative;
    margin: 0;
}

.embed-radio:checked {
    background-color: var(--embed-primary-color, var(--embed-color-link, #667eea));
    border-color: var(--embed-primary-color, var(--embed-color-link, #667eea));
}

.embed-radio:checked::after {
    content: '';
    position: absolute;
    top: 4px;
    left: 4px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: white;
}

/* Button */
.embed-button {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: 10px 20px;
    background: var(--embed-bg-button, #667eea);
    color: var(--embed-color-button, #ffffff);
    border: var(--embed-border-button, 1px solid transparent);
    border-radius: var(--embed-border-radius-button, 4px);
    font-size: var(--embed-font-size-button, 16px);
    font-weight: var(--embed-font-weight-button, 700);
    font-family: var(--embed-font-button, inherit);
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s, opacity 0.2s;
    margin-top: var(--embed-spacing-content, 15px);
    text-decoration: none;
}

.embed-button:hover {
    background: var(--embed-bg-button-hover, #5a67d8);
    color: var(--embed-color-button-hover, #ffffff);
}

.embed-button:active {
    background: var(--embed-bg-button-active, #4c51bf);
    color: var(--embed-color-button-active, #ffffff);
}

.embed-button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* Progress Bar & Stats */
.embed-stats {
    margin-bottom: var(--embed-spacing-content, 15px);
}

.embed-goal-text {
    font-size: 0.875rem;
    font-weight: bold;
    margin-bottom: 5px;
    color: var(--embed-primary-color, var(--embed-color-counter, #667eea));
}

.embed-progress-bar {
    width: 100%;
    height: 10px;
    background-color: #f0f2f5;
    border-radius: 5px;
    overflow: hidden;
    appearance: none;
    -webkit-appearance: none;
}

.embed-progress-bar::-webkit-progress-bar {
    background-color: #f0f2f5;
}

.embed-progress-bar::-webkit-progress-value {
    background-color: var(--embed-primary-color, var(--embed-color-counter, #667eea));
    transition: width 1s ease;
}

.embed-progress-bar::-moz-progress-bar {
    background-color: var(--embed-primary-color, var(--embed-color-counter, #667eea));
}

.embed-signature-badge {
    background: #f0f2f5;
    color: var(--embed-primary-color, var(--embed-color-counter, #667eea));
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    display: inline-block;
}

/* Alerts */
.embed-alert {
    padding: 15px;
    border-radius: 4px;
    margin-bottom: 15px;
    font-size: 0.9rem;
}

.embed-alert-warning {
    background-color: #fff3cd;
    color: #856404;
    border: 1px solid #ffeeba;
}

.embed-alert-danger {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.embed-alert-success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 99999;
    display: none;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-overlay.open {
    opacity: 1;
    display: flex;
}

.modal-container {
    background: white;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    position: relative;
    transform: scale(0.95) translateY(10px);
    opacity: 0;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
}

.modal-overlay.open .modal-container {
    transform: scale(1) translateY(0);
    opacity: 1;
}

.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
    color: #333;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: #999;
    padding: 0;
}

.modal-close:hover {
    color: #333;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    font-size: 1rem;
    line-height: 1.6;
    color: #333;
}

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

.margin-top-small {
    margin-top: 10px;
}

/* Mobile Responsive Styles */
@media (max-width: 500px) {
    .embed-container {
        min-width: 100%;
        max-width: 100%;
        padding: 16px;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    /* Stack grids with 3+ fields vertically on mobile */
    .embed-grid[data-field-count]:not([data-field-count="1"]):not([data-field-count="2"]) {
        display: flex !important;
        flex-direction: column;
        gap: 12px;
    }

    .embed-grid[data-field-count]:not([data-field-count="1"]):not([data-field-count="2"])>* {
        width: 100%;
        flex: none;
    }

    /* Keep 2-field rows side-by-side but allow wrapping */
    .embed-grid[data-field-count="2"] {
        display: flex !important;
        flex-wrap: wrap;
        gap: 10px;
    }

    .embed-grid[data-field-count="2"]>* {
        flex: 1 1 45%;
        min-width: 140px;
    }

    /* Ensure inputs take full width */
    .embed-input,
    .embed-select,
    .embed-textarea {
        font-size: 16px;
        /* Prevent iOS zoom */
    }
}

/* =====================
   Multistep Form Styles
   ===================== */

/* Progress Indicator Container */
.embed-progress {
    margin-bottom: 1.5rem;
}

/* Progress Bar Style */
.embed-progress[data-style="progress_bar"] .embed-progress-bar {
    height: 6px;
    background: #e5e5e5;
    border-radius: 3px;
    overflow: hidden;
}

.embed-progress .embed-progress-fill {
    height: 100%;
    background: var(--embed-primary-color, var(--embed-bg-button, #667eea));
    transition: width 0.3s ease;
    border-radius: 3px;
}

.embed-progress .embed-progress-text {
    text-align: center;
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: #666;
}

/* Step Numbers Style */
.embed-progress-numbers {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
}

.embed-step-number {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #e5e5e5;
    color: #666;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.embed-step-number.active {
    background: var(--embed-primary-color, var(--embed-bg-button, #667eea));
    color: #fff;
}

.embed-step-number.completed {
    background: var(--embed-primary-color, var(--embed-bg-button, #667eea));
    opacity: 0.6;
    color: #fff;
}

/* Note: .embed-page and .embed-page-single have no special base styles;
   they are used for JavaScript targeting */

/* Page Validation Message */
.embed-page-validation-message {
    background: linear-gradient(135deg, #fff5f5 0%, #fff0f0 100%);
    border: 1px solid #f5c2c7;
    border-left: 4px solid #dc3545;
    border-radius: 6px;
    padding: 12px 16px;
    margin-top: 1rem;
    color: #842029;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: embed-shake 0.5s ease-in-out;
}

.embed-page-validation-message .embed-validation-icon {
    font-style: normal;
    font-size: 1.1em;
}

@keyframes embed-shake {

    0%,
    100% {
        transform: translateX(0);
    }

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-4px);
    }

    20%,
    40%,
    60%,
    80% {
        transform: translateX(4px);
    }
}

/* Page Navigation */
.embed-page-nav {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid #e5e5e5;
}

/* Secondary Button (Previous) */
.embed-button-secondary {
    background: transparent;
    color: var(--embed-bg-button, #667eea);
    border: 1px solid var(--embed-bg-button, #667eea);
}

.embed-button-secondary:hover {
    background: var(--embed-bg-button, #667eea);
    color: #fff;
}

/* Navigation Buttons - auto width */
.embed-page-nav .embed-button {
    width: auto;
    flex: 0 0 auto;
    margin-top: 0;
}

/* Next button - align right */
.embed-page-nav .embed-next-btn {
    margin-left: auto;
}

/* Note: .embed-preview-page has no special base styles; styled via children */

.embed-preview-title {
    font-size: 1.2rem;
    margin-bottom: 1.5rem;
    color: #333;
    font-weight: 600;
}

.embed-preview-list {
    background: #f9f9f9;
    border-radius: 8px;
    padding: 1rem;
}

.embed-preview-item {
    display: flex;
    padding: 0.75rem 0;
    border-bottom: 1px solid #e5e5e5;
}

.embed-preview-item:last-child {
    border-bottom: none;
}

.embed-preview-label {
    flex: 0 0 40%;
    font-weight: 500;
    color: #666;
}

.embed-preview-value {
    flex: 1;
    color: #333;
}

/* Range/Slider Input */
.embed-range-container {
    padding: 4px 0;
}

.embed-range {
    width: 100%;
    height: 8px;
    -webkit-appearance: none;
    appearance: none;
    background: #e5e5e5;
    border-radius: 4px;
    outline: none;
    cursor: pointer;
}

.embed-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--embed-primary-color, var(--embed-bg-button, #667eea));
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s ease;
}

.embed-range::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.embed-range::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--embed-primary-color, var(--embed-bg-button, #667eea));
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.embed-range::-moz-range-track {
    background: #e5e5e5;
    height: 8px;
    border-radius: 4px;
}

.embed-range-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.85em;
    color: #666;
    margin-top: 4px;
}

.embed-range-value {
    font-weight: 600;
    color: var(--embed-primary-color, var(--embed-bg-button, #667eea));
}

/* Input Validation Error State */
.embed-input-error {
    border-color: #dc3545 !important;
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.1);
}

/* Email Typo Suggestion */
.embed-email-suggestion {
    margin-top: 6px;
    padding: 8px 12px;
    background-color: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 4px;
    font-size: 0.875rem;
    color: #856404;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.embed-email-suggestion .suggestion-text {
    flex: 1;
    min-width: 0;
}

.embed-email-suggestion .suggestion-fix-link {
    color: #856404;
    text-decoration: underline;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.2s;
}

.embed-email-suggestion .suggestion-fix-link:hover {
    color: #533f03;
    text-decoration: underline;
}

.embed-email-suggestion .suggestion-fix-link:active {
    color: #856404;
}

/* Mobile Responsive for Multistep */
@media (max-width: 500px) {
    .embed-progress-numbers {
        gap: 0.5rem;
    }

    .embed-step-number {
        width: 28px;
        height: 28px;
        font-size: 0.8rem;
    }

    .embed-page-nav {
        flex-direction: column;
        gap: 0.75rem;
    }

    .embed-page-nav .embed-button {
        width: 100%;
        margin-left: 0;
    }

    .embed-preview-item {
        flex-direction: column;
        gap: 0.25rem;
    }

    .embed-preview-label {
        flex: none;
    }
}

/* Rating Stars */
.embed-rating-stars {
    display: flex;
    gap: 4px;
    cursor: pointer;
}

.embed-star {
    font-size: 1.5em;
    color: #ddd;
    transition: color 0.15s ease, transform 0.1s ease;
    user-select: none;
}

.embed-star:hover {
    transform: scale(1.1);
}

/* Color Picker */
.embed-color {
    width: 50px;
    height: 38px;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    padding: 2px;
    background: transparent;
}

.embed-color::-webkit-color-swatch-wrapper {
    padding: 0;
}

.embed-color::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

.embed-color::-moz-color-swatch {
    border: none;
    border-radius: 4px;
}

/* File Upload */
.embed-file-container {
    font-family: inherit;
}

.embed-file-dropzone {
    display: block;
    border: 2px dashed #ddd;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    background: #fafafa;
    transition: border-color 0.2s ease, background 0.2s ease;
    font-family: inherit;
}

.embed-file-dropzone:hover,
.embed-file-dropzone.drag-over {
    border-color: var(--embed-primary-color, var(--embed-bg-button, #667eea));
    background: #f0f4ff;
}

.embed-file-list {
    font-family: inherit;
}

.embed-file-item {
    font-family: inherit;
}

.embed-file-name,
.embed-file-error {
    font-family: inherit;
}

/* File Upload Error State */
.embed-file-dropzone.embed-input-error {
    border-color: #dc3545 !important;
    background: #fff5f5;
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.1);
}

.embed-file-container.embed-input-error .embed-file-dropzone {
    border-color: #dc3545 !important;
    background: #fff5f5;
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.1);
}