.sleepmed-form-container {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    width: 100%;
    max-width: 860px;
    margin: 40px auto;
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 40px 100px -40px rgba(15, 23, 42, 0.35);
    overflow: hidden;
    position: relative;
    box-sizing: border-box;
    -webkit-text-size-adjust: 100%;
    --sleepmed-primary: #2563eb;
    --sleepmed-primary-rgb: 37, 99, 235;
    --sleepmed-secondary: #0ea5e9;
    --sleepmed-secondary-rgb: 14, 165, 233;
}

.sleepmed-form-container,
.sleepmed-form-container * {
    box-sizing: border-box;
}

/* Keep Google Material Icons rendering consistent across themes/builders. */
.material-icons-round {
    font-family: 'Material Icons Round' !important;
    font-weight: normal;
    font-style: normal;
    font-size: 24px;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    display: inline-block;
    white-space: nowrap;
    direction: ltr;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    -webkit-font-feature-settings: 'liga';
    font-feature-settings: 'liga';
}

.sleepmed-error-notice {
    padding: 24px;
    margin: 24px auto;
    max-width: 640px;
    border-radius: 12px;
    background: #fef2f2;
    color: #b91c1c;
    font-weight: 600;
    text-align: center;
    box-shadow: 0 20px 45px -24px rgba(185, 28, 28, 0.45);
}

.sleepmed-hero-intro {
    padding: 28px 32px 24px;
    background: linear-gradient(135deg, rgba(var(--sleepmed-secondary-rgb), 0.12), rgba(var(--sleepmed-primary-rgb), 0.12));
    border-bottom: 1px solid rgba(226, 232, 240, 0.6);
}

.sleepmed-hero-intro__layout {
    display: flex;
    gap: 24px;
    align-items: center;
}

.sleepmed-hero-intro__copy {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sleepmed-hero-intro__badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(var(--sleepmed-primary-rgb), 0.15);
    color: #1e3a8a;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 6px 12px;
    border-radius: 999px;
}

.sleepmed-hero-intro__copy h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #0f172a;
    margin: 0;
}

.sleepmed-hero-intro__copy p {
    margin: 0;
    color: #475569;
    font-size: 0.98rem;
}

.sleepmed-hero-intro__contact {
    margin-top: 18px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    color: var(--sleepmed-primary);
}

.sleepmed-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(var(--sleepmed-primary-rgb), 0.15);
    font-size: 0.95rem;
}

.sleepmed-inline-icon {
    margin-right: 8px;
}

.sleepmed-hero-intro__contact a {
    color: inherit;
    text-decoration: none;
}

@media (max-width: 640px) {
    .sleepmed-hero-intro {
        padding: 24px;
    }

    .sleepmed-hero-intro__layout {
        flex-direction: column;
        align-items: flex-start;
    }

}

.sleepmed-progress {
    position: sticky;
    top: 0;
    z-index: 10;
    background: linear-gradient(90deg, rgba(var(--sleepmed-secondary-rgb), 0.9), rgba(var(--sleepmed-primary-rgb), 0.9));
    color: #fff;
    padding: 18px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.sleepmed-progress > * {
    min-width: 0;
}

.sleepmed-progress-bar {
    position: relative;
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 12px;
}

.sleepmed-progress-fill {
    height: 100%;
    background: var(--sleepmed-primary);
    width: 0;
    transition: width 0.35s ease;
}

.sleepmed-content {
    padding: 32px 36px 44px;
}

.sleepmed-loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.88);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 99;
}

.sleepmed-spinner {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 6px solid rgba(148, 163, 184, 0.35);
    border-top-color: var(--sleepmed-primary);
    animation: sleepmed-spin 0.8s linear infinite;
}

.sleepmed-loading-text {
    font-size: 0.95rem;
    font-weight: 600;
    color: #0f172a;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.sleepmed-decoy {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    border: 0;
    margin: 0;
    opacity: 0;
    pointer-events: auto;
    background: transparent;
    color: transparent;
}

@keyframes sleepmed-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.sleepmed-card {
    background: rgba(248, 250, 252, 0.85);
    border-radius: 18px;
    padding: 24px;
    margin-bottom: 24px;
    border: 1px solid rgba(226, 232, 240, 0.7);
}

.sleepmed-step-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: 12px;
}

.sleepmed-step-title .sleepmed-step-icon {
    font-size: 1.5rem;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: rgba(var(--sleepmed-secondary-rgb), 0.1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.sleepmed-step-icon {
    line-height: 1;
    font-size: 22px;
}

.sleepmed-step-description {
    color: #475569;
    margin-top: 8px;
}

.sleepmed-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-top: 20px;
}

.sleepmed-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
}

.sleepmed-field label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #334155;
}

.sleepmed-field input,
.sleepmed-field select,
.sleepmed-field textarea {
    width: 100%;
    max-width: 100%;
    height: 48px;
    border-radius: 16px;
    border: 1px solid rgba(var(--sleepmed-primary-rgb), 0.45);
    padding: 10px 14px;
    font-size: 1rem;
    font-weight: 500;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    background: #f8fafc;
    color: #0f172a;
}

.sleepmed-field textarea {
    min-height: 96px;
    height: auto;
}

.sleepmed-field input::placeholder,
.sleepmed-field textarea::placeholder {
    color: #c7cdd4;
    font-weight: 600;
}

.sleepmed-field input.has-voice {
    padding-right: 56px;
}

/* Invalid state for required fields */
.sleepmed-field input.invalid,
.sleepmed-field select.invalid,
.sleepmed-field textarea.invalid {
    border-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}

.sleepmed-field input:focus,
.sleepmed-field select:focus,
.sleepmed-field textarea:focus {
    border-color: var(--sleepmed-secondary);
    box-shadow: 0 0 0 3px rgba(var(--sleepmed-secondary-rgb), 0.2);
    outline: none;
}

.sleepmed-toggle-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-top: 20px;
}

.sleepmed-toggle {
    background: #fff;
    border-radius: 16px;
    border: 1px solid rgba(203, 213, 225, 0.8);
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: all 0.25s ease;
}

.sleepmed-toggle input[type="checkbox"] {
    display: none;
}

.sleepmed-toggle-status {
    font-weight: 600;
    color: #0f172a;
}

.sleepmed-toggle.active .sleepmed-toggle-status {
    color: var(--sleepmed-secondary);
}

.sleepmed-toggle.active {
    border-color: var(--sleepmed-secondary);
    box-shadow: 0 18px 30px -20px rgba(var(--sleepmed-secondary-rgb), 0.45);
}

.sleepmed-scale-row {
    display: grid;
    grid-template-columns: 1.3fr 1fr;
    gap: 10px;
    align-items: center;
    padding: 12px 16px;
    background: rgba(241, 245, 249, 0.7);
    border-radius: 14px;
    margin-bottom: 12px;
}

.sleepmed-scale-row span {
    font-size: 0.95rem;
    color: #1e293b;
}

.sleepmed-scale-row select { display: none; }

/* Numeric chips for scales */
.sleepmed-scale-options {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

.sleepmed-chip {
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    white-space: nowrap;
    border-radius: 50%;
    border: 1px solid rgba(203, 213, 225, 0.8);
    background: rgba(255,255,255,0.7);
    color: #0f172a;
    font-weight: 700;
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease, background .15s ease, color .15s ease, border-color .15s ease;
}

.sleepmed-chip:hover {
    background: rgba(var(--sleepmed-secondary-rgb), 0.10);
    border-color: rgba(var(--sleepmed-secondary-rgb), 0.6);
}

.sleepmed-chip.active {
    background: rgba(var(--sleepmed-secondary-rgb), 0.18);
    border-color: var(--sleepmed-secondary);
    color: #0369a1;
    box-shadow: 0 8px 18px -12px rgba(var(--sleepmed-secondary-rgb), 0.6);
    transform: translateY(-1px);
}

.sleepmed-chip:focus-visible {
    outline: 3px solid rgba(var(--sleepmed-secondary-rgb), 0.35);
    outline-offset: 2px;
}

.sleepmed-nav {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-top: 24px;
}

.sleepmed-nav button {
    flex: 1;
    padding: 14px 20px;
    border-radius: 14px;
    font-weight: 600;
    font-size: 1.05rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.sleepmed-nav .primary {
    background: linear-gradient(135deg, var(--sleepmed-secondary), var(--sleepmed-primary));
    color: #fff;
    border: none;
    box-shadow: 0 18px 30px -18px rgba(var(--sleepmed-primary-rgb), 0.6);
}

.sleepmed-nav .secondary {
    background: #e2e8f0;
    color: #1e293b;
    border: none;
}

.sleepmed-nav button:hover {
    transform: translateY(-1px);
}

.sleepmed-language-switcher {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.sleepmed-language-switcher button {
    height: 40px;
    min-width: 58px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.24);
    background: rgba(255, 255, 255, 0.12);
    color: #e7f0ff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 0 10px;
    white-space: nowrap;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, color 0.2s ease;
    cursor: pointer;
}

.sleepmed-language-switcher button.active,
.sleepmed-language-switcher button:hover {
    background: #ffffff;
    color: #155fb5;
    box-shadow: 0 10px 20px -14px rgba(15, 23, 42, 0.85);
}

.sleepmed-lang-icon {
    font-size: 16px;
    line-height: 1;
}

.sleepmed-lang-label {
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.sleepmed-step-title .sleepmed-step-icon {
    line-height: 1;
}

.sleepmed-alert {
    border-radius: 12px;
    padding: 14px 16px;
    margin-top: 18px;
    font-weight: 600;
}

.sleepmed-alert.error {
    background: rgba(248, 113, 113, 0.15);
    color: #b91c1c;
}

.sleepmed-alert.success {
    background: rgba(74, 222, 128, 0.15);
    color: #047857;
}

.sleepmed-alert.info {
    background: rgba(125, 211, 252, 0.25);
    color: #0369a1;
}

.sleepmed-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.58);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 9999;
}

.sleepmed-modal-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.sleepmed-modal {
    background: #ffffff;
    border-radius: 16px;
    border: 1px solid #e2e8f0;
    padding: 22px 22px 18px;
    max-width: 460px;
    width: 100%;
    text-align: center;
    max-height: min(88vh, 560px);
    overflow: auto;
    box-shadow: 0 30px 80px -34px rgba(2, 6, 23, 0.5);
    transform: translateY(20px);
    transition: transform 0.2s ease;
    position: relative;
}

.sleepmed-modal-overlay.visible .sleepmed-modal {
    transform: translateY(0);
}

.sleepmed-modal__icon {
    font-size: 44px;
    margin: 4px auto 10px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.sleepmed-modal__icon.success {
    color: #16a34a;
    background: rgba(22, 163, 74, 0.12);
}

.sleepmed-modal__icon.error {
    color: #dc2626;
    background: rgba(220, 38, 38, 0.1);
}

.sleepmed-modal__icon.warning {
    color: #d97706;
    background: rgba(217, 119, 6, 0.12);
}

.sleepmed-modal__icon.info {
    color: #0ea5e9;
    background: rgba(14, 165, 233, 0.12);
}

.sleepmed-modal__title {
    margin: 0;
    font-size: 1.18rem;
    font-weight: 700;
    color: #0f172a;
}

.sleepmed-modal__message {
    margin: 10px 0 0;
    color: #334155;
    font-size: 0.95rem;
    line-height: 1.5;
}

.sleepmed-modal__actions {
    margin-top: 16px;
    display: flex;
    justify-content: center;
}

.sleepmed-modal__actions button {
    padding: 10px 20px;
    border-radius: 10px;
    border: 1px solid rgba(var(--sleepmed-primary-rgb), 0.2);
    background: var(--sleepmed-primary);
    color: #fff;
    font-weight: 700;
    letter-spacing: 0.02em;
    cursor: pointer;
    box-shadow: 0 10px 30px -15px rgba(var(--sleepmed-primary-rgb), 0.9);
}

.sleepmed-modal__actions button:hover {
    filter: brightness(1.05);
}

.sleepmed-modal__close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    color: #475569;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 19px;
    line-height: 1;
}

.sleepmed-modal__close:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.sleepmed-voice-button {
    position: absolute;
    right: 8px;
    bottom: 9px;
    top: auto;
    transform: none;
    width: 42px;
    height: 30px;
    border-radius: 0;
    border: none;
    border-left: 1px solid rgba(var(--sleepmed-primary-rgb), 0.25);
    background: transparent;
    color: rgba(var(--sleepmed-primary-rgb), 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    cursor: pointer;
}

.sleepmed-voice-button:hover {
    color: #64748b;
}

.sleepmed-voice-icon {
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
    margin: 0;
    padding: 0;
    pointer-events: none;
}

.sleepmed-consent-step {
    display: grid;
    gap: 18px;
}

.sleepmed-consent-stack {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
}

.sleepmed-consent-panel,
.sleepmed-consent-date,
.sleepmed-consent-card,
.sleepmed-signature-panel {
    margin: 0;
}

.sleepmed-consent-panel,
.sleepmed-consent-date,
.sleepmed-consent-card,
.sleepmed-signature-panel {
    padding: 16px 18px;
    border: 1px solid rgba(203, 213, 225, 0.72);
    border-radius: 16px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 250, 252, 0.94));
    box-shadow: 0 14px 32px -30px rgba(15, 23, 42, 0.2);
}

.sleepmed-consent-panel {
    display: grid;
    gap: 14px;
}

.sleepmed-consent-date > label,
.sleepmed-signature-title {
    display: block;
    margin: 0 0 10px;
    color: #334155;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.sleepmed-consent-date input {
    margin-top: 0;
    height: 42px;
    border-radius: 13px;
    border-color: rgba(147, 197, 253, 0.95);
    background: rgba(248, 250, 252, 0.9);
    box-shadow: none;
}

.sleepmed-consent-card {
    display: flex;
    align-items: center;
    min-height: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

.sleepmed-consent-row {
    width: 100%;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    padding: 2px 0;
}

.sleepmed-consent-row input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin-top: 0;
    accent-color: var(--sleepmed-primary);
}

.sleepmed-consent-row label {
    margin: 0;
    color: #0f172a;
    font-size: 0.96rem;
    font-weight: 500;
    line-height: 1.45;
}

.sleepmed-signature-panel {
    padding: 18px 20px 20px;
}

.sleepmed-signature {
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(191, 219, 254, 0.9);
    border-radius: 16px;
    height: 200px;
    margin-top: 0;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.99), rgba(248, 250, 252, 0.96)),
        repeating-linear-gradient(
            0deg,
            rgba(148, 163, 184, 0.08) 0,
            rgba(148, 163, 184, 0.08) 1px,
            transparent 1px,
            transparent 28px
        );
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.sleepmed-signature::after {
    content: "";
    position: absolute;
    left: 18px;
    right: 18px;
    bottom: 28px;
    height: 1px;
    background: rgba(148, 163, 184, 0.32);
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.sleepmed-signature.sleepmed-signature--empty::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at top right, rgba(var(--sleepmed-primary-rgb), 0.08), transparent 42%);
    pointer-events: none;
}

.sleepmed-signature.invalid {
    border-color: #ef4444;
    box-shadow: inset 0 0 0 3px rgba(239, 68, 68, 0.12);
}

.sleepmed-signature canvas {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    display: block;
    background-color: transparent;
}

.sleepmed-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
    flex-wrap: wrap;
}

.sleepmed-actions--compact {
    justify-content: flex-end;
    margin-top: 14px;
}

.sleepmed-actions button {
    padding: 12px 16px;
    border-radius: 12px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    background: var(--sleepmed-primary);
    color: #fff;
}

.sleepmed-actions button.secondary {
    background: var(--sleepmed-secondary);
}

.sleepmed-consent-row.invalid {
    outline: 2px solid #ef4444;
    outline-offset: 4px;
    border-radius: 10px;
}

@media (max-width: 640px) {
    .sleepmed-content {
        padding: 24px;
    }

    .sleepmed-form-container {
        width: calc(100% - 24px);
        max-width: calc(100vw - 24px);
        margin: 16px auto;
        border-radius: 14px;
        box-shadow: 0 24px 60px -32px rgba(15, 23, 42, 0.25);
    }

    .sleepmed-progress {
        padding: 12px 16px;
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .sleepmed-card {
        padding: 18px 16px;
    }

    .sleepmed-step-title {
        font-size: 1.25rem;
    }

    .sleepmed-grid,
    .sleepmed-toggle-grid,
    .sleepmed-consent-stack {
        grid-template-columns: 1fr;
    }

    .sleepmed-nav {
        flex-direction: column;
    }

    .sleepmed-nav button {
        width: 100%;
    }

    .sleepmed-scale-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }
}
